]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
6f6430d7 SG |
2 | /* |
3 | * Copyright (c) 2011 The Chromium OS Authors. | |
4 | * (C) Copyright 2002-2006 | |
5 | * Wolfgang Denk, DENX Software Engineering, [email protected]. | |
6 | * | |
7 | * (C) Copyright 2002 | |
8 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> | |
9 | * Marius Groeger <[email protected]> | |
6f6430d7 SG |
10 | */ |
11 | ||
03de305e | 12 | #include <config.h> |
12d738ae | 13 | #include <api.h> |
52f24238 | 14 | #include <bootstage.h> |
1eb69ae4 | 15 | #include <cpu_func.h> |
70545642 | 16 | #include <cyclic.h> |
4e4bf944 | 17 | #include <display_options.h> |
a6f2aafe | 18 | #include <exports.h> |
17ead040 | 19 | #ifdef CONFIG_MTD_NOR_FLASH |
b79fdc76 | 20 | #include <flash.h> |
17ead040 | 21 | #endif |
db41d65a | 22 | #include <hang.h> |
8e8ccfe1 | 23 | #include <image.h> |
36bf446b | 24 | #include <irq_func.h> |
b6400de7 | 25 | #include <lmb.h> |
f7ae49fc | 26 | #include <log.h> |
5e6267af | 27 | #include <net.h> |
90526e9f | 28 | #include <asm/cache.h> |
401d1c4f | 29 | #include <asm/global_data.h> |
3db71108 | 30 | #include <u-boot/crc.h> |
3c10dc95 | 31 | #include <binman.h> |
cbb2df20 | 32 | #include <command.h> |
24b852a7 | 33 | #include <console.h> |
1ce60176 | 34 | #include <dm.h> |
3f989e7b | 35 | #include <env.h> |
f3998fdc | 36 | #include <env_internal.h> |
6f6430d7 | 37 | #include <fdtdec.h> |
c2240d4d | 38 | #include <ide.h> |
6b8d3cea | 39 | #include <init.h> |
6f6430d7 | 40 | #include <initcall.h> |
c2240d4d | 41 | #include <kgdb.h> |
c30b7adb | 42 | #include <irq_func.h> |
fc55ae03 | 43 | #include <led.h> |
6f6430d7 | 44 | #include <malloc.h> |
0eb25b61 | 45 | #include <mapmem.h> |
c2240d4d | 46 | #include <miiphy.h> |
6f6430d7 | 47 | #include <mmc.h> |
90a979d7 | 48 | #include <mux.h> |
6f6430d7 | 49 | #include <nand.h> |
3af86a4e | 50 | #include <of_live.h> |
6f6430d7 | 51 | #include <onenand_uboot.h> |
722bc5b5 | 52 | #include <pvblock.h> |
c2240d4d | 53 | #include <scsi.h> |
6f6430d7 | 54 | #include <serial.h> |
c3e4430e | 55 | #include <status_led.h> |
6f6430d7 | 56 | #include <stdio_dev.h> |
1057e6cf | 57 | #include <timer.h> |
71c52dba | 58 | #include <trace.h> |
c2240d4d | 59 | #include <watchdog.h> |
48654416 | 60 | #include <xen.h> |
6f6430d7 | 61 | #include <asm/sections.h> |
1ce60176 | 62 | #include <dm/root.h> |
7de8bd03 | 63 | #include <dm/ofnode.h> |
c2240d4d | 64 | #include <linux/compiler.h> |
1ce60176 | 65 | #include <linux/err.h> |
50149ea3 | 66 | #include <efi_loader.h> |
06985289 | 67 | #include <wdt.h> |
fd765b0e | 68 | #include <asm-generic/gpio.h> |
c57c9439 | 69 | #include <efi_loader.h> |
13ae36cc | 70 | #include <relocate.h> |
6f6430d7 SG |
71 | |
72 | DECLARE_GLOBAL_DATA_PTR; | |
73 | ||
74 | ulong monitor_flash_len; | |
75 | ||
dd2a6cd0 | 76 | __weak int board_flash_wp_on(void) |
c2240d4d SG |
77 | { |
78 | /* | |
79 | * Most flashes can't be detected when write protection is enabled, | |
80 | * so provide a way to let U-Boot gracefully ignore write protected | |
81 | * devices. | |
82 | */ | |
83 | return 0; | |
84 | } | |
85 | ||
fb504b2c | 86 | __weak int cpu_secondary_init_r(void) |
c2240d4d | 87 | { |
c2240d4d SG |
88 | return 0; |
89 | } | |
6f6430d7 | 90 | |
71c52dba SG |
91 | static int initr_trace(void) |
92 | { | |
93 | #ifdef CONFIG_TRACE | |
94 | trace_init(gd->trace_buff, CONFIG_TRACE_BUFFER_SIZE); | |
95 | #endif | |
96 | ||
97 | return 0; | |
98 | } | |
99 | ||
6f6430d7 SG |
100 | static int initr_reloc(void) |
101 | { | |
c9356be3 SG |
102 | /* tell others: relocation done */ |
103 | gd->flags |= GD_FLG_RELOC | GD_FLG_FULL_MALLOC_INIT; | |
6f6430d7 SG |
104 | |
105 | return 0; | |
106 | } | |
107 | ||
4d4222d0 | 108 | #if defined(CONFIG_ARM) || defined(CONFIG_RISCV) |
6f6430d7 SG |
109 | /* |
110 | * Some of these functions are needed purely because the functions they | |
111 | * call return void. If we change them to return 0, these stubs can go away. | |
112 | */ | |
113 | static int initr_caches(void) | |
114 | { | |
115 | /* Enable caches */ | |
116 | enable_caches(); | |
117 | return 0; | |
118 | } | |
119 | #endif | |
120 | ||
c2240d4d SG |
121 | __weak int fixup_cpu(void) |
122 | { | |
123 | return 0; | |
124 | } | |
125 | ||
6f6430d7 SG |
126 | static int initr_reloc_global_data(void) |
127 | { | |
b60eff31 AA |
128 | #ifdef __ARM__ |
129 | monitor_flash_len = _end - __image_copy_start; | |
11232139 | 130 | #elif defined(CONFIG_RISCV) |
ccea96f4 | 131 | monitor_flash_len = (ulong)_end - (ulong)_start; |
5ff10aa7 | 132 | #elif !defined(CONFIG_SANDBOX) && !defined(CONFIG_NIOS2) |
ccea96f4 | 133 | monitor_flash_len = (ulong)__init_end - gd->relocaddr; |
6f6430d7 | 134 | #endif |
c2240d4d SG |
135 | #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) |
136 | /* | |
137 | * The gd->cpu pointer is set to an address in flash before relocation. | |
138 | * We need to update it to point to the same CPU entry in RAM. | |
139 | * TODO: why not just add gd->reloc_ofs? | |
140 | */ | |
a0ba279a | 141 | gd->arch.cpu += gd->relocaddr - CONFIG_SYS_MONITOR_BASE; |
c2240d4d SG |
142 | |
143 | /* | |
144 | * If we didn't know the cpu mask & # cores, we can save them of | |
145 | * now rather than 'computing' them constantly | |
146 | */ | |
147 | fixup_cpu(); | |
148 | #endif | |
8d8ee47e | 149 | #ifdef CONFIG_SYS_RELOC_GD_ENV_ADDR |
c2240d4d | 150 | /* |
6c6add60 SG |
151 | * Relocate the early env_addr pointer unless we know it is not inside |
152 | * the binary. Some systems need this and for the rest, it doesn't hurt. | |
c2240d4d | 153 | */ |
6c6add60 | 154 | gd->env_addr += gd->reloc_off; |
c2240d4d | 155 | #endif |
50149ea3 | 156 | #ifdef CONFIG_EFI_LOADER |
e7ac009b HS |
157 | /* |
158 | * On the ARM architecture gd is mapped to a fixed register (r9 or x18). | |
159 | * As this register may be overwritten by an EFI payload we save it here | |
160 | * and restore it on every callback entered. | |
161 | */ | |
162 | efi_save_gd(); | |
163 | ||
50149ea3 AG |
164 | efi_runtime_relocate(gd->relocaddr, NULL); |
165 | #endif | |
e9acb9ea | 166 | |
c2240d4d | 167 | return 0; |
6f6430d7 SG |
168 | } |
169 | ||
130845ba | 170 | __weak int arch_initr_trap(void) |
c2240d4d | 171 | { |
c2240d4d SG |
172 | return 0; |
173 | } | |
c2240d4d | 174 | |
c2240d4d SG |
175 | #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500) |
176 | static int initr_unlock_ram_in_cache(void) | |
177 | { | |
178 | unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */ | |
179 | return 0; | |
180 | } | |
181 | #endif | |
182 | ||
c2240d4d SG |
183 | static int initr_barrier(void) |
184 | { | |
185 | #ifdef CONFIG_PPC | |
186 | /* TODO: Can we not use dmb() macros for this? */ | |
187 | asm("sync ; isync"); | |
188 | #endif | |
189 | return 0; | |
190 | } | |
191 | ||
6f6430d7 SG |
192 | static int initr_malloc(void) |
193 | { | |
0be0f205 | 194 | ulong start; |
6f6430d7 | 195 | |
3d6d5075 | 196 | #if CONFIG_IS_ENABLED(SYS_MALLOC_F) |
92aa3ec3 | 197 | debug("Pre-reloc malloc() used %#x bytes (%d KB)\n", gd->malloc_ptr, |
d59476b6 SG |
198 | gd->malloc_ptr / 1024); |
199 | #endif | |
6f6430d7 | 200 | /* The malloc area is immediately below the monitor copy in DRAM */ |
5e0404ff SW |
201 | /* |
202 | * This value MUST match the value of gd->start_addr_sp in board_f.c: | |
203 | * reserve_noncached(). | |
204 | */ | |
0be0f205 SG |
205 | start = gd->relocaddr - TOTAL_MALLOC_LEN; |
206 | gd_set_malloc_start(start); | |
207 | mem_malloc_init((ulong)map_sysmem(start, TOTAL_MALLOC_LEN), | |
a733b06b | 208 | TOTAL_MALLOC_LEN); |
6f6430d7 SG |
209 | return 0; |
210 | } | |
211 | ||
3af86a4e SG |
212 | static int initr_of_live(void) |
213 | { | |
a652d9c7 SG |
214 | if (CONFIG_IS_ENABLED(OF_LIVE)) { |
215 | int ret; | |
a132f770 | 216 | |
a652d9c7 SG |
217 | bootstage_start(BOOTSTAGE_ID_ACCUM_OF_LIVE, "of_live"); |
218 | ret = of_live_build(gd->fdt_blob, | |
219 | (struct device_node **)gd_of_root_ptr()); | |
220 | bootstage_accum(BOOTSTAGE_ID_ACCUM_OF_LIVE); | |
221 | if (ret) | |
222 | return ret; | |
223 | } | |
a132f770 SG |
224 | |
225 | return 0; | |
3af86a4e | 226 | } |
3af86a4e | 227 | |
1ce60176 SG |
228 | #ifdef CONFIG_DM |
229 | static int initr_dm(void) | |
230 | { | |
1057e6cf SG |
231 | int ret; |
232 | ||
ee88ba71 SG |
233 | oftree_reset(); |
234 | ||
a8729a26 | 235 | /* Drop the pre-reloc driver model and start a new one */ |
ab7cd627 | 236 | gd->dm_root = NULL; |
d74d6b44 SG |
237 | #ifdef CONFIG_TIMER |
238 | gd->timer = NULL; | |
239 | #endif | |
b67eefdb | 240 | bootstage_start(BOOTSTAGE_ID_ACCUM_DM_R, "dm_r"); |
1057e6cf | 241 | ret = dm_init_and_scan(false); |
b67eefdb | 242 | bootstage_accum(BOOTSTAGE_ID_ACCUM_DM_R); |
1057e6cf SG |
243 | if (ret) |
244 | return ret; | |
1057e6cf SG |
245 | |
246 | return 0; | |
1ce60176 SG |
247 | } |
248 | #endif | |
249 | ||
dd0edcb2 SG |
250 | static int initr_dm_devices(void) |
251 | { | |
252 | int ret; | |
253 | ||
254 | if (IS_ENABLED(CONFIG_TIMER_EARLY)) { | |
255 | ret = dm_timer_init(); | |
256 | if (ret) | |
257 | return ret; | |
258 | } | |
259 | ||
90a979d7 JJH |
260 | if (IS_ENABLED(CONFIG_MULTIPLEXER)) { |
261 | /* | |
262 | * Initialize the multiplexer controls to their default state. | |
263 | * This must be done early as other drivers may unknowingly | |
264 | * rely on it. | |
265 | */ | |
266 | ret = dm_mux_init(); | |
267 | if (ret) | |
268 | return ret; | |
269 | } | |
270 | ||
dd0edcb2 SG |
271 | return 0; |
272 | } | |
273 | ||
881c124a SG |
274 | static int initr_bootstage(void) |
275 | { | |
881c124a SG |
276 | bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r"); |
277 | ||
278 | return 0; | |
279 | } | |
280 | ||
6f6430d7 SG |
281 | __weak int power_init_board(void) |
282 | { | |
283 | return 0; | |
284 | } | |
285 | ||
286 | static int initr_announce(void) | |
287 | { | |
a0ba279a | 288 | debug("Now running in RAM - U-Boot at: %08lx\n", gd->relocaddr); |
6f6430d7 SG |
289 | return 0; |
290 | } | |
291 | ||
3c10dc95 SG |
292 | static int initr_binman(void) |
293 | { | |
c03cb022 TH |
294 | int ret; |
295 | ||
3c10dc95 SG |
296 | if (!CONFIG_IS_ENABLED(BINMAN_FDT)) |
297 | return 0; | |
298 | ||
c03cb022 TH |
299 | ret = binman_init(); |
300 | if (ret) | |
301 | printf("binman_init failed:%d\n", ret); | |
302 | ||
303 | return ret; | |
3c10dc95 SG |
304 | } |
305 | ||
e856bdcf | 306 | #if defined(CONFIG_MTD_NOR_FLASH) |
62d3a58d PG |
307 | __weak int is_flash_available(void) |
308 | { | |
309 | return 1; | |
310 | } | |
311 | ||
6f6430d7 SG |
312 | static int initr_flash(void) |
313 | { | |
c2240d4d | 314 | ulong flash_size = 0; |
b75d8dc5 | 315 | struct bd_info *bd = gd->bd; |
6f6430d7 | 316 | |
62d3a58d PG |
317 | if (!is_flash_available()) |
318 | return 0; | |
319 | ||
6f6430d7 SG |
320 | puts("Flash: "); |
321 | ||
70879a92 | 322 | if (board_flash_wp_on()) |
c2240d4d | 323 | printf("Uninitialized - Write Protect On\n"); |
70879a92 | 324 | else |
c2240d4d | 325 | flash_size = flash_init(); |
70879a92 | 326 | |
6f6430d7 SG |
327 | print_size(flash_size, ""); |
328 | #ifdef CONFIG_SYS_FLASH_CHECKSUM | |
329 | /* | |
92f84b67 MS |
330 | * Compute and print flash CRC if flashchecksum is set to 'y' |
331 | * | |
29caf930 | 332 | * NOTE: Maybe we should add some schedule()? XXX |
92f84b67 | 333 | */ |
bfebc8c9 | 334 | if (env_get_yesno("flashchecksum") == 1) { |
65cc0e2a | 335 | const uchar *flash_base = (const uchar *)CFG_SYS_FLASH_BASE; |
92f84b67 | 336 | |
6f6430d7 | 337 | printf(" CRC: %08X", crc32(0, |
92f84b67 MS |
338 | flash_base, |
339 | flash_size)); | |
6f6430d7 SG |
340 | } |
341 | #endif /* CONFIG_SYS_FLASH_CHECKSUM */ | |
342 | putc('\n'); | |
343 | ||
c2240d4d | 344 | /* update start of FLASH memory */ |
65cc0e2a TR |
345 | #ifdef CFG_SYS_FLASH_BASE |
346 | bd->bi_flashstart = CFG_SYS_FLASH_BASE; | |
c2240d4d SG |
347 | #endif |
348 | /* size of FLASH memory (final value) */ | |
349 | bd->bi_flashsize = flash_size; | |
350 | ||
351 | #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE) | |
352 | /* Make a update of the Memctrl. */ | |
353 | update_flash_size(flash_size); | |
354 | #endif | |
355 | ||
c2240d4d SG |
356 | #if defined(CONFIG_OXC) || defined(CONFIG_RMU) |
357 | /* flash mapped at end of memory map */ | |
98463903 | 358 | bd->bi_flashoffset = CONFIG_TEXT_BASE + flash_size; |
65cc0e2a | 359 | #elif CONFIG_SYS_MONITOR_BASE == CFG_SYS_FLASH_BASE |
c2240d4d SG |
360 | bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */ |
361 | #endif | |
362 | return 0; | |
363 | } | |
364 | #endif | |
365 | ||
6f6430d7 SG |
366 | #ifdef CONFIG_CMD_NAND |
367 | /* go init the NAND */ | |
2588ba14 | 368 | static int initr_nand(void) |
6f6430d7 SG |
369 | { |
370 | puts("NAND: "); | |
371 | nand_init(); | |
203db38a | 372 | printf("%lu MiB\n", nand_size() / 1024); |
6f6430d7 SG |
373 | return 0; |
374 | } | |
375 | #endif | |
376 | ||
377 | #if defined(CONFIG_CMD_ONENAND) | |
378 | /* go init the NAND */ | |
2588ba14 | 379 | static int initr_onenand(void) |
6f6430d7 SG |
380 | { |
381 | puts("NAND: "); | |
382 | onenand_init(); | |
383 | return 0; | |
384 | } | |
385 | #endif | |
386 | ||
4aa2ba3a | 387 | #ifdef CONFIG_MMC |
2588ba14 | 388 | static int initr_mmc(void) |
6f6430d7 SG |
389 | { |
390 | puts("MMC: "); | |
391 | mmc_initialize(gd->bd); | |
392 | return 0; | |
393 | } | |
394 | #endif | |
395 | ||
722bc5b5 AL |
396 | #ifdef CONFIG_PVBLOCK |
397 | static int initr_pvblock(void) | |
398 | { | |
399 | puts("PVBLOCK: "); | |
400 | pvblock_init(); | |
401 | return 0; | |
402 | } | |
403 | #endif | |
404 | ||
6f6430d7 SG |
405 | /* |
406 | * Tell if it's OK to load the environment early in boot. | |
407 | * | |
776babd7 | 408 | * If CONFIG_OF_CONTROL is defined, we'll check with the FDT to see |
6f6430d7 SG |
409 | * if this is OK (defaulting to saying it's OK). |
410 | * | |
411 | * NOTE: Loading the environment early can be a bad idea if security is | |
412 | * important, since no verification is done on the environment. | |
413 | * | |
185f812c | 414 | * Return: 0 if environment should not be loaded, !=0 if it is ok to load |
6f6430d7 SG |
415 | */ |
416 | static int should_load_env(void) | |
417 | { | |
9441f8cb | 418 | if (IS_ENABLED(CONFIG_OF_CONTROL)) |
7de8bd03 | 419 | return ofnode_conf_read_int("load-environment", 1); |
9441f8cb OP |
420 | |
421 | if (IS_ENABLED(CONFIG_DELAY_ENVIRONMENT)) | |
422 | return 0; | |
423 | ||
6f6430d7 | 424 | return 1; |
6f6430d7 SG |
425 | } |
426 | ||
427 | static int initr_env(void) | |
428 | { | |
429 | /* initialize environment */ | |
430 | if (should_load_env()) | |
431 | env_relocate(); | |
432 | else | |
0ac7d722 | 433 | env_set_default(NULL, 0); |
9441f8cb | 434 | |
95fd9772 RV |
435 | env_import_fdt(); |
436 | ||
9441f8cb OP |
437 | if (IS_ENABLED(CONFIG_OF_CONTROL)) |
438 | env_set_hex("fdtcontroladdr", | |
439 | (unsigned long)map_to_sysmem(gd->fdt_blob)); | |
6f6430d7 | 440 | |
4c776089 | 441 | #if (IS_ENABLED(CONFIG_SAVE_PREV_BL_INITRAMFS_START_ADDR) || \ |
10f8bc09 | 442 | IS_ENABLED(CONFIG_SAVE_PREV_BL_FDT_ADDR)) |
12a3e1ad DS |
443 | save_prev_bl_data(); |
444 | #endif | |
445 | ||
6f6430d7 | 446 | /* Initialize from environment */ |
bb872dd9 | 447 | image_load_addr = env_get_ulong("loadaddr", 16, image_load_addr); |
c2240d4d | 448 | |
c2240d4d SG |
449 | return 0; |
450 | } | |
451 | ||
167f699b | 452 | #ifdef CONFIG_SYS_MALLOC_BOOTPARAMS |
c722f0b0 AB |
453 | static int initr_malloc_bootparams(void) |
454 | { | |
455 | gd->bd->bi_boot_params = (ulong)malloc(CONFIG_SYS_BOOTPARAMS_LEN); | |
456 | if (!gd->bd->bi_boot_params) { | |
457 | puts("WARNING: Cannot allocate space for boot parameters\n"); | |
458 | return -ENOMEM; | |
459 | } | |
460 | return 0; | |
461 | } | |
462 | #endif | |
463 | ||
c2240d4d SG |
464 | static int initr_status_led(void) |
465 | { | |
13cfbe51 | 466 | status_led_init(); |
fc55ae03 CM |
467 | |
468 | return 0; | |
469 | } | |
470 | ||
471 | static int initr_boot_led_blink(void) | |
472 | { | |
473 | status_led_boot_blink(); | |
474 | ||
475 | led_boot_blink(); | |
476 | ||
477 | return 0; | |
478 | } | |
479 | ||
480 | static int initr_boot_led_on(void) | |
481 | { | |
482 | led_boot_on(); | |
483 | ||
c2240d4d SG |
484 | return 0; |
485 | } | |
c2240d4d | 486 | |
98ad145d | 487 | #if defined(CONFIG_CMD_NET) |
6f6430d7 SG |
488 | static int initr_net(void) |
489 | { | |
490 | puts("Net: "); | |
d2eaec60 | 491 | eth_initialize(); |
6f6430d7 SG |
492 | #if defined(CONFIG_RESET_PHY_R) |
493 | debug("Reset Ethernet PHY\n"); | |
494 | reset_phy(); | |
495 | #endif | |
496 | return 0; | |
497 | } | |
498 | #endif | |
499 | ||
500 | #ifdef CONFIG_POST | |
501 | static int initr_post(void) | |
502 | { | |
503 | post_run(NULL, POST_RAM | post_bootmode_get(0)); | |
504 | return 0; | |
505 | } | |
506 | #endif | |
507 | ||
7c5c137c | 508 | #if defined(CFG_PRAM) |
6f6430d7 SG |
509 | /* |
510 | * Export available size of memory for Linux, taking into account the | |
511 | * protected RAM at top of memory | |
512 | */ | |
513 | int initr_mem(void) | |
514 | { | |
515 | ulong pram = 0; | |
516 | char memsz[32]; | |
517 | ||
7c5c137c | 518 | pram = env_get_ulong("pram", 10, CFG_PRAM); |
92f84b67 | 519 | sprintf(memsz, "%ldk", (long int)((gd->ram_size / 1024) - pram)); |
382bee57 | 520 | env_set("mem", memsz); |
c2240d4d SG |
521 | |
522 | return 0; | |
523 | } | |
524 | #endif | |
525 | ||
b6400de7 SG |
526 | static int initr_lmb(void) |
527 | { | |
528 | if (CONFIG_IS_ENABLED(LMB)) | |
529 | return lmb_init(); | |
530 | else | |
531 | return 0; | |
532 | } | |
533 | ||
ff66e7bb SG |
534 | static int dm_announce(void) |
535 | { | |
536 | int device_count; | |
537 | int uclass_count; | |
538 | ||
539 | if (IS_ENABLED(CONFIG_DM)) { | |
540 | dm_get_stats(&device_count, &uclass_count); | |
541 | printf("Core: %d devices, %d uclasses", device_count, | |
542 | uclass_count); | |
543 | if (CONFIG_IS_ENABLED(OF_REAL)) | |
544 | printf(", devicetree: %s", fdtdec_get_srcname()); | |
0fc406ab SG |
545 | if (CONFIG_IS_ENABLED(UPL)) |
546 | printf(", universal payload active"); | |
ff66e7bb | 547 | printf("\n"); |
93233b07 SG |
548 | if (IS_ENABLED(CONFIG_OF_HAS_PRIOR_STAGE) && |
549 | (gd->fdt_src == FDTSRC_SEPARATE || | |
550 | gd->fdt_src == FDTSRC_EMBED)) { | |
551 | printf("Warning: Unexpected devicetree source (not from a prior stage)"); | |
552 | printf("Warning: U-Boot may not function properly\n"); | |
553 | } | |
c74e0341 SG |
554 | if (IS_ENABLED(CONFIG_OF_TAG_MIGRATE) && |
555 | (gd->flags & GD_FLG_OF_TAG_MIGRATE)) | |
556 | /* | |
557 | * U-Boot will silently fail to work after 2023.07 if | |
558 | * there are old tags present | |
559 | */ | |
560 | printf("Warning: Device tree includes old 'u-boot,dm-' tags: please fix by 2023.07!\n"); | |
ff66e7bb SG |
561 | } |
562 | ||
563 | return 0; | |
564 | } | |
565 | ||
6f6430d7 SG |
566 | static int run_main_loop(void) |
567 | { | |
a733b06b SG |
568 | #ifdef CONFIG_SANDBOX |
569 | sandbox_main_loop_init(); | |
570 | #endif | |
467bad5e SG |
571 | |
572 | event_notify_null(EVT_MAIN_LOOP); | |
573 | ||
6f6430d7 SG |
574 | /* main_loop() can return to retry autoboot, if so just run it again */ |
575 | for (;;) | |
576 | main_loop(); | |
577 | return 0; | |
578 | } | |
579 | ||
580 | /* | |
e7f59dea SG |
581 | * Over time we hope to remove these functions with code fragments and |
582 | * stub functions, and instead call the relevant function directly. | |
583 | * | |
584 | * We also hope to remove most of the driver-related init and do it if/when | |
6f6430d7 | 585 | * the driver is later used. |
c2240d4d SG |
586 | * |
587 | * TODO: perhaps reset the watchdog in the initcall function after each call? | |
6f6430d7 | 588 | */ |
4acff452 | 589 | static init_fnc_t init_sequence_r[] = { |
71c52dba | 590 | initr_trace, |
6f6430d7 | 591 | initr_reloc, |
87a5d1b5 | 592 | event_init, |
c2240d4d | 593 | /* TODO: could x86/PPC have this also perhaps? */ |
4d4222d0 | 594 | #if defined(CONFIG_ARM) || defined(CONFIG_RISCV) |
6f6430d7 | 595 | initr_caches, |
12eaf31c YS |
596 | /* Note: For Freescale LS2 SoCs, new MMU table is created in DDR. |
597 | * A temporary mapping of IFC high region is since removed, | |
92f84b67 | 598 | * so environmental variables in NOR flash is not available |
12eaf31c YS |
599 | * until board_init() is called below to remap IFC to high |
600 | * region. | |
601 | */ | |
9fb02491 SG |
602 | #endif |
603 | initr_reloc_global_data, | |
fef3e25f YS |
604 | #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500) |
605 | initr_unlock_ram_in_cache, | |
606 | #endif | |
9fb02491 SG |
607 | initr_barrier, |
608 | initr_malloc, | |
af1bc0cf | 609 | log_init, |
5ac44a55 | 610 | initr_bootstage, /* Needs malloc() but has its own timer */ |
51c5a2c5 OP |
611 | #if defined(CONFIG_CONSOLE_RECORD) |
612 | console_record_init, | |
613 | #endif | |
671fa63e | 614 | #ifdef CONFIG_SYS_NONCACHED_MEMORY |
42d0d422 | 615 | noncached_init, |
671fa63e | 616 | #endif |
3af86a4e | 617 | initr_of_live, |
9fb02491 SG |
618 | #ifdef CONFIG_DM |
619 | initr_dm, | |
620 | #endif | |
a43b598c | 621 | #ifdef CONFIG_ADDR_MAP |
1b212bb9 | 622 | init_addr_map, |
a43b598c | 623 | #endif |
11232139 | 624 | #if defined(CONFIG_ARM) || defined(CONFIG_RISCV) || defined(CONFIG_SANDBOX) |
6f6430d7 | 625 | board_init, /* Setup chipselects */ |
c2240d4d SG |
626 | #endif |
627 | /* | |
628 | * TODO: printing of the clock inforamtion of the board is now | |
629 | * implemented as part of bdinfo command. Currently only support for | |
630 | * davinci SOC's is added. Remove this check once all the board | |
631 | * implement this. | |
632 | */ | |
633 | #ifdef CONFIG_CLOCKS | |
634 | set_cpu_clk_info, /* Setup clock information */ | |
5d00995c | 635 | #endif |
b6400de7 | 636 | initr_lmb, |
5d00995c AG |
637 | #ifdef CONFIG_EFI_LOADER |
638 | efi_memory_init, | |
6f6430d7 | 639 | #endif |
3c10dc95 | 640 | initr_binman, |
fe08d39d SG |
641 | #ifdef CONFIG_FSP_VERSION2 |
642 | arch_fsp_init_r, | |
643 | #endif | |
dd0edcb2 | 644 | initr_dm_devices, |
9fb02491 | 645 | stdio_init_tables, |
bf2fb81a | 646 | serial_initialize, |
6f6430d7 | 647 | initr_announce, |
ff66e7bb | 648 | dm_announce, |
6874cb72 | 649 | #if CONFIG_IS_ENABLED(WDT) |
84b2416b WG |
650 | initr_watchdog, |
651 | #endif | |
c2240d4d | 652 | INIT_FUNC_WATCHDOG_RESET |
130845ba | 653 | arch_initr_trap, |
c2240d4d SG |
654 | #if defined(CONFIG_BOARD_EARLY_INIT_R) |
655 | board_early_init_r, | |
656 | #endif | |
657 | INIT_FUNC_WATCHDOG_RESET | |
6f6430d7 | 658 | #ifdef CONFIG_POST |
7addd3c6 | 659 | post_output_backlog, |
6f6430d7 | 660 | #endif |
c2240d4d | 661 | INIT_FUNC_WATCHDOG_RESET |
b9f6d0f7 | 662 | #if defined(CONFIG_PCI_INIT_R) && defined(CONFIG_SYS_EARLY_PCI_INIT) |
c2240d4d SG |
663 | /* |
664 | * Do early PCI configuration _before_ the flash gets initialised, | |
92f84b67 | 665 | * because PCU resources are crucial for flash access on some boards. |
c2240d4d | 666 | */ |
b9f6d0f7 | 667 | pci_init, |
c2240d4d | 668 | #endif |
6f6430d7 SG |
669 | #ifdef CONFIG_ARCH_EARLY_INIT_R |
670 | arch_early_init_r, | |
671 | #endif | |
672 | power_init_board, | |
e856bdcf | 673 | #ifdef CONFIG_MTD_NOR_FLASH |
6f6430d7 | 674 | initr_flash, |
c2240d4d SG |
675 | #endif |
676 | INIT_FUNC_WATCHDOG_RESET | |
936478e7 | 677 | #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_X86) |
c2240d4d SG |
678 | /* initialize higher level parts of CPU like time base and timers */ |
679 | cpu_init_r, | |
be274b99 | 680 | #endif |
023d9c93 | 681 | #ifdef CONFIG_EFI_LOADER |
5e847f77 HS |
682 | efi_init_early, |
683 | #endif | |
6f6430d7 SG |
684 | #ifdef CONFIG_CMD_NAND |
685 | initr_nand, | |
686 | #endif | |
687 | #ifdef CONFIG_CMD_ONENAND | |
688 | initr_onenand, | |
689 | #endif | |
4aa2ba3a | 690 | #ifdef CONFIG_MMC |
6f6430d7 | 691 | initr_mmc, |
48654416 OA |
692 | #endif |
693 | #ifdef CONFIG_XEN | |
eb2825b7 | 694 | xen_init, |
722bc5b5 AL |
695 | #endif |
696 | #ifdef CONFIG_PVBLOCK | |
697 | initr_pvblock, | |
6f6430d7 SG |
698 | #endif |
699 | initr_env, | |
167f699b | 700 | #ifdef CONFIG_SYS_MALLOC_BOOTPARAMS |
c722f0b0 AB |
701 | initr_malloc_bootparams, |
702 | #endif | |
c2240d4d | 703 | INIT_FUNC_WATCHDOG_RESET |
fb504b2c | 704 | cpu_secondary_init_r, |
d7d40f61 | 705 | #if defined(CONFIG_ID_EEPROM) |
c2240d4d SG |
706 | mac_read_from_eeprom, |
707 | #endif | |
6092ce50 | 708 | INITCALL_EVENT(EVT_SETTINGS_R), |
c2240d4d | 709 | INIT_FUNC_WATCHDOG_RESET |
b9f6d0f7 | 710 | #if defined(CONFIG_PCI_INIT_R) && !defined(CONFIG_SYS_EARLY_PCI_INIT) |
c2240d4d SG |
711 | /* |
712 | * Do pci configuration | |
713 | */ | |
b9f6d0f7 | 714 | pci_init, |
c2240d4d | 715 | #endif |
9fb02491 | 716 | stdio_add_devices, |
01548580 | 717 | jumptable_init, |
6f6430d7 | 718 | #ifdef CONFIG_API |
ce41e735 | 719 | api_init, |
6f6430d7 SG |
720 | #endif |
721 | console_init_r, /* fully init console as a device */ | |
722 | #ifdef CONFIG_DISPLAY_BOARDINFO_LATE | |
b0895384 | 723 | console_announce_r, |
0365ffcc | 724 | show_board_info, |
6f6430d7 SG |
725 | #endif |
726 | #ifdef CONFIG_ARCH_MISC_INIT | |
727 | arch_misc_init, /* miscellaneous arch-dependent init */ | |
728 | #endif | |
729 | #ifdef CONFIG_MISC_INIT_R | |
730 | misc_init_r, /* miscellaneous platform-dependent init */ | |
c2240d4d SG |
731 | #endif |
732 | INIT_FUNC_WATCHDOG_RESET | |
733 | #ifdef CONFIG_CMD_KGDB | |
78fc0395 | 734 | kgdb_init, |
6f6430d7 SG |
735 | #endif |
736 | interrupt_init, | |
daab59ac | 737 | #if defined(CONFIG_MICROBLAZE) || defined(CONFIG_M68K) |
be274b99 SG |
738 | timer_init, /* initialize timer */ |
739 | #endif | |
c2240d4d | 740 | initr_status_led, |
fc55ae03 | 741 | initr_boot_led_blink, |
c2240d4d | 742 | /* PPC has a udelay(20) here dating from 2002. Why? */ |
6f6430d7 SG |
743 | #ifdef CONFIG_BOARD_LATE_INIT |
744 | board_late_init, | |
745 | #endif | |
746 | #ifdef CONFIG_BITBANGMII | |
c65abc70 | 747 | bb_miiphy_init, |
6f6430d7 | 748 | #endif |
fd00c53f | 749 | #ifdef CONFIG_PCI_ENDPOINT |
c343e8c0 | 750 | pci_ep_init, |
fd00c53f | 751 | #endif |
98ad145d | 752 | #if defined(CONFIG_CMD_NET) |
c2240d4d | 753 | INIT_FUNC_WATCHDOG_RESET |
6f6430d7 SG |
754 | initr_net, |
755 | #endif | |
756 | #ifdef CONFIG_POST | |
757 | initr_post, | |
c2240d4d | 758 | #endif |
c2240d4d | 759 | INIT_FUNC_WATCHDOG_RESET |
91caa3bb | 760 | INITCALL_EVENT(EVT_LAST_STAGE_INIT), |
7c5c137c | 761 | #if defined(CFG_PRAM) |
c2240d4d | 762 | initr_mem, |
6f6430d7 | 763 | #endif |
fc55ae03 | 764 | initr_boot_led_on, |
6f6430d7 SG |
765 | run_main_loop, |
766 | }; | |
767 | ||
768 | void board_init_r(gd_t *new_gd, ulong dest_addr) | |
769 | { | |
c38a21d7 SG |
770 | /* |
771 | * The pre-relocation drivers may be using memory that has now gone | |
772 | * away. Mark serial as unavailable - this will fall back to the debug | |
773 | * UART if available. | |
774 | * | |
775 | * Do the same with log drivers since the memory may not be available. | |
776 | */ | |
777 | gd->flags &= ~(GD_FLG_SERIAL_READY | GD_FLG_LOG_READY); | |
778 | ||
fb92308b SG |
779 | /* |
780 | * Set up the new global data pointer. So far only x86 does this | |
781 | * here. | |
782 | * TODO([email protected]): Consider doing this for all archs, or | |
783 | * dropping the new_gd parameter. | |
784 | */ | |
86bb4888 SG |
785 | if (CONFIG_IS_ENABLED(X86_64) && !IS_ENABLED(CONFIG_EFI_APP)) |
786 | arch_setup_gd(new_gd); | |
fb92308b | 787 | |
47a602ea | 788 | #if !defined(CONFIG_X86) && !defined(CONFIG_ARM) && !defined(CONFIG_ARM64) |
6f6430d7 | 789 | gd = new_gd; |
be274b99 | 790 | #endif |
af1bc0cf | 791 | gd->flags &= ~GD_FLG_LOG_READY; |
7395398a | 792 | |
6f6430d7 SG |
793 | if (initcall_run_list(init_sequence_r)) |
794 | hang(); | |
795 | ||
796 | /* NOTREACHED - run_main_loop() does not return */ | |
797 | hang(); | |
798 | } |