From patchwork Tue Mar 8 14:07:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 549287 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6713:0:0:0:0 with SMTP id u19csp2655870mag; Tue, 8 Mar 2022 06:08:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJyEaW/jieiWgFwhfuH2J6r7KRiOviQypUTXQrXaTB5bdcc/mV22kzakw4EPfkqln8rf7Qaf X-Received: by 2002:aa7:cb96:0:b0:413:8d05:ebc with SMTP id r22-20020aa7cb96000000b004138d050ebcmr16415167edt.81.1646748506385; Tue, 08 Mar 2022 06:08:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646748506; cv=none; d=google.com; s=arc-20160816; b=VJFH4w/LDCMBxepK0AHVuuzMHeR+2iKWwSRBiyW5VRLRQNqbcJ0Ntw1OmWOySoZyQv uiHqZVFPFjeYZECu20d6RlAVp2rBel6fnRxnMIFhpRVil2sYlCJhMMrInBxUG4t4twVg S68vfzFXVaEyjBl8bW24NpMB/pHC2yY2L5BCTncD6YTcPVYayQUbbY+OXyDaNh2CVNyH /+T7P6oV8TDgKASN7CaN1o/vPgiiW/RR8dK8ZX5gW+TZOjLlikym43g35eIacq/QWNNG CMGgTJR7b9onHpWpajLmNuk+HmbPr+M+auNyHNOycrIj+Rd79F9013SA3H2NnNgo2GKA gygw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=NOqB4EvPzx6IMS7gf4xl1Q/t9oYdiZChLezc7ijSKh8=; b=R3pzSNs7W1YyHJ6pjZbPnkE/c51Gt+p7dqj6L23yJ1uLlWOxVorrlpa3cAmBDQ1TGK VwR1Xs+v7l+IXU/v5elD4YrC9jRYRY2qij6mB3xt0dwaULIUiz0wtMxiAsPlLKMqBH++ Z5uGh3yBkKxzhTe2nE2YdJhKjDQGVj/MXrwlfSMnsvTuIrhNjb/NAPbrMM9ep8Qevier xToOEzSNkXm1Z+r01F5Wd874zA0etp7nfheTyQtLIj8pJ/OShPXTdnw6G/uyv9oTeLz+ 9JioW45GzDR0TFRWpdKc91JHLT9KuP5FSrsSxnxHr02oZfXNxJYuLNuXE6sO8WKTSmFO 99Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ny0eSSJb; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id w16-20020a1709061f1000b006d1240c3431si10001381ejj.896.2022.03.08.06.08.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 06:08:26 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ny0eSSJb; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7E6FE83932; Tue, 8 Mar 2022 15:08:12 +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="ny0eSSJb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2C81783932; Tue, 8 Mar 2022 15:08:01 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (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 C31EE83927 for ; Tue, 8 Mar 2022 15:07:55 +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=masahisa.kojima@linaro.org Received: by mail-pl1-x632.google.com with SMTP id s18so3926804plp.1 for ; Tue, 08 Mar 2022 06:07:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NOqB4EvPzx6IMS7gf4xl1Q/t9oYdiZChLezc7ijSKh8=; b=ny0eSSJbHyprq4oMsZo6OSK/uP3lS85oW8S+5JPuCNw4Af4wiiUopiexLIJekCOT+h PBr1TPJRCT1kTUvLTCiNsmMk8TRkCtM1R8eTInB14kaSbj5R22t2cM/N5uUVBmdQ5Jzy ZeZhnJHGVcL/9AIZJKXJwPXMyYFeXQfP6Z0ON8ryaiFlQEDXOmLUBDdlm4uIOCcI4AyZ de1pmBwHSxJhzRLlIKtT14gl09LORUd+B5Nl7KjpNd9lD219gbp+5ovh6rjMRW1Q1BAX KdQwbDWwOH2sHU1CsqrLff+QkUzIxCPJV/0Pd3ADE53namW3V27vCnczbbVADMDTUZgs ByEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NOqB4EvPzx6IMS7gf4xl1Q/t9oYdiZChLezc7ijSKh8=; b=oKHZYupRz5+Pw8RNEpw7TCtkt5CPwqlmFdcantIiuAWMgkJMJo3UflG4xvzWWHLMYD nuALE8Jslgc0K9c0B6smm8jevxtILh4o7hAvi592gpv311WBG1avywHPgKkNu5RD3+ha +uD2cZH5ieqgomD9QKDYDitDfawRG+eQZ/wXA28Z7NzrpK+H7eqKk/vieYEZbrQgGTI+ 6QH/F3L+kNZ1LRuD0m/ZofJRS1JkYZkKZZmR4YMkGkYrP/mSNdm5+iAVWv/TmeRVBAp7 FV/BCz6IfaynP/dstmJJyOsKQzx3gUMvhhhhcjTF9BnQ6nceMp/5ccugKYL+ssrQwnwA CEvw== X-Gm-Message-State: AOAM532RNp96TjQ1IF6iL2wQ+XFJ57BDv1VjSUgep+RWmw89s9/A71AG +HMhvAmmBFZyVSKIQBkcuom6jw8LWpQMuA== X-Received: by 2002:a17:902:8605:b0:151:b6a2:8a1 with SMTP id f5-20020a170902860500b00151b6a208a1mr18144071plo.64.1646748474159; Tue, 08 Mar 2022 06:07:54 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id k62-20020a17090a4cc400b001bf0d92e1c7sm3142989pjh.41.2022.03.08.06.07.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 06:07:53 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Francois Ozog , Mark Kettenis , Masahisa Kojima Subject: [RFC PATCH v3 1/2] efi_loader: introduce "bootefi bootindex" command Date: Tue, 8 Mar 2022 23:07:44 +0900 Message-Id: <20220308140745.26180-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308140745.26180-1-masahisa.kojima@linaro.org> References: <20220308140745.26180-1-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 This commit introduces the new command "bootefi bootindex". With this command, user can select which "Boot####" option to load and execute. 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; }