From patchwork Thu Aug 28 02:07:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 153 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756346887; bh=H15k7AWv2SQgj/yFJZnIJjLsSvg9FT7x1JTl8GBN4uI=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=QFKPTt5xr295vYgIYy7lSOmUON5iBjrsluPKsE3jgtLEHCQGHaHE5pRNPhvhl2K4M HnkjkKJZfhYVU5nfe64vr48wGO0CQQ3FwwtwShyFn3mfaaFwBohbUCBb1tDg8yMgDu Ox2mZQ9tESV4rQsgxjxNYfyb+RjpPlVAR5aVJLYfN7jFGTXGY4iXcP8ZyRga+VI2yz Fqvg68v3ZknNd5Cpc+OD1yCF+iR0Ya7lrd3IeGvm/md2GXTn66YiRo4zRBV4qz6W/G yLwEtUjazidL9EwVvW33dF4ihxg1oSVK7JiA8HqalwNpCsrAqAsrofG3L1D/8oEX2t UIJP7cpm+VAgw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E3997677B6 for ; Wed, 27 Aug 2025 20:08:07 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id T50dUAnZ3Sqo for ; Wed, 27 Aug 2025 20:08:07 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756346887; bh=H15k7AWv2SQgj/yFJZnIJjLsSvg9FT7x1JTl8GBN4uI=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=QFKPTt5xr295vYgIYy7lSOmUON5iBjrsluPKsE3jgtLEHCQGHaHE5pRNPhvhl2K4M HnkjkKJZfhYVU5nfe64vr48wGO0CQQ3FwwtwShyFn3mfaaFwBohbUCBb1tDg8yMgDu Ox2mZQ9tESV4rQsgxjxNYfyb+RjpPlVAR5aVJLYfN7jFGTXGY4iXcP8ZyRga+VI2yz Fqvg68v3ZknNd5Cpc+OD1yCF+iR0Ya7lrd3IeGvm/md2GXTn66YiRo4zRBV4qz6W/G yLwEtUjazidL9EwVvW33dF4ihxg1oSVK7JiA8HqalwNpCsrAqAsrofG3L1D/8oEX2t UIJP7cpm+VAgw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D0DDC6777E for ; Wed, 27 Aug 2025 20:08:07 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756346885; bh=wyswUlvWuQKbY864wSAiE9lgAZJKbp4wyEGLZW0JzQs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WLMDbOyTaIOwpsjHGPghh29g4tU0fYUPU5E6D3WAA8PUz79mCQ5YMMK5CmknTufRh 7DfSlh6RJ4S31CiecXY2bsplJidH0W16Xj6dKXDCns3F4gTLczoJ9USIcoeIk7bYml 04IOWN9XdvMPyJNpqq8mQV6cqlQ0gzHGpEg3jYmmIY20VRt8/MlH07ZJFXjyjlx4dS QLLUasyc8VWVdhnLUD97iIykv6/9PaIAhHj3Nd2zPd5El2sw7pVtiWWD7MtnkPjjZF IOE4vVrpSRW8ue0qsav/WWp37ARCect5Yv40bW9biCJ8SpQ8QffOWOecWsskKK9qTy SKHBthAJN7bIA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A26EC6777F; Wed, 27 Aug 2025 20:08:05 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id cv0d86qU7QHx; Wed, 27 Aug 2025 20:08:05 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756346878; bh=yZkFoJGjMt59yO64C0kOUu/vKxpLHA77hfPyG/ZyMZE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gBKnfYFLfy3InwbbM+27eSc8wx7DOKIsR+EBUe2AWQj8dwahIiZCzh+XrFRF8JJpK Vxg0TEkXFyDQyV1kWHbSYQtk7fZmUyck6KWThYNE4J1wqwvPz0M+/kInzIcg4LJOgb hdWOO2y32TuUbH0ecAo7fPsmtc9vZYr4QzbBiZ2MaNeMr04KBuIWvaY1tNYwCkRSZV MsWmJHgBWlhqAuNykNi9+Er0mO2BhTJcE1TzBZ3AkEFGsEZl5Yb6zsfwtMwAI8/wmJ iUb/ElxxJVD5H1TrMAxrHnvQhcKAXReu/44JczawNtN0oLSbDtO4x0XwYxq4dOt6fZ O4F9ch4mC3wnA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 70A10677B6; Wed, 27 Aug 2025 20:07:58 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Wed, 27 Aug 2025 20:07:13 -0600 Message-ID: <20250828020732.981415-11-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250828020732.981415-1-sjg@u-boot.org> References: <20250828020732.981415-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: NUWOEOJLVM2I36UWHKLCZ3AVHOQQO6UM X-Message-ID-Hash: NUWOEOJLVM2I36UWHKLCZ3AVHOQQO6UM X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 10/20] boot: Show the device path for EFI bootflows List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass If the bootflow relates to the EFI bootmeth, show the device path along with the other info. Signed-off-by: Simon Glass --- cmd/bootflow.c | 17 +++++++++++++++++ include/efi.h | 15 +++++++++++++++ include/efi_device_path.h | 14 ++++++++++++++ lib/efi/device_path.c | 37 +++++++++++++++++++++++++++++++++++++ lib/efi_client/app_run.c | 18 ++++++++++++++++++ 5 files changed, 101 insertions(+) diff --git a/cmd/bootflow.c b/cmd/bootflow.c index 464c3e40475..ae692cf521b 100644 --- a/cmd/bootflow.c +++ b/cmd/bootflow.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -453,6 +454,22 @@ static int do_bootflow_info(struct cmd_tbl *cmdtp, int flag, int argc, printf("FDT addr: %lx\n", bflow->fdt_addr); } printf("Error: %d\n", bflow->err); + if (IS_ENABLED(CONFIG_BOOTMETH_EFI) && + bflow->method->driver == DM_DRIVER_GET(bootmeth_4efi)) { + struct efi_device_path *dp; + bool alloced; + + ret = efi_dp_from_bootflow(bflow, &dp, &alloced); + printf("EFI path "); + if (!ret) { + printf("%pD\n", dp); + if (alloced) + efi_free_pool(dp); + } else { + printf("(err %dE)\n", ret); + } + } + if (dump && bflow->buf) { /* Set some sort of maximum on the size */ int size = min(bflow->size, 10 << 10); diff --git a/include/efi.h b/include/efi.h index 3558c03db23..c07717811da 100644 --- a/include/efi.h +++ b/include/efi.h @@ -23,6 +23,8 @@ #include #endif +struct udevice; + /* Type INTN in UEFI specification */ #define efi_intn_t ssize_t /* Type UINTN in UEFI specification*/ @@ -848,4 +850,17 @@ efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size, struct efi_device_path *dp_dev, struct efi_device_path *dp_img); +/** + * efi_dp_from_bootdev() - Get the device path from a bootdev + * + * This is only available in the app. It looks up the bootdev and returns the + * assocated device path (attached to its sibling block device) + * + * @dev: UCLASS_BOOTDEV device to check + * @dpp: Returns device path on success + * Returns: 0 if OK, -ve on error + */ +int efi_dp_from_bootdev(const struct udevice *dev, + const struct efi_device_path **dpp); + #endif /* _LINUX_EFI_H */ diff --git a/include/efi_device_path.h b/include/efi_device_path.h index 2e425a6d82b..d030674d6bd 100644 --- a/include/efi_device_path.h +++ b/include/efi_device_path.h @@ -12,6 +12,7 @@ enum uclass_id; struct blk_desc; +struct bootflow; struct efi_load_option; struct udevice; @@ -429,4 +430,17 @@ struct efi_device_path *efi_dp_from_http(const char *server, const char *efi_dp_guess_uclass(struct efi_device_path *device_path, enum uclass_id *guessp); +/** + * efi_dp_from_bootflow() - Get the device path for a bootflow + * + * @bflow: Bootflow to check + * @dpp: Returns the device path + * @allocedp: if NULL, no allocation is permitted, otherwise retrusn true if + * efi_free_pool() must be called to free the device path + * Return: 0 if OK, -EINVAL if @allocedp is NULL and allocation is needed, + * -ve on error + */ +int efi_dp_from_bootflow(const struct bootflow *bflow, + struct efi_device_path **dpp, bool *allocedp); + #endif /* EFI_DEVICE_PATH_H */ diff --git a/lib/efi/device_path.c b/lib/efi/device_path.c index 191d58bbd2d..bae9e5c537a 100644 --- a/lib/efi/device_path.c +++ b/lib/efi/device_path.c @@ -8,6 +8,7 @@ #define LOG_CATEGORY LOGC_EFI #include +#include #include #include #include @@ -1376,3 +1377,39 @@ const char *efi_dp_guess_uclass(struct efi_device_path *device_path, return best_name; } +int efi_dp_from_bootflow(const struct bootflow *bflow, + struct efi_device_path **dpp, bool *allocedp) +{ + struct udevice *bdev = bflow->dev; + struct blk_desc *desc; + struct udevice *blk; + int ret; + + if (IS_ENABLED(CONFIG_EFI_APP)) { + const struct efi_device_path *dpc; + + ret = efi_dp_from_bootdev(bflow->dev, &dpc); + if (ret) + return log_msg_ret("dfa", ret); + *dpp = (struct efi_device_path *)dpc; + if (allocedp) + *allocedp = false; + } else { + struct efi_device_path *dp; + + if (!allocedp) + return log_msg_ret("dfb", -EINVAL); + ret = bootdev_get_sibling_blk(bdev, &blk); + if (ret) + return log_msg_ret("dfc", ret); + + desc = dev_get_uclass_plat(blk); + dp = efi_dp_from_part(desc, bflow->part); + if (!dp) + return log_msg_ret("dfd", -ENOMEM); + *allocedp = true; + *dpp = dp; + } + + return 0; +} diff --git a/lib/efi_client/app_run.c b/lib/efi_client/app_run.c index 03cc29778d8..9fc753ceed8 100644 --- a/lib/efi_client/app_run.c +++ b/lib/efi_client/app_run.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -89,3 +90,20 @@ efi_status_t efi_binary_run_dp(void *image, size_t size, void *fdt, { return efi_run_image(image, size, dp_dev, dp_img); } + +int efi_dp_from_bootdev(const struct udevice *dev, + const struct efi_device_path **dpp) +{ + const struct udevice *media = dev_get_parent(dev); + const struct efi_media_plat *plat; + + log_debug("dev '%s': uclass ID %d\n", media->name, + device_get_uclass_id(media)); + if (device_get_uclass_id(media) != UCLASS_EFI_MEDIA) + return log_msg_ret("efb", -ENOTSUPP); + + plat = dev_get_plat(media); + *dpp = plat->device_path; + + return 0; +}