mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: anis chali <chalianis1@gmail.com>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v3 3/4] efi: payload: export resolved state as a BareboxState UEFI variable
Date: Wed, 26 Aug 2026 01:30:13 +0200	[thread overview]
Message-ID: <CAL+1fyAgM2hKxoiaVE6kh54pS8Umc5cvT1SsLqfmgZGA65QA4g@mail.gmail.com> (raw)
In-Reply-To: <d7543375-fbad-495c-a1a5-3556a4f6090e@pengutronix.de>

Hi,

Le mar. 25 août 2026 à 19:04, Ahmad Fatoum <a.fatoum@pengutronix.de> a écrit :
>
> Hi,
>
> On 8/25/26 5:05 AM, chalianis1@gmail.com wrote:
> > 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.
>
> Why not pass along the whole barebox DT? For EFI payloads, that's
> effectively the state and the backend already and in case we gain more
> content in future, it will just be passed along as well.
I understand, so we should call the efivar BareboxDT-XXXXX ??
or If we keep the variable name BareboxState and pass the entire device tree,
going forward we would only support state definitions within the barebox DT
in efi payloads???

> >
> > state_to_efivars_export() and efi_late_init() are both late_efi_initcall,
> > and within one initcall level, execution follows definition order in the
> > object file, so state_to_efivars_export() must be defined after
> > efi_late_init(): on boards with no state node in their own static
> > devicetree, efi_late_init() is what loads and registers
> > /boot/EFI/barebox/state.dtb, and only once that has had a chance to run
> > does state_by_alias() have anything to find. Defined the other way
> > around, state_to_efivars_export() would always run first and never see
> > a state.dtb efi_late_init() had not loaded yet - it would only have
> > happened to work when CONFIG_STATE_OVERLAY had already registered the
> > node much earlier, at postcore_initcall, a narrower case than the
> > state.dtb fallback efi_late_init() exists to support.
> >
> > Look the state instance up via the state_by_alias() helper
> > (common/state/state.c) rather than open-coding the equivalent
> > of_find_node_by_alias() + state_by_node(). This also means state not
> > being set up yet is just a clean no-op, rather than the -ENODEV that
> > open-coded version returned, which would've been logged as an initcall
> > failure for what is an entirely ordinary condition.
> >
> > Assisted-by: Claude Sonnet 5
> > Signed-off-by: Chali Anis <chalianis1@gmail.com>
> > ---
> >  efi/payload/init.c | 51 +++++++++++++++++++++++++++++++++++++++++++++-
> >  1 file changed, 50 insertions(+), 1 deletion(-)
> >
> > diff --git a/efi/payload/init.c b/efi/payload/init.c
> > index f0ce2a82cefc..cdb73afffa2c 100644
> > --- a/efi/payload/init.c
> > +++ b/efi/payload/init.c
> > @@ -287,7 +287,6 @@ 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 efi_postcore_init(void)
> >  {
> >       const struct efi_device_path *parent_image_dp, *loaded_image_dp;
> > @@ -404,6 +403,56 @@ static int efi_late_init(void)
> >  }
> >  late_efi_initcall(efi_late_init);
> >
> > +/*
> > + * Must run after efi_late_init(): on boards with no state node compiled
> > + * into their own devicetree, efi_late_init() is what loads and registers
> > + * /boot/EFI/barebox/state.dtb (or, on CONFIG_STATE_OVERLAY targets, that
> > + * already happened much earlier). Only once that has had a chance to run
> > + * does state_by_alias() have anything to find here.
> > + */
> > +static int state_to_efivars_export(void)
> > +{
> > +     struct device_node *np;
> > +     struct state *state;
> > +     void *fdt;
> > +     size_t size;
> > +     int ret;
> > +
> > +     if (!IS_ENABLED(CONFIG_STATE))
> > +             return 0;
> > +
> > +     state = state_by_alias("state");
> > +     if (!state)
> > +             return 0;
> > +
> > +     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 do_efiexit(int argc, char *argv[])
> >  {
> >       if (!BS)
> >
>
> --
> Pengutronix e.K.                  |                             |
> Steuerwalder Str. 21              | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |
>

best regards.
Anis



  reply	other threads:[~2026-08-25 23:33 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 [this message]
2026-08-25  3:05 ` [PATCH v3 4/4] efi: payload: make CONFIG_STATE_OVERLAY (and BareboxState export) work on x86 chalianis1
2026-08-25 17:06   ` 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=CAL+1fyAgM2hKxoiaVE6kh54pS8Umc5cvT1SsLqfmgZGA65QA4g@mail.gmail.com \
    --to=chalianis1@gmail.com \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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