+ talloc_free(task);
+}
+
+int boot(void *ctx, struct discover_boot_option *opt, struct boot_command *cmd,
+ int dry_run, boot_status_fn status_fn, void *status_arg)
+{
+ struct boot_task *boot_task;
+ struct pb_url *image = NULL;
+ const char *boot_desc;
+
+ if (opt && opt->option->name)
+ boot_desc = opt->option->name;
+ else if (cmd && cmd->boot_image_file)
+ boot_desc = cmd->boot_image_file;
+ else
+ boot_desc = "(unknown)";
+
+ update_status(status_fn, status_arg, BOOT_STATUS_INFO,
+ "Booting %s.", boot_desc);
+
+ 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\n", __func__);
+ update_status(status_fn, status_arg, BOOT_STATUS_INFO,
+ "Boot failed: no image specified");
+ return -1;
+ }
+
+ boot_task = talloc_zero(ctx, struct boot_task);
+ boot_task->image = image;
+ boot_task->dry_run = dry_run;
+ boot_task->status_fn = status_fn;
+ boot_task->status_arg = status_arg;
+ boot_task->state = BOOT_STATE_INITIAL;
+
+ if (cmd && cmd->initrd_file) {
+ boot_task->initrd = pb_url_parse(opt, cmd->initrd_file);
+ } else if (opt && opt->initrd) {
+ boot_task->initrd = opt->initrd->url;
+ }
+
+ if (cmd && cmd->dtb_file) {
+ boot_task->dtb = pb_url_parse(opt, cmd->dtb_file);
+ } else if (opt && opt->dtb) {
+ boot_task->dtb = opt->dtb->url;
+ }
+
+ if (cmd && cmd->boot_args) {
+ boot_task->args = talloc_strdup(boot_task, cmd->boot_args);
+ } else if (opt && opt->option->boot_args) {
+ boot_task->args = talloc_strdup(boot_task,
+ opt->option->boot_args);
+ } else {
+ boot_task->args = NULL;
+ }
+
+ boot_process(boot_task, 0);
+
+ return 0;