Fork of the vendor (Boundary Devices) u-boot for Reform 2, with minor tweaks. The goal is to migrate to mainstream u-boot or barebox ASAP. The main impediment so far is the 4GB RAM config.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

132 lines
2.6 KiB

  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2015 Google, Inc
  4. * Written by Simon Glass <sjg@chromium.org>
  5. */
  6. #include <common.h>
  7. #include <command.h>
  8. #include <errno.h>
  9. static int test_get_timer(void)
  10. {
  11. ulong base, start, next, diff;
  12. int iter;
  13. base = get_timer(0);
  14. start = get_timer(0);
  15. for (iter = 0; iter < 10; iter++) {
  16. do {
  17. next = get_timer(0);
  18. } while (start == next);
  19. if (start + 1 != next) {
  20. printf("%s: iter=%d, start=%lu, next=%lu, expected a difference of 1\n",
  21. __func__, iter, start, next);
  22. return -EINVAL;
  23. }
  24. start++;
  25. }
  26. /*
  27. * Check that get_timer(base) matches our elapsed time, allowing that
  28. * an extra millisecond may have passed.
  29. */
  30. diff = get_timer(base);
  31. if (diff != iter && diff != iter + 1) {
  32. printf("%s: expected get_timer(base) to match elapsed time: diff=%lu, expected=%d\n",
  33. __func__, diff, iter);
  34. return -EINVAL;
  35. }
  36. return 0;
  37. }
  38. static int test_timer_get_us(void)
  39. {
  40. ulong prev, next, min = 1000000;
  41. long delta;
  42. int iter;
  43. /* Find the minimum delta we can measure, in microseconds */
  44. prev = timer_get_us();
  45. for (iter = 0; iter < 100; ) {
  46. next = timer_get_us();
  47. if (next != prev) {
  48. delta = next - prev;
  49. if (delta < 0) {
  50. printf("%s: timer_get_us() went backwards from %lu to %lu\n",
  51. __func__, prev, next);
  52. return -EINVAL;
  53. } else if (delta != 0) {
  54. if (delta < min)
  55. min = delta;
  56. prev = next;
  57. iter++;
  58. }
  59. }
  60. }
  61. if (min != 1) {
  62. printf("%s: Minimum microsecond delta should be 1 but is %lu\n",
  63. __func__, min);
  64. return -EINVAL;
  65. }
  66. return 0;
  67. }
  68. static int test_time_comparison(void)
  69. {
  70. ulong start_us, end_us, delta_us;
  71. long error;
  72. ulong start;
  73. start = get_timer(0);
  74. start_us = timer_get_us();
  75. while (get_timer(start) < 1000)
  76. ;
  77. end_us = timer_get_us();
  78. delta_us = end_us - start_us;
  79. error = delta_us - 1000000;
  80. printf("%s: Microsecond time for 1 second: %lu, error = %ld\n",
  81. __func__, delta_us, error);
  82. if (abs(error) > 1000)
  83. return -EINVAL;
  84. return 0;
  85. }
  86. static int test_udelay(void)
  87. {
  88. long error;
  89. ulong start, delta;
  90. int iter;
  91. start = get_timer(0);
  92. for (iter = 0; iter < 1000; iter++)
  93. udelay(1000);
  94. delta = get_timer(start);
  95. error = delta - 1000;
  96. printf("%s: Delay time for 1000 udelay(1000): %lu ms, error = %ld\n",
  97. __func__, delta, error);
  98. if (abs(error) > 100)
  99. return -EINVAL;
  100. return 0;
  101. }
  102. int do_ut_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  103. {
  104. int ret = 0;
  105. ret |= test_get_timer();
  106. ret |= test_timer_get_us();
  107. ret |= test_time_comparison();
  108. ret |= test_udelay();
  109. printf("Test %s\n", ret ? "failed" : "passed");
  110. return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
  111. }