blob: 8d850df9d4875c41cadabdeb4df9c6fde3fed99a [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
7#include <common.h>
8#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>
Simon Glass399ed9a2014-04-10 20:01:30 -060013#include <watchdog.h>
14
Simon Glass399ed9a2014-04-10 20:01:30 -060015static uint64_t endtime; /* must be set, default is instant timeout */
16static int retry_time = -1; /* -1 so can call readline before main_loop */
17
18/***************************************************************************
19 * initialize command line timeout
20 */
Simon Glass09007c42014-04-10 20:01:31 -060021void bootretry_init_cmd_timeout(void)
Simon Glass399ed9a2014-04-10 20:01:30 -060022{
Simon Glass64b723f2017-08-03 12:22:12 -060023 char *s = env_get("bootretry");
Simon Glass399ed9a2014-04-10 20:01:30 -060024
25 if (s != NULL)
26 retry_time = (int)simple_strtol(s, NULL, 10);
27 else
28 retry_time = CONFIG_BOOT_RETRY_TIME;
29
30 if (retry_time >= 0 && retry_time < CONFIG_BOOT_RETRY_MIN)
31 retry_time = CONFIG_BOOT_RETRY_MIN;
32}
33
34/***************************************************************************
35 * reset command line timeout to retry_time seconds
36 */
Simon Glass09007c42014-04-10 20:01:31 -060037void bootretry_reset_cmd_timeout(void)
Simon Glass399ed9a2014-04-10 20:01:30 -060038{
39 endtime = endtick(retry_time);
40}
41
42int bootretry_tstc_timeout(void)
43{
44 while (!tstc()) { /* while no incoming data */
45 if (retry_time >= 0 && get_ticks() > endtime)
46 return -ETIMEDOUT;
Stefan Roese80877fa2022-09-02 14:10:46 +020047 schedule();
Simon Glass399ed9a2014-04-10 20:01:30 -060048 }
49
50 return 0;
51}
52
53void bootretry_dont_retry(void)
54{
55 retry_time = -1;
56}