1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2013-2014 Synopsys, Inc. All rights reserved.
12 #include <asm/cache.h>
14 DECLARE_GLOBAL_DATA_PTR;
16 static ulong get_sp(void)
20 asm("mov %0, sp" : "=r"(ret) : );
24 void arch_lmb_reserve(struct lmb *lmb)
29 * Booting a (Linux) kernel image
31 * Allocate space for command line and board info - the
32 * address should be as high as possible within the reach of
33 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
34 * memory, which means far enough below the current stack
38 debug("## Current stack ends at 0x%08lx ", sp);
40 /* adjust sp by 4K to be safe */
42 lmb_reserve(lmb, sp, (CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp));
45 static int cleanup_before_linux(void)
48 sync_n_cleanup_cache_all();
53 __weak int board_prep_linux(bootm_headers_t *images) { return 0; }
55 /* Subcommand: PREP */
56 static int boot_prep_linux(bootm_headers_t *images)
60 ret = image_setup_linux(images);
64 return board_prep_linux(images);
67 /* Generic implementation for single core CPU */
68 __weak void board_jump_and_run(ulong entry, int zero, int arch, uint params)
70 void (*kernel_entry)(int zero, int arch, uint params);
72 kernel_entry = (void (*)(int, int, uint))entry;
74 kernel_entry(zero, arch, params);
78 static void boot_jump_linux(bootm_headers_t *images, int flag)
82 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
84 kernel_entry = images->ep;
86 debug("## Transferring control to Linux (at address %08lx)...\n",
88 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
90 printf("\nStarting kernel ...%s\n\n", fake ?
91 "(fake run for tracing)" : "");
92 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
94 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
96 r2 = (unsigned int)images->ft_addr;
99 r2 = (unsigned int)env_get("bootargs");
102 cleanup_before_linux();
105 board_jump_and_run(kernel_entry, r0, 0, r2);
108 int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
110 /* No need for those on ARC */
111 if ((flag & BOOTM_STATE_OS_BD_T) || (flag & BOOTM_STATE_OS_CMDLINE))
114 if (flag & BOOTM_STATE_OS_PREP)
115 return boot_prep_linux(images);
117 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
118 boot_jump_linux(images, flag);