post.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * BF537-STAMP POST code
  3. *
  4. * Enter bugs at http://blackfin.uclinux.org/
  5. *
  6. * Copyright (c) 2005-2009 Analog Devices Inc.
  7. *
  8. * Licensed under the GPL-2 or later.
  9. */
  10. #include <common.h>
  11. #include <config.h>
  12. #include <command.h>
  13. #include <asm/blackfin.h>
  14. /* Using sw10-PF5 as the hotkey */
  15. int post_hotkeys_pressed(void)
  16. {
  17. int delay = 3;
  18. int i;
  19. unsigned short value;
  20. *pPORTF_FER &= ~PF5;
  21. *pPORTFIO_DIR &= ~PF5;
  22. *pPORTFIO_INEN |= PF5;
  23. printf("########Press SW10 to enter Memory POST########: %2d ", delay);
  24. while (delay--) {
  25. for (i = 0; i < 100; i++) {
  26. value = *pPORTFIO & PF5;
  27. if (value != 0) {
  28. break;
  29. }
  30. udelay(10000);
  31. }
  32. printf("\b\b\b%2d ", delay);
  33. }
  34. printf("\b\b\b 0");
  35. printf("\n");
  36. if (value == 0)
  37. return 0;
  38. else {
  39. printf("Hotkey has been pressed, Enter POST . . . . . .\n");
  40. return 1;
  41. }
  42. }
  43. int uart_post_test(int flags)
  44. {
  45. return 0;
  46. }
  47. #define BLOCK_SIZE 0x10000
  48. #define VERIFY_ADDR 0x2000000
  49. extern int erase_block_flash(int);
  50. extern int write_data(long lStart, long lCount, uchar * pnData);
  51. int flash_post_test(int flags)
  52. {
  53. unsigned short *pbuf, *temp;
  54. int offset, n, i;
  55. int value = 0;
  56. int result = 0;
  57. printf("\n");
  58. pbuf = (unsigned short *)VERIFY_ADDR;
  59. temp = pbuf;
  60. for (n = FLASH_START_POST_BLOCK; n < FLASH_END_POST_BLOCK; n++) {
  61. offset = (n - 7) * BLOCK_SIZE;
  62. printf("--------Erase block:%2d..", n);
  63. erase_block_flash(n);
  64. printf("OK\r");
  65. printf("--------Program block:%2d...", n);
  66. write_data(CONFIG_SYS_FLASH_BASE + offset, BLOCK_SIZE, pbuf);
  67. printf("OK\r");
  68. printf("--------Verify block:%2d...", n);
  69. for (i = 0; i < BLOCK_SIZE; i += 2) {
  70. if (*(unsigned short *)(CONFIG_SYS_FLASH_BASE + offset + i) !=
  71. *temp++) {
  72. value = 1;
  73. result = 1;
  74. }
  75. }
  76. if (value)
  77. printf("failed\n");
  78. else
  79. printf("OK %3d%%\r",
  80. (int)(
  81. (n + 1 -
  82. FLASH_START_POST_BLOCK) *
  83. 100 / (FLASH_END_POST_BLOCK -
  84. FLASH_START_POST_BLOCK)));
  85. temp = pbuf;
  86. value = 0;
  87. }
  88. printf("\n");
  89. if (result)
  90. return -1;
  91. else
  92. return 0;
  93. }
  94. /****************************************************
  95. * LED1 ---- PF6 LED2 ---- PF7 *
  96. * LED3 ---- PF8 LED4 ---- PF9 *
  97. * LED5 ---- PF10 LED6 ---- PF11 *
  98. ****************************************************/
  99. int led_post_test(int flags)
  100. {
  101. *pPORTF_FER &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
  102. *pPORTFIO_DIR |= PF6 | PF7 | PF8 | PF9 | PF10 | PF11;
  103. *pPORTFIO_INEN &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
  104. *pPORTFIO &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
  105. udelay(1000000);
  106. printf("LED1 on");
  107. *pPORTFIO |= PF6;
  108. udelay(1000000);
  109. printf("\b\b\b\b\b\b\b");
  110. printf("LED2 on");
  111. *pPORTFIO |= PF7;
  112. udelay(1000000);
  113. printf("\b\b\b\b\b\b\b");
  114. printf("LED3 on");
  115. *pPORTFIO |= PF8;
  116. udelay(1000000);
  117. printf("\b\b\b\b\b\b\b");
  118. printf("LED4 on");
  119. *pPORTFIO |= PF9;
  120. udelay(1000000);
  121. printf("\b\b\b\b\b\b\b");
  122. printf("LED5 on");
  123. *pPORTFIO |= PF10;
  124. udelay(1000000);
  125. printf("\b\b\b\b\b\b\b");
  126. printf("lED6 on");
  127. *pPORTFIO |= PF11;
  128. printf("\b\b\b\b\b\b\b ");
  129. return 0;
  130. }
  131. /************************************************
  132. * SW10 ---- PF5 SW11 ---- PF4 *
  133. * SW12 ---- PF3 SW13 ---- PF2 *
  134. ************************************************/
  135. int button_post_test(int flags)
  136. {
  137. int i, delay = 5;
  138. unsigned short value = 0;
  139. int result = 0;
  140. *pPORTF_FER &= ~(PF5 | PF4 | PF3 | PF2);
  141. *pPORTFIO_DIR &= ~(PF5 | PF4 | PF3 | PF2);
  142. *pPORTFIO_INEN |= (PF5 | PF4 | PF3 | PF2);
  143. printf("\n--------Press SW10: %2d ", delay);
  144. while (delay--) {
  145. for (i = 0; i < 100; i++) {
  146. value = *pPORTFIO & PF5;
  147. if (value != 0) {
  148. break;
  149. }
  150. udelay(10000);
  151. }
  152. printf("\b\b\b%2d ", delay);
  153. }
  154. if (value != 0)
  155. printf("\b\bOK");
  156. else {
  157. result = -1;
  158. printf("\b\bfailed");
  159. }
  160. delay = 5;
  161. printf("\n--------Press SW11: %2d ", delay);
  162. while (delay--) {
  163. for (i = 0; i < 100; i++) {
  164. value = *pPORTFIO & PF4;
  165. if (value != 0) {
  166. break;
  167. }
  168. udelay(10000);
  169. }
  170. printf("\b\b\b%2d ", delay);
  171. }
  172. if (value != 0)
  173. printf("\b\bOK");
  174. else {
  175. result = -1;
  176. printf("\b\bfailed");
  177. }
  178. delay = 5;
  179. printf("\n--------Press SW12: %2d ", delay);
  180. while (delay--) {
  181. for (i = 0; i < 100; i++) {
  182. value = *pPORTFIO & PF3;
  183. if (value != 0) {
  184. break;
  185. }
  186. udelay(10000);
  187. }
  188. printf("\b\b\b%2d ", delay);
  189. }
  190. if (value != 0)
  191. printf("\b\bOK");
  192. else {
  193. result = -1;
  194. printf("\b\bfailed");
  195. }
  196. delay = 5;
  197. printf("\n--------Press SW13: %2d ", delay);
  198. while (delay--) {
  199. for (i = 0; i < 100; i++) {
  200. value = *pPORTFIO & PF2;
  201. if (value != 0) {
  202. break;
  203. }
  204. udelay(10000);
  205. }
  206. printf("\b\b\b%2d ", delay);
  207. }
  208. if (value != 0)
  209. printf("\b\bOK");
  210. else {
  211. result = -1;
  212. printf("\b\bfailed");
  213. }
  214. printf("\n");
  215. return result;
  216. }