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