From patchwork Wed Jul 19 00:21:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 704314 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e4d:0:b0:314:25da:8dc4 with SMTP id r13csp1830875wrt; Tue, 18 Jul 2023 17:22:28 -0700 (PDT) X-Google-Smtp-Source: APBJJlFcKTAzXgJBjpTeWLPDnVTUV5ebGKXO/l23hIfuDTz0JmHLxjj3lKNrLMI334jiEbeLZ8JS X-Received: by 2002:a1c:7915:0:b0:3fc:d5:dc14 with SMTP id l21-20020a1c7915000000b003fc00d5dc14mr3020839wme.5.1689726148465; Tue, 18 Jul 2023 17:22:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689726148; cv=none; d=google.com; s=arc-20160816; b=H7gjPJsNsBPhnZx+BtW/WWsiUaz1LacaWyElRTme0PaQL1zoNgr56pC5LCVTM0bvrd f3rhjGAt1WGc1+KFttcOWuBL0D2BB3DDj3PbTPt+bxEDk6ZDn/5nvHKP0taVjHWw/tEN 7ui3Z0S3J384LOqLva0tXNjIz6l8p6AjzM6zamPFjCBvWr6C3E+4UU6PirsNOj1bhZ2U OXqCwrjJk3aSQNbNOjVZYy/Cwdcs1luckOj49GGMRxuwCIjPxzMi6apUL9thrfVqyOZi ybcY0pYHEzY7W113ffjI9r9toCSA2u24HRwGvdlMYhX6T8k1HLb2LYF4YuDd+Km9a2a3 bIjg== 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=JL8yaRJEk0s7nzd4tWYFRXgtEFBAGHVMoVFwwLhlwNU=; b=qVbkSKl9GrGGnE5Ha8Y3Yfgyq4Ve9v51iG7f1stPN9oWpOzvQhkb/OkhOy6/nnbXNY 0xv5xYgwPpEcoeWaB0a8U1aa7rnj1Z5zdvO4TgnhluCnlf5dPbQGYYqBX6BpxluwMHX+ XMg0V7htK1vcz5vHruwTcMpFK0P8Qbj930YK49A39oyv+pBswA2MCX/KxiUjmQk10Ycz t7s/YnRQHjcVp+EJkVLVBHmcJsR9YK1N0X88Uj6rEmE/pWvKbqigT9QFUi31x824ei7e X5DAMgnEEvo2D7FakmS0YEt748J1v1Qy4BJDrf8Xvt/6CBFWOlpITAVjnSQitq9cff+1 ismw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gR6xHAze; 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 z12-20020a05600c0a0c00b003fbc38557e0si186265wmp.161.2023.07.18.17.22.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jul 2023 17:22:28 -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=gR6xHAze; 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 D0EEC863A4; Wed, 19 Jul 2023 02:22:26 +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="gR6xHAze"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B1A05863A4; Wed, 19 Jul 2023 02:22:24 +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-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) (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 B006986205 for ; Wed, 19 Jul 2023 02:22:21 +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-x1030.google.com with SMTP id 98e67ed59e1d1-262ee777d1cso1149445a91.1 for ; Tue, 18 Jul 2023 17:22:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689726140; x=1690330940; 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=gR6xHAze+pnIcuwC/zB+HSR7kSr0FH68TOmvPHiYhG19xXnhcIJUZPBbWfo8ek3BW2 UCJdTrSLI61Dbe5zCQ19z8XbHaDYagXZWDCScGsYAzb7F6oi5RiXVcwm9DwC/kSOIxgN aMPRTW5uTecJFGzGsYQS4wf29fy0vEX+vaw9YJXifxv60IBturAVgYthO4iso1x5pNdv +QDjNSriLKtohe3bI1OOmoKs53bHgyq38mkhyObclgruTZb+3ivwPbfzszUI0ixn1mL4 dnNBqX8DMilHNlrbWTbf8R/S6B1Gi0SDki48Q2MJGjanRGBV4HUKXoXZ3rnTjhfMLQU0 y3GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689726140; x=1690330940; 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=YAr5cbP1CduwvZWTJLKrJ2GpjSyfyB3JAriLadxIcSZdVIBgcGV6/7/YU6EhOTCDKE BnUWQ5NLQGn6qNKz0TfgA/ByQ/RpQqf0KZ6CRLS4zMuZnnR91E+dmnRyJfKZy+6EdC9B GDgPENISXQ6jxngaG0ZyF60VjZidp6r1O/RxsPEHQBhfSshxQhDv8RJOphPaGkeJKvUW dNZnU+hGcRXA4IokkpYxI0HjIAn84KtlHSlJ61n6CNc3p0fIUkPeluiZYlpp3xwP+4jZ s3ZtIMYOvrdTKHFZXM0lOhd1veo2FiCS1IfHbKSYB7JCt4dV8YOBq64z1ZQlPczIGIwR aksw== X-Gm-Message-State: ABy/qLbn53JT+vYbx/BDTPGczEG5GBKlJu/gzXxsq/N920N5yBor7eui dfhellhMnlt3Y/Fa+vki29Vg0g== X-Received: by 2002:a17:90b:3c47:b0:263:e4bb:1367 with SMTP id pm7-20020a17090b3c4700b00263e4bb1367mr11347092pjb.0.1689726139803; Tue, 18 Jul 2023 17:22:19 -0700 (PDT) Received: from laputa.. ([2400:4050:c3e1:100:21dc:6a82:5204:1378]) by smtp.gmail.com with ESMTPSA id 28-20020a17090a031c00b00262fc84b931sm137763pje.44.2023.07.18.17.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jul 2023 17:22:19 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, sjg@chromium.org Cc: masahisa.kojima@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RFC] efi_driver: fix a parent issue in efi-created block devices Date: Wed, 19 Jul 2023 09:21:58 +0900 Message-ID: <20230719002158.27004-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; }