1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2007 Michal Simek
4 * (C) Copyright 2004 Atmark Techno, Inc.
6 * Michal SIMEK <monstr@monstr.eu>
7 * Yasushi SHOJI <yashi@atmark-techno.com>
14 #include <fdt_support.h>
17 #include <asm/cache.h>
18 #include <u-boot/zlib.h>
19 #include <asm/byteorder.h>
21 DECLARE_GLOBAL_DATA_PTR;
23 static ulong get_sp(void)
27 asm("addik %0, r1, 0" : "=r"(ret) : );
31 void arch_lmb_reserve(struct lmb *lmb)
37 * Booting a (Linux) kernel image
39 * Allocate space for command line and board info - the
40 * address should be as high as possible within the reach of
41 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
42 * memory, which means far enough below the current stack
46 debug("## Current stack ends at 0x%08lx ", sp);
48 /* adjust sp by 4K to be safe */
50 for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
51 if (sp < gd->bd->bi_dram[bank].start)
53 bank_end = gd->bd->bi_dram[bank].start +
54 gd->bd->bi_dram[bank].size;
57 lmb_reserve(lmb, sp, bank_end - sp);
62 static void boot_jump_linux(bootm_headers_t *images, int flag)
64 void (*thekernel)(char *cmdline, ulong rd, ulong dt);
65 ulong dt = (ulong)images->ft_addr;
66 ulong rd_start = images->initrd_start;
67 ulong cmdline = images->cmdline_start;
68 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
70 thekernel = (void (*)(char *, ulong, ulong))images->ep;
72 debug("## Transferring control to Linux (at address 0x%08lx) ",
74 debug("cmdline 0x%08lx, ramdisk 0x%08lx, FDT 0x%08lx...\n",
75 cmdline, rd_start, dt);
76 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
78 printf("\nStarting kernel ...%s\n\n", fake ?
79 "(fake run for tracing)" : "");
80 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
82 #ifdef XILINX_USE_DCACHE
83 flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
88 * Linux Kernel Parameters (passing device tree):
89 * r5: pointer to command line
90 * r6: pointer to ramdisk
91 * r7: pointer to the fdt, followed by the board info data
93 thekernel((char *)cmdline, rd_start, dt);
98 static void boot_prep_linux(bootm_headers_t *images)
100 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
101 debug("using: FDT\n");
102 if (image_setup_linux(images)) {
103 printf("FDT creation failed! hanging...");
109 int do_bootm_linux(int flag, int argc, char * const argv[],
110 bootm_headers_t *images)
112 images->cmdline_start = (ulong)env_get("bootargs");
114 /* cmdline init is the part of 'prep' and nothing to do for 'bdt' */
115 if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
118 if (flag & BOOTM_STATE_OS_PREP) {
119 boot_prep_linux(images);
123 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
124 boot_jump_linux(images, flag);
128 boot_prep_linux(images);
129 boot_jump_linux(images, flag);