Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 0098e17 | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2000 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Simon Glass | 0098e17 | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <bootretry.h> |
| 9 | #include <cli.h> |
Simon Glass | 7b51b57 | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 10 | #include <env.h> |
Simon Glass | 0098e17 | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 11 | #include <errno.h> |
Simon Glass | 1045315 | 2019-11-14 12:57:30 -0700 | [diff] [blame] | 12 | #include <time.h> |
Simon Glass | 0098e17 | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 13 | #include <watchdog.h> |
| 14 | |
Simon Glass | 0098e17 | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 15 | static uint64_t endtime; /* must be set, default is instant timeout */ |
| 16 | static int retry_time = -1; /* -1 so can call readline before main_loop */ |
| 17 | |
| 18 | /*************************************************************************** |
| 19 | * initialize command line timeout |
| 20 | */ |
Simon Glass | b26440f | 2014-04-10 20:01:31 -0600 | [diff] [blame] | 21 | void bootretry_init_cmd_timeout(void) |
Simon Glass | 0098e17 | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 22 | { |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 23 | char *s = env_get("bootretry"); |
Simon Glass | 0098e17 | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 24 | |
| 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 Glass | b26440f | 2014-04-10 20:01:31 -0600 | [diff] [blame] | 37 | void bootretry_reset_cmd_timeout(void) |
Simon Glass | 0098e17 | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 38 | { |
| 39 | endtime = endtick(retry_time); |
| 40 | } |
| 41 | |
| 42 | int bootretry_tstc_timeout(void) |
| 43 | { |
| 44 | while (!tstc()) { /* while no incoming data */ |
| 45 | if (retry_time >= 0 && get_ticks() > endtime) |
| 46 | return -ETIMEDOUT; |
Stefan Roese | 29caf93 | 2022-09-02 14:10:46 +0200 | [diff] [blame^] | 47 | schedule(); |
Simon Glass | 0098e17 | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | void bootretry_dont_retry(void) |
| 54 | { |
| 55 | retry_time = -1; |
| 56 | } |