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 71D1DC433EF for ; Mon, 4 Apr 2022 06:49:43 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EB97E83D4D; Mon, 4 Apr 2022 08:49:39 +0200 (CEST) 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="VXazIBxu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9316083D57; Mon, 4 Apr 2022 08:49:30 +0200 (CEST) Received: from mail-yw1-x112c.google.com (mail-yw1-x112c.google.com [IPv6:2607:f8b0:4864:20::112c]) (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 3267F83D40 for ; Mon, 4 Apr 2022 08:49:10 +0200 (CEST) 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-yw1-x112c.google.com with SMTP id 00721157ae682-2eb46d33db9so35253417b3.12 for ; Sun, 03 Apr 2022 23:49:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Kz/yp7No1zytSJJbe2c/SB0jyn8aytFrnLmazMyFe6c=; b=VXazIBxu1n2knn49tT8i/NbFMCEF2f4qxDIEa9TWDC2fchB5PROX5q23kkPGWartR4 0GyqiNONMIi2jwa37ctXHkU1J03Dq+s6pzxaCrRu0sY5QR35HbEtL0I7g+TSM9W+xWB6 p8uOldE5ej9TCoxoXufNN41R3HDDIXCByTySEYXFQEgYtSUPcC0fhkUKbXhblBqV79o+ YKetMoQZKmE2m1E9HnjU+YWIETZpVTxKT4OWGYfCQ1gHvBx5MlYDNjzjpOhyd8f8pZ68 ZouN8GiDy1G2r6w805aLm5yoUrCm4QGGGVIdvYhZThLuVM/07BlWNzD7p7S4yEsrjbsz XA7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Kz/yp7No1zytSJJbe2c/SB0jyn8aytFrnLmazMyFe6c=; b=TDA1udRDeHahIwdC6rjek6HCDUr7QZJUjUgtcEvOI+cObVwgJiiLVR7i32Pg15m0qC 0TONTDiozhTHkNEqx4bNKccjxzGza4AjAf6DYteWSz9VOYotHrsyq7drKYYXx9os8iVi QJC3YLi9nzhtk2+RdxBXXw15hCGtFl/AnDP+YCODwjx+Cue4RXFAUB/OVaVZty74iGaW 8GcJkEBYQZgZCVrSjL+6pZnMmcq26GYiETfNzd+MQY1jxwSFjAM1HjAInUyz0M6M0pQO 7gclZFIL8dcot4dTANbkJNqOqP1+aj7jBpuw+oUcLmovNGrRE3JzeF6BJWFQsu+2Nvn0 W2hQ== X-Gm-Message-State: AOAM531rYxALIt3OhNpqGeaJxqtorsKgkClhYIwliW7YmJ8CcPUAS00C /4Mzd77E33DkrKQzkDVzibJXILiyyDZBlH2ctaPTDA== X-Google-Smtp-Source: ABdhPJwDMkuR/YJz2TLZEnXp1E2CgfQ2x9ebDIp1tkXs6WUhNe0Qo9i8xyu7DfDMrVZM53WB7y7SNxqHzg7zCI8l8nE= X-Received: by 2002:a0d:ddcf:0:b0:2eb:559f:ddbc with SMTP id g198-20020a0dddcf000000b002eb559fddbcmr5952689ywe.57.1649054926781; Sun, 03 Apr 2022 23:48:46 -0700 (PDT) MIME-Version: 1.0 References: <20220324135443.1571-1-masahisa.kojima@linaro.org> <20220324135443.1571-7-masahisa.kojima@linaro.org> <9adca934-4947-8cf5-591f-4a9b53af47e1@gmx.de> In-Reply-To: <9adca934-4947-8cf5-591f-4a9b53af47e1@gmx.de> From: Masahisa Kojima Date: Mon, 4 Apr 2022 15:48:35 +0900 Message-ID: Subject: Re: [PATCH v4 06/11] efi_loader: bootmgr: add booting from removable media To: Heinrich Schuchardt Cc: u-boot@lists.denx.de, Ilias Apalodimas , Simon Glass , Takahiro Akashi , Francois Ozog , Mark Kettenis , Mark Kettenis , Andre Przywara , Neil Armstrong Content-Type: text/plain; charset="UTF-8" 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 Sat, 2 Apr 2022 at 15:12, Heinrich Schuchardt wrote: > > On 3/24/22 14:54, Masahisa Kojima wrote: > > 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. > > At every boot you will have to delete autogenerated boot options and > create new ones according to the media which are present. > > Your implementation does not offer any possibility to identify > autogenerated boot options. > > On my laptop all autogenerated boot options use a VenMsg() device path > > Boot0016* USB CD > VenMsg(bc7838d2-0f82-4d60-8316-c068ee79d25b,86701296aa5a7848b66cd49dd3ba6a55) > Boot0017* USB FDD > VenMsg(bc7838d2-0f82-4d60-8316-c068ee79d25b,6ff015a28830b543a8b8641009461e49) > Boot0018* NVMe0 > VenMsg(bc7838d2-0f82-4d60-8316-c068ee79d25b,001c199932d94c4eae9aa0b6e98eb8a400) > Boot0019* ATA HDD0 > VenMsg(bc7838d2-0f82-4d60-8316-c068ee79d25b,91af625956449f41a7b91f4f892ab0f600) > Boot001A* USB HDD > VenMsg(bc7838d2-0f82-4d60-8316-c068ee79d25b,33e821aaaf33bc4789bd419f88c50803) > Boot001B* PCI LAN > VenMsg(bc7838d2-0f82-4d60-8316-c068ee79d25b,78a84aaf2b2afc4ea79cf5cc8f3d3803) > > while manual boot options use normal device paths > > Boot0001* debian > HD(2,GPT,54e58b03-c1db-4c6b-afda-24340c3acda5,0x109000,0x32000)/File(\EFI\debian\shimx64.efi) > Boot0002* ubuntu > HD(2,GPT,54e58b03-c1db-4c6b-afda-24340c3acda5,0x109000,0x32000)/File(\EFI\ubuntu\shimx64.efi) > > Please, provide a concept that can differentiate between autogenerated > and manually set boot options. The patch "[PATCH v4 10/11] bootmenu: add removable media entries" [*1] handles this auto generation and auto deletion. # Sorry, I should clearly describe this in the commit message. u"bootmenu" string is stored in EFI_LOAD_OPTION.OptionalData of the autogenerated Boot#### variable, to differentiate the boot options between autogenerated and manually set. # In EDK2 implementation, a special GUID is used for this purpose and GUID is stored in EFI_LOAD_OPTION.OptionalData. # In U-Boot, lib/efi_loader/efi_load_option.c::efi_serialize_load_option() handles the EFI_LOAD_OPTION.OptionalData as u16 string, so I use "bootmenu" string. The example is as below, Boot0003 is an auto generated boot option, and Boot0004 is manually set. ========== Boot0003: attributes: A-- (0x00000001) label: virtio1:2 file_path: /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(63293792-adf5-9325-b99f-4e0e455c1b1e,01)/HD(2,GPT,fb12642d-1b5a-4e31-b074-ba2d813bed71,0x100800,0x18fff) data: 00000000: 62 00 6f 00 6f 00 74 00 6d 00 65 00 6e 00 75 00 b.o.o.t.m.e.n.u. 00000010: 00 00 .. Boot0004: attributes: A-- (0x00000001) label: debian file_path: /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(63293792-adf5-9325-b99f-4e0e455c1b1e,00)/HD(1,GPT,c2475a57-2735-4744-9f01-67fefa1d06ae,0x800,0x100000)/EFI\debian\grubaa64.efi data: ========== In "[PATCH v4 10/11]" [*1], auto generation is handled as follows. 1) bootmenu enumerates the all devices having EFI_SIMPLE_FILE_SYSTEM_PROTOCOL 2) bootmenu compares the device path enumerated in step#1 and existing boot option read from EFI variable 3-a) if the enumerated device path in step#1 already exist in EFI variable, nothing to do. 3-b) if the enumerated device path in step#1 does not exist in EFI variable, boot option is auto generated. 3-c) If the boot option stored in EFI variable with "bootmenu" OptionalData does not appear in the device path enumerated in step#1, this boot option is treated as "invalid" and auto deleted. [*1] https://lore.kernel.org/u-boot/20220324135443.1571-11-masahisa.kojima@linaro.org/ Thanks, Masahisa Kojima > > Best regards > > Heinrich > > > > > 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); >