+static bool load_pending(struct load_url_result *result)
+{
+ return result && result->status == LOAD_ASYNC;
+}
+
+static int check_load(struct boot_task *task, const char *name,
+ struct load_url_result *result)
+{
+ if (!result)
+ return 0;
+ if (result->status != LOAD_ERROR)
+ return 0;
+
+ update_status(task->status_fn, task->status_arg,
+ BOOT_STATUS_ERROR,
+ "Couldn't load %s", name);
+ return -1;
+}
+
+static void cleanup_load(struct load_url_result *result)
+{
+ if (!result)
+ return;
+ if (result->status != LOAD_OK)
+ return;
+ if (!result->cleanup_local)
+ return;
+ unlink(result->local);
+}
+
+static void boot_process(struct load_url_result *result __attribute__((unused)),
+ void *data)
+{
+ struct boot_task *task = data;
+ int rc = -1;
+
+ if (load_pending(task->image) ||
+ load_pending(task->initrd) ||
+ load_pending(task->dtb))
+ return;
+
+ if (check_load(task, "kernel image", task->image) ||
+ check_load(task, "initrd", task->initrd) ||
+ check_load(task, "dtb", task->dtb))
+ goto no_load;
+
+ run_boot_hooks(task);
+
+ update_status(task->status_fn, task->status_arg, BOOT_STATUS_INFO,
+ "performing kexec_load");
+
+ rc = kexec_load(task);
+ if (rc) {
+ update_status(task->status_fn, task->status_arg,
+ BOOT_STATUS_ERROR, "kexec load failed");
+ }
+
+no_load:
+ cleanup_load(task->image);
+ cleanup_load(task->initrd);
+ cleanup_load(task->dtb);
+
+ if (!rc) {
+ update_status(task->status_fn, task->status_arg,
+ BOOT_STATUS_INFO,
+ "performing kexec reboot");
+
+ rc = kexec_reboot(task);
+ if (rc) {
+ update_status(task->status_fn, task->status_arg,
+ BOOT_STATUS_ERROR,
+ "kexec reboot failed");
+ }
+ }
+
+ talloc_free(task);
+}
+
+static int start_url_load(struct boot_task *task, const char *name,
+ struct pb_url *url, struct load_url_result **result)
+{
+ if (!url)
+ return 0;
+
+ *result = load_url_async(task, url, boot_process, task);
+ if (!*result) {
+ update_status(task->status_fn, task->status_arg,
+ BOOT_STATUS_ERROR,
+ "Error loading %s", name);
+ return -1;
+ }
+ return 0;
+}
+