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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT 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 EC8CAC433EF for ; Wed, 8 Sep 2021 13:37:20 +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 75F9F61167 for ; Wed, 8 Sep 2021 13:37:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 75F9F61167 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.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 8FD78833B0; Wed, 8 Sep 2021 15:35:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="gcFyH8C6"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6BD40833B0; Wed, 8 Sep 2021 15:34:47 +0200 (CEST) Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) (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 197448336D for ; Wed, 8 Sep 2021 15:34:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-wr1-x42d.google.com with SMTP id i28so3372363wrb.2 for ; Wed, 08 Sep 2021 06:34:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xFXnEx5U48Qj2XXBSnO6DhvgYPE4zzR6OxbdsQSAiL8=; b=gcFyH8C6Pym858D2NLBK8LywDPxzKgd8CuwdxDxmW/gn+Vu8xfQkjrKoiQ5yVL6oAt WlgOIaCEHqaVtALUGrPuZsiOrsDlYh6myovDufKGW+Tlk53+I6OAMFuIZg9tQ191q8gu Z2rPVqVF04Ge1JvUvrxD/IU6aZTtXZ/9T8FqY= 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=xFXnEx5U48Qj2XXBSnO6DhvgYPE4zzR6OxbdsQSAiL8=; b=QqEFWc6tXeYtbIGm/2bn6PrYLaflu7X76vB99exra70B0zUnzcLzFIrpoRHglcN89V jp0p6NZqn/2pUGBqbUwHd17KfaQ+rFeC4JwbP0mBzJP2GTF8yAA+CBjaHEpCVdpkluK1 CBqaXjE9DruqBtwf8lVwNayFHPMLr3vle8JmUj8ZBU6YqZWCKIw8kkwCvqTw72uHMxRN UD0eFb56W0hBrZLqrQ92iYRTvzzocY3IVZmVWPA/3koBKSi2aqx6/1kDCSK8FW+9RJwK x76p8gPpyyOLsGJu4QfX/mhVzKcJi6qqLkIMDW8LfxIQX2GrpFTawzsY2/MybN00U4DE d3Fw== X-Gm-Message-State: AOAM532QUW39RdG6k0DceJEQE+rcHMz3FxlL4OPFmMXfxD6jZPgde439 hQeOQvUjyO+45Qyh1kb7gIVgGW+aFzumfvUL X-Google-Smtp-Source: ABdhPJzruqlQOQhMPwKoz6SrUuozVfO6SVlOFYBuXkNEjhK/Nk2bAB359H7ButIijPBAirDIC3dbZg== X-Received: by 2002:adf:916f:: with SMTP id j102mr4128437wrj.422.1631108077265; Wed, 08 Sep 2021 06:34:37 -0700 (PDT) Received: from sjg1.roam.corp.google.com (82-69-54-180.dsl.in-addr.zen.co.uk. [82.69.54.180]) by smtp.gmail.com with ESMTPSA id l2sm2209065wmi.1.2021.09.08.06.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 06:34:36 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Ilias Apalodimas , Heinrich Schuchardt , Bin Meng , Tom Rini , Christian Melki , Simon Glass , Alexander Graf Subject: [PATCH 14/35] efi: Locate all block devices in the app Date: Wed, 8 Sep 2021 07:33:44 -0600 Message-Id: <20210908073355.14.I0774d3540ebe726f31838b851815e829fb6a4056@changeid> X-Mailer: git-send-email 2.33.0.153.gba50c8fa24-goog In-Reply-To: <20210908133405.696481-1-sjg@chromium.org> References: <20210908133405.696481-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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. 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); + 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); + if (ret) { + log_warning("- devpath %d failed (ret=%d)\n", i, ret); + continue; + } + + 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); + if (ret) { + log_warning("- blkio bind %d failed (ret=%d)\n", i, ret); + continue; + } + } + if (ret) + return log_msg_ret("prot", -ENOTSUPP); + + return 0; +} + +int dm_scan_other(bool pre_reloc_only) +{ + if (gd->flags & GD_FLG_RELOC) { + int ret; + + /* Find all block devices and setup EFI devices for them */ + ret = setup_block(); + if (ret) + return ret; + + /* Not needed at present, but could be useful one day? */ + ret = setup_disks(); + if (ret) + return ret; + } + + return 0; +} + /** * efi_main() - Start an EFI image * -- 2.33.0.153.gba50c8fa24-goog