board_r.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. /*
  2. * Copyright (c) 2011 The Chromium OS Authors.
  3. * (C) Copyright 2002-2006
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. *
  6. * (C) Copyright 2002
  7. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  8. * Marius Groeger <mgroeger@sysgo.de>
  9. *
  10. * See file CREDITS for list of people who contributed to this
  11. * project.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation; either version 2 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  26. * MA 02111-1307 USA
  27. */
  28. #include <common.h>
  29. #ifdef CONFIG_HAS_DATAFLASH
  30. #include <dataflash.h>
  31. #endif
  32. #include <environment.h>
  33. #include <fdtdec.h>
  34. #include <initcall.h>
  35. #include <logbuff.h>
  36. #include <malloc.h>
  37. #include <mmc.h>
  38. #include <nand.h>
  39. #include <onenand_uboot.h>
  40. #include <serial.h>
  41. #include <stdio_dev.h>
  42. #include <asm/sections.h>
  43. DECLARE_GLOBAL_DATA_PTR;
  44. ulong monitor_flash_len;
  45. static int initr_reloc(void)
  46. {
  47. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  48. bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
  49. return 0;
  50. }
  51. #ifdef CONFIG_ARM
  52. /*
  53. * Some of these functions are needed purely because the functions they
  54. * call return void. If we change them to return 0, these stubs can go away.
  55. */
  56. static int initr_caches(void)
  57. {
  58. /* Enable caches */
  59. enable_caches();
  60. return 0;
  61. }
  62. #endif
  63. static int initr_reloc_global_data(void)
  64. {
  65. #ifdef CONFIG_SYS_SYM_OFFSETS
  66. monitor_flash_len = _end_ofs;
  67. #else
  68. monitor_flash_len = (ulong)&__init_end - gd->dest_addr;
  69. #endif
  70. }
  71. static int initr_serial(void)
  72. {
  73. serial_initialize();
  74. return 0;
  75. }
  76. #ifdef CONFIG_LOGBUFFER
  77. unsigned long logbuffer_base(void)
  78. {
  79. return gd->ram_top - LOGBUFF_LEN;
  80. }
  81. static int initr_logbuffer(void)
  82. {
  83. logbuff_init_ptrs();
  84. return 0;
  85. }
  86. #endif
  87. #ifdef CONFIG_POST
  88. static int initr_post_backlog(void)
  89. {
  90. post_output_backlog();
  91. return 0;
  92. }
  93. #endif
  94. static int initr_malloc(void)
  95. {
  96. ulong malloc_start;
  97. /* The malloc area is immediately below the monitor copy in DRAM */
  98. malloc_start = gd->dest_addr - TOTAL_MALLOC_LEN;
  99. mem_malloc_init(malloc_start, TOTAL_MALLOC_LEN);
  100. return 0;
  101. }
  102. __weak int power_init_board(void)
  103. {
  104. return 0;
  105. }
  106. static int initr_announce(void)
  107. {
  108. debug("Now running in RAM - U-Boot at: %08lx\n", gd->dest_addr);
  109. return 0;
  110. }
  111. #if !defined(CONFIG_SYS_NO_FLASH)
  112. static int initr_flash(void)
  113. {
  114. ulong flash_size;
  115. puts("Flash: ");
  116. flash_size = flash_init();
  117. if (flash_size <= 0) {
  118. puts("*** failed ***\n");
  119. return -1;
  120. }
  121. print_size(flash_size, "");
  122. #ifdef CONFIG_SYS_FLASH_CHECKSUM
  123. /*
  124. * Compute and print flash CRC if flashchecksum is set to 'y'
  125. *
  126. * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
  127. */
  128. if (getenv_yesno("flashchecksum") == 1) {
  129. printf(" CRC: %08X", crc32(0,
  130. (const unsigned char *) CONFIG_SYS_FLASH_BASE,
  131. flash_size));
  132. }
  133. #endif /* CONFIG_SYS_FLASH_CHECKSUM */
  134. putc('\n');
  135. return 0;
  136. }
  137. #endif
  138. #ifdef CONFIG_CMD_NAND
  139. /* go init the NAND */
  140. int initr_nand(void)
  141. {
  142. puts("NAND: ");
  143. nand_init();
  144. return 0;
  145. }
  146. #endif
  147. #if defined(CONFIG_CMD_ONENAND)
  148. /* go init the NAND */
  149. int initr_onenand(void)
  150. {
  151. puts("NAND: ");
  152. onenand_init();
  153. return 0;
  154. }
  155. #endif
  156. #ifdef CONFIG_GENERIC_MMC
  157. int initr_mmc(void)
  158. {
  159. puts("MMC: ");
  160. mmc_initialize(gd->bd);
  161. return 0;
  162. }
  163. #endif
  164. #ifdef CONFIG_HAS_DATAFLASH
  165. int initr_dataflash(void)
  166. {
  167. AT91F_DataflashInit();
  168. dataflash_print_info();
  169. return 0;
  170. }
  171. #endif
  172. /*
  173. * Tell if it's OK to load the environment early in boot.
  174. *
  175. * If CONFIG_OF_CONFIG is defined, we'll check with the FDT to see
  176. * if this is OK (defaulting to saying it's OK).
  177. *
  178. * NOTE: Loading the environment early can be a bad idea if security is
  179. * important, since no verification is done on the environment.
  180. *
  181. * @return 0 if environment should not be loaded, !=0 if it is ok to load
  182. */
  183. static int should_load_env(void)
  184. {
  185. #ifdef CONFIG_OF_CONTROL
  186. return fdtdec_get_config_int(gd->fdt_blob, "load-environment", 1);
  187. #elif defined CONFIG_DELAY_ENVIRONMENT
  188. return 0;
  189. #else
  190. return 1;
  191. #endif
  192. }
  193. static int initr_env(void)
  194. {
  195. /* initialize environment */
  196. if (should_load_env())
  197. env_relocate();
  198. else
  199. set_default_env(NULL);
  200. /* Initialize from environment */
  201. load_addr = getenv_ulong("loadaddr", 16, load_addr);
  202. return 0;
  203. }
  204. static int initr_jumptable(void)
  205. {
  206. jumptable_init();
  207. return 0;
  208. }
  209. #if defined(CONFIG_API)
  210. static int initr_api(void)
  211. {
  212. /* Initialize API */
  213. api_init();
  214. return 0;
  215. }
  216. #endif
  217. #ifdef CONFIG_DISPLAY_BOARDINFO_LATE
  218. static int show_model_r(void)
  219. {
  220. /* Put this here so it appears on the LCD, now it is ready */
  221. # ifdef CONFIG_OF_CONTROL
  222. const char *model;
  223. model = (char *)fdt_getprop(gd->fdt_blob, 0, "model", NULL);
  224. printf("Model: %s\n", model ? model : "<unknown>");
  225. # else
  226. checkboard();
  227. # endif
  228. }
  229. #endif
  230. /* enable exceptions */
  231. static int initr_enable_interrupts(void)
  232. {
  233. enable_interrupts();
  234. return 0;
  235. }
  236. #ifdef CONFIG_CMD_NET
  237. static int initr_ethaddr(void)
  238. {
  239. return 0;
  240. }
  241. #endif /* CONFIG_CMD_NET */
  242. #ifdef CONFIG_BITBANGMII
  243. static int initr_bbmii(void)
  244. {
  245. bb_miiphy_init();
  246. return 0;
  247. }
  248. #endif
  249. #ifdef CONFIG_CMD_NET
  250. static int initr_net(void)
  251. {
  252. puts("Net: ");
  253. eth_initialize(gd->bd);
  254. #if defined(CONFIG_RESET_PHY_R)
  255. debug("Reset Ethernet PHY\n");
  256. reset_phy();
  257. #endif
  258. return 0;
  259. }
  260. #endif
  261. #ifdef CONFIG_POST
  262. static int initr_post(void)
  263. {
  264. post_run(NULL, POST_RAM | post_bootmode_get(0));
  265. return 0;
  266. }
  267. #endif
  268. #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
  269. /*
  270. * Export available size of memory for Linux, taking into account the
  271. * protected RAM at top of memory
  272. */
  273. int initr_mem(void)
  274. {
  275. ulong pram = 0;
  276. char memsz[32];
  277. # ifdef CONFIG_PRAM
  278. pram = getenv_ulong("pram", 10, CONFIG_PRAM);
  279. # endif
  280. # if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
  281. /* Also take the logbuffer into account (pram is in kB) */
  282. pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
  283. # endif
  284. sprintf(memsz, "%ldk", (gd->ram_size / 1024) - pram);
  285. setenv("mem", memsz);
  286. }
  287. #endif
  288. static int run_main_loop(void)
  289. {
  290. /* main_loop() can return to retry autoboot, if so just run it again */
  291. for (;;)
  292. main_loop();
  293. return 0;
  294. }
  295. /*
  296. * Over time we hope to remove these functions with code fragments and
  297. * stub funtcions, and instead call the relevant function directly.
  298. *
  299. * We also hope to remove most of the driver-related init and do it if/when
  300. * the driver is later used.
  301. */
  302. init_fnc_t init_sequence_r[] = {
  303. initr_reloc,
  304. #ifdef CONFIG_ARM
  305. initr_caches,
  306. board_init, /* Setup chipselects */
  307. #endif
  308. initr_reloc_global_data,
  309. initr_serial,
  310. initr_announce,
  311. #ifdef CONFIG_LOGBUFFER
  312. initr_logbuffer,
  313. #endif
  314. #ifdef CONFIG_POST
  315. initr_post_backlog,
  316. #endif
  317. initr_malloc,
  318. #ifdef CONFIG_ARCH_EARLY_INIT_R
  319. arch_early_init_r,
  320. #endif
  321. power_init_board,
  322. #ifndef CONFIG_SYS_NO_FLASH
  323. initr_flash,
  324. #endif
  325. #ifdef CONFIG_CMD_NAND
  326. initr_nand,
  327. #endif
  328. #ifdef CONFIG_CMD_ONENAND
  329. initr_onenand,
  330. #endif
  331. #ifdef CONFIG_GENERIC_MMC
  332. initr_mmc,
  333. #endif
  334. #ifdef CONFIG_HAS_DATAFLASH
  335. initr_dataflash,
  336. #endif
  337. initr_env,
  338. stdio_init,
  339. initr_jumptable,
  340. #ifdef CONFIG_API
  341. initr_api,
  342. #endif
  343. console_init_r, /* fully init console as a device */
  344. #ifdef CONFIG_DISPLAY_BOARDINFO_LATE
  345. show_model_r,
  346. #endif
  347. #ifdef CONFIG_ARCH_MISC_INIT
  348. arch_misc_init, /* miscellaneous arch-dependent init */
  349. #endif
  350. #ifdef CONFIG_MISC_INIT_R
  351. misc_init_r, /* miscellaneous platform-dependent init */
  352. #endif
  353. interrupt_init,
  354. initr_enable_interrupts,
  355. #ifdef CONFIG_CMD_NET
  356. initr_ethaddr,
  357. #endif
  358. #ifdef CONFIG_BOARD_LATE_INIT
  359. board_late_init,
  360. #endif
  361. #ifdef CONFIG_BITBANGMII
  362. initr_bbmii,
  363. #endif
  364. #ifdef CONFIG_CMD_NET
  365. initr_net,
  366. #endif
  367. #ifdef CONFIG_POST
  368. initr_post,
  369. #endif
  370. run_main_loop,
  371. };
  372. void board_init_r(gd_t *new_gd, ulong dest_addr)
  373. {
  374. gd = new_gd;
  375. if (initcall_run_list(init_sequence_r))
  376. hang();
  377. /* NOTREACHED - run_main_loop() does not return */
  378. hang();
  379. }