]> git.ipfire.org Git - thirdparty/u-boot.git/blame - boot/bootretry.c
Merge tag 'u-boot-dfu-20240419' of https://source.denx.de/u-boot/custodians/u-boot-dfu
[thirdparty/u-boot.git] / boot / bootretry.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
0098e179
SG
2/*
3 * (C) Copyright 2000
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
0098e179
SG
5 */
6
7#include <common.h>
8#include <bootretry.h>
9#include <cli.h>
7b51b576 10#include <env.h>
0098e179 11#include <errno.h>
1045315d 12#include <time.h>
0098e179
SG
13#include <watchdog.h>
14
0098e179
SG
15static uint64_t endtime; /* must be set, default is instant timeout */
16static int retry_time = -1; /* -1 so can call readline before main_loop */
17
18/***************************************************************************
19 * initialize command line timeout
20 */
b26440f1 21void bootretry_init_cmd_timeout(void)
0098e179 22{
00caae6d 23 char *s = env_get("bootretry");
0098e179
SG
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 */
b26440f1 37void bootretry_reset_cmd_timeout(void)
0098e179
SG
38{
39 endtime = endtick(retry_time);
40}
41
42int bootretry_tstc_timeout(void)
43{
44 while (!tstc()) { /* while no incoming data */
45 if (retry_time >= 0 && get_ticks() > endtime)
46 return -ETIMEDOUT;
29caf930 47 schedule();
0098e179
SG
48 }
49
50 return 0;
51}
52
53void bootretry_dont_retry(void)
54{
55 retry_time = -1;
56}