bootretry.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2000
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. */
  6. #include <common.h>
  7. #include <bootretry.h>
  8. #include <cli.h>
  9. #include <env.h>
  10. #include <errno.h>
  11. #include <time.h>
  12. #include <watchdog.h>
  13. #ifndef CONFIG_BOOT_RETRY_MIN
  14. #define CONFIG_BOOT_RETRY_MIN CONFIG_BOOT_RETRY_TIME
  15. #endif
  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. * initialize command line timeout
  20. */
  21. void bootretry_init_cmd_timeout(void)
  22. {
  23. char *s = env_get("bootretry");
  24. if (s != NULL)
  25. retry_time = (int)simple_strtol(s, NULL, 10);
  26. else
  27. retry_time = CONFIG_BOOT_RETRY_TIME;
  28. if (retry_time >= 0 && retry_time < CONFIG_BOOT_RETRY_MIN)
  29. retry_time = CONFIG_BOOT_RETRY_MIN;
  30. }
  31. /***************************************************************************
  32. * reset command line timeout to retry_time seconds
  33. */
  34. void bootretry_reset_cmd_timeout(void)
  35. {
  36. endtime = endtick(retry_time);
  37. }
  38. int bootretry_tstc_timeout(void)
  39. {
  40. while (!tstc()) { /* while no incoming data */
  41. if (retry_time >= 0 && get_ticks() > endtime)
  42. return -ETIMEDOUT;
  43. WATCHDOG_RESET();
  44. }
  45. return 0;
  46. }
  47. void bootretry_dont_retry(void)
  48. {
  49. retry_time = -1;
  50. }