From patchwork Tue Apr 21 18:34:48 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2234 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=1776796573; bh=feQ7MqF9l2Q0Fyx1VvkTqHISIOAPL69iDG8BS1W9Cxk=; 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=nmhv4nlQC4SzcmmN8AZawLn8+b+XoUESBNCENqXOcIXnApU3ysIlt+b99SNQYh4Yb YfKn+SvPFcbhKaqjhCKUtGTGjveasHGzMBJPjWISIUSWJhsLlUTJt7pXsUGInP/m4j lmdHDuftXSo7xUpeZeEWOqevSNP8T0+Q1tZF0w28= Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9A41F6A60B for ; Tue, 21 Apr 2026 12:36:13 -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 s6YAUQDTljZL for ; Tue, 21 Apr 2026 12:36:13 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1776796573; bh=feQ7MqF9l2Q0Fyx1VvkTqHISIOAPL69iDG8BS1W9Cxk=; 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=nmhv4nlQC4SzcmmN8AZawLn8+b+XoUESBNCENqXOcIXnApU3ysIlt+b99SNQYh4Yb YfKn+SvPFcbhKaqjhCKUtGTGjveasHGzMBJPjWISIUSWJhsLlUTJt7pXsUGInP/m4j lmdHDuftXSo7xUpeZeEWOqevSNP8T0+Q1tZF0w28= Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 88F6D6A604 for ; Tue, 21 Apr 2026 12:36:13 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1776796570; bh=wRfNxOXqqKjypyxIu5nvpjq2TUMUhxkWxTv0n2diN+g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PUXpkGKbiMz4byIEOfy1dgyeY61IlSTIZlBZaZnac/9/WNgGTvbxbYkDaE0tIyFK0 4kvdftnadQcLG8tmY8PC6SDgvQj+5hgUaNYkr4KLBfOvNAfgLH1XMeNJdblHKQ16p9 OeMKzbI4NSC+b6xsgsjC/fh2NRgpVKWn8OlOnl9o= Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 79D9F6A604; Tue, 21 Apr 2026 12:36:10 -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 B0QZSFULpBBg; Tue, 21 Apr 2026 12:36:10 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1776796565; bh=BEPzagjqquG2qPP4ScynZU5y3o/OQip15q7Ymou0BYo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rpC/7j8OfnpDCXI1rB7sdgqle5Fh04WOFPid/cPI62dEj9WvjE542gdKH64vhMsdv NWQqTvoUKXz59MtGKG0DLH2pHArbZSfOr8TKjlKDTlou14GvnfbLGvMLztyrby2b1v Py00qO6VgBLxhKasYGjUcfPJzJ4En27B4geYrrKs= Received: from u-boot.org (unknown [174.51.25.52]) by mail.u-boot.org (Postfix) with ESMTPSA id F272C6A603; Tue, 21 Apr 2026 12:36:04 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Tue, 21 Apr 2026 12:34:48 -0600 Message-ID: <20260421183511.2044469-8-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260421183511.2044469-1-sjg@u-boot.org> References: <20260421183511.2044469-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: VFNCUES3IVCNO6HKFAIJNWIUEBLDTV5Q X-Message-ID-Hash: VFNCUES3IVCNO6HKFAIJNWIUEBLDTV5Q 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: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 07/16] part: Add a BLS target-partition check 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 The Boot Loader Specification places Type #1 entries on the ESP, the Extended Boot Loader Partition (XBOOTLDR), or an MBR type 0xea partition. Discovery is by partition type only; the spec never mentions the GPT or MBR 'bootable' flag. Add a small helper that identifies those three cases so the bootflow layer can scan them for loader/entry.conf regardless of bootable attribute. Keep it in disk/part.c alongside part_get_bootable(), with a trivial stub for !CONFIG_PARTITIONS builds. Also add a sandbox unit test that exercises the helper with the three partition type identifiers the spec calls out (ESP, XBOOTLDR and MBR 0xea), plus a few negative cases covering a common Linux partition type and a stray Linux MBR sys_ind, and verifies that the GUID match is case-insensitive. Signed-off-by: Simon Glass --- disk/part.c | 21 +++++++++++++++++++++ include/part.h | 17 +++++++++++++++++ test/dm/part.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/disk/part.c b/disk/part.c index 2ddbf50ee6c..e22dabc4090 100644 --- a/disk/part.c +++ b/disk/part.c @@ -882,3 +882,24 @@ int part_get_bootable(struct blk_desc *desc) return 0; } + +bool part_is_bls_target(const struct disk_partition *info) +{ + if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)) { + const char *guid = disk_partition_type_guid(info); + + /* EFI System Partition */ + if (!strcasecmp(guid, "c12a7328-f81f-11d2-ba4b-00a0c93ec93b")) + return true; + /* Extended Boot Loader Partition (XBOOTLDR) */ + if (!strcasecmp(guid, "bc13c2ff-59e6-4262-a352-b275fd6f7172")) + return true; + } + + /* MBR/DOS disks: BLS uses partition type 0xea */ + if (IS_ENABLED(CONFIG_DOS_PARTITION) && + disk_partition_sys_ind(info) == 0xea) + return true; + + return false; +} diff --git a/include/part.h b/include/part.h index 6c9558e2c71..3ecf6d8e165 100644 --- a/include/part.h +++ b/include/part.h @@ -755,6 +755,20 @@ int part_get_type_by_name(const char *name); */ int part_get_bootable(struct blk_desc *desc); +/** + * part_is_bls_target() - Check whether a partition holds BLS boot entries + * + * The Boot Loader Specification defines two GPT partition types as homes + * for Type #1 entries (the ESP and the Extended Boot Loader Partition) and + * one MBR type ID (0xea). This helper returns true when @info names one of + * them, so the caller can scan the partition for loader/entries/.conf + * (or loader/entry.conf) regardless of any 'bootable' flag. + * + * @info: Partition information + * Return: true if the partition is an ESP, XBOOTLDR or MBR-0xea partition + */ +bool part_is_bls_target(const struct disk_partition *info); + /** * part_driver_lookup_type() - Look up the partition driver for a blk device * @@ -783,6 +797,9 @@ static inline struct part_driver *part_driver_get_first(void) static inline bool part_get_bootable(struct blk_desc *desc) { return false; } +static inline bool part_is_bls_target(const struct disk_partition *info) +{ return false; } + static inline struct part_driver *part_driver_lookup_type(struct blk_desc *desc) { return NULL; } diff --git a/test/dm/part.c b/test/dm/part.c index caae23bd4aa..02f36c0803a 100644 --- a/test/dm/part.c +++ b/test/dm/part.c @@ -109,6 +109,48 @@ static int dm_test_part_bootable(struct unit_test_state *uts) } DM_TEST(dm_test_part_bootable, UTF_SCAN_FDT); +static int dm_test_part_is_bls_target(struct unit_test_state *uts) +{ + struct disk_partition info; + + /* GPT: ESP type GUID */ + memset(&info, '\0', sizeof(info)); + disk_partition_set_type_guid(&info, + "c12a7328-f81f-11d2-ba4b-00a0c93ec93b"); + ut_asserteq(true, part_is_bls_target(&info)); + + /* GPT: XBOOTLDR type GUID */ + memset(&info, '\0', sizeof(info)); + disk_partition_set_type_guid(&info, + "bc13c2ff-59e6-4262-a352-b275fd6f7172"); + ut_asserteq(true, part_is_bls_target(&info)); + + /* GPT: GUID match must be case-insensitive */ + memset(&info, '\0', sizeof(info)); + disk_partition_set_type_guid(&info, + "c12a7328-f81f-11d2-ba4b-00a0c93ec93b"); + ut_asserteq(true, part_is_bls_target(&info)); + + /* GPT: a Linux filesystem partition is not a BLS target */ + memset(&info, '\0', sizeof(info)); + disk_partition_set_type_guid(&info, + "0fc63daf-8483-4772-8e79-3d69d8477de4"); + ut_asserteq(false, part_is_bls_target(&info)); + + /* MBR: BLS partition type 0xea */ + memset(&info, '\0', sizeof(info)); + info.sys_ind = 0xea; + ut_asserteq(true, part_is_bls_target(&info)); + + /* MBR: a Linux partition (0x83) is not a BLS target */ + memset(&info, '\0', sizeof(info)); + info.sys_ind = 0x83; + ut_asserteq(false, part_is_bls_target(&info)); + + return 0; +} +DM_TEST(dm_test_part_is_bls_target, 0); + static int do_get_info_test(struct unit_test_state *uts, struct blk_desc *dev_desc, int part, int part_type, struct disk_partition const *reference)