blob: 587b2de7d6b08db07e1dea512a834cb5590c2d12 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass399ed9a2014-04-10 20:01:30 -06002/*
3 * (C) Copyright 2000
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Simon Glass399ed9a2014-04-10 20:01:30 -06005 */
6
Tom Rinic9d098f2024-04-27 08:11:02 -06007#include <stdio.h>
Simon Glass399ed9a2014-04-10 20:01:30 -06008#include <bootretry.h>
9#include <cli.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -060010#include <env.h>
Simon Glass399ed9a2014-04-10 20:01:30 -060011#include <errno.h>
Simon Glass495a5dc2019-11-14 12:57:30 -070012#include <time.h>
Tom Rinic9d098f2024-04-27 08:11:02 -060013#include <vsprintf.h>
Simon Glass399ed9a2014-04-10 20:01:30 -060014#include <watchdog.h>
15
Simon Glass399ed9a2014-04-10 20:01:30 -060016static uint64_t endtime; /* must be set, default is instant timeout */
17static int retry_time = -1; /* -1 so can call readline before main_loop */
18
19/***************************************************************************
20 * initialize command line timeout
21 */
Simon Glass09007c42014-04-10 20:01:31 -060022void bootretry_init_cmd_timeout(void)
Simon Glass399ed9a2014-04-10 20:01:30 -060023{
Simon Glass64b723f2017-08-03 12:22:12 -060024 char *s = env_get("bootretry");
Simon Glass399ed9a2014-04-10 20:01:30 -060025
26 if (s != NULL)
27 retry_time = (int)simple_strtol(s, NULL, 10);
28 else
29 retry_time = CONFIG_BOOT_RETRY_TIME;
30
31 if (retry_time >= 0 && retry_time < CONFIG_BOOT_RETRY_MIN)
32 retry_time = CONFIG_BOOT_RETRY_MIN;
33}
34
35/***************************************************************************
36 * reset command line timeout to retry_time seconds
37 */
Simon Glass09007c42014-04-10 20:01:31 -060038void bootretry_reset_cmd_timeout(void)
Simon Glass399ed9a2014-04-10 20:01:30 -060039{
40 endtime = endtick(retry_time);
41}
42
43int bootretry_tstc_timeout(void)
44{
45 while (!tstc()) { /* while no incoming data */
46 if (retry_time >= 0 && get_ticks() > endtime)
47 return -ETIMEDOUT;
Stefan Roese80877fa2022-09-02 14:10:46 +020048 schedule();
Simon Glass399ed9a2014-04-10 20:01:30 -060049 }
50
51 return 0;
52}
53
54void bootretry_dont_retry(void)
55{
56 retry_time = -1;
57}