board_f.c 26 KB

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