board_f.c 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  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. #ifdef CONFIG_SYS_SYM_OFFSETS
  137. bss_start = _bss_start_ofs + _TEXT_BASE;
  138. bss_end = _bss_end_ofs + _TEXT_BASE;
  139. #else
  140. bss_start = (ulong)&__bss_start;
  141. bss_end = (ulong)&__bss_end;
  142. #endif
  143. debug("U-Boot code: %08X -> %08lX BSS: -> %08lX\n",
  144. CONFIG_SYS_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. #ifdef CONFIG_PPC
  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. ulong 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: %08lx ", i, gd->bd->bi_dram[i].start);
  184. #ifdef DEBUG
  185. print_size(gd->bd->bi_dram[i].size, "\n");
  186. #endif
  187. }
  188. debug("\nDRAM: ");
  189. #else
  190. size = gd->ram_size;
  191. #endif
  192. print_size(size, "");
  193. board_add_ram_info(0);
  194. putc('\n');
  195. return 0;
  196. }
  197. ulong get_effective_memsize(void)
  198. {
  199. #ifndef CONFIG_VERY_BIG_RAM
  200. return gd->ram_size;
  201. #else
  202. /* limit stack to what we can reasonable map */
  203. return ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
  204. CONFIG_MAX_MEM_MAPPED : gd->ram_size);
  205. #endif
  206. }
  207. void __dram_init_banksize(void)
  208. {
  209. #if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE)
  210. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  211. gd->bd->bi_dram[0].size = get_effective_memsize();
  212. #endif
  213. }
  214. void dram_init_banksize(void)
  215. __attribute__((weak, alias("__dram_init_banksize")));
  216. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
  217. static int init_func_i2c(void)
  218. {
  219. puts("I2C: ");
  220. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  221. puts("ready\n");
  222. return 0;
  223. }
  224. #endif
  225. #if defined(CONFIG_HARD_SPI)
  226. static int init_func_spi(void)
  227. {
  228. puts("SPI: ");
  229. spi_init();
  230. puts("ready\n");
  231. return 0;
  232. }
  233. #endif
  234. __maybe_unused
  235. static int zero_global_data(void)
  236. {
  237. memset((void *)gd, '\0', sizeof(gd_t));
  238. return 0;
  239. }
  240. static int setup_mon_len(void)
  241. {
  242. #ifdef CONFIG_SYS_SYM_OFFSETS
  243. gd->mon_len = _bss_end_ofs;
  244. #elif defined(CONFIG_SANDBOX)
  245. gd->mon_len = (ulong)&_end - (ulong)_init;
  246. #else
  247. /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
  248. gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
  249. #endif
  250. return 0;
  251. }
  252. __weak int arch_cpu_init(void)
  253. {
  254. return 0;
  255. }
  256. #ifdef CONFIG_OF_HOSTFILE
  257. #define CHECK(x) err = (x); if (err) goto failed;
  258. /* Create an empty device tree blob */
  259. static int make_empty_fdt(void *fdt)
  260. {
  261. int err;
  262. CHECK(fdt_create(fdt, 256));
  263. CHECK(fdt_finish_reservemap(fdt));
  264. CHECK(fdt_begin_node(fdt, ""));
  265. CHECK(fdt_end_node(fdt));
  266. CHECK(fdt_finish(fdt));
  267. return 0;
  268. failed:
  269. printf("Unable to create empty FDT: %s\n", fdt_strerror(err));
  270. return -EACCES;
  271. }
  272. static int read_fdt_from_file(void)
  273. {
  274. struct sandbox_state *state = state_get_current();
  275. void *blob;
  276. int size;
  277. int err;
  278. blob = map_sysmem(CONFIG_SYS_FDT_LOAD_ADDR, 0);
  279. if (!state->fdt_fname) {
  280. err = make_empty_fdt(blob);
  281. if (!err)
  282. goto done;
  283. return err;
  284. }
  285. err = fs_set_blk_dev("host", NULL, FS_TYPE_SANDBOX);
  286. if (err)
  287. return err;
  288. size = fs_read(state->fdt_fname, CONFIG_SYS_FDT_LOAD_ADDR, 0, 0);
  289. if (size < 0)
  290. return -EIO;
  291. done:
  292. gd->fdt_blob = blob;
  293. return 0;
  294. }
  295. #endif
  296. #ifdef CONFIG_SANDBOX
  297. static int setup_ram_buf(void)
  298. {
  299. gd->arch.ram_buf = os_malloc(CONFIG_SYS_SDRAM_SIZE);
  300. assert(gd->arch.ram_buf);
  301. gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
  302. return 0;
  303. }
  304. #endif
  305. static int setup_fdt(void)
  306. {
  307. #ifdef CONFIG_OF_EMBED
  308. /* Get a pointer to the FDT */
  309. gd->fdt_blob = _binary_dt_dtb_start;
  310. #elif defined CONFIG_OF_SEPARATE
  311. /* FDT is at end of image */
  312. # ifdef CONFIG_SYS_SYM_OFFSETS
  313. gd->fdt_blob = (void *)(_end_ofs + CONFIG_SYS_TEXT_BASE);
  314. # else
  315. gd->fdt_blob = (ulong *)&_end;
  316. # endif
  317. #elif defined(CONFIG_OF_HOSTFILE)
  318. if (read_fdt_from_file()) {
  319. puts("Failed to read control FDT\n");
  320. return -1;
  321. }
  322. #endif
  323. /* Allow the early environment to override the fdt address */
  324. gd->fdt_blob = (void *)getenv_ulong("fdtcontroladdr", 16,
  325. (uintptr_t)gd->fdt_blob);
  326. return 0;
  327. }
  328. /* Get the top of usable RAM */
  329. __weak ulong board_get_usable_ram_top(ulong total_size)
  330. {
  331. return gd->ram_top;
  332. }
  333. static int setup_dest_addr(void)
  334. {
  335. debug("Monitor len: %08lX\n", gd->mon_len);
  336. /*
  337. * Ram is setup, size stored in gd !!
  338. */
  339. debug("Ram size: %08lX\n", (ulong)gd->ram_size);
  340. #if defined(CONFIG_SYS_MEM_TOP_HIDE)
  341. /*
  342. * Subtract specified amount of memory to hide so that it won't
  343. * get "touched" at all by U-Boot. By fixing up gd->ram_size
  344. * the Linux kernel should now get passed the now "corrected"
  345. * memory size and won't touch it either. This should work
  346. * for arch/ppc and arch/powerpc. Only Linux board ports in
  347. * arch/powerpc with bootwrapper support, that recalculate the
  348. * memory size from the SDRAM controller setup will have to
  349. * get fixed.
  350. */
  351. gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
  352. #endif
  353. #ifdef CONFIG_SYS_SDRAM_BASE
  354. gd->ram_top = CONFIG_SYS_SDRAM_BASE;
  355. #endif
  356. gd->ram_top += get_effective_memsize();
  357. gd->ram_top = board_get_usable_ram_top(gd->mon_len);
  358. gd->relocaddr = gd->ram_top;
  359. debug("Ram top: %08lX\n", (ulong)gd->ram_top);
  360. #if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
  361. /*
  362. * We need to make sure the location we intend to put secondary core
  363. * boot code is reserved and not used by any part of u-boot
  364. */
  365. if (gd->relocaddr > determine_mp_bootpg(NULL)) {
  366. gd->relocaddr = determine_mp_bootpg(NULL);
  367. debug("Reserving MP boot page to %08lx\n", gd->relocaddr);
  368. }
  369. #endif
  370. return 0;
  371. }
  372. #if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
  373. static int reserve_logbuffer(void)
  374. {
  375. /* reserve kernel log buffer */
  376. gd->relocaddr -= LOGBUFF_RESERVE;
  377. debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
  378. gd->relocaddr);
  379. return 0;
  380. }
  381. #endif
  382. #ifdef CONFIG_PRAM
  383. /* reserve protected RAM */
  384. static int reserve_pram(void)
  385. {
  386. ulong reg;
  387. reg = getenv_ulong("pram", 10, CONFIG_PRAM);
  388. gd->relocaddr -= (reg << 10); /* size is in kB */
  389. debug("Reserving %ldk for protected RAM at %08lx\n", reg,
  390. gd->relocaddr);
  391. return 0;
  392. }
  393. #endif /* CONFIG_PRAM */
  394. /* Round memory pointer down to next 4 kB limit */
  395. static int reserve_round_4k(void)
  396. {
  397. gd->relocaddr &= ~(4096 - 1);
  398. return 0;
  399. }
  400. #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \
  401. defined(CONFIG_ARM)
  402. static int reserve_mmu(void)
  403. {
  404. /* reserve TLB table */
  405. gd->arch.tlb_size = 4096 * 4;
  406. gd->relocaddr -= gd->arch.tlb_size;
  407. /* round down to next 64 kB limit */
  408. gd->relocaddr &= ~(0x10000 - 1);
  409. gd->arch.tlb_addr = gd->relocaddr;
  410. debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
  411. gd->arch.tlb_addr + gd->arch.tlb_size);
  412. return 0;
  413. }
  414. #endif
  415. #ifdef CONFIG_LCD
  416. static int reserve_lcd(void)
  417. {
  418. #ifdef CONFIG_FB_ADDR
  419. gd->fb_base = CONFIG_FB_ADDR;
  420. #else
  421. /* reserve memory for LCD display (always full pages) */
  422. gd->relocaddr = lcd_setmem(gd->relocaddr);
  423. gd->fb_base = gd->relocaddr;
  424. #endif /* CONFIG_FB_ADDR */
  425. return 0;
  426. }
  427. #endif /* CONFIG_LCD */
  428. static int reserve_trace(void)
  429. {
  430. #ifdef CONFIG_TRACE
  431. gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
  432. gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
  433. debug("Reserving %dk for trace data at: %08lx\n",
  434. CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
  435. #endif
  436. return 0;
  437. }
  438. #if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) \
  439. && !defined(CONFIG_ARM) && !defined(CONFIG_X86)
  440. static int reserve_video(void)
  441. {
  442. /* reserve memory for video display (always full pages) */
  443. gd->relocaddr = video_setmem(gd->relocaddr);
  444. gd->fb_base = gd->relocaddr;
  445. return 0;
  446. }
  447. #endif
  448. static int reserve_uboot(void)
  449. {
  450. /*
  451. * reserve memory for U-Boot code, data & bss
  452. * round down to next 4 kB limit
  453. */
  454. gd->relocaddr -= gd->mon_len;
  455. gd->relocaddr &= ~(4096 - 1);
  456. #ifdef CONFIG_E500
  457. /* round down to next 64 kB limit so that IVPR stays aligned */
  458. gd->relocaddr &= ~(65536 - 1);
  459. #endif
  460. debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10,
  461. gd->relocaddr);
  462. gd->start_addr_sp = gd->relocaddr;
  463. return 0;
  464. }
  465. #ifndef CONFIG_SPL_BUILD
  466. /* reserve memory for malloc() area */
  467. static int reserve_malloc(void)
  468. {
  469. gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
  470. debug("Reserving %dk for malloc() at: %08lx\n",
  471. TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
  472. return 0;
  473. }
  474. /* (permanently) allocate a Board Info struct */
  475. static int reserve_board(void)
  476. {
  477. gd->start_addr_sp -= sizeof(bd_t);
  478. gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
  479. memset(gd->bd, '\0', sizeof(bd_t));
  480. debug("Reserving %zu Bytes for Board Info at: %08lx\n",
  481. sizeof(bd_t), gd->start_addr_sp);
  482. return 0;
  483. }
  484. #endif
  485. static int setup_machine(void)
  486. {
  487. #ifdef CONFIG_MACH_TYPE
  488. gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
  489. #endif
  490. return 0;
  491. }
  492. static int reserve_global_data(void)
  493. {
  494. gd->start_addr_sp -= sizeof(gd_t);
  495. gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
  496. debug("Reserving %zu Bytes for Global Data at: %08lx\n",
  497. sizeof(gd_t), gd->start_addr_sp);
  498. return 0;
  499. }
  500. static int reserve_fdt(void)
  501. {
  502. /*
  503. * If the device tree is sitting immediate above our image then we
  504. * must relocate it. If it is embedded in the data section, then it
  505. * will be relocated with other data.
  506. */
  507. if (gd->fdt_blob) {
  508. gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
  509. gd->start_addr_sp -= gd->fdt_size;
  510. gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
  511. debug("Reserving %lu Bytes for FDT at: %08lx\n",
  512. gd->fdt_size, gd->start_addr_sp);
  513. }
  514. return 0;
  515. }
  516. static int reserve_stacks(void)
  517. {
  518. #ifdef CONFIG_SPL_BUILD
  519. # ifdef CONFIG_ARM
  520. gd->start_addr_sp -= 128; /* leave 32 words for abort-stack */
  521. gd->irq_sp = gd->start_addr_sp;
  522. # endif
  523. #else
  524. # ifdef CONFIG_PPC
  525. ulong *s;
  526. # endif
  527. /* setup stack pointer for exceptions */
  528. gd->start_addr_sp -= 16;
  529. gd->start_addr_sp &= ~0xf;
  530. gd->irq_sp = gd->start_addr_sp;
  531. /*
  532. * Handle architecture-specific things here
  533. * TODO(sjg@chromium.org): Perhaps create arch_reserve_stack()
  534. * to handle this and put in arch/xxx/lib/stack.c
  535. */
  536. # ifdef CONFIG_ARM
  537. # ifdef CONFIG_USE_IRQ
  538. gd->start_addr_sp -= (CONFIG_STACKSIZE_IRQ + CONFIG_STACKSIZE_FIQ);
  539. debug("Reserving %zu Bytes for IRQ stack at: %08lx\n",
  540. CONFIG_STACKSIZE_IRQ + CONFIG_STACKSIZE_FIQ, gd->start_addr_sp);
  541. /* 8-byte alignment for ARM ABI compliance */
  542. gd->start_addr_sp &= ~0x07;
  543. # endif
  544. /* leave 3 words for abort-stack, plus 1 for alignment */
  545. gd->start_addr_sp -= 16;
  546. # elif defined(CONFIG_PPC)
  547. /* Clear initial stack frame */
  548. s = (ulong *) gd->start_addr_sp;
  549. *s = 0; /* Terminate back chain */
  550. *++s = 0; /* NULL return address */
  551. # endif /* Architecture specific code */
  552. return 0;
  553. #endif
  554. }
  555. static int display_new_sp(void)
  556. {
  557. debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
  558. return 0;
  559. }
  560. #ifdef CONFIG_PPC
  561. static int setup_board_part1(void)
  562. {
  563. bd_t *bd = gd->bd;
  564. /*
  565. * Save local variables to board info struct
  566. */
  567. bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
  568. bd->bi_memsize = gd->ram_size; /* size in bytes */
  569. #ifdef CONFIG_SYS_SRAM_BASE
  570. bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
  571. bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
  572. #endif
  573. #if defined(CONFIG_8xx) || defined(CONFIG_8260) || defined(CONFIG_5xx) || \
  574. defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
  575. bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
  576. #endif
  577. #if defined(CONFIG_MPC5xxx)
  578. bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
  579. #endif
  580. #if defined(CONFIG_MPC83xx)
  581. bd->bi_immrbar = CONFIG_SYS_IMMR;
  582. #endif
  583. return 0;
  584. }
  585. static int setup_board_part2(void)
  586. {
  587. bd_t *bd = gd->bd;
  588. bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
  589. bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
  590. #if defined(CONFIG_CPM2)
  591. bd->bi_cpmfreq = gd->arch.cpm_clk;
  592. bd->bi_brgfreq = gd->arch.brg_clk;
  593. bd->bi_sccfreq = gd->arch.scc_clk;
  594. bd->bi_vco = gd->arch.vco_out;
  595. #endif /* CONFIG_CPM2 */
  596. #if defined(CONFIG_MPC512X)
  597. bd->bi_ipsfreq = gd->arch.ips_clk;
  598. #endif /* CONFIG_MPC512X */
  599. #if defined(CONFIG_MPC5xxx)
  600. bd->bi_ipbfreq = gd->arch.ipb_clk;
  601. bd->bi_pcifreq = gd->pci_clk;
  602. #endif /* CONFIG_MPC5xxx */
  603. return 0;
  604. }
  605. #endif
  606. #ifdef CONFIG_SYS_EXTBDINFO
  607. static int setup_board_extra(void)
  608. {
  609. bd_t *bd = gd->bd;
  610. strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version));
  611. strncpy((char *) bd->bi_r_version, U_BOOT_VERSION,
  612. sizeof(bd->bi_r_version));
  613. bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
  614. bd->bi_plb_busfreq = gd->bus_clk;
  615. #if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
  616. defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
  617. defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  618. bd->bi_pci_busfreq = get_PCI_freq();
  619. bd->bi_opbfreq = get_OPB_freq();
  620. #elif defined(CONFIG_XILINX_405)
  621. bd->bi_pci_busfreq = get_PCI_freq();
  622. #endif
  623. return 0;
  624. }
  625. #endif
  626. #ifdef CONFIG_POST
  627. static int init_post(void)
  628. {
  629. post_bootmode_init();
  630. post_run(NULL, POST_ROM | post_bootmode_get(0));
  631. return 0;
  632. }
  633. #endif
  634. static int setup_baud_rate(void)
  635. {
  636. /* Ick, can we get rid of this line? */
  637. gd->bd->bi_baudrate = gd->baudrate;
  638. return 0;
  639. }
  640. static int setup_dram_config(void)
  641. {
  642. /* Ram is board specific, so move it to board code ... */
  643. dram_init_banksize();
  644. return 0;
  645. }
  646. static int reloc_fdt(void)
  647. {
  648. if (gd->new_fdt) {
  649. memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
  650. gd->fdt_blob = gd->new_fdt;
  651. }
  652. return 0;
  653. }
  654. static int setup_reloc(void)
  655. {
  656. gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
  657. memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
  658. debug("Relocation Offset is: %08lx\n", gd->reloc_off);
  659. debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
  660. gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
  661. gd->start_addr_sp);
  662. return 0;
  663. }
  664. /* ARM calls relocate_code from its crt0.S */
  665. #if !defined(CONFIG_ARM)
  666. static int jump_to_copy(void)
  667. {
  668. /*
  669. * x86 is special, but in a nice way. It uses a trampoline which
  670. * enables the dcache if possible.
  671. *
  672. * For now, other archs use relocate_code(), which is implemented
  673. * similarly for all archs. When we do generic relocation, hopefully
  674. * we can make all archs enable the dcache prior to relocation.
  675. */
  676. #ifdef CONFIG_X86
  677. /*
  678. * SDRAM and console are now initialised. The final stack can now
  679. * be setup in SDRAM. Code execution will continue in Flash, but
  680. * with the stack in SDRAM and Global Data in temporary memory
  681. * (CPU cache)
  682. */
  683. board_init_f_r_trampoline(gd->start_addr_sp);
  684. #elif defined(CONFIG_SANDBOX)
  685. board_init_r(gd->new_gd, 0);
  686. #else
  687. relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
  688. #endif
  689. return 0;
  690. }
  691. #endif
  692. /* Record the board_init_f() bootstage (after arch_cpu_init()) */
  693. static int mark_bootstage(void)
  694. {
  695. bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
  696. return 0;
  697. }
  698. static init_fnc_t init_sequence_f[] = {
  699. #if !defined(CONFIG_CPM2) && !defined(CONFIG_MPC512X) && \
  700. !defined(CONFIG_MPC83xx) && !defined(CONFIG_MPC85xx) && \
  701. !defined(CONFIG_MPC86xx) && !defined(CONFIG_X86)
  702. zero_global_data,
  703. #endif
  704. #ifdef CONFIG_SANDBOX
  705. setup_ram_buf,
  706. #endif
  707. setup_mon_len,
  708. setup_fdt,
  709. trace_early_init,
  710. #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
  711. /* TODO: can this go into arch_cpu_init()? */
  712. probecpu,
  713. #endif
  714. arch_cpu_init, /* basic arch cpu dependent setup */
  715. #ifdef CONFIG_X86
  716. cpu_init_f, /* TODO(sjg@chromium.org): remove */
  717. # ifdef CONFIG_OF_CONTROL
  718. find_fdt, /* TODO(sjg@chromium.org): remove */
  719. # endif
  720. #endif
  721. mark_bootstage,
  722. #ifdef CONFIG_OF_CONTROL
  723. fdtdec_check_fdt,
  724. #endif
  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. #ifdef CONFIG_ARM
  739. timer_init, /* initialize timer */
  740. #endif
  741. #ifdef CONFIG_SYS_ALLOC_DPRAM
  742. #if !defined(CONFIG_CPM2)
  743. dpram_init,
  744. #endif
  745. #endif
  746. #if defined(CONFIG_BOARD_POSTCLK_INIT)
  747. board_postclk_init,
  748. #endif
  749. #ifdef CONFIG_FSL_ESDHC
  750. get_clocks,
  751. #endif
  752. env_init, /* initialize environment */
  753. #if defined(CONFIG_8xx_CPUCLK_DEFAULT)
  754. /* get CPU and bus clocks according to the environment variable */
  755. get_clocks_866,
  756. /* adjust sdram refresh rate according to the new clock */
  757. sdram_adjust_866,
  758. init_timebase,
  759. #endif
  760. init_baud_rate, /* initialze baudrate settings */
  761. serial_init, /* serial communications setup */
  762. console_init_f, /* stage 1 init of console */
  763. #ifdef CONFIG_SANDBOX
  764. sandbox_early_getopt_check,
  765. #endif
  766. #ifdef CONFIG_OF_CONTROL
  767. fdtdec_prepare_fdt,
  768. #endif
  769. display_options, /* say that we are here */
  770. display_text_info, /* show debugging info if required */
  771. #if defined(CONFIG_8260)
  772. prt_8260_rsr,
  773. prt_8260_clks,
  774. #endif /* CONFIG_8260 */
  775. #if defined(CONFIG_MPC83xx)
  776. prt_83xx_rsr,
  777. #endif
  778. #ifdef CONFIG_PPC
  779. checkcpu,
  780. #endif
  781. #if defined(CONFIG_DISPLAY_CPUINFO)
  782. print_cpuinfo, /* display cpu info (and speed) */
  783. #endif
  784. #if defined(CONFIG_MPC5xxx)
  785. prt_mpc5xxx_clks,
  786. #endif /* CONFIG_MPC5xxx */
  787. #if defined(CONFIG_DISPLAY_BOARDINFO)
  788. checkboard, /* display 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. #ifdef CONFIG_X86
  802. dram_init_f, /* configure available RAM banks */
  803. calculate_relocation_address,
  804. #endif
  805. announce_dram_init,
  806. /* TODO: unify all these dram functions? */
  807. #ifdef CONFIG_ARM
  808. dram_init, /* configure available RAM banks */
  809. #endif
  810. #ifdef CONFIG_PPC
  811. init_func_ram,
  812. #endif
  813. #ifdef CONFIG_POST
  814. post_init_f,
  815. #endif
  816. INIT_FUNC_WATCHDOG_RESET
  817. #if defined(CONFIG_SYS_DRAM_TEST)
  818. testdram,
  819. #endif /* CONFIG_SYS_DRAM_TEST */
  820. INIT_FUNC_WATCHDOG_RESET
  821. #ifdef CONFIG_POST
  822. init_post,
  823. #endif
  824. INIT_FUNC_WATCHDOG_RESET
  825. /*
  826. * Now that we have DRAM mapped and working, we can
  827. * relocate the code and continue running from DRAM.
  828. *
  829. * Reserve memory at end of RAM for (top down in that order):
  830. * - area that won't get touched by U-Boot and Linux (optional)
  831. * - kernel log buffer
  832. * - protected RAM
  833. * - LCD framebuffer
  834. * - monitor code
  835. * - board info struct
  836. */
  837. setup_dest_addr,
  838. #if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
  839. reserve_logbuffer,
  840. #endif
  841. #ifdef CONFIG_PRAM
  842. reserve_pram,
  843. #endif
  844. reserve_round_4k,
  845. #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) && \
  846. defined(CONFIG_ARM)
  847. reserve_mmu,
  848. #endif
  849. #ifdef CONFIG_LCD
  850. reserve_lcd,
  851. #endif
  852. reserve_trace,
  853. /* TODO: Why the dependency on CONFIG_8xx? */
  854. #if defined(CONFIG_VIDEO) && (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) \
  855. && !defined(CONFIG_ARM) && !defined(CONFIG_X86)
  856. reserve_video,
  857. #endif
  858. reserve_uboot,
  859. #ifndef CONFIG_SPL_BUILD
  860. reserve_malloc,
  861. reserve_board,
  862. #endif
  863. setup_machine,
  864. reserve_global_data,
  865. reserve_fdt,
  866. reserve_stacks,
  867. setup_dram_config,
  868. show_dram_config,
  869. #ifdef CONFIG_PPC
  870. setup_board_part1,
  871. INIT_FUNC_WATCHDOG_RESET
  872. setup_board_part2,
  873. #endif
  874. setup_baud_rate,
  875. display_new_sp,
  876. #ifdef CONFIG_SYS_EXTBDINFO
  877. setup_board_extra,
  878. #endif
  879. INIT_FUNC_WATCHDOG_RESET
  880. reloc_fdt,
  881. setup_reloc,
  882. #ifndef CONFIG_ARM
  883. jump_to_copy,
  884. #endif
  885. NULL,
  886. };
  887. void board_init_f(ulong boot_flags)
  888. {
  889. #ifndef CONFIG_X86
  890. gd_t data;
  891. gd = &data;
  892. #endif
  893. gd->flags = boot_flags;
  894. if (initcall_run_list(init_sequence_f))
  895. hang();
  896. #ifndef CONFIG_ARM
  897. /* NOTREACHED - jump_to_copy() does not return */
  898. hang();
  899. #endif
  900. }
  901. #ifdef CONFIG_X86
  902. /*
  903. * For now this code is only used on x86.
  904. *
  905. * init_sequence_f_r is the list of init functions which are run when
  906. * U-Boot is executing from Flash with a semi-limited 'C' environment.
  907. * The following limitations must be considered when implementing an
  908. * '_f_r' function:
  909. * - 'static' variables are read-only
  910. * - Global Data (gd->xxx) is read/write
  911. *
  912. * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
  913. * supported). It _should_, if possible, copy global data to RAM and
  914. * initialise the CPU caches (to speed up the relocation process)
  915. *
  916. * NOTE: At present only x86 uses this route, but it is intended that
  917. * all archs will move to this when generic relocation is implemented.
  918. */
  919. static init_fnc_t init_sequence_f_r[] = {
  920. init_cache_f_r,
  921. copy_uboot_to_ram,
  922. clear_bss,
  923. do_elf_reloc_fixups,
  924. NULL,
  925. };
  926. void board_init_f_r(void)
  927. {
  928. if (initcall_run_list(init_sequence_f_r))
  929. hang();
  930. /*
  931. * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
  932. * Transfer execution from Flash to RAM by calculating the address
  933. * of the in-RAM copy of board_init_r() and calling it
  934. */
  935. (board_init_r + gd->reloc_off)(gd, gd->relocaddr);
  936. /* NOTREACHED - board_init_r() does not return */
  937. hang();
  938. }
  939. #endif /* CONFIG_X86 */