From patchwork Thu Jul 27 00:29:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 706992 Delivered-To: patch@linaro.org Received: by 2002:a5d:6787:0:b0:317:2194:b2bc with SMTP id v7csp56292wru; Wed, 26 Jul 2023 17:30:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlHUQd6/W+cGeIcQRdN5JkJRVDgFJIV2ge0dp8ebnSsoQKQR0FA5j0U3lRGOoDbUq/klLPjd X-Received: by 2002:a05:600c:b58:b0:3fa:96ad:5d2e with SMTP id k24-20020a05600c0b5800b003fa96ad5d2emr420489wmr.19.1690417818403; Wed, 26 Jul 2023 17:30:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690417818; cv=none; d=google.com; s=arc-20160816; b=anwNzob4RJ4qGSabxR/ycJ62kEnoSQERqK8406UtH6sBvjYa+9/c6K9LC1KIKhZjf7 hxBZ8OHrdP4qdFGqn5XrN7EFe5tUujUNo9qoLlZJhR0/kkr1DC+RHzs0BJ+Umb4iixE6 2yktP2JioyTHRuVvc7mH3SomfSzRynUgdlnQ03XFIrpaOqmvPyFXvM1M8q1FihZzf1ks JQdDEItBx8ezwn4hBxi90jTQL2waY0yI0T+swL9I58214TavvJ2fjR7fnK12NGcU48Sl AMBlVM3d3qOVvhFDd6znX23K7cLyXuvARbJ7UZxLWabiZOBhaMKAHf7Fk6WOG4uaAp8q vUvg== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=DqE4DNAsuEvXOTKusMw0ieO4ScBigz7lRUPTIQ7J43I=; fh=eBXV55+PFECL10OD4xzzShXAjaGCihN3fdp7sn9gPfc=; b=tc2ipdMNM1kuRdPoPIXALlbWrzugmwRqavf8PoKXTRMKiBV6v/PqTVaNBWJgxLaQdJ yWaMMypBp+xE4lGsZTFSK073oFtNV5sq0bcBZF/Qscr6IGyOLkVmnvGub/ATSDRmV6B7 G8eBL+SGiLe9o4mB76ePovaYbfl5Ty0YFK8hzwO1JGok/e7woAXzXdgCmqkPw/Wfzo+R W1OrFyQxdamtvXKZLL25Ium8GLleCQ5MDR4rxz5R5kquZbhdmGnri7HNLo05qqsotYXS LckMzR4mI3hPyOS8bPLIWzluG1HdLfMqaTioAMUoT3+6AlTzysT/YyEVGSRoU99F48if N0IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XjjNxR96; 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 l22-20020a7bc456000000b003fbf11dffe5si1478115wmi.30.2023.07.26.17.30.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 17:30:18 -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=XjjNxR96; 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 6504086373; Thu, 27 Jul 2023 02:30:12 +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="XjjNxR96"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6097E862A9; Thu, 27 Jul 2023 02:30:10 +0200 (CEST) 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-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) (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 2696C865B0 for ; Thu, 27 Jul 2023 02:30:04 +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-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6748a616e17so95237b3a.1 for ; Wed, 26 Jul 2023 17:30:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690417802; x=1691022602; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=DqE4DNAsuEvXOTKusMw0ieO4ScBigz7lRUPTIQ7J43I=; b=XjjNxR96Taph3LNqDfa7nEP4LgPeVgEcDS9Bjlx/83E1nUTmgKP1oWmYnj8FY5aNnz b0AoC1GxgpX0TGEI5nURYuzWraMCIBcD7MpNDwFWrSASDiakGp0qGT6SvhiHKbL80PBq nKiqb/V13C5escmMShoJ9kP16DDG5am+Rh6/jZEvf+hOuGuMlGLGD5oMFwjwfQBnARm0 18Lmcv2Qv6yL0Q9Hy/pcUT8Be7kN2GGrP4fK0Pq0jQrpy4ZUiHb2XXBoRENnyDQprS5j YwrfrlxIWLEGAphawV1eqfcau6hJ35wbJS1p2IvksC6lsLAAkCiPf59PYPjJ3Ry4Ar/+ nKdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690417802; x=1691022602; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DqE4DNAsuEvXOTKusMw0ieO4ScBigz7lRUPTIQ7J43I=; b=K0dS1a4Sxqz/Z0jUg0lzJsfdSu6bJbNgELziiQ907n/FwtMCsC7ply5G5OHUp9pjrr KJ4GZMXSnfFIfhDSEFcJTLytFuiifYMNCrM+/ll6Zt/9J96YrvFGiWJwytR57hkCqVti nDMelj+h9J7sWPREb1g1ZmCz3zVS7iT+6b/d759gb8e0EZiSyyfkMr0zTjcaf+FRc63j FakxRPE1QVeoj5TcFadmiWpeS8F9UIwv/ntXtW4eLxWZ5+FVsdLeWq5nhC1tM1hmAB// sxMIab4qBgU9zK52r7tzPdAUQj/RbBaRF3H9ZmU5arqpH1GIV1buOQDxrOMc96ycHYuB oNRw== X-Gm-Message-State: ABy/qLYVVuozSYOmPbwbNzUlc2AhWbjy8URgVqLlqxwyTkTsDBnYJj4v DAhrcXPC+plk6XYCnDgf2CFv2w== X-Received: by 2002:a17:902:eccc:b0:1b3:d8ac:8db3 with SMTP id a12-20020a170902eccc00b001b3d8ac8db3mr4394202plh.6.1690417801734; Wed, 26 Jul 2023 17:30:01 -0700 (PDT) Received: from laputa.. ([2400:4050:c3e1:100:2103:cbda:74f4:860a]) by smtp.gmail.com with ESMTPSA id e21-20020a170902d39500b001a9b29b6759sm141653pld.183.2023.07.26.17.29.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 17:30:01 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, ilias.apalodimas@linaro.org, michal.simek@amd.com, sughosh.ganu@linaro.org Cc: u-boot@lists.denx.de, AKASHI Takahiro Subject: [RFC] efi_driver: fix a parent issue in efi-created block devices Date: Thu, 27 Jul 2023 09:29:55 +0900 Message-ID: <20230727002955.24940-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean An EFI application may create an EFI block device (EFI_BLOCK_IO_PROTOCOL) in EFI world, which in turn generates a corresponding U-Boot block device based on U-Boot's Driver Model. The latter device, however, doesn't work as U-Boot proper block device due to an issue in efi_driver's implementation. We saw discussions in the past, most recently in [1]. [1] https://lists.denx.de/pipermail/u-boot/2023-July/522565.html This RFC patch tries to address (part of) the issue. If it is considered acceptable, I will create a formal patch. Withtout this patch, ===8<=== => env set efi_selftest 'block device' => bootefi selftest ... Summary: 0 failures => dm tree Class Index Probed Driver Name ----------------------------------------------------------- root 0 [ + ] root_driver root_driver ... bootmeth 7 [ ] vbe_simple | `-- vbe_simple blk 0 [ + ] efi_blk `-- efiblk#0 partition 0 [ + ] blk_partition `-- efiblk#0:1 => ls efiloader 0:1 ** Bad device specification efiloader 0 ** Couldn't find partition efiloader 0:1 ===>8=== With this patch applied, efiblk#0(:1) now gets accessible. ===8<=== => env set efi_selftest 'block device' => bootefi selftest ... Summary: 0 failures => dm tree Class Index Probed Driver Name ----------------------------------------------------------- root 0 [ + ] root_driver root_driver ... bootmeth 7 [ ] vbe_simple | `-- vbe_simple efi 0 [ + ] EFI block driver `-- /VenHw(dbca4c98-6cb0-694d-0872-819c650cb7b8) blk 0 [ + ] efi_blk `-- efiblk#0 partition 0 [ + ] blk_partition `-- efiblk#0:1 => ls efiloader 0:1 13 hello.txt 7 u-boot.txt 2 file(s), 0 dir(s) ===>8=== Signed-off-by: AKASHI Takahiro --- include/efi_driver.h | 2 +- lib/efi_driver/efi_block_device.c | 17 ++++++++++++----- lib/efi_driver/efi_uclass.c | 8 +++++++- lib/efi_selftest/efi_selftest_block_device.c | 2 ++ 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/include/efi_driver.h b/include/efi_driver.h index 63a95e4cf800..ed66796f3519 100644 --- a/include/efi_driver.h +++ b/include/efi_driver.h @@ -42,7 +42,7 @@ struct efi_driver_ops { const efi_guid_t *child_protocol; efi_status_t (*init)(struct efi_driver_binding_extended_protocol *this); efi_status_t (*bind)(struct efi_driver_binding_extended_protocol *this, - efi_handle_t handle, void *interface); + efi_handle_t handle, void *interface, char *name); }; #endif /* _EFI_DRIVER_H */ diff --git a/lib/efi_driver/efi_block_device.c b/lib/efi_driver/efi_block_device.c index add00eeebbea..43b7ed7c973c 100644 --- a/lib/efi_driver/efi_block_device.c +++ b/lib/efi_driver/efi_block_device.c @@ -115,9 +115,9 @@ static ulong efi_bl_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, * Return: status code */ static efi_status_t -efi_bl_create_block_device(efi_handle_t handle, void *interface) +efi_bl_create_block_device(efi_handle_t handle, void *interface, struct udevice *parent) { - struct udevice *bdev = NULL, *parent = dm_root(); + struct udevice *bdev = NULL; efi_status_t ret; int devnum; char *name; @@ -181,7 +181,7 @@ err: */ static efi_status_t efi_bl_bind( struct efi_driver_binding_extended_protocol *this, - efi_handle_t handle, void *interface) + efi_handle_t handle, void *interface, char *name) { efi_status_t ret = EFI_SUCCESS; struct efi_object *obj = efi_search_obj(handle); @@ -191,8 +191,15 @@ static efi_status_t efi_bl_bind( if (!obj || !interface) return EFI_INVALID_PARAMETER; - if (!handle->dev) - ret = efi_bl_create_block_device(handle, interface); + if (!handle->dev) { + struct udevice *parent; + + ret = device_bind_driver(dm_root(), "EFI block driver", name, &parent); + if (!ret) + ret = efi_bl_create_block_device(handle, interface, parent); + else + ret = EFI_DEVICE_ERROR; + } return ret; } diff --git a/lib/efi_driver/efi_uclass.c b/lib/efi_driver/efi_uclass.c index 45f935198874..bf669742783e 100644 --- a/lib/efi_driver/efi_uclass.c +++ b/lib/efi_driver/efi_uclass.c @@ -145,7 +145,13 @@ static efi_status_t EFIAPI efi_uc_start( ret = check_node_type(controller_handle); if (ret != EFI_SUCCESS) goto err; - ret = bp->ops->bind(bp, controller_handle, interface); + + struct efi_handler *handler; + char tmpname[256] = "AppName"; + ret = efi_search_protocol(controller_handle, &efi_guid_device_path, + &handler); + snprintf(tmpname, 256, "%pD", handler->protocol_interface); + ret = bp->ops->bind(bp, controller_handle, interface, strdup(tmpname)); if (ret == EFI_SUCCESS) goto out; diff --git a/lib/efi_selftest/efi_selftest_block_device.c b/lib/efi_selftest/efi_selftest_block_device.c index a367e8b89d17..0ab8e4590dfe 100644 --- a/lib/efi_selftest/efi_selftest_block_device.c +++ b/lib/efi_selftest/efi_selftest_block_device.c @@ -248,6 +248,7 @@ static int teardown(void) { efi_status_t r = EFI_ST_SUCCESS; +#if 0 /* Temporarily out for confirmation */ if (disk_handle) { r = boottime->uninstall_protocol_interface(disk_handle, &guid_device_path, @@ -273,6 +274,7 @@ static int teardown(void) return EFI_ST_FAILURE; } } +#endif return r; }