From patchwork Thu Mar 24 13:54:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 553917 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1248:0:0:0:0 with SMTP id z8csp4438865mag; Thu, 24 Mar 2022 06:56:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8CcJrsUvjdyY3wARM/p3oxcYNgaEEouWfCfLEShkdw+SJgUWf5i5iAtl4TvNEmAmcUNJc X-Received: by 2002:a17:907:9805:b0:6db:4c33:7883 with SMTP id ji5-20020a170907980500b006db4c337883mr6031763ejc.555.1648130168849; Thu, 24 Mar 2022 06:56:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648130168; cv=none; d=google.com; s=arc-20160816; b=Wu0JKl7ljgFUtFKfBWYsqPn6f4cWj0ZzdWifm//RW/agZdBvkdrgjx/haXQ7aOKutu vcQuiB32uiTw57sNpT17K6durjTAe/b67vddndItmqDGEMwuWveJcqyRFbb3OBYLY2Ox VmFM9up/6bc8ZAGvBy5CmfhC+AY8AoTzc7eziHKOy7TNqidfCKBOvUwMWejFMkqXZ4+N 2Rez8ZQqSNAkmJG6iID7EF8e29X2zCa2/vL7O7yojSuEwjVauEldfPyImMm+eP2NmR/C Bqvyz0egjjwxwXI9jmqwssIZeJzL9b/ney+HO+8DFZzkJ6GAftLhYV8J1nUvawY2cW3J 2feQ== 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=GOezjTssLHvI1Nn5U9dVQHrrcZp9+fMf0V7XRbaJooU=; b=gxmlGkaSb5l0hKhDsO3zT1mCyl0pbgiDDZNSzgJZh1tp5RUZeM36oZeUlHYjYud2lx NvP05sQJSzYpy5bxSgA45GJTCreKvkc+bdSbICDBdx5x0g+uAb/c2iWT2M8o7sYo4tJs G9jmcMY3CqJtlSqG17sdb7rZstw5Kz4loeEVW5sPaIlcSkVCLnSPzbA4QloagZENhG9S G3//LCbotD4i0dWDVZdo5UD2F90DMd4BAfmiwXoDDGHcON4S4mK8SOZF9C/8kkA1ixOe 0z8uX9/0zNGUBmT4ig6x0C/iZ0DO2pJ+aORT+4AGIA8h6sHeZv30hel8ida1jGn3wl62 bATg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ikQOp+8t; 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 26-20020a17090600da00b006df76385c0csi16096721eji.172.2022.03.24.06.56.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Mar 2022 06:56:08 -0700 (PDT) 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=ikQOp+8t; 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 5912C840C4; Thu, 24 Mar 2022 14:55:21 +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="ikQOp+8t"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EB730840BB; Thu, 24 Mar 2022 14:54:59 +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 57295840B7 for ; Thu, 24 Mar 2022 14:54:56 +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 k6so4735161plg.12 for ; Thu, 24 Mar 2022 06:54:56 -0700 (PDT) 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=GOezjTssLHvI1Nn5U9dVQHrrcZp9+fMf0V7XRbaJooU=; b=ikQOp+8tcEQZr2IGr9LAonNjHiadfOwAyP0GIu+RW5w7wWrGCQs1lAsv5iVG8HLE/W k4YD3GJuxG44h6DapZRlinMtzrYykhMTznWnzdGdBT/7CYu3ewocuZfAHN9cFUSvqA02 bLjrmi2r3kgfcBBjGJLzdXsUY/W7cOruhegbsBrzayW8ABJjqnNKTUad69dmCJF0wYUT uYXfSvYk5Yra7hMINwmjkUvUzPP50QXuOv9rfRFkyM0qGD2ta/ZX5i9VgjEVipzCclDO jAnqdplqvHEvS0R0BoRo5btWtoUeb4YL+VP6HTujpLPmsWU2MRcaANRxG1Y18PeqAcmO x/Ow== 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=GOezjTssLHvI1Nn5U9dVQHrrcZp9+fMf0V7XRbaJooU=; b=xoFSRwPUdShdZV/JgrPQf7DYxpRoT/fOtmAh1d0VUyYNSPT5X6IsKp/HCcyixaGfE7 S/9P9SiL9xqB0stqXrKmyjiW9IwSl18JHrzp61OC6Nqg721IHRYl/gNMassJyVQFSIZy b9efCUSAlraeYjCHE5u4gu/By3/YMXU9WOhk6UcPsmuNmvrfY++ez8g6cmVWPjz3fFgg oCDhgWN/TvDQjGfNcYOr69oNYu+Uc1yq2FxBfsTHkVvIjQg2ePp9M9DV8x+ejaXn8s8Z 7oKOk+BFJP8ohGvacAOEuM8hfg2w21SFq9yCOiAUkV5Nt0tvouJdNUe+ejLPHNFtpK9v ZNWw== X-Gm-Message-State: AOAM531Iw4MLIIhyF5/CdStbt/lss09SB4j3Apf8QMh6cEOBoBje5XP6 DlXOQ8tw76mL7YklN+RFssdR5RjqyYHCcw== X-Received: by 2002:a17:90a:5b0d:b0:1bc:7e66:2970 with SMTP id o13-20020a17090a5b0d00b001bc7e662970mr6424645pji.12.1648130094487; Thu, 24 Mar 2022 06:54:54 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id p15-20020a056a000a0f00b004f7c63cba5asm3974609pfh.21.2022.03.24.06.54.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Mar 2022 06:54:54 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Francois Ozog , Mark Kettenis , Masahisa Kojima , Mark Kettenis , Andre Przywara , Neil Armstrong Subject: [PATCH v4 06/11] efi_loader: bootmgr: add booting from removable media Date: Thu, 24 Mar 2022 22:54:38 +0900 Message-Id: <20220324135443.1571-7-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220324135443.1571-1-masahisa.kojima@linaro.org> References: <20220324135443.1571-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 From: AKASHI Takahiro Under the current implementation, booting from removable media using a architecture-specific default image name, say BOOTAA64.EFI, is supported only in distro_bootcmd script. See the commit 74522c898b35 ("efi_loader: Add distro boot script for removable media"). This is, however, half-baked implementation because 1) UEFI specification requires this feature to be implemented as part of Boot Manager's responsibility: 3 - Boot Manager 3.5.1 Boot via the Simple File Protocol When booting via the EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, the FilePath will start with a device path that points to the device that implements the EFI_SIMPLE_FILE_SYSTEM_PROTOCOL or the EFI_BLOCK_IO_PROTOCOL. The next part of the FilePath may point to the file name, including subdirectories, which contain the bootable image. If the file name is a null device path, the file name must be generated from the rules defined below. ... 3.5.1.1 Removable Media Boot Behavior To generate a file name when none is present in the FilePath, the firmware must append a default file name in the form \EFI\BOOT\BOOT{machine type short-name}.EFI ... 2) So (1) entails the hehavior that the user's preference of boot media order should be determined by Boot#### and BootOrder variables. With this patch, the semantics mentioned above is fully implemented. For example, if you want to boot the system from USB and SCSI in this order, * define Boot0001 which contains only a device path to the USB device (without any file path/name) * define Boot0002 which contains only a device path to the SCSI device, and * set BootOrder to Boot0001:Boot0002 Signed-off-by: AKASHI Takahiro Signed-off-by: Masahisa Kojima --- Changes from original version: - create new include file "efi_default_filename.h" to avoid conflict with config_distro_bootcmd.h - modify the target pointer of efi_free_pool(), expand_media_path() should only free the pointer allocated by efi_dp_from_file() function. include/config_distro_bootcmd.h | 14 +-------- include/efi_default_filename.h | 26 +++++++++++++++++ lib/efi_loader/efi_bootmgr.c | 50 ++++++++++++++++++++++++++++++++- 3 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 include/efi_default_filename.h diff --git a/include/config_distro_bootcmd.h b/include/config_distro_bootcmd.h index 2f90929178..ef2c9f330e 100644 --- a/include/config_distro_bootcmd.h +++ b/include/config_distro_bootcmd.h @@ -91,19 +91,7 @@ #endif #ifdef CONFIG_EFI_LOADER -#if defined(CONFIG_ARM64) -#define BOOTEFI_NAME "bootaa64.efi" -#elif defined(CONFIG_ARM) -#define BOOTEFI_NAME "bootarm.efi" -#elif defined(CONFIG_X86_RUN_32BIT) -#define BOOTEFI_NAME "bootia32.efi" -#elif defined(CONFIG_X86_RUN_64BIT) -#define BOOTEFI_NAME "bootx64.efi" -#elif defined(CONFIG_ARCH_RV32I) -#define BOOTEFI_NAME "bootriscv32.efi" -#elif defined(CONFIG_ARCH_RV64I) -#define BOOTEFI_NAME "bootriscv64.efi" -#endif +#include #endif #ifdef BOOTEFI_NAME diff --git a/include/efi_default_filename.h b/include/efi_default_filename.h new file mode 100644 index 0000000000..de030d2692 --- /dev/null +++ b/include/efi_default_filename.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Default boot file name when none is present in the FilePath. + * + * Copyright (c) 2022, Linaro Limited + */ +#ifndef _EFI_DEFAULT_FILENAME_H +#define _EFI_DEFAULT_FILENAME_H + +#if defined(CONFIG_ARM64) +#define BOOTEFI_NAME "BOOTAA64.EFI" +#elif defined(CONFIG_ARM) +#define BOOTEFI_NAME "BOOTARM.EFI" +#elif defined(CONFIG_X86_64) +#define BOOTEFI_NAME "BOOTX64.EFI" +#elif defined(CONFIG_X86) +#define BOOTEFI_NAME "BOOTIA32.EFI" +#elif defined(CONFIG_ARCH_RV32I) +#define BOOTEFI_NAME "BOOTRISCV32.EFI" +#elif defined(CONFIG_ARCH_RV64I) +#define BOOTEFI_NAME "BOOTRISCV64.EFI" +#else +#error Unsupported UEFI architecture +#endif + +#endif diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 8c04ecbdc8..22a4302aac 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -30,6 +31,50 @@ static const struct efi_runtime_services *rs; * should do normal or recovery boot. */ +/** + * expand_media_path() - expand a device path for default file name + * @device_path: device path to check against + * + * If @device_path is a media or disk partition which houses a file + * system, this function returns a full device path which contains + * an architecture-specific default file name for removable media. + * + * Return: a newly allocated device path + */ +static +struct efi_device_path *expand_media_path(struct efi_device_path *device_path) +{ + struct efi_device_path *dp, *full_path; + efi_handle_t handle; + efi_status_t ret; + + if (!device_path) + return NULL; + + /* + * If device_path is a (removable) media or partition which provides + * simple file system protocol, append a default file name to support + * booting from removable media. + */ + dp = device_path; + ret = efi_locate_device_path(&efi_simple_file_system_protocol_guid, + &dp, &handle); + if (ret == EFI_SUCCESS) { + if (dp->type == DEVICE_PATH_TYPE_END) { + dp = efi_dp_from_file(NULL, 0, + "/EFI/BOOT/" BOOTEFI_NAME); + full_path = efi_dp_append(device_path, dp); + efi_free_pool(dp); + } else { + full_path = efi_dp_dup(device_path); + } + } else { + full_path = efi_dp_dup(device_path); + } + + return full_path; +} + /** * try_load_entry() - try to load image for boot option * @@ -68,13 +113,16 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t *handle, } if (lo.attributes & LOAD_OPTION_ACTIVE) { + struct efi_device_path *file_path; u32 attributes; log_debug("%s: trying to load \"%ls\" from %pD\n", __func__, lo.label, lo.file_path); - ret = EFI_CALL(efi_load_image(true, efi_root, lo.file_path, + file_path = expand_media_path(lo.file_path); + ret = EFI_CALL(efi_load_image(true, efi_root, file_path, NULL, 0, handle)); + efi_free_pool(file_path); if (ret != EFI_SUCCESS) { log_warning("Loading %ls '%ls' failed\n", varname, lo.label);