board_f.c 25 KB

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