]> git.ozlabs.org Git - petitboot/blobdiff - discover/yaboot-parser.c
Use yaboot global boot option
[petitboot] / discover / yaboot-parser.c
index c47dee13c00189d0d9e3b71da9f018e78d3b7127..1000505b9681df66da2bfff4e17709d503c0175e 100644 (file)
@@ -15,7 +15,6 @@ struct yaboot_state {
        struct boot_option *opt;
        const char *desc_image;
        char *desc_initrd;
-       int found_suse;
        int globals_done;
        const char *const *known_names;
 };
@@ -24,7 +23,12 @@ static void yaboot_finish(struct conf_context *conf)
 {
        struct yaboot_state *state = conf->parser_info;
 
-       assert(state->desc_image);
+       if (!state->desc_image) {
+               pb_log("%s: %s: no image found\n", __func__,
+                       conf->dc->device->id);
+               return;
+       }
+
        assert(state->opt);
        assert(state->opt->name);
        assert(state->opt->boot_args);
@@ -51,6 +55,19 @@ static void yaboot_process_pair(struct conf_context *conf, const char *name,
                char *value)
 {
        struct yaboot_state *state = conf->parser_info;
+       struct fixed_pair {
+               const char *image;
+               const char *initrd;
+       };
+       static const struct fixed_pair suse_fp32 = {
+               .image = "/suseboot/vmlinux32",
+               .initrd = "/suseboot/initrd32",
+       };
+       static const struct fixed_pair suse_fp64 = {
+               .image = "/suseboot/vmlinux64",
+               .initrd = "/suseboot/initrd64",
+       };
+       const struct fixed_pair *suse_fp;
 
        /* fixup for bare values */
 
@@ -68,32 +85,70 @@ static void yaboot_process_pair(struct conf_context *conf, const char *name,
        /* image */
 
        if (streq(name, "image")) {
+               const char *g_boot = conf_get_global_option(conf, "boot");
+               const char *g_part = conf_get_global_option(conf, "partition");
+
+               /* First finish any previous image. */
+
                if (state->opt->boot_image_file)
                        yaboot_finish(conf);
 
-               state->opt->boot_image_file = resolve_path(state->opt, value,
-                       conf->dc->device_path);
-               state->desc_image = talloc_strdup(state->opt, value);
+               /* Then start the new image. */
+
+               if (g_boot && g_part) {
+                       char* dev = talloc_asprintf(NULL, "%s%s", g_boot,
+                               g_part);
+
+                       state->opt->boot_image_file = resolve_path(state->opt,
+                               value, dev);
+                       state->desc_image = talloc_asprintf(state->opt,
+                               "%s%s", dev, value);
+                       talloc_free(dev);
+               } else if (g_boot) {
+                       state->opt->boot_image_file = resolve_path(state->opt,
+                               value, g_boot);
+                       state->desc_image = talloc_asprintf(state->opt,
+                               "%s%s", g_boot, value);
+               } else {
+                       state->opt->boot_image_file = resolve_path(state->opt,
+                               value, conf->dc->device_path);
+                       state->desc_image = talloc_strdup(state->opt, value);
+               }
+
                return;
        }
 
-       if (streq(name, "image[32bit]") || streq(name, "image[64bit]")) {
-               state->found_suse = 1;
+       /* Special processing for SUSE install CD. */
+
+       if (streq(name, "image[32bit]"))
+               suse_fp = &suse_fp32;
+       else if (streq(name, "image[64bit]"))
+               suse_fp = &suse_fp64;
+       else
+               suse_fp = NULL;
+
+       if (suse_fp) {
+               /* First finish any previous image. */
 
                if (state->opt->boot_image_file)
                        yaboot_finish(conf);
 
+               /* Then start the new image. */
+
                if (*value == '/') {
                        state->opt->boot_image_file = resolve_path(state->opt,
                                value, conf->dc->device_path);
                        state->desc_image = talloc_strdup(state->opt, value);
                } else {
-                       char *s;
-                       asprintf(&s, "/suseboot/%s", value);
                        state->opt->boot_image_file = resolve_path(state->opt,
-                               s, conf->dc->device_path);
-                       state->desc_image = talloc_strdup(state->opt, s);
-                       free(s);
+                               suse_fp->image, conf->dc->device_path);
+                       state->desc_image = talloc_strdup(state->opt,
+                               suse_fp->image);
+
+                       state->opt->initrd_file = resolve_path(state->opt,
+                               suse_fp->initrd, conf->dc->device_path);
+                       state->desc_initrd = talloc_asprintf(state, "initrd=%s",
+                               suse_fp->initrd);
                }
 
                return;
@@ -107,19 +162,28 @@ static void yaboot_process_pair(struct conf_context *conf, const char *name,
        /* initrd */
 
        if (streq(name, "initrd")) {
-               if (!state->found_suse || (*value == '/')) {
+               const char *g_boot = conf_get_global_option(conf, "boot");
+               const char *g_part = conf_get_global_option(conf, "partition");
+
+               if (g_boot && g_part) {
+                       char* dev = talloc_asprintf(NULL, "%s%s", g_boot,
+                               g_part);
+
                        state->opt->initrd_file = resolve_path(state->opt,
-                               value, conf->dc->device_path);
-                       state->desc_initrd = talloc_asprintf(state, "initrd=%s",
-                               value);
+                               value, dev);
+                       state->desc_initrd = talloc_asprintf(state,
+                               "initrd=%s%s", dev, value);
+                       talloc_free(dev);
+               } else if (g_boot) {
+                       state->opt->initrd_file = resolve_path(state->opt,
+                               value, g_boot);
+                       state->desc_initrd = talloc_asprintf(state,
+                               "initrd=%s%s", g_boot, value);
                } else {
-                       char *s;
-                       asprintf(&s, "/suseboot/%s", value);
                        state->opt->initrd_file = resolve_path(state->opt,
-                               s, conf->dc->device_path);
+                               value, conf->dc->device_path);
                        state->desc_initrd = talloc_asprintf(state, "initrd=%s",
-                               s);
-                       free(s);
+                               value);
                }
                return;
        }
@@ -235,6 +299,7 @@ static int yaboot_parse(struct discover_context *dc)
 
        conf->dc = dc;
        conf->global_options = yaboot_global_options,
+       conf_init_global_options(conf);
        conf->conf_files = yaboot_conf_files,
        conf->process_pair = yaboot_process_pair;
        conf->finish = yaboot_finish;