From c11bcba9a99e858e618f4d872a5be7d52dcaaa5a Mon Sep 17 00:00:00 2001 From: Geoff Levand Date: Mon, 15 Apr 2013 15:23:05 -0700 Subject: Add initial dtb support Updates & fixes by Jeremy Kerr . Signed-off-by: Geoff Levand Signed-off-by: Jeremy Kerr --- discover/boot.c | 49 +++++++++++++++++++++++++++++++++++++++-------- discover/device-handler.c | 5 +++++ discover/device-handler.h | 1 + discover/kboot-parser.c | 25 +++++++++++++++++++----- 4 files changed, 67 insertions(+), 13 deletions(-) (limited to 'discover') diff --git a/discover/boot.c b/discover/boot.c index 5ca69b9..c922fb6 100644 --- a/discover/boot.c +++ b/discover/boot.c @@ -16,16 +16,18 @@ * kexec_load - kexec load helper. * @l_image: The local image file for kexec to execute. * @l_initrd: Optional local initrd file for kexec --initrd, can be NULL. + * @l_dtb: Optional local dtb file for kexec --dtb, can be NULL. * @args: Optional command line args for kexec --append, can be NULL. */ static int kexec_load(const char *l_image, const char *l_initrd, - const char *args, int dry_run) + const char *l_dtb, const char *args, int dry_run) { int result; - const char *argv[6]; + const char *argv[7]; const char **p; char *s_initrd = NULL; + char *s_dtb = NULL; char *s_args = NULL; p = argv; @@ -38,14 +40,20 @@ static int kexec_load(const char *l_image, const char *l_initrd, *p++ = s_initrd; /* 3 */ } + if (l_dtb) { + s_dtb = talloc_asprintf(NULL, "--dtb=%s", l_dtb); + assert(s_dtb); + *p++ = s_dtb; /* 4 */ + } + if (args) { s_args = talloc_asprintf(NULL, "--append=%s", args); assert(s_args); - *p++ = s_args; /* 4 */ + *p++ = s_args; /* 5 */ } - *p++ = l_image; /* 5 */ - *p++ = NULL; /* 6 */ + *p++ = l_image; /* 6*/ + *p++ = NULL; /* 7 */ result = pb_run_cmd(argv, 1, dry_run); @@ -53,6 +61,7 @@ static int kexec_load(const char *l_image, const char *l_initrd, pb_log("%s: failed: (%d)\n", __func__, result); talloc_free(s_initrd); + talloc_free(s_dtb); talloc_free(s_args); return result; @@ -128,16 +137,18 @@ static void update_status(boot_status_fn fn, void *arg, int type, int boot(void *ctx, struct discover_boot_option *opt, struct boot_command *cmd, int dry_run, boot_status_fn status_fn, void *status_arg) { - char *local_image, *local_initrd; + char *local_image, *local_initrd, *local_dtb; + struct pb_url *image, *initrd, *dtb; unsigned int clean_image = 0; unsigned int clean_initrd = 0; - struct pb_url *image, *initrd; + unsigned int clean_dtb = 0; char *args; int result; local_initrd = NULL; image = NULL; initrd = NULL; + dtb = NULL; args = NULL; if (cmd && cmd->boot_image_file) { @@ -155,6 +166,12 @@ int boot(void *ctx, struct discover_boot_option *opt, struct boot_command *cmd, initrd = opt->initrd->url; } + if (cmd && cmd->dtb_file) { + dtb = pb_url_parse(opt, cmd->dtb_file); + } else if (opt && opt->dtb) { + dtb = opt->dtb->url; + } + if (cmd && cmd->boot_args) { args = talloc_strdup(ctx, cmd->boot_args); } else if (opt && opt->option->boot_args) { @@ -183,10 +200,23 @@ int boot(void *ctx, struct discover_boot_option *opt, struct boot_command *cmd, } } + local_dtb = NULL; + if (dtb) { + update_status(status_fn, status_arg, BOOT_STATUS_INFO, + "loading device tree"); + local_dtb = load_url(NULL, dtb, &clean_dtb); + if (!local_dtb) { + update_status(status_fn, status_arg, BOOT_STATUS_ERROR, + "Couldn't load device tree"); + goto no_load; + } + } + update_status(status_fn, status_arg, BOOT_STATUS_INFO, "performing kexec_load"); - result = kexec_load(local_image, local_initrd, args, dry_run); + result = kexec_load(local_image, local_initrd, local_dtb, + args, dry_run); if (result) { update_status(status_fn, status_arg, BOOT_STATUS_ERROR, @@ -198,9 +228,12 @@ no_load: unlink(local_image); if (clean_initrd) unlink(local_initrd); + if (clean_dtb) + unlink(local_dtb); talloc_free(local_image); talloc_free(local_initrd); + talloc_free(local_dtb); if (!result) { update_status(status_fn, status_arg, BOOT_STATUS_INFO, diff --git a/discover/device-handler.c b/discover/device-handler.c index 46fecd2..d2a3f16 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -460,6 +460,7 @@ static bool __attribute__((used)) boot_option_is_resolved( { return resource_is_resolved(opt->boot_image) && resource_is_resolved(opt->initrd) && + resource_is_resolved(opt->dtb) && resource_is_resolved(opt->icon); } @@ -484,6 +485,7 @@ static bool boot_option_resolve(struct discover_boot_option *opt, { return resource_resolve(opt->boot_image, "boot_image", opt, handler) && resource_resolve(opt->initrd, "initrd", opt, handler) && + resource_resolve(opt->dtb, "dtb", opt, handler) && resource_resolve(opt->icon, "icon", opt, handler); } @@ -495,6 +497,7 @@ static void boot_option_finalise(struct device_handler *handler, /* check that the parsers haven't set any of the final data */ assert(!opt->option->boot_image_file); assert(!opt->option->initrd_file); + assert(!opt->option->dtb_file); assert(!opt->option->icon_file); assert(!opt->option->device_id); @@ -502,6 +505,8 @@ static void boot_option_finalise(struct device_handler *handler, opt->option->boot_image_file = opt->boot_image->url->full; if (opt->initrd) opt->option->initrd_file = opt->initrd->url->full; + if (opt->dtb) + opt->option->dtb_file = opt->dtb->url->full; if (opt->icon) opt->option->icon_file = opt->icon->url->full; diff --git a/discover/device-handler.h b/discover/device-handler.h index 60a33b7..693f5e4 100644 --- a/discover/device-handler.h +++ b/discover/device-handler.h @@ -46,6 +46,7 @@ struct discover_boot_option { struct resource *boot_image; struct resource *initrd; + struct resource *dtb; struct resource *icon; }; diff --git a/discover/kboot-parser.c b/discover/kboot-parser.c index 4b4c2f7..9d0322d 100644 --- a/discover/kboot-parser.c +++ b/discover/kboot-parser.c @@ -21,6 +21,7 @@ static void kboot_process_pair(struct conf_context *conf, const char *name, char *args; const char *initrd; const char *root; + const char *dtb; /* ignore bare values */ @@ -50,6 +51,7 @@ static void kboot_process_pair(struct conf_context *conf, const char *name, args = talloc_strdup(opt, ""); initrd = conf_get_global_option(conf, "initrd"); root = conf_get_global_option(conf, "root"); + dtb = conf_get_global_option(conf, "dtb"); pos = strchr(value, ' '); @@ -79,6 +81,11 @@ static void kboot_process_pair(struct conf_context *conf, const char *name, continue; } + if (streq(cl_name, "dtb")) { + dtb = cl_value; + continue; + } + args = talloc_asprintf_append(args, "%s=%s ", cl_name, cl_value); } @@ -93,15 +100,22 @@ out_add: } else opt->boot_args = args; + opt->description = talloc_asprintf(opt, "%s %s", value, + opt->boot_args); + if (initrd) { d_opt->initrd = create_devpath_resource(d_opt, conf->dc->device, initrd); + opt->description = talloc_asprintf_append(opt->description, + " initrd=%s", initrd); + } - opt->description = talloc_asprintf(opt, "%s initrd=%s %s", - value, initrd, opt->boot_args); - } else - opt->description = talloc_asprintf(opt, "%s %s", value, - opt->boot_args); + if (dtb) { + d_opt->dtb = create_devpath_resource(d_opt, + conf->dc->device, dtb); + opt->description = talloc_asprintf_append(opt->description, + " dtb=%s", dtb); + } conf_strip_str(opt->boot_args); conf_strip_str(opt->description); @@ -110,6 +124,7 @@ out_add: } static struct conf_global_option kboot_global_options[] = { + { .name = "dtb" }, { .name = "initrd" }, { .name = "root" }, { .name = "video" }, -- cgit v1.2.1