board_f.c 26 KB

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