Files
u-boot-krane/boot/bootretry.c
T
Rasmus VillemoesandTom Rini 4cb0bd4702 bootretry: only reinitialize retry_time when bootretry env variable has been touched
Commit aa5ef3c0a7 ("bootretry: check for bootretry variable changes")
broke the feature where one can define different keys for "delaying"
versus "stopping" boot. The way the latter is implemented is by the code
in autoboot.c calling bootretry_dont_retry() when the stop sequence
has been detected, and that simply sets the retry_time variable in
bootretry.c to -1.

However, with the mentioned commit, that is unconditionally overridden
on every command, since it gets re-initialized from either the
bootretry environment variable or CONFIG_BOOT_RETRY_TIME, thus making
"delay" and "stop" effectively the same.

To fix that, while still picking up changes to the bootretry
environment variable, use the proper mechanism for C code to be
notified about changes to environment variables.

Since the callback is invoked before the change has actually been done
to the environment (callbacks can reject the change from taking
effect), we cannot simply call the existing
bootretry_init_cmd_timeout() from the callback, as its env_get() would
not see the new value. Instead, refactor most of it to an internal
bootretry_parse(), and call that with the new value (which is NULL in
the case bootretry is being deleted, so that works exactly as it
should).

Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
2026-08-10 14:47:50 -06:00

78 lines
1.6 KiB
C

// SPDX-License-Identifier: GPL-2.0+
/*
* (C) Copyright 2000
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*/
#include <stdio.h>
#include <bootretry.h>
#include <cli.h>
#include <env.h>
#include <env_callback.h>
#include <errno.h>
#include <time.h>
#include <vsprintf.h>
#include <watchdog.h>
static uint64_t endtime; /* must be set, default is instant timeout */
static int retry_time = -1; /* -1 so can call readline before main_loop */
/***************************************************************************
* initialize command line timeout
*/
static void bootretry_parse(const char *s)
{
if (s != NULL)
retry_time = (int)simple_strtol(s, NULL, 10);
else
retry_time = CONFIG_BOOT_RETRY_TIME;
if (retry_time >= 0 && retry_time < CONFIG_BOOT_RETRY_MIN)
retry_time = CONFIG_BOOT_RETRY_MIN;
}
void bootretry_init_cmd_timeout(void)
{
bootretry_parse(env_get("bootretry"));
}
/* Parse changes to bootretry */
static int on_bootretry(const char *name, const char *value, enum env_op op,
int flags)
{
switch (op) {
case env_op_create:
case env_op_overwrite:
case env_op_delete:
bootretry_parse(value);
break;
}
return 0;
}
U_BOOT_ENV_CALLBACK(bootretry, on_bootretry);
/***************************************************************************
* reset command line timeout to retry_time seconds
*/
void bootretry_reset_cmd_timeout(void)
{
endtime = endtick(retry_time);
}
int bootretry_tstc_timeout(void)
{
while (!tstc()) { /* while no incoming data */
if (retry_time >= 0 && get_ticks() > endtime)
return -ETIMEDOUT;
schedule();
}
return 0;
}
void bootretry_dont_retry(void)
{
retry_time = -1;
}