+ res = talloc_zero(task, struct boot_resource);
+ if (!res)
+ return NULL;
+
+ res->name = talloc_strdup(res, name);
+ res->url = pb_url_copy(res, url);
+ res->local_path = local_path;
+
+ list_add(&task->resources, &res->list);
+ return res;
+}
+
+struct boot_task *boot(void *ctx, struct discover_boot_option *opt,
+ struct boot_command *cmd, int dry_run,
+ boot_status_fn status_fn, void *status_arg)
+{
+ struct pb_url *image = NULL, *initrd = NULL, *dtb = NULL;
+ struct pb_url *image_sig = NULL, *initrd_sig = NULL, *dtb_sig = NULL,
+ *cmdline_sig = NULL;
+ struct boot_resource *image_res, *initrd_res, *dtb_res, *tmp;
+ const struct config *config = config_get();
+ struct boot_task *boot_task;
+ const char *boot_desc;
+ int rc;
+ int lockdown_type;
+
+ 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, 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_fn("no image specified\n");
+ update_status(status_fn, status_arg, STATUS_INFO,
+ _("Boot failed: no image specified"));
+ return NULL;
+ }
+
+ 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 (opt && opt->proxy) {
+ setenv("http_proxy", opt->proxy, 1);
+ setenv("https_proxy", opt->proxy, 1);
+ }
+
+ boot_task = talloc_zero(ctx, struct boot_task);
+ boot_task->dry_run = dry_run;
+ boot_task->status_fn = status_fn;
+ boot_task->status_arg = status_arg;
+ list_init(&boot_task->resources);
+
+ lockdown_type = lockdown_status();
+ boot_task->verify_signature = (lockdown_type == PB_LOCKDOWN_SIGN);
+ boot_task->decrypt_files = (lockdown_type == PB_LOCKDOWN_DECRYPT);
+
+ 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;
+ }
+
+ if (cmd && cmd->console && !config->manual_console)
+ boot_task->boot_console = talloc_strdup(boot_task, cmd->console);
+ else
+ boot_task->boot_console = config ? config->boot_console : NULL;
+
+ if (boot_task->verify_signature || boot_task->decrypt_files) {
+ if (cmd && cmd->args_sig_file) {
+ cmdline_sig = pb_url_parse(opt, cmd->args_sig_file);
+ } else if (opt && opt->args_sig_file) {
+ cmdline_sig = opt->args_sig_file->url;
+ } else {
+ pb_log("%s: no command line signature file"
+ " specified\n", __func__);
+ update_status(status_fn, status_arg, STATUS_INFO,
+ _("Boot failed: no command line"
+ " signature file specified"));
+ talloc_free(boot_task);
+ return NULL;
+ }
+ }
+
+ image_res = add_boot_resource(boot_task, _("kernel image"), image,
+ &boot_task->local_image);
+ initrd_res = add_boot_resource(boot_task, _("initrd"), initrd,
+ &boot_task->local_initrd);
+ dtb_res = add_boot_resource(boot_task, _("dtb"), dtb,
+ &boot_task->local_dtb);
+
+ /* start async loads for boot resources */
+ rc = start_url_load(boot_task, image_res)
+ || start_url_load(boot_task, initrd_res)
+ || start_url_load(boot_task, dtb_res);
+
+ if (boot_task->verify_signature) {
+ /* Generate names of associated signature files and load */
+ if (image) {
+ image_sig = get_signature_url(ctx, image);
+ tmp = add_boot_resource(boot_task,
+ _("kernel image signature"), image_sig,
+ &boot_task->local_image_signature);
+ rc |= start_url_load(boot_task, tmp);
+ }
+ if (initrd) {
+ initrd_sig = get_signature_url(ctx, initrd);
+ tmp = add_boot_resource(boot_task,
+ _("initrd signature"), initrd_sig,
+ &boot_task->local_initrd_signature);
+ rc |= start_url_load(boot_task, tmp);
+ }
+ if (dtb) {
+ dtb_sig = get_signature_url(ctx, dtb);
+ tmp = add_boot_resource(boot_task,
+ _("dtb signature"), dtb_sig,
+ &boot_task->local_dtb_signature);
+ rc |= start_url_load(boot_task, tmp);
+ }
+ }
+
+ if (boot_task->verify_signature || boot_task->decrypt_files) {
+ tmp = add_boot_resource(boot_task,
+ _("kernel command line signature"), cmdline_sig,
+ &boot_task->local_cmdline_signature);
+ rc |= start_url_load(boot_task, tmp);
+ }
+
+ /* If all URLs are local, we may be done. */
+ if (rc) {
+ /* Don't call boot_cancel() to preserve the status update */
+ boot_task->cancelled = true;
+ cleanup_cancellations(boot_task, NULL);
+ return NULL;
+ }
+
+ boot_process(NULL, boot_task);
+
+ return boot_task;
+}
+
+void boot_cancel(struct boot_task *task)
+{
+ task->cancelled = true;
+
+ update_status(task->status_fn, task->status_arg, STATUS_INFO,
+ _("Boot cancelled"));
+
+ cleanup_cancellations(task, NULL);