From patchwork Tue Nov 9 01:32:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 518030 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp1052896iml; Mon, 8 Nov 2021 17:33:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJziuvZiZPoydpDC+2HVei4qVwVAW6kKc5mOsde5sgzSz/I0gwIIQDFSdJe6gV0H7vQgj24D X-Received: by 2002:a17:907:9723:: with SMTP id jg35mr4911747ejc.329.1636421625405; Mon, 08 Nov 2021 17:33:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636421625; cv=none; d=google.com; s=arc-20160816; b=LbBshKdbVY48/UO/C2PCAjf8bc7X2gG+p6tuxp2hcSB9rbnt7/5UJyBMb6mA1Zi8d2 mkBZQ/RMCxXdjZzF5sJFB3Pe1/VqH2Wcc/IN1cMf7Cq4EQjqYILJOy9fjBkHqIDeiF41 N9p7upHeejYsxK+81dsfVVu216w/SwpPZ9jTBCu4EhpYi0DRTGpYOPy/FcRIaH1TUwqL ik144epkO78qX6dWGJ0EvRADmxXyzBM3aGXGOo0vYropQIigWbNLkofY7fJBgZjxlH2h z9pWhVbfhEJ2SPUZxJlF4KgRXd9HiK3SGJ4zXlE5wTqyBS9RsGRl3+ImekDkuMCna8eA 3o5A== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=F9DOx3uElvZGGYKZ1NnUJKaxOFOmNphkke/IFoVulBE=; b=YJBOsSeNuGWpIHvMZ40E4OHKJrNJrY9DDdFGWAX3jIhdsTwqOmD1WigjCDmA1AB9Bo EVAITXmzKfoFaY7e9ePvxDsw/mSlH17DaDdIMlYaZXbIR08kM+SOrxj11O2K8MK74779 tBRMW2cGYglW8tbI0Y0PzhPzKYDcK3D9YUL8PmFI1OXAyegexetophoj16VU2cPocTeQ 7go95/iVrfBwBX+BJG+tCeBhxpO36K0kWrSZmxu1p/R30CIqZpDSaNwoZq761FqQYaSy qPDDizege0nhBpCfqiv0/fRyrdF+uxwhZUKyvtRhj8DuDpnbVYyZYWSpo6ZR/eaUQR9/ dN5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S+ZvW0Oo; 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 w14si37685682edd.141.2021.11.08.17.33.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 17:33:45 -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=S+ZvW0Oo; 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 48B01838F6; Tue, 9 Nov 2021 02:33:44 +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="S+ZvW0Oo"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 67393838EE; Tue, 9 Nov 2021 02:33:34 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) (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 88A89838E9 for ; Tue, 9 Nov 2021 02:33:25 +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-pl1-x636.google.com with SMTP id k4so17911869plx.8 for ; Mon, 08 Nov 2021 17:33:25 -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 :mime-version:content-transfer-encoding; bh=F9DOx3uElvZGGYKZ1NnUJKaxOFOmNphkke/IFoVulBE=; b=S+ZvW0OoG6/NuzxD28SE+zNopOI4vAaAp9sD4tAmuwMweejTsaw5puSmfHMAZ4a1bq L+/aDv3XOGRKbzUZYos3Xavz4Sf1dv6hgKqEdbK+af1FHOwXUJDq0FVXTpd8ZyysKvGO Yq9QzzyZVCYfkUwKYUDev88nk9cLWOkk19gcxM0tB+IIGZs1QkdU0YteW1rhBubPbEHi vF+kBGTnFaEm5BtjRkrRtNB7w75e9w4YhhVxT2v7QaEXnM6QesNLXVbWBTrS+k9BRnGP x9Jn72CsEsX4Wre4GWEBvwmczMsWSNBzrOkj+xYsUo9rw0b3etnURdeB73+2rueGfQfc QeiQ== 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:mime-version:content-transfer-encoding; bh=F9DOx3uElvZGGYKZ1NnUJKaxOFOmNphkke/IFoVulBE=; b=OYZV5GNel1CiW6rFrF3P0lvxyawOzyaynm7na8mhjwAKGOtlR7sZwolpOEaUanyuvE XO2bzDUYawTTyw9KNKRIBta91jBo6UwJmeIwvBNISRSeFsPgT4vdPsmrgMoY5s3vre7s ifFOLoAPr+imIppJGGtbZpKKR3wmJJnl3k2VchleqYcexNJSMTITLPpm9isSlgsI5BE6 WS8QuPq/mvU7O2+W/ApX7IjBQQwIC4uWb5r9G8uQYoV2plwi+kBLYEhhb3hM3FFHxMEz 5C8YRJPxSktWj7da7rbBriL6UqVPZMzMkp0jPpGos+XT+4gPBFITxHXzfJAS/erkhRkY GDyg== X-Gm-Message-State: AOAM531vyeYKXqlrALeEVM6H+n71xYwWog4q4BYxmWMdDQ4BqPZY2Cvb x4JkxVjWMdnO8I7FJVME5W8joQ== X-Received: by 2002:a17:902:694b:b0:143:722f:91c1 with SMTP id k11-20020a170902694b00b00143722f91c1mr41351plt.68.1636421603885; Mon, 08 Nov 2021 17:33:23 -0800 (PST) Received: from localhost.localdomain ([2400:4050:c3e1:100:e857:cfcb:a6ed:9a8]) by smtp.gmail.com with ESMTPSA id v10sm4946589pfg.162.2021.11.08.17.33.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 17:33:23 -0800 (PST) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Cc: sjg@chromium.org, ilias.apalodimas@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RFC 2/3] efi_loader: bootmgr: add booting from removable media Date: Tue, 9 Nov 2021 10:32:32 +0900 Message-Id: <20211109013233.72902-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211109013233.72902-1-takahiro.akashi@linaro.org> References: <20211109013233.72902-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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.103.2 at phobos.denx.de X-Virus-Status: Clean Under the current implementation, booting from removal 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 --- lib/efi_loader/efi_bootmgr.c | 65 +++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 1fe19237f9a6..1d9d5858561f 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -30,6 +30,66 @@ static const struct efi_runtime_services *rs; * should do normal or recovery boot. */ +#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" +#else +#define BOOTEFI_NAME "dummy.efi" +#endif + +/** + * 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); + } else { + full_path = efi_dp_dup(device_path); + } + efi_free_pool(dp); + } else { + full_path = efi_dp_dup(device_path); + } + + return full_path; +} + /** * try_load_entry() - try to load image for boot option * @@ -68,13 +128,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);