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