3 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4 * Marius Groeger <mgroeger@sysgo.de>
6 * Copyright (C) 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
8 * SPDX-License-Identifier: GPL-2.0+
14 #include <fdt_support.h>
16 #include <u-boot/zlib.h>
17 #include <asm/bootparam.h>
19 #include <asm/byteorder.h>
20 #include <asm/zimage.h>
21 #ifdef CONFIG_SYS_COREBOOT
22 #include <asm/arch/timestamp.h>
25 DECLARE_GLOBAL_DATA_PTR;
27 #define COMMAND_LINE_OFFSET 0x9000
29 __weak void board_quiesce_devices(void)
33 void bootm_announce_and_cleanup(void)
35 printf("\nStarting kernel ...\n\n");
37 #ifdef CONFIG_SYS_COREBOOT
38 timestamp_add_now(TS_U_BOOT_START_KERNEL);
40 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
41 #ifdef CONFIG_BOOTSTAGE_REPORT
46 #if defined(CONFIG_OF_LIBFDT) && !defined(CONFIG_OF_NO_KERNEL)
47 int arch_fixup_memory_node(void *blob)
51 u64 start[CONFIG_NR_DRAM_BANKS];
52 u64 size[CONFIG_NR_DRAM_BANKS];
54 for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
55 start[bank] = bd->bi_dram[bank].start;
56 size[bank] = bd->bi_dram[bank].size;
59 return fdt_fixup_memory_banks(blob, start, size, CONFIG_NR_DRAM_BANKS);
63 /* Subcommand: PREP */
64 static int boot_prep_linux(bootm_headers_t *images)
66 char *cmd_line_dest = NULL;
73 #ifdef CONFIG_OF_LIBFDT
75 debug("using: FDT\n");
76 if (image_setup_linux(images)) {
77 puts("FDT creation failed! hanging...");
82 if (images->legacy_hdr_valid) {
83 hdr = images->legacy_hdr_os;
84 if (image_check_type(hdr, IH_TYPE_MULTI)) {
85 ulong os_data, os_len;
87 /* if multi-part image, we need to get first subimage */
88 image_multi_getimg(hdr, 0, &os_data, &os_len);
89 data = (void *)os_data;
92 /* otherwise get image data */
93 data = (void *)image_get_data(hdr);
94 len = image_get_data_size(hdr);
97 #if defined(CONFIG_FIT)
98 } else if (images->fit_uname_os && is_zimage) {
99 ret = fit_image_get_data(images->fit_hdr_os,
100 images->fit_noffset_os,
101 (const void **)&data, &len);
103 puts("Can't get image data/size!\n");
114 base_ptr = (char *)load_zimage(data, len, &load_address);
115 images->os.load = load_address;
116 cmd_line_dest = base_ptr + COMMAND_LINE_OFFSET;
117 images->ep = (ulong)base_ptr;
118 } else if (images->ep) {
119 cmd_line_dest = (void *)images->ep + COMMAND_LINE_OFFSET;
121 printf("## Kernel loading failed (missing x86 kernel setup) ...\n");
125 printf("Setup at %#08lx\n", images->ep);
126 ret = setup_zimage((void *)images->ep, cmd_line_dest,
128 images->rd_end - images->rd_start);
131 printf("## Setting up boot parameters failed ...\n");
141 int boot_linux_kernel(ulong setup_base, ulong load_address, bool image_64bit)
143 bootm_announce_and_cleanup();
145 #ifdef CONFIG_SYS_COREBOOT
146 timestamp_add_now(TS_U_BOOT_START_KERNEL);
149 if (!cpu_has_64bit()) {
150 puts("Cannot boot 64-bit kernel on 32-bit machine\n");
153 return cpu_jump_to_64bit(setup_base, load_address);
156 * Set %ebx, %ebp, and %edi to 0, %esi to point to the
157 * boot_params structure, and then jump to the kernel. We
158 * assume that %cs is 0x10, 4GB flat, and read/execute, and
159 * the data segments are 0x18, 4GB flat, and read/write.
160 * U-Boot is setting them up that way for itself in
161 * arch/i386/cpu/cpu.c.
163 * Note that we cannot currently boot a kernel while running as
164 * an EFI application. Please use the payload option for that.
166 #ifndef CONFIG_EFI_APP
167 __asm__ __volatile__ (
170 "jmp *%[kernel_entry]\n"
171 :: [kernel_entry]"a"(load_address),
172 [boot_params] "S"(setup_base),
178 /* We can't get to here */
183 static int boot_jump_linux(bootm_headers_t *images)
185 debug("## Transferring control to Linux (at address %08lx, kernel %08lx) ...\n",
186 images->ep, images->os.load);
188 return boot_linux_kernel(images->ep, images->os.load,
189 images->os.arch == IH_ARCH_X86_64);
192 int do_bootm_linux(int flag, int argc, char * const argv[],
193 bootm_headers_t *images)
195 /* No need for those on x86 */
196 if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
199 if (flag & BOOTM_STATE_OS_PREP)
200 return boot_prep_linux(images);
202 if (flag & BOOTM_STATE_OS_GO)
203 return boot_jump_linux(images);
205 return boot_jump_linux(images);