1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright (c) 2011 The Chromium OS Authors.
3*4882a593Smuzhiyun * (C) Copyright 2002-2006
4*4882a593Smuzhiyun * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * (C) Copyright 2002
7*4882a593Smuzhiyun * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8*4882a593Smuzhiyun * Marius Groeger <mgroeger@sysgo.de>
9*4882a593Smuzhiyun *
10*4882a593Smuzhiyun * SPDX-License-Identifier: GPL-2.0+
11*4882a593Smuzhiyun */
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #include <common.h>
14*4882a593Smuzhiyun #include <api.h>
15*4882a593Smuzhiyun /* TODO: can we just include all these headers whether needed or not? */
16*4882a593Smuzhiyun #if defined(CONFIG_CMD_BEDBUG)
17*4882a593Smuzhiyun #include <bedbug/type.h>
18*4882a593Smuzhiyun #endif
19*4882a593Smuzhiyun #include <command.h>
20*4882a593Smuzhiyun #include <console.h>
21*4882a593Smuzhiyun #include <dm.h>
22*4882a593Smuzhiyun #include <environment.h>
23*4882a593Smuzhiyun #include <fdtdec.h>
24*4882a593Smuzhiyun #include <ide.h>
25*4882a593Smuzhiyun #include <initcall.h>
26*4882a593Smuzhiyun #include <init_helpers.h>
27*4882a593Smuzhiyun #ifdef CONFIG_PS2KBD
28*4882a593Smuzhiyun #include <keyboard.h>
29*4882a593Smuzhiyun #endif
30*4882a593Smuzhiyun #if defined(CONFIG_CMD_KGDB)
31*4882a593Smuzhiyun #include <kgdb.h>
32*4882a593Smuzhiyun #endif
33*4882a593Smuzhiyun #include <malloc.h>
34*4882a593Smuzhiyun #include <mapmem.h>
35*4882a593Smuzhiyun #include <memalign.h>
36*4882a593Smuzhiyun #ifdef CONFIG_BITBANGMII
37*4882a593Smuzhiyun #include <miiphy.h>
38*4882a593Smuzhiyun #endif
39*4882a593Smuzhiyun #include <mmc.h>
40*4882a593Smuzhiyun #include <nand.h>
41*4882a593Smuzhiyun #include <of_live.h>
42*4882a593Smuzhiyun #include <onenand_uboot.h>
43*4882a593Smuzhiyun #include <scsi.h>
44*4882a593Smuzhiyun #include <serial.h>
45*4882a593Smuzhiyun #include <spi.h>
46*4882a593Smuzhiyun #include <stdio_dev.h>
47*4882a593Smuzhiyun #include <timer.h>
48*4882a593Smuzhiyun #include <trace.h>
49*4882a593Smuzhiyun #include <watchdog.h>
50*4882a593Smuzhiyun #ifdef CONFIG_ADDR_MAP
51*4882a593Smuzhiyun #include <asm/mmu.h>
52*4882a593Smuzhiyun #endif
53*4882a593Smuzhiyun #include <asm/sections.h>
54*4882a593Smuzhiyun #include <asm/system.h>
55*4882a593Smuzhiyun #include <dm/root.h>
56*4882a593Smuzhiyun #include <linux/compiler.h>
57*4882a593Smuzhiyun #include <linux/err.h>
58*4882a593Smuzhiyun #include <efi_loader.h>
59*4882a593Smuzhiyun #include <sysmem.h>
60*4882a593Smuzhiyun #include <bidram.h>
61*4882a593Smuzhiyun #include <boot_rkimg.h>
62*4882a593Smuzhiyun #include <mtd_blk.h>
63*4882a593Smuzhiyun #if defined(CONFIG_GPIO_HOG)
64*4882a593Smuzhiyun #include <asm/gpio.h>
65*4882a593Smuzhiyun #endif
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun DECLARE_GLOBAL_DATA_PTR;
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun ulong monitor_flash_len;
70*4882a593Smuzhiyun
board_flash_wp_on(void)71*4882a593Smuzhiyun __weak int board_flash_wp_on(void)
72*4882a593Smuzhiyun {
73*4882a593Smuzhiyun /*
74*4882a593Smuzhiyun * Most flashes can't be detected when write protection is enabled,
75*4882a593Smuzhiyun * so provide a way to let U-Boot gracefully ignore write protected
76*4882a593Smuzhiyun * devices.
77*4882a593Smuzhiyun */
78*4882a593Smuzhiyun return 0;
79*4882a593Smuzhiyun }
80*4882a593Smuzhiyun
cpu_secondary_init_r(void)81*4882a593Smuzhiyun __weak void cpu_secondary_init_r(void)
82*4882a593Smuzhiyun {
83*4882a593Smuzhiyun }
84*4882a593Smuzhiyun
initr_secondary_cpu(void)85*4882a593Smuzhiyun static int initr_secondary_cpu(void)
86*4882a593Smuzhiyun {
87*4882a593Smuzhiyun /*
88*4882a593Smuzhiyun * after non-volatile devices & environment is setup and cpu code have
89*4882a593Smuzhiyun * another round to deal with any initialization that might require
90*4882a593Smuzhiyun * full access to the environment or loading of some image (firmware)
91*4882a593Smuzhiyun * from a non-volatile device
92*4882a593Smuzhiyun */
93*4882a593Smuzhiyun /* TODO: maybe define this for all archs? */
94*4882a593Smuzhiyun cpu_secondary_init_r();
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun return 0;
97*4882a593Smuzhiyun }
98*4882a593Smuzhiyun
initr_trace(void)99*4882a593Smuzhiyun static int initr_trace(void)
100*4882a593Smuzhiyun {
101*4882a593Smuzhiyun #ifdef CONFIG_TRACE
102*4882a593Smuzhiyun trace_init(gd->trace_buff, CONFIG_TRACE_BUFFER_SIZE);
103*4882a593Smuzhiyun #endif
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun return 0;
106*4882a593Smuzhiyun }
107*4882a593Smuzhiyun
initr_reloc(void)108*4882a593Smuzhiyun static int initr_reloc(void)
109*4882a593Smuzhiyun {
110*4882a593Smuzhiyun /* tell others: relocation done */
111*4882a593Smuzhiyun gd->flags |= GD_FLG_RELOC | GD_FLG_FULL_MALLOC_INIT;
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun return 0;
114*4882a593Smuzhiyun }
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun #ifdef CONFIG_ARM
117*4882a593Smuzhiyun /*
118*4882a593Smuzhiyun * Some of these functions are needed purely because the functions they
119*4882a593Smuzhiyun * call return void. If we change them to return 0, these stubs can go away.
120*4882a593Smuzhiyun */
121*4882a593Smuzhiyun
print_cr(void)122*4882a593Smuzhiyun static void print_cr(void)
123*4882a593Smuzhiyun {
124*4882a593Smuzhiyun u32 reg;
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun #ifdef CONFIG_ARM64
127*4882a593Smuzhiyun reg = get_sctlr(); /* get control reg. */
128*4882a593Smuzhiyun #else
129*4882a593Smuzhiyun reg = get_cr();
130*4882a593Smuzhiyun #endif
131*4882a593Smuzhiyun puts("CR: ");
132*4882a593Smuzhiyun if (reg & CR_M)
133*4882a593Smuzhiyun puts("M/");
134*4882a593Smuzhiyun if (reg & CR_C)
135*4882a593Smuzhiyun puts("C/");
136*4882a593Smuzhiyun if (reg & CR_I)
137*4882a593Smuzhiyun puts("I");
138*4882a593Smuzhiyun putc('\n');
139*4882a593Smuzhiyun }
140*4882a593Smuzhiyun
initr_caches(void)141*4882a593Smuzhiyun static int initr_caches(void)
142*4882a593Smuzhiyun {
143*4882a593Smuzhiyun /* Enable caches */
144*4882a593Smuzhiyun enable_caches();
145*4882a593Smuzhiyun print_cr();
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun return 0;
148*4882a593Smuzhiyun }
149*4882a593Smuzhiyun #endif
150*4882a593Smuzhiyun
fixup_cpu(void)151*4882a593Smuzhiyun __weak int fixup_cpu(void)
152*4882a593Smuzhiyun {
153*4882a593Smuzhiyun return 0;
154*4882a593Smuzhiyun }
155*4882a593Smuzhiyun
initr_reloc_global_data(void)156*4882a593Smuzhiyun static int initr_reloc_global_data(void)
157*4882a593Smuzhiyun {
158*4882a593Smuzhiyun #ifdef __ARM__
159*4882a593Smuzhiyun monitor_flash_len = _end - __image_copy_start;
160*4882a593Smuzhiyun #elif defined(CONFIG_NDS32) || defined(CONFIG_RISCV)
161*4882a593Smuzhiyun monitor_flash_len = (ulong)&_end - (ulong)&_start;
162*4882a593Smuzhiyun #elif !defined(CONFIG_SANDBOX) && !defined(CONFIG_NIOS2)
163*4882a593Smuzhiyun monitor_flash_len = (ulong)&__init_end - gd->relocaddr;
164*4882a593Smuzhiyun #endif
165*4882a593Smuzhiyun #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
166*4882a593Smuzhiyun /*
167*4882a593Smuzhiyun * The gd->cpu pointer is set to an address in flash before relocation.
168*4882a593Smuzhiyun * We need to update it to point to the same CPU entry in RAM.
169*4882a593Smuzhiyun * TODO: why not just add gd->reloc_ofs?
170*4882a593Smuzhiyun */
171*4882a593Smuzhiyun gd->arch.cpu += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun /*
174*4882a593Smuzhiyun * If we didn't know the cpu mask & # cores, we can save them of
175*4882a593Smuzhiyun * now rather than 'computing' them constantly
176*4882a593Smuzhiyun */
177*4882a593Smuzhiyun fixup_cpu();
178*4882a593Smuzhiyun #endif
179*4882a593Smuzhiyun #ifdef CONFIG_SYS_EXTRA_ENV_RELOC
180*4882a593Smuzhiyun /*
181*4882a593Smuzhiyun * Some systems need to relocate the env_addr pointer early because the
182*4882a593Smuzhiyun * location it points to will get invalidated before env_relocate is
183*4882a593Smuzhiyun * called. One example is on systems that might use a L2 or L3 cache
184*4882a593Smuzhiyun * in SRAM mode and initialize that cache from SRAM mode back to being
185*4882a593Smuzhiyun * a cache in cpu_init_r.
186*4882a593Smuzhiyun */
187*4882a593Smuzhiyun gd->env_addr += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
188*4882a593Smuzhiyun #endif
189*4882a593Smuzhiyun #ifdef CONFIG_OF_EMBED
190*4882a593Smuzhiyun /*
191*4882a593Smuzhiyun * The fdt_blob needs to be moved to new relocation address
192*4882a593Smuzhiyun * incase of FDT blob is embedded with in image
193*4882a593Smuzhiyun */
194*4882a593Smuzhiyun gd->fdt_blob += gd->reloc_off;
195*4882a593Smuzhiyun #endif
196*4882a593Smuzhiyun #ifdef CONFIG_EFI_LOADER
197*4882a593Smuzhiyun efi_runtime_relocate(gd->relocaddr, NULL);
198*4882a593Smuzhiyun #endif
199*4882a593Smuzhiyun
200*4882a593Smuzhiyun return 0;
201*4882a593Smuzhiyun }
202*4882a593Smuzhiyun
initr_serial(void)203*4882a593Smuzhiyun static int initr_serial(void)
204*4882a593Smuzhiyun {
205*4882a593Smuzhiyun serial_initialize();
206*4882a593Smuzhiyun return 0;
207*4882a593Smuzhiyun }
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
initr_trap(void)210*4882a593Smuzhiyun static int initr_trap(void)
211*4882a593Smuzhiyun {
212*4882a593Smuzhiyun /*
213*4882a593Smuzhiyun * Setup trap handlers
214*4882a593Smuzhiyun */
215*4882a593Smuzhiyun #if defined(CONFIG_PPC)
216*4882a593Smuzhiyun trap_init(gd->relocaddr);
217*4882a593Smuzhiyun #else
218*4882a593Smuzhiyun trap_init(CONFIG_SYS_SDRAM_BASE);
219*4882a593Smuzhiyun #endif
220*4882a593Smuzhiyun return 0;
221*4882a593Smuzhiyun }
222*4882a593Smuzhiyun #endif
223*4882a593Smuzhiyun
224*4882a593Smuzhiyun #ifdef CONFIG_ADDR_MAP
initr_addr_map(void)225*4882a593Smuzhiyun static int initr_addr_map(void)
226*4882a593Smuzhiyun {
227*4882a593Smuzhiyun init_addr_map();
228*4882a593Smuzhiyun
229*4882a593Smuzhiyun return 0;
230*4882a593Smuzhiyun }
231*4882a593Smuzhiyun #endif
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun #ifdef CONFIG_POST
initr_post_backlog(void)234*4882a593Smuzhiyun static int initr_post_backlog(void)
235*4882a593Smuzhiyun {
236*4882a593Smuzhiyun post_output_backlog();
237*4882a593Smuzhiyun return 0;
238*4882a593Smuzhiyun }
239*4882a593Smuzhiyun #endif
240*4882a593Smuzhiyun
241*4882a593Smuzhiyun #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
initr_unlock_ram_in_cache(void)242*4882a593Smuzhiyun static int initr_unlock_ram_in_cache(void)
243*4882a593Smuzhiyun {
244*4882a593Smuzhiyun unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */
245*4882a593Smuzhiyun return 0;
246*4882a593Smuzhiyun }
247*4882a593Smuzhiyun #endif
248*4882a593Smuzhiyun
249*4882a593Smuzhiyun #ifdef CONFIG_PCI
initr_pci(void)250*4882a593Smuzhiyun static int initr_pci(void)
251*4882a593Smuzhiyun {
252*4882a593Smuzhiyun #ifndef CONFIG_DM_PCI
253*4882a593Smuzhiyun pci_init();
254*4882a593Smuzhiyun #endif
255*4882a593Smuzhiyun
256*4882a593Smuzhiyun return 0;
257*4882a593Smuzhiyun }
258*4882a593Smuzhiyun #endif
259*4882a593Smuzhiyun
initr_barrier(void)260*4882a593Smuzhiyun static int initr_barrier(void)
261*4882a593Smuzhiyun {
262*4882a593Smuzhiyun #ifdef CONFIG_PPC
263*4882a593Smuzhiyun /* TODO: Can we not use dmb() macros for this? */
264*4882a593Smuzhiyun asm("sync ; isync");
265*4882a593Smuzhiyun #endif
266*4882a593Smuzhiyun return 0;
267*4882a593Smuzhiyun }
268*4882a593Smuzhiyun
initr_malloc(void)269*4882a593Smuzhiyun static int initr_malloc(void)
270*4882a593Smuzhiyun {
271*4882a593Smuzhiyun ulong malloc_start;
272*4882a593Smuzhiyun
273*4882a593Smuzhiyun #if CONFIG_VAL(SYS_MALLOC_F_LEN)
274*4882a593Smuzhiyun debug("Pre-reloc malloc() used %#lx bytes (%ld KB)\n", gd->malloc_ptr,
275*4882a593Smuzhiyun gd->malloc_ptr / 1024);
276*4882a593Smuzhiyun #endif
277*4882a593Smuzhiyun /* The malloc area is immediately below the monitor copy in DRAM */
278*4882a593Smuzhiyun malloc_start = gd->relocaddr - TOTAL_MALLOC_LEN;
279*4882a593Smuzhiyun mem_malloc_init((ulong)map_sysmem(malloc_start, TOTAL_MALLOC_LEN),
280*4882a593Smuzhiyun TOTAL_MALLOC_LEN);
281*4882a593Smuzhiyun return 0;
282*4882a593Smuzhiyun }
283*4882a593Smuzhiyun
initr_console_record(void)284*4882a593Smuzhiyun static int initr_console_record(void)
285*4882a593Smuzhiyun {
286*4882a593Smuzhiyun #if defined(CONFIG_CONSOLE_RECORD)
287*4882a593Smuzhiyun int ret;
288*4882a593Smuzhiyun
289*4882a593Smuzhiyun ret = console_record_init();
290*4882a593Smuzhiyun if (!ret)
291*4882a593Smuzhiyun console_record_reset_enable();
292*4882a593Smuzhiyun return ret;
293*4882a593Smuzhiyun #else
294*4882a593Smuzhiyun return 0;
295*4882a593Smuzhiyun #endif
296*4882a593Smuzhiyun }
297*4882a593Smuzhiyun
298*4882a593Smuzhiyun #ifdef CONFIG_SYS_NONCACHED_MEMORY
initr_noncached(void)299*4882a593Smuzhiyun static int initr_noncached(void)
300*4882a593Smuzhiyun {
301*4882a593Smuzhiyun noncached_init();
302*4882a593Smuzhiyun return 0;
303*4882a593Smuzhiyun }
304*4882a593Smuzhiyun #endif
305*4882a593Smuzhiyun
306*4882a593Smuzhiyun #ifdef CONFIG_OF_LIVE
initr_of_live(void)307*4882a593Smuzhiyun static int initr_of_live(void)
308*4882a593Smuzhiyun {
309*4882a593Smuzhiyun int ret;
310*4882a593Smuzhiyun
311*4882a593Smuzhiyun bootstage_start(BOOTSTAGE_ID_ACCUM_OF_LIVE, "of_live");
312*4882a593Smuzhiyun ret = of_live_build(gd->fdt_blob, (struct device_node **)&gd->of_root);
313*4882a593Smuzhiyun bootstage_accum(BOOTSTAGE_ID_ACCUM_OF_LIVE);
314*4882a593Smuzhiyun if (ret)
315*4882a593Smuzhiyun return ret;
316*4882a593Smuzhiyun
317*4882a593Smuzhiyun return 0;
318*4882a593Smuzhiyun }
319*4882a593Smuzhiyun #endif
320*4882a593Smuzhiyun
321*4882a593Smuzhiyun #ifdef CONFIG_DM
initr_dm(void)322*4882a593Smuzhiyun static int initr_dm(void)
323*4882a593Smuzhiyun {
324*4882a593Smuzhiyun int ret;
325*4882a593Smuzhiyun
326*4882a593Smuzhiyun /* Save the pre-reloc driver model and start a new one */
327*4882a593Smuzhiyun gd->dm_root_f = gd->dm_root;
328*4882a593Smuzhiyun gd->dm_root = NULL;
329*4882a593Smuzhiyun #ifdef CONFIG_TIMER
330*4882a593Smuzhiyun gd->timer = NULL;
331*4882a593Smuzhiyun #endif
332*4882a593Smuzhiyun bootstage_start(BOOTSTATE_ID_ACCUM_DM_R, "dm_r");
333*4882a593Smuzhiyun ret = dm_init_and_scan(false);
334*4882a593Smuzhiyun bootstage_accum(BOOTSTATE_ID_ACCUM_DM_R);
335*4882a593Smuzhiyun if (ret)
336*4882a593Smuzhiyun return ret;
337*4882a593Smuzhiyun #ifdef CONFIG_TIMER_EARLY
338*4882a593Smuzhiyun ret = dm_timer_init();
339*4882a593Smuzhiyun if (ret)
340*4882a593Smuzhiyun return ret;
341*4882a593Smuzhiyun #endif
342*4882a593Smuzhiyun
343*4882a593Smuzhiyun return 0;
344*4882a593Smuzhiyun }
345*4882a593Smuzhiyun #endif
346*4882a593Smuzhiyun
initr_bootstage(void)347*4882a593Smuzhiyun static int initr_bootstage(void)
348*4882a593Smuzhiyun {
349*4882a593Smuzhiyun bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
350*4882a593Smuzhiyun
351*4882a593Smuzhiyun return 0;
352*4882a593Smuzhiyun }
353*4882a593Smuzhiyun
power_init_board(void)354*4882a593Smuzhiyun __weak int power_init_board(void)
355*4882a593Smuzhiyun {
356*4882a593Smuzhiyun return 0;
357*4882a593Smuzhiyun }
358*4882a593Smuzhiyun
initr_announce(void)359*4882a593Smuzhiyun static int initr_announce(void)
360*4882a593Smuzhiyun {
361*4882a593Smuzhiyun ulong addr;
362*4882a593Smuzhiyun
363*4882a593Smuzhiyun #ifndef CONFIG_SKIP_RELOCATE_UBOOT
364*4882a593Smuzhiyun addr = gd->relocaddr;
365*4882a593Smuzhiyun #else
366*4882a593Smuzhiyun addr = CONFIG_SYS_TEXT_BASE;
367*4882a593Smuzhiyun #endif
368*4882a593Smuzhiyun debug("Now running in RAM - U-Boot at: %08lx\n", addr);
369*4882a593Smuzhiyun
370*4882a593Smuzhiyun return 0;
371*4882a593Smuzhiyun }
372*4882a593Smuzhiyun
373*4882a593Smuzhiyun #ifdef CONFIG_NEEDS_MANUAL_RELOC
initr_manual_reloc_cmdtable(void)374*4882a593Smuzhiyun static int initr_manual_reloc_cmdtable(void)
375*4882a593Smuzhiyun {
376*4882a593Smuzhiyun fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
377*4882a593Smuzhiyun ll_entry_count(cmd_tbl_t, cmd));
378*4882a593Smuzhiyun return 0;
379*4882a593Smuzhiyun }
380*4882a593Smuzhiyun #endif
381*4882a593Smuzhiyun
382*4882a593Smuzhiyun #if defined(CONFIG_MTD_NOR_FLASH)
initr_flash(void)383*4882a593Smuzhiyun static int initr_flash(void)
384*4882a593Smuzhiyun {
385*4882a593Smuzhiyun ulong flash_size = 0;
386*4882a593Smuzhiyun bd_t *bd = gd->bd;
387*4882a593Smuzhiyun
388*4882a593Smuzhiyun puts("Flash: ");
389*4882a593Smuzhiyun
390*4882a593Smuzhiyun if (board_flash_wp_on())
391*4882a593Smuzhiyun printf("Uninitialized - Write Protect On\n");
392*4882a593Smuzhiyun else
393*4882a593Smuzhiyun flash_size = flash_init();
394*4882a593Smuzhiyun
395*4882a593Smuzhiyun print_size(flash_size, "");
396*4882a593Smuzhiyun #ifdef CONFIG_SYS_FLASH_CHECKSUM
397*4882a593Smuzhiyun /*
398*4882a593Smuzhiyun * Compute and print flash CRC if flashchecksum is set to 'y'
399*4882a593Smuzhiyun *
400*4882a593Smuzhiyun * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
401*4882a593Smuzhiyun */
402*4882a593Smuzhiyun if (env_get_yesno("flashchecksum") == 1) {
403*4882a593Smuzhiyun printf(" CRC: %08X", crc32(0,
404*4882a593Smuzhiyun (const unsigned char *) CONFIG_SYS_FLASH_BASE,
405*4882a593Smuzhiyun flash_size));
406*4882a593Smuzhiyun }
407*4882a593Smuzhiyun #endif /* CONFIG_SYS_FLASH_CHECKSUM */
408*4882a593Smuzhiyun putc('\n');
409*4882a593Smuzhiyun
410*4882a593Smuzhiyun /* update start of FLASH memory */
411*4882a593Smuzhiyun #ifdef CONFIG_SYS_FLASH_BASE
412*4882a593Smuzhiyun bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
413*4882a593Smuzhiyun #endif
414*4882a593Smuzhiyun /* size of FLASH memory (final value) */
415*4882a593Smuzhiyun bd->bi_flashsize = flash_size;
416*4882a593Smuzhiyun
417*4882a593Smuzhiyun #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
418*4882a593Smuzhiyun /* Make a update of the Memctrl. */
419*4882a593Smuzhiyun update_flash_size(flash_size);
420*4882a593Smuzhiyun #endif
421*4882a593Smuzhiyun
422*4882a593Smuzhiyun
423*4882a593Smuzhiyun #if defined(CONFIG_OXC) || defined(CONFIG_RMU)
424*4882a593Smuzhiyun /* flash mapped at end of memory map */
425*4882a593Smuzhiyun bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
426*4882a593Smuzhiyun #elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
427*4882a593Smuzhiyun bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */
428*4882a593Smuzhiyun #endif
429*4882a593Smuzhiyun return 0;
430*4882a593Smuzhiyun }
431*4882a593Smuzhiyun #endif
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun #if defined(CONFIG_PPC) && !defined(CONFIG_DM_SPI)
initr_spi(void)434*4882a593Smuzhiyun static int initr_spi(void)
435*4882a593Smuzhiyun {
436*4882a593Smuzhiyun /* MPC8xx does this here */
437*4882a593Smuzhiyun #ifdef CONFIG_MPC8XX_SPI
438*4882a593Smuzhiyun #if !defined(CONFIG_ENV_IS_IN_EEPROM)
439*4882a593Smuzhiyun spi_init_f();
440*4882a593Smuzhiyun #endif
441*4882a593Smuzhiyun spi_init_r();
442*4882a593Smuzhiyun #endif
443*4882a593Smuzhiyun return 0;
444*4882a593Smuzhiyun }
445*4882a593Smuzhiyun #endif
446*4882a593Smuzhiyun
447*4882a593Smuzhiyun #ifdef CONFIG_CMD_NAND
448*4882a593Smuzhiyun /* go init the NAND */
initr_nand(void)449*4882a593Smuzhiyun static int initr_nand(void)
450*4882a593Smuzhiyun {
451*4882a593Smuzhiyun #ifndef CONFIG_USING_KERNEL_DTB
452*4882a593Smuzhiyun puts("NAND: ");
453*4882a593Smuzhiyun nand_init();
454*4882a593Smuzhiyun printf("%lu MiB\n", nand_size() / 1024);
455*4882a593Smuzhiyun #endif
456*4882a593Smuzhiyun return 0;
457*4882a593Smuzhiyun }
458*4882a593Smuzhiyun #endif
459*4882a593Smuzhiyun
460*4882a593Smuzhiyun #if defined(CONFIG_CMD_ONENAND)
461*4882a593Smuzhiyun /* go init the NAND */
initr_onenand(void)462*4882a593Smuzhiyun static int initr_onenand(void)
463*4882a593Smuzhiyun {
464*4882a593Smuzhiyun puts("NAND: ");
465*4882a593Smuzhiyun onenand_init();
466*4882a593Smuzhiyun return 0;
467*4882a593Smuzhiyun }
468*4882a593Smuzhiyun #endif
469*4882a593Smuzhiyun
470*4882a593Smuzhiyun #ifdef CONFIG_MMC
initr_mmc(void)471*4882a593Smuzhiyun static int initr_mmc(void)
472*4882a593Smuzhiyun {
473*4882a593Smuzhiyun /*
474*4882a593Smuzhiyun * When CONFIG_USING_KERNEL_DTB is enabled, mmc has been initialized earlier.
475*4882a593Smuzhiyun */
476*4882a593Smuzhiyun #ifndef CONFIG_USING_KERNEL_DTB
477*4882a593Smuzhiyun puts("MMC: ");
478*4882a593Smuzhiyun mmc_initialize(gd->bd);
479*4882a593Smuzhiyun #endif
480*4882a593Smuzhiyun return 0;
481*4882a593Smuzhiyun }
482*4882a593Smuzhiyun #endif
483*4882a593Smuzhiyun
484*4882a593Smuzhiyun #if !defined(CONFIG_USING_KERNEL_DTB) || !defined(CONFIG_ENV_IS_NOWHERE)
485*4882a593Smuzhiyun /*
486*4882a593Smuzhiyun * Tell if it's OK to load the environment early in boot.
487*4882a593Smuzhiyun *
488*4882a593Smuzhiyun * If CONFIG_OF_CONTROL is defined, we'll check with the FDT to see
489*4882a593Smuzhiyun * if this is OK (defaulting to saying it's OK).
490*4882a593Smuzhiyun *
491*4882a593Smuzhiyun * NOTE: Loading the environment early can be a bad idea if security is
492*4882a593Smuzhiyun * important, since no verification is done on the environment.
493*4882a593Smuzhiyun *
494*4882a593Smuzhiyun * @return 0 if environment should not be loaded, !=0 if it is ok to load
495*4882a593Smuzhiyun */
should_load_env(void)496*4882a593Smuzhiyun static int should_load_env(void)
497*4882a593Smuzhiyun {
498*4882a593Smuzhiyun #ifdef CONFIG_OF_CONTROL
499*4882a593Smuzhiyun return fdtdec_get_config_int(gd->fdt_blob, "load-environment", 1);
500*4882a593Smuzhiyun #elif defined CONFIG_DELAY_ENVIRONMENT
501*4882a593Smuzhiyun return 0;
502*4882a593Smuzhiyun #else
503*4882a593Smuzhiyun return 1;
504*4882a593Smuzhiyun #endif
505*4882a593Smuzhiyun }
506*4882a593Smuzhiyun
initr_env(void)507*4882a593Smuzhiyun static int initr_env(void)
508*4882a593Smuzhiyun {
509*4882a593Smuzhiyun /* initialize environment */
510*4882a593Smuzhiyun if (should_load_env())
511*4882a593Smuzhiyun env_relocate();
512*4882a593Smuzhiyun else
513*4882a593Smuzhiyun set_default_env(NULL);
514*4882a593Smuzhiyun #ifdef CONFIG_OF_CONTROL
515*4882a593Smuzhiyun env_set_addr("fdtcontroladdr", gd->fdt_blob);
516*4882a593Smuzhiyun #endif
517*4882a593Smuzhiyun
518*4882a593Smuzhiyun /* Initialize from environment */
519*4882a593Smuzhiyun load_addr = env_get_ulong("loadaddr", 16, load_addr);
520*4882a593Smuzhiyun
521*4882a593Smuzhiyun return 0;
522*4882a593Smuzhiyun }
523*4882a593Smuzhiyun #endif
524*4882a593Smuzhiyun
525*4882a593Smuzhiyun #ifdef CONFIG_USING_KERNEL_DTB
526*4882a593Smuzhiyun /*
527*4882a593Smuzhiyun * If !defined(CONFIG_ENV_IS_NOWHERE):
528*4882a593Smuzhiyun *
529*4882a593Smuzhiyun * Storage env or kernel dtb load depends on bootdev, while bootdev
530*4882a593Smuzhiyun * depends on env varname: devtype, devnum and rkimg_bootdev, etc.
531*4882a593Smuzhiyun * So we have to use nowhere env firstly and cover the storage env
532*4882a593Smuzhiyun * after it is loaded.
533*4882a593Smuzhiyun *
534*4882a593Smuzhiyun * Providing a minimum and necessary nowhere env for board init to
535*4882a593Smuzhiyun * avoid covering the other varnames in storage env.
536*4882a593Smuzhiyun */
initr_env_nowhere(void)537*4882a593Smuzhiyun static int initr_env_nowhere(void)
538*4882a593Smuzhiyun {
539*4882a593Smuzhiyun #ifdef CONFIG_ENV_IS_NOWHERE
540*4882a593Smuzhiyun set_default_env(NULL);
541*4882a593Smuzhiyun #if defined(CONFIG_ENVF)
542*4882a593Smuzhiyun /* init envf and partitiont from envf before any partition query action */
543*4882a593Smuzhiyun env_load();
544*4882a593Smuzhiyun #endif
545*4882a593Smuzhiyun return 0;
546*4882a593Smuzhiyun #else
547*4882a593Smuzhiyun const char env_minimum[] = {
548*4882a593Smuzhiyun ENV_MEM_LAYOUT_SETTINGS
549*4882a593Smuzhiyun #ifdef ENV_MEM_LAYOUT_SETTINGS1
550*4882a593Smuzhiyun ENV_MEM_LAYOUT_SETTINGS1
551*4882a593Smuzhiyun #endif
552*4882a593Smuzhiyun #ifdef RKIMG_DET_BOOTDEV
553*4882a593Smuzhiyun RKIMG_DET_BOOTDEV
554*4882a593Smuzhiyun #endif
555*4882a593Smuzhiyun };
556*4882a593Smuzhiyun
557*4882a593Smuzhiyun return set_board_env((char *)env_minimum, ENV_SIZE, 0, true);
558*4882a593Smuzhiyun #endif
559*4882a593Smuzhiyun }
560*4882a593Smuzhiyun
561*4882a593Smuzhiyun #if !defined(CONFIG_ENV_IS_NOWHERE)
562*4882a593Smuzhiyun /*
563*4882a593Smuzhiyun * storage has been initialized in board_init(), we could switch env
564*4882a593Smuzhiyun * from nowhere to storage, i.e. CONFIG_ENV_IS_IN_xxx=y.
565*4882a593Smuzhiyun */
initr_env_switch(void)566*4882a593Smuzhiyun static int initr_env_switch(void)
567*4882a593Smuzhiyun {
568*4882a593Smuzhiyun ALLOC_CACHE_ALIGN_BUFFER(env_t, env_nowhere, 1);
569*4882a593Smuzhiyun char *data;
570*4882a593Smuzhiyun int ret;
571*4882a593Smuzhiyun
572*4882a593Smuzhiyun data = env_get("bootargs");
573*4882a593Smuzhiyun if (data) {
574*4882a593Smuzhiyun env_set("bootargs_tmp", data);
575*4882a593Smuzhiyun env_set("bootargs", NULL);
576*4882a593Smuzhiyun }
577*4882a593Smuzhiyun
578*4882a593Smuzhiyun /* Export nowhere env for late use */
579*4882a593Smuzhiyun ret = env_export(env_nowhere);
580*4882a593Smuzhiyun if (ret) {
581*4882a593Smuzhiyun printf("%s: export nowhere env fail, ret=%d\n", __func__, ret);
582*4882a593Smuzhiyun return -EINVAL;
583*4882a593Smuzhiyun }
584*4882a593Smuzhiyun
585*4882a593Smuzhiyun /* Destroy nowhere env and import storage env */
586*4882a593Smuzhiyun initr_env();
587*4882a593Smuzhiyun
588*4882a593Smuzhiyun /* Append/override nowhere env to storage env */
589*4882a593Smuzhiyun set_board_env((char *)env_nowhere->data, ENV_SIZE, H_NOCLEAR, false);
590*4882a593Smuzhiyun
591*4882a593Smuzhiyun /*
592*4882a593Smuzhiyun * Restore nowhere bootargs to append/override the one in env storage.
593*4882a593Smuzhiyun *
594*4882a593Smuzhiyun * Without this, the entire "bootargs" in storage env is replaces by
595*4882a593Smuzhiyun * the one in env_nowhere->data.
596*4882a593Smuzhiyun */
597*4882a593Smuzhiyun data = env_get("bootargs_tmp");
598*4882a593Smuzhiyun if (data) {
599*4882a593Smuzhiyun env_update("bootargs", data);
600*4882a593Smuzhiyun env_set("bootargs_tmp", NULL);
601*4882a593Smuzhiyun }
602*4882a593Smuzhiyun
603*4882a593Smuzhiyun return 0;
604*4882a593Smuzhiyun }
605*4882a593Smuzhiyun #endif /* CONFIG_ENV_IS_NOWHERE */
606*4882a593Smuzhiyun #endif /* CONFIG_USING_KERNEL_DTB */
607*4882a593Smuzhiyun
608*4882a593Smuzhiyun #ifdef CONFIG_SYS_BOOTPARAMS_LEN
initr_malloc_bootparams(void)609*4882a593Smuzhiyun static int initr_malloc_bootparams(void)
610*4882a593Smuzhiyun {
611*4882a593Smuzhiyun gd->bd->bi_boot_params = (ulong)malloc(CONFIG_SYS_BOOTPARAMS_LEN);
612*4882a593Smuzhiyun if (!gd->bd->bi_boot_params) {
613*4882a593Smuzhiyun puts("WARNING: Cannot allocate space for boot parameters\n");
614*4882a593Smuzhiyun return -ENOMEM;
615*4882a593Smuzhiyun }
616*4882a593Smuzhiyun return 0;
617*4882a593Smuzhiyun }
618*4882a593Smuzhiyun #endif
619*4882a593Smuzhiyun
initr_jumptable(void)620*4882a593Smuzhiyun static int initr_jumptable(void)
621*4882a593Smuzhiyun {
622*4882a593Smuzhiyun jumptable_init();
623*4882a593Smuzhiyun return 0;
624*4882a593Smuzhiyun }
625*4882a593Smuzhiyun
626*4882a593Smuzhiyun #if defined(CONFIG_API)
initr_api(void)627*4882a593Smuzhiyun static int initr_api(void)
628*4882a593Smuzhiyun {
629*4882a593Smuzhiyun /* Initialize API */
630*4882a593Smuzhiyun api_init();
631*4882a593Smuzhiyun return 0;
632*4882a593Smuzhiyun }
633*4882a593Smuzhiyun #endif
634*4882a593Smuzhiyun
635*4882a593Smuzhiyun /* enable exceptions */
636*4882a593Smuzhiyun #ifdef CONFIG_ARM
initr_enable_interrupts(void)637*4882a593Smuzhiyun static int initr_enable_interrupts(void)
638*4882a593Smuzhiyun {
639*4882a593Smuzhiyun enable_interrupts();
640*4882a593Smuzhiyun return 0;
641*4882a593Smuzhiyun }
642*4882a593Smuzhiyun #endif
643*4882a593Smuzhiyun
644*4882a593Smuzhiyun #ifdef CONFIG_CMD_NET
initr_ethaddr(void)645*4882a593Smuzhiyun static int initr_ethaddr(void)
646*4882a593Smuzhiyun {
647*4882a593Smuzhiyun bd_t *bd = gd->bd;
648*4882a593Smuzhiyun
649*4882a593Smuzhiyun /* kept around for legacy kernels only ... ignore the next section */
650*4882a593Smuzhiyun eth_env_get_enetaddr("ethaddr", bd->bi_enetaddr);
651*4882a593Smuzhiyun #ifdef CONFIG_HAS_ETH1
652*4882a593Smuzhiyun eth_env_get_enetaddr("eth1addr", bd->bi_enet1addr);
653*4882a593Smuzhiyun #endif
654*4882a593Smuzhiyun #ifdef CONFIG_HAS_ETH2
655*4882a593Smuzhiyun eth_env_get_enetaddr("eth2addr", bd->bi_enet2addr);
656*4882a593Smuzhiyun #endif
657*4882a593Smuzhiyun #ifdef CONFIG_HAS_ETH3
658*4882a593Smuzhiyun eth_env_get_enetaddr("eth3addr", bd->bi_enet3addr);
659*4882a593Smuzhiyun #endif
660*4882a593Smuzhiyun #ifdef CONFIG_HAS_ETH4
661*4882a593Smuzhiyun eth_env_get_enetaddr("eth4addr", bd->bi_enet4addr);
662*4882a593Smuzhiyun #endif
663*4882a593Smuzhiyun #ifdef CONFIG_HAS_ETH5
664*4882a593Smuzhiyun eth_env_get_enetaddr("eth5addr", bd->bi_enet5addr);
665*4882a593Smuzhiyun #endif
666*4882a593Smuzhiyun return 0;
667*4882a593Smuzhiyun }
668*4882a593Smuzhiyun #endif /* CONFIG_CMD_NET */
669*4882a593Smuzhiyun
670*4882a593Smuzhiyun #ifdef CONFIG_CMD_KGDB
initr_kgdb(void)671*4882a593Smuzhiyun static int initr_kgdb(void)
672*4882a593Smuzhiyun {
673*4882a593Smuzhiyun puts("KGDB: ");
674*4882a593Smuzhiyun kgdb_init();
675*4882a593Smuzhiyun return 0;
676*4882a593Smuzhiyun }
677*4882a593Smuzhiyun #endif
678*4882a593Smuzhiyun
679*4882a593Smuzhiyun #if defined(CONFIG_LED_STATUS)
initr_status_led(void)680*4882a593Smuzhiyun static int initr_status_led(void)
681*4882a593Smuzhiyun {
682*4882a593Smuzhiyun #if defined(CONFIG_LED_STATUS_BOOT)
683*4882a593Smuzhiyun status_led_set(CONFIG_LED_STATUS_BOOT, CONFIG_LED_STATUS_BLINKING);
684*4882a593Smuzhiyun #else
685*4882a593Smuzhiyun status_led_init();
686*4882a593Smuzhiyun #endif
687*4882a593Smuzhiyun return 0;
688*4882a593Smuzhiyun }
689*4882a593Smuzhiyun #endif
690*4882a593Smuzhiyun
691*4882a593Smuzhiyun #if defined(CONFIG_SCSI) && !defined(CONFIG_DM_SCSI)
initr_scsi(void)692*4882a593Smuzhiyun static int initr_scsi(void)
693*4882a593Smuzhiyun {
694*4882a593Smuzhiyun puts("SCSI: ");
695*4882a593Smuzhiyun scsi_init();
696*4882a593Smuzhiyun
697*4882a593Smuzhiyun return 0;
698*4882a593Smuzhiyun }
699*4882a593Smuzhiyun #endif
700*4882a593Smuzhiyun
701*4882a593Smuzhiyun #ifdef CONFIG_BITBANGMII
initr_bbmii(void)702*4882a593Smuzhiyun static int initr_bbmii(void)
703*4882a593Smuzhiyun {
704*4882a593Smuzhiyun bb_miiphy_init();
705*4882a593Smuzhiyun return 0;
706*4882a593Smuzhiyun }
707*4882a593Smuzhiyun #endif
708*4882a593Smuzhiyun
709*4882a593Smuzhiyun #ifdef CONFIG_CMD_NET
initr_net(void)710*4882a593Smuzhiyun static int initr_net(void)
711*4882a593Smuzhiyun {
712*4882a593Smuzhiyun puts("Net: ");
713*4882a593Smuzhiyun eth_initialize();
714*4882a593Smuzhiyun #if defined(CONFIG_RESET_PHY_R)
715*4882a593Smuzhiyun debug("Reset Ethernet PHY\n");
716*4882a593Smuzhiyun reset_phy();
717*4882a593Smuzhiyun #endif
718*4882a593Smuzhiyun return 0;
719*4882a593Smuzhiyun }
720*4882a593Smuzhiyun #endif
721*4882a593Smuzhiyun
722*4882a593Smuzhiyun #ifdef CONFIG_POST
initr_post(void)723*4882a593Smuzhiyun static int initr_post(void)
724*4882a593Smuzhiyun {
725*4882a593Smuzhiyun post_run(NULL, POST_RAM | post_bootmode_get(0));
726*4882a593Smuzhiyun return 0;
727*4882a593Smuzhiyun }
728*4882a593Smuzhiyun #endif
729*4882a593Smuzhiyun
730*4882a593Smuzhiyun #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_IDE)
initr_pcmcia(void)731*4882a593Smuzhiyun static int initr_pcmcia(void)
732*4882a593Smuzhiyun {
733*4882a593Smuzhiyun puts("PCMCIA:");
734*4882a593Smuzhiyun pcmcia_init();
735*4882a593Smuzhiyun return 0;
736*4882a593Smuzhiyun }
737*4882a593Smuzhiyun #endif
738*4882a593Smuzhiyun
739*4882a593Smuzhiyun #if defined(CONFIG_IDE)
initr_ide(void)740*4882a593Smuzhiyun static int initr_ide(void)
741*4882a593Smuzhiyun {
742*4882a593Smuzhiyun puts("IDE: ");
743*4882a593Smuzhiyun #if defined(CONFIG_START_IDE)
744*4882a593Smuzhiyun if (board_start_ide())
745*4882a593Smuzhiyun ide_init();
746*4882a593Smuzhiyun #else
747*4882a593Smuzhiyun ide_init();
748*4882a593Smuzhiyun #endif
749*4882a593Smuzhiyun return 0;
750*4882a593Smuzhiyun }
751*4882a593Smuzhiyun #endif
752*4882a593Smuzhiyun
753*4882a593Smuzhiyun #if defined(CONFIG_PRAM)
754*4882a593Smuzhiyun /*
755*4882a593Smuzhiyun * Export available size of memory for Linux, taking into account the
756*4882a593Smuzhiyun * protected RAM at top of memory
757*4882a593Smuzhiyun */
initr_mem(void)758*4882a593Smuzhiyun int initr_mem(void)
759*4882a593Smuzhiyun {
760*4882a593Smuzhiyun ulong pram = 0;
761*4882a593Smuzhiyun char memsz[32];
762*4882a593Smuzhiyun
763*4882a593Smuzhiyun # ifdef CONFIG_PRAM
764*4882a593Smuzhiyun pram = env_get_ulong("pram", 10, CONFIG_PRAM);
765*4882a593Smuzhiyun # endif
766*4882a593Smuzhiyun sprintf(memsz, "%ldk", (long int) ((gd->ram_size / 1024) - pram));
767*4882a593Smuzhiyun env_set("mem", memsz);
768*4882a593Smuzhiyun
769*4882a593Smuzhiyun return 0;
770*4882a593Smuzhiyun }
771*4882a593Smuzhiyun #endif
772*4882a593Smuzhiyun
773*4882a593Smuzhiyun #ifdef CONFIG_CMD_BEDBUG
initr_bedbug(void)774*4882a593Smuzhiyun static int initr_bedbug(void)
775*4882a593Smuzhiyun {
776*4882a593Smuzhiyun bedbug_init();
777*4882a593Smuzhiyun
778*4882a593Smuzhiyun return 0;
779*4882a593Smuzhiyun }
780*4882a593Smuzhiyun #endif
781*4882a593Smuzhiyun
782*4882a593Smuzhiyun #ifdef CONFIG_PS2KBD
initr_kbd(void)783*4882a593Smuzhiyun static int initr_kbd(void)
784*4882a593Smuzhiyun {
785*4882a593Smuzhiyun puts("PS/2: ");
786*4882a593Smuzhiyun kbd_init();
787*4882a593Smuzhiyun return 0;
788*4882a593Smuzhiyun }
789*4882a593Smuzhiyun #endif
790*4882a593Smuzhiyun
interrupt_debugger_init(void)791*4882a593Smuzhiyun __weak int interrupt_debugger_init(void)
792*4882a593Smuzhiyun {
793*4882a593Smuzhiyun return 0;
794*4882a593Smuzhiyun }
795*4882a593Smuzhiyun
board_initr_caches_fixup(void)796*4882a593Smuzhiyun __weak int board_initr_caches_fixup(void)
797*4882a593Smuzhiyun {
798*4882a593Smuzhiyun return 0;
799*4882a593Smuzhiyun }
800*4882a593Smuzhiyun
check_fuse(void)801*4882a593Smuzhiyun __weak int check_fuse(void)
802*4882a593Smuzhiyun {
803*4882a593Smuzhiyun return 0;
804*4882a593Smuzhiyun }
805*4882a593Smuzhiyun
run_main_loop(void)806*4882a593Smuzhiyun static int run_main_loop(void)
807*4882a593Smuzhiyun {
808*4882a593Smuzhiyun #ifdef CONFIG_SANDBOX
809*4882a593Smuzhiyun sandbox_main_loop_init();
810*4882a593Smuzhiyun #endif
811*4882a593Smuzhiyun /* main_loop() can return to retry autoboot, if so just run it again */
812*4882a593Smuzhiyun for (;;)
813*4882a593Smuzhiyun main_loop();
814*4882a593Smuzhiyun return 0;
815*4882a593Smuzhiyun }
816*4882a593Smuzhiyun
817*4882a593Smuzhiyun /*
818*4882a593Smuzhiyun * Over time we hope to remove these functions with code fragments and
819*4882a593Smuzhiyun * stub funtcions, and instead call the relevant function directly.
820*4882a593Smuzhiyun *
821*4882a593Smuzhiyun * We also hope to remove most of the driver-related init and do it if/when
822*4882a593Smuzhiyun * the driver is later used.
823*4882a593Smuzhiyun *
824*4882a593Smuzhiyun * TODO: perhaps reset the watchdog in the initcall function after each call?
825*4882a593Smuzhiyun */
826*4882a593Smuzhiyun static init_fnc_t init_sequence_r[] = {
827*4882a593Smuzhiyun initr_trace,
828*4882a593Smuzhiyun initr_reloc,
829*4882a593Smuzhiyun /* TODO: could x86/PPC have this also perhaps? */
830*4882a593Smuzhiyun #ifdef CONFIG_ARM
831*4882a593Smuzhiyun initr_caches,
832*4882a593Smuzhiyun /* Note: For Freescale LS2 SoCs, new MMU table is created in DDR.
833*4882a593Smuzhiyun * A temporary mapping of IFC high region is since removed,
834*4882a593Smuzhiyun * so environmental variables in NOR flash is not availble
835*4882a593Smuzhiyun * until board_init() is called below to remap IFC to high
836*4882a593Smuzhiyun * region.
837*4882a593Smuzhiyun */
838*4882a593Smuzhiyun #endif
839*4882a593Smuzhiyun initr_reloc_global_data,
840*4882a593Smuzhiyun
841*4882a593Smuzhiyun /*
842*4882a593Smuzhiyun * Some platform requires to reserve memory regions for some firmware
843*4882a593Smuzhiyun * to avoid kernel touches it, but U-Boot may have communication with
844*4882a593Smuzhiyun * firmware by share memory. So that we had better reserve firmware
845*4882a593Smuzhiyun * region after the initr_caches() which enables MMU and init
846*4882a593Smuzhiyun * translation table, we need firmware region to be mapped as cacheable
847*4882a593Smuzhiyun * like other regions, otherwise there would be dcache coherence issue
848*4882a593Smuzhiyun * between firmware and U-Boot.
849*4882a593Smuzhiyun */
850*4882a593Smuzhiyun board_initr_caches_fixup,
851*4882a593Smuzhiyun
852*4882a593Smuzhiyun #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
853*4882a593Smuzhiyun initr_unlock_ram_in_cache,
854*4882a593Smuzhiyun #endif
855*4882a593Smuzhiyun initr_barrier,
856*4882a593Smuzhiyun initr_malloc,
857*4882a593Smuzhiyun #ifdef CONFIG_BIDRAM
858*4882a593Smuzhiyun bidram_initr,
859*4882a593Smuzhiyun #endif
860*4882a593Smuzhiyun #ifdef CONFIG_SYSMEM
861*4882a593Smuzhiyun sysmem_initr,
862*4882a593Smuzhiyun #endif
863*4882a593Smuzhiyun log_init,
864*4882a593Smuzhiyun initr_bootstage, /* Needs malloc() but has its own timer */
865*4882a593Smuzhiyun initr_console_record,
866*4882a593Smuzhiyun #ifdef CONFIG_SYS_NONCACHED_MEMORY
867*4882a593Smuzhiyun initr_noncached,
868*4882a593Smuzhiyun #endif
869*4882a593Smuzhiyun bootstage_relocate,
870*4882a593Smuzhiyun
871*4882a593Smuzhiyun interrupt_init,
872*4882a593Smuzhiyun #ifdef CONFIG_ARM
873*4882a593Smuzhiyun initr_enable_interrupts,
874*4882a593Smuzhiyun #endif
875*4882a593Smuzhiyun interrupt_debugger_init,
876*4882a593Smuzhiyun
877*4882a593Smuzhiyun #ifdef CONFIG_OF_LIVE
878*4882a593Smuzhiyun initr_of_live,
879*4882a593Smuzhiyun #endif
880*4882a593Smuzhiyun #ifdef CONFIG_DM
881*4882a593Smuzhiyun initr_dm,
882*4882a593Smuzhiyun #endif
883*4882a593Smuzhiyun
884*4882a593Smuzhiyun #ifdef CONFIG_USING_KERNEL_DTB
885*4882a593Smuzhiyun initr_env_nowhere,
886*4882a593Smuzhiyun #endif
887*4882a593Smuzhiyun #if defined(CONFIG_BOARD_EARLY_INIT_R)
888*4882a593Smuzhiyun board_early_init_r,
889*4882a593Smuzhiyun #endif
890*4882a593Smuzhiyun
891*4882a593Smuzhiyun #if defined(CONFIG_ARM) || defined(CONFIG_NDS32) || defined(CONFIG_RISCV)
892*4882a593Smuzhiyun board_init, /* Setup chipselects */
893*4882a593Smuzhiyun #endif
894*4882a593Smuzhiyun #if defined(CONFIG_USING_KERNEL_DTB) && !defined(CONFIG_ENV_IS_NOWHERE)
895*4882a593Smuzhiyun initr_env_switch,
896*4882a593Smuzhiyun #endif
897*4882a593Smuzhiyun /*
898*4882a593Smuzhiyun * TODO: printing of the clock inforamtion of the board is now
899*4882a593Smuzhiyun * implemented as part of bdinfo command. Currently only support for
900*4882a593Smuzhiyun * davinci SOC's is added. Remove this check once all the board
901*4882a593Smuzhiyun * implement this.
902*4882a593Smuzhiyun */
903*4882a593Smuzhiyun #ifdef CONFIG_CLOCKS
904*4882a593Smuzhiyun set_cpu_clk_info, /* Setup clock information */
905*4882a593Smuzhiyun #endif
906*4882a593Smuzhiyun #ifdef CONFIG_EFI_LOADER
907*4882a593Smuzhiyun efi_memory_init,
908*4882a593Smuzhiyun #endif
909*4882a593Smuzhiyun stdio_init_tables,
910*4882a593Smuzhiyun initr_serial,
911*4882a593Smuzhiyun initr_announce,
912*4882a593Smuzhiyun INIT_FUNC_WATCHDOG_RESET
913*4882a593Smuzhiyun #ifdef CONFIG_NEEDS_MANUAL_RELOC
914*4882a593Smuzhiyun initr_manual_reloc_cmdtable,
915*4882a593Smuzhiyun #endif
916*4882a593Smuzhiyun #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
917*4882a593Smuzhiyun initr_trap,
918*4882a593Smuzhiyun #endif
919*4882a593Smuzhiyun #ifdef CONFIG_ADDR_MAP
920*4882a593Smuzhiyun initr_addr_map,
921*4882a593Smuzhiyun #endif
922*4882a593Smuzhiyun INIT_FUNC_WATCHDOG_RESET
923*4882a593Smuzhiyun #ifdef CONFIG_POST
924*4882a593Smuzhiyun initr_post_backlog,
925*4882a593Smuzhiyun #endif
926*4882a593Smuzhiyun INIT_FUNC_WATCHDOG_RESET
927*4882a593Smuzhiyun
928*4882a593Smuzhiyun #ifndef CONFIG_USING_KERNEL_DTB
929*4882a593Smuzhiyun /* init before storage(for: devtype, devnum, ...) */
930*4882a593Smuzhiyun initr_env,
931*4882a593Smuzhiyun #endif
932*4882a593Smuzhiyun #if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
933*4882a593Smuzhiyun /*
934*4882a593Smuzhiyun * Do early PCI configuration _before_ the flash gets initialised,
935*4882a593Smuzhiyun * because PCU ressources are crucial for flash access on some boards.
936*4882a593Smuzhiyun */
937*4882a593Smuzhiyun initr_pci,
938*4882a593Smuzhiyun #endif
939*4882a593Smuzhiyun #ifdef CONFIG_ARCH_EARLY_INIT_R
940*4882a593Smuzhiyun arch_early_init_r,
941*4882a593Smuzhiyun #endif
942*4882a593Smuzhiyun power_init_board,
943*4882a593Smuzhiyun #ifdef CONFIG_MTD_NOR_FLASH
944*4882a593Smuzhiyun initr_flash,
945*4882a593Smuzhiyun #endif
946*4882a593Smuzhiyun INIT_FUNC_WATCHDOG_RESET
947*4882a593Smuzhiyun #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_X86)
948*4882a593Smuzhiyun /* initialize higher level parts of CPU like time base and timers */
949*4882a593Smuzhiyun cpu_init_r,
950*4882a593Smuzhiyun #endif
951*4882a593Smuzhiyun #ifdef CONFIG_PPC
952*4882a593Smuzhiyun initr_spi,
953*4882a593Smuzhiyun #endif
954*4882a593Smuzhiyun #ifdef CONFIG_CMD_NAND
955*4882a593Smuzhiyun initr_nand,
956*4882a593Smuzhiyun #endif
957*4882a593Smuzhiyun #ifdef CONFIG_CMD_ONENAND
958*4882a593Smuzhiyun initr_onenand,
959*4882a593Smuzhiyun #endif
960*4882a593Smuzhiyun #ifdef CONFIG_MMC
961*4882a593Smuzhiyun initr_mmc,
962*4882a593Smuzhiyun #endif
963*4882a593Smuzhiyun
964*4882a593Smuzhiyun #ifdef CONFIG_SYS_BOOTPARAMS_LEN
965*4882a593Smuzhiyun initr_malloc_bootparams,
966*4882a593Smuzhiyun #endif
967*4882a593Smuzhiyun INIT_FUNC_WATCHDOG_RESET
968*4882a593Smuzhiyun initr_secondary_cpu,
969*4882a593Smuzhiyun #if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET)
970*4882a593Smuzhiyun mac_read_from_eeprom,
971*4882a593Smuzhiyun #endif
972*4882a593Smuzhiyun INIT_FUNC_WATCHDOG_RESET
973*4882a593Smuzhiyun #if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
974*4882a593Smuzhiyun /*
975*4882a593Smuzhiyun * Do pci configuration
976*4882a593Smuzhiyun */
977*4882a593Smuzhiyun initr_pci,
978*4882a593Smuzhiyun #endif
979*4882a593Smuzhiyun stdio_add_devices,
980*4882a593Smuzhiyun initr_jumptable,
981*4882a593Smuzhiyun #ifdef CONFIG_API
982*4882a593Smuzhiyun initr_api,
983*4882a593Smuzhiyun #endif
984*4882a593Smuzhiyun console_init_r, /* fully init console as a device */
985*4882a593Smuzhiyun #ifdef CONFIG_DISPLAY_BOARDINFO_LATE
986*4882a593Smuzhiyun console_announce_r,
987*4882a593Smuzhiyun show_board_info,
988*4882a593Smuzhiyun #endif
989*4882a593Smuzhiyun #ifdef CONFIG_ARCH_MISC_INIT
990*4882a593Smuzhiyun arch_misc_init, /* miscellaneous arch-dependent init */
991*4882a593Smuzhiyun #endif
992*4882a593Smuzhiyun #ifdef CONFIG_MISC_INIT_R
993*4882a593Smuzhiyun misc_init_r, /* miscellaneous platform-dependent init */
994*4882a593Smuzhiyun #endif
995*4882a593Smuzhiyun INIT_FUNC_WATCHDOG_RESET
996*4882a593Smuzhiyun #ifdef CONFIG_CMD_KGDB
997*4882a593Smuzhiyun initr_kgdb,
998*4882a593Smuzhiyun #endif
999*4882a593Smuzhiyun
1000*4882a593Smuzhiyun #if defined(CONFIG_MICROBLAZE) || defined(CONFIG_M68K)
1001*4882a593Smuzhiyun timer_init, /* initialize timer */
1002*4882a593Smuzhiyun #endif
1003*4882a593Smuzhiyun #if defined(CONFIG_LED_STATUS)
1004*4882a593Smuzhiyun initr_status_led,
1005*4882a593Smuzhiyun #endif
1006*4882a593Smuzhiyun /* PPC has a udelay(20) here dating from 2002. Why? */
1007*4882a593Smuzhiyun #ifdef CONFIG_CMD_NET
1008*4882a593Smuzhiyun initr_ethaddr,
1009*4882a593Smuzhiyun #endif
1010*4882a593Smuzhiyun #if defined(CONFIG_GPIO_HOG)
1011*4882a593Smuzhiyun gpio_hog_probe_all,
1012*4882a593Smuzhiyun #endif
1013*4882a593Smuzhiyun #ifdef CONFIG_BOARD_LATE_INIT
1014*4882a593Smuzhiyun board_late_init,
1015*4882a593Smuzhiyun #endif
1016*4882a593Smuzhiyun check_fuse,
1017*4882a593Smuzhiyun #if defined(CONFIG_SCSI) && !defined(CONFIG_DM_SCSI)
1018*4882a593Smuzhiyun INIT_FUNC_WATCHDOG_RESET
1019*4882a593Smuzhiyun initr_scsi,
1020*4882a593Smuzhiyun #endif
1021*4882a593Smuzhiyun #ifdef CONFIG_BITBANGMII
1022*4882a593Smuzhiyun initr_bbmii,
1023*4882a593Smuzhiyun #endif
1024*4882a593Smuzhiyun #ifdef CONFIG_CMD_NET
1025*4882a593Smuzhiyun INIT_FUNC_WATCHDOG_RESET
1026*4882a593Smuzhiyun initr_net,
1027*4882a593Smuzhiyun #endif
1028*4882a593Smuzhiyun #ifdef CONFIG_POST
1029*4882a593Smuzhiyun initr_post,
1030*4882a593Smuzhiyun #endif
1031*4882a593Smuzhiyun #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_IDE)
1032*4882a593Smuzhiyun initr_pcmcia,
1033*4882a593Smuzhiyun #endif
1034*4882a593Smuzhiyun #if defined(CONFIG_IDE)
1035*4882a593Smuzhiyun initr_ide,
1036*4882a593Smuzhiyun #endif
1037*4882a593Smuzhiyun #ifdef CONFIG_LAST_STAGE_INIT
1038*4882a593Smuzhiyun INIT_FUNC_WATCHDOG_RESET
1039*4882a593Smuzhiyun /*
1040*4882a593Smuzhiyun * Some parts can be only initialized if all others (like
1041*4882a593Smuzhiyun * Interrupts) are up and running (i.e. the PC-style ISA
1042*4882a593Smuzhiyun * keyboard).
1043*4882a593Smuzhiyun */
1044*4882a593Smuzhiyun last_stage_init,
1045*4882a593Smuzhiyun #endif
1046*4882a593Smuzhiyun #ifdef CONFIG_CMD_BEDBUG
1047*4882a593Smuzhiyun INIT_FUNC_WATCHDOG_RESET
1048*4882a593Smuzhiyun initr_bedbug,
1049*4882a593Smuzhiyun #endif
1050*4882a593Smuzhiyun #if defined(CONFIG_PRAM)
1051*4882a593Smuzhiyun initr_mem,
1052*4882a593Smuzhiyun #endif
1053*4882a593Smuzhiyun #ifdef CONFIG_PS2KBD
1054*4882a593Smuzhiyun initr_kbd,
1055*4882a593Smuzhiyun #endif
1056*4882a593Smuzhiyun run_main_loop,
1057*4882a593Smuzhiyun };
1058*4882a593Smuzhiyun
board_init_r(gd_t * new_gd,ulong dest_addr)1059*4882a593Smuzhiyun void board_init_r(gd_t *new_gd, ulong dest_addr)
1060*4882a593Smuzhiyun {
1061*4882a593Smuzhiyun /*
1062*4882a593Smuzhiyun * Set up the new global data pointer. So far only x86 does this
1063*4882a593Smuzhiyun * here.
1064*4882a593Smuzhiyun * TODO(sjg@chromium.org): Consider doing this for all archs, or
1065*4882a593Smuzhiyun * dropping the new_gd parameter.
1066*4882a593Smuzhiyun */
1067*4882a593Smuzhiyun #if CONFIG_IS_ENABLED(X86_64)
1068*4882a593Smuzhiyun arch_setup_gd(new_gd);
1069*4882a593Smuzhiyun #endif
1070*4882a593Smuzhiyun
1071*4882a593Smuzhiyun #ifdef CONFIG_NEEDS_MANUAL_RELOC
1072*4882a593Smuzhiyun int i;
1073*4882a593Smuzhiyun #endif
1074*4882a593Smuzhiyun
1075*4882a593Smuzhiyun #if !defined(CONFIG_X86) && !defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
1076*4882a593Smuzhiyun gd = new_gd;
1077*4882a593Smuzhiyun #endif
1078*4882a593Smuzhiyun gd->flags &= ~GD_FLG_LOG_READY;
1079*4882a593Smuzhiyun
1080*4882a593Smuzhiyun #ifdef CONFIG_NEEDS_MANUAL_RELOC
1081*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(init_sequence_r); i++)
1082*4882a593Smuzhiyun init_sequence_r[i] += gd->reloc_off;
1083*4882a593Smuzhiyun #endif
1084*4882a593Smuzhiyun
1085*4882a593Smuzhiyun if (initcall_run_list(init_sequence_r))
1086*4882a593Smuzhiyun hang();
1087*4882a593Smuzhiyun
1088*4882a593Smuzhiyun /* NOTREACHED - run_main_loop() does not return */
1089*4882a593Smuzhiyun hang();
1090*4882a593Smuzhiyun }
1091