]> git.ozlabs.org Git - petitboot/blobdiff - discover/platform-powerpc.c
discover/powerpc: Parse & save default boot device parameter
[petitboot] / discover / platform-powerpc.c
index 28c081d7540332281e972609f935496141905a21..6ed65221c84b1ac14d5a7491e7e948bf7256e7be 100644 (file)
@@ -34,6 +34,7 @@ static const char *known_params[] = {
        "auto-boot?",
        "petitboot,network",
        "petitboot,timeout",
        "auto-boot?",
        "petitboot,network",
        "petitboot,timeout",
+       "petitboot,bootdev",
        NULL,
 };
 
        NULL,
 };
 
@@ -371,6 +372,32 @@ static void populate_network_config(struct platform_powerpc *platform,
        talloc_free(val);
 }
 
        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)
 {
 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_network_config(platform, config);
+
+       populate_bootdev_config(platform, config);
 }
 
 static char *iface_config_str(void *ctx, struct interface_config *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);
 }
 
        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)
 {
 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_network_config(platform, config);
 
+       update_bootdev_config(platform, config);
+
        return write_nvram(platform);
 }
 
        return write_nvram(platform);
 }
 
@@ -692,7 +738,7 @@ static bool probe(struct platform *p, void *ctx)
        struct stat statbuf;
        int rc;
 
        struct stat statbuf;
        int rc;
 
-       /* we need a device tree and a working nvram binary */
+       /* we need a device tree */
        rc = stat("/proc/device-tree", &statbuf);
        if (rc)
                return false;
        rc = stat("/proc/device-tree", &statbuf);
        if (rc)
                return false;
@@ -700,10 +746,6 @@ static bool probe(struct platform *p, void *ctx)
        if (!S_ISDIR(statbuf.st_mode))
                return false;
 
        if (!S_ISDIR(statbuf.st_mode))
                return false;
 
-       rc = process_run_simple(ctx, "nvram", "--print-config", NULL);
-       if (!WIFEXITED(rc) || WEXITSTATUS(rc) != 0)
-               return false;
-
        platform = talloc(ctx, struct platform_powerpc);
        list_init(&platform->params);
 
        platform = talloc(ctx, struct platform_powerpc);
        list_init(&platform->params);