X-Git-Url: https://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fyaboot-parser.c;h=0477d38ee6e7715e00d70c19c2aa4ff19edf3f4d;hp=d9f2aff5924f6e250074722c97dff0deaa3a66de;hb=39e06f5cfda0ed0c1eeb7a7604a3d05dda81ccf1;hpb=0216e1b8a561fed90f0da9d7a67954d5d67458e5 diff --git a/discover/yaboot-parser.c b/discover/yaboot-parser.c index d9f2aff..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" @@ -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; }; @@ -23,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; } @@ -47,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, ""); } @@ -56,6 +56,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 */ @@ -73,32 +86,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->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); + value, conf->dc->device->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->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->device_path); + state->desc_initrd = talloc_asprintf(state, "initrd=%s", + suse_fp->initrd); } return; @@ -112,19 +163,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->device_path); state->desc_initrd = talloc_asprintf(state, "initrd=%s", - s); - free(s); + value); } return; } @@ -133,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; } @@ -236,11 +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); @@ -258,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, +};