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>
11 #include <bootstage.h>
15 #include <fdt_support.h>
19 #include <asm/cache.h>
20 #include <u-boot/zlib.h>
21 #include <asm/byteorder.h>
23 DECLARE_GLOBAL_DATA_PTR;
25 static ulong get_sp(void)
29 asm("addik %0, r1, 0" : "=r"(ret) : );
33 void arch_lmb_reserve(struct lmb *lmb)
39 * Booting a (Linux) kernel image
41 * Allocate space for command line and board info - the
42 * address should be as high as possible within the reach of
43 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
44 * memory, which means far enough below the current stack
48 debug("## Current stack ends at 0x%08lx ", sp);
50 /* adjust sp by 4K to be safe */
52 for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
53 if (sp < gd->bd->bi_dram[bank].start)
55 bank_end = gd->bd->bi_dram[bank].start +
56 gd->bd->bi_dram[bank].size;
59 lmb_reserve(lmb, sp, bank_end - sp);
64 static void boot_jump_linux(bootm_headers_t *images, int flag)
66 void (*thekernel)(char *cmdline, ulong rd, ulong dt);
67 ulong dt = (ulong)images->ft_addr;
68 ulong rd_start = images->initrd_start;
69 ulong cmdline = images->cmdline_start;
70 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
72 thekernel = (void (*)(char *, ulong, ulong))images->ep;
74 debug("## Transferring control to Linux (at address 0x%08lx) ",
76 debug("cmdline 0x%08lx, ramdisk 0x%08lx, FDT 0x%08lx...\n",
77 cmdline, rd_start, dt);
78 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
80 printf("\nStarting kernel ...%s\n\n", fake ?
81 "(fake run for tracing)" : "");
82 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
84 #ifdef XILINX_USE_DCACHE
85 flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
90 * Linux Kernel Parameters (passing device tree):
91 * r5: pointer to command line
92 * r6: pointer to ramdisk
93 * r7: pointer to the fdt, followed by the board info data
95 thekernel((char *)cmdline, rd_start, dt);
100 static void boot_prep_linux(bootm_headers_t *images)
102 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
103 debug("using: FDT\n");
104 if (image_setup_linux(images)) {
105 printf("FDT creation failed! hanging...");
111 int do_bootm_linux(int flag, int argc, char * const argv[],
112 bootm_headers_t *images)
114 images->cmdline_start = (ulong)env_get("bootargs");
116 /* cmdline init is the part of 'prep' and nothing to do for 'bdt' */
117 if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
120 if (flag & BOOTM_STATE_OS_PREP) {
121 boot_prep_linux(images);
125 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
126 boot_jump_linux(images, flag);
130 boot_prep_linux(images);
131 boot_jump_linux(images, flag);