X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fyaboot-parser.c;h=0a66e8d588241d69b66a9fc3d1119edce7f3c38a;hp=d7a0a9f80744ef9e533b705637b1b98f87a86b24;hb=5be946c;hpb=06a49ebdfc795a70b938f5aee29f3c488ef9fc21 diff --git a/discover/yaboot-parser.c b/discover/yaboot-parser.c index d7a0a9f..0a66e8d 100644 --- a/discover/yaboot-parser.c +++ b/discover/yaboot-parser.c @@ -9,11 +9,11 @@ #include "types/types.h" #include "parser-conf.h" #include "parser-utils.h" -#include "paths.h" +#include "resource.h" struct yaboot_state { - struct boot_option *opt; - const char *desc_image; + struct discover_boot_option *opt; + char *desc_image; char *desc_initrd; int globals_done; const char *const *known_names; @@ -23,6 +23,7 @@ static void yaboot_finish(struct conf_context *conf) { struct yaboot_state *state = conf->parser_info; struct device *dev = conf->dc->device->device; + struct boot_option *opt; if (!state->desc_image) { pb_log("%s: %s: no image found\n", __func__, dev->id); @@ -30,32 +31,65 @@ static void yaboot_finish(struct conf_context *conf) } assert(state->opt); - assert(state->opt->name); - assert(state->opt->boot_args); - state->opt->description = talloc_asprintf(state->opt, "%s %s %s", + opt = state->opt->option; + assert(opt); + assert(opt->name); + assert(opt->boot_args); + + opt->description = talloc_asprintf(opt, "%s %s %s", state->desc_image, (state->desc_initrd ? state->desc_initrd : ""), - state->opt->boot_args); + opt->boot_args); talloc_free(state->desc_initrd); state->desc_initrd = NULL; - conf_strip_str(state->opt->boot_args); - conf_strip_str(state->opt->description); + conf_strip_str(opt->boot_args); + conf_strip_str(opt->description); /* opt is persistent, so must be associated with device */ 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, ""); + state->opt = discover_boot_option_create(conf->dc, conf->dc->device); + state->opt->option->boot_args = talloc_strdup(state->opt->option, ""); +} + +static struct resource *create_yaboot_devpath_resource( + struct conf_context *conf, + const char *path, char **desc_str) +{ + const char *g_boot = conf_get_global_option(conf, "boot"); + const char *g_part = conf_get_global_option(conf, "partition"); + struct resource *res; + char *devpath; + + if (g_boot && g_part) { + devpath = talloc_asprintf(conf, + "%s%s:%s", g_boot, g_part, path); + } else if (g_boot) { + devpath = talloc_asprintf(conf, "%s:%s", g_boot, path); + } else { + devpath = talloc_strdup(conf, path); + } + + res = create_devpath_resource(conf->dc, conf->dc->device, devpath); + + if (desc_str) + *desc_str = devpath; + else + talloc_free(devpath); + + return res; } + static void yaboot_process_pair(struct conf_context *conf, const char *name, char *value) { struct yaboot_state *state = conf->parser_info; + struct discover_boot_option *opt = state->opt; struct fixed_pair { const char *image; const char *initrd; @@ -86,35 +120,14 @@ 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) + if (opt->boot_image) yaboot_finish(conf); /* 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); - } + opt->boot_image = create_yaboot_devpath_resource(conf, + value, &state->desc_image); return; } @@ -131,31 +144,33 @@ static void yaboot_process_pair(struct conf_context *conf, const char *name, if (suse_fp) { /* First finish any previous image. */ - if (state->opt->boot_image_file) + if (opt->boot_image) yaboot_finish(conf); /* Then start the new image. */ if (*value == '/') { - state->opt->boot_image_file = resolve_path(state->opt, - value, conf->dc->device->device_path); - state->desc_image = talloc_strdup(state->opt, value); + opt->boot_image = create_yaboot_devpath_resource( + conf, value, &state->desc_image); } else { - state->opt->boot_image_file = resolve_path(state->opt, - 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); + char *tmp; + + opt->boot_image = create_yaboot_devpath_resource( + conf, suse_fp->image, + &state->desc_image); + + opt->initrd = create_yaboot_devpath_resource( + conf, suse_fp->initrd, &tmp); + + state->desc_initrd = talloc_asprintf(opt, + "initrd=%s", tmp); + talloc_free(tmp); } return; } - if (!state->opt->boot_image_file) { + if (!opt->boot_image) { pb_log("%s: unknown name: %s\n", __func__, name); return; } @@ -163,86 +178,66 @@ static void yaboot_process_pair(struct conf_context *conf, const char *name, /* initrd */ if (streq(name, "initrd")) { - 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); - } + opt->initrd = create_yaboot_devpath_resource(conf, + value, &state->desc_image); + return; } /* label */ if (streq(name, "label")) { - state->opt->id = talloc_asprintf(state->opt, "%s#%s", + opt->option->id = talloc_asprintf(opt->option, "%s#%s", conf->dc->device->device->id, value); - state->opt->name = talloc_strdup(state->opt, value); + opt->option->name = talloc_strdup(opt->option, value); return; } /* args */ if (streq(name, "append")) { - state->opt->boot_args = talloc_asprintf_append( - state->opt->boot_args, "%s ", value); + opt->option->boot_args = talloc_asprintf_append( + opt->option->boot_args, "%s ", value); return; } if (streq(name, "initrd-size")) { - state->opt->boot_args = talloc_asprintf_append( - state->opt->boot_args, "ramdisk_size=%s ", value); + opt->option->boot_args = talloc_asprintf_append( + opt->option->boot_args, "ramdisk_size=%s ", value); return; } if (streq(name, "literal")) { - if (*state->opt->boot_args) { + if (*opt->option->boot_args) { pb_log("%s: literal over writes '%s'\n", __func__, - state->opt->boot_args); - talloc_free(state->opt->boot_args); + opt->option->boot_args); + talloc_free(opt->option->boot_args); } - talloc_asprintf(state->opt, "%s ", value); + talloc_asprintf(opt->option, "%s ", value); return; } if (streq(name, "ramdisk")) { - state->opt->boot_args = talloc_asprintf_append( - state->opt->boot_args, "ramdisk=%s ", value); + opt->option->boot_args = talloc_asprintf_append( + opt->option->boot_args, "ramdisk=%s ", value); return; } if (streq(name, "read-only")) { - state->opt->boot_args = talloc_asprintf_append( - state->opt->boot_args, "ro "); + opt->option->boot_args = talloc_asprintf_append( + opt->option->boot_args, "ro "); return; } if (streq(name, "read-write")) { - state->opt->boot_args = talloc_asprintf_append( - state->opt->boot_args, "rw "); + opt->option->boot_args = talloc_asprintf_append( + opt->option->boot_args, "rw "); return; } if (streq(name, "root")) { - state->opt->boot_args = talloc_asprintf_append( - state->opt->boot_args, "root=%s ", value); + opt->option->boot_args = talloc_asprintf_append( + opt->option->boot_args, "root=%s ", value); return; } @@ -309,8 +304,8 @@ static int yaboot_parse(struct discover_context *dc, char *buf, int len) /* opt is persistent, so must be associated with device */ - state->opt = talloc_zero(conf->dc->device, struct boot_option); - state->opt->boot_args = talloc_strdup(state->opt, ""); + state->opt = discover_boot_option_create(conf->dc, conf->dc->device); + state->opt->option->boot_args = talloc_strdup(state->opt->option, ""); conf_parse_buf(conf, buf, len);