X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fplatform-powerpc.c;h=7370d7dcc20a21e78dacc57e2efc8ebe7e3cdb0f;hp=b4f2a771f64ce6b8016025860ded536a901ded1f;hb=8cfcec4279b229dacfb0589bc443f8a4cbd83082;hpb=37b4861cb01bf6bd9da41aa1b311a87b0d26fc25 diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c index b4f2a77..7370d7d 100644 --- a/discover/platform-powerpc.c +++ b/discover/platform-powerpc.c @@ -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; @@ -53,6 +53,8 @@ static const char *known_params[] = { "petitboot,bootdevs", "petitboot,language", "petitboot,debug?", + "petitboot,write?", + "petitboot,snapshots?", NULL, }; @@ -177,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"; @@ -436,7 +438,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; @@ -467,11 +468,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, @@ -548,6 +547,14 @@ static void populate_config(struct platform_powerpc *platform, val = get_param(platform, "petitboot,debug?"); config->debug = val && !strcmp(val, "true"); } + + 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) @@ -664,7 +671,7 @@ static void update_bootdev_config(struct platform_powerpc *platform, opt->uuid, delim); break; } - tmp = val = talloc_asprintf_append(val, boot_str); + tmp = val = talloc_asprintf_append(val, "%s", boot_str); } update_string_config(platform, "petitboot,bootdevs", val); @@ -707,6 +714,12 @@ static int update_config(struct platform_powerpc *platform, val = config->lang ?: ""; update_string_config(platform, "petitboot,language", val); + if (config->allow_writes == defaults->allow_writes) + val = ""; + else + val = config->allow_writes ? "true" : "false"; + update_string_config(platform, "petitboot,write?", val); + update_network_config(platform, config); update_bootdev_config(platform, config); @@ -743,9 +756,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) { @@ -779,9 +791,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) { @@ -973,6 +984,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); @@ -1041,6 +1077,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; } @@ -1069,7 +1109,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;