board_f.c 25 KB

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