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>
16 #include <asm/byteorder.h>
19 #include <dm/device.h>
21 #include <u-boot/zlib.h>
23 DECLARE_GLOBAL_DATA_PTR;
25 __weak void board_quiesce_devices(void)
30 * announce_and_cleanup() - Print message and prepare for kernel boot
32 * @fake: non-zero to do everything except actually boot
34 static void announce_and_cleanup(int fake)
36 printf("\nStarting kernel ...%s\n\n", fake ?
37 "(fake run for tracing)" : "");
38 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
39 #ifdef CONFIG_BOOTSTAGE_FDT
40 bootstage_fdt_add_report();
42 #ifdef CONFIG_BOOTSTAGE_REPORT
46 #ifdef CONFIG_USB_DEVICE
50 board_quiesce_devices();
53 * Call remove function of all devices with a removal flag set.
54 * This may be useful for last-stage operations, like cancelling
55 * of DMA operation or releasing device internal buffers.
57 dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
59 cleanup_before_linux();
62 static void boot_prep_linux(bootm_headers_t *images)
64 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
65 #ifdef CONFIG_OF_LIBFDT
66 debug("using: FDT\n");
67 if (image_setup_linux(images)) {
68 printf("FDT creation failed! hanging...");
73 printf("Device tree not found or missing FDT support\n");
78 static void boot_jump_linux(bootm_headers_t *images, int flag)
80 void (*kernel)(ulong hart, void *dtb);
81 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
86 kernel = (void (*)(ulong, void *))images->ep;
88 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
90 debug("## Transferring control to kernel (at address %08lx) ...\n",
93 announce_and_cleanup(fake);
96 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
98 ret = smp_call_function(images->ep,
99 (ulong)images->ft_addr, 0, 0);
103 kernel(gd->arch.boot_hart, images->ft_addr);
108 int do_bootm_linux(int flag, int argc, char * const argv[],
109 bootm_headers_t *images)
111 /* No need for those on RISC-V */
112 if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
115 if (flag & BOOTM_STATE_OS_PREP) {
116 boot_prep_linux(images);
120 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
121 boot_jump_linux(images, flag);
125 boot_prep_linux(images);
126 boot_jump_linux(images, flag);
130 int do_bootm_vxworks(int flag, int argc, char * const argv[],
131 bootm_headers_t *images)
133 return do_bootm_linux(flag, argc, argv, images);