]> git.ozlabs.org Git - petitboot/blobdiff - discover/yaboot-parser.c
protocol: Separate device add from boot-option add messages
[petitboot] / discover / yaboot-parser.c
index d58919800ae857d98eda105f3d5a656e89618b7d..59e52b82ac9f0315de5ee62118a063b9da59169d 100644 (file)
@@ -6,7 +6,7 @@
 
 #include "log/log.h"
 #include "talloc/talloc.h"
-#include "pb-protocol/pb-protocol.h"
+#include "types/types.h"
 #include "parser-conf.h"
 #include "parser-utils.h"
 #include "paths.h"
@@ -85,6 +85,8 @@ 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. */
 
@@ -93,9 +95,25 @@ static void yaboot_process_pair(struct conf_context *conf, const char *name,
 
                /* Then start the new image. */
 
-               state->opt->boot_image_file = resolve_path(state->opt, value,
-                       conf->dc->device_path);
-               state->desc_image = talloc_strdup(state->opt, value);
+               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;
        }
@@ -144,10 +162,29 @@ static void yaboot_process_pair(struct conf_context *conf, const char *name,
        /* initrd */
 
        if (streq(name, "initrd")) {
-               state->opt->initrd_file = resolve_path(state->opt,
-                       value, conf->dc->device_path);
-               state->desc_initrd = talloc_asprintf(state, "initrd=%s",
-                       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, 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 {
+                       state->opt->initrd_file = resolve_path(state->opt,
+                               value, conf->dc->device_path);
+                       state->desc_initrd = talloc_asprintf(state, "initrd=%s",
+                               value);
+               }
                return;
        }
 
@@ -258,12 +295,13 @@ static int yaboot_parse(struct discover_context *dc)
        conf = talloc_zero(dc, struct conf_context);
 
        if (!conf)
-               return -1;
+               return 0;
 
        conf->dc = dc;
        conf->global_options = yaboot_global_options,
        conf_init_global_options(conf);
        conf->conf_files = yaboot_conf_files,
+       conf->get_pair = conf_get_pair_equal;
        conf->process_pair = yaboot_process_pair;
        conf->finish = yaboot_finish;
        conf->parser_info = state = talloc_zero(conf, struct yaboot_state);
@@ -281,4 +319,4 @@ static int yaboot_parse(struct discover_context *dc)
        return rc;
 }
 
-define_parser(yaboot, 99, yaboot_parse);
+define_parser(yaboot, yaboot_parse);