Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 2 | /* |
Gabe Black | 1cf5121 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 3 | * Copyright (c) 2011 The Chromium OS Authors. |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 4 | * (C) Copyright 2002 |
Albert ARIBAUD | 60fbc8d | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 5 | * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 8 | /* |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 9 | * Linux x86 zImage and bzImage loading |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 10 | * |
| 11 | * based on the procdure described in |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 12 | * linux/Documentation/i386/boot.txt |
| 13 | */ |
| 14 | |
Simon Glass | 842ff44 | 2020-11-04 09:59:13 -0700 | [diff] [blame] | 15 | #define LOG_CATEGORY LOGC_BOOT |
| 16 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 17 | #include <common.h> |
Simon Glass | 7b48ce8 | 2020-11-05 10:33:46 -0700 | [diff] [blame] | 18 | #include <bootm.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 19 | #include <command.h> |
Simon Glass | 83c2e49 | 2019-08-01 09:46:50 -0600 | [diff] [blame] | 20 | #include <env.h> |
Simon Glass | 02c5120 | 2021-03-15 18:00:23 +1300 | [diff] [blame] | 21 | #include <init.h> |
Simon Glass | 8f3f761 | 2019-11-14 12:57:42 -0700 | [diff] [blame] | 22 | #include <irq_func.h> |
Simon Glass | 842ff44 | 2020-11-04 09:59:13 -0700 | [diff] [blame] | 23 | #include <log.h> |
Ivan Gorinov | 901bb0b | 2018-03-26 18:06:54 -0700 | [diff] [blame] | 24 | #include <malloc.h> |
Simon Glass | 858fed1 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 25 | #include <acpi/acpi_table.h> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 26 | #include <asm/io.h> |
| 27 | #include <asm/ptrace.h> |
| 28 | #include <asm/zimage.h> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 29 | #include <asm/byteorder.h> |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 30 | #include <asm/bootm.h> |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 31 | #include <asm/bootparam.h> |
Simon Glass | b73d48f | 2021-09-24 18:30:20 -0600 | [diff] [blame] | 32 | #include <asm/efi.h> |
Simon Glass | 02c5120 | 2021-03-15 18:00:23 +1300 | [diff] [blame] | 33 | #include <asm/global_data.h> |
Vadim Bendebury | 8cd22c8 | 2012-10-23 18:04:34 +0000 | [diff] [blame] | 34 | #ifdef CONFIG_SYS_COREBOOT |
| 35 | #include <asm/arch/timestamp.h> |
| 36 | #endif |
Stefan Reinauer | 2e5225e | 2012-10-23 18:04:37 +0000 | [diff] [blame] | 37 | #include <linux/compiler.h> |
Simon Glass | 8ee2854 | 2020-11-04 09:59:14 -0700 | [diff] [blame] | 38 | #include <linux/ctype.h> |
Ivan Gorinov | 901bb0b | 2018-03-26 18:06:54 -0700 | [diff] [blame] | 39 | #include <linux/libfdt.h> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 40 | |
Simon Glass | 02c5120 | 2021-03-15 18:00:23 +1300 | [diff] [blame] | 41 | DECLARE_GLOBAL_DATA_PTR; |
| 42 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 43 | /* |
| 44 | * Memory lay-out: |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 45 | * |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 46 | * relative to setup_base (which is 0x90000 currently) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 47 | * |
| 48 | * 0x0000-0x7FFF Real mode kernel |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 49 | * 0x8000-0x8FFF Stack and heap |
| 50 | * 0x9000-0x90FF Kernel command line |
| 51 | */ |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 52 | #define DEFAULT_SETUP_BASE 0x90000 |
| 53 | #define COMMAND_LINE_OFFSET 0x9000 |
| 54 | #define HEAP_END_OFFSET 0x8e00 |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 55 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 56 | #define COMMAND_LINE_SIZE 2048 |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 57 | |
Simon Glass | 48800f4 | 2020-09-05 14:50:38 -0600 | [diff] [blame] | 58 | /** |
| 59 | * struct zboot_state - Current state of the boot |
| 60 | * |
| 61 | * @bzimage_addr: Address of the bzImage to boot |
| 62 | * @bzimage_size: Size of the bzImage, or 0 to detect this |
| 63 | * @initrd_addr: Address of the initial ramdisk, or 0 if none |
| 64 | * @initrd_size: Size of the initial ramdisk, or 0 if none |
| 65 | * @load_address: Address where the bzImage is moved before booting, either |
| 66 | * BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR |
Simon Glass | 1931b19 | 2020-09-05 14:50:44 -0600 | [diff] [blame] | 67 | * @base_ptr: Pointer to the boot parameters, typically at address |
| 68 | * DEFAULT_SETUP_BASE |
Simon Glass | 5e956d1 | 2020-11-09 07:12:24 -0700 | [diff] [blame] | 69 | * @cmdline: Environment variable containing the 'override' command line, or |
| 70 | * NULL to use the one in the setup block |
Simon Glass | 48800f4 | 2020-09-05 14:50:38 -0600 | [diff] [blame] | 71 | */ |
| 72 | struct zboot_state { |
| 73 | ulong bzimage_addr; |
| 74 | ulong bzimage_size; |
| 75 | ulong initrd_addr; |
| 76 | ulong initrd_size; |
| 77 | ulong load_address; |
Simon Glass | 1931b19 | 2020-09-05 14:50:44 -0600 | [diff] [blame] | 78 | struct boot_params *base_ptr; |
Simon Glass | 5e956d1 | 2020-11-09 07:12:24 -0700 | [diff] [blame] | 79 | char *cmdline; |
Simon Glass | 48800f4 | 2020-09-05 14:50:38 -0600 | [diff] [blame] | 80 | } state; |
| 81 | |
Simon Glass | d9b3c98 | 2020-09-05 14:50:43 -0600 | [diff] [blame] | 82 | enum { |
| 83 | ZBOOT_STATE_START = BIT(0), |
Simon Glass | 24d26f7 | 2020-09-05 14:50:46 -0600 | [diff] [blame] | 84 | ZBOOT_STATE_LOAD = BIT(1), |
Simon Glass | 3063483 | 2020-09-05 14:50:47 -0600 | [diff] [blame] | 85 | ZBOOT_STATE_SETUP = BIT(2), |
| 86 | ZBOOT_STATE_INFO = BIT(3), |
| 87 | ZBOOT_STATE_GO = BIT(4), |
Simon Glass | d9b3c98 | 2020-09-05 14:50:43 -0600 | [diff] [blame] | 88 | |
Simon Glass | aad0d76 | 2020-09-05 14:50:50 -0600 | [diff] [blame] | 89 | /* This one doesn't execute automatically, so stop the count before 5 */ |
| 90 | ZBOOT_STATE_DUMP = BIT(5), |
Simon Glass | 3063483 | 2020-09-05 14:50:47 -0600 | [diff] [blame] | 91 | ZBOOT_STATE_COUNT = 5, |
Simon Glass | d9b3c98 | 2020-09-05 14:50:43 -0600 | [diff] [blame] | 92 | }; |
| 93 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 94 | static void build_command_line(char *command_line, int auto_boot) |
| 95 | { |
| 96 | char *env_command_line; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 97 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 98 | command_line[0] = '\0'; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 99 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 100 | env_command_line = env_get("bootargs"); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 101 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 102 | /* set console= argument if we use a serial console */ |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 103 | if (!strstr(env_command_line, "console=")) { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 104 | if (!strcmp(env_get("stdout"), "serial")) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 105 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 106 | /* We seem to use serial console */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 107 | sprintf(command_line, "console=ttyS0,%s ", |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 108 | env_get("baudrate")); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 109 | } |
| 110 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 111 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 112 | if (auto_boot) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 113 | strcat(command_line, "auto "); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 114 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 115 | if (env_command_line) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 116 | strcat(command_line, env_command_line); |
Simon Glass | eeb0122 | 2021-01-24 10:06:09 -0700 | [diff] [blame] | 117 | #ifdef DEBUG |
| 118 | printf("Kernel command line:"); |
| 119 | puts(command_line); |
| 120 | printf("\n"); |
| 121 | #endif |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 124 | static int kernel_magic_ok(struct setup_header *hdr) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 125 | { |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 126 | if (KERNEL_MAGIC != hdr->boot_flag) { |
Gabe Black | 1cf5121 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 127 | printf("Error: Invalid Boot Flag " |
| 128 | "(found 0x%04x, expected 0x%04x)\n", |
| 129 | hdr->boot_flag, KERNEL_MAGIC); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 130 | return 0; |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 131 | } else { |
| 132 | printf("Valid Boot Flag\n"); |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 133 | return 1; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 134 | } |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 135 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 136 | |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 137 | static int get_boot_protocol(struct setup_header *hdr, bool verbose) |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 138 | { |
| 139 | if (hdr->header == KERNEL_V2_MAGIC) { |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 140 | if (verbose) |
| 141 | printf("Magic signature found\n"); |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 142 | return hdr->version; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 143 | } else { |
| 144 | /* Very old kernel */ |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 145 | if (verbose) |
| 146 | printf("Magic signature not found\n"); |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 147 | return 0x0100; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 148 | } |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Ivan Gorinov | 901bb0b | 2018-03-26 18:06:54 -0700 | [diff] [blame] | 151 | static int setup_device_tree(struct setup_header *hdr, const void *fdt_blob) |
| 152 | { |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 153 | int bootproto = get_boot_protocol(hdr, false); |
Ivan Gorinov | 901bb0b | 2018-03-26 18:06:54 -0700 | [diff] [blame] | 154 | struct setup_data *sd; |
| 155 | int size; |
| 156 | |
| 157 | if (bootproto < 0x0209) |
| 158 | return -ENOTSUPP; |
| 159 | |
| 160 | if (!fdt_blob) |
| 161 | return 0; |
| 162 | |
| 163 | size = fdt_totalsize(fdt_blob); |
| 164 | if (size < 0) |
| 165 | return -EINVAL; |
| 166 | |
| 167 | size += sizeof(struct setup_data); |
| 168 | sd = (struct setup_data *)malloc(size); |
| 169 | if (!sd) { |
| 170 | printf("Not enough memory for DTB setup data\n"); |
| 171 | return -ENOMEM; |
| 172 | } |
| 173 | |
| 174 | sd->next = hdr->setup_data; |
| 175 | sd->type = SETUP_DTB; |
| 176 | sd->len = fdt_totalsize(fdt_blob); |
| 177 | memcpy(sd->data, fdt_blob, sd->len); |
| 178 | hdr->setup_data = (unsigned long)sd; |
| 179 | |
| 180 | return 0; |
| 181 | } |
| 182 | |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 183 | static const char *get_kernel_version(struct boot_params *params, |
| 184 | void *kernel_base) |
| 185 | { |
| 186 | struct setup_header *hdr = ¶ms->hdr; |
| 187 | int bootproto; |
Simon Glass | 8ee2854 | 2020-11-04 09:59:14 -0700 | [diff] [blame] | 188 | const char *s, *end; |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 189 | |
| 190 | bootproto = get_boot_protocol(hdr, false); |
| 191 | if (bootproto < 0x0200 || hdr->setup_sects < 15) |
| 192 | return NULL; |
| 193 | |
Simon Glass | 8ee2854 | 2020-11-04 09:59:14 -0700 | [diff] [blame] | 194 | /* sanity-check the kernel version in case it is missing */ |
| 195 | for (s = kernel_base + hdr->kernel_version + 0x200, end = s + 0x100; *s; |
| 196 | s++) { |
| 197 | if (!isprint(*s)) |
| 198 | return NULL; |
| 199 | } |
| 200 | |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 201 | return kernel_base + hdr->kernel_version + 0x200; |
| 202 | } |
| 203 | |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 204 | struct boot_params *load_zimage(char *image, unsigned long kernel_size, |
Simon Glass | d98a5bd | 2014-10-10 08:21:56 -0600 | [diff] [blame] | 205 | ulong *load_addressp) |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 206 | { |
| 207 | struct boot_params *setup_base; |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 208 | const char *version; |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 209 | int setup_size; |
| 210 | int bootproto; |
| 211 | int big_image; |
| 212 | |
| 213 | struct boot_params *params = (struct boot_params *)image; |
| 214 | struct setup_header *hdr = ¶ms->hdr; |
| 215 | |
| 216 | /* base address for real-mode segment */ |
| 217 | setup_base = (struct boot_params *)DEFAULT_SETUP_BASE; |
| 218 | |
| 219 | if (!kernel_magic_ok(hdr)) |
| 220 | return 0; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 221 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 222 | /* determine size of setup */ |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 223 | if (0 == hdr->setup_sects) { |
Simon Glass | 9d8ca9f | 2020-11-04 09:59:15 -0700 | [diff] [blame] | 224 | log_warning("Setup Sectors = 0 (defaulting to 4)\n"); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 225 | setup_size = 5 * 512; |
| 226 | } else { |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 227 | setup_size = (hdr->setup_sects + 1) * 512; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 228 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 229 | |
Simon Glass | 9d8ca9f | 2020-11-04 09:59:15 -0700 | [diff] [blame] | 230 | log_debug("Setup Size = 0x%8.8lx\n", (ulong)setup_size); |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 231 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 232 | if (setup_size > SETUP_MAX_SIZE) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 233 | printf("Error: Setup is too large (%d bytes)\n", setup_size); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 234 | |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 235 | /* determine boot protocol version */ |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 236 | bootproto = get_boot_protocol(hdr, true); |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 237 | |
Simon Glass | 9d8ca9f | 2020-11-04 09:59:15 -0700 | [diff] [blame] | 238 | log_debug("Using boot protocol version %x.%02x\n", |
| 239 | (bootproto & 0xff00) >> 8, bootproto & 0xff); |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 240 | |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 241 | version = get_kernel_version(params, image); |
| 242 | if (version) |
| 243 | printf("Linux kernel version %s\n", version); |
| 244 | else |
| 245 | printf("Setup Sectors < 15 - Cannot print kernel version\n"); |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 246 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 247 | /* Determine image type */ |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 248 | big_image = (bootproto >= 0x0200) && |
| 249 | (hdr->loadflags & BIG_KERNEL_FLAG); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 250 | |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 251 | /* Determine load address */ |
Gabe Black | 1cf5121 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 252 | if (big_image) |
Simon Glass | d98a5bd | 2014-10-10 08:21:56 -0600 | [diff] [blame] | 253 | *load_addressp = BZIMAGE_LOAD_ADDR; |
Gabe Black | 1cf5121 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 254 | else |
Simon Glass | d98a5bd | 2014-10-10 08:21:56 -0600 | [diff] [blame] | 255 | *load_addressp = ZIMAGE_LOAD_ADDR; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 256 | |
Gabe Black | c67a948 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 257 | printf("Building boot_params at 0x%8.8lx\n", (ulong)setup_base); |
| 258 | memset(setup_base, 0, sizeof(*setup_base)); |
| 259 | setup_base->hdr = params->hdr; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 260 | |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 261 | if (bootproto >= 0x0204) |
| 262 | kernel_size = hdr->syssize * 16; |
| 263 | else |
| 264 | kernel_size -= setup_size; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 265 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 266 | if (bootproto == 0x0100) { |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 267 | /* |
| 268 | * A very old kernel MUST have its real-mode code |
| 269 | * loaded at 0x90000 |
| 270 | */ |
Simon Glass | ca37a39 | 2017-01-16 07:03:35 -0700 | [diff] [blame] | 271 | if ((ulong)setup_base != 0x90000) { |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 272 | /* Copy the real-mode kernel */ |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 273 | memmove((void *)0x90000, setup_base, setup_size); |
| 274 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 275 | /* Copy the command line */ |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 276 | memmove((void *)0x99000, |
Gabe Black | 1cf5121 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 277 | (u8 *)setup_base + COMMAND_LINE_OFFSET, |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 278 | COMMAND_LINE_SIZE); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 279 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 280 | /* Relocated */ |
Gabe Black | 1cf5121 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 281 | setup_base = (struct boot_params *)0x90000; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 282 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 283 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 284 | /* It is recommended to clear memory up to the 32K mark */ |
Gabe Black | 1cf5121 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 285 | memset((u8 *)0x90000 + setup_size, 0, |
| 286 | SETUP_MAX_SIZE - setup_size); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 287 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 288 | |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 289 | if (big_image) { |
| 290 | if (kernel_size > BZIMAGE_MAX_SIZE) { |
| 291 | printf("Error: bzImage kernel too big! " |
| 292 | "(size: %ld, max: %d)\n", |
| 293 | kernel_size, BZIMAGE_MAX_SIZE); |
| 294 | return 0; |
| 295 | } |
| 296 | } else if ((kernel_size) > ZIMAGE_MAX_SIZE) { |
| 297 | printf("Error: zImage kernel too big! (size: %ld, max: %d)\n", |
| 298 | kernel_size, ZIMAGE_MAX_SIZE); |
| 299 | return 0; |
| 300 | } |
| 301 | |
Simon Glass | d98a5bd | 2014-10-10 08:21:56 -0600 | [diff] [blame] | 302 | printf("Loading %s at address %lx (%ld bytes)\n", |
| 303 | big_image ? "bzImage" : "zImage", *load_addressp, kernel_size); |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 304 | |
Simon Glass | d98a5bd | 2014-10-10 08:21:56 -0600 | [diff] [blame] | 305 | memmove((void *)*load_addressp, image + setup_size, kernel_size); |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 306 | |
| 307 | return setup_base; |
| 308 | } |
| 309 | |
| 310 | int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot, |
Simon Glass | 12d93ab | 2020-09-05 14:50:51 -0600 | [diff] [blame] | 311 | ulong initrd_addr, ulong initrd_size, ulong cmdline_force) |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 312 | { |
| 313 | struct setup_header *hdr = &setup_base->hdr; |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 314 | int bootproto = get_boot_protocol(hdr, false); |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 315 | |
Simon Glass | 842ff44 | 2020-11-04 09:59:13 -0700 | [diff] [blame] | 316 | log_debug("Setup E820 entries\n"); |
Simon Glass | 0de9c37 | 2021-07-10 21:15:21 -0600 | [diff] [blame] | 317 | if (IS_ENABLED(CONFIG_COREBOOT_SYSINFO)) { |
Simon Glass | 02c5120 | 2021-03-15 18:00:23 +1300 | [diff] [blame] | 318 | setup_base->e820_entries = cb_install_e820_map( |
| 319 | ARRAY_SIZE(setup_base->e820_map), setup_base->e820_map); |
Simon Glass | 0de9c37 | 2021-07-10 21:15:21 -0600 | [diff] [blame] | 320 | } else { |
| 321 | setup_base->e820_entries = install_e820_map( |
| 322 | ARRAY_SIZE(setup_base->e820_map), setup_base->e820_map); |
Simon Glass | 02c5120 | 2021-03-15 18:00:23 +1300 | [diff] [blame] | 323 | } |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 324 | |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 325 | if (bootproto == 0x0100) { |
| 326 | setup_base->screen_info.cl_magic = COMMAND_LINE_MAGIC; |
| 327 | setup_base->screen_info.cl_offset = COMMAND_LINE_OFFSET; |
| 328 | } |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 329 | if (bootproto >= 0x0200) { |
Simon Glass | d67ff03 | 2020-09-05 14:50:41 -0600 | [diff] [blame] | 330 | hdr->type_of_loader = 0x80; /* U-Boot version 0 */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 331 | if (initrd_addr) { |
Gabe Black | 1cf5121 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 332 | printf("Initial RAM disk at linear address " |
| 333 | "0x%08lx, size %ld bytes\n", |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 334 | initrd_addr, initrd_size); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 335 | |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 336 | hdr->ramdisk_image = initrd_addr; |
| 337 | hdr->ramdisk_size = initrd_size; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 338 | } |
| 339 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 340 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 341 | if (bootproto >= 0x0201) { |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 342 | hdr->heap_end_ptr = HEAP_END_OFFSET; |
| 343 | hdr->loadflags |= HEAP_FLAG; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 344 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 345 | |
Simon Glass | 4b4f273 | 2014-10-19 21:11:21 -0600 | [diff] [blame] | 346 | if (cmd_line) { |
Simon Glass | 7b48ce8 | 2020-11-05 10:33:46 -0700 | [diff] [blame] | 347 | int max_size = 0xff; |
| 348 | int ret; |
| 349 | |
Simon Glass | 842ff44 | 2020-11-04 09:59:13 -0700 | [diff] [blame] | 350 | log_debug("Setup cmdline\n"); |
Simon Glass | 7b48ce8 | 2020-11-05 10:33:46 -0700 | [diff] [blame] | 351 | if (bootproto >= 0x0206) |
| 352 | max_size = hdr->cmdline_size; |
Simon Glass | 4b4f273 | 2014-10-19 21:11:21 -0600 | [diff] [blame] | 353 | if (bootproto >= 0x0202) { |
| 354 | hdr->cmd_line_ptr = (uintptr_t)cmd_line; |
| 355 | } else if (bootproto >= 0x0200) { |
| 356 | setup_base->screen_info.cl_magic = COMMAND_LINE_MAGIC; |
| 357 | setup_base->screen_info.cl_offset = |
| 358 | (uintptr_t)cmd_line - (uintptr_t)setup_base; |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 359 | |
Simon Glass | 4b4f273 | 2014-10-19 21:11:21 -0600 | [diff] [blame] | 360 | hdr->setup_move_size = 0x9100; |
| 361 | } |
| 362 | |
| 363 | /* build command line at COMMAND_LINE_OFFSET */ |
Simon Glass | 12d93ab | 2020-09-05 14:50:51 -0600 | [diff] [blame] | 364 | if (cmdline_force) |
| 365 | strcpy(cmd_line, (char *)cmdline_force); |
| 366 | else |
| 367 | build_command_line(cmd_line, auto_boot); |
Simon Glass | e750698 | 2021-12-29 11:57:39 -0700 | [diff] [blame] | 368 | if (IS_ENABLED(CONFIG_CMD_BOOTM)) { |
| 369 | ret = bootm_process_cmdline(cmd_line, max_size, |
| 370 | BOOTM_CL_ALL); |
| 371 | if (ret) { |
| 372 | printf("Cmdline setup failed (max_size=%x, bootproto=%x, err=%d)\n", |
| 373 | max_size, bootproto, ret); |
| 374 | return ret; |
| 375 | } |
Simon Glass | 7b48ce8 | 2020-11-05 10:33:46 -0700 | [diff] [blame] | 376 | } |
| 377 | printf("Kernel command line: \""); |
| 378 | puts(cmd_line); |
| 379 | printf("\"\n"); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 380 | } |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 381 | |
Simon Glass | 3a17717 | 2020-09-05 14:50:39 -0600 | [diff] [blame] | 382 | if (IS_ENABLED(CONFIG_INTEL_MID) && bootproto >= 0x0207) |
Andy Shevchenko | 8b7adf8 | 2018-01-10 19:40:14 +0200 | [diff] [blame] | 383 | hdr->hardware_subarch = X86_SUBARCH_INTEL_MID; |
Andy Shevchenko | 8b7adf8 | 2018-01-10 19:40:14 +0200 | [diff] [blame] | 384 | |
Simon Glass | 3a17717 | 2020-09-05 14:50:39 -0600 | [diff] [blame] | 385 | if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE)) |
| 386 | setup_base->acpi_rsdp_addr = acpi_get_rsdp_addr(); |
Andy Shevchenko | d87a21d | 2019-09-13 18:42:00 +0300 | [diff] [blame] | 387 | |
Simon Glass | 842ff44 | 2020-11-04 09:59:13 -0700 | [diff] [blame] | 388 | log_debug("Setup devicetree\n"); |
Ivan Gorinov | 901bb0b | 2018-03-26 18:06:54 -0700 | [diff] [blame] | 389 | setup_device_tree(hdr, (const void *)env_get_hex("fdtaddr", 0)); |
Bin Meng | f6d504f | 2015-07-06 16:31:36 +0800 | [diff] [blame] | 390 | setup_video(&setup_base->screen_info); |
| 391 | |
Simon Glass | 3a17717 | 2020-09-05 14:50:39 -0600 | [diff] [blame] | 392 | if (IS_ENABLED(CONFIG_EFI_STUB)) |
| 393 | setup_efi_info(&setup_base->efi_info); |
Bin Meng | 106dcfc | 2018-08-23 08:24:10 -0700 | [diff] [blame] | 394 | |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 395 | return 0; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 396 | } |
| 397 | |
Simon Glass | d9b3c98 | 2020-09-05 14:50:43 -0600 | [diff] [blame] | 398 | static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc, |
| 399 | char *const argv[]) |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 400 | { |
Simon Glass | d9b3c98 | 2020-09-05 14:50:43 -0600 | [diff] [blame] | 401 | const char *s; |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 402 | |
Simon Glass | 48800f4 | 2020-09-05 14:50:38 -0600 | [diff] [blame] | 403 | memset(&state, '\0', sizeof(state)); |
Gabe Black | 1cf5121 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 404 | if (argc >= 2) { |
Graeme Russ | 3134be2 | 2010-10-07 20:03:19 +1100 | [diff] [blame] | 405 | /* argv[1] holds the address of the bzImage */ |
| 406 | s = argv[1]; |
Gabe Black | 1cf5121 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 407 | } else { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 408 | s = env_get("fileaddr"); |
Gabe Black | 1cf5121 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 409 | } |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 410 | |
Graeme Russ | 3134be2 | 2010-10-07 20:03:19 +1100 | [diff] [blame] | 411 | if (s) |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 412 | state.bzimage_addr = hextoul(s, NULL); |
Graeme Russ | 3134be2 | 2010-10-07 20:03:19 +1100 | [diff] [blame] | 413 | |
Gabe Black | 69b49ee | 2011-12-05 12:09:27 +0000 | [diff] [blame] | 414 | if (argc >= 3) { |
Graeme Russ | 3134be2 | 2010-10-07 20:03:19 +1100 | [diff] [blame] | 415 | /* argv[2] holds the size of the bzImage */ |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 416 | state.bzimage_size = hextoul(argv[2], NULL); |
Gabe Black | 69b49ee | 2011-12-05 12:09:27 +0000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | if (argc >= 4) |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 420 | state.initrd_addr = hextoul(argv[3], NULL); |
Gabe Black | 69b49ee | 2011-12-05 12:09:27 +0000 | [diff] [blame] | 421 | if (argc >= 5) |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 422 | state.initrd_size = hextoul(argv[4], NULL); |
Simon Glass | c55ce68 | 2020-09-05 14:50:49 -0600 | [diff] [blame] | 423 | if (argc >= 6) { |
| 424 | /* |
| 425 | * When the base_ptr is passed in, we assume that the image is |
| 426 | * already loaded at the address given by argv[1] and therefore |
| 427 | * the original bzImage is somewhere else, or not accessible. |
| 428 | * In any case, we don't need access to the bzImage since all |
| 429 | * the processing is assumed to be done. |
| 430 | * |
| 431 | * So set the base_ptr to the given address, use this arg as the |
| 432 | * load address and set bzimage_addr to 0 so we know that it |
| 433 | * cannot be proceesed (or processed again). |
| 434 | */ |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 435 | state.base_ptr = (void *)hextoul(argv[5], NULL); |
Simon Glass | c55ce68 | 2020-09-05 14:50:49 -0600 | [diff] [blame] | 436 | state.load_address = state.bzimage_addr; |
| 437 | state.bzimage_addr = 0; |
| 438 | } |
Simon Glass | 12d93ab | 2020-09-05 14:50:51 -0600 | [diff] [blame] | 439 | if (argc >= 7) |
Simon Glass | 5e956d1 | 2020-11-09 07:12:24 -0700 | [diff] [blame] | 440 | state.cmdline = env_get(argv[6]); |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 441 | |
Simon Glass | 24d26f7 | 2020-09-05 14:50:46 -0600 | [diff] [blame] | 442 | return 0; |
| 443 | } |
| 444 | |
| 445 | static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, int argc, |
| 446 | char *const argv[]) |
| 447 | { |
| 448 | struct boot_params *base_ptr; |
| 449 | |
Simon Glass | c55ce68 | 2020-09-05 14:50:49 -0600 | [diff] [blame] | 450 | if (state.base_ptr) { |
| 451 | struct boot_params *from = (struct boot_params *)state.base_ptr; |
| 452 | |
| 453 | base_ptr = (struct boot_params *)DEFAULT_SETUP_BASE; |
Simon Glass | 9d8ca9f | 2020-11-04 09:59:15 -0700 | [diff] [blame] | 454 | log_debug("Building boot_params at 0x%8.8lx\n", |
| 455 | (ulong)base_ptr); |
Simon Glass | c55ce68 | 2020-09-05 14:50:49 -0600 | [diff] [blame] | 456 | memset(base_ptr, '\0', sizeof(*base_ptr)); |
| 457 | base_ptr->hdr = from->hdr; |
| 458 | } else { |
| 459 | base_ptr = load_zimage((void *)state.bzimage_addr, state.bzimage_size, |
| 460 | &state.load_address); |
| 461 | if (!base_ptr) { |
| 462 | puts("## Kernel loading failed ...\n"); |
| 463 | return CMD_RET_FAILURE; |
| 464 | } |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 465 | } |
Simon Glass | 1931b19 | 2020-09-05 14:50:44 -0600 | [diff] [blame] | 466 | state.base_ptr = base_ptr; |
Simon Glass | 58a9046 | 2020-09-05 14:50:48 -0600 | [diff] [blame] | 467 | if (env_set_hex("zbootbase", (ulong)base_ptr) || |
| 468 | env_set_hex("zbootaddr", state.load_address)) |
| 469 | return CMD_RET_FAILURE; |
Simon Glass | 48800f4 | 2020-09-05 14:50:38 -0600 | [diff] [blame] | 470 | |
Simon Glass | 3063483 | 2020-09-05 14:50:47 -0600 | [diff] [blame] | 471 | return 0; |
| 472 | } |
| 473 | |
| 474 | static int do_zboot_setup(struct cmd_tbl *cmdtp, int flag, int argc, |
| 475 | char *const argv[]) |
| 476 | { |
| 477 | struct boot_params *base_ptr = state.base_ptr; |
| 478 | int ret; |
| 479 | |
| 480 | if (!base_ptr) { |
| 481 | printf("base is not set: use 'zboot load' first\n"); |
| 482 | return CMD_RET_FAILURE; |
| 483 | } |
| 484 | ret = setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET, |
Simon Glass | 12d93ab | 2020-09-05 14:50:51 -0600 | [diff] [blame] | 485 | 0, state.initrd_addr, state.initrd_size, |
Simon Glass | 5e956d1 | 2020-11-09 07:12:24 -0700 | [diff] [blame] | 486 | (ulong)state.cmdline); |
Simon Glass | 3063483 | 2020-09-05 14:50:47 -0600 | [diff] [blame] | 487 | if (ret) { |
Simon Glass | ddf446b | 2014-10-10 08:21:59 -0600 | [diff] [blame] | 488 | puts("Setting up boot parameters failed ...\n"); |
Simon Glass | 3063483 | 2020-09-05 14:50:47 -0600 | [diff] [blame] | 489 | return CMD_RET_FAILURE; |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 490 | } |
| 491 | |
Simon Glass | 1931b19 | 2020-09-05 14:50:44 -0600 | [diff] [blame] | 492 | return 0; |
| 493 | } |
| 494 | |
Simon Glass | 83dd29e | 2020-09-05 14:50:45 -0600 | [diff] [blame] | 495 | static int do_zboot_info(struct cmd_tbl *cmdtp, int flag, int argc, |
| 496 | char *const argv[]) |
| 497 | { |
| 498 | printf("Kernel loaded at %08lx, setup_base=%p\n", |
| 499 | state.load_address, state.base_ptr); |
| 500 | |
| 501 | return 0; |
| 502 | } |
| 503 | |
Simon Glass | 1931b19 | 2020-09-05 14:50:44 -0600 | [diff] [blame] | 504 | static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int argc, |
| 505 | char *const argv[]) |
| 506 | { |
| 507 | int ret; |
| 508 | |
Simon Glass | 0db800c | 2020-09-05 14:50:42 -0600 | [diff] [blame] | 509 | disable_interrupts(); |
Simon Glass | 1931b19 | 2020-09-05 14:50:44 -0600 | [diff] [blame] | 510 | |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 511 | /* we assume that the kernel is in place */ |
Simon Glass | 1931b19 | 2020-09-05 14:50:44 -0600 | [diff] [blame] | 512 | ret = boot_linux_kernel((ulong)state.base_ptr, state.load_address, |
| 513 | false); |
| 514 | printf("Kernel returned! (err=%d)\n", ret); |
| 515 | |
| 516 | return CMD_RET_FAILURE; |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 517 | } |
| 518 | |
Simon Glass | aad0d76 | 2020-09-05 14:50:50 -0600 | [diff] [blame] | 519 | static void print_num(const char *name, ulong value) |
| 520 | { |
| 521 | printf("%-20s: %lx\n", name, value); |
| 522 | } |
| 523 | |
| 524 | static void print_num64(const char *name, u64 value) |
| 525 | { |
| 526 | printf("%-20s: %llx\n", name, value); |
| 527 | } |
| 528 | |
| 529 | static const char *const e820_type_name[E820_COUNT] = { |
| 530 | [E820_RAM] = "RAM", |
| 531 | [E820_RESERVED] = "Reserved", |
| 532 | [E820_ACPI] = "ACPI", |
| 533 | [E820_NVS] = "ACPI NVS", |
| 534 | [E820_UNUSABLE] = "Unusable", |
| 535 | }; |
| 536 | |
| 537 | static const char *const bootloader_id[] = { |
| 538 | "LILO", |
| 539 | "Loadlin", |
| 540 | "bootsect-loader", |
| 541 | "Syslinux", |
| 542 | "Etherboot/gPXE/iPXE", |
| 543 | "ELILO", |
| 544 | "undefined", |
| 545 | "GRUB", |
| 546 | "U-Boot", |
| 547 | "Xen", |
| 548 | "Gujin", |
| 549 | "Qemu", |
| 550 | "Arcturus Networks uCbootloader", |
| 551 | "kexec-tools", |
| 552 | "Extended", |
| 553 | "Special", |
| 554 | "Reserved", |
| 555 | "Minimal Linux Bootloader", |
| 556 | "OVMF UEFI virtualization stack", |
| 557 | }; |
| 558 | |
| 559 | struct flag_info { |
| 560 | uint bit; |
| 561 | const char *name; |
| 562 | }; |
| 563 | |
| 564 | static struct flag_info load_flags[] = { |
| 565 | { LOADED_HIGH, "loaded-high" }, |
| 566 | { QUIET_FLAG, "quiet" }, |
| 567 | { KEEP_SEGMENTS, "keep-segments" }, |
| 568 | { CAN_USE_HEAP, "can-use-heap" }, |
| 569 | }; |
| 570 | |
| 571 | static struct flag_info xload_flags[] = { |
| 572 | { XLF_KERNEL_64, "64-bit-entry" }, |
| 573 | { XLF_CAN_BE_LOADED_ABOVE_4G, "can-load-above-4gb" }, |
| 574 | { XLF_EFI_HANDOVER_32, "32-efi-handoff" }, |
| 575 | { XLF_EFI_HANDOVER_64, "64-efi-handoff" }, |
| 576 | { XLF_EFI_KEXEC, "kexec-efi-runtime" }, |
| 577 | }; |
| 578 | |
| 579 | static void print_flags(struct flag_info *flags, int count, uint value) |
| 580 | { |
| 581 | int i; |
| 582 | |
| 583 | printf("%-20s:", ""); |
| 584 | for (i = 0; i < count; i++) { |
| 585 | uint mask = flags[i].bit; |
| 586 | |
| 587 | if (value & mask) |
| 588 | printf(" %s", flags[i].name); |
| 589 | } |
| 590 | printf("\n"); |
| 591 | } |
| 592 | |
| 593 | static void show_loader(struct setup_header *hdr) |
| 594 | { |
| 595 | bool version_valid = false; |
| 596 | int type, version; |
| 597 | const char *name; |
| 598 | |
| 599 | type = hdr->type_of_loader >> 4; |
| 600 | version = hdr->type_of_loader & 0xf; |
| 601 | if (type == 0xe) |
| 602 | type = 0x10 + hdr->ext_loader_type; |
| 603 | version |= hdr->ext_loader_ver << 4; |
| 604 | if (!hdr->type_of_loader) { |
| 605 | name = "pre-2.00 bootloader"; |
| 606 | } else if (hdr->type_of_loader == 0xff) { |
| 607 | name = "unknown"; |
| 608 | } else if (type < ARRAY_SIZE(bootloader_id)) { |
| 609 | name = bootloader_id[type]; |
| 610 | version_valid = true; |
| 611 | } else { |
| 612 | name = "undefined"; |
| 613 | } |
| 614 | printf("%20s %s", "", name); |
| 615 | if (version_valid) |
| 616 | printf(", version %x", version); |
| 617 | printf("\n"); |
| 618 | } |
| 619 | |
Simon Glass | ba094bb | 2021-01-24 10:06:08 -0700 | [diff] [blame] | 620 | void zimage_dump(struct boot_params *base_ptr) |
Simon Glass | aad0d76 | 2020-09-05 14:50:50 -0600 | [diff] [blame] | 621 | { |
Simon Glass | aad0d76 | 2020-09-05 14:50:50 -0600 | [diff] [blame] | 622 | struct setup_header *hdr; |
| 623 | const char *version; |
| 624 | int i; |
| 625 | |
Simon Glass | aad0d76 | 2020-09-05 14:50:50 -0600 | [diff] [blame] | 626 | printf("Setup located at %p:\n\n", base_ptr); |
| 627 | print_num64("ACPI RSDP addr", base_ptr->acpi_rsdp_addr); |
| 628 | |
| 629 | printf("E820: %d entries\n", base_ptr->e820_entries); |
| 630 | if (base_ptr->e820_entries) { |
| 631 | printf("%18s %16s %s\n", "Addr", "Size", "Type"); |
| 632 | for (i = 0; i < base_ptr->e820_entries; i++) { |
| 633 | struct e820_entry *entry = &base_ptr->e820_map[i]; |
| 634 | |
| 635 | printf("%12llx %10llx %s\n", entry->addr, entry->size, |
| 636 | entry->type < E820_COUNT ? |
| 637 | e820_type_name[entry->type] : |
| 638 | simple_itoa(entry->type)); |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | hdr = &base_ptr->hdr; |
| 643 | print_num("Setup sectors", hdr->setup_sects); |
| 644 | print_num("Root flags", hdr->root_flags); |
| 645 | print_num("Sys size", hdr->syssize); |
| 646 | print_num("RAM size", hdr->ram_size); |
| 647 | print_num("Video mode", hdr->vid_mode); |
| 648 | print_num("Root dev", hdr->root_dev); |
| 649 | print_num("Boot flag", hdr->boot_flag); |
| 650 | print_num("Jump", hdr->jump); |
| 651 | print_num("Header", hdr->header); |
| 652 | if (hdr->header == KERNEL_V2_MAGIC) |
| 653 | printf("%-20s %s\n", "", "Kernel V2"); |
| 654 | else |
| 655 | printf("%-20s %s\n", "", "Ancient kernel, using version 100"); |
| 656 | print_num("Version", hdr->version); |
| 657 | print_num("Real mode switch", hdr->realmode_swtch); |
| 658 | print_num("Start sys", hdr->start_sys); |
| 659 | print_num("Kernel version", hdr->kernel_version); |
| 660 | version = get_kernel_version(base_ptr, (void *)state.bzimage_addr); |
| 661 | if (version) |
| 662 | printf(" @%p: %s\n", version, version); |
| 663 | print_num("Type of loader", hdr->type_of_loader); |
| 664 | show_loader(hdr); |
| 665 | print_num("Load flags", hdr->loadflags); |
| 666 | print_flags(load_flags, ARRAY_SIZE(load_flags), hdr->loadflags); |
| 667 | print_num("Setup move size", hdr->setup_move_size); |
| 668 | print_num("Code32 start", hdr->code32_start); |
| 669 | print_num("Ramdisk image", hdr->ramdisk_image); |
| 670 | print_num("Ramdisk size", hdr->ramdisk_size); |
| 671 | print_num("Bootsect kludge", hdr->bootsect_kludge); |
| 672 | print_num("Heap end ptr", hdr->heap_end_ptr); |
| 673 | print_num("Ext loader ver", hdr->ext_loader_ver); |
| 674 | print_num("Ext loader type", hdr->ext_loader_type); |
| 675 | print_num("Command line ptr", hdr->cmd_line_ptr); |
| 676 | if (hdr->cmd_line_ptr) { |
| 677 | printf(" "); |
| 678 | /* Use puts() to avoid limits from CONFIG_SYS_PBSIZE */ |
Simon Glass | 12d93ab | 2020-09-05 14:50:51 -0600 | [diff] [blame] | 679 | puts((char *)(ulong)hdr->cmd_line_ptr); |
Simon Glass | aad0d76 | 2020-09-05 14:50:50 -0600 | [diff] [blame] | 680 | printf("\n"); |
| 681 | } |
| 682 | print_num("Initrd addr max", hdr->initrd_addr_max); |
| 683 | print_num("Kernel alignment", hdr->kernel_alignment); |
| 684 | print_num("Relocatable kernel", hdr->relocatable_kernel); |
| 685 | print_num("Min alignment", hdr->min_alignment); |
| 686 | if (hdr->min_alignment) |
| 687 | printf("%-20s: %x\n", "", 1 << hdr->min_alignment); |
| 688 | print_num("Xload flags", hdr->xloadflags); |
| 689 | print_flags(xload_flags, ARRAY_SIZE(xload_flags), hdr->xloadflags); |
| 690 | print_num("Cmdline size", hdr->cmdline_size); |
| 691 | print_num("Hardware subarch", hdr->hardware_subarch); |
| 692 | print_num64("HW subarch data", hdr->hardware_subarch_data); |
| 693 | print_num("Payload offset", hdr->payload_offset); |
| 694 | print_num("Payload length", hdr->payload_length); |
| 695 | print_num64("Setup data", hdr->setup_data); |
| 696 | print_num64("Pref address", hdr->pref_address); |
| 697 | print_num("Init size", hdr->init_size); |
| 698 | print_num("Handover offset", hdr->handover_offset); |
| 699 | if (get_boot_protocol(hdr, false) >= 0x215) |
| 700 | print_num("Kernel info offset", hdr->kernel_info_offset); |
Simon Glass | ba094bb | 2021-01-24 10:06:08 -0700 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | static int do_zboot_dump(struct cmd_tbl *cmdtp, int flag, int argc, |
| 704 | char *const argv[]) |
| 705 | { |
| 706 | struct boot_params *base_ptr = state.base_ptr; |
| 707 | |
| 708 | if (argc > 1) |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 709 | base_ptr = (void *)hextoul(argv[1], NULL); |
Simon Glass | ba094bb | 2021-01-24 10:06:08 -0700 | [diff] [blame] | 710 | if (!base_ptr) { |
| 711 | printf("No zboot setup_base\n"); |
| 712 | return CMD_RET_FAILURE; |
| 713 | } |
| 714 | zimage_dump(base_ptr); |
Simon Glass | aad0d76 | 2020-09-05 14:50:50 -0600 | [diff] [blame] | 715 | |
| 716 | return 0; |
| 717 | } |
| 718 | |
Simon Glass | d9b3c98 | 2020-09-05 14:50:43 -0600 | [diff] [blame] | 719 | /* Note: This defines the complete_zboot() function */ |
| 720 | U_BOOT_SUBCMDS(zboot, |
Simon Glass | 12d93ab | 2020-09-05 14:50:51 -0600 | [diff] [blame] | 721 | U_BOOT_CMD_MKENT(start, 8, 1, do_zboot_start, "", ""), |
Simon Glass | 24d26f7 | 2020-09-05 14:50:46 -0600 | [diff] [blame] | 722 | U_BOOT_CMD_MKENT(load, 1, 1, do_zboot_load, "", ""), |
Simon Glass | 3063483 | 2020-09-05 14:50:47 -0600 | [diff] [blame] | 723 | U_BOOT_CMD_MKENT(setup, 1, 1, do_zboot_setup, "", ""), |
Simon Glass | 83dd29e | 2020-09-05 14:50:45 -0600 | [diff] [blame] | 724 | U_BOOT_CMD_MKENT(info, 1, 1, do_zboot_info, "", ""), |
Simon Glass | 1931b19 | 2020-09-05 14:50:44 -0600 | [diff] [blame] | 725 | U_BOOT_CMD_MKENT(go, 1, 1, do_zboot_go, "", ""), |
Simon Glass | aad0d76 | 2020-09-05 14:50:50 -0600 | [diff] [blame] | 726 | U_BOOT_CMD_MKENT(dump, 2, 1, do_zboot_dump, "", ""), |
Simon Glass | d9b3c98 | 2020-09-05 14:50:43 -0600 | [diff] [blame] | 727 | ) |
| 728 | |
| 729 | int do_zboot_states(struct cmd_tbl *cmdtp, int flag, int argc, |
| 730 | char *const argv[], int state_mask) |
| 731 | { |
| 732 | int i; |
| 733 | |
| 734 | for (i = 0; i < ZBOOT_STATE_COUNT; i++) { |
| 735 | struct cmd_tbl *cmd = &zboot_subcmds[i]; |
| 736 | int mask = 1 << i; |
| 737 | int ret; |
| 738 | |
| 739 | if (mask & state_mask) { |
| 740 | ret = cmd->cmd(cmd, flag, argc, argv); |
| 741 | if (ret) |
| 742 | return ret; |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | return 0; |
| 747 | } |
| 748 | |
| 749 | int do_zboot_parent(struct cmd_tbl *cmdtp, int flag, int argc, |
| 750 | char *const argv[], int *repeatable) |
| 751 | { |
| 752 | /* determine if we have a sub command */ |
| 753 | if (argc > 1) { |
| 754 | char *endp; |
| 755 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 756 | hextoul(argv[1], &endp); |
Simon Glass | d9b3c98 | 2020-09-05 14:50:43 -0600 | [diff] [blame] | 757 | /* |
| 758 | * endp pointing to nul means that argv[1] was just a valid |
| 759 | * number, so pass it along to the normal processing |
| 760 | */ |
| 761 | if (*endp) |
| 762 | return do_zboot(cmdtp, flag, argc, argv, repeatable); |
| 763 | } |
| 764 | |
Simon Glass | 1931b19 | 2020-09-05 14:50:44 -0600 | [diff] [blame] | 765 | do_zboot_states(cmdtp, flag, argc, argv, ZBOOT_STATE_START | |
Simon Glass | 3063483 | 2020-09-05 14:50:47 -0600 | [diff] [blame] | 766 | ZBOOT_STATE_LOAD | ZBOOT_STATE_SETUP | |
| 767 | ZBOOT_STATE_INFO | ZBOOT_STATE_GO); |
Simon Glass | d9b3c98 | 2020-09-05 14:50:43 -0600 | [diff] [blame] | 768 | |
| 769 | return CMD_RET_FAILURE; |
| 770 | } |
| 771 | |
| 772 | U_BOOT_CMDREP_COMPLETE( |
Simon Glass | 12d93ab | 2020-09-05 14:50:51 -0600 | [diff] [blame] | 773 | zboot, 8, do_zboot_parent, "Boot bzImage", |
| 774 | "[addr] [size] [initrd addr] [initrd size] [setup] [cmdline]\n" |
Gabe Black | 69b49ee | 2011-12-05 12:09:27 +0000 | [diff] [blame] | 775 | " addr - The optional starting address of the bzimage.\n" |
| 776 | " If not set it defaults to the environment\n" |
| 777 | " variable \"fileaddr\".\n" |
| 778 | " size - The optional size of the bzimage. Defaults to\n" |
| 779 | " zero.\n" |
| 780 | " initrd addr - The address of the initrd image to use, if any.\n" |
| 781 | " initrd size - The size of the initrd image to use, if any.\n" |
Simon Glass | c55ce68 | 2020-09-05 14:50:49 -0600 | [diff] [blame] | 782 | " setup - The address of the kernel setup region, if this\n" |
| 783 | " is not at addr\n" |
Simon Glass | 5e956d1 | 2020-11-09 07:12:24 -0700 | [diff] [blame] | 784 | " cmdline - Environment variable containing the kernel\n" |
| 785 | " command line, to override U-Boot's normal\n" |
| 786 | " cmdline generation\n" |
Simon Glass | d9b3c98 | 2020-09-05 14:50:43 -0600 | [diff] [blame] | 787 | "\n" |
| 788 | "Sub-commands to do part of the zboot sequence:\n" |
Simon Glass | 1931b19 | 2020-09-05 14:50:44 -0600 | [diff] [blame] | 789 | "\tstart [addr [arg ...]] - specify arguments\n" |
Simon Glass | 24d26f7 | 2020-09-05 14:50:46 -0600 | [diff] [blame] | 790 | "\tload - load OS image\n" |
Simon Glass | 3063483 | 2020-09-05 14:50:47 -0600 | [diff] [blame] | 791 | "\tsetup - set up table\n" |
Simon Glass | 83dd29e | 2020-09-05 14:50:45 -0600 | [diff] [blame] | 792 | "\tinfo - show summary info\n" |
Simon Glass | aad0d76 | 2020-09-05 14:50:50 -0600 | [diff] [blame] | 793 | "\tgo - start OS\n" |
| 794 | "\tdump [addr] - dump info (optional address of boot params)", |
Simon Glass | d9b3c98 | 2020-09-05 14:50:43 -0600 | [diff] [blame] | 795 | complete_zboot |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 796 | ); |