discover/powerpc: Parse & save default boot device parameter
authorJeremy Kerr <jk@ozlabs.org>
Wed, 30 Apr 2014 03:25:42 +0000 (11:25 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Mon, 21 Jul 2014 09:20:09 +0000 (17:20 +0800)
This change implement load & save support for the default boot device
configuration parameter.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/platform-powerpc.c

index a115e34bf38375a45243ec933243559f5317eb4d..6ed65221c84b1ac14d5a7491e7e948bf7256e7be 100644 (file)
@@ -34,6 +34,7 @@ static const char *known_params[] = {
        "auto-boot?",
        "petitboot,network",
        "petitboot,timeout",
+       "petitboot,bootdev",
        NULL,
 };
 
@@ -371,6 +372,32 @@ static void populate_network_config(struct platform_powerpc *platform,
        talloc_free(val);
 }
 
+static void populate_bootdev_config(struct platform_powerpc *platform,
+               struct config *config)
+
+{
+       const char *val;
+
+       config->boot_device = NULL;
+
+       val = get_param(platform, "petitboot,bootdev");
+       if (!val || !strlen(val))
+               return;
+
+       if (!strncmp(val, "uuid:", strlen("uuid:"))) {
+               config->boot_device = talloc_strdup(config,
+                                               val + strlen("uuid:"));
+
+       } else if (!strncmp(val, "mac:", strlen("mac:"))) {
+               config->boot_device = talloc_strdup(config,
+                                               val + strlen("mac:"));
+
+       } else {
+               pb_log("bootdev config is in an unknown format "
+                               "(expected uuid:... or mac:...)");
+       }
+}
+
 static void populate_config(struct platform_powerpc *platform,
                struct config *config)
 {
@@ -394,6 +421,8 @@ static void populate_config(struct platform_powerpc *platform,
        }
 
        populate_network_config(platform, config);
+
+       populate_bootdev_config(platform, config);
 }
 
 static char *iface_config_str(void *ctx, struct interface_config *config)
@@ -481,6 +510,21 @@ static void update_network_config(struct platform_powerpc *platform,
        talloc_free(val);
 }
 
+static void update_bootdev_config(struct platform_powerpc *platform,
+               struct config *config)
+{
+       char *val, *tmp = NULL;
+
+       if (!config->boot_device)
+               val = "";
+       else
+               tmp = val = talloc_asprintf(platform,
+                               "uuid:%s", config->boot_device);
+
+       update_string_config(platform, "petitboot,bootdev", val);
+       talloc_free(tmp);
+}
+
 static int update_config(struct platform_powerpc *platform,
                struct config *config, struct config *defaults)
 {
@@ -505,6 +549,8 @@ static int update_config(struct platform_powerpc *platform,
 
        update_network_config(platform, config);
 
+       update_bootdev_config(platform, config);
+
        return write_nvram(platform);
 }