board.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * (C) Copyright 2008-2011
  3. * Graeme Russ, <graeme.russ@gmail.com>
  4. *
  5. * (C) Copyright 2002
  6. * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
  7. *
  8. * (C) Copyright 2002
  9. * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
  10. *
  11. * (C) Copyright 2002
  12. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  13. * Marius Groeger <mgroeger@sysgo.de>
  14. *
  15. * See file CREDITS for list of people who contributed to this
  16. * project.
  17. *
  18. * This program is free software; you can redistribute it and/or
  19. * modify it under the terms of the GNU General Public License as
  20. * published by the Free Software Foundation; either version 2 of
  21. * the License, or (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU General Public License
  29. * along with this program; if not, write to the Free Software
  30. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  31. * MA 02111-1307 USA
  32. */
  33. #include <common.h>
  34. #include <watchdog.h>
  35. #include <stdio_dev.h>
  36. #include <asm/u-boot-x86.h>
  37. #include <asm/relocate.h>
  38. #include <asm/init_helpers.h>
  39. #include <asm/init_wrappers.h>
  40. /*
  41. * Breath some life into the board...
  42. *
  43. * Getting the board up and running is a three-stage process:
  44. * 1) Execute from Flash, SDRAM Uninitialised
  45. * At this point, there is a limited amount of non-SDRAM memory
  46. * (typically the CPU cache, but can also be SRAM or even a buffer of
  47. * of some peripheral). This limited memory is used to hold:
  48. * - The initial copy of the Global Data Structure
  49. * - A temporary stack
  50. * - A temporary x86 Global Descriptor Table
  51. * - The pre-console buffer (if enabled)
  52. *
  53. * The following is performed during this phase of execution:
  54. * - Core low-level CPU initialisation
  55. * - Console initialisation
  56. * - SDRAM initialisation
  57. *
  58. * 2) Execute from Flash, SDRAM Initialised
  59. * At this point we copy Global Data from the initial non-SDRAM
  60. * memory and set up the permanent stack in SDRAM. The CPU cache is no
  61. * longer being used as temporary memory, so we can now fully enable
  62. * it.
  63. *
  64. * The following is performed during this phase of execution:
  65. * - Create final stack in SDRAM
  66. * - Copy Global Data from temporary memory to SDRAM
  67. * - Enabling of CPU cache(s),
  68. * - Copying of U-Boot code and data from Flash to RAM
  69. * - Clearing of the BSS
  70. * - ELF relocation adjustments
  71. *
  72. * 3) Execute from SDRAM
  73. * The following is performed during this phase of execution:
  74. * - All remaining initialisation
  75. */
  76. /*
  77. * The requirements for any new initalization function is simple: it is
  78. * a function with no parameters which returns an integer return code,
  79. * where 0 means "continue" and != 0 means "fatal error, hang the system"
  80. */
  81. typedef int (init_fnc_t) (void);
  82. /*
  83. * init_sequence_f is the list of init functions which are run when U-Boot
  84. * is executing from Flash with a limited 'C' environment. The following
  85. * limitations must be considered when implementing an '_f' function:
  86. * - 'static' variables are read-only
  87. * - Global Data (gd->xxx) is read/write
  88. * - Stack space is limited
  89. *
  90. * The '_f' sequence must, as a minimum, initialise SDRAM. It _should_
  91. * also initialise the console (to provide early debug output)
  92. */
  93. init_fnc_t *init_sequence_f[] = {
  94. cpu_init_f,
  95. board_early_init_f,
  96. env_init,
  97. init_baudrate_f,
  98. serial_init,
  99. console_init_f,
  100. dram_init_f,
  101. calculate_relocation_address,
  102. NULL,
  103. };
  104. /*
  105. * init_sequence_f_r is the list of init functions which are run when
  106. * U-Boot is executing from Flash with a semi-limited 'C' environment.
  107. * The following limitations must be considered when implementing an
  108. * '_f_r' function:
  109. * - 'static' variables are read-only
  110. * - Global Data (gd->xxx) is read/write
  111. *
  112. * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
  113. * supported). It _should_, if possible, copy global data to RAM and
  114. * initialise the CPU caches (to speed up the relocation process)
  115. */
  116. init_fnc_t *init_sequence_f_r[] = {
  117. copy_gd_to_ram_f_r,
  118. init_cache_f_r,
  119. copy_uboot_to_ram,
  120. clear_bss,
  121. do_elf_reloc_fixups,
  122. NULL,
  123. };
  124. /*
  125. * init_sequence_r is the list of init functions which are run when U-Boot
  126. * is executing from RAM with a full 'C' environment. There are no longer
  127. * any limitations which must be considered when implementing an '_r'
  128. * function, (i.e.'static' variables are read/write)
  129. *
  130. * If not already done, the '_r' sequence must copy global data to RAM and
  131. * (should) initialise the CPU caches.
  132. */
  133. init_fnc_t *init_sequence_r[] = {
  134. set_reloc_flag_r,
  135. init_bd_struct_r,
  136. mem_malloc_init_r,
  137. cpu_init_r,
  138. board_early_init_r,
  139. dram_init,
  140. interrupt_init,
  141. timer_init,
  142. display_banner,
  143. display_dram_config,
  144. #ifdef CONFIG_SERIAL_MULTI
  145. serial_initialize_r,
  146. #endif
  147. #ifndef CONFIG_SYS_NO_FLASH
  148. flash_init_r,
  149. #endif
  150. env_relocate_r,
  151. #ifdef CONFIG_PCI
  152. pci_init_r,
  153. #endif
  154. stdio_init,
  155. jumptable_init_r,
  156. console_init_r,
  157. #ifdef CONFIG_MISC_INIT_R
  158. misc_init_r,
  159. #endif
  160. #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
  161. pci_init_r,
  162. #endif
  163. #if defined(CONFIG_CMD_KGDB)
  164. kgdb_init_r,
  165. #endif
  166. enable_interrupts_r,
  167. #ifdef CONFIG_STATUS_LED
  168. status_led_set_r,
  169. #endif
  170. set_load_addr_r,
  171. #if defined(CONFIG_CMD_IDE)
  172. ide_init_r,
  173. #endif
  174. #if defined(CONFIG_CMD_SCSI)
  175. scsi_init_r,
  176. #endif
  177. #if defined(CONFIG_CMD_DOC)
  178. doc_init_r,
  179. #endif
  180. #ifdef CONFIG_BITBANGMII
  181. bb_miiphy_init_r,
  182. #endif
  183. #if defined(CONFIG_CMD_NET)
  184. eth_initialize_r,
  185. #ifdef CONFIG_RESET_PHY_R
  186. reset_phy_r,
  187. #endif
  188. #endif
  189. #ifdef CONFIG_LAST_STAGE_INIT
  190. last_stage_init,
  191. #endif
  192. NULL,
  193. };
  194. static void do_init_loop(init_fnc_t **init_fnc_ptr)
  195. {
  196. for (; *init_fnc_ptr; ++init_fnc_ptr) {
  197. WATCHDOG_RESET();
  198. if ((*init_fnc_ptr)() != 0)
  199. hang();
  200. }
  201. }
  202. void board_init_f(ulong boot_flags)
  203. {
  204. gd->flags = boot_flags;
  205. do_init_loop(init_sequence_f);
  206. /*
  207. * SDRAM and console are now initialised. The final stack can now
  208. * be setup in SDRAM. Code execution will continue in Flash, but
  209. * with the stack in SDRAM and Global Data in temporary memory
  210. * (CPU cache)
  211. */
  212. board_init_f_r_trampoline(gd->start_addr_sp);
  213. /* NOTREACHED - board_init_f_r_trampoline() does not return */
  214. while (1)
  215. ;
  216. }
  217. void board_init_f_r(void)
  218. {
  219. do_init_loop(init_sequence_f_r);
  220. /*
  221. * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
  222. * Transfer execution from Flash to RAM by calculating the address
  223. * of the in-RAM copy of board_init_r() and calling it
  224. */
  225. (board_init_r + gd->reloc_off)(gd, gd->relocaddr);
  226. /* NOTREACHED - board_init_r() does not return */
  227. while (1)
  228. ;
  229. }
  230. void board_init_r(gd_t *id, ulong dest_addr)
  231. {
  232. do_init_loop(init_sequence_r);
  233. /* main_loop() can return to retry autoboot, if so just run it again. */
  234. for (;;)
  235. main_loop();
  236. /* NOTREACHED - no way out of command loop except booting */
  237. }
  238. void hang(void)
  239. {
  240. puts("### ERROR ### Please RESET the board ###\n");
  241. for (;;)
  242. ;
  243. }