board_f.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  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. #include <linux/compiler.h>
  30. #include <version.h>
  31. #include <environment.h>
  32. #include <fdtdec.h>
  33. #if defined(CONFIG_CMD_IDE)
  34. #include <ide.h>
  35. #endif
  36. #include <i2c.h>
  37. #include <initcall.h>
  38. #include <logbuff.h>
  39. /* TODO: Can we move these into arch/ headers? */
  40. #ifdef CONFIG_8xx
  41. #include <mpc8xx.h>
  42. #endif
  43. #ifdef CONFIG_5xx
  44. #include <mpc5xx.h>
  45. #endif
  46. #ifdef CONFIG_MPC5xxx
  47. #include <mpc5xxx.h>
  48. #endif
  49. #include <os.h>
  50. #include <post.h>
  51. #include <spi.h>
  52. #include <watchdog.h>
  53. #include <asm/errno.h>
  54. #include <asm/io.h>
  55. #ifdef CONFIG_MP
  56. #include <asm/mp.h>
  57. #endif
  58. #include <asm/sections.h>
  59. #ifdef CONFIG_X86
  60. #include <asm/init_helpers.h>
  61. #include <asm/relocate.h>
  62. #endif
  63. #ifdef CONFIG_SANDBOX
  64. #include <asm/state.h>
  65. #endif
  66. #include <linux/compiler.h>
  67. /*
  68. * Pointer to initial global data area
  69. *
  70. * Here we initialize it if needed.
  71. */
  72. #ifdef XTRN_DECLARE_GLOBAL_DATA_PTR
  73. #undef XTRN_DECLARE_GLOBAL_DATA_PTR
  74. #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
  75. DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_GD_ADDR);
  76. #else
  77. DECLARE_GLOBAL_DATA_PTR;
  78. #endif
  79. /*
  80. * sjg: IMO this code should be
  81. * refactored to a single function, something like:
  82. *
  83. * void led_set_state(enum led_colour_t colour, int on);
  84. */
  85. /************************************************************************
  86. * Coloured LED functionality
  87. ************************************************************************
  88. * May be supplied by boards if desired
  89. */
  90. inline void __coloured_LED_init(void) {}
  91. void coloured_LED_init(void)
  92. __attribute__((weak, alias("__coloured_LED_init")));
  93. inline void __red_led_on(void) {}
  94. void red_led_on(void) __attribute__((weak, alias("__red_led_on")));
  95. inline void __red_led_off(void) {}
  96. void red_led_off(void) __attribute__((weak, alias("__red_led_off")));
  97. inline void __green_led_on(void) {}
  98. void green_led_on(void) __attribute__((weak, alias("__green_led_on")));
  99. inline void __green_led_off(void) {}
  100. void green_led_off(void) __attribute__((weak, alias("__green_led_off")));
  101. inline void __yellow_led_on(void) {}
  102. void yellow_led_on(void) __attribute__((weak, alias("__yellow_led_on")));
  103. inline void __yellow_led_off(void) {}
  104. void yellow_led_off(void) __attribute__((weak, alias("__yellow_led_off")));
  105. inline void __blue_led_on(void) {}
  106. void blue_led_on(void) __attribute__((weak, alias("__blue_led_on")));
  107. inline void __blue_led_off(void) {}
  108. void blue_led_off(void) __attribute__((weak, alias("__blue_led_off")));
  109. /*
  110. * Why is gd allocated a register? Prior to reloc it might be better to
  111. * just pass it around to each function in this file?
  112. *
  113. * After reloc one could argue that it is hardly used and doesn't need
  114. * to be in a register. Or if it is it should perhaps hold pointers to all
  115. * global data for all modules, so that post-reloc we can avoid the massive
  116. * literal pool we get on ARM. Or perhaps just encourage each module to use
  117. * a structure...
  118. */
  119. /*
  120. * Could the CONFIG_SPL_BUILD infection become a flag in gd?
  121. */
  122. #if defined(CONFIG_WATCHDOG)
  123. static int init_func_watchdog_init(void)
  124. {
  125. puts(" Watchdog enabled\n");
  126. WATCHDOG_RESET();
  127. return 0;
  128. }
  129. int init_func_watchdog_reset(void)
  130. {
  131. WATCHDOG_RESET();
  132. return 0;
  133. }
  134. #endif /* CONFIG_WATCHDOG */
  135. void __board_add_ram_info(int use_default)
  136. {
  137. /* please define platform specific board_add_ram_info() */
  138. }
  139. void board_add_ram_info(int)
  140. __attribute__ ((weak, alias("__board_add_ram_info")));
  141. static int init_baud_rate(void)
  142. {
  143. gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
  144. return 0;
  145. }
  146. static int display_text_info(void)
  147. {
  148. #ifndef CONFIG_SANDBOX
  149. ulong bss_start, bss_end;
  150. #ifdef CONFIG_SYS_SYM_OFFSETS
  151. bss_start = _bss_start_ofs + _TEXT_BASE;
  152. bss_end = _bss_end_ofs + _TEXT_BASE;
  153. #else
  154. bss_start = (ulong)&__bss_start;
  155. bss_end = (ulong)&__bss_end;
  156. #endif
  157. debug("U-Boot code: %08X -> %08lX BSS: -> %08lX\n",
  158. CONFIG_SYS_TEXT_BASE, bss_start, bss_end);
  159. #endif
  160. #ifdef CONFIG_MODEM_SUPPORT
  161. debug("Modem Support enabled\n");
  162. #endif
  163. #ifdef CONFIG_USE_IRQ
  164. debug("IRQ Stack: %08lx\n", IRQ_STACK_START);
  165. debug("FIQ Stack: %08lx\n", FIQ_STACK_START);
  166. #endif
  167. return 0;
  168. }
  169. static int announce_dram_init(void)
  170. {
  171. puts("DRAM: ");
  172. return 0;
  173. }
  174. #ifdef CONFIG_PPC
  175. static int init_func_ram(void)
  176. {
  177. #ifdef CONFIG_BOARD_TYPES
  178. int board_type = gd->board_type;
  179. #else
  180. int board_type = 0; /* use dummy arg */
  181. #endif
  182. gd->ram_size = initdram(board_type);
  183. if (gd->ram_size > 0)
  184. return 0;
  185. puts("*** failed ***\n");
  186. return 1;
  187. }
  188. #endif
  189. static int show_dram_config(void)
  190. {
  191. ulong size;
  192. #ifdef CONFIG_NR_DRAM_BANKS
  193. int i;
  194. debug("\nRAM Configuration:\n");
  195. for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  196. size += gd->bd->bi_dram[i].size;
  197. debug("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
  198. #ifdef DEBUG
  199. print_size(gd->bd->bi_dram[i].size, "\n");
  200. #endif
  201. }
  202. debug("\nDRAM: ");
  203. #else
  204. size = gd->ram_size;
  205. #endif
  206. print_size(size, "");
  207. board_add_ram_info(0);
  208. putc('\n');
  209. return 0;
  210. }
  211. ulong get_effective_memsize(void)
  212. {
  213. #ifndef CONFIG_VERY_BIG_RAM
  214. return gd->ram_size;
  215. #else
  216. /* limit stack to what we can reasonable map */
  217. return ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
  218. CONFIG_MAX_MEM_MAPPED : gd->ram_size);
  219. #endif
  220. }
  221. void __dram_init_banksize(void)
  222. {
  223. #if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE)
  224. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  225. gd->bd->bi_dram[0].size = get_effective_memsize();
  226. #endif
  227. }
  228. void dram_init_banksize(void)
  229. __attribute__((weak, alias("__dram_init_banksize")));
  230. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
  231. static int init_func_i2c(void)
  232. {
  233. puts("I2C: ");
  234. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  235. puts("ready\n");
  236. return 0;
  237. }
  238. #endif
  239. #if defined(CONFIG_HARD_SPI)
  240. static int init_func_spi(void)
  241. {
  242. puts("SPI: ");
  243. spi_init();
  244. puts("ready\n");
  245. return 0;
  246. }
  247. #endif
  248. __maybe_unused
  249. static int zero_global_data(void)
  250. {
  251. memset((void *)gd, '\0', sizeof(gd_t));
  252. return 0;
  253. }
  254. static int setup_mon_len(void)
  255. {
  256. #ifdef CONFIG_SYS_SYM_OFFSETS
  257. gd->mon_len = _bss_end_ofs;
  258. #elif defined(CONFIG_SANDBOX)
  259. gd->mon_len = (ulong)&_end - (ulong)_init;
  260. #else
  261. /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
  262. gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
  263. #endif
  264. return 0;
  265. }
  266. __weak int arch_cpu_init(void)
  267. {
  268. return 0;
  269. }
  270. #ifdef CONFIG_SANDBOX
  271. static int setup_ram_buf(void)
  272. {
  273. gd->arch.ram_buf = os_malloc(CONFIG_SYS_SDRAM_SIZE);
  274. assert(gd->arch.ram_buf);
  275. gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
  276. return 0;
  277. }
  278. #endif
  279. static int setup_fdt(void)
  280. {
  281. #ifdef CONFIG_OF_EMBED
  282. /* Get a pointer to the FDT */
  283. gd->fdt_blob = _binary_dt_dtb_start;
  284. #elif defined CONFIG_OF_SEPARATE
  285. /* FDT is at end of image */
  286. # ifdef CONFIG_SYS_SYM_OFFSETS
  287. gd->fdt_blob = (void *)(_end_ofs + CONFIG_SYS_TEXT_BASE);
  288. # else
  289. gd->fdt_blob = (ulong *)&_end;
  290. # endif
  291. #endif
  292. /* Allow the early environment to override the fdt address */
  293. gd->fdt_blob = (void *)getenv_ulong("fdtcontroladdr", 16,
  294. (uintptr_t)gd->fdt_blob);
  295. return 0;
  296. }
  297. /* Get the top of usable RAM */
  298. __weak ulong board_get_usable_ram_top(ulong total_size)
  299. {
  300. return gd->ram_top;
  301. }
  302. static int setup_dest_addr(void)
  303. {
  304. debug("Monitor len: %08lX\n", gd->mon_len);
  305. /*
  306. * Ram is setup, size stored in gd !!
  307. */
  308. debug("Ram size: %08lX\n", (ulong)gd->ram_size);
  309. #if defined(CONFIG_SYS_MEM_TOP_HIDE)
  310. /*
  311. * Subtract specified amount of memory to hide so that it won't
  312. * get "touched" at all by U-Boot. By fixing up gd->ram_size
  313. * the Linux kernel should now get passed the now "corrected"
  314. * memory size and won't touch it either. This should work
  315. * for arch/ppc and arch/powerpc. Only Linux board ports in
  316. * arch/powerpc with bootwrapper support, that recalculate the
  317. * memory size from the SDRAM controller setup will have to
  318. * get fixed.
  319. */
  320. gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
  321. #endif
  322. #ifdef CONFIG_SYS_SDRAM_BASE
  323. gd->ram_top = CONFIG_SYS_SDRAM_BASE;
  324. #endif
  325. gd->ram_top += get_effective_memsize();
  326. gd->ram_top = board_get_usable_ram_top(gd->mon_len);
  327. gd->dest_addr = gd->ram_top;
  328. debug("Ram top: %08lX\n", (ulong)gd->ram_top);
  329. #if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
  330. /*
  331. * We need to make sure the location we intend to put secondary core
  332. * boot code is reserved and not used by any part of u-boot
  333. */
  334. if (gd->dest_addr > determine_mp_bootpg(NULL)) {
  335. gd->dest_addr = determine_mp_bootpg(NULL);
  336. debug("Reserving MP boot page to %08lx\n", gd->dest_addr);
  337. }
  338. #endif
  339. gd->dest_addr_sp = gd->dest_addr;
  340. return 0;
  341. }
  342. #if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
  343. static int reserve_logbuffer(void)
  344. {
  345. /* reserve kernel log buffer */
  346. gd->dest_addr -= LOGBUFF_RESERVE;
  347. debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
  348. gd->dest_addr);
  349. return 0;
  350. }
  351. #endif
  352. #ifdef CONFIG_PRAM
  353. /* reserve protected RAM */
  354. static int reserve_pram(void)
  355. {
  356. ulong reg;
  357. reg = getenv_ulong("pram", 10, CONFIG_PRAM);
  358. gd->dest_addr -= (reg << 10); /* size is in kB */
  359. debug("Reserving %ldk for protected RAM at %08lx\n", reg,
  360. gd->dest_addr);
  361. return 0;
  362. }
  363. #endif /* CONFIG_PRAM */
  364. /* Round memory pointer down to next 4 kB limit */
  365. static int reserve_round_4k(void)
  366. {
  367. gd->dest_addr &= ~(4096 - 1);
  368. return 0;
  369. }
  370. #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \
  371. defined(CONFIG_ARM)
  372. static int reserve_mmu(void)
  373. {
  374. /* reserve TLB table */
  375. gd->arch.tlb_size = 4096 * 4;
  376. gd->dest_addr -= gd->arch.tlb_size;
  377. /* round down to next 64 kB limit */
  378. gd->dest_addr &= ~(0x10000 - 1);
  379. gd->arch.tlb_addr = gd->dest_addr;
  380. debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
  381. gd->arch.tlb_addr + gd->arch.tlb_size);
  382. return 0;
  383. }
  384. #endif
  385. #ifdef CONFIG_LCD
  386. static int reserve_lcd(void)
  387. {
  388. #ifdef CONFIG_FB_ADDR
  389. gd->fb_base = CONFIG_FB_ADDR;
  390. #else
  391. /* reserve memory for LCD display (always full pages) */
  392. gd->dest_addr = lcd_setmem(gd->dest_addr);
  393. gd->fb_base = gd->dest_addr;
  394. #endif /* CONFIG_FB_ADDR */
  395. return 0;
  396. }
  397. #endif /* CONFIG_LCD */
  398. #if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) \
  399. && !defined(CONFIG_ARM) && !defined(CONFIG_X86)
  400. static int reserve_video(void)
  401. {
  402. /* reserve memory for video display (always full pages) */
  403. gd->dest_addr = video_setmem(gd->dest_addr);
  404. gd->fb_base = gd->dest_addr;
  405. return 0;
  406. }
  407. #endif
  408. static int reserve_uboot(void)
  409. {
  410. /*
  411. * reserve memory for U-Boot code, data & bss
  412. * round down to next 4 kB limit
  413. */
  414. gd->dest_addr -= gd->mon_len;
  415. gd->dest_addr &= ~(4096 - 1);
  416. #ifdef CONFIG_E500
  417. /* round down to next 64 kB limit so that IVPR stays aligned */
  418. gd->dest_addr &= ~(65536 - 1);
  419. #endif
  420. debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10,
  421. gd->dest_addr);
  422. return 0;
  423. }
  424. #ifndef CONFIG_SPL_BUILD
  425. /* reserve memory for malloc() area */
  426. static int reserve_malloc(void)
  427. {
  428. gd->dest_addr_sp = gd->dest_addr - TOTAL_MALLOC_LEN;
  429. debug("Reserving %dk for malloc() at: %08lx\n",
  430. TOTAL_MALLOC_LEN >> 10, gd->dest_addr_sp);
  431. return 0;
  432. }
  433. /* (permanently) allocate a Board Info struct */
  434. static int reserve_board(void)
  435. {
  436. gd->dest_addr_sp -= sizeof(bd_t);
  437. gd->bd = (bd_t *)map_sysmem(gd->dest_addr_sp, sizeof(bd_t));
  438. memset(gd->bd, '\0', sizeof(bd_t));
  439. debug("Reserving %zu Bytes for Board Info at: %08lx\n",
  440. sizeof(bd_t), gd->dest_addr_sp);
  441. return 0;
  442. }
  443. #endif
  444. static int setup_machine(void)
  445. {
  446. #ifdef CONFIG_MACH_TYPE
  447. gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
  448. #endif
  449. return 0;
  450. }
  451. static int reserve_global_data(void)
  452. {
  453. gd->dest_addr_sp -= sizeof(gd_t);
  454. gd->new_gd = (gd_t *)map_sysmem(gd->dest_addr_sp, sizeof(gd_t));
  455. debug("Reserving %zu Bytes for Global Data at: %08lx\n",
  456. sizeof(gd_t), gd->dest_addr_sp);
  457. return 0;
  458. }
  459. static int reserve_fdt(void)
  460. {
  461. /*
  462. * If the device tree is sitting immediate above our image then we
  463. * must relocate it. If it is embedded in the data section, then it
  464. * will be relocated with other data.
  465. */
  466. if (gd->fdt_blob) {
  467. gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
  468. gd->dest_addr_sp -= gd->fdt_size;
  469. gd->new_fdt = map_sysmem(gd->dest_addr_sp, gd->fdt_size);
  470. debug("Reserving %lu Bytes for FDT at: %08lx\n",
  471. gd->fdt_size, gd->dest_addr_sp);
  472. }
  473. return 0;
  474. }
  475. static int reserve_stacks(void)
  476. {
  477. #ifdef CONFIG_SPL_BUILD
  478. # ifdef CONFIG_ARM
  479. gd->dest_addr_sp -= 128; /* leave 32 words for abort-stack */
  480. gd->irq_sp = gd->dest_addr_sp;
  481. # endif
  482. #else
  483. # ifdef CONFIG_PPC
  484. ulong *s;
  485. # endif
  486. /* setup stack pointer for exceptions */
  487. gd->dest_addr_sp -= 16;
  488. gd->dest_addr_sp &= ~0xf;
  489. gd->irq_sp = gd->dest_addr_sp;
  490. /*
  491. * Handle architecture-specific things here
  492. * TODO(sjg@chromium.org): Perhaps create arch_reserve_stack()
  493. * to handle this and put in arch/xxx/lib/stack.c
  494. */
  495. # ifdef CONFIG_ARM
  496. # ifdef CONFIG_USE_IRQ
  497. gd->dest_addr_sp -= (CONFIG_STACKSIZE_IRQ + CONFIG_STACKSIZE_FIQ);
  498. debug("Reserving %zu Bytes for IRQ stack at: %08lx\n",
  499. CONFIG_STACKSIZE_IRQ + CONFIG_STACKSIZE_FIQ, gd->dest_addr_sp);
  500. /* 8-byte alignment for ARM ABI compliance */
  501. gd->dest_addr_sp &= ~0x07;
  502. # endif
  503. /* leave 3 words for abort-stack, plus 1 for alignment */
  504. gd->dest_addr_sp -= 16;
  505. # elif defined(CONFIG_PPC)
  506. /* Clear initial stack frame */
  507. s = (ulong *) gd->dest_addr_sp;
  508. *s = 0; /* Terminate back chain */
  509. *++s = 0; /* NULL return address */
  510. # endif /* Architecture specific code */
  511. return 0;
  512. #endif
  513. }
  514. static int display_new_sp(void)
  515. {
  516. debug("New Stack Pointer is: %08lx\n", gd->dest_addr_sp);
  517. return 0;
  518. }
  519. #ifdef CONFIG_PPC
  520. static int setup_board_part1(void)
  521. {
  522. bd_t *bd = gd->bd;
  523. /*
  524. * Save local variables to board info struct
  525. */
  526. bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
  527. bd->bi_memsize = gd->ram_size; /* size in bytes */
  528. #ifdef CONFIG_SYS_SRAM_BASE
  529. bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
  530. bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
  531. #endif
  532. #if defined(CONFIG_8xx) || defined(CONFIG_8260) || defined(CONFIG_5xx) || \
  533. defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
  534. bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
  535. #endif
  536. #if defined(CONFIG_MPC5xxx)
  537. bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
  538. #endif
  539. #if defined(CONFIG_MPC83xx)
  540. bd->bi_immrbar = CONFIG_SYS_IMMR;
  541. #endif
  542. #if defined(CONFIG_MPC8220)
  543. bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
  544. bd->bi_inpfreq = gd->arch.inp_clk;
  545. bd->bi_pcifreq = gd->pci_clk;
  546. bd->bi_vcofreq = gd->arch.vco_clk;
  547. bd->bi_pevfreq = gd->arch.pev_clk;
  548. bd->bi_flbfreq = gd->arch.flb_clk;
  549. /* store bootparam to sram (backward compatible), here? */
  550. {
  551. u32 *sram = (u32 *) CONFIG_SYS_SRAM_BASE;
  552. *sram++ = gd->ram_size;
  553. *sram++ = gd->bus_clk;
  554. *sram++ = gd->arch.inp_clk;
  555. *sram++ = gd->cpu_clk;
  556. *sram++ = gd->arch.vco_clk;
  557. *sram++ = gd->arch.flb_clk;
  558. *sram++ = 0xb8c3ba11; /* boot signature */
  559. }
  560. #endif
  561. return 0;
  562. }
  563. static int setup_board_part2(void)
  564. {
  565. bd_t *bd = gd->bd;
  566. bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
  567. bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
  568. #if defined(CONFIG_CPM2)
  569. bd->bi_cpmfreq = gd->arch.cpm_clk;
  570. bd->bi_brgfreq = gd->arch.brg_clk;
  571. bd->bi_sccfreq = gd->arch.scc_clk;
  572. bd->bi_vco = gd->arch.vco_out;
  573. #endif /* CONFIG_CPM2 */
  574. #if defined(CONFIG_MPC512X)
  575. bd->bi_ipsfreq = gd->arch.ips_clk;
  576. #endif /* CONFIG_MPC512X */
  577. #if defined(CONFIG_MPC5xxx)
  578. bd->bi_ipbfreq = gd->arch.ipb_clk;
  579. bd->bi_pcifreq = gd->pci_clk;
  580. #endif /* CONFIG_MPC5xxx */
  581. return 0;
  582. }
  583. #endif
  584. #ifdef CONFIG_SYS_EXTBDINFO
  585. static int setup_board_extra(void)
  586. {
  587. bd_t *bd = gd->bd;
  588. strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version));
  589. strncpy((char *) bd->bi_r_version, U_BOOT_VERSION,
  590. sizeof(bd->bi_r_version));
  591. bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
  592. bd->bi_plb_busfreq = gd->bus_clk;
  593. #if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
  594. defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
  595. defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  596. bd->bi_pci_busfreq = get_PCI_freq();
  597. bd->bi_opbfreq = get_OPB_freq();
  598. #elif defined(CONFIG_XILINX_405)
  599. bd->bi_pci_busfreq = get_PCI_freq();
  600. #endif
  601. return 0;
  602. }
  603. #endif
  604. #ifdef CONFIG_POST
  605. static int init_post(void)
  606. {
  607. post_bootmode_init();
  608. post_run(NULL, POST_ROM | post_bootmode_get(0));
  609. return 0;
  610. }
  611. #endif
  612. static int setup_baud_rate(void)
  613. {
  614. /* Ick, can we get rid of this line? */
  615. gd->bd->bi_baudrate = gd->baudrate;
  616. return 0;
  617. }
  618. static int setup_dram_config(void)
  619. {
  620. /* Ram is board specific, so move it to board code ... */
  621. dram_init_banksize();
  622. return 0;
  623. }
  624. static int reloc_fdt(void)
  625. {
  626. if (gd->new_fdt) {
  627. memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
  628. gd->fdt_blob = gd->new_fdt;
  629. }
  630. return 0;
  631. }
  632. static int setup_reloc(void)
  633. {
  634. gd->relocaddr = gd->dest_addr;
  635. gd->start_addr_sp = gd->dest_addr_sp;
  636. gd->reloc_off = gd->dest_addr - CONFIG_SYS_TEXT_BASE;
  637. memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
  638. debug("Relocation Offset is: %08lx\n", gd->reloc_off);
  639. debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
  640. gd->dest_addr, (ulong)map_to_sysmem(gd->new_gd),
  641. gd->dest_addr_sp);
  642. return 0;
  643. }
  644. /* ARM calls relocate_code from its crt0.S */
  645. #if !defined(CONFIG_ARM)
  646. static int jump_to_copy(void)
  647. {
  648. /*
  649. * x86 is special, but in a nice way. It uses a trampoline which
  650. * enables the dcache if possible.
  651. *
  652. * For now, other archs use relocate_code(), which is implemented
  653. * similarly for all archs. When we do generic relocation, hopefully
  654. * we can make all archs enable the dcache prior to relocation.
  655. */
  656. #ifdef CONFIG_X86
  657. /*
  658. * SDRAM and console are now initialised. The final stack can now
  659. * be setup in SDRAM. Code execution will continue in Flash, but
  660. * with the stack in SDRAM and Global Data in temporary memory
  661. * (CPU cache)
  662. */
  663. board_init_f_r_trampoline(gd->start_addr_sp);
  664. #elif defined(CONFIG_SANDBOX)
  665. board_init_r(gd->new_gd, 0);
  666. #else
  667. relocate_code(gd->dest_addr_sp, gd->new_gd, gd->dest_addr);
  668. #endif
  669. return 0;
  670. }
  671. #endif
  672. /* Record the board_init_f() bootstage (after arch_cpu_init()) */
  673. static int mark_bootstage(void)
  674. {
  675. bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
  676. return 0;
  677. }
  678. static init_fnc_t init_sequence_f[] = {
  679. #if !defined(CONFIG_CPM2) && !defined(CONFIG_MPC512X) && \
  680. !defined(CONFIG_MPC83xx) && !defined(CONFIG_MPC85xx) && \
  681. !defined(CONFIG_MPC86xx) && !defined(CONFIG_X86)
  682. zero_global_data,
  683. #endif
  684. #ifdef CONFIG_SANDBOX
  685. setup_ram_buf,
  686. #endif
  687. setup_fdt,
  688. setup_mon_len,
  689. #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
  690. /* TODO: can this go into arch_cpu_init()? */
  691. probecpu,
  692. #endif
  693. arch_cpu_init, /* basic arch cpu dependent setup */
  694. #ifdef CONFIG_X86
  695. cpu_init_f, /* TODO(sjg@chromium.org): remove */
  696. # ifdef CONFIG_OF_CONTROL
  697. find_fdt, /* TODO(sjg@chromium.org): remove */
  698. # endif
  699. #endif
  700. mark_bootstage,
  701. #ifdef CONFIG_OF_CONTROL
  702. fdtdec_check_fdt,
  703. #endif
  704. #if defined(CONFIG_BOARD_EARLY_INIT_F)
  705. board_early_init_f,
  706. #endif
  707. /* TODO: can any of this go into arch_cpu_init()? */
  708. #if defined(CONFIG_PPC) && !defined(CONFIG_8xx_CPUCLK_DEFAULT)
  709. get_clocks, /* get CPU and bus clocks (etc.) */
  710. #if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \
  711. && !defined(CONFIG_TQM885D)
  712. adjust_sdram_tbs_8xx,
  713. #endif
  714. /* TODO: can we rename this to timer_init()? */
  715. init_timebase,
  716. #endif
  717. #ifdef CONFIG_ARM
  718. timer_init, /* initialize timer */
  719. #endif
  720. #ifdef CONFIG_BOARD_POSTCLK_INIT
  721. board_postclk_init,
  722. #endif
  723. #ifdef CONFIG_FSL_ESDHC
  724. get_clocks,
  725. #endif
  726. #ifdef CONFIG_SYS_ALLOC_DPRAM
  727. #if !defined(CONFIG_CPM2)
  728. dpram_init,
  729. #endif
  730. #endif
  731. #if defined(CONFIG_BOARD_POSTCLK_INIT)
  732. board_postclk_init,
  733. #endif
  734. env_init, /* initialize environment */
  735. #if defined(CONFIG_8xx_CPUCLK_DEFAULT)
  736. /* get CPU and bus clocks according to the environment variable */
  737. get_clocks_866,
  738. /* adjust sdram refresh rate according to the new clock */
  739. sdram_adjust_866,
  740. init_timebase,
  741. #endif
  742. init_baud_rate, /* initialze baudrate settings */
  743. serial_init, /* serial communications setup */
  744. console_init_f, /* stage 1 init of console */
  745. #ifdef CONFIG_SANDBOX
  746. sandbox_early_getopt_check,
  747. #endif
  748. #ifdef CONFIG_OF_CONTROL
  749. fdtdec_prepare_fdt,
  750. #endif
  751. display_options, /* say that we are here */
  752. display_text_info, /* show debugging info if required */
  753. #if defined(CONFIG_8260)
  754. prt_8260_rsr,
  755. prt_8260_clks,
  756. #endif /* CONFIG_8260 */
  757. #if defined(CONFIG_MPC83xx)
  758. prt_83xx_rsr,
  759. #endif
  760. #ifdef CONFIG_PPC
  761. checkcpu,
  762. #endif
  763. #if defined(CONFIG_DISPLAY_CPUINFO)
  764. print_cpuinfo, /* display cpu info (and speed) */
  765. #endif
  766. #if defined(CONFIG_MPC5xxx)
  767. prt_mpc5xxx_clks,
  768. #endif /* CONFIG_MPC5xxx */
  769. #if defined(CONFIG_MPC8220)
  770. prt_mpc8220_clks,
  771. #endif
  772. #if defined(CONFIG_DISPLAY_BOARDINFO)
  773. checkboard, /* display board info */
  774. #endif
  775. INIT_FUNC_WATCHDOG_INIT
  776. #if defined(CONFIG_MISC_INIT_F)
  777. misc_init_f,
  778. #endif
  779. INIT_FUNC_WATCHDOG_RESET
  780. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
  781. init_func_i2c,
  782. #endif
  783. #if defined(CONFIG_HARD_SPI)
  784. init_func_spi,
  785. #endif
  786. #ifdef CONFIG_X86
  787. dram_init_f, /* configure available RAM banks */
  788. calculate_relocation_address,
  789. #endif
  790. announce_dram_init,
  791. /* TODO: unify all these dram functions? */
  792. #ifdef CONFIG_ARM
  793. dram_init, /* configure available RAM banks */
  794. #endif
  795. #ifdef CONFIG_PPC
  796. init_func_ram,
  797. #endif
  798. #ifdef CONFIG_POST
  799. post_init_f,
  800. #endif
  801. INIT_FUNC_WATCHDOG_RESET
  802. #if defined(CONFIG_SYS_DRAM_TEST)
  803. testdram,
  804. #endif /* CONFIG_SYS_DRAM_TEST */
  805. INIT_FUNC_WATCHDOG_RESET
  806. #ifdef CONFIG_POST
  807. init_post,
  808. #endif
  809. INIT_FUNC_WATCHDOG_RESET
  810. /*
  811. * Now that we have DRAM mapped and working, we can
  812. * relocate the code and continue running from DRAM.
  813. *
  814. * Reserve memory at end of RAM for (top down in that order):
  815. * - area that won't get touched by U-Boot and Linux (optional)
  816. * - kernel log buffer
  817. * - protected RAM
  818. * - LCD framebuffer
  819. * - monitor code
  820. * - board info struct
  821. */
  822. setup_dest_addr,
  823. #if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
  824. reserve_logbuffer,
  825. #endif
  826. #ifdef CONFIG_PRAM
  827. reserve_pram,
  828. #endif
  829. reserve_round_4k,
  830. #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \
  831. defined(CONFIG_ARM)
  832. reserve_mmu,
  833. #endif
  834. #ifdef CONFIG_LCD
  835. reserve_lcd,
  836. #endif
  837. /* TODO: Why the dependency on CONFIG_8xx? */
  838. #if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) \
  839. && !defined(CONFIG_ARM) && !defined(CONFIG_X86)
  840. reserve_video,
  841. #endif
  842. reserve_uboot,
  843. #ifndef CONFIG_SPL_BUILD
  844. reserve_malloc,
  845. reserve_board,
  846. #endif
  847. setup_machine,
  848. reserve_global_data,
  849. reserve_fdt,
  850. reserve_stacks,
  851. setup_dram_config,
  852. show_dram_config,
  853. #ifdef CONFIG_PPC
  854. setup_board_part1,
  855. INIT_FUNC_WATCHDOG_RESET
  856. setup_board_part2,
  857. #endif
  858. setup_baud_rate,
  859. display_new_sp,
  860. #ifdef CONFIG_SYS_EXTBDINFO
  861. setup_board_extra,
  862. #endif
  863. INIT_FUNC_WATCHDOG_RESET
  864. reloc_fdt,
  865. setup_reloc,
  866. #ifndef CONFIG_ARM
  867. jump_to_copy,
  868. #endif
  869. NULL,
  870. };
  871. void board_init_f(ulong boot_flags)
  872. {
  873. #ifndef CONFIG_X86
  874. gd_t data;
  875. gd = &data;
  876. #endif
  877. gd->flags = boot_flags;
  878. if (initcall_run_list(init_sequence_f))
  879. hang();
  880. #ifndef CONFIG_ARM
  881. /* NOTREACHED - jump_to_copy() does not return */
  882. hang();
  883. #endif
  884. }
  885. #ifdef CONFIG_X86
  886. /*
  887. * For now this code is only used on x86.
  888. *
  889. * init_sequence_f_r is the list of init functions which are run when
  890. * U-Boot is executing from Flash with a semi-limited 'C' environment.
  891. * The following limitations must be considered when implementing an
  892. * '_f_r' function:
  893. * - 'static' variables are read-only
  894. * - Global Data (gd->xxx) is read/write
  895. *
  896. * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
  897. * supported). It _should_, if possible, copy global data to RAM and
  898. * initialise the CPU caches (to speed up the relocation process)
  899. *
  900. * NOTE: At present only x86 uses this route, but it is intended that
  901. * all archs will move to this when generic relocation is implemented.
  902. */
  903. static init_fnc_t init_sequence_f_r[] = {
  904. init_cache_f_r,
  905. copy_uboot_to_ram,
  906. clear_bss,
  907. do_elf_reloc_fixups,
  908. NULL,
  909. };
  910. void board_init_f_r(void)
  911. {
  912. if (initcall_run_list(init_sequence_f_r))
  913. hang();
  914. /*
  915. * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
  916. * Transfer execution from Flash to RAM by calculating the address
  917. * of the in-RAM copy of board_init_r() and calling it
  918. */
  919. (board_init_r + gd->reloc_off)(gd, gd->relocaddr);
  920. /* NOTREACHED - board_init_r() does not return */
  921. hang();
  922. }
  923. #endif /* CONFIG_X86 */
  924. void hang(void)
  925. {
  926. puts("### ERROR ### Please RESET the board ###\n");
  927. #ifdef CONFIG_SANDBOX
  928. os_exit(0);
  929. #else
  930. for (;;);
  931. #endif
  932. }