11 #include <asm/byteorder.h>
13 #include <file/file.h>
14 #include <talloc/talloc.h>
15 #include <list/list.h>
17 #include <process/process.h>
18 #include <types/types.h>
26 static const char *partition = "common";
27 static const char *sysparams_dir = "/sys/firmware/opal/sysparams/";
28 static const char *devtree_dir = "/proc/device-tree/";
34 struct list_item list;
37 struct platform_powerpc {
40 bool ipmi_bootdev_persistent;
41 int (*get_ipmi_bootdev)(
42 struct platform_powerpc *platform,
43 uint8_t *bootdev, bool *persistent);
44 int (*clear_ipmi_bootdev)(
45 struct platform_powerpc *platform,
47 int (*set_os_boot_sensor)(
48 struct platform_powerpc *platform);
49 void (*get_platform_versions)(struct system_info *info);
52 static const char *known_params[] = {
60 "petitboot,snapshots?",
62 "petitboot,http_proxy",
63 "petitboot,https_proxy",
67 #define to_platform_powerpc(p) \
68 (struct platform_powerpc *)(p->platform_data)
70 static bool param_is_known(const char *param, unsigned int len)
72 const char *known_param;
75 for (i = 0; known_params[i]; i++) {
76 known_param = known_params[i];
77 if (len == strlen(known_param) &&
78 !strncmp(param, known_param, len))
85 static int parse_nvram_params(struct platform_powerpc *platform,
88 char *pos, *name, *value;
89 unsigned int paramlen;
92 /* discard 2 header lines:
99 for (i = 0; i < len; i++) {
107 fprintf(stderr, "failure parsing nvram output\n");
111 for (pos = buf + i; pos < buf + len; pos += paramlen + 1) {
112 unsigned int namelen;
116 newline = strchr(pos, '\n');
122 paramlen = strlen(pos);
125 value = strchr(pos, '=');
129 namelen = value - name;
133 if (!param_is_known(name, namelen))
138 param = talloc(platform, struct param);
139 param->modified = false;
140 param->name = talloc_strndup(platform, name, namelen);
141 param->value = talloc_strdup(platform, value);
142 list_add(&platform->params, ¶m->list);
148 static int parse_nvram(struct platform_powerpc *platform)
150 struct process_stdout *stdout;
155 argv[1] = "--print-config";
156 argv[2] = "--partition";
160 rc = process_get_stdout_argv(NULL, &stdout, argv);
163 fprintf(stderr, "nvram process returned "
164 "non-zero exit status\n");
167 rc = parse_nvram_params(platform, stdout->buf, stdout->len);
174 static int write_nvram(struct platform_powerpc *platform)
176 struct process *process;
182 argv[1] = "--update-config";
184 argv[3] = "--partition";
188 process = process_create(platform);
189 process->path = "nvram";
190 process->argv = argv;
192 list_for_each_entry(&platform->params, param, list) {
195 if (!param->modified)
198 paramstr = talloc_asprintf(platform, "%s=%s",
199 param->name, param->value);
202 rc = process_run_sync(process);
204 talloc_free(paramstr);
206 if (rc || !process_exit_ok(process)) {
208 pb_log("nvram update process returned "
209 "non-zero exit status\n");
214 process_release(process);
218 static const char *get_param(struct platform_powerpc *platform,
223 list_for_each_entry(&platform->params, param, list)
224 if (!strcmp(param->name, name))
229 static void set_param(struct platform_powerpc *platform, const char *name,
234 list_for_each_entry(&platform->params, param, list) {
235 if (strcmp(param->name, name))
238 if (!strcmp(param->value, value))
241 talloc_free(param->value);
242 param->value = talloc_strdup(param, value);
243 param->modified = true;
248 param = talloc(platform, struct param);
249 param->modified = true;
250 param->name = talloc_strdup(platform, name);
251 param->value = talloc_strdup(platform, value);
252 list_add(&platform->params, ¶m->list);
255 static int parse_hwaddr(struct interface_config *ifconf, char *str)
259 if (strlen(str) != strlen("00:00:00:00:00:00"))
262 for (i = 0; i < HWADDR_SIZE; i++) {
266 byte[0] = str[i * 3 + 0];
267 byte[1] = str[i * 3 + 1];
270 x = strtoul(byte, &endp, 16);
271 if (endp != byte + 2)
274 ifconf->hwaddr[i] = x & 0xff;
280 static int parse_one_interface_config(struct config *config,
283 struct interface_config *ifconf;
284 char *tok, *tok_gw, *tok_url, *saveptr;
286 ifconf = talloc_zero(config, struct interface_config);
288 if (!confstr || !strlen(confstr))
291 /* first token should be the mac address */
292 tok = strtok_r(confstr, ",", &saveptr);
296 if (parse_hwaddr(ifconf, tok))
299 /* second token is the method */
300 tok = strtok_r(NULL, ",", &saveptr);
301 if (!tok || !strlen(tok) || !strcmp(tok, "ignore")) {
302 ifconf->ignore = true;
304 } else if (!strcmp(tok, "dhcp")) {
305 ifconf->method = CONFIG_METHOD_DHCP;
307 } else if (!strcmp(tok, "static")) {
308 ifconf->method = CONFIG_METHOD_STATIC;
310 /* ip/mask, [optional] gateway, [optional] url */
311 tok = strtok_r(NULL, ",", &saveptr);
314 ifconf->static_config.address =
315 talloc_strdup(ifconf, tok);
318 * If a url is set but not a gateway, we can accidentally
319 * interpret the url as the gateway. To avoid changing the
320 * parameter format check if the "gateway" is actually a
321 * pb-url if it's the last token.
323 tok_gw = strtok_r(NULL, ",", &saveptr);
324 tok_url = strtok_r(NULL, ",", &saveptr);
327 if (tok_url || !is_url(tok_gw))
328 ifconf->static_config.gateway =
329 talloc_strdup(ifconf, tok_gw);
335 ifconf->static_config.url =
336 talloc_strdup(ifconf, tok_url);
338 pb_log("Unknown network configuration method %s\n", tok);
342 config->network.interfaces = talloc_realloc(config,
343 config->network.interfaces,
344 struct interface_config *,
345 ++config->network.n_interfaces);
347 config->network.interfaces[config->network.n_interfaces - 1] = ifconf;
355 static int parse_one_dns_config(struct config *config,
358 char *tok, *saveptr = NULL;
360 for (tok = strtok_r(confstr, ",", &saveptr); tok;
361 tok = strtok_r(NULL, ",", &saveptr)) {
363 char *server = talloc_strdup(config, tok);
365 config->network.dns_servers = talloc_realloc(config,
366 config->network.dns_servers, const char *,
367 ++config->network.n_dns_servers);
369 config->network.dns_servers[config->network.n_dns_servers - 1]
376 static void populate_network_config(struct platform_powerpc *platform,
377 struct config *config)
379 char *val, *saveptr = NULL;
383 cval = get_param(platform, "petitboot,network");
384 if (!cval || !strlen(cval))
387 val = talloc_strdup(config, cval);
392 tok = strtok_r(i == 0 ? val : NULL, " ", &saveptr);
396 if (!strncasecmp(tok, "dns,", strlen("dns,")))
397 parse_one_dns_config(config, tok + strlen("dns,"));
399 parse_one_interface_config(config, tok);
406 static int read_bootdev(void *ctx, char **pos, struct autoboot_option *opt)
408 char *delim = strchr(*pos, ' ');
409 int len, prefix = 0, rc = -1;
410 enum device_type type;
412 if (!strncmp(*pos, "uuid:", strlen("uuid:"))) {
413 prefix = strlen("uuid:");
414 opt->boot_type = BOOT_DEVICE_UUID;
415 } else if (!strncmp(*pos, "mac:", strlen("mac:"))) {
416 prefix = strlen("mac:");
417 opt->boot_type = BOOT_DEVICE_UUID;
419 type = find_device_type(*pos);
420 if (type != DEVICE_TYPE_UNKNOWN) {
422 opt->boot_type = BOOT_DEVICE_TYPE;
427 if (opt->boot_type == BOOT_DEVICE_UUID) {
429 len = (int)(delim - *pos) - prefix;
431 len = strlen(*pos) - prefix;
434 opt->uuid = talloc_strndup(ctx, *pos + prefix, len);
439 /* Always advance pointer to next option or end */
443 *pos += strlen(*pos);
448 static void populate_bootdev_config(struct platform_powerpc *platform,
449 struct config *config)
451 struct autoboot_option *opt, *new = NULL;
453 unsigned int n_new = 0;
456 /* Check for ordered bootdevs */
457 val = get_param(platform, "petitboot,bootdevs");
458 if (!val || !strlen(val)) {
461 pos = talloc_strdup(config, val);
462 end = strchr(pos, '\0');
465 while (pos && pos < end) {
466 opt = talloc(config, struct autoboot_option);
468 if (read_bootdev(config, &pos, opt)) {
469 pb_log("bootdev config is in an unknown format "
470 "(expected uuid:... or mac:...)\n");
475 new = talloc_realloc(config, new, struct autoboot_option,
484 /* If autoboot has been disabled, clear the default options */
485 if (!config->autoboot_enabled) {
486 talloc_free(config->autoboot_opts);
487 config->n_autoboot_opts = 0;
492 talloc_free(config->autoboot_opts);
493 config->autoboot_opts = new;
494 config->n_autoboot_opts = n_new;
497 static void populate_config(struct platform_powerpc *platform,
498 struct config *config)
502 unsigned long timeout;
504 /* if the "auto-boot?' property is present and "false", disable auto
506 val = get_param(platform, "auto-boot?");
507 config->autoboot_enabled = !val || strcmp(val, "false");
509 val = get_param(platform, "petitboot,timeout");
511 timeout = strtoul(val, &end, 10);
513 if (timeout >= INT_MAX)
515 config->autoboot_timeout_sec = (int)timeout;
519 val = get_param(platform, "petitboot,language");
520 config->lang = val ? talloc_strdup(config, val) : NULL;
522 populate_network_config(platform, config);
524 populate_bootdev_config(platform, config);
526 if (!config->debug) {
527 val = get_param(platform, "petitboot,debug?");
528 config->debug = val && !strcmp(val, "true");
531 val = get_param(platform, "petitboot,write?");
533 config->allow_writes = !strcmp(val, "true");
535 val = get_param(platform, "petitboot,snapshots?");
537 config->disable_snapshots = !strcmp(val, "false");
539 val = get_param(platform, "petitboot,console");
541 config->boot_console = talloc_strdup(config, val);
542 /* If a full path is already set we don't want to override it */
543 config->manual_console = config->boot_console &&
544 !strchr(config->boot_console, '[');
546 val = get_param(platform, "petitboot,http_proxy");
548 config->http_proxy = talloc_strdup(config, val);
549 val = get_param(platform, "petitboot,https_proxy");
551 config->https_proxy = talloc_strdup(config, val);
554 static char *iface_config_str(void *ctx, struct interface_config *config)
558 /* todo: HWADDR size is hardcoded as 6, but we may need to handle
559 * different hardware address formats */
560 str = talloc_asprintf(ctx, "%02x:%02x:%02x:%02x:%02x:%02x,",
561 config->hwaddr[0], config->hwaddr[1],
562 config->hwaddr[2], config->hwaddr[3],
563 config->hwaddr[4], config->hwaddr[5]);
565 if (config->ignore) {
566 str = talloc_asprintf_append(str, "ignore");
568 } else if (config->method == CONFIG_METHOD_DHCP) {
569 str = talloc_asprintf_append(str, "dhcp");
571 } else if (config->method == CONFIG_METHOD_STATIC) {
572 str = talloc_asprintf_append(str, "static,%s%s%s%s%s",
573 config->static_config.address,
574 config->static_config.gateway ? "," : "",
575 config->static_config.gateway ?: "",
576 config->static_config.url ? "," : "",
577 config->static_config.url ?: "");
582 static char *dns_config_str(void *ctx, const char **dns_servers, int n)
587 str = talloc_strdup(ctx, "dns,");
588 for (i = 0; i < n; i++) {
589 str = talloc_asprintf_append(str, "%s%s",
597 static void update_string_config(struct platform_powerpc *platform,
598 const char *name, const char *value)
602 cur = get_param(platform, name);
604 /* don't set an empty parameter if it doesn't already exist */
605 if (!cur && !strlen(value))
608 set_param(platform, name, value);
611 static void update_network_config(struct platform_powerpc *platform,
612 struct config *config)
618 * Don't store IPMI overrides to NVRAM. If this was a persistent
619 * override it was already stored in NVRAM by
620 * get_ipmi_network_override()
622 if (config->network.n_interfaces &&
623 config->network.interfaces[0]->override)
626 val = talloc_strdup(platform, "");
628 for (i = 0; i < config->network.n_interfaces; i++) {
629 char *iface_str = iface_config_str(platform,
630 config->network.interfaces[i]);
631 val = talloc_asprintf_append(val, "%s%s",
632 *val == '\0' ? "" : " ", iface_str);
633 talloc_free(iface_str);
636 if (config->network.n_dns_servers) {
637 char *dns_str = dns_config_str(platform,
638 config->network.dns_servers,
639 config->network.n_dns_servers);
640 val = talloc_asprintf_append(val, "%s%s",
641 *val == '\0' ? "" : " ", dns_str);
642 talloc_free(dns_str);
645 update_string_config(platform, "petitboot,network", val);
650 static void update_bootdev_config(struct platform_powerpc *platform,
651 struct config *config)
653 char *val = NULL, *boot_str = NULL, *tmp = NULL;
654 struct autoboot_option *opt;
655 const char delim = ' ';
658 if (!config->n_autoboot_opts)
661 for (i = 0; i < config->n_autoboot_opts; i++) {
662 opt = &config->autoboot_opts[i];
663 switch (opt->boot_type) {
664 case BOOT_DEVICE_TYPE:
665 boot_str = talloc_asprintf(config, "%s%c",
666 device_type_name(opt->type),
669 case BOOT_DEVICE_UUID:
670 boot_str = talloc_asprintf(config, "uuid:%s%c",
674 tmp = val = talloc_asprintf_append(val, "%s", boot_str);
677 update_string_config(platform, "petitboot,bootdevs", val);
680 talloc_free(boot_str);
683 static void update_config(struct platform_powerpc *platform,
684 struct config *config, struct config *defaults)
689 if (config->autoboot_enabled == defaults->autoboot_enabled)
692 val = config->autoboot_enabled ? "true" : "false";
693 update_string_config(platform, "auto-boot?", val);
695 if (config->autoboot_timeout_sec == defaults->autoboot_timeout_sec)
698 val = tmp = talloc_asprintf(platform, "%d",
699 config->autoboot_timeout_sec);
701 update_string_config(platform, "petitboot,timeout", val);
705 val = config->lang ?: "";
706 update_string_config(platform, "petitboot,language", val);
708 if (config->allow_writes == defaults->allow_writes)
711 val = config->allow_writes ? "true" : "false";
712 update_string_config(platform, "petitboot,write?", val);
714 if (!config->manual_console) {
715 val = config->boot_console ?: "";
716 update_string_config(platform, "petitboot,console", val);
719 val = config->http_proxy ?: "";
720 update_string_config(platform, "petitboot,http_proxy", val);
721 val = config->https_proxy ?: "";
722 update_string_config(platform, "petitboot,https_proxy", val);
724 update_network_config(platform, config);
726 update_bootdev_config(platform, config);
729 static void set_ipmi_bootdev(struct config *config, enum ipmi_bootdev bootdev,
732 config->ipmi_bootdev = bootdev;
733 config->ipmi_bootdev_persistent = persistent;
735 if (bootdev == IPMI_BOOTDEV_SAFE)
736 config->safe_mode = true;
739 static int read_bootdev_sysparam(const char *name, uint8_t *val)
745 assert(strlen(sysparams_dir) + strlen(name) < sizeof(path));
746 snprintf(path, sizeof(path), "%s%s", sysparams_dir, name);
748 fd = open(path, O_RDONLY);
750 pb_debug("powerpc: can't access sysparam %s\n",
755 rc = read(fd, buf, sizeof(buf));
759 /* bootdev definitions should only be one byte in size */
761 pb_debug("powerpc: sysparam %s read returned %d\n",
766 pb_debug("powerpc: sysparam %s: 0x%02x\n", name, buf[0]);
768 if (!ipmi_bootdev_is_valid(buf[0]))
775 static int write_bootdev_sysparam(const char *name, uint8_t val)
780 assert(strlen(sysparams_dir) + strlen(name) < sizeof(path));
781 snprintf(path, sizeof(path), "%s%s", sysparams_dir, name);
783 fd = open(path, O_WRONLY);
785 pb_debug("powerpc: can't access sysparam %s for writing\n",
792 rc = write(fd, &val, sizeof(val));
793 if (rc == sizeof(val)) {
798 if (rc <= 0 && errno != EINTR) {
799 pb_log("powerpc: error updating sysparam %s: %s",
800 name, strerror(errno));
809 pb_debug("powerpc: set sysparam %s: 0x%02x\n", name, val);
814 static int clear_ipmi_bootdev_sysparams(
815 struct platform_powerpc *platform __attribute__((unused)),
819 /* invalidate default-boot-device setting */
820 write_bootdev_sysparam("default-boot-device", 0xff);
822 /* invalidate next-boot-device setting */
823 write_bootdev_sysparam("next-boot-device", 0xff);
828 static int get_ipmi_bootdev_sysparams(
829 struct platform_powerpc *platform __attribute__((unused)),
830 uint8_t *bootdev, bool *persistent)
832 uint8_t next_bootdev, default_bootdev;
833 bool next_valid, default_valid;
836 rc = read_bootdev_sysparam("next-boot-device", &next_bootdev);
837 next_valid = rc == 0;
839 rc = read_bootdev_sysparam("default-boot-device", &default_bootdev);
840 default_valid = rc == 0;
842 /* nothing valid? no need to change the config */
843 if (!next_valid && !default_valid)
846 *persistent = !next_valid;
847 *bootdev = next_valid ? next_bootdev : default_bootdev;
851 static int clear_ipmi_bootdev_ipmi(struct platform_powerpc *platform,
852 bool persistent __attribute__((unused)))
857 0x05, /* parameter selector: boot flags */
858 0x80, /* data 1: valid */
859 0x00, /* data 2: bootdev: no override */
860 0x00, /* data 3: system defaults */
861 0x00, /* data 4: no request for shared mode, mux defaults */
862 0x00, /* data 5: no instance request */
865 resp_len = sizeof(resp);
867 ipmi_transaction(platform->ipmi, IPMI_NETFN_CHASSIS,
868 IPMI_CMD_CHASSIS_SET_SYSTEM_BOOT_OPTIONS,
875 static int get_ipmi_bootdev_ipmi(struct platform_powerpc *platform,
876 uint8_t *bootdev, bool *persistent)
882 0x05, /* parameter selector: boot flags */
883 0x00, /* no set selector */
884 0x00, /* no block selector */
887 resp_len = sizeof(resp);
888 rc = ipmi_transaction(platform->ipmi, IPMI_NETFN_CHASSIS,
889 IPMI_CMD_CHASSIS_GET_SYSTEM_BOOT_OPTIONS,
894 pb_log("platform: error reading IPMI boot options\n");
898 if (resp_len != sizeof(resp)) {
899 pb_log("platform: unexpected length (%d) in "
900 "boot options response\n", resp_len);
904 pb_debug("IPMI get_bootdev response:\n");
905 for (int i = 0; i < resp_len; i++)
906 pb_debug("%x ", resp[i]);
910 pb_log("platform: non-zero completion code %d from IPMI req\n",
915 /* check for correct parameter version */
916 if ((resp[1] & 0xf) != 0x1) {
917 pb_log("platform: unexpected version (0x%x) in "
918 "boot options response\n", resp[0]);
922 /* check for valid paramters */
923 if (resp[2] & 0x80) {
924 pb_debug("platform: boot options are invalid/locked\n");
930 /* check for valid flags */
931 if (!(resp[3] & 0x80)) {
932 pb_debug("platform: boot flags are invalid, ignoring\n");
936 *persistent = resp[3] & 0x40;
937 *bootdev = (resp[4] >> 2) & 0x0f;
941 static int set_ipmi_os_boot_sensor(struct platform_powerpc *platform)
947 0x00, /* sensor number: os boot */
948 0xA9, /* operation: set everything */
949 0x00, /* sensor reading: none */
950 0x40, /* assertion mask lsb: set state 6 */
951 0x00, /* assertion mask msb: none */
952 0x00, /* deassertion mask lsb: none */
953 0x00, /* deassertion mask msb: none */
954 0x00, /* event data 1: none */
955 0x00, /* event data 2: none */
956 0x00, /* event data 3: none */
959 sensor_number = get_ipmi_sensor(platform, IPMI_SENSOR_ID_OS_BOOT);
960 if (sensor_number < 0) {
961 pb_log("Couldn't find OS boot sensor in device tree\n");
965 req[0] = sensor_number;
967 resp_len = sizeof(resp);
969 ipmi_transaction(platform->ipmi, IPMI_NETFN_SE,
973 ipmi_timeout); return 0;
978 static void get_ipmi_network_override(struct platform_powerpc *platform,
979 struct config *config)
981 uint16_t min_len = 12, resp_len = 53, version;
982 const uint32_t magic_value = 0x21706221;
983 uint8_t resp[resp_len];
988 0x61, /* parameter selector: OEM section (network) */
989 0x00, /* no set selector */
990 0x00, /* no block selector */
993 rc = ipmi_transaction(platform->ipmi, IPMI_NETFN_CHASSIS,
994 IPMI_CMD_CHASSIS_GET_SYSTEM_BOOT_OPTIONS,
999 pb_debug("IPMI net override resp [%d][%d]:\n", rc, resp_len);
1001 for (i = 0; i < resp_len; i++) {
1002 pb_debug(" %02x", resp[i]);
1003 if (i && (i + 1) % 16 == 0 && i != resp_len - 1)
1005 else if (i && (i + 1) % 8 == 0)
1012 pb_debug("IPMI network config option unavailable\n");
1016 if (resp_len < min_len) {
1017 pb_debug("IPMI net response too small\n");
1022 pb_log("platform: non-zero completion code %d from IPMI network req\n",
1027 /* Check for correct parameter version */
1028 if ((resp[1] & 0xf) != 0x1) {
1029 pb_log("platform: unexpected version (0x%x) in network override response\n",
1034 /* Check that the parameters are valid */
1035 if (resp[2] & 0x80) {
1036 pb_debug("platform: network override is invalid/locked\n");
1040 /* Check for valid parameters in the boot flags section */
1041 if (!(resp[3] & 0x80)) {
1042 pb_debug("platform: network override valid flag not set\n");
1045 /* Read the persistent flag; if it is set we need to save this config */
1046 persistent = resp[3] & 0x40;
1048 pb_debug("platform: network override is persistent\n");
1050 /* Check 4-byte cookie value */
1052 memcpy(&cookie, &resp[i], sizeof(cookie));
1053 cookie = __be32_to_cpu(cookie);
1054 if (cookie != magic_value) {
1055 pb_log_fn("Incorrect cookie %x\n", cookie);
1058 i += sizeof(cookie);
1060 /* Check 2-byte version number */
1061 memcpy(&version, &resp[i], sizeof(version));
1062 version = __be16_to_cpu(version);
1063 i += sizeof(version);
1065 pb_debug("Unexpected version: %u\n", version);
1069 /* Interpret the rest of the interface config */
1070 rc = parse_ipmi_interface_override(config, &resp[i], resp_len - i);
1072 if (!rc && persistent) {
1073 /* Write this new config to NVRAM */
1074 update_network_config(platform, config);
1075 rc = write_nvram(platform);
1077 pb_log("platform: Failed to save persistent interface override\n");
1081 static void get_active_consoles(struct config *config)
1084 char *fsp_prop = NULL;
1086 config->n_consoles = 2;
1087 config->consoles = talloc_array(config, char *, config->n_consoles);
1088 if (!config->consoles)
1091 config->consoles[0] = talloc_asprintf(config->consoles,
1092 "/dev/hvc0 [IPMI / Serial]");
1093 config->consoles[1] = talloc_asprintf(config->consoles,
1096 fsp_prop = talloc_asprintf(config, "%sfsps", devtree_dir);
1097 if (stat(fsp_prop, &sbuf) == 0) {
1098 /* FSP based machines also have a separate serial console */
1099 config->consoles = talloc_realloc(config, config->consoles,
1100 char *, config->n_consoles + 1);
1101 if (!config->consoles)
1103 config->consoles[config->n_consoles++] = talloc_asprintf(
1105 "/dev/hvc1 [Serial]");
1110 config->n_consoles = 0;
1111 pb_log("Failed to allocate memory for consoles\n");
1114 static int load_config(struct platform *p, struct config *config)
1116 struct platform_powerpc *platform = to_platform_powerpc(p);
1119 rc = parse_nvram(platform);
1121 pb_log_fn("Failed to parse nvram\n");
1123 populate_config(platform, config);
1125 if (platform->get_ipmi_bootdev) {
1126 bool bootdev_persistent;
1127 uint8_t bootdev = IPMI_BOOTDEV_INVALID;
1128 rc = platform->get_ipmi_bootdev(platform, &bootdev,
1129 &bootdev_persistent);
1130 if (!rc && ipmi_bootdev_is_valid(bootdev)) {
1131 set_ipmi_bootdev(config, bootdev, bootdev_persistent);
1136 get_ipmi_network_override(platform, config);
1138 get_active_consoles(config);
1143 static int save_config(struct platform *p, struct config *config)
1145 struct platform_powerpc *platform = to_platform_powerpc(p);
1146 struct config *defaults;
1148 if (config->ipmi_bootdev == IPMI_BOOTDEV_INVALID &&
1149 platform->clear_ipmi_bootdev) {
1150 platform->clear_ipmi_bootdev(platform,
1151 config->ipmi_bootdev_persistent);
1152 config->ipmi_bootdev = IPMI_BOOTDEV_NONE;
1153 config->ipmi_bootdev_persistent = false;
1156 defaults = talloc_zero(platform, struct config);
1157 config_set_defaults(defaults);
1159 update_config(platform, config, defaults);
1161 talloc_free(defaults);
1162 return write_nvram(platform);
1165 static void pre_boot(struct platform *p, const struct config *config)
1167 struct platform_powerpc *platform = to_platform_powerpc(p);
1169 if (!config->ipmi_bootdev_persistent && platform->clear_ipmi_bootdev)
1170 platform->clear_ipmi_bootdev(platform, false);
1172 if (platform->set_os_boot_sensor)
1173 platform->set_os_boot_sensor(platform);
1176 static int get_sysinfo(struct platform *p, struct system_info *sysinfo)
1178 struct platform_powerpc *platform = p->platform_data;
1179 char *buf, *filename;
1182 filename = talloc_asprintf(platform, "%smodel", devtree_dir);
1183 rc = read_file(platform, filename, &buf, &len);
1185 sysinfo->type = talloc_steal(sysinfo, buf);
1186 talloc_free(filename);
1188 filename = talloc_asprintf(platform, "%ssystem-id", devtree_dir);
1189 rc = read_file(platform, filename, &buf, &len);
1191 sysinfo->identifier = talloc_steal(sysinfo, buf);
1192 talloc_free(filename);
1194 sysinfo->bmc_mac = talloc_zero_size(sysinfo, HWADDR_SIZE);
1196 if (platform->ipmi) {
1197 ipmi_get_bmc_mac(platform->ipmi, sysinfo->bmc_mac);
1198 ipmi_get_bmc_versions(platform->ipmi, sysinfo);
1201 if (platform->get_platform_versions)
1202 platform->get_platform_versions(sysinfo);
1207 static bool probe(struct platform *p, void *ctx)
1209 struct platform_powerpc *platform;
1210 struct stat statbuf;
1214 /* we need a device tree */
1215 rc = stat("/proc/device-tree", &statbuf);
1219 if (!S_ISDIR(statbuf.st_mode))
1222 platform = talloc_zero(ctx, struct platform_powerpc);
1223 list_init(&platform->params);
1225 p->platform_data = platform;
1227 bmc_present = stat("/proc/device-tree/bmc", &statbuf) == 0;
1229 if (ipmi_present() && bmc_present) {
1230 pb_debug("platform: using direct IPMI for IPMI paramters\n");
1231 platform->ipmi = ipmi_open(platform);
1232 platform->get_ipmi_bootdev = get_ipmi_bootdev_ipmi;
1233 platform->clear_ipmi_bootdev = clear_ipmi_bootdev_ipmi;
1234 platform->set_os_boot_sensor = set_ipmi_os_boot_sensor;
1235 } else if (!stat(sysparams_dir, &statbuf)) {
1236 pb_debug("platform: using sysparams for IPMI paramters\n");
1237 platform->get_ipmi_bootdev = get_ipmi_bootdev_sysparams;
1238 platform->clear_ipmi_bootdev = clear_ipmi_bootdev_sysparams;
1241 pb_log("platform: no IPMI parameter support\n");
1245 platform->get_platform_versions = hostboot_load_versions;
1251 static struct platform platform_powerpc = {
1253 .dhcp_arch_id = 0x000e,
1255 .load_config = load_config,
1256 .save_config = save_config,
1257 .pre_boot = pre_boot,
1258 .get_sysinfo = get_sysinfo,
1261 register_platform(platform_powerpc);