bootretry.c 1.3 KB

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