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