1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2013-2014 Synopsys, Inc. All rights reserved.
13 #include <asm/cache.h>
15 DECLARE_GLOBAL_DATA_PTR;
17 static ulong get_sp(void)
21 asm("mov %0, sp" : "=r"(ret) : );
25 void arch_lmb_reserve(struct lmb *lmb)
30 * Booting a (Linux) kernel image
32 * Allocate space for command line and board info - the
33 * address should be as high as possible within the reach of
34 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
35 * memory, which means far enough below the current stack
39 debug("## Current stack ends at 0x%08lx ", sp);
41 /* adjust sp by 4K to be safe */
43 lmb_reserve(lmb, sp, (CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp));
46 static int cleanup_before_linux(void)
49 sync_n_cleanup_cache_all();
54 __weak int board_prep_linux(bootm_headers_t *images) { return 0; }
56 /* Subcommand: PREP */
57 static int boot_prep_linux(bootm_headers_t *images)
61 ret = image_setup_linux(images);
65 return board_prep_linux(images);
68 /* Generic implementation for single core CPU */
69 __weak void board_jump_and_run(ulong entry, int zero, int arch, uint params)
71 void (*kernel_entry)(int zero, int arch, uint params);
73 kernel_entry = (void (*)(int, int, uint))entry;
75 kernel_entry(zero, arch, params);
79 static void boot_jump_linux(bootm_headers_t *images, int flag)
83 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
85 kernel_entry = images->ep;
87 debug("## Transferring control to Linux (at address %08lx)...\n",
89 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
91 printf("\nStarting kernel ...%s\n\n", fake ?
92 "(fake run for tracing)" : "");
93 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
95 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
97 r2 = (unsigned int)images->ft_addr;
100 r2 = (unsigned int)env_get("bootargs");
103 cleanup_before_linux();
106 board_jump_and_run(kernel_entry, r0, 0, r2);
109 int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
111 /* No need for those on ARC */
112 if ((flag & BOOTM_STATE_OS_BD_T) || (flag & BOOTM_STATE_OS_CMDLINE))
115 if (flag & BOOTM_STATE_OS_PREP)
116 return boot_prep_linux(images);
118 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
119 boot_jump_linux(images, flag);