]> git.ozlabs.org Git - petitboot/blobdiff - discover/platform-powerpc.c
ui/ncurses: Add nc_widget_subset
[petitboot] / discover / platform-powerpc.c
index 395f1349312e8deeeea240eecfa876515d0c16f1..895f0ecd73cc54ccea2420c037b26124f9a68076 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "platform.h"
 #include "ipmi.h"
+#include "dt.h"
 
 static const char *partition = "common";
 static const char *sysparams_dir = "/sys/firmware/opal/sysparams/";
@@ -39,6 +40,8 @@ struct platform_powerpc {
                                uint8_t *bootdev, bool *persistent);
        int             (*clear_ipmi_bootdev)(
                                struct platform_powerpc *platform);
+       int             (*set_os_boot_sensor)(
+                               struct platform_powerpc *platform);
 };
 
 static const char *known_params[] = {
@@ -337,7 +340,7 @@ out_err:
 static int parse_one_dns_config(struct config *config,
                char *confstr)
 {
-       char *tok, *saveptr;
+       char *tok, *saveptr = NULL;
 
        for (tok = strtok_r(confstr, ",", &saveptr); tok;
                        tok = strtok_r(NULL, ",", &saveptr)) {
@@ -385,6 +388,47 @@ static void populate_network_config(struct platform_powerpc *platform,
        talloc_free(val);
 }
 
+static int read_bootdev(void *ctx, char **pos, struct autoboot_option *opt)
+{
+       char *delim = strchr(*pos, ' ');
+       int len, prefix = 0, rc = -1;
+       enum device_type type;
+
+       if (!strncmp(*pos, "uuid:", strlen("uuid:"))) {
+               prefix = strlen("uuid:");
+               opt->boot_type = BOOT_DEVICE_UUID;
+               rc = 0;
+       } else if (!strncmp(*pos, "mac:", strlen("mac:"))) {
+               prefix = strlen("mac:");
+               opt->boot_type = BOOT_DEVICE_UUID;
+               rc = 0;
+       } else {
+               type = find_device_type(*pos);
+               if (type != DEVICE_TYPE_UNKNOWN) {
+                       opt->type = type;
+                       opt->boot_type = BOOT_DEVICE_TYPE;
+                       rc = 0;
+               }
+       }
+
+       if (opt->boot_type == BOOT_DEVICE_UUID) {
+               if (delim)
+                       len = (int)(delim - *pos) - prefix;
+               else
+                       len = strlen(*pos);
+
+               opt->uuid = talloc_strndup(ctx, *pos + prefix, len);
+       }
+
+       /* Always advance pointer to next option or end */
+       if (delim)
+               *pos = delim + 1;
+       else
+               *pos += strlen(*pos);
+
+       return rc;
+}
+
 static void populate_bootdev_config(struct platform_powerpc *platform,
                struct config *config)
 
@@ -792,6 +836,42 @@ static int get_ipmi_bootdev_ipmi(struct platform_powerpc *platform,
        return 0;
 }
 
+static int set_ipmi_os_boot_sensor(struct platform_powerpc *platform)
+{
+       int sensor_number;
+       uint16_t resp_len;
+       uint8_t resp[1];
+       uint8_t req[] = {
+               0x00, /* sensor number: os boot */
+               0xA9, /* operation: set everything */
+               0x00, /* sensor reading: none */
+               0x40, /* assertion mask lsb: set state 6 */
+               0x00, /* assertion mask msb: none */
+               0x00, /* deassertion mask lsb: none */
+               0x00, /* deassertion mask msb: none */
+               0x00, /* event data 1: none */
+               0x00, /* event data 2: none */
+               0x00, /* event data 3: none */
+       };
+
+       sensor_number = get_ipmi_sensor(platform, IPMI_SENSOR_ID_OS_BOOT);
+       if (sensor_number < 0) {
+               pb_log("Couldn't find OS boot sensor in device tree\n");
+               return -1;
+       }
+
+       req[0] = sensor_number;
+
+       resp_len = sizeof(resp);
+
+       ipmi_transaction(platform->ipmi, IPMI_NETFN_SE,
+                       IPMI_CMD_SENSOR_SET,
+                       req, sizeof(req),
+                       resp, &resp_len,
+                       ipmi_timeout); return 0;
+
+       return 0;
+}
 
 static int load_config(struct platform *p, struct config *config)
 {
@@ -838,6 +918,9 @@ static void pre_boot(struct platform *p, const struct config *config)
 
        if (!config->ipmi_bootdev_persistent && platform->clear_ipmi_bootdev)
                platform->clear_ipmi_bootdev(platform);
+
+       if (platform->set_os_boot_sensor)
+               platform->set_os_boot_sensor(platform);
 }
 
 static int get_sysinfo(struct platform *p, struct system_info *sysinfo)
@@ -875,7 +958,7 @@ static bool probe(struct platform *p, void *ctx)
        if (!S_ISDIR(statbuf.st_mode))
                return false;
 
-       platform = talloc(ctx, struct platform_powerpc);
+       platform = talloc_zero(ctx, struct platform_powerpc);
        list_init(&platform->params);
 
        p->platform_data = platform;
@@ -885,6 +968,7 @@ static bool probe(struct platform *p, void *ctx)
                platform->ipmi = ipmi_open(platform);
                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");