board_f.c 24 KB

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