mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: chalianis1@gmail.com
To: s.hauer@pengutronix.de
Cc: barebox@lists.infradead.org, Chali Anis <chalianis1@gmail.com>
Subject: [PATCH v3 4/4] efi: payload: make CONFIG_STATE_OVERLAY (and BareboxState export) work on x86
Date: Tue, 25 Aug 2026 05:05:48 +0200	[thread overview]
Message-ID: <20260825030548.473672-5-chalianis1@gmail.com> (raw)
In-Reply-To: <20260825030548.473672-1-chalianis1@gmail.com>

From: Chali Anis <chalianis1@gmail.com>

barebox_register_of() - the only thing that ever registers a live
devicetree root pre-boot on x86 EFI - lived in boarddata.c, which was
compiled solely for CONFIG_EFI_STUB (the chain-loaded/ARM handoff-data
entry point). x86 uses CONFIG_EFI_PAYLOAD (entry-single.c's standalone
efi_main()), so no code ever called it there: of_get_root_node() stayed
NULL for the entire pre-boot sequence. That's what state_overlay_apply()
(CONFIG_STATE_OVERLAY's postcore_initcall) and state_to_efivars_export()
(the BareboxState UEFI variable export) both rely on, so neither ever
had anything to work with on x86. Compile boarddata.o for
CONFIG_EFI_PAYLOAD too - efi_register_of() only needs BS, which
entry-single.c's efi_main() already sets before any initcall runs, and
handle_efi_boarddata() already no-ops cleanly when there is no PBL
handoff data, the normal case for this entry point.

On x86, actually binding a struct state to the node CONFIG_STATE_OVERLAY
adds still needs a fresh of_probe() pass: barebox_register_of() already
ran one, before the overlay added anything, and the next one needs to
happen later still than state_overlay_apply()'s own postcore_initcall,
too - PCI/SATA enumeration (and thus the disk cdevs a partuuid-based
state backend resolves against) only completes well after that point.
Add efi_devices_probe() at device_efi_initcall to cover it.

Finally, now that a state node reachable via CONFIG_STATE_OVERLAY is
something x86 can actually end up with pre-boot, add efi_late_init()'s
"skip loading the standalone state.dtb whenever a 'state' alias is
already present" check - it's only meaningful once that can happen.

Tested on QEMU as the EFI payload with a partuuid-referenced backend.

Assisted-by: Claude Sonnet 5
Signed-off-by: Chali Anis <chalianis1@gmail.com>
---
 efi/payload/Makefile |  1 +
 efi/payload/init.c   | 18 +++++++++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/efi/payload/Makefile b/efi/payload/Makefile
index 6306540ab595..f8b19428a99c 100644
--- a/efi/payload/Makefile
+++ b/efi/payload/Makefile
@@ -11,3 +11,4 @@ obj-pbl-$(CONFIG_EFI_PAYLOAD) += early-mem.o
 obj-$(CONFIG_EFI_PAYLOAD) += entry-single.o
 pbl-$(CONFIG_EFI_STUB) += entry-multi.o
 obj-$(CONFIG_EFI_STUB) += boarddata.o
+obj-$(CONFIG_EFI_PAYLOAD) += boarddata.o
diff --git a/efi/payload/init.c b/efi/payload/init.c
index cdb73afffa2c..e644ec60bb87 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -355,7 +355,7 @@ static int efi_late_init(void)
 	void *fdt;
 	int ret;
 
-	if (!IS_ENABLED(CONFIG_STATE))
+	if (!IS_ENABLED(CONFIG_STATE) || of_find_node_by_alias(NULL, "state"))
 		return 0;
 
 	if (!get_mounted_path("/boot")) {
@@ -453,6 +453,22 @@ static int state_to_efivars_export(void)
 	return ret;
 }
 late_efi_initcall(state_to_efivars_export);
+
+/*
+ * On x86, PCI/SATA enumeration (and thus the disk cdevs a partuuid-based
+ * state backend resolves against) only completes well after the one
+ * of_probe() pass barebox_register_of() already did, before the state
+ * overlay even added its node. Re-probe once devices have actually shown
+ * up, so such a backend can still bind.
+ */
+static int __maybe_unused efi_devices_probe(void)
+{
+	return of_probe();
+}
+#if IS_ENABLED(CONFIG_X86)
+device_efi_initcall(efi_devices_probe);
+#endif
+
 static int do_efiexit(int argc, char *argv[])
 {
 	if (!BS)



  parent reply	other threads:[~2026-08-25  3:06 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25  3:05 [PATCH v3 0/4] state: generic devicetree-overlay based state node injection chalianis1
2026-08-25  3:05 ` [PATCH v3 1/4] state: make of_state_fixup() usable outside common/state/ chalianis1
2026-08-25 17:00   ` Ahmad Fatoum
2026-08-25 23:34     ` anis chali
2026-08-25  3:05 ` [PATCH v3 2/4] state: add CONFIG_STATE_OVERLAY to inject a state node via devicetree overlay chalianis1
2026-08-25 16:57   ` Ahmad Fatoum
2026-08-25 23:36     ` anis chali
2026-08-25  3:05 ` [PATCH v3 3/4] efi: payload: export resolved state as a BareboxState UEFI variable chalianis1
2026-08-25 17:04   ` Ahmad Fatoum
2026-08-25 23:30     ` anis chali
2026-08-25  3:05 ` chalianis1 [this message]
2026-08-25 17:06   ` [PATCH v3 4/4] efi: payload: make CONFIG_STATE_OVERLAY (and BareboxState export) work on x86 Ahmad Fatoum
2026-08-25 15:02 ` [PATCH v3 0/4] state: generic devicetree-overlay based state node injection Ahmad Fatoum
2026-08-25 17:10   ` Ahmad Fatoum
2026-08-25 23:23     ` anis chali
2026-08-25 23:13   ` anis chali

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260825030548.473672-5-chalianis1@gmail.com \
    --to=chalianis1@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox