EXTERNAL - [PATCH v1] Add bootchooser command option for active boot target

Burri Markus LabTec Markus.Burri at mt.com
Mon Apr 17 02:42:39 PDT 2023


Hi Ahmad
I removed my init script and replaced it by a script added to bootchooser.system0.boot=<script>.
This fit my requirements and therefor the patch is obsolete.
Thanks for your support.
Best regards Markus

-----Original Message-----
From: Ahmad Fatoum <a.fatoum at pengutronix.de> 
Sent: Freitag, 14. April 2023 14:47
To: Burri Markus LabTec <Markus.Burri at mt.com>
Cc: barebox at lists.infradead.org
Subject: Re: EXTERNAL - [PATCH v1] Add bootchooser command option for active boot target

Hello Markus,

On 14.04.23 14:41, Burri Markus LabTec wrote:
> Hello Ahmad
> 
> The Idea is to run some scripts stored in the rootfs before booting 
> the system. In our case e.g we enable led according to customer needs. 
> This is stored in to rootfs where the customer is able to update 
> without update barebox

Once you give your customer the ability to run arbitrary code, they will run arbitrary code, e.g. apply an overlay to the kernel DT or tune kernel command line argument. With your init script approach, you could apply old overlays when booting a new kernel, which can lead to very surprising results.

> The new command option will store this information in a variable where I can use this information in the init script.
> It sound that a script as bootchooser target will fit my requirement. 
> I didn't know that. I will try

I am not opposed to give these scripts knowledge of what bootchooser target is executed, see untested patch below. But it should be the boot scripts that run hooks, not an init script on a subsequent boot.

Cheers,
Ahmad

---
 common/bootchooser.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/common/bootchooser.c b/common/bootchooser.c index 08d05e885250..3d400af08ef1 100644
--- a/common/bootchooser.c
+++ b/common/bootchooser.c
@@ -827,6 +827,7 @@ static int bootchooser_boot_one(struct bootchooser *bc, int *tryagain)
                goto out;
        }

+       globalvar_add_simple("bootchooser.active", target->name);
        system = basprintf("bootchooser.active=%s", target->name);
        globalvar_add_simple("linux.bootargs.bootchooser", system);
        free(system);
@@ -854,6 +855,7 @@ static int bootchooser_boot_one(struct bootchooser *bc, int *tryagain)
        *tryagain = 1;
 out:
        globalvar_set_match("linux.bootargs.bootchooser", NULL);
+       globalvar_set_match("bootchooser.active", NULL);

        bootentries_free(entries);

@@ -976,3 +978,5 @@ BAREBOX_MAGICVAR(global.bootchooser.default_priority,
                 "bootchooser: Default priority for a target");  BAREBOX_MAGICVAR(global.bootchooser.state_prefix,
                 "bootchooser: state name prefix, empty for nv backend");
+BAREBOX_MAGICVAR(global.bootchooser.active,
+                "bootchooser: holds name of active bootchooser target 
+during boot");



More information about the barebox mailing list