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 X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4FD8CC433EF for ; Fri, 10 Sep 2021 00:51:03 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 8366E60F6B for ; Fri, 10 Sep 2021 00:51:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8366E60F6B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A709E833B3; Fri, 10 Sep 2021 02:51:00 +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="YzZEcjaH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 614C0833B3; Fri, 10 Sep 2021 02:50:58 +0200 (CEST) Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) (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 A6F5B8334B for ; Fri, 10 Sep 2021 02:50:53 +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=takahiro.akashi@linaro.org Received: by mail-pj1-x102e.google.com with SMTP id g13-20020a17090a3c8d00b00196286963b9so287982pjc.3 for ; Thu, 09 Sep 2021 17:50:53 -0700 (PDT) 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=AzrOboNMWeZlYr1Rd7NLSIZP7q/hxPfawuk0GulkhCc=; b=YzZEcjaHEWfZKhEVLiXi7Y1jaQ69Z4yyqX8cQMa8fX37KeesiWySMqS2JaJU15i+A7 MKf0eCeEFdysqVVUDyCKzNSATCF2A+W3JHmRaxuUXBpucqvM3xc6V8g6nMG8O9vklbvF FCbC4jnXZyVT9ppGaU+egbOm+GyzeoME3R+GkwA5nvJiA7uzbEuQEU/pPfIJS6UNVUOL Vud1uAfM+6HnqgE7YwNp5Dt1zAoCo5BRM09iUlof+X5yYk6wYCBz989gJUFCRGCDTWPn ekdSW2w5qJ2wTCoNpXvpzfVj4h0ma99rCnjLVbSTU21yF+CXEArkYA59bpczr2M8ClVz E1lQ== 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=AzrOboNMWeZlYr1Rd7NLSIZP7q/hxPfawuk0GulkhCc=; b=D2esE7OW88bKh7B3jv1wwO8aQyxWVaYrWYHkIc/BdAqE6d6oHZwaY4PbyRZHnzf0qR FGVeu1T5eXankXLDOr0lfzu5XFM+eEoEFEhMPg475azhlkb+v9lXd9FfGQ3klqnpdLpO MFFN5QaOo/AtYlwXf7Ok+S+u/GkTMO3jG+ZIoPVKc03M17HHyiA280o7CYXhta6oIFWz AMHns7eS5wF5c4c0RE+utlwiJGNm0bcjn3K0B9tqXCn/TbyqnAgITh28ZcpOAk5LmB8+ 1RgyBxYDuLvNrg10OFo2pnCYhdrjJepznEcyic3N/D859ADy3TAkMcT8HQXfPwhE5vO3 yJng== X-Gm-Message-State: AOAM532sdvkpCIee4VQVJ10Xz3rtau/gSReaQUATJwN39Z26zR2EtjA8 VBpweZj2e/nRo5CcDRppjBE1FA== X-Google-Smtp-Source: ABdhPJwrn7I2nIVR7b1Y7UxVrG1r5XwdgNDqXm4VlbzOTA80iRnpCtOmm6aWn1yKDpgpIVzvlibN/Q== X-Received: by 2002:a17:90a:44:: with SMTP id 4mr6585740pjb.130.1631235051635; Thu, 09 Sep 2021 17:50:51 -0700 (PDT) Received: from laputa (p784a2304.tkyea130.ap.so-net.ne.jp. [120.74.35.4]) by smtp.gmail.com with ESMTPSA id d11sm3153655pjx.12.2021.09.09.17.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 17:50:51 -0700 (PDT) Date: Fri, 10 Sep 2021 09:50:46 +0900 From: AKASHI Takahiro To: Simon Glass Cc: Heinrich Schuchardt , U-Boot Mailing List , Ilias Apalodimas , Bin Meng , Tom Rini , Christian Melki , Alexander Graf Subject: Re: [PATCH 14/35] efi: Locate all block devices in the app Message-ID: <20210910005046.GA42777@laputa> Mail-Followup-To: AKASHI Takahiro , Simon Glass , Heinrich Schuchardt , U-Boot Mailing List , Ilias Apalodimas , Bin Meng , Tom Rini , Christian Melki , Alexander Graf References: <20210908133405.696481-1-sjg@chromium.org> <20210908073355.14.I0774d3540ebe726f31838b851815e829fb6a4056@changeid> <2924c018-6a5b-4261-cff3-0ad1a416ef98@gmx.de> <20210909011140.GA56666@laputa> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 On Thu, Sep 09, 2021 at 02:09:12PM -0600, Simon Glass wrote: > Hi Takahiro, > > On Wed, 8 Sept 2021 at 19:11, AKASHI Takahiro > wrote: > > > > Hi Simon, > > > > On Wed, Sep 08, 2021 at 08:14:30PM +0200, Heinrich Schuchardt wrote: > > > On 9/8/21 3:33 PM, Simon Glass wrote: > > > > When starting the app, locate all block devices and make them available > > > > to U-Boot. This allows listing partitions and accessing files in > > > > filesystems. > > > > > > > > EFI also has the concept of 'disks', meaning boot media. For now, this > > > > is not obviously useful in U-Boot, but add code to at least locate these. > > > > This can be expanded later as needed. > > > > > > UEFI firmware handles with the EFI_BLOCK_IO_PROTOCOL for raw access to > > > disks and partitions. It further provides the > > > EFI_SIMPLE_FILE_SYSTEM_PROTOCOL on these handles to access files on > > > formatted media. > > > > Do you want to implement "efifs" as a U-Boot's file system on top of > > SIMPLE_FILE_SYSTEM_PROTO? > > Just kidding. > > Eek. > > > > > I have one concern: > > > > > > > > > > Signed-off-by: Simon Glass > > > > --- > > > > > > > > include/efi.h | 15 ++++++ > > > > include/efi_api.h | 15 ++++++ > > > > lib/efi/efi_app.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++ > > > > 3 files changed, 149 insertions(+) > > > > > > > > diff --git a/include/efi.h b/include/efi.h > > > > index 0ec5913ddd1..c0fddf7f6cd 100644 > > > > --- a/include/efi.h > > > > +++ b/include/efi.h > > > > @@ -529,4 +529,19 @@ void efi_putc(struct efi_priv *priv, const char ch); > > > > */ > > > > int efi_info_get(enum efi_entry_t type, void **datap, int *sizep); > > > > > > > > +/** > > > > + * efi_bind_block() - bind a new block device to an EFI device > > > > + * > > > > + * Binds a new top-level EFI_MEDIA device as well as a child block device so > > > > + * that the block device can be accessed in U-Boot. > > > > + * > > > > + * The device can then be accessed using 'part list efi 0', 'fat ls efi 0:1', > > > > + * for example, just like any other interface type. > > > > + * > > > > + * @handle: handle of the controller on which this driver is installed > > > > + * @blkio: block io protocol proxied by this driver > > > > + * @return 0 if OK, -ve on error > > > > + */ > > > > +int efi_bind_block(efi_handle_t handle, struct efi_block_io *blkio); > > > > + > > > > #endif /* _LINUX_EFI_H */ > > > > diff --git a/include/efi_api.h b/include/efi_api.h > > > > index c8f959bb720..0e88b3e5dbe 100644 > > > > --- a/include/efi_api.h > > > > +++ b/include/efi_api.h > > > > @@ -1994,4 +1994,19 @@ struct efi_firmware_management_protocol { > > > > const u16 *package_version_name); > > > > }; > > > > > > > > +#define EFI_DISK_IO_PROTOCOL_GUID \ > > > > + EFI_GUID(0xce345171, 0xba0b, 0x11d2, 0x8e, 0x4f, \ > > > > + 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b) > > > > + > > > > +struct efi_disk { > > > > + u64 revision; > > > > + efi_status_t (EFIAPI *read_disk)(struct efi_disk *this, u32 media_id, > > > > + u64 offset, efi_uintn_t buffer_size, > > > > + void *buffer); > > > > + > > > > + efi_status_t (EFIAPI *write_disk)(struct efi_disk *this, u32 media_id, > > > > + u64 offset, efi_uintn_t buffer_size, > > > > + void *buffer); > > > > +}; > > > > + > > > > #endif > > > > diff --git a/lib/efi/efi_app.c b/lib/efi/efi_app.c > > > > index f61665686c5..9ba48517422 100644 > > > > --- a/lib/efi/efi_app.c > > > > +++ b/lib/efi/efi_app.c > > > > @@ -21,6 +21,9 @@ > > > > #include > > > > #include > > > > #include > > > > +#include > > > > +#include > > > > +#include > > > > > > > > DECLARE_GLOBAL_DATA_PTR; > > > > > > > > @@ -46,6 +49,33 @@ int efi_info_get(enum efi_entry_t type, void **datap, int *sizep) > > > > return -ENOSYS; > > > > } > > > > > > > > +/** > > > > + * Create a block device so U-Boot can access an EFI device > > > > + * > > > > + * @handle: EFI handle to bind > > > > + * @blkio: block io protocol > > > > + * Return: 0 = success > > > > + */ > > > > +int efi_bind_block(efi_handle_t handle, struct efi_block_io *blkio) > > > > +{ > > > > + struct efi_media_plat plat; > > > > + struct udevice *dev; > > > > + char name[18]; > > > > + int ret; > > > > + > > > > + plat.handle = handle; > > > > + plat.blkio = blkio; > > > > + ret = device_bind(dm_root(), DM_DRIVER_GET(efi_media), "efi_media", > > > > + &plat, ofnode_null(), &dev); > > > > + if (ret) > > > > + return log_msg_ret("bind", ret); > > > > + > > > > + snprintf(name, sizeof(name), "efi_media_%x", dev_seq(dev)); > > > > + device_set_name(dev, name); > > > > + > > > > + return 0; > > > > +} > > > > + > > > > static efi_status_t setup_memory(struct efi_priv *priv) > > > > { > > > > struct efi_boot_services *boot = priv->boot; > > > > @@ -105,6 +135,95 @@ static void free_memory(struct efi_priv *priv) > > > > global_data_ptr = NULL; > > > > } > > > > > > > > +static int setup_disks(void) > > > > +{ > > > > + /* This is not fully implemented yet */ > > > > + return 0; > > > > + > > > > + efi_guid_t efi_disk_guid = EFI_DISK_IO_PROTOCOL_GUID; > > > > + struct efi_boot_services *boot = efi_get_boot(); > > > > + struct efi_disk *disk; > > > > + int ret; > > > > + > > > > + if (!boot) > > > > + return log_msg_ret("sys", -ENOSYS); > > > > + ret = boot->locate_protocol(&efi_disk_guid, NULL, (void **)&disk); > > > > + if (ret) > > > > + return log_msg_ret("prot", -ENOTSUPP); > > > > + > > > > + return 0; > > > > +} > > > > + > > > > +static int setup_block(void) > > > > +{ > > > > + efi_guid_t efi_blkio_guid = EFI_BLOCK_IO_PROTOCOL_GUID; > > > > + efi_guid_t efi_devpath_guid = EFI_DEVICE_PATH_PROTOCOL_GUID; > > > > + struct efi_boot_services *boot = efi_get_boot(); > > > > + struct efi_block_io *blkio; > > > > + struct efi_device_path device_path; > > > > + efi_handle_t handle[100]; > > > > + efi_uintn_t buf_size; > > > > + int num_handles; > > > > + int ret, i; > > > > + > > > > + if (!boot) > > > > + return log_msg_ret("sys", -ENOSYS); > > > > + > > > > + buf_size = sizeof(handle); > > > > + ret = boot->locate_handle(BY_PROTOCOL, &efi_blkio_guid, NULL, > > > > + &buf_size, handle); > > > > > > You could use LocateHandleBuffer() here which will allocate enough > > > memory for all matching handles. > > > > > > > + if (ret) > > > > + return log_msg_ret("loc", -ENOTSUPP); > > > > + > > > > + num_handles = buf_size / sizeof(efi_handle_t); > > > > + log_info("Found %d EFI handles\n", num_handles); > > > > + > > > > + for (i = 0; i < num_handles; i++) { > > > > + ret = boot->handle_protocol(handle[i], &efi_devpath_guid, > > > > + (void **)&device_path); > > > > > > > > > Why do you read the devicepath if you don't use it? > > > > > > > + if (ret) { > > > > + log_warning("- devpath %d failed (ret=%d)\n", i, ret); > > > > + continue; > > > > + } > > > > > > Here some analysis of devicepaths and installed protocols is missing to > > > find out which of the handles represents a block device and which > > > represents a partition: > > > > > > If the last devicepath node is type 4 , Media Device Path with SubType 1 > > > Hard Drive and the partition number is non-zero it is a partition. > > > > > > If the devicepath without the last node relates to a handle with the > > > EFI_BLOCK_IO_PROTOCOL, this also indicates that the current handle is > > > for a partition. > > > > > > Best regards > > > > > > Heinrich > > > > > > > + > > > > + ret = boot->handle_protocol(handle[i], &efi_blkio_guid, > > > > + (void **)&blkio); > > > > + if (ret) { > > > > + log_warning("- blkio %d failed (ret=%d)\n", i, ret); > > > > + continue; > > > > + } > > > > + > > > > + ret = efi_bind_block(handle[i], blkio); > > > > Here you are trying to create a U-Boot block device for > > every UEFI block device (i.e.BLOCK_IO_PROTOCOL interface), > > but please remember that U-Boot UEFI has created UEFI block devices > > for all the existing U-Boot block devices at the initialization time. > > Do you mean with EFI_LOADER? This code is for U-Boot as an app, where > EFI_LOADER is disabled, at least at present. Ah ok, but in this patch series, you touched some files under lib/efi_loader and lib/efi_driver and I thought you have assumed the option as well. So your patch#11 are fully independent from the rest. -Takahiro Akashi > > > > So any physical disk may end up having one (original) U-Boot block device > > and another U-Boot block device rooted in UEFI object (and > > yet another U-Boot block device rooted in the second one and so on?). > > Hopefully that is not an issue, for now. We will need to figure it out > later, if we enable EFI_LOADER. > > Regards, > Simon > > [..]