board_f.c 25 KB

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