1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * (C) Copyright 2000 4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 5 */ 6 7 #include <common.h> 8 #include <bootretry.h> 9 #include <cli.h> 10 #include <env.h> 11 #include <errno.h> 12 #include <time.h> 13 #include <watchdog.h> 14 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 */ bootretry_init_cmd_timeout(void)21void bootretry_init_cmd_timeout(void) 22 { 23 char *s = env_get("bootretry"); 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 */ bootretry_reset_cmd_timeout(void)37void bootretry_reset_cmd_timeout(void) 38 { 39 endtime = endtick(retry_time); 40 } 41 bootretry_tstc_timeout(void)42int bootretry_tstc_timeout(void) 43 { 44 while (!tstc()) { /* while no incoming data */ 45 if (retry_time >= 0 && get_ticks() > endtime) 46 return -ETIMEDOUT; 47 schedule(); 48 } 49 50 return 0; 51 } 52 bootretry_dont_retry(void)53void bootretry_dont_retry(void) 54 { 55 retry_time = -1; 56 } 57