blob: 072055b0105767873ba8baf636837b80a34ffb14 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass0098e172014-04-10 20:01:30 -06002/*
3 * (C) Copyright 2000
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Simon Glass0098e172014-04-10 20:01:30 -06005 */
6
7#include <common.h>
8#include <bootretry.h>
9#include <cli.h>
10#include <errno.h>
11#include <watchdog.h>
12
13#ifndef CONFIG_BOOT_RETRY_MIN
14#define CONFIG_BOOT_RETRY_MIN CONFIG_BOOT_RETRY_TIME
15#endif
16
17static uint64_t endtime; /* must be set, default is instant timeout */
18static int retry_time = -1; /* -1 so can call readline before main_loop */
19
20/***************************************************************************
21 * initialize command line timeout
22 */
Simon Glassb26440f2014-04-10 20:01:31 -060023void bootretry_init_cmd_timeout(void)
Simon Glass0098e172014-04-10 20:01:30 -060024{
Simon Glass00caae62017-08-03 12:22:12 -060025 char *s = env_get("bootretry");
Simon Glass0098e172014-04-10 20:01:30 -060026
27 if (s != NULL)
28 retry_time = (int)simple_strtol(s, NULL, 10);
29 else
30 retry_time = CONFIG_BOOT_RETRY_TIME;
31
32 if (retry_time >= 0 && retry_time < CONFIG_BOOT_RETRY_MIN)
33 retry_time = CONFIG_BOOT_RETRY_MIN;
34}
35
36/***************************************************************************
37 * reset command line timeout to retry_time seconds
38 */
Simon Glassb26440f2014-04-10 20:01:31 -060039void bootretry_reset_cmd_timeout(void)
Simon Glass0098e172014-04-10 20:01:30 -060040{
41 endtime = endtick(retry_time);
42}
43
44int bootretry_tstc_timeout(void)
45{
46 while (!tstc()) { /* while no incoming data */
47 if (retry_time >= 0 && get_ticks() > endtime)
48 return -ETIMEDOUT;
49 WATCHDOG_RESET();
50 }
51
52 return 0;
53}
54
55void bootretry_dont_retry(void)
56{
57 retry_time = -1;
58}