From patchwork Fri Aug 7 17:46:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1342360 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=a8EAYFPN; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BNXqc3FwQz9sTN for ; Sat, 8 Aug 2020 03:47:08 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B9223821E7; Fri, 7 Aug 2020 19:46:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="a8EAYFPN"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 42FF0821A4; Fri, 7 Aug 2020 19:46:46 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C079E821A4 for ; Fri, 7 Aug 2020 19:46:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1596822400; bh=eiWJA2B3sar0gGeIlPQhKDBa8p0g9bKAsvYSIKa/NE4=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=a8EAYFPNlfon7IBC7lisuUDhCDgiUrJCAvzyGtuzS6pXjfs2fiuXC/W7UAREyfaNa iE5BAFUtdzDRqFSjvOJ5Z1LM0rlp7RfivWKp7NPamG/EoN/CFo8zSMXqofa85S7ELS pE5LtGvz1ibgEnnCFbdEWLA73Q+7BjQ0NOTQj/bc= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from LT02.fritz.box ([178.202.41.107]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1N1wlv-1kjbAH2AWH-012K1h; Fri, 07 Aug 2020 19:46:40 +0200 From: Heinrich Schuchardt To: Alexander Graf Cc: AKASHI Takahiro , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 2/2] efi_loader: set load options in boot manager Date: Fri, 7 Aug 2020 19:46:34 +0200 Message-Id: <20200807174634.127495-3-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200807174634.127495-1-xypron.glpk@gmx.de> References: <20200807174634.127495-1-xypron.glpk@gmx.de> MIME-Version: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agZGx3/GLv0xVNJvLXq6+T74EdkB2toU5 5Alk0AtixKnbpt+wGIPdXpjJFDVEq178pPGxI2D9iHnwI9VYMQVGruH4Crn0QGrL5JBxm05iK 1804XCwkROGmHiBDI3D/I6C0k+VZ788DCpORIYzrtusGaowEVrPc38TTTBW0Hv/4Hp6y0Bh0A tfCxd+cp//WXSAsQexpNAdNxiFNJEVqzZtpjivLCJPwFYAvLfmRVf/uwGnaeoAUsA3lCxWare zXhXliJK5nePEWFmvMtaUIpT8BRbca+lbh5CJ+fJypypa6F0wPUtjyYFrCodD77mq8dvIP0dT sphyXhzTKsJ1o3isnPW7RK1IHsGR/bQCkAxsxavf/G0Ngj1bYOCI83FEYwAOLe9LMNwkB9gAi +Buqz97ECucDPXhPysT6Yz/qYze37RINFC909d7M+CbX/omSyE+7Z3qpi6lW4WnfDOYtIQBlm fTj6FcqApq+z4v8Bbm8KH4wH3vrHMPSKikvU6LQ== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Up to now we used the value of the bootargs environment variable as load options in the boot manager. This is not correct. The data has to be taken from the Boot#### variable. Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load options to the loaded image protocol. Signed-off-by: Heinrich Schuchardt --- cmd/bootefi.c | 22 +++++++++++---------- cmd/efidebug.c | 4 +++- include/efi_loader.h | 2 +- lib/efi_loader/efi_bootmgr.c | 38 +++++++++++++++++++++++++----------- 4 files changed, 43 insertions(+), 23 deletions(-) -- 2.28.0 diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 5523405e13..fbfed54e85 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -310,17 +310,11 @@ efi_status_t efi_install_fdt(void *fdt) * Load the EFI binary into a newly assigned memory unwinding the relocation * information, install the loaded image protocol, and call the binary. */ -static efi_status_t do_bootefi_exec(efi_handle_t handle) +static efi_status_t do_bootefi_exec(efi_handle_t handle, void *load_options) { efi_status_t ret; efi_uintn_t exit_data_size = 0; u16 *exit_data = NULL; - u16 *load_options; - - /* Transfer environment variable as load options */ - ret = efi_env_set_load_options(handle, "bootargs", &load_options); - if (ret != EFI_SUCCESS) - return ret; /* Call our payload! */ ret = EFI_CALL(efi_start_image(handle, &exit_data_size, &exit_data)); @@ -349,14 +343,15 @@ static int do_efibootmgr(void) { efi_handle_t handle; efi_status_t ret; + void *load_options; - ret = efi_bootmgr_load(&handle); + ret = efi_bootmgr_load(&handle, &load_options); if (ret != EFI_SUCCESS) { log_notice("EFI boot manager: Cannot load any image\n"); return CMD_RET_FAILURE; } - ret = do_bootefi_exec(handle); + ret = do_bootefi_exec(handle, load_options); if (ret != EFI_SUCCESS) return CMD_RET_FAILURE; @@ -467,7 +462,14 @@ efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size) if (ret != EFI_SUCCESS) goto out; - ret = do_bootefi_exec(handle); + u16 *load_options; + + /* Transfer environment variable as load options */ + ret = efi_env_set_load_options(handle, "bootargs", &load_options); + if (ret != EFI_SUCCESS) + goto out; + + ret = do_bootefi_exec(handle, load_options); out: efi_delete_handle(mem_handle); diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 58018f700c..d00d4247dc 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -1126,8 +1126,9 @@ static int do_efi_test_bootmgr(struct cmd_tbl *cmdtp, int flag, efi_uintn_t exit_data_size = 0; u16 *exit_data = NULL; efi_status_t ret; + void *load_options; - ret = efi_bootmgr_load(&image); + ret = efi_bootmgr_load(&image, &load_options); printf("efi_bootmgr_load() returned: %ld\n", ret & ~EFI_ERROR_MASK); /* We call efi_start_image() even if error for test purpose. */ @@ -1138,6 +1139,7 @@ static int do_efi_test_bootmgr(struct cmd_tbl *cmdtp, int flag, efi_restore_gd(); + free(load_options); return CMD_RET_SUCCESS; } diff --git a/include/efi_loader.h b/include/efi_loader.h index ad580bd226..7f0ab1be56 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -720,7 +720,7 @@ unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data); efi_status_t efi_set_load_options(efi_handle_t handle, efi_uintn_t load_options_size, void *load_options); -efi_status_t efi_bootmgr_load(efi_handle_t *handle); +efi_status_t efi_bootmgr_load(efi_handle_t *handle, void **load_options); /** * efi_image_regions - A list of memory regions diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index a4bc272c34..1e06e60963 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -206,11 +206,13 @@ static void *get_var(u16 *name, const efi_guid_t *vendor, * if successful. This checks that the EFI_LOAD_OPTION is active (enabled) * and that the specified file to boot exists. * - * @n: number of the boot option, e.g. 0x0a13 for Boot0A13 - * @handle: on return handle for the newly installed image - * Return: status code + * @n: number of the boot option, e.g. 0x0a13 for Boot0A13 + * @handle: on return handle for the newly installed image + * @load_options: load options set on the loaded image protocol + * Return: status code */ -static efi_status_t try_load_entry(u16 n, efi_handle_t *handle) +static efi_status_t try_load_entry(u16 n, efi_handle_t *handle, + void **load_options) { struct efi_load_option lo; u16 varname[] = L"Boot0000"; @@ -250,10 +252,9 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t *handle) attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS; - size = sizeof(n); ret = efi_set_variable_int(L"BootCurrent", &efi_global_variable_guid, - attributes, size, &n, false); + attributes, sizeof(n), &n, false); if (ret != EFI_SUCCESS) { if (EFI_CALL(efi_unload_image(*handle)) != EFI_SUCCESS) @@ -266,6 +267,19 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t *handle) ret = EFI_LOAD_ERROR; } + /* Set load options */ + if (size) { + *load_options = malloc(size); + if (!*load_options) { + ret = EFI_OUT_OF_RESOURCES; + goto error; + } + memcpy(*load_options, lo.optional_data, size); + ret = efi_set_load_options(*handle, size, *load_options); + } else { + load_options = NULL; + } + error: free(load_option); @@ -279,10 +293,11 @@ error: * EFI variable, the available load-options, finding and returning * the first one that can be loaded successfully. * - * @handle: on return handle for the newly installed image - * Return: status code + * @handle: on return handle for the newly installed image + * @load_options: load options set on the loaded image protocol + * Return: status code */ -efi_status_t efi_bootmgr_load(efi_handle_t *handle) +efi_status_t efi_bootmgr_load(efi_handle_t *handle, void **load_options) { u16 bootnext, *bootorder; efi_uintn_t size; @@ -310,7 +325,8 @@ efi_status_t efi_bootmgr_load(efi_handle_t *handle) /* load BootNext */ if (ret == EFI_SUCCESS) { if (size == sizeof(u16)) { - ret = try_load_entry(bootnext, handle); + ret = try_load_entry(bootnext, handle, + load_options); if (ret == EFI_SUCCESS) return ret; log_warning( @@ -333,7 +349,7 @@ efi_status_t efi_bootmgr_load(efi_handle_t *handle) for (i = 0; i < num; i++) { log_debug("%s trying to load Boot%04X\n", __func__, bootorder[i]); - ret = try_load_entry(bootorder[i], handle); + ret = try_load_entry(bootorder[i], handle, load_options); if (ret == EFI_SUCCESS) break; }