X-Git-Url: https://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fyaboot-parser.c;h=0477d38ee6e7715e00d70c19c2aa4ff19edf3f4d;hp=d58919800ae857d98eda105f3d5a656e89618b7d;hb=39e06f5cfda0ed0c1eeb7a7604a3d05dda81ccf1;hpb=4d1d4bf2f4c97b489472f6d1db95d15a6e09ea3d diff --git a/discover/yaboot-parser.c b/discover/yaboot-parser.c index d589198..0477d38 100644 --- a/discover/yaboot-parser.c +++ b/discover/yaboot-parser.c @@ -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" @@ -22,10 +22,10 @@ struct yaboot_state { static void yaboot_finish(struct conf_context *conf) { struct yaboot_state *state = conf->parser_info; + struct device *dev = conf->dc->device->device; if (!state->desc_image) { - pb_log("%s: %s: no image found\n", __func__, - conf->dc->device->id); + pb_log("%s: %s: no image found\n", __func__, dev->id); return; } @@ -46,8 +46,9 @@ static void yaboot_finish(struct conf_context *conf) /* opt is persistent, so must be associated with device */ - device_add_boot_option(conf->dc->device, state->opt); - state->opt = talloc_zero(conf->dc->device, struct boot_option); + discover_context_add_boot_option(conf->dc, state->opt); + + state->opt = talloc_zero(conf->dc, struct boot_option); state->opt->boot_args = talloc_strdup(state->opt, ""); } @@ -85,6 +86,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 +96,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->device_path); + state->desc_image = talloc_strdup(state->opt, value); + } return; } @@ -119,16 +138,16 @@ static void yaboot_process_pair(struct conf_context *conf, const char *name, if (*value == '/') { state->opt->boot_image_file = resolve_path(state->opt, - value, conf->dc->device_path); + value, conf->dc->device->device_path); state->desc_image = talloc_strdup(state->opt, value); } else { state->opt->boot_image_file = resolve_path(state->opt, - suse_fp->image, conf->dc->device_path); + suse_fp->image, conf->dc->device->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); + suse_fp->initrd, conf->dc->device->device_path); state->desc_initrd = talloc_asprintf(state, "initrd=%s", suse_fp->initrd); } @@ -144,10 +163,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->device_path); + state->desc_initrd = talloc_asprintf(state, "initrd=%s", + value); + } return; } @@ -155,7 +193,7 @@ static void yaboot_process_pair(struct conf_context *conf, const char *name, if (streq(name, "label")) { state->opt->id = talloc_asprintf(state->opt, "%s#%s", - conf->dc->device->id, value); + conf->dc->device->device->id, value); state->opt->name = talloc_strdup(state->opt, value); return; } @@ -258,12 +296,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 +320,8 @@ static int yaboot_parse(struct discover_context *dc) return rc; } -define_parser(yaboot, 99, yaboot_parse); +struct parser __yaboot_parser = { + .name = "yaboot", + .parse = yaboot_parse, + .filenames = yaboot_conf_files, +};