post.c 4.9 KB

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