]> git.ozlabs.org Git - petitboot/blobdiff - discover/platform-powerpc.c
discover: Print IPMI bootdev response for debug
[petitboot] / discover / platform-powerpc.c
index fc96305ad70bc56d71d5e002a5b03617a84a57a6..992123e58a92bb3cc9ba161bcfd1e8356fb48118 100644 (file)
@@ -22,7 +22,7 @@
 static const char *partition = "common";
 static const char *sysparams_dir = "/sys/firmware/opal/sysparams/";
 static const char *devtree_dir = "/proc/device-tree/";
-static const int ipmi_timeout = 500; /* milliseconds */
+static const int ipmi_timeout = 5000; /* milliseconds. */
 
 struct param {
        char                    *name;
@@ -54,6 +54,7 @@ static const char *known_params[] = {
        "petitboot,language",
        "petitboot,debug?",
        "petitboot,write?",
+       "petitboot,snapshots?",
        NULL,
 };
 
@@ -178,7 +179,7 @@ static int write_nvram(struct platform_powerpc *platform)
        struct process *process;
        struct param *param;
        const char *argv[6];
-       int rc;
+       int rc = 0;
 
        argv[0] = "nvram";
        argv[1] = "--update-config";
@@ -309,7 +310,7 @@ static int parse_one_interface_config(struct config *config,
        } else if (!strcmp(tok, "static")) {
                ifconf->method = CONFIG_METHOD_STATIC;
 
-               /* ip/mask, [optional] gateway */
+               /* ip/mask, [optional] gateway, [optional] url */
                tok = strtok_r(NULL, ",", &saveptr);
                if (!tok)
                        goto out_err;
@@ -322,6 +323,12 @@ static int parse_one_interface_config(struct config *config,
                                talloc_strdup(ifconf, tok);
                }
 
+               tok = strtok_r(NULL, ",", &saveptr);
+               if (tok) {
+                       ifconf->static_config.url =
+                               talloc_strdup(ifconf, tok);
+               }
+
        } else {
                pb_log("Unknown network configuration method %s\n", tok);
                goto out_err;
@@ -437,7 +444,6 @@ static void populate_bootdev_config(struct platform_powerpc *platform,
 {
        struct autoboot_option *opt, *new = NULL;
        char *pos, *end, *old_dev = NULL;
-       const char delim = ' ';
        unsigned int n_new = 0;
        const char *val;
        bool conflict;
@@ -468,11 +474,9 @@ static void populate_bootdev_config(struct platform_powerpc *platform,
 
                if (read_bootdev(config, &pos, opt)) {
                        pb_log("bootdev config is in an unknown format "
-                              "(expected uuid:... or mac:...)");
+                              "(expected uuid:... or mac:...)\n");
                        talloc_free(opt);
-                       if (strchr(pos, delim))
-                               continue;
-                       return;
+                       continue;
                }
 
                new = talloc_realloc(config, new, struct autoboot_option,
@@ -553,6 +557,10 @@ static void populate_config(struct platform_powerpc *platform,
        val = get_param(platform, "petitboot,write?");
        if (val)
                config->allow_writes = !strcmp(val, "true");
+
+       val = get_param(platform, "petitboot,snapshots?");
+       if (val)
+               config->disable_snapshots = !strcmp(val, "false");
 }
 
 static char *iface_config_str(void *ctx, struct interface_config *config)
@@ -573,10 +581,12 @@ static char *iface_config_str(void *ctx, struct interface_config *config)
                str = talloc_asprintf_append(str, "dhcp");
 
        } else if (config->method == CONFIG_METHOD_STATIC) {
-               str = talloc_asprintf_append(str, "static,%s%s%s",
+               str = talloc_asprintf_append(str, "static,%s%s%s%s%s",
                                config->static_config.address,
                                config->static_config.gateway ? "," : "",
-                               config->static_config.gateway ?: "");
+                               config->static_config.gateway ?: "",
+                               config->static_config.url ? "," : "",
+                               config->static_config.url ?: "");
        }
        return str;
 }
@@ -754,9 +764,8 @@ static int read_bootdev_sysparam(const char *name, uint8_t *val)
        char path[50];
        int fd, rc;
 
-       strcpy(path, sysparams_dir);
-       assert(strlen(name) < sizeof(path) - strlen(path));
-       strcat(path, name);
+       assert(strlen(sysparams_dir) + strlen(name) < sizeof(path));
+       snprintf(path, sizeof(path), "%s%s", sysparams_dir, name);
 
        fd = open(path, O_RDONLY);
        if (fd < 0) {
@@ -790,9 +799,8 @@ static int write_bootdev_sysparam(const char *name, uint8_t val)
        char path[50];
        int fd, rc;
 
-       strcpy(path, sysparams_dir);
-       assert(strlen(name) < sizeof(path) - strlen(path));
-       strcat(path, name);
+       assert(strlen(sysparams_dir) + strlen(name) < sizeof(path));
+       snprintf(path, sizeof(path), "%s%s", sysparams_dir, name);
 
        fd = open(path, O_WRONLY);
        if (fd < 0) {
@@ -915,6 +923,11 @@ static int get_ipmi_bootdev_ipmi(struct platform_powerpc *platform,
                return -1;
        }
 
+       pb_debug("IPMI get_bootdev response:\n");
+       for (int i = 0; i < resp_len; i++)
+               pb_debug("%x ", resp[i]);
+       pb_debug("\n");
+
        if (resp[0] != 0) {
                pb_log("platform: non-zero completion code %d from IPMI req\n",
                                resp[0]);
@@ -984,6 +997,31 @@ static int set_ipmi_os_boot_sensor(struct platform_powerpc *platform)
        return 0;
 }
 
+static void get_ipmi_bmc_mac(struct platform *p, uint8_t *buf)
+{
+       struct platform_powerpc *platform = p->platform_data;
+       uint16_t resp_len = 8;
+       uint8_t resp[8];
+       uint8_t req[] = { 0x1, 0x5, 0x0, 0x0 };
+       int i, rc;
+
+       rc = ipmi_transaction(platform->ipmi, IPMI_NETFN_TRANSPORT,
+                       IPMI_CMD_TRANSPORT_GET_LAN_PARAMS,
+                       req, sizeof(req),
+                       resp, &resp_len,
+                       ipmi_timeout);
+
+       pb_debug("BMC MAC resp [%d][%d]:\n", rc, resp_len);
+
+       if (rc == 0 && resp_len > 0) {
+               for (i = 2; i < resp_len; i++) {
+                       pb_debug(" %x", resp[i]);
+                       buf[i - 2] = resp[i];
+               }
+               pb_debug("\n");
+       }
+}
+
 static int load_config(struct platform *p, struct config *config)
 {
        struct platform_powerpc *platform = to_platform_powerpc(p);
@@ -1052,6 +1090,10 @@ static int get_sysinfo(struct platform *p, struct system_info *sysinfo)
                sysinfo->identifier = talloc_steal(sysinfo, buf);
        talloc_free(filename);
 
+       sysinfo->bmc_mac = talloc_zero_size(sysinfo, HWADDR_SIZE);
+       if (platform->ipmi)
+               get_ipmi_bmc_mac(p, sysinfo->bmc_mac);
+
        return 0;
 }
 
@@ -1080,7 +1122,6 @@ static bool probe(struct platform *p, void *ctx)
                platform->get_ipmi_bootdev = get_ipmi_bootdev_ipmi;
                platform->clear_ipmi_bootdev = clear_ipmi_bootdev_ipmi;
                platform->set_os_boot_sensor = set_ipmi_os_boot_sensor;
-
        } else if (!stat(sysparams_dir, &statbuf)) {
                pb_debug("platform: using sysparams for IPMI paramters\n");
                platform->get_ipmi_bootdev = get_ipmi_bootdev_sysparams;