board_f.c 24 KB

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