1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2011 Andes Technology Corporation
4 * Shawn Lin, Andes Technology Corporation <nobuhiro@andestech.com>
5 * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
6 * Rick Chen, Andes Technology Corporation <rick@andestech.com>
12 #include <fdt_support.h>
15 #include <asm/byteorder.h>
18 #include <dm/device.h>
20 #include <u-boot/zlib.h>
22 DECLARE_GLOBAL_DATA_PTR;
24 __weak void board_quiesce_devices(void)
28 int arch_fixup_fdt(void *blob)
34 * announce_and_cleanup() - Print message and prepare for kernel boot
36 * @fake: non-zero to do everything except actually boot
38 static void announce_and_cleanup(int fake)
40 printf("\nStarting kernel ...%s\n\n", fake ?
41 "(fake run for tracing)" : "");
42 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
43 #ifdef CONFIG_BOOTSTAGE_FDT
44 bootstage_fdt_add_report();
46 #ifdef CONFIG_BOOTSTAGE_REPORT
50 #ifdef CONFIG_USB_DEVICE
54 board_quiesce_devices();
57 * Call remove function of all devices with a removal flag set.
58 * This may be useful for last-stage operations, like cancelling
59 * of DMA operation or releasing device internal buffers.
61 dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
63 cleanup_before_linux();
66 static void boot_prep_linux(bootm_headers_t *images)
68 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
69 #ifdef CONFIG_OF_LIBFDT
70 debug("using: FDT\n");
71 if (image_setup_linux(images)) {
72 printf("FDT creation failed! hanging...");
77 printf("Device tree not found or missing FDT support\n");
82 static void boot_jump_linux(bootm_headers_t *images, int flag)
84 void (*kernel)(ulong hart, void *dtb);
85 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
90 kernel = (void (*)(ulong, void *))images->ep;
92 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
94 debug("## Transferring control to kernel (at address %08lx) ...\n",
97 announce_and_cleanup(fake);
100 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
102 ret = smp_call_function(images->ep,
103 (ulong)images->ft_addr, 0, 0);
107 kernel(gd->arch.boot_hart, images->ft_addr);
112 int do_bootm_linux(int flag, int argc, char * const argv[],
113 bootm_headers_t *images)
115 /* No need for those on RISC-V */
116 if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
119 if (flag & BOOTM_STATE_OS_PREP) {
120 boot_prep_linux(images);
124 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
125 boot_jump_linux(images, flag);
129 boot_prep_linux(images);
130 boot_jump_linux(images, flag);
134 int do_bootm_vxworks(int flag, int argc, char * const argv[],
135 bootm_headers_t *images)
137 return do_bootm_linux(flag, argc, argv, images);