board_f.c 26 KB

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