board_f.c 25 KB

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