board_f.c 25 KB

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