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 | 84305a1 | 2023-07-12 09:04:43 -0600 | [diff] [blame] | 25 | #include <mapmem.h> |
Simon Glass | 858fed1 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 26 | #include <acpi/acpi_table.h> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 27 | #include <asm/io.h> |
| 28 | #include <asm/ptrace.h> |
| 29 | #include <asm/zimage.h> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 30 | #include <asm/byteorder.h> |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 31 | #include <asm/bootm.h> |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 32 | #include <asm/bootparam.h> |
Simon Glass | b73d48f | 2021-09-24 18:30:20 -0600 | [diff] [blame] | 33 | #include <asm/efi.h> |
Simon Glass | 02c5120 | 2021-03-15 18:00:23 +1300 | [diff] [blame] | 34 | #include <asm/global_data.h> |
Vadim Bendebury | 8cd22c8 | 2012-10-23 18:04:34 +0000 | [diff] [blame] | 35 | #ifdef CONFIG_SYS_COREBOOT |
| 36 | #include <asm/arch/timestamp.h> |
| 37 | #endif |
Stefan Reinauer | 2e5225e | 2012-10-23 18:04:37 +0000 | [diff] [blame] | 38 | #include <linux/compiler.h> |
Simon Glass | 8ee2854 | 2020-11-04 09:59:14 -0700 | [diff] [blame] | 39 | #include <linux/ctype.h> |
Ivan Gorinov | 901bb0b | 2018-03-26 18:06:54 -0700 | [diff] [blame] | 40 | #include <linux/libfdt.h> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 41 | |
Simon Glass | 02c5120 | 2021-03-15 18:00:23 +1300 | [diff] [blame] | 42 | DECLARE_GLOBAL_DATA_PTR; |
| 43 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 44 | /* |
| 45 | * Memory lay-out: |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 46 | * |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 47 | * relative to setup_base (which is 0x90000 currently) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 48 | * |
| 49 | * 0x0000-0x7FFF Real mode kernel |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 50 | * 0x8000-0x8FFF Stack and heap |
| 51 | * 0x9000-0x90FF Kernel command line |
| 52 | */ |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 53 | #define DEFAULT_SETUP_BASE 0x90000 |
| 54 | #define COMMAND_LINE_OFFSET 0x9000 |
| 55 | #define HEAP_END_OFFSET 0x8e00 |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 56 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 57 | #define COMMAND_LINE_SIZE 2048 |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 58 | |
Simon Glass | 2bf90bd | 2023-12-03 17:29:27 -0700 | [diff] [blame] | 59 | /* Current state of the boot */ |
Simon Glass | bf4af11 | 2023-12-03 17:29:26 -0700 | [diff] [blame] | 60 | struct zboot_state state; |
Simon Glass | d9b3c98 | 2020-09-05 14:50:43 -0600 | [diff] [blame] | 61 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 62 | static void build_command_line(char *command_line, int auto_boot) |
| 63 | { |
| 64 | char *env_command_line; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 65 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 66 | command_line[0] = '\0'; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 67 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 68 | env_command_line = env_get("bootargs"); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 69 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 70 | /* set console= argument if we use a serial console */ |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 71 | if (!strstr(env_command_line, "console=")) { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 72 | if (!strcmp(env_get("stdout"), "serial")) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 73 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 74 | /* We seem to use serial console */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 75 | sprintf(command_line, "console=ttyS0,%s ", |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 76 | env_get("baudrate")); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 77 | } |
| 78 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 79 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 80 | if (auto_boot) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 81 | strcat(command_line, "auto "); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 82 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 83 | if (env_command_line) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 84 | strcat(command_line, env_command_line); |
Simon Glass | eeb0122 | 2021-01-24 10:06:09 -0700 | [diff] [blame] | 85 | #ifdef DEBUG |
| 86 | printf("Kernel command line:"); |
| 87 | puts(command_line); |
| 88 | printf("\n"); |
| 89 | #endif |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 92 | static int kernel_magic_ok(struct setup_header *hdr) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 93 | { |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 94 | if (KERNEL_MAGIC != hdr->boot_flag) { |
Gabe Black | 1cf5121 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 95 | printf("Error: Invalid Boot Flag " |
| 96 | "(found 0x%04x, expected 0x%04x)\n", |
| 97 | hdr->boot_flag, KERNEL_MAGIC); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 98 | return 0; |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 99 | } else { |
| 100 | printf("Valid Boot Flag\n"); |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 101 | return 1; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 102 | } |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 103 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 104 | |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 105 | static int get_boot_protocol(struct setup_header *hdr, bool verbose) |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 106 | { |
| 107 | if (hdr->header == KERNEL_V2_MAGIC) { |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 108 | if (verbose) |
| 109 | printf("Magic signature found\n"); |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 110 | return hdr->version; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 111 | } else { |
| 112 | /* Very old kernel */ |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 113 | if (verbose) |
| 114 | printf("Magic signature not found\n"); |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 115 | return 0x0100; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 116 | } |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Ivan Gorinov | 901bb0b | 2018-03-26 18:06:54 -0700 | [diff] [blame] | 119 | static int setup_device_tree(struct setup_header *hdr, const void *fdt_blob) |
| 120 | { |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 121 | int bootproto = get_boot_protocol(hdr, false); |
Ivan Gorinov | 901bb0b | 2018-03-26 18:06:54 -0700 | [diff] [blame] | 122 | struct setup_data *sd; |
| 123 | int size; |
| 124 | |
| 125 | if (bootproto < 0x0209) |
| 126 | return -ENOTSUPP; |
| 127 | |
| 128 | if (!fdt_blob) |
| 129 | return 0; |
| 130 | |
| 131 | size = fdt_totalsize(fdt_blob); |
| 132 | if (size < 0) |
| 133 | return -EINVAL; |
| 134 | |
| 135 | size += sizeof(struct setup_data); |
| 136 | sd = (struct setup_data *)malloc(size); |
| 137 | if (!sd) { |
| 138 | printf("Not enough memory for DTB setup data\n"); |
| 139 | return -ENOMEM; |
| 140 | } |
| 141 | |
| 142 | sd->next = hdr->setup_data; |
| 143 | sd->type = SETUP_DTB; |
| 144 | sd->len = fdt_totalsize(fdt_blob); |
| 145 | memcpy(sd->data, fdt_blob, sd->len); |
| 146 | hdr->setup_data = (unsigned long)sd; |
| 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
Simon Glass | 531efde | 2023-07-12 09:04:44 -0600 | [diff] [blame] | 151 | const char *zimage_get_kernel_version(struct boot_params *params, |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 152 | void *kernel_base) |
| 153 | { |
| 154 | struct setup_header *hdr = ¶ms->hdr; |
| 155 | int bootproto; |
Simon Glass | 8ee2854 | 2020-11-04 09:59:14 -0700 | [diff] [blame] | 156 | const char *s, *end; |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 157 | |
| 158 | bootproto = get_boot_protocol(hdr, false); |
Simon Glass | 531efde | 2023-07-12 09:04:44 -0600 | [diff] [blame] | 159 | log_debug("bootproto %x, hdr->setup_sects %x\n", bootproto, |
| 160 | hdr->setup_sects); |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 161 | if (bootproto < 0x0200 || hdr->setup_sects < 15) |
| 162 | return NULL; |
| 163 | |
Simon Glass | 8ee2854 | 2020-11-04 09:59:14 -0700 | [diff] [blame] | 164 | /* sanity-check the kernel version in case it is missing */ |
Simon Glass | 531efde | 2023-07-12 09:04:44 -0600 | [diff] [blame] | 165 | log_debug("hdr->kernel_version %x, str at %p\n", hdr->kernel_version, |
| 166 | kernel_base + hdr->kernel_version + 0x200); |
Simon Glass | 8ee2854 | 2020-11-04 09:59:14 -0700 | [diff] [blame] | 167 | for (s = kernel_base + hdr->kernel_version + 0x200, end = s + 0x100; *s; |
| 168 | s++) { |
| 169 | if (!isprint(*s)) |
| 170 | return NULL; |
| 171 | } |
| 172 | |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 173 | return kernel_base + hdr->kernel_version + 0x200; |
| 174 | } |
| 175 | |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 176 | struct boot_params *load_zimage(char *image, unsigned long kernel_size, |
Simon Glass | d98a5bd | 2014-10-10 08:21:56 -0600 | [diff] [blame] | 177 | ulong *load_addressp) |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 178 | { |
| 179 | struct boot_params *setup_base; |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 180 | const char *version; |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 181 | int setup_size; |
| 182 | int bootproto; |
| 183 | int big_image; |
| 184 | |
| 185 | struct boot_params *params = (struct boot_params *)image; |
| 186 | struct setup_header *hdr = ¶ms->hdr; |
| 187 | |
| 188 | /* base address for real-mode segment */ |
| 189 | setup_base = (struct boot_params *)DEFAULT_SETUP_BASE; |
| 190 | |
| 191 | if (!kernel_magic_ok(hdr)) |
| 192 | return 0; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 193 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 194 | /* determine size of setup */ |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 195 | if (0 == hdr->setup_sects) { |
Simon Glass | 9d8ca9f | 2020-11-04 09:59:15 -0700 | [diff] [blame] | 196 | log_warning("Setup Sectors = 0 (defaulting to 4)\n"); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 197 | setup_size = 5 * 512; |
| 198 | } else { |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 199 | setup_size = (hdr->setup_sects + 1) * 512; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 200 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 201 | |
Simon Glass | 9d8ca9f | 2020-11-04 09:59:15 -0700 | [diff] [blame] | 202 | log_debug("Setup Size = 0x%8.8lx\n", (ulong)setup_size); |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 203 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 204 | if (setup_size > SETUP_MAX_SIZE) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 205 | printf("Error: Setup is too large (%d bytes)\n", setup_size); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 206 | |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 207 | /* determine boot protocol version */ |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 208 | bootproto = get_boot_protocol(hdr, true); |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 209 | |
Simon Glass | 9d8ca9f | 2020-11-04 09:59:15 -0700 | [diff] [blame] | 210 | log_debug("Using boot protocol version %x.%02x\n", |
| 211 | (bootproto & 0xff00) >> 8, bootproto & 0xff); |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 212 | |
Simon Glass | 531efde | 2023-07-12 09:04:44 -0600 | [diff] [blame] | 213 | version = zimage_get_kernel_version(params, image); |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 214 | if (version) |
| 215 | printf("Linux kernel version %s\n", version); |
| 216 | else |
| 217 | printf("Setup Sectors < 15 - Cannot print kernel version\n"); |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 218 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 219 | /* Determine image type */ |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 220 | big_image = (bootproto >= 0x0200) && |
| 221 | (hdr->loadflags & BIG_KERNEL_FLAG); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 222 | |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 223 | /* Determine load address */ |
Gabe Black | 1cf5121 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 224 | if (big_image) |
Simon Glass | d98a5bd | 2014-10-10 08:21:56 -0600 | [diff] [blame] | 225 | *load_addressp = BZIMAGE_LOAD_ADDR; |
Gabe Black | 1cf5121 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 226 | else |
Simon Glass | d98a5bd | 2014-10-10 08:21:56 -0600 | [diff] [blame] | 227 | *load_addressp = ZIMAGE_LOAD_ADDR; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 228 | |
Gabe Black | c67a948 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 229 | printf("Building boot_params at 0x%8.8lx\n", (ulong)setup_base); |
| 230 | memset(setup_base, 0, sizeof(*setup_base)); |
| 231 | setup_base->hdr = params->hdr; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 232 | |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 233 | if (bootproto >= 0x0204) |
| 234 | kernel_size = hdr->syssize * 16; |
| 235 | else |
| 236 | kernel_size -= setup_size; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 237 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 238 | if (bootproto == 0x0100) { |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 239 | /* |
| 240 | * A very old kernel MUST have its real-mode code |
| 241 | * loaded at 0x90000 |
| 242 | */ |
Simon Glass | ca37a39 | 2017-01-16 07:03:35 -0700 | [diff] [blame] | 243 | if ((ulong)setup_base != 0x90000) { |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 244 | /* Copy the real-mode kernel */ |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 245 | memmove((void *)0x90000, setup_base, setup_size); |
| 246 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 247 | /* Copy the command line */ |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 248 | memmove((void *)0x99000, |
Gabe Black | 1cf5121 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 249 | (u8 *)setup_base + COMMAND_LINE_OFFSET, |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 250 | COMMAND_LINE_SIZE); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 251 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 252 | /* Relocated */ |
Gabe Black | 1cf5121 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 253 | setup_base = (struct boot_params *)0x90000; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 254 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 255 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 256 | /* It is recommended to clear memory up to the 32K mark */ |
Gabe Black | 1cf5121 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 257 | memset((u8 *)0x90000 + setup_size, 0, |
| 258 | SETUP_MAX_SIZE - setup_size); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 259 | } |
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 (big_image) { |
| 262 | if (kernel_size > BZIMAGE_MAX_SIZE) { |
| 263 | printf("Error: bzImage kernel too big! " |
| 264 | "(size: %ld, max: %d)\n", |
| 265 | kernel_size, BZIMAGE_MAX_SIZE); |
| 266 | return 0; |
| 267 | } |
| 268 | } else if ((kernel_size) > ZIMAGE_MAX_SIZE) { |
| 269 | printf("Error: zImage kernel too big! (size: %ld, max: %d)\n", |
| 270 | kernel_size, ZIMAGE_MAX_SIZE); |
| 271 | return 0; |
| 272 | } |
| 273 | |
Simon Glass | d98a5bd | 2014-10-10 08:21:56 -0600 | [diff] [blame] | 274 | printf("Loading %s at address %lx (%ld bytes)\n", |
| 275 | big_image ? "bzImage" : "zImage", *load_addressp, kernel_size); |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 276 | |
Simon Glass | d98a5bd | 2014-10-10 08:21:56 -0600 | [diff] [blame] | 277 | memmove((void *)*load_addressp, image + setup_size, kernel_size); |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 278 | |
| 279 | return setup_base; |
| 280 | } |
| 281 | |
| 282 | 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] | 283 | ulong initrd_addr, ulong initrd_size, ulong cmdline_force) |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 284 | { |
| 285 | struct setup_header *hdr = &setup_base->hdr; |
Simon Glass | df30d41 | 2020-09-05 14:50:40 -0600 | [diff] [blame] | 286 | int bootproto = get_boot_protocol(hdr, false); |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 287 | |
Simon Glass | 842ff44 | 2020-11-04 09:59:13 -0700 | [diff] [blame] | 288 | log_debug("Setup E820 entries\n"); |
Simon Glass | 0de9c37 | 2021-07-10 21:15:21 -0600 | [diff] [blame] | 289 | if (IS_ENABLED(CONFIG_COREBOOT_SYSINFO)) { |
Simon Glass | 02c5120 | 2021-03-15 18:00:23 +1300 | [diff] [blame] | 290 | setup_base->e820_entries = cb_install_e820_map( |
| 291 | ARRAY_SIZE(setup_base->e820_map), setup_base->e820_map); |
Simon Glass | 0de9c37 | 2021-07-10 21:15:21 -0600 | [diff] [blame] | 292 | } else { |
| 293 | setup_base->e820_entries = install_e820_map( |
| 294 | ARRAY_SIZE(setup_base->e820_map), setup_base->e820_map); |
Simon Glass | 02c5120 | 2021-03-15 18:00:23 +1300 | [diff] [blame] | 295 | } |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 296 | |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 297 | if (bootproto == 0x0100) { |
| 298 | setup_base->screen_info.cl_magic = COMMAND_LINE_MAGIC; |
| 299 | setup_base->screen_info.cl_offset = COMMAND_LINE_OFFSET; |
| 300 | } |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 301 | if (bootproto >= 0x0200) { |
Simon Glass | d67ff03 | 2020-09-05 14:50:41 -0600 | [diff] [blame] | 302 | hdr->type_of_loader = 0x80; /* U-Boot version 0 */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 303 | if (initrd_addr) { |
Gabe Black | 1cf5121 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 304 | printf("Initial RAM disk at linear address " |
| 305 | "0x%08lx, size %ld bytes\n", |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 306 | initrd_addr, initrd_size); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 307 | |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 308 | hdr->ramdisk_image = initrd_addr; |
| 309 | hdr->ramdisk_size = initrd_size; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 310 | } |
| 311 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 312 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 313 | if (bootproto >= 0x0201) { |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 314 | hdr->heap_end_ptr = HEAP_END_OFFSET; |
| 315 | hdr->loadflags |= HEAP_FLAG; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 316 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 317 | |
Simon Glass | 4b4f273 | 2014-10-19 21:11:21 -0600 | [diff] [blame] | 318 | if (cmd_line) { |
Simon Glass | 7b48ce8 | 2020-11-05 10:33:46 -0700 | [diff] [blame] | 319 | int max_size = 0xff; |
| 320 | int ret; |
| 321 | |
Simon Glass | 842ff44 | 2020-11-04 09:59:13 -0700 | [diff] [blame] | 322 | log_debug("Setup cmdline\n"); |
Simon Glass | 7b48ce8 | 2020-11-05 10:33:46 -0700 | [diff] [blame] | 323 | if (bootproto >= 0x0206) |
| 324 | max_size = hdr->cmdline_size; |
Simon Glass | 4b4f273 | 2014-10-19 21:11:21 -0600 | [diff] [blame] | 325 | if (bootproto >= 0x0202) { |
| 326 | hdr->cmd_line_ptr = (uintptr_t)cmd_line; |
| 327 | } else if (bootproto >= 0x0200) { |
| 328 | setup_base->screen_info.cl_magic = COMMAND_LINE_MAGIC; |
| 329 | setup_base->screen_info.cl_offset = |
| 330 | (uintptr_t)cmd_line - (uintptr_t)setup_base; |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 331 | |
Simon Glass | 4b4f273 | 2014-10-19 21:11:21 -0600 | [diff] [blame] | 332 | hdr->setup_move_size = 0x9100; |
| 333 | } |
| 334 | |
| 335 | /* build command line at COMMAND_LINE_OFFSET */ |
Simon Glass | 12d93ab | 2020-09-05 14:50:51 -0600 | [diff] [blame] | 336 | if (cmdline_force) |
| 337 | strcpy(cmd_line, (char *)cmdline_force); |
| 338 | else |
| 339 | build_command_line(cmd_line, auto_boot); |
Simon Glass | e750698 | 2021-12-29 11:57:39 -0700 | [diff] [blame] | 340 | if (IS_ENABLED(CONFIG_CMD_BOOTM)) { |
| 341 | ret = bootm_process_cmdline(cmd_line, max_size, |
| 342 | BOOTM_CL_ALL); |
| 343 | if (ret) { |
| 344 | printf("Cmdline setup failed (max_size=%x, bootproto=%x, err=%d)\n", |
| 345 | max_size, bootproto, ret); |
| 346 | return ret; |
| 347 | } |
Simon Glass | 7b48ce8 | 2020-11-05 10:33:46 -0700 | [diff] [blame] | 348 | } |
| 349 | printf("Kernel command line: \""); |
| 350 | puts(cmd_line); |
| 351 | printf("\"\n"); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 352 | } |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 353 | |
Simon Glass | 3a17717 | 2020-09-05 14:50:39 -0600 | [diff] [blame] | 354 | if (IS_ENABLED(CONFIG_INTEL_MID) && bootproto >= 0x0207) |
Andy Shevchenko | 8b7adf8 | 2018-01-10 19:40:14 +0200 | [diff] [blame] | 355 | hdr->hardware_subarch = X86_SUBARCH_INTEL_MID; |
Andy Shevchenko | 8b7adf8 | 2018-01-10 19:40:14 +0200 | [diff] [blame] | 356 | |
Simon Glass | 3a17717 | 2020-09-05 14:50:39 -0600 | [diff] [blame] | 357 | if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE)) |
| 358 | setup_base->acpi_rsdp_addr = acpi_get_rsdp_addr(); |
Andy Shevchenko | d87a21d | 2019-09-13 18:42:00 +0300 | [diff] [blame] | 359 | |
Simon Glass | 842ff44 | 2020-11-04 09:59:13 -0700 | [diff] [blame] | 360 | log_debug("Setup devicetree\n"); |
Ivan Gorinov | 901bb0b | 2018-03-26 18:06:54 -0700 | [diff] [blame] | 361 | setup_device_tree(hdr, (const void *)env_get_hex("fdtaddr", 0)); |
Bin Meng | f6d504f | 2015-07-06 16:31:36 +0800 | [diff] [blame] | 362 | setup_video(&setup_base->screen_info); |
| 363 | |
Simon Glass | 3a17717 | 2020-09-05 14:50:39 -0600 | [diff] [blame] | 364 | if (IS_ENABLED(CONFIG_EFI_STUB)) |
| 365 | setup_efi_info(&setup_base->efi_info); |
Bin Meng | 106dcfc | 2018-08-23 08:24:10 -0700 | [diff] [blame] | 366 | |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 367 | return 0; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 368 | } |
| 369 | |
Simon Glass | 2bf90bd | 2023-12-03 17:29:27 -0700 | [diff] [blame] | 370 | int zboot_load(void) |
Simon Glass | 24d26f7 | 2020-09-05 14:50:46 -0600 | [diff] [blame] | 371 | { |
| 372 | struct boot_params *base_ptr; |
Simon Glass | f6d7ebd | 2023-12-03 17:29:31 -0700 | [diff] [blame^] | 373 | int ret; |
Simon Glass | 24d26f7 | 2020-09-05 14:50:46 -0600 | [diff] [blame] | 374 | |
Simon Glass | c55ce68 | 2020-09-05 14:50:49 -0600 | [diff] [blame] | 375 | if (state.base_ptr) { |
| 376 | struct boot_params *from = (struct boot_params *)state.base_ptr; |
| 377 | |
| 378 | base_ptr = (struct boot_params *)DEFAULT_SETUP_BASE; |
Simon Glass | 9d8ca9f | 2020-11-04 09:59:15 -0700 | [diff] [blame] | 379 | log_debug("Building boot_params at 0x%8.8lx\n", |
| 380 | (ulong)base_ptr); |
Simon Glass | c55ce68 | 2020-09-05 14:50:49 -0600 | [diff] [blame] | 381 | memset(base_ptr, '\0', sizeof(*base_ptr)); |
| 382 | base_ptr->hdr = from->hdr; |
| 383 | } else { |
| 384 | base_ptr = load_zimage((void *)state.bzimage_addr, state.bzimage_size, |
| 385 | &state.load_address); |
| 386 | if (!base_ptr) { |
| 387 | puts("## Kernel loading failed ...\n"); |
Simon Glass | 84305a1 | 2023-07-12 09:04:43 -0600 | [diff] [blame] | 388 | return -EINVAL; |
Simon Glass | c55ce68 | 2020-09-05 14:50:49 -0600 | [diff] [blame] | 389 | } |
Graeme Russ | 1bab104 | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 390 | } |
Simon Glass | 1931b19 | 2020-09-05 14:50:44 -0600 | [diff] [blame] | 391 | state.base_ptr = base_ptr; |
Simon Glass | 84305a1 | 2023-07-12 09:04:43 -0600 | [diff] [blame] | 392 | |
Simon Glass | f6d7ebd | 2023-12-03 17:29:31 -0700 | [diff] [blame^] | 393 | ret = env_set_hex("zbootbase", map_to_sysmem(state.base_ptr)); |
| 394 | if (!ret) |
| 395 | ret = env_set_hex("zbootaddr", state.load_address); |
| 396 | if (ret) |
| 397 | return ret; |
| 398 | |
Simon Glass | 84305a1 | 2023-07-12 09:04:43 -0600 | [diff] [blame] | 399 | return 0; |
| 400 | } |
| 401 | |
Simon Glass | 2bf90bd | 2023-12-03 17:29:27 -0700 | [diff] [blame] | 402 | int zboot_setup(void) |
Simon Glass | 84305a1 | 2023-07-12 09:04:43 -0600 | [diff] [blame] | 403 | { |
| 404 | struct boot_params *base_ptr = state.base_ptr; |
| 405 | int ret; |
| 406 | |
| 407 | ret = setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET, |
| 408 | 0, state.initrd_addr, state.initrd_size, |
| 409 | (ulong)state.cmdline); |
| 410 | if (ret) |
| 411 | return -EINVAL; |
| 412 | |
| 413 | return 0; |
| 414 | } |
| 415 | |
Simon Glass | 2bf90bd | 2023-12-03 17:29:27 -0700 | [diff] [blame] | 416 | int zboot_go(void) |
Simon Glass | 1931b19 | 2020-09-05 14:50:44 -0600 | [diff] [blame] | 417 | { |
Simon Glass | 6d49632 | 2023-03-20 08:30:08 +1300 | [diff] [blame] | 418 | struct boot_params *params = state.base_ptr; |
| 419 | struct setup_header *hdr = ¶ms->hdr; |
| 420 | bool image_64bit; |
| 421 | ulong entry; |
Simon Glass | 1931b19 | 2020-09-05 14:50:44 -0600 | [diff] [blame] | 422 | int ret; |
| 423 | |
Simon Glass | 0db800c | 2020-09-05 14:50:42 -0600 | [diff] [blame] | 424 | disable_interrupts(); |
Simon Glass | 1931b19 | 2020-09-05 14:50:44 -0600 | [diff] [blame] | 425 | |
Simon Glass | 6d49632 | 2023-03-20 08:30:08 +1300 | [diff] [blame] | 426 | entry = state.load_address; |
| 427 | image_64bit = false; |
| 428 | if (IS_ENABLED(CONFIG_X86_RUN_64BIT) && |
| 429 | (hdr->xloadflags & XLF_KERNEL_64)) { |
| 430 | entry += 0x200; |
| 431 | image_64bit = true; |
| 432 | } |
| 433 | |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 434 | /* we assume that the kernel is in place */ |
Simon Glass | 6d49632 | 2023-03-20 08:30:08 +1300 | [diff] [blame] | 435 | ret = boot_linux_kernel((ulong)state.base_ptr, entry, image_64bit); |
Simon Glass | 84305a1 | 2023-07-12 09:04:43 -0600 | [diff] [blame] | 436 | |
| 437 | return ret; |
| 438 | } |
| 439 | |
Simon Glass | 84305a1 | 2023-07-12 09:04:43 -0600 | [diff] [blame] | 440 | int zboot_start(ulong addr, ulong size, ulong initrd, ulong initrd_size, |
| 441 | ulong base, char *cmdline) |
| 442 | { |
| 443 | int ret; |
| 444 | |
| 445 | memset(&state, '\0', sizeof(state)); |
| 446 | |
| 447 | if (base) { |
| 448 | state.base_ptr = map_sysmem(base, 0); |
| 449 | state.load_address = addr; |
| 450 | } else { |
| 451 | state.bzimage_addr = addr; |
| 452 | } |
| 453 | state.bzimage_size = size; |
| 454 | state.initrd_addr = initrd; |
| 455 | state.initrd_size = initrd_size; |
| 456 | state.cmdline = cmdline; |
| 457 | |
| 458 | ret = zboot_load(); |
| 459 | if (ret) |
| 460 | return log_msg_ret("ld", ret); |
| 461 | ret = zboot_setup(); |
| 462 | if (ret) |
| 463 | return log_msg_ret("set", ret); |
| 464 | ret = zboot_go(); |
| 465 | if (ret) |
| 466 | return log_msg_ret("set", ret); |
| 467 | |
| 468 | return -EFAULT; |
| 469 | } |
| 470 | |
Simon Glass | aad0d76 | 2020-09-05 14:50:50 -0600 | [diff] [blame] | 471 | static void print_num(const char *name, ulong value) |
| 472 | { |
| 473 | printf("%-20s: %lx\n", name, value); |
| 474 | } |
| 475 | |
| 476 | static void print_num64(const char *name, u64 value) |
| 477 | { |
| 478 | printf("%-20s: %llx\n", name, value); |
| 479 | } |
| 480 | |
| 481 | static const char *const e820_type_name[E820_COUNT] = { |
| 482 | [E820_RAM] = "RAM", |
| 483 | [E820_RESERVED] = "Reserved", |
| 484 | [E820_ACPI] = "ACPI", |
| 485 | [E820_NVS] = "ACPI NVS", |
| 486 | [E820_UNUSABLE] = "Unusable", |
| 487 | }; |
| 488 | |
| 489 | static const char *const bootloader_id[] = { |
| 490 | "LILO", |
| 491 | "Loadlin", |
| 492 | "bootsect-loader", |
| 493 | "Syslinux", |
| 494 | "Etherboot/gPXE/iPXE", |
| 495 | "ELILO", |
| 496 | "undefined", |
| 497 | "GRUB", |
| 498 | "U-Boot", |
| 499 | "Xen", |
| 500 | "Gujin", |
| 501 | "Qemu", |
| 502 | "Arcturus Networks uCbootloader", |
| 503 | "kexec-tools", |
| 504 | "Extended", |
| 505 | "Special", |
| 506 | "Reserved", |
| 507 | "Minimal Linux Bootloader", |
| 508 | "OVMF UEFI virtualization stack", |
| 509 | }; |
| 510 | |
| 511 | struct flag_info { |
| 512 | uint bit; |
| 513 | const char *name; |
| 514 | }; |
| 515 | |
| 516 | static struct flag_info load_flags[] = { |
| 517 | { LOADED_HIGH, "loaded-high" }, |
| 518 | { QUIET_FLAG, "quiet" }, |
| 519 | { KEEP_SEGMENTS, "keep-segments" }, |
| 520 | { CAN_USE_HEAP, "can-use-heap" }, |
| 521 | }; |
| 522 | |
| 523 | static struct flag_info xload_flags[] = { |
| 524 | { XLF_KERNEL_64, "64-bit-entry" }, |
| 525 | { XLF_CAN_BE_LOADED_ABOVE_4G, "can-load-above-4gb" }, |
| 526 | { XLF_EFI_HANDOVER_32, "32-efi-handoff" }, |
| 527 | { XLF_EFI_HANDOVER_64, "64-efi-handoff" }, |
| 528 | { XLF_EFI_KEXEC, "kexec-efi-runtime" }, |
| 529 | }; |
| 530 | |
| 531 | static void print_flags(struct flag_info *flags, int count, uint value) |
| 532 | { |
| 533 | int i; |
| 534 | |
| 535 | printf("%-20s:", ""); |
| 536 | for (i = 0; i < count; i++) { |
| 537 | uint mask = flags[i].bit; |
| 538 | |
| 539 | if (value & mask) |
| 540 | printf(" %s", flags[i].name); |
| 541 | } |
| 542 | printf("\n"); |
| 543 | } |
| 544 | |
| 545 | static void show_loader(struct setup_header *hdr) |
| 546 | { |
| 547 | bool version_valid = false; |
| 548 | int type, version; |
| 549 | const char *name; |
| 550 | |
| 551 | type = hdr->type_of_loader >> 4; |
| 552 | version = hdr->type_of_loader & 0xf; |
| 553 | if (type == 0xe) |
| 554 | type = 0x10 + hdr->ext_loader_type; |
| 555 | version |= hdr->ext_loader_ver << 4; |
| 556 | if (!hdr->type_of_loader) { |
| 557 | name = "pre-2.00 bootloader"; |
| 558 | } else if (hdr->type_of_loader == 0xff) { |
| 559 | name = "unknown"; |
| 560 | } else if (type < ARRAY_SIZE(bootloader_id)) { |
| 561 | name = bootloader_id[type]; |
| 562 | version_valid = true; |
| 563 | } else { |
| 564 | name = "undefined"; |
| 565 | } |
| 566 | printf("%20s %s", "", name); |
| 567 | if (version_valid) |
| 568 | printf(", version %x", version); |
| 569 | printf("\n"); |
| 570 | } |
| 571 | |
Simon Glass | 5495aaf | 2023-07-30 11:17:00 -0600 | [diff] [blame] | 572 | void zimage_dump(struct boot_params *base_ptr, bool show_cmdline) |
Simon Glass | aad0d76 | 2020-09-05 14:50:50 -0600 | [diff] [blame] | 573 | { |
Simon Glass | aad0d76 | 2020-09-05 14:50:50 -0600 | [diff] [blame] | 574 | struct setup_header *hdr; |
| 575 | const char *version; |
| 576 | int i; |
| 577 | |
Simon Glass | aad0d76 | 2020-09-05 14:50:50 -0600 | [diff] [blame] | 578 | printf("Setup located at %p:\n\n", base_ptr); |
| 579 | print_num64("ACPI RSDP addr", base_ptr->acpi_rsdp_addr); |
| 580 | |
| 581 | printf("E820: %d entries\n", base_ptr->e820_entries); |
| 582 | if (base_ptr->e820_entries) { |
Simon Glass | 5495aaf | 2023-07-30 11:17:00 -0600 | [diff] [blame] | 583 | printf("%12s %10s %s\n", "Addr", "Size", "Type"); |
Simon Glass | aad0d76 | 2020-09-05 14:50:50 -0600 | [diff] [blame] | 584 | for (i = 0; i < base_ptr->e820_entries; i++) { |
| 585 | struct e820_entry *entry = &base_ptr->e820_map[i]; |
| 586 | |
| 587 | printf("%12llx %10llx %s\n", entry->addr, entry->size, |
| 588 | entry->type < E820_COUNT ? |
| 589 | e820_type_name[entry->type] : |
| 590 | simple_itoa(entry->type)); |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | hdr = &base_ptr->hdr; |
| 595 | print_num("Setup sectors", hdr->setup_sects); |
| 596 | print_num("Root flags", hdr->root_flags); |
| 597 | print_num("Sys size", hdr->syssize); |
| 598 | print_num("RAM size", hdr->ram_size); |
| 599 | print_num("Video mode", hdr->vid_mode); |
| 600 | print_num("Root dev", hdr->root_dev); |
| 601 | print_num("Boot flag", hdr->boot_flag); |
| 602 | print_num("Jump", hdr->jump); |
| 603 | print_num("Header", hdr->header); |
| 604 | if (hdr->header == KERNEL_V2_MAGIC) |
| 605 | printf("%-20s %s\n", "", "Kernel V2"); |
| 606 | else |
| 607 | printf("%-20s %s\n", "", "Ancient kernel, using version 100"); |
| 608 | print_num("Version", hdr->version); |
| 609 | print_num("Real mode switch", hdr->realmode_swtch); |
Simon Glass | 83ec1ca | 2023-03-20 08:30:06 +1300 | [diff] [blame] | 610 | print_num("Start sys seg", hdr->start_sys_seg); |
Simon Glass | aad0d76 | 2020-09-05 14:50:50 -0600 | [diff] [blame] | 611 | print_num("Kernel version", hdr->kernel_version); |
Simon Glass | 531efde | 2023-07-12 09:04:44 -0600 | [diff] [blame] | 612 | version = zimage_get_kernel_version(base_ptr, |
| 613 | (void *)state.bzimage_addr); |
Simon Glass | aad0d76 | 2020-09-05 14:50:50 -0600 | [diff] [blame] | 614 | if (version) |
| 615 | printf(" @%p: %s\n", version, version); |
| 616 | print_num("Type of loader", hdr->type_of_loader); |
| 617 | show_loader(hdr); |
| 618 | print_num("Load flags", hdr->loadflags); |
| 619 | print_flags(load_flags, ARRAY_SIZE(load_flags), hdr->loadflags); |
| 620 | print_num("Setup move size", hdr->setup_move_size); |
| 621 | print_num("Code32 start", hdr->code32_start); |
| 622 | print_num("Ramdisk image", hdr->ramdisk_image); |
| 623 | print_num("Ramdisk size", hdr->ramdisk_size); |
| 624 | print_num("Bootsect kludge", hdr->bootsect_kludge); |
| 625 | print_num("Heap end ptr", hdr->heap_end_ptr); |
| 626 | print_num("Ext loader ver", hdr->ext_loader_ver); |
| 627 | print_num("Ext loader type", hdr->ext_loader_type); |
| 628 | print_num("Command line ptr", hdr->cmd_line_ptr); |
Simon Glass | 5495aaf | 2023-07-30 11:17:00 -0600 | [diff] [blame] | 629 | if (show_cmdline && hdr->cmd_line_ptr) { |
Simon Glass | aad0d76 | 2020-09-05 14:50:50 -0600 | [diff] [blame] | 630 | printf(" "); |
| 631 | /* Use puts() to avoid limits from CONFIG_SYS_PBSIZE */ |
Simon Glass | 12d93ab | 2020-09-05 14:50:51 -0600 | [diff] [blame] | 632 | puts((char *)(ulong)hdr->cmd_line_ptr); |
Simon Glass | aad0d76 | 2020-09-05 14:50:50 -0600 | [diff] [blame] | 633 | printf("\n"); |
| 634 | } |
| 635 | print_num("Initrd addr max", hdr->initrd_addr_max); |
| 636 | print_num("Kernel alignment", hdr->kernel_alignment); |
| 637 | print_num("Relocatable kernel", hdr->relocatable_kernel); |
| 638 | print_num("Min alignment", hdr->min_alignment); |
| 639 | if (hdr->min_alignment) |
| 640 | printf("%-20s: %x\n", "", 1 << hdr->min_alignment); |
| 641 | print_num("Xload flags", hdr->xloadflags); |
| 642 | print_flags(xload_flags, ARRAY_SIZE(xload_flags), hdr->xloadflags); |
| 643 | print_num("Cmdline size", hdr->cmdline_size); |
| 644 | print_num("Hardware subarch", hdr->hardware_subarch); |
| 645 | print_num64("HW subarch data", hdr->hardware_subarch_data); |
| 646 | print_num("Payload offset", hdr->payload_offset); |
| 647 | print_num("Payload length", hdr->payload_length); |
| 648 | print_num64("Setup data", hdr->setup_data); |
| 649 | print_num64("Pref address", hdr->pref_address); |
| 650 | print_num("Init size", hdr->init_size); |
| 651 | print_num("Handover offset", hdr->handover_offset); |
| 652 | if (get_boot_protocol(hdr, false) >= 0x215) |
| 653 | print_num("Kernel info offset", hdr->kernel_info_offset); |
Simon Glass | ba094bb | 2021-01-24 10:06:08 -0700 | [diff] [blame] | 654 | } |