board_f.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124
  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. #elif defined(CONFIG_SYS_MONITOR_BASE)
  243. /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
  244. gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
  245. #endif
  246. return 0;
  247. }
  248. __weak int arch_cpu_init(void)
  249. {
  250. return 0;
  251. }
  252. #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->arch.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. #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
  385. /*
  386. * Record allocated tlb_addr in case gd->tlb_addr to be overwritten
  387. * with location within secure ram.
  388. */
  389. gd->arch.tlb_allocated = gd->arch.tlb_addr;
  390. #endif
  391. return 0;
  392. }
  393. #endif
  394. #ifdef CONFIG_DM_VIDEO
  395. static int reserve_video(void)
  396. {
  397. ulong addr;
  398. int ret;
  399. addr = gd->relocaddr;
  400. ret = video_reserve(&addr);
  401. if (ret)
  402. return ret;
  403. gd->relocaddr = addr;
  404. return 0;
  405. }
  406. #else
  407. # ifdef CONFIG_LCD
  408. static int reserve_lcd(void)
  409. {
  410. # ifdef CONFIG_FB_ADDR
  411. gd->fb_base = CONFIG_FB_ADDR;
  412. # else
  413. /* reserve memory for LCD display (always full pages) */
  414. gd->relocaddr = lcd_setmem(gd->relocaddr);
  415. gd->fb_base = gd->relocaddr;
  416. # endif /* CONFIG_FB_ADDR */
  417. return 0;
  418. }
  419. # endif /* CONFIG_LCD */
  420. # if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
  421. !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
  422. !defined(CONFIG_BLACKFIN) && !defined(CONFIG_M68K)
  423. static int reserve_legacy_video(void)
  424. {
  425. /* reserve memory for video display (always full pages) */
  426. gd->relocaddr = video_setmem(gd->relocaddr);
  427. gd->fb_base = gd->relocaddr;
  428. return 0;
  429. }
  430. # endif
  431. #endif /* !CONFIG_DM_VIDEO */
  432. static int reserve_trace(void)
  433. {
  434. #ifdef CONFIG_TRACE
  435. gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
  436. gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
  437. debug("Reserving %dk for trace data at: %08lx\n",
  438. CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
  439. #endif
  440. return 0;
  441. }
  442. static int reserve_uboot(void)
  443. {
  444. /*
  445. * reserve memory for U-Boot code, data & bss
  446. * round down to next 4 kB limit
  447. */
  448. gd->relocaddr -= gd->mon_len;
  449. gd->relocaddr &= ~(4096 - 1);
  450. #ifdef CONFIG_E500
  451. /* round down to next 64 kB limit so that IVPR stays aligned */
  452. gd->relocaddr &= ~(65536 - 1);
  453. #endif
  454. debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10,
  455. gd->relocaddr);
  456. gd->start_addr_sp = gd->relocaddr;
  457. return 0;
  458. }
  459. #ifndef CONFIG_SPL_BUILD
  460. /* reserve memory for malloc() area */
  461. static int reserve_malloc(void)
  462. {
  463. gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
  464. debug("Reserving %dk for malloc() at: %08lx\n",
  465. TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
  466. return 0;
  467. }
  468. /* (permanently) allocate a Board Info struct */
  469. static int reserve_board(void)
  470. {
  471. if (!gd->bd) {
  472. gd->start_addr_sp -= sizeof(bd_t);
  473. gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
  474. memset(gd->bd, '\0', sizeof(bd_t));
  475. debug("Reserving %zu Bytes for Board Info at: %08lx\n",
  476. sizeof(bd_t), gd->start_addr_sp);
  477. }
  478. return 0;
  479. }
  480. #endif
  481. static int setup_machine(void)
  482. {
  483. #ifdef CONFIG_MACH_TYPE
  484. gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
  485. #endif
  486. return 0;
  487. }
  488. static int reserve_global_data(void)
  489. {
  490. gd->start_addr_sp -= sizeof(gd_t);
  491. gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
  492. debug("Reserving %zu Bytes for Global Data at: %08lx\n",
  493. sizeof(gd_t), gd->start_addr_sp);
  494. return 0;
  495. }
  496. static int reserve_fdt(void)
  497. {
  498. #ifndef CONFIG_OF_EMBED
  499. /*
  500. * If the device tree is sitting immediately above our image then we
  501. * must relocate it. If it is embedded in the data section, then it
  502. * will be relocated with other data.
  503. */
  504. if (gd->fdt_blob) {
  505. gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
  506. gd->start_addr_sp -= gd->fdt_size;
  507. gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
  508. debug("Reserving %lu Bytes for FDT at: %08lx\n",
  509. gd->fdt_size, gd->start_addr_sp);
  510. }
  511. #endif
  512. return 0;
  513. }
  514. int arch_reserve_stacks(void)
  515. {
  516. return 0;
  517. }
  518. static int reserve_stacks(void)
  519. {
  520. /* make stack pointer 16-byte aligned */
  521. gd->start_addr_sp -= 16;
  522. gd->start_addr_sp &= ~0xf;
  523. /*
  524. * let the architecture-specific code tailor gd->start_addr_sp and
  525. * gd->irq_sp
  526. */
  527. return arch_reserve_stacks();
  528. }
  529. static int display_new_sp(void)
  530. {
  531. debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
  532. return 0;
  533. }
  534. #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
  535. static int setup_board_part1(void)
  536. {
  537. bd_t *bd = gd->bd;
  538. /*
  539. * Save local variables to board info struct
  540. */
  541. bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
  542. bd->bi_memsize = gd->ram_size; /* size in bytes */
  543. #ifdef CONFIG_SYS_SRAM_BASE
  544. bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
  545. bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
  546. #endif
  547. #if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \
  548. defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
  549. bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
  550. #endif
  551. #if defined(CONFIG_MPC5xxx) || defined(CONFIG_M68K)
  552. bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
  553. #endif
  554. #if defined(CONFIG_MPC83xx)
  555. bd->bi_immrbar = CONFIG_SYS_IMMR;
  556. #endif
  557. return 0;
  558. }
  559. #endif
  560. #if defined(CONFIG_PPC) || defined(CONFIG_M68K)
  561. static int setup_board_part2(void)
  562. {
  563. bd_t *bd = gd->bd;
  564. bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
  565. bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
  566. #if defined(CONFIG_CPM2)
  567. bd->bi_cpmfreq = gd->arch.cpm_clk;
  568. bd->bi_brgfreq = gd->arch.brg_clk;
  569. bd->bi_sccfreq = gd->arch.scc_clk;
  570. bd->bi_vco = gd->arch.vco_out;
  571. #endif /* CONFIG_CPM2 */
  572. #if defined(CONFIG_MPC512X)
  573. bd->bi_ipsfreq = gd->arch.ips_clk;
  574. #endif /* CONFIG_MPC512X */
  575. #if defined(CONFIG_MPC5xxx)
  576. bd->bi_ipbfreq = gd->arch.ipb_clk;
  577. bd->bi_pcifreq = gd->pci_clk;
  578. #endif /* CONFIG_MPC5xxx */
  579. #if defined(CONFIG_M68K) && defined(CONFIG_PCI)
  580. bd->bi_pcifreq = gd->pci_clk;
  581. #endif
  582. #if defined(CONFIG_EXTRA_CLOCK)
  583. bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */
  584. bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */
  585. bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */
  586. #endif
  587. return 0;
  588. }
  589. #endif
  590. #ifdef CONFIG_SYS_EXTBDINFO
  591. static int setup_board_extra(void)
  592. {
  593. bd_t *bd = gd->bd;
  594. strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version));
  595. strncpy((char *) bd->bi_r_version, U_BOOT_VERSION,
  596. sizeof(bd->bi_r_version));
  597. bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
  598. bd->bi_plb_busfreq = gd->bus_clk;
  599. #if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
  600. defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
  601. defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  602. bd->bi_pci_busfreq = get_PCI_freq();
  603. bd->bi_opbfreq = get_OPB_freq();
  604. #elif defined(CONFIG_XILINX_405)
  605. bd->bi_pci_busfreq = get_PCI_freq();
  606. #endif
  607. return 0;
  608. }
  609. #endif
  610. #ifdef CONFIG_POST
  611. static int init_post(void)
  612. {
  613. post_bootmode_init();
  614. post_run(NULL, POST_ROM | post_bootmode_get(0));
  615. return 0;
  616. }
  617. #endif
  618. static int setup_dram_config(void)
  619. {
  620. /* Ram is board specific, so move it to board code ... */
  621. dram_init_banksize();
  622. return 0;
  623. }
  624. static int reloc_fdt(void)
  625. {
  626. #ifndef CONFIG_OF_EMBED
  627. if (gd->flags & GD_FLG_SKIP_RELOC)
  628. return 0;
  629. if (gd->new_fdt) {
  630. memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
  631. gd->fdt_blob = gd->new_fdt;
  632. }
  633. #endif
  634. return 0;
  635. }
  636. static int setup_reloc(void)
  637. {
  638. if (gd->flags & GD_FLG_SKIP_RELOC) {
  639. debug("Skipping relocation due to flag\n");
  640. return 0;
  641. }
  642. #ifdef CONFIG_SYS_TEXT_BASE
  643. gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
  644. #ifdef CONFIG_M68K
  645. /*
  646. * On all ColdFire arch cpu, monitor code starts always
  647. * just after the default vector table location, so at 0x400
  648. */
  649. gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
  650. #endif
  651. #endif
  652. memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
  653. debug("Relocation Offset is: %08lx\n", gd->reloc_off);
  654. debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
  655. gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
  656. gd->start_addr_sp);
  657. return 0;
  658. }
  659. /* ARM calls relocate_code from its crt0.S */
  660. #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
  661. static int jump_to_copy(void)
  662. {
  663. if (gd->flags & GD_FLG_SKIP_RELOC)
  664. return 0;
  665. /*
  666. * x86 is special, but in a nice way. It uses a trampoline which
  667. * enables the dcache if possible.
  668. *
  669. * For now, other archs use relocate_code(), which is implemented
  670. * similarly for all archs. When we do generic relocation, hopefully
  671. * we can make all archs enable the dcache prior to relocation.
  672. */
  673. #if defined(CONFIG_X86) || defined(CONFIG_ARC)
  674. /*
  675. * SDRAM and console are now initialised. The final stack can now
  676. * be setup in SDRAM. Code execution will continue in Flash, but
  677. * with the stack in SDRAM and Global Data in temporary memory
  678. * (CPU cache)
  679. */
  680. arch_setup_gd(gd->new_gd);
  681. board_init_f_r_trampoline(gd->start_addr_sp);
  682. #else
  683. relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
  684. #endif
  685. return 0;
  686. }
  687. #endif
  688. /* Record the board_init_f() bootstage (after arch_cpu_init()) */
  689. static int mark_bootstage(void)
  690. {
  691. bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
  692. return 0;
  693. }
  694. static int initf_console_record(void)
  695. {
  696. #if defined(CONFIG_CONSOLE_RECORD) && defined(CONFIG_SYS_MALLOC_F_LEN)
  697. return console_record_init();
  698. #else
  699. return 0;
  700. #endif
  701. }
  702. static int initf_dm(void)
  703. {
  704. #if defined(CONFIG_DM) && defined(CONFIG_SYS_MALLOC_F_LEN)
  705. int ret;
  706. ret = dm_init_and_scan(true);
  707. if (ret)
  708. return ret;
  709. #endif
  710. #ifdef CONFIG_TIMER_EARLY
  711. ret = dm_timer_init();
  712. if (ret)
  713. return ret;
  714. #endif
  715. return 0;
  716. }
  717. /* Architecture-specific memory reservation */
  718. __weak int reserve_arch(void)
  719. {
  720. return 0;
  721. }
  722. __weak int arch_cpu_init_dm(void)
  723. {
  724. return 0;
  725. }
  726. static init_fnc_t init_sequence_f[] = {
  727. #ifdef CONFIG_SANDBOX
  728. setup_ram_buf,
  729. #endif
  730. setup_mon_len,
  731. #ifdef CONFIG_OF_CONTROL
  732. fdtdec_setup,
  733. #endif
  734. #ifdef CONFIG_TRACE
  735. trace_early_init,
  736. #endif
  737. initf_malloc,
  738. initf_console_record,
  739. #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
  740. /* TODO: can this go into arch_cpu_init()? */
  741. probecpu,
  742. #endif
  743. #if defined(CONFIG_X86) && defined(CONFIG_HAVE_FSP)
  744. x86_fsp_init,
  745. #endif
  746. arch_cpu_init, /* basic arch cpu dependent setup */
  747. initf_dm,
  748. arch_cpu_init_dm,
  749. mark_bootstage, /* need timer, go after init dm */
  750. #if defined(CONFIG_BOARD_EARLY_INIT_F)
  751. board_early_init_f,
  752. #endif
  753. /* TODO: can any of this go into arch_cpu_init()? */
  754. #if defined(CONFIG_PPC) && !defined(CONFIG_8xx_CPUCLK_DEFAULT)
  755. get_clocks, /* get CPU and bus clocks (etc.) */
  756. #if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \
  757. && !defined(CONFIG_TQM885D)
  758. adjust_sdram_tbs_8xx,
  759. #endif
  760. /* TODO: can we rename this to timer_init()? */
  761. init_timebase,
  762. #endif
  763. #if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \
  764. defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \
  765. defined(CONFIG_SPARC)
  766. timer_init, /* initialize timer */
  767. #endif
  768. #ifdef CONFIG_SYS_ALLOC_DPRAM
  769. #if !defined(CONFIG_CPM2)
  770. dpram_init,
  771. #endif
  772. #endif
  773. #if defined(CONFIG_BOARD_POSTCLK_INIT)
  774. board_postclk_init,
  775. #endif
  776. #if defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
  777. get_clocks,
  778. #endif
  779. env_init, /* initialize environment */
  780. #if defined(CONFIG_8xx_CPUCLK_DEFAULT)
  781. /* get CPU and bus clocks according to the environment variable */
  782. get_clocks_866,
  783. /* adjust sdram refresh rate according to the new clock */
  784. sdram_adjust_866,
  785. init_timebase,
  786. #endif
  787. init_baud_rate, /* initialze baudrate settings */
  788. serial_init, /* serial communications setup */
  789. console_init_f, /* stage 1 init of console */
  790. #ifdef CONFIG_SANDBOX
  791. sandbox_early_getopt_check,
  792. #endif
  793. #ifdef CONFIG_OF_CONTROL
  794. fdtdec_prepare_fdt,
  795. #endif
  796. display_options, /* say that we are here */
  797. display_text_info, /* show debugging info if required */
  798. #if defined(CONFIG_MPC8260)
  799. prt_8260_rsr,
  800. prt_8260_clks,
  801. #endif /* CONFIG_MPC8260 */
  802. #if defined(CONFIG_MPC83xx)
  803. prt_83xx_rsr,
  804. #endif
  805. #if defined(CONFIG_PPC) || defined(CONFIG_M68K)
  806. checkcpu,
  807. #endif
  808. print_cpuinfo, /* display cpu info (and speed) */
  809. #if defined(CONFIG_MPC5xxx)
  810. prt_mpc5xxx_clks,
  811. #endif /* CONFIG_MPC5xxx */
  812. #if defined(CONFIG_DISPLAY_BOARDINFO)
  813. show_board_info,
  814. #endif
  815. INIT_FUNC_WATCHDOG_INIT
  816. #if defined(CONFIG_MISC_INIT_F)
  817. misc_init_f,
  818. #endif
  819. INIT_FUNC_WATCHDOG_RESET
  820. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
  821. init_func_i2c,
  822. #endif
  823. #if defined(CONFIG_HARD_SPI)
  824. init_func_spi,
  825. #endif
  826. announce_dram_init,
  827. /* TODO: unify all these dram functions? */
  828. #if defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_NDS32) || \
  829. defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32)
  830. dram_init, /* configure available RAM banks */
  831. #endif
  832. #if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
  833. init_func_ram,
  834. #endif
  835. #ifdef CONFIG_POST
  836. post_init_f,
  837. #endif
  838. INIT_FUNC_WATCHDOG_RESET
  839. #if defined(CONFIG_SYS_DRAM_TEST)
  840. testdram,
  841. #endif /* CONFIG_SYS_DRAM_TEST */
  842. INIT_FUNC_WATCHDOG_RESET
  843. #ifdef CONFIG_POST
  844. init_post,
  845. #endif
  846. INIT_FUNC_WATCHDOG_RESET
  847. /*
  848. * Now that we have DRAM mapped and working, we can
  849. * relocate the code and continue running from DRAM.
  850. *
  851. * Reserve memory at end of RAM for (top down in that order):
  852. * - area that won't get touched by U-Boot and Linux (optional)
  853. * - kernel log buffer
  854. * - protected RAM
  855. * - LCD framebuffer
  856. * - monitor code
  857. * - board info struct
  858. */
  859. setup_dest_addr,
  860. #if defined(CONFIG_BLACKFIN)
  861. /* Blackfin u-boot monitor should be on top of the ram */
  862. reserve_uboot,
  863. #endif
  864. #if defined(CONFIG_SPARC)
  865. reserve_prom,
  866. #endif
  867. #if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
  868. reserve_logbuffer,
  869. #endif
  870. #ifdef CONFIG_PRAM
  871. reserve_pram,
  872. #endif
  873. reserve_round_4k,
  874. #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \
  875. defined(CONFIG_ARM)
  876. reserve_mmu,
  877. #endif
  878. #ifdef CONFIG_DM_VIDEO
  879. reserve_video,
  880. #else
  881. # ifdef CONFIG_LCD
  882. reserve_lcd,
  883. # endif
  884. /* TODO: Why the dependency on CONFIG_8xx? */
  885. # if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
  886. !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
  887. !defined(CONFIG_BLACKFIN) && !defined(CONFIG_M68K)
  888. reserve_legacy_video,
  889. # endif
  890. #endif /* CONFIG_DM_VIDEO */
  891. reserve_trace,
  892. #if !defined(CONFIG_BLACKFIN)
  893. reserve_uboot,
  894. #endif
  895. #ifndef CONFIG_SPL_BUILD
  896. reserve_malloc,
  897. reserve_board,
  898. #endif
  899. setup_machine,
  900. reserve_global_data,
  901. reserve_fdt,
  902. reserve_arch,
  903. reserve_stacks,
  904. setup_dram_config,
  905. show_dram_config,
  906. #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
  907. setup_board_part1,
  908. #endif
  909. #if defined(CONFIG_PPC) || defined(CONFIG_M68K)
  910. INIT_FUNC_WATCHDOG_RESET
  911. setup_board_part2,
  912. #endif
  913. display_new_sp,
  914. #ifdef CONFIG_SYS_EXTBDINFO
  915. setup_board_extra,
  916. #endif
  917. INIT_FUNC_WATCHDOG_RESET
  918. reloc_fdt,
  919. setup_reloc,
  920. #if defined(CONFIG_X86) || defined(CONFIG_ARC)
  921. copy_uboot_to_ram,
  922. clear_bss,
  923. do_elf_reloc_fixups,
  924. #endif
  925. #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX)
  926. jump_to_copy,
  927. #endif
  928. NULL,
  929. };
  930. void board_init_f(ulong boot_flags)
  931. {
  932. #ifdef CONFIG_SYS_GENERIC_GLOBAL_DATA
  933. /*
  934. * For some archtectures, global data is initialized and used before
  935. * calling this function. The data should be preserved. For others,
  936. * CONFIG_SYS_GENERIC_GLOBAL_DATA should be defined and use the stack
  937. * here to host global data until relocation.
  938. */
  939. gd_t data;
  940. gd = &data;
  941. /*
  942. * Clear global data before it is accessed at debug print
  943. * in initcall_run_list. Otherwise the debug print probably
  944. * get the wrong vaule of gd->have_console.
  945. */
  946. zero_global_data();
  947. #endif
  948. gd->flags = boot_flags;
  949. gd->have_console = 0;
  950. if (initcall_run_list(init_sequence_f))
  951. hang();
  952. #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
  953. !defined(CONFIG_EFI_APP)
  954. /* NOTREACHED - jump_to_copy() does not return */
  955. hang();
  956. #endif
  957. }
  958. #if defined(CONFIG_X86) || defined(CONFIG_ARC)
  959. /*
  960. * For now this code is only used on x86.
  961. *
  962. * init_sequence_f_r is the list of init functions which are run when
  963. * U-Boot is executing from Flash with a semi-limited 'C' environment.
  964. * The following limitations must be considered when implementing an
  965. * '_f_r' function:
  966. * - 'static' variables are read-only
  967. * - Global Data (gd->xxx) is read/write
  968. *
  969. * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
  970. * supported). It _should_, if possible, copy global data to RAM and
  971. * initialise the CPU caches (to speed up the relocation process)
  972. *
  973. * NOTE: At present only x86 uses this route, but it is intended that
  974. * all archs will move to this when generic relocation is implemented.
  975. */
  976. static init_fnc_t init_sequence_f_r[] = {
  977. init_cache_f_r,
  978. NULL,
  979. };
  980. void board_init_f_r(void)
  981. {
  982. if (initcall_run_list(init_sequence_f_r))
  983. hang();
  984. /*
  985. * The pre-relocation drivers may be using memory that has now gone
  986. * away. Mark serial as unavailable - this will fall back to the debug
  987. * UART if available.
  988. */
  989. gd->flags &= ~GD_FLG_SERIAL_READY;
  990. /*
  991. * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
  992. * Transfer execution from Flash to RAM by calculating the address
  993. * of the in-RAM copy of board_init_r() and calling it
  994. */
  995. (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
  996. /* NOTREACHED - board_init_r() does not return */
  997. hang();
  998. }
  999. #endif /* CONFIG_X86 */