11 #include <asm/byteorder.h>
13 #include <file/file.h>
14 #include <talloc/talloc.h>
15 #include <list/list.h>
17 #include <param_list/param_list.h>
18 #include <process/process.h>
19 #include <types/types.h>
27 static const char *partition = "common";
28 static const char *sysparams_dir = "/sys/firmware/opal/sysparams/";
29 static const char *devtree_dir = "/proc/device-tree/";
31 struct platform_powerpc {
32 struct param_list params;
34 bool ipmi_bootdev_persistent;
35 int (*get_ipmi_bootdev)(
36 struct platform_powerpc *platform,
37 uint8_t *bootdev, bool *persistent);
38 int (*clear_ipmi_bootdev)(
39 struct platform_powerpc *platform,
41 int (*set_os_boot_sensor)(
42 struct platform_powerpc *platform);
43 void (*get_platform_versions)(struct system_info *info);
46 #define to_platform_powerpc(p) \
47 (struct platform_powerpc *)(p->platform_data)
49 static int parse_nvram_params(struct platform_powerpc *platform,
52 char *pos, *name, *value;
53 unsigned int paramlen;
56 /* discard 2 header lines:
63 for (i = 0; i < len; i++) {
71 fprintf(stderr, "failure parsing nvram output\n");
75 for (pos = buf + i; pos < buf + len; pos += paramlen + 1) {
79 newline = strchr(pos, '\n');
85 paramlen = strlen(pos);
88 value = strchr(pos, '=');
92 namelen = value - name;
96 if (!param_list_is_known_n(&platform->params, name, namelen))
102 param_list_set(&platform->params, name, value, false);
108 static int parse_nvram(struct platform_powerpc *platform)
110 struct process_stdout *stdout;
115 argv[1] = "--print-config";
116 argv[2] = "--partition";
120 rc = process_get_stdout_argv(NULL, &stdout, argv);
123 fprintf(stderr, "nvram process returned "
124 "non-zero exit status\n");
127 rc = parse_nvram_params(platform, stdout->buf, stdout->len);
134 static int write_nvram(struct platform_powerpc *platform)
136 struct process *process;
142 argv[1] = "--update-config";
144 argv[3] = "--partition";
148 process = process_create(platform);
149 process->path = "nvram";
150 process->argv = argv;
152 param_list_for_each(&platform->params, param) {
155 if (!param->modified)
158 paramstr = talloc_asprintf(platform, "%s=%s",
159 param->name, param->value);
162 rc = process_run_sync(process);
164 talloc_free(paramstr);
166 if (rc || !process_exit_ok(process)) {
168 pb_log("nvram update process returned "
169 "non-zero exit status\n");
174 process_release(process);
178 static int parse_hwaddr(struct interface_config *ifconf, char *str)
182 if (strlen(str) != strlen("00:00:00:00:00:00"))
185 for (i = 0; i < HWADDR_SIZE; i++) {
189 byte[0] = str[i * 3 + 0];
190 byte[1] = str[i * 3 + 1];
193 x = strtoul(byte, &endp, 16);
194 if (endp != byte + 2)
197 ifconf->hwaddr[i] = x & 0xff;
203 static int parse_one_interface_config(struct config *config, char *confstr)
205 struct interface_config *ifconf;
206 char *tok, *tok_gw, *tok_url, *saveptr;
208 ifconf = talloc_zero(config, struct interface_config);
210 if (!confstr || !strlen(confstr))
213 /* first token should be the mac address */
214 tok = strtok_r(confstr, ",", &saveptr);
218 if (parse_hwaddr(ifconf, tok))
221 /* second token is the method */
222 tok = strtok_r(NULL, ",", &saveptr);
223 if (!tok || !strlen(tok) || !strcmp(tok, "ignore")) {
224 ifconf->ignore = true;
226 } else if (!strcmp(tok, "dhcp")) {
227 ifconf->method = CONFIG_METHOD_DHCP;
229 } else if (!strcmp(tok, "static")) {
230 ifconf->method = CONFIG_METHOD_STATIC;
232 /* ip/mask, [optional] gateway, [optional] url */
233 tok = strtok_r(NULL, ",", &saveptr);
236 ifconf->static_config.address =
237 talloc_strdup(ifconf, tok);
240 * If a url is set but not a gateway, we can accidentally
241 * interpret the url as the gateway. To avoid changing the
242 * parameter format check if the "gateway" is actually a
243 * pb-url if it's the last token.
245 tok_gw = strtok_r(NULL, ",", &saveptr);
246 tok_url = strtok_r(NULL, ",", &saveptr);
249 if (tok_url || !is_url(tok_gw))
250 ifconf->static_config.gateway =
251 talloc_strdup(ifconf, tok_gw);
257 ifconf->static_config.url =
258 talloc_strdup(ifconf, tok_url);
260 pb_log("Unknown network configuration method %s\n", tok);
264 config->network.interfaces = talloc_realloc(config,
265 config->network.interfaces,
266 struct interface_config *,
267 ++config->network.n_interfaces);
269 config->network.interfaces[config->network.n_interfaces - 1] = ifconf;
277 static int parse_one_dns_config(struct config *config, char *confstr)
279 char *tok, *saveptr = NULL;
281 for (tok = strtok_r(confstr, ",", &saveptr); tok;
282 tok = strtok_r(NULL, ",", &saveptr)) {
284 char *server = talloc_strdup(config, tok);
286 config->network.dns_servers = talloc_realloc(config,
287 config->network.dns_servers, const char *,
288 ++config->network.n_dns_servers);
290 config->network.dns_servers[config->network.n_dns_servers - 1]
297 static void populate_network_config(struct config *config, const char *cval)
299 char *val, *saveptr = NULL;
302 if (!cval || !strlen(cval))
305 val = talloc_strdup(config, cval);
310 tok = strtok_r(i == 0 ? val : NULL, " ", &saveptr);
314 if (!strncasecmp(tok, "dns,", strlen("dns,")))
315 parse_one_dns_config(config, tok + strlen("dns,"));
317 parse_one_interface_config(config, tok);
324 static int read_bootdev(void *ctx, char **pos, struct autoboot_option *opt)
326 char *delim = strchr(*pos, ' ');
327 int len, prefix = 0, rc = -1;
328 enum device_type type;
330 if (!strncmp(*pos, "uuid:", strlen("uuid:"))) {
331 prefix = strlen("uuid:");
332 opt->boot_type = BOOT_DEVICE_UUID;
333 } else if (!strncmp(*pos, "mac:", strlen("mac:"))) {
334 prefix = strlen("mac:");
335 opt->boot_type = BOOT_DEVICE_UUID;
337 type = find_device_type(*pos);
338 if (type != DEVICE_TYPE_UNKNOWN) {
340 opt->boot_type = BOOT_DEVICE_TYPE;
345 if (opt->boot_type == BOOT_DEVICE_UUID) {
347 len = (int)(delim - *pos) - prefix;
349 len = strlen(*pos) - prefix;
352 opt->uuid = talloc_strndup(ctx, *pos + prefix, len);
357 /* Always advance pointer to next option or end */
361 *pos += strlen(*pos);
366 static void populate_bootdev_config(struct config *config,
367 const struct param_list *pl)
369 struct autoboot_option *opt, *new = NULL;
371 unsigned int n_new = 0;
374 /* Check for ordered bootdevs */
375 val = param_list_get_value(pl, "petitboot,bootdevs");
376 if (!val || !strlen(val)) {
379 pos = talloc_strdup(config, val);
380 end = strchr(pos, '\0');
383 while (pos && pos < end) {
384 opt = talloc(config, struct autoboot_option);
386 if (read_bootdev(config, &pos, opt)) {
387 pb_log("bootdev config is in an unknown format "
388 "(expected uuid:... or mac:...)\n");
393 new = talloc_realloc(config, new, struct autoboot_option,
402 /* If autoboot has been disabled, clear the default options */
403 if (!config->autoboot_enabled) {
404 talloc_free(config->autoboot_opts);
405 config->n_autoboot_opts = 0;
410 talloc_free(config->autoboot_opts);
411 config->autoboot_opts = new;
412 config->n_autoboot_opts = n_new;
415 static void populate_config(struct config *config, const struct param_list *pl)
419 unsigned long timeout;
421 /* if the "auto-boot?' property is present and "false", disable auto
423 val = param_list_get_value(pl, "auto-boot?");
424 config->autoboot_enabled = !val || strcmp(val, "false");
426 val = param_list_get_value(pl, "petitboot,timeout");
428 timeout = strtoul(val, &end, 10);
430 if (timeout >= INT_MAX)
432 config->autoboot_timeout_sec = (int)timeout;
436 val = param_list_get_value(pl, "petitboot,language");
437 config->lang = val ? talloc_strdup(config, val) : NULL;
439 val = param_list_get_value(pl, "petitboot,network");
440 populate_network_config(config, val);
442 populate_bootdev_config(config, pl);
444 if (!config->debug) {
445 val = param_list_get_value(pl, "petitboot,debug?");
446 config->debug = val && !strcmp(val, "true");
449 val = param_list_get_value(pl, "petitboot,write?");
451 config->allow_writes = !strcmp(val, "true");
453 val = param_list_get_value(pl, "petitboot,snapshots?");
455 config->disable_snapshots = !strcmp(val, "false");
457 val = param_list_get_value(pl, "petitboot,console");
459 config->boot_console = talloc_strdup(config, val);
460 /* If a full path is already set we don't want to override it */
461 config->manual_console = config->boot_console &&
462 !strchr(config->boot_console, '[');
464 val = param_list_get_value(pl, "petitboot,http_proxy");
466 config->http_proxy = talloc_strdup(config, val);
467 val = param_list_get_value(pl, "petitboot,https_proxy");
469 config->https_proxy = talloc_strdup(config, val);
472 static char *iface_config_str(void *ctx, struct interface_config *config)
476 /* todo: HWADDR size is hardcoded as 6, but we may need to handle
477 * different hardware address formats */
478 str = talloc_asprintf(ctx, "%02x:%02x:%02x:%02x:%02x:%02x,",
479 config->hwaddr[0], config->hwaddr[1],
480 config->hwaddr[2], config->hwaddr[3],
481 config->hwaddr[4], config->hwaddr[5]);
483 if (config->ignore) {
484 str = talloc_asprintf_append(str, "ignore");
486 } else if (config->method == CONFIG_METHOD_DHCP) {
487 str = talloc_asprintf_append(str, "dhcp");
489 } else if (config->method == CONFIG_METHOD_STATIC) {
490 str = talloc_asprintf_append(str, "static,%s%s%s%s%s",
491 config->static_config.address,
492 config->static_config.gateway ? "," : "",
493 config->static_config.gateway ?: "",
494 config->static_config.url ? "," : "",
495 config->static_config.url ?: "");
500 static char *dns_config_str(void *ctx, const char **dns_servers, int n)
505 str = talloc_strdup(ctx, "dns,");
506 for (i = 0; i < n; i++) {
507 str = talloc_asprintf_append(str, "%s%s",
515 static void update_network_config(struct param_list *pl, const char *param_name,
516 const struct config *config)
522 * Don't store IPMI overrides to NVRAM. If this was a persistent
523 * override it was already stored in NVRAM by
524 * get_ipmi_network_override()
526 if (config->network.n_interfaces &&
527 config->network.interfaces[0]->override)
530 val = talloc_strdup(pl, "");
532 for (i = 0; i < config->network.n_interfaces; i++) {
533 char *iface_str = iface_config_str(pl,
534 config->network.interfaces[i]);
535 val = talloc_asprintf_append(val, "%s%s",
536 *val == '\0' ? "" : " ", iface_str);
537 talloc_free(iface_str);
540 if (config->network.n_dns_servers) {
541 char *dns_str = dns_config_str(pl,
542 config->network.dns_servers,
543 config->network.n_dns_servers);
544 val = talloc_asprintf_append(val, "%s%s",
545 *val == '\0' ? "" : " ", dns_str);
546 talloc_free(dns_str);
549 param_list_set_non_empty(pl, param_name, val, true);
553 static void update_bootdev_config(struct param_list *pl, const char *param_name,
554 const struct config *config)
556 char *val = NULL, *boot_str = NULL, *tmp = NULL;
557 struct autoboot_option *opt;
558 const char delim = ' ';
561 if (!config->n_autoboot_opts)
564 for (i = 0; i < config->n_autoboot_opts; i++) {
565 opt = &config->autoboot_opts[i];
566 switch (opt->boot_type) {
567 case BOOT_DEVICE_TYPE:
568 boot_str = talloc_asprintf(config, "%s%c",
569 device_type_name(opt->type),
572 case BOOT_DEVICE_UUID:
573 boot_str = talloc_asprintf(config, "uuid:%s%c",
577 tmp = val = talloc_asprintf_append(val, "%s", boot_str);
580 param_list_set_non_empty(pl, param_name, val, true);
583 talloc_free(boot_str);
586 static void update_config(struct param_list *pl, struct config *config,
587 const struct config *defaults)
592 if (config->autoboot_enabled == defaults->autoboot_enabled)
595 val = config->autoboot_enabled ? "true" : "false";
597 param_list_set_non_empty(pl, "auto-boot?", val, true);
599 if (config->autoboot_timeout_sec == defaults->autoboot_timeout_sec)
602 val = tmp = talloc_asprintf(pl, "%d",
603 config->autoboot_timeout_sec);
605 param_list_set_non_empty(pl, "petitboot,timeout", val, true);
609 val = config->lang ?: "";
610 param_list_set_non_empty(pl, "petitboot,language", val, true);
612 if (config->allow_writes == defaults->allow_writes)
615 val = config->allow_writes ? "true" : "false";
616 param_list_set_non_empty(pl, "petitboot,write?", val, true);
618 if (!config->manual_console) {
619 val = config->boot_console ?: "";
620 param_list_set_non_empty(pl, "petitboot,console", val, true);
623 val = config->http_proxy ?: "";
624 param_list_set_non_empty(pl, "petitboot,http_proxy", val, true);
625 val = config->https_proxy ?: "";
626 param_list_set_non_empty(pl, "petitboot,https_proxy", val, true);
628 update_network_config(pl, "petitboot,network", config);
629 update_bootdev_config(pl, "petitboot,bootdevs", config);
632 static void set_ipmi_bootdev(struct config *config, enum ipmi_bootdev bootdev,
635 config->ipmi_bootdev = bootdev;
636 config->ipmi_bootdev_persistent = persistent;
638 if (bootdev == IPMI_BOOTDEV_SAFE)
639 config->safe_mode = true;
642 static int read_bootdev_sysparam(const char *name, uint8_t *val)
648 assert(strlen(sysparams_dir) + strlen(name) < sizeof(path));
649 snprintf(path, sizeof(path), "%s%s", sysparams_dir, name);
651 fd = open(path, O_RDONLY);
653 pb_debug("powerpc: can't access sysparam %s\n",
658 rc = read(fd, buf, sizeof(buf));
662 /* bootdev definitions should only be one byte in size */
664 pb_debug("powerpc: sysparam %s read returned %d\n",
669 pb_debug("powerpc: sysparam %s: 0x%02x\n", name, buf[0]);
671 if (!ipmi_bootdev_is_valid(buf[0]))
678 static int write_bootdev_sysparam(const char *name, uint8_t val)
683 assert(strlen(sysparams_dir) + strlen(name) < sizeof(path));
684 snprintf(path, sizeof(path), "%s%s", sysparams_dir, name);
686 fd = open(path, O_WRONLY);
688 pb_debug("powerpc: can't access sysparam %s for writing\n",
695 rc = write(fd, &val, sizeof(val));
696 if (rc == sizeof(val)) {
701 if (rc <= 0 && errno != EINTR) {
702 pb_log("powerpc: error updating sysparam %s: %s",
703 name, strerror(errno));
712 pb_debug("powerpc: set sysparam %s: 0x%02x\n", name, val);
717 static int clear_ipmi_bootdev_sysparams(
718 struct platform_powerpc *platform __attribute__((unused)),
722 /* invalidate default-boot-device setting */
723 write_bootdev_sysparam("default-boot-device", 0xff);
725 /* invalidate next-boot-device setting */
726 write_bootdev_sysparam("next-boot-device", 0xff);
731 static int get_ipmi_bootdev_sysparams(
732 struct platform_powerpc *platform __attribute__((unused)),
733 uint8_t *bootdev, bool *persistent)
735 uint8_t next_bootdev, default_bootdev;
736 bool next_valid, default_valid;
739 rc = read_bootdev_sysparam("next-boot-device", &next_bootdev);
740 next_valid = rc == 0;
742 rc = read_bootdev_sysparam("default-boot-device", &default_bootdev);
743 default_valid = rc == 0;
745 /* nothing valid? no need to change the config */
746 if (!next_valid && !default_valid)
749 *persistent = !next_valid;
750 *bootdev = next_valid ? next_bootdev : default_bootdev;
754 static int clear_ipmi_bootdev_ipmi(struct platform_powerpc *platform,
755 bool persistent __attribute__((unused)))
760 0x05, /* parameter selector: boot flags */
761 0x80, /* data 1: valid */
762 0x00, /* data 2: bootdev: no override */
763 0x00, /* data 3: system defaults */
764 0x00, /* data 4: no request for shared mode, mux defaults */
765 0x00, /* data 5: no instance request */
768 resp_len = sizeof(resp);
770 ipmi_transaction(platform->ipmi, IPMI_NETFN_CHASSIS,
771 IPMI_CMD_CHASSIS_SET_SYSTEM_BOOT_OPTIONS,
778 static int get_ipmi_bootdev_ipmi(struct platform_powerpc *platform,
779 uint8_t *bootdev, bool *persistent)
785 0x05, /* parameter selector: boot flags */
786 0x00, /* no set selector */
787 0x00, /* no block selector */
790 resp_len = sizeof(resp);
791 rc = ipmi_transaction(platform->ipmi, IPMI_NETFN_CHASSIS,
792 IPMI_CMD_CHASSIS_GET_SYSTEM_BOOT_OPTIONS,
797 pb_log("platform: error reading IPMI boot options\n");
801 if (resp_len != sizeof(resp)) {
802 pb_log("platform: unexpected length (%d) in "
803 "boot options response\n", resp_len);
807 pb_debug("IPMI get_bootdev response:\n");
808 for (int i = 0; i < resp_len; i++)
809 pb_debug("%x ", resp[i]);
813 pb_log("platform: non-zero completion code %d from IPMI req\n",
818 /* check for correct parameter version */
819 if ((resp[1] & 0xf) != 0x1) {
820 pb_log("platform: unexpected version (0x%x) in "
821 "boot options response\n", resp[0]);
825 /* check for valid paramters */
826 if (resp[2] & 0x80) {
827 pb_debug("platform: boot options are invalid/locked\n");
833 /* check for valid flags */
834 if (!(resp[3] & 0x80)) {
835 pb_debug("platform: boot flags are invalid, ignoring\n");
839 *persistent = resp[3] & 0x40;
840 *bootdev = (resp[4] >> 2) & 0x0f;
844 static int set_ipmi_os_boot_sensor(struct platform_powerpc *platform)
850 0x00, /* sensor number: os boot */
851 0xA9, /* operation: set everything */
852 0x00, /* sensor reading: none */
853 0x40, /* assertion mask lsb: set state 6 */
854 0x00, /* assertion mask msb: none */
855 0x00, /* deassertion mask lsb: none */
856 0x00, /* deassertion mask msb: none */
857 0x00, /* event data 1: none */
858 0x00, /* event data 2: none */
859 0x00, /* event data 3: none */
862 sensor_number = get_ipmi_sensor(platform, IPMI_SENSOR_ID_OS_BOOT);
863 if (sensor_number < 0) {
864 pb_log("Couldn't find OS boot sensor in device tree\n");
868 req[0] = sensor_number;
870 resp_len = sizeof(resp);
872 ipmi_transaction(platform->ipmi, IPMI_NETFN_SE,
876 ipmi_timeout); return 0;
881 static void get_ipmi_network_override(struct platform_powerpc *platform,
882 struct config *config)
884 uint16_t min_len = 12, resp_len = 53, version;
885 const uint32_t magic_value = 0x21706221;
886 uint8_t resp[resp_len];
891 0x61, /* parameter selector: OEM section (network) */
892 0x00, /* no set selector */
893 0x00, /* no block selector */
896 rc = ipmi_transaction(platform->ipmi, IPMI_NETFN_CHASSIS,
897 IPMI_CMD_CHASSIS_GET_SYSTEM_BOOT_OPTIONS,
902 pb_debug("IPMI net override resp [%d][%d]:\n", rc, resp_len);
904 for (i = 0; i < resp_len; i++) {
905 pb_debug(" %02x", resp[i]);
906 if (i && (i + 1) % 16 == 0 && i != resp_len - 1)
908 else if (i && (i + 1) % 8 == 0)
915 pb_debug("IPMI network config option unavailable\n");
919 if (resp_len < min_len) {
920 pb_debug("IPMI net response too small\n");
925 pb_log("platform: non-zero completion code %d from IPMI network req\n",
930 /* Check for correct parameter version */
931 if ((resp[1] & 0xf) != 0x1) {
932 pb_log("platform: unexpected version (0x%x) in network override response\n",
937 /* Check that the parameters are valid */
938 if (resp[2] & 0x80) {
939 pb_debug("platform: network override is invalid/locked\n");
943 /* Check for valid parameters in the boot flags section */
944 if (!(resp[3] & 0x80)) {
945 pb_debug("platform: network override valid flag not set\n");
948 /* Read the persistent flag; if it is set we need to save this config */
949 persistent = resp[3] & 0x40;
951 pb_debug("platform: network override is persistent\n");
953 /* Check 4-byte cookie value */
955 memcpy(&cookie, &resp[i], sizeof(cookie));
956 cookie = __be32_to_cpu(cookie);
957 if (cookie != magic_value) {
958 pb_log_fn("Incorrect cookie %x\n", cookie);
963 /* Check 2-byte version number */
964 memcpy(&version, &resp[i], sizeof(version));
965 version = __be16_to_cpu(version);
966 i += sizeof(version);
968 pb_debug("Unexpected version: %u\n", version);
972 /* Interpret the rest of the interface config */
973 rc = parse_ipmi_interface_override(config, &resp[i], resp_len - i);
975 if (!rc && persistent) {
976 /* Write this new config to NVRAM */
977 update_network_config(&platform->params, "petitboot,network",
979 rc = write_nvram(platform);
981 pb_log("platform: Failed to save persistent interface override\n");
985 static void get_active_consoles(struct config *config)
988 char *fsp_prop = NULL;
990 config->n_consoles = 2;
991 config->consoles = talloc_array(config, char *, config->n_consoles);
992 if (!config->consoles)
995 config->consoles[0] = talloc_asprintf(config->consoles,
996 "/dev/hvc0 [IPMI / Serial]");
997 config->consoles[1] = talloc_asprintf(config->consoles,
1000 fsp_prop = talloc_asprintf(config, "%sfsps", devtree_dir);
1001 if (stat(fsp_prop, &sbuf) == 0) {
1002 /* FSP based machines also have a separate serial console */
1003 config->consoles = talloc_realloc(config, config->consoles,
1004 char *, config->n_consoles + 1);
1005 if (!config->consoles)
1007 config->consoles[config->n_consoles++] = talloc_asprintf(
1009 "/dev/hvc1 [Serial]");
1014 config->n_consoles = 0;
1015 pb_log("Failed to allocate memory for consoles\n");
1018 static int load_config(struct platform *p, struct config *config)
1020 struct platform_powerpc *platform = to_platform_powerpc(p);
1023 rc = parse_nvram(platform);
1025 pb_log_fn("Failed to parse nvram\n");
1027 populate_config(config, &platform->params);
1029 if (platform->get_ipmi_bootdev) {
1030 bool bootdev_persistent;
1031 uint8_t bootdev = IPMI_BOOTDEV_INVALID;
1032 rc = platform->get_ipmi_bootdev(platform, &bootdev,
1033 &bootdev_persistent);
1034 if (!rc && ipmi_bootdev_is_valid(bootdev)) {
1035 set_ipmi_bootdev(config, bootdev, bootdev_persistent);
1040 get_ipmi_network_override(platform, config);
1042 get_active_consoles(config);
1047 static int save_config(struct platform *p, struct config *config)
1049 struct platform_powerpc *platform = to_platform_powerpc(p);
1050 struct config *defaults;
1052 if (config->ipmi_bootdev == IPMI_BOOTDEV_INVALID &&
1053 platform->clear_ipmi_bootdev) {
1054 platform->clear_ipmi_bootdev(platform,
1055 config->ipmi_bootdev_persistent);
1056 config->ipmi_bootdev = IPMI_BOOTDEV_NONE;
1057 config->ipmi_bootdev_persistent = false;
1060 defaults = talloc_zero(platform, struct config);
1061 config_set_defaults(defaults);
1063 update_config(&platform->params, config, defaults);
1065 talloc_free(defaults);
1066 return write_nvram(platform);
1069 static void pre_boot(struct platform *p, const struct config *config)
1071 struct platform_powerpc *platform = to_platform_powerpc(p);
1073 if (!config->ipmi_bootdev_persistent && platform->clear_ipmi_bootdev)
1074 platform->clear_ipmi_bootdev(platform, false);
1076 if (platform->set_os_boot_sensor)
1077 platform->set_os_boot_sensor(platform);
1080 static int get_sysinfo(struct platform *p, struct system_info *sysinfo)
1082 struct platform_powerpc *platform = p->platform_data;
1083 char *buf, *filename;
1086 filename = talloc_asprintf(platform, "%smodel", devtree_dir);
1087 rc = read_file(platform, filename, &buf, &len);
1089 sysinfo->type = talloc_steal(sysinfo, buf);
1090 talloc_free(filename);
1092 filename = talloc_asprintf(platform, "%ssystem-id", devtree_dir);
1093 rc = read_file(platform, filename, &buf, &len);
1095 sysinfo->identifier = talloc_steal(sysinfo, buf);
1096 talloc_free(filename);
1098 sysinfo->bmc_mac = talloc_zero_size(sysinfo, HWADDR_SIZE);
1100 if (platform->ipmi) {
1101 ipmi_get_bmc_mac(platform->ipmi, sysinfo->bmc_mac);
1102 ipmi_get_bmc_versions(platform->ipmi, sysinfo);
1105 if (platform->get_platform_versions)
1106 platform->get_platform_versions(sysinfo);
1111 static bool probe(struct platform *p, void *ctx)
1113 struct platform_powerpc *platform;
1114 struct stat statbuf;
1118 /* we need a device tree */
1119 rc = stat("/proc/device-tree", &statbuf);
1123 if (!S_ISDIR(statbuf.st_mode))
1126 platform = talloc_zero(ctx, struct platform_powerpc);
1127 param_list_init(&platform->params, common_known_params());
1129 p->platform_data = platform;
1131 bmc_present = stat("/proc/device-tree/bmc", &statbuf) == 0;
1133 if (ipmi_present() && bmc_present) {
1134 pb_debug("platform: using direct IPMI for IPMI paramters\n");
1135 platform->ipmi = ipmi_open(platform);
1136 platform->get_ipmi_bootdev = get_ipmi_bootdev_ipmi;
1137 platform->clear_ipmi_bootdev = clear_ipmi_bootdev_ipmi;
1138 platform->set_os_boot_sensor = set_ipmi_os_boot_sensor;
1139 } else if (!stat(sysparams_dir, &statbuf)) {
1140 pb_debug("platform: using sysparams for IPMI paramters\n");
1141 platform->get_ipmi_bootdev = get_ipmi_bootdev_sysparams;
1142 platform->clear_ipmi_bootdev = clear_ipmi_bootdev_sysparams;
1145 pb_log("platform: no IPMI parameter support\n");
1149 platform->get_platform_versions = hostboot_load_versions;
1155 static struct platform platform_powerpc = {
1157 .dhcp_arch_id = 0x000e,
1159 .load_config = load_config,
1160 .save_config = save_config,
1161 .pre_boot = pre_boot,
1162 .get_sysinfo = get_sysinfo,
1165 register_platform(platform_powerpc);