board_f.c 25 KB

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