board_f.c 23 KB

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