* [PATCH] fixup! bootchooser: extend cmd tool by option to set attempts_locked
@ 2025-06-23 6:22 Ahmad Fatoum
0 siblings, 0 replies; only message in thread
From: Ahmad Fatoum @ 2025-06-23 6:22 UTC (permalink / raw)
To: barebox; +Cc: Lars Schmidt, Ahmad Fatoum
commands: bootchooser: fix new locking/unlocking options
The bootchooser instance is reference counted and the command releases
it again when it's done. Setting the struct bootchooser::lock_attempts
member in the command is thus without effect if the reference count
drops to zero when the command terminates.
Fix the issue by setting a global bootchooser instance independent flag
that forces locking until disabled. This is also the way that
bootchooser_last_boot_successful() is implemented.
This also drops the check for existence of the attempts_locked variable
in the boot state as the command doesn't interact with the state anyway.
Cc: Lars Schmidt <l.schmidt@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
commands/bootchooser.c | 2 +-
common/bootchooser.c | 25 ++++++++-----------------
include/bootchooser.h | 2 +-
3 files changed, 10 insertions(+), 19 deletions(-)
diff --git a/commands/bootchooser.c b/commands/bootchooser.c
index 4199085f352b..a59b5ebf7cce 100644
--- a/commands/bootchooser.c
+++ b/commands/bootchooser.c
@@ -117,7 +117,7 @@ static int do_bootchooser(int argc, char *argv[])
}
if (lock_state >= 0) {
- ret = bootchooser_lock_attempts(bootchooser, lock_state);
+ bootchooser_lock_attempts(lock_state);
done_something = true;
}
diff --git a/common/bootchooser.c b/common/bootchooser.c
index f2beed543db0..623cb8ce7714 100644
--- a/common/bootchooser.c
+++ b/common/bootchooser.c
@@ -41,6 +41,7 @@ static int global_default_priority = 1;
static int disable_on_zero_attempts;
static int retry;
static int last_boot_successful;
+static bool attempts_locked;
struct bootchooser {
struct list_head targets;
@@ -400,12 +401,13 @@ struct bootchooser *bootchooser_get(void)
}
/* this is an optional value */
- bc->attempts_locked = false;
+ bc->attempts_locked = attempts_locked;
ret = getenv_u32(bc->state_prefix, "attempts_locked", &locked);
- if (!ret && locked) {
+ if (!ret && locked)
bc->attempts_locked = true;
+
+ if (bc->attempts_locked)
pr_debug("remaining attempt counter is locked\n");
- }
INIT_LIST_HEAD(&bc->targets);
@@ -632,7 +634,7 @@ void bootchooser_info(struct bootchooser *bc)
printf("\nlast booted target: %s\n", bc->last_chosen ?
bc->last_chosen->name : "unknown");
- printf("Locking of boot attempt counter: %s",
+ printf("Locking of boot attempt counter: %s\n",
bc->attempts_locked ? "enabled" : "disabled");
}
@@ -822,7 +824,6 @@ struct bootchooser_target *bootchooser_get_last_chosen(struct bootchooser *bc)
/**
* bootchooser_lock_attempts - lock the bootchooser attempt counter
- * @bc: The bootchooser
* @locked: Whether the attempt counter is locked or not.
*
* Instruct bootchooser to lock the boot attempts counter.
@@ -830,19 +831,9 @@ struct bootchooser_target *bootchooser_get_last_chosen(struct bootchooser *bc)
*
* Return: 0 for success, negative error code otherwise
*/
-int bootchooser_lock_attempts(struct bootchooser *bc, bool locked)
+void bootchooser_lock_attempts(bool locked)
{
- uint32_t not_needed;
- /* We just need to check here, if the value exists in the device tree
- * So if it doesn't exist, inform user about it for easier debugging
- */
- if (getenv_u32(bc->state_prefix, "attempts_locked", ¬_needed)) {
- pr_warn("Missing attempts_locked property in state DT node\n");
- return -ENOENT;
- }
-
- bc->attempts_locked = locked;
- return 0;
+ attempts_locked = locked;
}
static int bootchooser_boot_one(struct bootchooser *bc, int *tryagain)
diff --git a/include/bootchooser.h b/include/bootchooser.h
index 69783b0b7494..36cbd0dd0a01 100644
--- a/include/bootchooser.h
+++ b/include/bootchooser.h
@@ -17,7 +17,7 @@ void bootchooser_info(struct bootchooser *bootchooser);
int bootchooser_boot(struct bootchooser *bc);
struct bootchooser_target *bootchooser_get_last_chosen(struct bootchooser *bootchooser);
-int bootchooser_lock_attempts(struct bootchooser *bc, bool locked);
+void bootchooser_lock_attempts(bool locked);
const char *bootchooser_target_name(struct bootchooser_target *target);
struct bootchooser_target *bootchooser_target_by_name(struct bootchooser *bootchooser,
const char *name);
--
2.39.5
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-06-23 6:40 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-23 6:22 [PATCH] fixup! bootchooser: extend cmd tool by option to set attempts_locked Ahmad Fatoum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox