+ struct boot_task boot_task;
+ struct pb_url *image, *initrd, *dtb;
+ unsigned int clean_image = 0;
+ unsigned int clean_initrd = 0;
+ unsigned int clean_dtb = 0;
+ int result;
+
+ image = NULL;
+ initrd = NULL;
+ dtb = NULL;
+ boot_task.dry_run = dry_run;
+
+ if (cmd && cmd->boot_image_file) {
+ image = pb_url_parse(opt, cmd->boot_image_file);
+ } else if (opt && opt->boot_image) {
+ image = opt->boot_image->url;
+ } else {
+ pb_log("%s: no image specified", __func__);
+ return -1;
+ }
+
+ if (cmd && cmd->initrd_file) {
+ initrd = pb_url_parse(opt, cmd->initrd_file);
+ } else if (opt && opt->initrd) {
+ 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) {
+ boot_task.args = talloc_strdup(ctx, cmd->boot_args);
+ } else if (opt && opt->option->boot_args) {
+ boot_task.args = talloc_strdup(ctx, opt->option->boot_args);
+ } else {
+ boot_task.args = NULL;
+ }
+
+ result = -1;
+
+ update_status(status_fn, status_arg, BOOT_STATUS_INFO,
+ "loading kernel");
+ boot_task.local_image = load_url(NULL, image, &clean_image);
+ if (!boot_task.local_image) {
+ update_status(status_fn, status_arg, BOOT_STATUS_ERROR,
+ "Couldn't load kernel image");
+ goto no_load;
+ }
+
+ boot_task.local_initrd = NULL;
+ if (initrd) {
+ update_status(status_fn, status_arg, BOOT_STATUS_INFO,
+ "loading initrd");
+ boot_task.local_initrd = load_url(NULL, initrd, &clean_initrd);
+ if (!boot_task.local_initrd) {
+ update_status(status_fn, status_arg, BOOT_STATUS_ERROR,
+ "Couldn't load initrd image");
+ goto no_load;
+ }
+ }
+
+ boot_task.local_dtb = NULL;
+ if (dtb) {
+ update_status(status_fn, status_arg, BOOT_STATUS_INFO,
+ "loading device tree");
+ boot_task.local_dtb = load_url(NULL, dtb, &clean_dtb);
+ if (!boot_task.local_dtb) {
+ update_status(status_fn, status_arg, BOOT_STATUS_ERROR,
+ "Couldn't load device tree");
+ goto no_load;
+ }
+ }
+
+ run_boot_hooks(ctx, &boot_task, status_fn, status_arg);
+
+ update_status(status_fn, status_arg, BOOT_STATUS_INFO,
+ "performing kexec_load");
+
+ result = kexec_load(&boot_task);
+
+ if (result) {
+ update_status(status_fn, status_arg, BOOT_STATUS_ERROR,
+ "kexec load failed");
+ }
+
+no_load:
+ if (clean_image)
+ unlink(boot_task.local_image);
+ if (clean_initrd)
+ unlink(boot_task.local_initrd);
+ if (clean_dtb)
+ unlink(boot_task.local_dtb);
+
+ talloc_free(boot_task.local_image);
+ talloc_free(boot_task.local_initrd);
+ talloc_free(boot_task.local_dtb);
+
+ if (!result) {
+ update_status(status_fn, status_arg, BOOT_STATUS_INFO,
+ "performing kexec reboot");
+
+ result = kexec_reboot(boot_task.dry_run);
+
+ if (result) {
+ update_status(status_fn, status_arg, BOOT_STATUS_ERROR,
+ "kexec reboot failed");
+ }
+ }