bootretry.c 1.2 KB

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