board_f.c 25 KB

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