Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 2 | /* |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 3 | * Copyright (c) 2011 The Chromium OS Authors. |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 4 | * (C) Copyright 2002 |
Albert ARIBAUD | fa82f87 | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 5 | * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 8 | /* |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 9 | * Linux x86 zImage and bzImage loading |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 10 | * |
| 11 | * based on the procdure described in |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 12 | * linux/Documentation/i386/boot.txt |
| 13 | */ |
| 14 | |
| 15 | #include <common.h> |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 16 | #include <command.h> |
Simon Glass | cdbff9f | 2019-08-01 09:46:50 -0600 | [diff] [blame] | 17 | #include <env.h> |
Simon Glass | 36bf446 | 2019-11-14 12:57:42 -0700 | [diff] [blame] | 18 | #include <irq_func.h> |
Ivan Gorinov | 5d73292 | 2018-03-26 18:06:54 -0700 | [diff] [blame] | 19 | #include <malloc.h> |
Simon Glass | 776cc20 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 20 | #include <acpi/acpi_table.h> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 21 | #include <asm/io.h> |
| 22 | #include <asm/ptrace.h> |
| 23 | #include <asm/zimage.h> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 24 | #include <asm/byteorder.h> |
Simon Glass | 0d0ba59 | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 25 | #include <asm/bootm.h> |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 26 | #include <asm/bootparam.h> |
Vadim Bendebury | 3cdc18a | 2012-10-23 18:04:34 +0000 | [diff] [blame] | 27 | #ifdef CONFIG_SYS_COREBOOT |
| 28 | #include <asm/arch/timestamp.h> |
| 29 | #endif |
Stefan Reinauer | 61e0ea9 | 2012-10-23 18:04:37 +0000 | [diff] [blame] | 30 | #include <linux/compiler.h> |
Ivan Gorinov | 5d73292 | 2018-03-26 18:06:54 -0700 | [diff] [blame] | 31 | #include <linux/libfdt.h> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * Memory lay-out: |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 35 | * |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 36 | * relative to setup_base (which is 0x90000 currently) |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 37 | * |
| 38 | * 0x0000-0x7FFF Real mode kernel |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 39 | * 0x8000-0x8FFF Stack and heap |
| 40 | * 0x9000-0x90FF Kernel command line |
| 41 | */ |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 42 | #define DEFAULT_SETUP_BASE 0x90000 |
| 43 | #define COMMAND_LINE_OFFSET 0x9000 |
| 44 | #define HEAP_END_OFFSET 0x8e00 |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 45 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 46 | #define COMMAND_LINE_SIZE 2048 |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 47 | |
Simon Glass | e814837 | 2020-09-05 14:50:38 -0600 | [diff] [blame^] | 48 | /** |
| 49 | * struct zboot_state - Current state of the boot |
| 50 | * |
| 51 | * @bzimage_addr: Address of the bzImage to boot |
| 52 | * @bzimage_size: Size of the bzImage, or 0 to detect this |
| 53 | * @initrd_addr: Address of the initial ramdisk, or 0 if none |
| 54 | * @initrd_size: Size of the initial ramdisk, or 0 if none |
| 55 | * @load_address: Address where the bzImage is moved before booting, either |
| 56 | * BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR |
| 57 | */ |
| 58 | struct zboot_state { |
| 59 | ulong bzimage_addr; |
| 60 | ulong bzimage_size; |
| 61 | ulong initrd_addr; |
| 62 | ulong initrd_size; |
| 63 | ulong load_address; |
| 64 | } state; |
| 65 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 66 | static void build_command_line(char *command_line, int auto_boot) |
| 67 | { |
| 68 | char *env_command_line; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 69 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 70 | command_line[0] = '\0'; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 71 | |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 72 | env_command_line = env_get("bootargs"); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 73 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 74 | /* set console= argument if we use a serial console */ |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 75 | if (!strstr(env_command_line, "console=")) { |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 76 | if (!strcmp(env_get("stdout"), "serial")) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 77 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 78 | /* We seem to use serial console */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 79 | sprintf(command_line, "console=ttyS0,%s ", |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 80 | env_get("baudrate")); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 81 | } |
| 82 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 83 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 84 | if (auto_boot) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 85 | strcat(command_line, "auto "); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 86 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 87 | if (env_command_line) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 88 | strcat(command_line, env_command_line); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 89 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 90 | printf("Kernel command line: \"%s\"\n", command_line); |
| 91 | } |
| 92 | |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 93 | static int kernel_magic_ok(struct setup_header *hdr) |
| 94 | { |
| 95 | if (KERNEL_MAGIC != hdr->boot_flag) { |
| 96 | printf("Error: Invalid Boot Flag " |
| 97 | "(found 0x%04x, expected 0x%04x)\n", |
| 98 | hdr->boot_flag, KERNEL_MAGIC); |
| 99 | return 0; |
| 100 | } else { |
| 101 | printf("Valid Boot Flag\n"); |
| 102 | return 1; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | static int get_boot_protocol(struct setup_header *hdr) |
| 107 | { |
| 108 | if (hdr->header == KERNEL_V2_MAGIC) { |
| 109 | printf("Magic signature found\n"); |
| 110 | return hdr->version; |
| 111 | } else { |
| 112 | /* Very old kernel */ |
| 113 | printf("Magic signature not found\n"); |
| 114 | return 0x0100; |
| 115 | } |
| 116 | } |
| 117 | |
Ivan Gorinov | 5d73292 | 2018-03-26 18:06:54 -0700 | [diff] [blame] | 118 | static int setup_device_tree(struct setup_header *hdr, const void *fdt_blob) |
| 119 | { |
| 120 | int bootproto = get_boot_protocol(hdr); |
| 121 | struct setup_data *sd; |
| 122 | int size; |
| 123 | |
| 124 | if (bootproto < 0x0209) |
| 125 | return -ENOTSUPP; |
| 126 | |
| 127 | if (!fdt_blob) |
| 128 | return 0; |
| 129 | |
| 130 | size = fdt_totalsize(fdt_blob); |
| 131 | if (size < 0) |
| 132 | return -EINVAL; |
| 133 | |
| 134 | size += sizeof(struct setup_data); |
| 135 | sd = (struct setup_data *)malloc(size); |
| 136 | if (!sd) { |
| 137 | printf("Not enough memory for DTB setup data\n"); |
| 138 | return -ENOMEM; |
| 139 | } |
| 140 | |
| 141 | sd->next = hdr->setup_data; |
| 142 | sd->type = SETUP_DTB; |
| 143 | sd->len = fdt_totalsize(fdt_blob); |
| 144 | memcpy(sd->data, fdt_blob, sd->len); |
| 145 | hdr->setup_data = (unsigned long)sd; |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 150 | struct boot_params *load_zimage(char *image, unsigned long kernel_size, |
Simon Glass | 7653938 | 2014-10-10 08:21:56 -0600 | [diff] [blame] | 151 | ulong *load_addressp) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 152 | { |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 153 | struct boot_params *setup_base; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 154 | int setup_size; |
| 155 | int bootproto; |
| 156 | int big_image; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 157 | |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 158 | struct boot_params *params = (struct boot_params *)image; |
| 159 | struct setup_header *hdr = ¶ms->hdr; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 160 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 161 | /* base address for real-mode segment */ |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 162 | setup_base = (struct boot_params *)DEFAULT_SETUP_BASE; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 163 | |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 164 | if (!kernel_magic_ok(hdr)) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 165 | return 0; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 166 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 167 | /* determine size of setup */ |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 168 | if (0 == hdr->setup_sects) { |
| 169 | printf("Setup Sectors = 0 (defaulting to 4)\n"); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 170 | setup_size = 5 * 512; |
| 171 | } else { |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 172 | setup_size = (hdr->setup_sects + 1) * 512; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 173 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 174 | |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 175 | printf("Setup Size = 0x%8.8lx\n", (ulong)setup_size); |
| 176 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 177 | if (setup_size > SETUP_MAX_SIZE) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 178 | printf("Error: Setup is too large (%d bytes)\n", setup_size); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 179 | |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 180 | /* determine boot protocol version */ |
| 181 | bootproto = get_boot_protocol(hdr); |
| 182 | |
| 183 | printf("Using boot protocol version %x.%02x\n", |
| 184 | (bootproto & 0xff00) >> 8, bootproto & 0xff); |
| 185 | |
| 186 | if (bootproto >= 0x0200) { |
| 187 | if (hdr->setup_sects >= 15) { |
| 188 | printf("Linux kernel version %s\n", |
| 189 | (char *)params + |
| 190 | hdr->kernel_version + 0x200); |
| 191 | } else { |
| 192 | printf("Setup Sectors < 15 - " |
| 193 | "Cannot print kernel version.\n"); |
| 194 | } |
| 195 | } |
| 196 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 197 | /* Determine image type */ |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 198 | big_image = (bootproto >= 0x0200) && |
| 199 | (hdr->loadflags & BIG_KERNEL_FLAG); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 200 | |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 201 | /* Determine load address */ |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 202 | if (big_image) |
Simon Glass | 7653938 | 2014-10-10 08:21:56 -0600 | [diff] [blame] | 203 | *load_addressp = BZIMAGE_LOAD_ADDR; |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 204 | else |
Simon Glass | 7653938 | 2014-10-10 08:21:56 -0600 | [diff] [blame] | 205 | *load_addressp = ZIMAGE_LOAD_ADDR; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 206 | |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 207 | printf("Building boot_params at 0x%8.8lx\n", (ulong)setup_base); |
| 208 | memset(setup_base, 0, sizeof(*setup_base)); |
| 209 | setup_base->hdr = params->hdr; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 210 | |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 211 | if (bootproto >= 0x0204) |
| 212 | kernel_size = hdr->syssize * 16; |
| 213 | else |
| 214 | kernel_size -= setup_size; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 215 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 216 | if (bootproto == 0x0100) { |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 217 | /* |
| 218 | * A very old kernel MUST have its real-mode code |
| 219 | * loaded at 0x90000 |
| 220 | */ |
Simon Glass | 42fd8c1 | 2017-01-16 07:03:35 -0700 | [diff] [blame] | 221 | if ((ulong)setup_base != 0x90000) { |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 222 | /* Copy the real-mode kernel */ |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 223 | memmove((void *)0x90000, setup_base, setup_size); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 224 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 225 | /* Copy the command line */ |
| 226 | memmove((void *)0x99000, |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 227 | (u8 *)setup_base + COMMAND_LINE_OFFSET, |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 228 | COMMAND_LINE_SIZE); |
| 229 | |
| 230 | /* Relocated */ |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 231 | setup_base = (struct boot_params *)0x90000; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 232 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 233 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 234 | /* It is recommended to clear memory up to the 32K mark */ |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 235 | memset((u8 *)0x90000 + setup_size, 0, |
| 236 | SETUP_MAX_SIZE - setup_size); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 237 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 238 | |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 239 | if (big_image) { |
| 240 | if (kernel_size > BZIMAGE_MAX_SIZE) { |
| 241 | printf("Error: bzImage kernel too big! " |
| 242 | "(size: %ld, max: %d)\n", |
| 243 | kernel_size, BZIMAGE_MAX_SIZE); |
| 244 | return 0; |
| 245 | } |
| 246 | } else if ((kernel_size) > ZIMAGE_MAX_SIZE) { |
| 247 | printf("Error: zImage kernel too big! (size: %ld, max: %d)\n", |
| 248 | kernel_size, ZIMAGE_MAX_SIZE); |
| 249 | return 0; |
| 250 | } |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 251 | |
Simon Glass | 7653938 | 2014-10-10 08:21:56 -0600 | [diff] [blame] | 252 | printf("Loading %s at address %lx (%ld bytes)\n", |
| 253 | big_image ? "bzImage" : "zImage", *load_addressp, kernel_size); |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 254 | |
Simon Glass | 7653938 | 2014-10-10 08:21:56 -0600 | [diff] [blame] | 255 | memmove((void *)*load_addressp, image + setup_size, kernel_size); |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 256 | |
| 257 | return setup_base; |
| 258 | } |
| 259 | |
| 260 | int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot, |
| 261 | unsigned long initrd_addr, unsigned long initrd_size) |
| 262 | { |
| 263 | struct setup_header *hdr = &setup_base->hdr; |
| 264 | int bootproto = get_boot_protocol(hdr); |
| 265 | |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 266 | setup_base->e820_entries = install_e820_map( |
| 267 | ARRAY_SIZE(setup_base->e820_map), setup_base->e820_map); |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 268 | |
| 269 | if (bootproto == 0x0100) { |
| 270 | setup_base->screen_info.cl_magic = COMMAND_LINE_MAGIC; |
| 271 | setup_base->screen_info.cl_offset = COMMAND_LINE_OFFSET; |
| 272 | } |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 273 | if (bootproto >= 0x0200) { |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 274 | hdr->type_of_loader = 8; |
| 275 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 276 | if (initrd_addr) { |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 277 | printf("Initial RAM disk at linear address " |
| 278 | "0x%08lx, size %ld bytes\n", |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 279 | initrd_addr, initrd_size); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 280 | |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 281 | hdr->ramdisk_image = initrd_addr; |
| 282 | hdr->ramdisk_size = initrd_size; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 283 | } |
| 284 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 285 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 286 | if (bootproto >= 0x0201) { |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 287 | hdr->heap_end_ptr = HEAP_END_OFFSET; |
| 288 | hdr->loadflags |= HEAP_FLAG; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 289 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 290 | |
Simon Glass | 97d1e0c | 2014-10-19 21:11:21 -0600 | [diff] [blame] | 291 | if (cmd_line) { |
| 292 | if (bootproto >= 0x0202) { |
| 293 | hdr->cmd_line_ptr = (uintptr_t)cmd_line; |
| 294 | } else if (bootproto >= 0x0200) { |
| 295 | setup_base->screen_info.cl_magic = COMMAND_LINE_MAGIC; |
| 296 | setup_base->screen_info.cl_offset = |
| 297 | (uintptr_t)cmd_line - (uintptr_t)setup_base; |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 298 | |
Simon Glass | 97d1e0c | 2014-10-19 21:11:21 -0600 | [diff] [blame] | 299 | hdr->setup_move_size = 0x9100; |
| 300 | } |
| 301 | |
| 302 | /* build command line at COMMAND_LINE_OFFSET */ |
| 303 | build_command_line(cmd_line, auto_boot); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 304 | } |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 305 | |
Andy Shevchenko | 378960d | 2018-01-10 19:40:14 +0200 | [diff] [blame] | 306 | #ifdef CONFIG_INTEL_MID |
| 307 | if (bootproto >= 0x0207) |
| 308 | hdr->hardware_subarch = X86_SUBARCH_INTEL_MID; |
| 309 | #endif |
| 310 | |
Andy Shevchenko | d905aa8 | 2019-09-13 18:42:00 +0300 | [diff] [blame] | 311 | #ifdef CONFIG_GENERATE_ACPI_TABLE |
| 312 | setup_base->acpi_rsdp_addr = acpi_get_rsdp_addr(); |
| 313 | #endif |
| 314 | |
Ivan Gorinov | 5d73292 | 2018-03-26 18:06:54 -0700 | [diff] [blame] | 315 | setup_device_tree(hdr, (const void *)env_get_hex("fdtaddr", 0)); |
Bin Meng | a452002 | 2015-07-06 16:31:36 +0800 | [diff] [blame] | 316 | setup_video(&setup_base->screen_info); |
| 317 | |
Bin Meng | 1fdeacd | 2018-08-23 08:24:10 -0700 | [diff] [blame] | 318 | #ifdef CONFIG_EFI_STUB |
| 319 | setup_efi_info(&setup_base->efi_info); |
| 320 | #endif |
| 321 | |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 322 | return 0; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 325 | int do_zboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 326 | { |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 327 | struct boot_params *base_ptr; |
Graeme Russ | abe98f4 | 2010-10-07 20:03:19 +1100 | [diff] [blame] | 328 | char *s; |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 329 | |
| 330 | disable_interrupts(); |
Simon Glass | e814837 | 2020-09-05 14:50:38 -0600 | [diff] [blame^] | 331 | memset(&state, '\0', sizeof(state)); |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 332 | if (argc >= 2) { |
Graeme Russ | abe98f4 | 2010-10-07 20:03:19 +1100 | [diff] [blame] | 333 | /* argv[1] holds the address of the bzImage */ |
| 334 | s = argv[1]; |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 335 | } else { |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 336 | s = env_get("fileaddr"); |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 337 | } |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 338 | |
Graeme Russ | abe98f4 | 2010-10-07 20:03:19 +1100 | [diff] [blame] | 339 | if (s) |
Simon Glass | e814837 | 2020-09-05 14:50:38 -0600 | [diff] [blame^] | 340 | state.bzimage_addr = simple_strtoul(s, NULL, 16); |
Graeme Russ | abe98f4 | 2010-10-07 20:03:19 +1100 | [diff] [blame] | 341 | |
Gabe Black | 6f9d998 | 2011-12-05 12:09:27 +0000 | [diff] [blame] | 342 | if (argc >= 3) { |
Graeme Russ | abe98f4 | 2010-10-07 20:03:19 +1100 | [diff] [blame] | 343 | /* argv[2] holds the size of the bzImage */ |
Simon Glass | e814837 | 2020-09-05 14:50:38 -0600 | [diff] [blame^] | 344 | state.bzimage_size = simple_strtoul(argv[2], NULL, 16); |
Gabe Black | 6f9d998 | 2011-12-05 12:09:27 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | if (argc >= 4) |
Simon Glass | e814837 | 2020-09-05 14:50:38 -0600 | [diff] [blame^] | 348 | state.initrd_addr = simple_strtoul(argv[3], NULL, 16); |
Gabe Black | 6f9d998 | 2011-12-05 12:09:27 +0000 | [diff] [blame] | 349 | if (argc >= 5) |
Simon Glass | e814837 | 2020-09-05 14:50:38 -0600 | [diff] [blame^] | 350 | state.initrd_size = simple_strtoul(argv[4], NULL, 16); |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 351 | |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 352 | /* Lets look for */ |
Simon Glass | e814837 | 2020-09-05 14:50:38 -0600 | [diff] [blame^] | 353 | base_ptr = load_zimage((void *)state.bzimage_addr, state.bzimage_size, |
| 354 | &state.load_address); |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 355 | if (!base_ptr) { |
Simon Glass | 2c363cb | 2014-10-10 08:21:59 -0600 | [diff] [blame] | 356 | puts("## Kernel loading failed ...\n"); |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 357 | return -1; |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 358 | } |
Simon Glass | e814837 | 2020-09-05 14:50:38 -0600 | [diff] [blame^] | 359 | |
| 360 | if (setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET, 0, |
| 361 | state.initrd_addr, state.initrd_size)) { |
Simon Glass | 2c363cb | 2014-10-10 08:21:59 -0600 | [diff] [blame] | 362 | puts("Setting up boot parameters failed ...\n"); |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 363 | return -1; |
| 364 | } |
| 365 | |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 366 | /* we assume that the kernel is in place */ |
Simon Glass | e814837 | 2020-09-05 14:50:38 -0600 | [diff] [blame^] | 367 | return boot_linux_kernel((ulong)base_ptr, state.load_address, false); |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | U_BOOT_CMD( |
Gabe Black | 6f9d998 | 2011-12-05 12:09:27 +0000 | [diff] [blame] | 371 | zboot, 5, 0, do_zboot, |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 372 | "Boot bzImage", |
Gabe Black | 6f9d998 | 2011-12-05 12:09:27 +0000 | [diff] [blame] | 373 | "[addr] [size] [initrd addr] [initrd size]\n" |
| 374 | " addr - The optional starting address of the bzimage.\n" |
| 375 | " If not set it defaults to the environment\n" |
| 376 | " variable \"fileaddr\".\n" |
| 377 | " size - The optional size of the bzimage. Defaults to\n" |
| 378 | " zero.\n" |
| 379 | " initrd addr - The address of the initrd image to use, if any.\n" |
| 380 | " initrd size - The size of the initrd image to use, if any.\n" |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 381 | ); |