[PATCH 2/4] bootchooser: extend cmd tool by option to set slot locking
Ahmad Fatoum
a.fatoum at pengutronix.de
Mon Jun 16 03:49:29 PDT 2025
Hi,
On 6/13/25 16:08, Lars Schmidt wrote:
Please write a commit message.
> Signed-off-by: Lars Schmidt <l.schmidt at pengutronix.de>
> ---
> commands/bootchooser.c | 16 +++++++++++++++-
> common/bootchooser.c | 28 ++++++++++++++++++++++++++++
> include/bootchooser.h | 1 +
> 3 files changed, 44 insertions(+), 1 deletion(-)
>
> diff --git a/commands/bootchooser.c b/commands/bootchooser.c
> index 46b063e027..497427eaf0 100644
> --- a/commands/bootchooser.c
> +++ b/commands/bootchooser.c
> @@ -48,8 +48,9 @@ static int do_bootchooser(int argc, char *argv[])
> int info = 0;
> bool done_something = false;
> bool last_boot_successful = false;
> + int lock_state = -1;
>
> - while ((opt = getopt(argc, argv, "a:p:is")) > 0) {
> + while ((opt = getopt(argc, argv, "a:p:islL")) > 0) {
> switch (opt) {
> case 'a':
> if (!strcmp(optarg, "default"))
> @@ -69,6 +70,12 @@ static int do_bootchooser(int argc, char *argv[])
> case 's':
> last_boot_successful = true;
> break;
> + case 'l':
> + lock_state = true;
> + break;
> + case 'L':
> + lock_state = false;
> + break;
> default:
> return COMMAND_ERROR_USAGE;
> }
> @@ -109,6 +116,11 @@ static int do_bootchooser(int argc, char *argv[])
> done_something = true;
> }
>
> + if (lock_state >= 0) {
> + ret = bootchooser_lock_slots(bootchooser, lock_state);
s/slots/attempts/
> + done_something = true;
> + }
> +
> if (!done_something) {
> printf("Nothing to do\n");
> ret = COMMAND_ERROR_USAGE;
> @@ -126,6 +138,8 @@ BAREBOX_CMD_HELP_TEXT("Options:")
> BAREBOX_CMD_HELP_OPT ("-a <n|default> [TARGETS]", "set remaining attempts of given targets to 'n' or the default attempts")
> BAREBOX_CMD_HELP_OPT ("-p <n|default> [TARGETS]", "set priority of given targets to 'n' or the default priority")
> BAREBOX_CMD_HELP_OPT ("-i", "Show information about the bootchooser")
> +BAREBOX_CMD_HELP_OPT ("-l", "Enable global slots lock")
> +BAREBOX_CMD_HELP_OPT ("-L", "Disable global slots lock")
s/slots/attempts/
> BAREBOX_CMD_HELP_OPT ("-s", "Mark the last boot successful")
> BAREBOX_CMD_HELP_END
>
> diff --git a/common/bootchooser.c b/common/bootchooser.c
> index a50f757791..b25ce3681d 100644
> --- a/common/bootchooser.c
> +++ b/common/bootchooser.c
> @@ -635,6 +635,9 @@ void bootchooser_info(struct bootchooser *bc)
>
> printf("\nlast booted target: %s\n", bc->last_chosen ?
> bc->last_chosen->name : "unknown");
> +
> + printf("Locking of boot slots: %s",
s/boot slots/boot attempt counter/
> + bc->slots_locked ? "enabled" : "disabled");
> }
>
> /**
> @@ -821,6 +824,31 @@ struct bootchooser_target *bootchooser_get_last_chosen(struct bootchooser *bc)
> return bc->last_chosen;
> }
>
> +/**
> + * bootchooser_locks_slots - sets the state of the slots_locked
bootchooser_lock_attempts - lock bootchooser attempt counter
> + * @bc: The bootchooser
> + * @locked: Set slots_locked to true or false
whether attempt counter is locked or not
> + *
> + * Bootchooser stores the value if states are locked globally.
Instruct bootchooser to lock the boto attempts counter.
> + * This means remaining_attempts will not be counted down, when slots are
> + * locked
> + *
> + * Return: 0 for success, negative error code otherwise
> + */
> +int bootchooser_lock_slots(struct bootchooser *bc, 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, we can inform user about it for easier debugging
> + */
> + if (getenv_u32(bc->state_prefix, "slots_locked", ¬_needed))
> + pr_warn("Could not find value in device tree\n");
> + else
> + bc->slots_locked = locked;
> +
> + return 0;
Return error code, bootchooser -l without support should be an error,
but there is no point in printing that error code here, when we just
chose one ourselves.
Cheers,
Ahmad
> +}
> +
> static int bootchooser_boot_one(struct bootchooser *bc, int *tryagain)
> {
> char *system;
> diff --git a/include/bootchooser.h b/include/bootchooser.h
> index 31989163b2..d63868abe4 100644
> --- a/include/bootchooser.h
> +++ b/include/bootchooser.h
> @@ -17,6 +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_slots(struct bootchooser *bc, bool locked);
> const char *bootchooser_target_name(struct bootchooser_target *target);
> struct bootchooser_target *bootchooser_target_by_name(struct bootchooser *bootchooser,
> const char *name);
--
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 |
More information about the barebox
mailing list