bootretry.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 <errno.h>
  10. #include <watchdog.h>
  11. #ifndef CONFIG_BOOT_RETRY_MIN
  12. #define CONFIG_BOOT_RETRY_MIN CONFIG_BOOT_RETRY_TIME
  13. #endif
  14. static uint64_t endtime; /* must be set, default is instant timeout */
  15. static int retry_time = -1; /* -1 so can call readline before main_loop */
  16. /***************************************************************************
  17. * initialize command line timeout
  18. */
  19. void bootretry_init_cmd_timeout(void)
  20. {
  21. char *s = env_get("bootretry");
  22. if (s != NULL)
  23. retry_time = (int)simple_strtol(s, NULL, 10);
  24. else
  25. retry_time = CONFIG_BOOT_RETRY_TIME;
  26. if (retry_time >= 0 && retry_time < CONFIG_BOOT_RETRY_MIN)
  27. retry_time = CONFIG_BOOT_RETRY_MIN;
  28. }
  29. /***************************************************************************
  30. * reset command line timeout to retry_time seconds
  31. */
  32. void bootretry_reset_cmd_timeout(void)
  33. {
  34. endtime = endtick(retry_time);
  35. }
  36. int bootretry_tstc_timeout(void)
  37. {
  38. while (!tstc()) { /* while no incoming data */
  39. if (retry_time >= 0 && get_ticks() > endtime)
  40. return -ETIMEDOUT;
  41. WATCHDOG_RESET();
  42. }
  43. return 0;
  44. }
  45. void bootretry_dont_retry(void)
  46. {
  47. retry_time = -1;
  48. }