mirror of
https://github.com/u-boot/u-boot.git
synced 2025-05-04 02:32:32 +00:00

To enable more complex sequencing of the bootmenu, autoboot, and bootretry, handle changes to the bootretry variable between tries. This makes it possible to turn bootretry off (e.g. to drop to a shell) and then back on again. This makes it possible to have a persistent bootmenu (the only way to navigate U-Boot on devices like smartphones which lack a physical keyboard) by having bootcmd be defined to launch the bootmenu. This allows for menu options like enabling USB mass storage gadget to return back to the boot menu once the gadget is shut down. Reviewed-by: Tom Rini <trini@konsulko.com> Tested-by: Danila Tikhonov <danila@jiaxyga.com> # google-sunfish Tested-by: Jens Reidel <adrian@mainlining.org> # xiaomi-davinci Link: https://lore.kernel.org/r/20250331-qcom-phones-v4-3-f52e57d3b8c6@linaro.org Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
59 lines
1.3 KiB
C
59 lines
1.3 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 <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
|
|
*/
|
|
void bootretry_init_cmd_timeout(void)
|
|
{
|
|
char *s = env_get("bootretry");
|
|
|
|
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;
|
|
}
|
|
|
|
/***************************************************************************
|
|
* reset command line timeout to retry_time seconds
|
|
*/
|
|
void bootretry_reset_cmd_timeout(void)
|
|
{
|
|
/* Parse changes to bootretry */
|
|
bootretry_init_cmd_timeout();
|
|
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;
|
|
}
|