From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8F08AC433F5 for ; Tue, 8 Mar 2022 14:17:43 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 66C6B8383E; Tue, 8 Mar 2022 15:17:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="ILJdJhHg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4EAEA83400; Tue, 8 Mar 2022 15:17:39 +0100 (CET) Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 099AF8383E for ; Tue, 8 Mar 2022 15:17:35 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pf1-x435.google.com with SMTP id s8so13367839pfk.12 for ; Tue, 08 Mar 2022 06:17:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=cHWZ5I9lvc4vsUDIEhlFFwmaxqVpQFbYuD4x8o2qGHM=; b=ILJdJhHg8+Vke1CwAkaagt/J56E9+L+gwpQip2y2U+XCxSljPFifQTnHEUj80ajeHy ZV3gOt+wp+wZ2sukfVMjrMi0IlR7eM6a5aN7iXSApy0fk8DbqKj92JPnmF/XjFmBIyJa wx2+4vEuJdWtb24pKsIeKcr5Et1BuoJRq5bzsIPwmJCl/YMImsgC1phCCxDiPRQcwem3 Q9+mlwyNcTVjYqkN01GdgPQYFMVcrQE8vDGu4ta6oO+lf1BbqP1oXieVrRX3k/5tGZmW ymREr5sW6rnse8mn1UNfAYNEGGf3eRoe5/gPd721pm7DhgoWN3EvOVbWZx9e3q6j6F1r aRxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=cHWZ5I9lvc4vsUDIEhlFFwmaxqVpQFbYuD4x8o2qGHM=; b=AiqSAu1r6Gt8T/dB7hy8HhYsDOp7QZcq2funm18cnO3m5r3o0Ko5F3Bi7TZbZ5yJvU c4cFWhm28460hBgmibERH6pV8wedBUnO/8GjDrsC2rwkMoyqXSF80H6P6VWs1UqNhVou QwO1gFe9czQ9Js9X9+gHRfuKvp0YTYgtIifjhK662txxgaMqrlSggbesiN/0bTU4Z9HT O3IkKNHsDW2ZxjLi36+HckLpgP++/BfVPE1DausDLdhO7Tsattay6ce0CuCzsFoLZwMA XufN+spFP1kXIZ+MHqXgml0syEZGQ7gBGS4c1chX1T8gwEjfWOPZdO2yNBl3X+q1Nglw GWsg== X-Gm-Message-State: AOAM533NWQMQE6mMfNTU6ZpW0Gzdf0wakfmvpIgrrvo04GizSTzhr+Nk qOb5AjlpD4fobkBY4OX4srXn4A== X-Google-Smtp-Source: ABdhPJxUuwnnylgUxltf1sGhhID2t2LKx0+XEiFqeYZs3Hl1OJX243I4nG7NpNz6QdI/atPtzbEuUA== X-Received: by 2002:a05:6a00:10cb:b0:4f7:942:6a22 with SMTP id d11-20020a056a0010cb00b004f709426a22mr9241243pfu.84.1646749053393; Tue, 08 Mar 2022 06:17:33 -0800 (PST) Received: from laputa ([2400:4050:c3e1:100:b94a:f47a:3d51:185c]) by smtp.gmail.com with ESMTPSA id j22-20020a17090a7e9600b001bc67215a52sm2968517pjl.56.2022.03.08.06.17.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 06:17:33 -0800 (PST) Date: Tue, 8 Mar 2022 23:17:28 +0900 From: Takahiro Akashi To: Masahisa Kojima Cc: u-boot@lists.denx.de, Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Francois Ozog , Mark Kettenis Subject: Re: [RFC PATCH v3 1/2] efi_loader: introduce "bootefi bootindex" command Message-ID: <20220308141728.GC228584@laputa> Mail-Followup-To: Takahiro Akashi , Masahisa Kojima , u-boot@lists.denx.de, Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Francois Ozog , Mark Kettenis References: <20220308140745.26180-1-masahisa.kojima@linaro.org> <20220308140745.26180-2-masahisa.kojima@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220308140745.26180-2-masahisa.kojima@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.5 at phobos.denx.de X-Virus-Status: Clean On Tue, Mar 08, 2022 at 11:07:44PM +0900, Masahisa Kojima wrote: > This commit introduces the new command "bootefi bootindex". > With this command, user can select which "Boot####" option > to load and execute. You can do the same thing with: $ efidebug boot next 1 (for BOOT0001) $ bootefi bootmgr -Takahiro Akashi > Signed-off-by: Masahisa Kojima > --- > Changes in v3: > - newly created > > cmd/bootefi.c | 42 ++++++++++++++++++++++++++++++++++++ > include/efi_loader.h | 1 + > lib/efi_loader/efi_bootmgr.c | 7 +++--- > 3 files changed, 46 insertions(+), 4 deletions(-) > > diff --git a/cmd/bootefi.c b/cmd/bootefi.c > index 46eebd5ee2..df86438fec 100644 > --- a/cmd/bootefi.c > +++ b/cmd/bootefi.c > @@ -416,6 +416,30 @@ static int do_efibootmgr(void) > return CMD_RET_SUCCESS; > } > > +/** > + * do_efibootindex() - load and execute the specified Boot#### option > + * > + * Return: status code > + */ > +static int do_efibootindex(u16 boot_index) > +{ > + efi_handle_t handle; > + efi_status_t ret; > + void *load_options; > + > + ret = efi_try_load_entry(boot_index, &handle, &load_options); > + if (ret != EFI_SUCCESS) { > + log_notice("EFI boot manager: failed to load Boot%04X\n", boot_index); > + return CMD_RET_FAILURE; > + } > + > + ret = do_bootefi_exec(handle, load_options); > + > + if (ret != EFI_SUCCESS) > + return CMD_RET_FAILURE; > + > + return CMD_RET_SUCCESS; > +} > /** > * do_bootefi_image() - execute EFI binary > * > @@ -654,6 +678,22 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc, > return CMD_RET_FAILURE; > } > > + if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) { > + if (!strcmp(argv[1], "bootindex")) { > + char *endp; > + int boot_index; > + > + if (argc < 3) > + return CMD_RET_USAGE; > + > + boot_index = (int)hextoul(argv[2], &endp); > + if (*endp != '\0' || boot_index > 0xffff) > + return CMD_RET_USAGE; > + > + return do_efibootindex((u16)boot_index); > + } > + } > + > if (argc > 2) { > uintptr_t fdt_addr; > > @@ -702,6 +742,8 @@ static char bootefi_help_text[] = > "\n" > " If specified, the device tree located at gets\n" > " exposed as EFI configuration table.\n" > + "bootefi bootindex \n" > + " - load and boot EFI payload based on the specified BootXXXX variable.\n" > #endif > ; > #endif > diff --git a/include/efi_loader.h b/include/efi_loader.h > index 80a5f1ec01..e5972f5fee 100644 > --- a/include/efi_loader.h > +++ b/include/efi_loader.h > @@ -861,6 +861,7 @@ 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, void **load_options); > +efi_status_t efi_try_load_entry(u16 n, efi_handle_t *handle, void **load_options); > > /** > * struct 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 8c04ecbdc8..a3060b5c62 100644 > --- a/lib/efi_loader/efi_bootmgr.c > +++ b/lib/efi_loader/efi_bootmgr.c > @@ -42,8 +42,7 @@ static const struct efi_runtime_services *rs; > * @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, > - void **load_options) > +efi_status_t efi_try_load_entry(u16 n, efi_handle_t *handle, void **load_options) > { > struct efi_load_option lo; > u16 varname[] = u"Boot0000"; > @@ -165,7 +164,7 @@ efi_status_t efi_bootmgr_load(efi_handle_t *handle, void **load_options) > /* load BootNext */ > if (ret == EFI_SUCCESS) { > if (size == sizeof(u16)) { > - ret = try_load_entry(bootnext, handle, > + ret = efi_try_load_entry(bootnext, handle, > load_options); > if (ret == EFI_SUCCESS) > return ret; > @@ -189,7 +188,7 @@ efi_status_t efi_bootmgr_load(efi_handle_t *handle, void **load_options) > 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, load_options); > + ret = efi_try_load_entry(bootorder[i], handle, load_options); > if (ret == EFI_SUCCESS) > break; > } > -- > 2.17.1 >