blob: 47aaaa82201ea60a9bf470d1771032f41c4f1766 [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>
12#include <watchdog.h>
13
14#ifndef CONFIG_BOOT_RETRY_MIN
15#define CONFIG_BOOT_RETRY_MIN CONFIG_BOOT_RETRY_TIME
16#endif
17
18static uint64_t endtime; /* must be set, default is instant timeout */
19static int retry_time = -1; /* -1 so can call readline before main_loop */
20
21/***************************************************************************
22 * initialize command line timeout
23 */
Simon Glass09007c42014-04-10 20:01:31 -060024void bootretry_init_cmd_timeout(void)
Simon Glass399ed9a2014-04-10 20:01:30 -060025{
Simon Glass64b723f2017-08-03 12:22:12 -060026 char *s = env_get("bootretry");
Simon Glass399ed9a2014-04-10 20:01:30 -060027
28 if (s != NULL)
29 retry_time = (int)simple_strtol(s, NULL, 10);
30 else
31 retry_time = CONFIG_BOOT_RETRY_TIME;
32
33 if (retry_time >= 0 && retry_time < CONFIG_BOOT_RETRY_MIN)
34 retry_time = CONFIG_BOOT_RETRY_MIN;
35}
36
37/***************************************************************************
38 * reset command line timeout to retry_time seconds
39 */
Simon Glass09007c42014-04-10 20:01:31 -060040void bootretry_reset_cmd_timeout(void)
Simon Glass399ed9a2014-04-10 20:01:30 -060041{
42 endtime = endtick(retry_time);
43}
44
45int bootretry_tstc_timeout(void)
46{
47 while (!tstc()) { /* while no incoming data */
48 if (retry_time >= 0 && get_ticks() > endtime)
49 return -ETIMEDOUT;
50 WATCHDOG_RESET();
51 }
52
53 return 0;
54}
55
56void bootretry_dont_retry(void)
57{
58 retry_time = -1;
59}