board_f.c 23 KB

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