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>
10 #include <bootstage.h>
13 #include <fdt_support.h>
16 #include <asm/global_data.h>
19 #include <asm/byteorder.h>
22 #include <dm/device.h>
24 #include <u-boot/zlib.h>
26 DECLARE_GLOBAL_DATA_PTR;
28 __weak void board_quiesce_devices(void)
33 * announce_and_cleanup() - Print message and prepare for kernel boot
35 * @fake: non-zero to do everything except actually boot
37 static void announce_and_cleanup(int fake)
39 printf("\nStarting kernel ...%s\n\n", fake ?
40 "(fake run for tracing)" : "");
41 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
42 #ifdef CONFIG_BOOTSTAGE_FDT
43 bootstage_fdt_add_report();
45 #ifdef CONFIG_BOOTSTAGE_REPORT
49 #ifdef CONFIG_USB_DEVICE
53 board_quiesce_devices();
56 * Call remove function of all devices with a removal flag set.
57 * This may be useful for last-stage operations, like cancelling
58 * of DMA operation or releasing device internal buffers.
60 dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
62 cleanup_before_linux();
65 static void boot_prep_linux(struct bootm_headers *images)
67 if (CONFIG_IS_ENABLED(OF_LIBFDT) && IS_ENABLED(CONFIG_LMB) && images->ft_len) {
68 debug("using: FDT\n");
69 if (image_setup_linux(images)) {
70 printf("FDT creation failed! hanging...");
74 printf("Device tree not found or missing FDT support\n");
79 static void boot_jump_linux(struct bootm_headers *images, int flag)
81 void (*kernel)(ulong hart, void *dtb);
82 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
87 kernel = (void (*)(ulong, void *))images->ep;
89 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
91 debug("## Transferring control to kernel (at address %08lx) ...\n",
94 announce_and_cleanup(fake);
97 if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) {
99 ret = smp_call_function(images->ep,
100 (ulong)images->ft_addr, 0, 0);
104 kernel(gd->arch.boot_hart, images->ft_addr);
109 int do_bootm_linux(int flag, int argc, char *const argv[],
110 struct bootm_headers *images)
112 /* No need for those on RISC-V */
113 if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
116 if (flag & BOOTM_STATE_OS_PREP) {
117 boot_prep_linux(images);
121 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
122 boot_jump_linux(images, flag);
126 boot_prep_linux(images);
127 boot_jump_linux(images, flag);
131 int do_bootm_vxworks(int flag, int argc, char *const argv[],
132 struct bootm_headers *images)
134 return do_bootm_linux(flag, argc, argv, images);
137 static ulong get_sp(void)
141 asm("mv %0, sp" : "=r"(ret) : );
145 void arch_lmb_reserve(struct lmb *lmb)
147 arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096);