board_f.c 25 KB

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