]>
Commit | Line | Data |
---|---|---|
2262cfee WD |
1 | /* |
2 | * (C) Copyright 2002 | |
3 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> | |
4 | * Marius Groeger <mgroeger@sysgo.de> | |
5 | * | |
6 | * Copyright (C) 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl) | |
7 | * | |
1a459660 | 8 | * SPDX-License-Identifier: GPL-2.0+ |
2262cfee WD |
9 | */ |
10 | ||
11 | #include <common.h> | |
12 | #include <command.h> | |
76539383 | 13 | #include <errno.h> |
0d0ba59c | 14 | #include <fdt_support.h> |
2262cfee | 15 | #include <image.h> |
a31e091a | 16 | #include <u-boot/zlib.h> |
69370d14 | 17 | #include <asm/bootparam.h> |
2262cfee WD |
18 | #include <asm/byteorder.h> |
19 | #include <asm/zimage.h> | |
0d0ba59c SG |
20 | #ifdef CONFIG_SYS_COREBOOT |
21 | #include <asm/arch/timestamp.h> | |
22 | #endif | |
2262cfee | 23 | |
69370d14 GB |
24 | #define COMMAND_LINE_OFFSET 0x9000 |
25 | ||
0d0ba59c SG |
26 | /* |
27 | * Implement a weak default function for boards that optionally | |
28 | * need to clean up the system before jumping to the kernel. | |
29 | */ | |
30 | __weak void board_final_cleanup(void) | |
2262cfee | 31 | { |
0d0ba59c | 32 | } |
3ef96ded | 33 | |
0d0ba59c SG |
34 | void bootm_announce_and_cleanup(void) |
35 | { | |
36 | printf("\nStarting kernel ...\n\n"); | |
37 | ||
38 | #ifdef CONFIG_SYS_COREBOOT | |
39 | timestamp_add_now(TS_U_BOOT_START_KERNEL); | |
40 | #endif | |
41 | bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel"); | |
42 | #ifdef CONFIG_BOOTSTAGE_REPORT | |
43 | bootstage_report(); | |
cd7c596e | 44 | #endif |
0d0ba59c SG |
45 | board_final_cleanup(); |
46 | } | |
8bde7f77 | 47 | |
0d0ba59c SG |
48 | #if defined(CONFIG_OF_LIBFDT) && !defined(CONFIG_OF_NO_KERNEL) |
49 | int arch_fixup_memory_node(void *blob) | |
50 | { | |
51 | bd_t *bd = gd->bd; | |
52 | int bank; | |
53 | u64 start[CONFIG_NR_DRAM_BANKS]; | |
54 | u64 size[CONFIG_NR_DRAM_BANKS]; | |
55 | ||
56 | for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) { | |
57 | start[bank] = bd->bi_dram[bank].start; | |
58 | size[bank] = bd->bi_dram[bank].size; | |
59 | } | |
60 | ||
61 | return fdt_fixup_memory_banks(blob, start, size, CONFIG_NR_DRAM_BANKS); | |
62 | } | |
63 | #endif | |
49c3a861 | 64 | |
0d0ba59c SG |
65 | /* Subcommand: PREP */ |
66 | static int boot_prep_linux(bootm_headers_t *images) | |
67 | { | |
68 | char *cmd_line_dest = NULL; | |
69 | image_header_t *hdr; | |
70 | int is_zimage = 0; | |
71 | void *data = NULL; | |
72 | size_t len; | |
73 | int ret; | |
74 | ||
75 | #ifdef CONFIG_OF_LIBFDT | |
76 | if (images->ft_len) { | |
77 | debug("using: FDT\n"); | |
78 | if (image_setup_linux(images)) { | |
79 | puts("FDT creation failed! hanging..."); | |
80 | hang(); | |
81 | } | |
82 | } | |
83 | #endif | |
d5934ad7 MB |
84 | if (images->legacy_hdr_valid) { |
85 | hdr = images->legacy_hdr_os; | |
83088afb | 86 | if (image_check_type(hdr, IH_TYPE_MULTI)) { |
0d0ba59c SG |
87 | ulong os_data, os_len; |
88 | ||
d5934ad7 | 89 | /* if multi-part image, we need to get first subimage */ |
83088afb | 90 | image_multi_getimg(hdr, 0, &os_data, &os_len); |
0d0ba59c SG |
91 | data = (void *)os_data; |
92 | len = os_len; | |
d5934ad7 MB |
93 | } else { |
94 | /* otherwise get image data */ | |
0d0ba59c SG |
95 | data = (void *)image_get_data(hdr); |
96 | len = image_get_data_size(hdr); | |
d5934ad7 | 97 | } |
0d0ba59c | 98 | is_zimage = 1; |
d5934ad7 | 99 | #if defined(CONFIG_FIT) |
0d0ba59c | 100 | } else if (images->fit_uname_os && is_zimage) { |
83088afb | 101 | ret = fit_image_get_data(images->fit_hdr_os, |
0d0ba59c SG |
102 | images->fit_noffset_os, |
103 | (const void **)&data, &len); | |
cd7c596e | 104 | if (ret) { |
83088afb | 105 | puts("Can't get image data/size!\n"); |
cd7c596e MB |
106 | goto error; |
107 | } | |
0d0ba59c | 108 | is_zimage = 1; |
d5934ad7 | 109 | #endif |
e644670b WD |
110 | } |
111 | ||
0d0ba59c | 112 | if (is_zimage) { |
76539383 | 113 | ulong load_address; |
0d0ba59c | 114 | char *base_ptr; |
2262cfee | 115 | |
0d0ba59c | 116 | base_ptr = (char *)load_zimage(data, len, &load_address); |
76539383 | 117 | images->os.load = load_address; |
0d0ba59c SG |
118 | cmd_line_dest = base_ptr + COMMAND_LINE_OFFSET; |
119 | images->ep = (ulong)base_ptr; | |
120 | } else if (images->ep) { | |
121 | cmd_line_dest = (void *)images->ep + COMMAND_LINE_OFFSET; | |
122 | } else { | |
123 | printf("## Kernel loading failed (no setup) ...\n"); | |
cd7c596e | 124 | goto error; |
69370d14 | 125 | } |
8bde7f77 | 126 | |
0d0ba59c SG |
127 | printf("Setup at %#08lx\n", images->ep); |
128 | ret = setup_zimage((void *)images->ep, cmd_line_dest, | |
69370d14 | 129 | 0, images->rd_start, |
0d0ba59c SG |
130 | images->rd_end - images->rd_start); |
131 | ||
132 | if (ret) { | |
69370d14 | 133 | printf("## Setting up boot parameters failed ...\n"); |
0d0ba59c | 134 | return 1; |
2262cfee | 135 | } |
8bde7f77 | 136 | |
0d0ba59c | 137 | return 0; |
2262cfee | 138 | |
cd7c596e | 139 | error: |
40d7e99d | 140 | return 1; |
8bde7f77 | 141 | } |
0d0ba59c | 142 | |
76539383 SG |
143 | int boot_linux_kernel(ulong setup_base, ulong load_address, bool image_64bit) |
144 | { | |
145 | bootm_announce_and_cleanup(); | |
146 | ||
147 | #ifdef CONFIG_SYS_COREBOOT | |
148 | timestamp_add_now(TS_U_BOOT_START_KERNEL); | |
149 | #endif | |
150 | if (image_64bit) { | |
151 | /* TODO(boot 64-bit kernel) */ | |
152 | } else { | |
153 | /* | |
154 | * Set %ebx, %ebp, and %edi to 0, %esi to point to the | |
155 | * boot_params structure, and then jump to the kernel. We | |
156 | * assume that %cs is 0x10, 4GB flat, and read/execute, and | |
157 | * the data segments are 0x18, 4GB flat, and read/write. | |
158 | * U-boot is setting them up that way for itself in | |
159 | * arch/i386/cpu/cpu.c. | |
160 | */ | |
161 | __asm__ __volatile__ ( | |
162 | "movl $0, %%ebp\n" | |
163 | "cli\n" | |
164 | "jmp *%[kernel_entry]\n" | |
165 | :: [kernel_entry]"a"(load_address), | |
166 | [boot_params] "S"(setup_base), | |
167 | "b"(0), "D"(0) | |
168 | ); | |
169 | } | |
170 | ||
171 | /* We can't get to here */ | |
172 | return -EFAULT; | |
173 | } | |
174 | ||
0d0ba59c SG |
175 | /* Subcommand: GO */ |
176 | static int boot_jump_linux(bootm_headers_t *images) | |
177 | { | |
178 | debug("## Transferring control to Linux (at address %08lx, kernel %08lx) ...\n", | |
179 | images->ep, images->os.load); | |
180 | ||
76539383 | 181 | return boot_linux_kernel(images->ep, images->os.load, false); |
0d0ba59c SG |
182 | } |
183 | ||
184 | int do_bootm_linux(int flag, int argc, char * const argv[], | |
185 | bootm_headers_t *images) | |
186 | { | |
187 | /* No need for those on x86 */ | |
188 | if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE) | |
189 | return -1; | |
190 | ||
191 | if (flag & BOOTM_STATE_OS_PREP) | |
192 | return boot_prep_linux(images); | |
193 | ||
76539383 SG |
194 | if (flag & BOOTM_STATE_OS_GO) |
195 | return boot_jump_linux(images); | |
0d0ba59c SG |
196 | |
197 | return boot_jump_linux(images); | |
198 | } |