board_f.c 24 KB

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