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