+ int result = -1;
+
+ if (task->state == BOOT_STATE_INITIAL) {
+ update_status(task->status_fn, task->status_arg,
+ BOOT_STATUS_INFO, "loading kernel");
+ task->local_image = load_url_async(task, task->image,
+ &clean_image, boot_process);
+ if (!task->local_image) {
+ update_status(task->status_fn, task->status_arg,
+ BOOT_STATUS_ERROR,
+ "Couldn't load kernel image");
+ goto no_load;
+ } else {
+ task->state = BOOT_STATE_IMAGE_LOADING;
+ *status = 0;
+ return;
+ }
+ }
+
+ if (task->state == BOOT_STATE_IMAGE_LOADING) {
+ if (task->initrd) {
+ update_status(task->status_fn, task->status_arg,
+ BOOT_STATUS_INFO, "loading initrd");
+ task->local_initrd = load_url_async(task, task->initrd,
+ &clean_initrd, boot_process);
+ if (!task->local_initrd) {
+ update_status(task->status_fn, task->status_arg,
+ BOOT_STATUS_ERROR,
+ "Couldn't load initrd image");
+ goto no_load;
+ } else {
+ task->state = BOOT_STATE_INITRD_LOADING;
+ *status = 0;
+ return;
+ }
+ } else {
+ task->state = BOOT_STATE_INITRD_LOADING;
+ }
+ }
+
+ if (task->state == BOOT_STATE_INITRD_LOADING) {
+ if (task->dtb) {
+ update_status(task->status_fn, task->status_arg,
+ BOOT_STATUS_INFO,
+ "loading device tree");
+ task->local_dtb = load_url_async(task, task->dtb,
+ &clean_dtb, boot_process);
+ if (!task->local_dtb) {
+ update_status(task->status_fn, task->status_arg,
+ BOOT_STATUS_ERROR,
+ "Couldn't load device tree");
+ goto no_load;
+ } else {
+ task->state = BOOT_STATE_FINISH;
+ *status = 0;
+ return;
+ }
+ } else {
+ task->state = BOOT_STATE_FINISH;
+ }
+ }
+
+ if (task->state != BOOT_STATE_FINISH) {
+ task->state = BOOT_STATE_UNKNOWN;
+ *status = -1;
+ return;
+ }
+
+ run_boot_hooks(task);
+
+ update_status(task->status_fn, task->status_arg, BOOT_STATUS_INFO,
+ "performing kexec_load");
+
+ result = kexec_load(task);
+
+ if (result) {
+ update_status(task->status_fn, task->status_arg,
+ BOOT_STATUS_ERROR, "kexec load failed");
+ }
+
+no_load:
+ if (clean_image)
+ unlink(task->local_image);
+ if (clean_initrd)
+ unlink(task->local_initrd);
+ if (clean_dtb)
+ unlink(task->local_dtb);
+
+ if (!result) {
+ update_status(task->status_fn, task->status_arg,
+ BOOT_STATUS_INFO,
+ "performing kexec reboot");
+
+ result = kexec_reboot(task);
+
+ if (result) {
+ update_status(task->status_fn, task->status_arg,
+ BOOT_STATUS_ERROR,
+ "kexec reboot failed");
+ }
+ }
+
+ talloc_free(task);
+
+ *status = result;
+}
+
+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;