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 v2 3/3] efi: payload: export resolved state as a BareboxState UEFI variable
Date: Tue, 25 Aug 2026 02:06:45 +0200	[thread overview]
Message-ID: <20260825000645.122086-4-chalianis1@gmail.com> (raw)
In-Reply-To: <20260825000645.122086-1-chalianis1@gmail.com>

From: Chali Anis <chalianis1@gmail.com>

When a "barebox,state" node is already reachable via barebox's live
devicetree (statically compiled in, or injected by
CONFIG_STATE_OVERLAY), render its fully resolved description - backend
phandle included - with of_state_fixup() and publish it as a
"BareboxState" UEFI variable, so an OS-side consumer can locate the
state layout without needing a separate state.dtb file on the ESP.

Since a state node reachable this way makes the standalone
/boot/EFI/barebox/state.dtb loading path redundant, skip it whenever
a "state" alias is already present in the live devicetree.

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

diff --git a/efi/payload/init.c b/efi/payload/init.c
index f0ce2a82cefc..7c1cb21d9ecd 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -287,6 +287,50 @@ core_efi_initcall(efi_register_firmware_nodes_fixup);
 #define EFI_LOADER_FEATURE_SECUREBOOT_ENROLL       (1LL << 11)
 #define EFI_LOADER_FEATURE_RETAIN_SHIM             (1LL << 12)
 
+static int state_to_efivars_export(void)
+{
+	struct device_node *np, *state_root;
+	struct state *state;
+	void *fdt;
+	size_t size;
+	int ret;
+
+	state_root = of_find_node_by_alias(NULL, "state");
+	if (!IS_ENABLED(CONFIG_STATE) || !state_root)
+		return 0;
+
+	state = state_by_node(state_root);
+	if (!state)
+		return -ENODEV;
+
+	np = of_new_node(NULL, NULL);
+	if (!np)
+		return -ENOMEM;
+
+	ret = of_state_fixup(np, state);
+	if (ret)
+		goto out;
+
+	fdt = of_flatten_dtb(np);
+	if (!fdt) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	size = fdt_totalsize(fdt);
+
+	efi_set_variable("BareboxState", &efi_barebox_vendor_guid,
+			  EFI_VARIABLE_BOOTSERVICE_ACCESS |
+			  EFI_VARIABLE_RUNTIME_ACCESS,
+			  fdt, size);
+
+	free(fdt);
+	ret = 0;
+out:
+	of_delete_node(np);
+	return ret;
+}
+late_efi_initcall(state_to_efivars_export);
 
 static int efi_postcore_init(void)
 {
@@ -356,7 +400,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")) {



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

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25  0:06 [PATCH v2 0/3] state: generic devicetree-overlay based state node injection chalianis1
2026-08-25  0:06 ` [PATCH v2 1/3] state: make of_state_fixup() usable outside common/state/ chalianis1
2026-08-25  0:06 ` [PATCH v2 2/3] state: add CONFIG_STATE_OVERLAY to inject a state node via devicetree overlay chalianis1
2026-08-25  0:06 ` chalianis1 [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-08-24 23:52 [PATCH v2 0/3] state: generic devicetree-overlay based state node injection chalianis1
2026-08-24 23:52 ` [PATCH v2 3/3] efi: payload: export resolved state as a BareboxState UEFI variable chalianis1

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=20260825000645.122086-4-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