Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 399ed9a | 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 | 399ed9a | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 7 | #include <stdio.h> |
Simon Glass | 399ed9a | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 8 | #include <bootretry.h> |
| 9 | #include <cli.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 10 | #include <env.h> |
Simon Glass | 399ed9a | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 11 | #include <errno.h> |
Simon Glass | 495a5dc | 2019-11-14 12:57:30 -0700 | [diff] [blame] | 12 | #include <time.h> |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 13 | #include <vsprintf.h> |
Simon Glass | 399ed9a | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 14 | #include <watchdog.h> |
| 15 | |
Simon Glass | 399ed9a | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 16 | static uint64_t endtime; /* must be set, default is instant timeout */ |
| 17 | static int retry_time = -1; /* -1 so can call readline before main_loop */ |
| 18 | |
| 19 | /*************************************************************************** |
| 20 | * initialize command line timeout |
| 21 | */ |
Simon Glass | 09007c4 | 2014-04-10 20:01:31 -0600 | [diff] [blame] | 22 | void bootretry_init_cmd_timeout(void) |
Simon Glass | 399ed9a | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 23 | { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 24 | char *s = env_get("bootretry"); |
Simon Glass | 399ed9a | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 25 | |
| 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 Glass | 09007c4 | 2014-04-10 20:01:31 -0600 | [diff] [blame] | 38 | void bootretry_reset_cmd_timeout(void) |
Simon Glass | 399ed9a | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 39 | { |
| 40 | endtime = endtick(retry_time); |
| 41 | } |
| 42 | |
| 43 | int bootretry_tstc_timeout(void) |
| 44 | { |
| 45 | while (!tstc()) { /* while no incoming data */ |
| 46 | if (retry_time >= 0 && get_ticks() > endtime) |
| 47 | return -ETIMEDOUT; |
Stefan Roese | 80877fa | 2022-09-02 14:10:46 +0200 | [diff] [blame] | 48 | schedule(); |
Simon Glass | 399ed9a | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | void bootretry_dont_retry(void) |
| 55 | { |
| 56 | retry_time = -1; |
| 57 | } |