From patchwork Tue Sep 30 23:25:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 458 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=1759274811; bh=TwjHV8/6WmQbBJWz+vkFfKMLU6Jp0xel9lSOgjQradg=; 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=VexIUIf0ZwhHzlAheVjVmTi837p+tMHsnl1P/INnRgruP8pQnQDMwe182Z1wKtjG7 dvlhYRXjsGhucOrzEzXcm7LR6jymBlwXOVjJuIn2HadzO9iKWcDCtX2HiU7fc+yNkw fQFX6hzajWto6zAkek84ETmXOHBN3iG3YZ8bYTUy+220zBv+yRjRwZrM1KiTpyjv2Z nL+Wx6DQ6jCkRoPbbtfzR3rdjvxNG7uPmNLS3rZXvPm+2HcSrlr9debQl5lhTAafe3 srGtgVax4ekz+mZUmSPrZ/RsHFiz5zHSSuLjZZ4UGF3IcXIc5lDCaNH8owOb2L49jE DaY0OONMNjXkw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C7B6667B5E for ; Tue, 30 Sep 2025 17:26:51 -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 OcPHw8l4ot3e for ; Tue, 30 Sep 2025 17:26:51 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759274810; bh=TwjHV8/6WmQbBJWz+vkFfKMLU6Jp0xel9lSOgjQradg=; 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=l85kdqDcAJha5PxRHB9g8NtzcoLE/yMnsD9sLyfgaoSp/Q2hl88cZeDb/Bx7B2fnj yl/S2hSo2jkT/L1Ztc6JR5j1rXixtTArNz0odQb7ljuESEeZarAkzoSzTupmOXAxnL XgDdOaCG6TTy5gtCeX7IYo1+XoX+mkC9x3oDTYS8NcRrRL9TpekVdy6gLnMpDrL/r6 ObNHSKqV1xEczqNMa6xxHKymAC7wVrCqznNrNQEEcDI5IEBwtuUbuHD28bm+4hxYlN 97+flJR6nEP8VR0LtuIA3e0tXK0aFLBQpNnG2GwYPtPudiLufCWrUlLEVNdjtB29VG DGoaJ2ap2WihQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DA93567E7F for ; Tue, 30 Sep 2025 17:26:50 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759274809; bh=U7RTFpGnoc97xRSqsr8zpsG2kVa74bfK3HJmW3qPoW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GLgrXkg0P3IwqzC9g3rhVmFIywwdJAwt9YvX4lMy/laD+QZ/rhUyA8+1WYuvljE42 NTQYD3Rfj20eWjHo01PB+uv9OOOM6325uw3x36Gn3tcrX/Ns40coWN1TxeLuuv5z01 3neMUjUw5Ha95ALbsgcfhsoxEsLwIuCU9ayRLVWS1fR3i5vcQ7t0dzCbL5ivBT0hrU 84JeAQZXc0FwqyGQY8IbB3h7ohEPDKeBIQF3uY/ytmJir01pAiStzTLcOGSpZpH1df gCc9e8QewgsvltGFTnQoMixZw5oWCmhW7h/FVkWfkwj2ExevPCRC55OoNaHXyzfvke dq6MUEcTl5sdg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 19D4067E2F; Tue, 30 Sep 2025 17:26:49 -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 w3jfHEZtYj97; Tue, 30 Sep 2025 17:26:49 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759274808; bh=VJ22Zlb7BGbsu0F2IEWq+BzdzRPi+Zeg5LKK4nPJwUU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YWl0SnIyUGAzWFMRtluUfKK3W/8V2tOzyPmh6YQp9uwvMnicjOCRNCKCXH+i6qViC IYkTQRF4HlZOgCYmzcnKe7V4VvzRabtpIeqE7treISaDER1xJ75vrl0L07SI2Bm1Cs l6wEj3vbM5JRwJ9GmkHDo+AgCuIsNs9D64fQObxPtULC5T0i6FGkpfMGxvJQVFYjss rtloXNW8/4H6avwiE916hwkwUSJ9R5cg7V5Qf6FFdn95S0jgfF6dR1jSaAEG/Y+izY Zg2Ca2XFMsUz+RDpN78FWtqNU3GwLsQr4Sn+39O9kYw9/eWVyr9OinrcFw3KlCFuwY Aj891NBcVZ1rw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 5FF9867B7A; Tue, 30 Sep 2025 17:26:48 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Tue, 30 Sep 2025 17:25:44 -0600 Message-ID: <20250930232611.1564850-8-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250930232611.1564850-1-sjg@u-boot.org> References: <20250930232611.1564850-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: MLKZHFQ32RTGMED4CA6RU5OUP7Q67B66 X-Message-ID-Hash: MLKZHFQ32RTGMED4CA6RU5OUP7Q67B66 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 v2 07/15] boot: Keep track of which bootmeths have been used 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 Add a bitfield which tracks when bootmeths have been used. This will be needed when global bootmeths can be used later in the iteration. Fix a missing bootflow_free() while here. Signed-off-by: Simon Glass --- (no changes since v1) boot/bootflow.c | 13 +++++++++++++ boot/bootmeth-uclass.c | 10 ++++++++++ include/bootflow.h | 8 ++++++++ test/boot/bootflow.c | 8 ++++++++ 4 files changed, 39 insertions(+) diff --git a/boot/bootflow.c b/boot/bootflow.c index dab4397e5eb..4e2a227c807 100644 --- a/boot/bootflow.c +++ b/boot/bootflow.c @@ -18,6 +18,10 @@ #include #include +/* ensure BOOTMETH_MAX_COUNT fits in method_flags field */ +static_assert(BOOTMETH_MAX_COUNT <= + (sizeof(((struct bootflow_iter *)NULL)->method_flags) * 8)); + /* error codes used to signal running out of things */ enum { BF_NO_MORE_PARTS = -ESHUTDOWN, @@ -493,6 +497,10 @@ int bootflow_scan_first(struct udevice *dev, const char *label, bootflow_iter_set_dev(iter, dev, method_flags); } + if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL)) { + iter->methods_done |= BIT(iter->cur_method); + log_debug("methods_done now %x\n", iter->cur_method); + } ret = bootflow_check(iter, bflow); if (ret) { log_debug("check - ret=%d\n", ret); @@ -520,6 +528,11 @@ int bootflow_scan_next(struct bootflow_iter *iter, struct bootflow *bflow) return log_msg_ret("done", ret); if (!ret) { + if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL)) { + iter->methods_done |= BIT(iter->cur_method); + log_debug("methods_done now %x\n", + iter->cur_method); + } ret = bootflow_check(iter, bflow); log_debug("check - ret=%d\n", ret); if (!ret) diff --git a/boot/bootmeth-uclass.c b/boot/bootmeth-uclass.c index 0147b97fcb0..d71e4f001f1 100644 --- a/boot/bootmeth-uclass.c +++ b/boot/bootmeth-uclass.c @@ -199,6 +199,16 @@ int bootmeth_setup_iter_order(struct bootflow_iter *iter, bool include_global) iter->doing_global = true; iter->have_global = true; } + + /* + * check we don't exceed the maximum bits in methods_done when tracking + * which global bootmeths have run + */ + if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) && count > BOOTMETH_MAX_COUNT) { + free(order); + return log_msg_ret("tmb", -ENOSPC); + } + iter->method_order = order; iter->num_methods = count; diff --git a/include/bootflow.h b/include/bootflow.h index 0805d10e197..051158780e6 100644 --- a/include/bootflow.h +++ b/include/bootflow.h @@ -12,6 +12,7 @@ #include #include #include +#include struct bootstd_priv; struct expo; @@ -226,6 +227,10 @@ enum bootflow_meth_flags_t { BOOTFLOW_METHF_SINGLE_UCLASS = 1 << 3, }; +enum { + BOOTMETH_MAX_COUNT = 32, +}; + /** * struct bootflow_iter - state for iterating through bootflows * @@ -273,6 +278,8 @@ enum bootflow_meth_flags_t { * happens before the normal ones) * @method_flags: flags controlling which methods should be used for this @dev * (enum bootflow_meth_flags_t) + * @methods_done: indicates which methods have been processed, one bit for + * each method in @method_order[] */ struct bootflow_iter { int flags; @@ -295,6 +302,7 @@ struct bootflow_iter { bool have_global; bool doing_global; int method_flags; + uint methods_done; }; /** diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index a18afad0f72..af7f7391160 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -316,6 +316,7 @@ static int bootflow_iter(struct unit_test_state *uts) ut_assert(!iter.doing_global); ut_assert(!iter.have_global); ut_asserteq(-1, iter.first_glob_method); + ut_asserteq(BIT(0), iter.methods_done); /* * This shows MEDIA even though there is none, since in @@ -324,6 +325,7 @@ static int bootflow_iter(struct unit_test_state *uts) * know. */ ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); + bootflow_free(&bflow); ut_asserteq(-EPROTONOSUPPORT, bootflow_scan_next(&iter, &bflow)); ut_asserteq(3, iter.num_methods); @@ -333,6 +335,7 @@ static int bootflow_iter(struct unit_test_state *uts) ut_asserteq_str("efi", iter.method->name); ut_asserteq(0, bflow.err); ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); + ut_asserteq(BIT(0) | BIT(1), iter.methods_done); bootflow_free(&bflow); /* now the VBE boothmeth */ @@ -344,6 +347,7 @@ static int bootflow_iter(struct unit_test_state *uts) ut_asserteq_str("vbe", iter.method->name); ut_asserteq(0, bflow.err); ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); + ut_asserteq(BIT(0) | BIT(1) | BIT(2), iter.methods_done); bootflow_free(&bflow); /* The next device is mmc1.bootdev - at first we use the whole device */ @@ -355,6 +359,7 @@ static int bootflow_iter(struct unit_test_state *uts) ut_asserteq_str("extlinux", iter.method->name); ut_asserteq(0, bflow.err); ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); + ut_asserteq(BIT(0) | BIT(1) | BIT(2), iter.methods_done); bootflow_free(&bflow); ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow)); @@ -365,6 +370,7 @@ static int bootflow_iter(struct unit_test_state *uts) ut_asserteq_str("efi", iter.method->name); ut_asserteq(0, bflow.err); ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); + ut_asserteq(BIT(0) | BIT(1) | BIT(2), iter.methods_done); bootflow_free(&bflow); /* now the VBE boothmeth */ @@ -376,6 +382,7 @@ static int bootflow_iter(struct unit_test_state *uts) ut_asserteq_str("vbe", iter.method->name); ut_asserteq(0, bflow.err); ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); + ut_asserteq(BIT(0) | BIT(1) | BIT(2), iter.methods_done); bootflow_free(&bflow); /* Then move to partition 1 where we find something */ @@ -418,6 +425,7 @@ static int bootflow_iter(struct unit_test_state *uts) ut_asserteq_str("extlinux", iter.method->name); ut_asserteq(0, bflow.err); ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); + ut_asserteq(BIT(0) | BIT(1) | BIT(2), iter.methods_done); bootflow_free(&bflow); bootflow_iter_uninit(&iter);