Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2000-2009 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
Simon Glass | 0232ba7 | 2014-06-12 07:24:51 -0600 | [diff] [blame] | 7 | #ifndef USE_HOSTCC |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 8 | #include <common.h> |
Simon Glass | 0232ba7 | 2014-06-12 07:24:51 -0600 | [diff] [blame] | 9 | #include <bootstage.h> |
Simon Glass | 529e208 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 10 | #include <cli.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 11 | #include <cpu_func.h> |
Simon Glass | 313112a | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 12 | #include <env.h> |
Simon Glass | 0129b52 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 13 | #include <errno.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 14 | #include <fdt_support.h> |
Simon Glass | 8f3f761 | 2019-11-14 12:57:42 -0700 | [diff] [blame] | 15 | #include <irq_func.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 16 | #include <lmb.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 17 | #include <log.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 18 | #include <malloc.h> |
Joe Hershberger | 65b905b | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 19 | #include <mapmem.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 20 | #include <net.h> |
| 21 | #include <asm/cache.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 22 | #include <asm/global_data.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 23 | #include <asm/io.h> |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 24 | #include <linux/sizes.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 25 | #if defined(CONFIG_CMD_USB) |
| 26 | #include <usb.h> |
| 27 | #endif |
Simon Glass | 0232ba7 | 2014-06-12 07:24:51 -0600 | [diff] [blame] | 28 | #else |
| 29 | #include "mkimage.h" |
| 30 | #endif |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 31 | |
Simon Glass | 0232ba7 | 2014-06-12 07:24:51 -0600 | [diff] [blame] | 32 | #include <command.h> |
| 33 | #include <bootm.h> |
| 34 | #include <image.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 35 | |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 36 | #define MAX_CMDLINE_SIZE SZ_4K |
| 37 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 38 | #define IH_INITRD_ARCH IH_ARCH_DEFAULT |
| 39 | |
Simon Glass | 0232ba7 | 2014-06-12 07:24:51 -0600 | [diff] [blame] | 40 | #ifndef USE_HOSTCC |
| 41 | |
| 42 | DECLARE_GLOBAL_DATA_PTR; |
| 43 | |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 44 | struct bootm_headers images; /* pointers to os/initrd/fdt images */ |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 45 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 46 | static const void *boot_get_kernel(struct cmd_tbl *cmdtp, int flag, int argc, |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 47 | char *const argv[], struct bootm_headers *images, |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 48 | ulong *os_data, ulong *os_len); |
| 49 | |
Simon Glass | f55305a | 2018-05-16 09:42:25 -0600 | [diff] [blame] | 50 | __weak void board_quiesce_devices(void) |
| 51 | { |
| 52 | } |
| 53 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 54 | #ifdef CONFIG_LMB |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 55 | static void boot_start_lmb(struct bootm_headers *images) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 56 | { |
| 57 | ulong mem_start; |
| 58 | phys_size_t mem_size; |
| 59 | |
Simon Glass | da1a134 | 2017-08-03 12:22:15 -0600 | [diff] [blame] | 60 | mem_start = env_get_bootm_low(); |
| 61 | mem_size = env_get_bootm_size(); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 62 | |
Simon Goldschmidt | 8890e7d | 2019-01-26 22:13:04 +0100 | [diff] [blame] | 63 | lmb_init_and_reserve_range(&images->lmb, (phys_addr_t)mem_start, |
| 64 | mem_size, NULL); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 65 | } |
| 66 | #else |
| 67 | #define lmb_reserve(lmb, base, size) |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 68 | static inline void boot_start_lmb(struct bootm_headers *images) { } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 69 | #endif |
| 70 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 71 | static int bootm_start(struct cmd_tbl *cmdtp, int flag, int argc, |
| 72 | char *const argv[]) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 73 | { |
| 74 | memset((void *)&images, 0, sizeof(images)); |
Simon Glass | 22c34c2 | 2017-08-03 12:22:13 -0600 | [diff] [blame] | 75 | images.verify = env_get_yesno("verify"); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 76 | |
| 77 | boot_start_lmb(&images); |
| 78 | |
| 79 | bootstage_mark_name(BOOTSTAGE_ID_BOOTM_START, "bootm_start"); |
| 80 | images.state = BOOTM_STATE_START; |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
Philippe Reynes | ae1f2ca | 2022-03-28 22:57:00 +0200 | [diff] [blame] | 85 | static ulong bootm_data_addr(int argc, char *const argv[]) |
| 86 | { |
| 87 | ulong addr; |
| 88 | |
| 89 | if (argc > 0) |
| 90 | addr = simple_strtoul(argv[0], NULL, 16); |
| 91 | else |
| 92 | addr = image_load_addr; |
| 93 | |
| 94 | return addr; |
| 95 | } |
| 96 | |
| 97 | static int bootm_pre_load(struct cmd_tbl *cmdtp, int flag, int argc, |
| 98 | char *const argv[]) |
| 99 | { |
| 100 | ulong data_addr = bootm_data_addr(argc, argv); |
| 101 | int ret = 0; |
| 102 | |
Simon Glass | 88b6f92 | 2023-02-05 15:36:24 -0700 | [diff] [blame] | 103 | if (IS_ENABLED(CONFIG_CMD_BOOTM_PRE_LOAD)) |
Philippe Reynes | ae1f2ca | 2022-03-28 22:57:00 +0200 | [diff] [blame] | 104 | ret = image_pre_load(data_addr); |
| 105 | |
| 106 | if (ret) |
| 107 | ret = CMD_RET_FAILURE; |
| 108 | |
| 109 | return ret; |
| 110 | } |
| 111 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 112 | static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc, |
| 113 | char *const argv[]) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 114 | { |
| 115 | const void *os_hdr; |
| 116 | bool ep_found = false; |
Simon Glass | 0129b52 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 117 | int ret; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 118 | |
| 119 | /* get kernel image header, start address and length */ |
| 120 | os_hdr = boot_get_kernel(cmdtp, flag, argc, argv, |
| 121 | &images, &images.os.image_start, &images.os.image_len); |
| 122 | if (images.os.image_len == 0) { |
| 123 | puts("ERROR: can't get kernel image!\n"); |
| 124 | return 1; |
| 125 | } |
| 126 | |
| 127 | /* get image parameters */ |
| 128 | switch (genimg_get_format(os_hdr)) { |
Tom Rini | c220bd9 | 2019-05-23 07:14:07 -0400 | [diff] [blame] | 129 | #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 130 | case IMAGE_FORMAT_LEGACY: |
| 131 | images.os.type = image_get_type(os_hdr); |
| 132 | images.os.comp = image_get_comp(os_hdr); |
| 133 | images.os.os = image_get_os(os_hdr); |
| 134 | |
| 135 | images.os.end = image_get_image_end(os_hdr); |
| 136 | images.os.load = image_get_load(os_hdr); |
Simon Glass | 0129b52 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 137 | images.os.arch = image_get_arch(os_hdr); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 138 | break; |
| 139 | #endif |
Simon Glass | e719d3b | 2021-09-25 19:43:20 -0600 | [diff] [blame] | 140 | #if CONFIG_IS_ENABLED(FIT) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 141 | case IMAGE_FORMAT_FIT: |
| 142 | if (fit_image_get_type(images.fit_hdr_os, |
| 143 | images.fit_noffset_os, |
| 144 | &images.os.type)) { |
| 145 | puts("Can't get image type!\n"); |
| 146 | bootstage_error(BOOTSTAGE_ID_FIT_TYPE); |
| 147 | return 1; |
| 148 | } |
| 149 | |
| 150 | if (fit_image_get_comp(images.fit_hdr_os, |
| 151 | images.fit_noffset_os, |
| 152 | &images.os.comp)) { |
| 153 | puts("Can't get image compression!\n"); |
| 154 | bootstage_error(BOOTSTAGE_ID_FIT_COMPRESSION); |
| 155 | return 1; |
| 156 | } |
| 157 | |
| 158 | if (fit_image_get_os(images.fit_hdr_os, images.fit_noffset_os, |
| 159 | &images.os.os)) { |
| 160 | puts("Can't get image OS!\n"); |
| 161 | bootstage_error(BOOTSTAGE_ID_FIT_OS); |
| 162 | return 1; |
| 163 | } |
| 164 | |
Simon Glass | 0129b52 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 165 | if (fit_image_get_arch(images.fit_hdr_os, |
| 166 | images.fit_noffset_os, |
| 167 | &images.os.arch)) { |
| 168 | puts("Can't get image ARCH!\n"); |
| 169 | return 1; |
| 170 | } |
| 171 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 172 | images.os.end = fit_get_end(images.fit_hdr_os); |
| 173 | |
| 174 | if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os, |
| 175 | &images.os.load)) { |
| 176 | puts("Can't get image load address!\n"); |
| 177 | bootstage_error(BOOTSTAGE_ID_FIT_LOADADDR); |
| 178 | return 1; |
| 179 | } |
| 180 | break; |
| 181 | #endif |
| 182 | #ifdef CONFIG_ANDROID_BOOT_IMAGE |
| 183 | case IMAGE_FORMAT_ANDROID: |
| 184 | images.os.type = IH_TYPE_KERNEL; |
Eugeniu Rosca | 1403f39 | 2019-04-08 17:35:27 +0200 | [diff] [blame] | 185 | images.os.comp = android_image_get_kcomp(os_hdr); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 186 | images.os.os = IH_OS_LINUX; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 187 | |
| 188 | images.os.end = android_image_get_end(os_hdr); |
| 189 | images.os.load = android_image_get_kload(os_hdr); |
Ahmad Draidi | 9a1cb5d | 2014-10-23 20:50:07 +0300 | [diff] [blame] | 190 | images.ep = images.os.load; |
| 191 | ep_found = true; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 192 | break; |
| 193 | #endif |
| 194 | default: |
| 195 | puts("ERROR: unknown image format type!\n"); |
| 196 | return 1; |
| 197 | } |
| 198 | |
Simon Glass | 0129b52 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 199 | /* If we have a valid setup.bin, we will use that for entry (x86) */ |
Simon Glass | 9d42830 | 2014-10-10 08:21:57 -0600 | [diff] [blame] | 200 | if (images.os.arch == IH_ARCH_I386 || |
| 201 | images.os.arch == IH_ARCH_X86_64) { |
Simon Glass | 0129b52 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 202 | ulong len; |
| 203 | |
| 204 | ret = boot_get_setup(&images, IH_ARCH_I386, &images.ep, &len); |
| 205 | if (ret < 0 && ret != -ENOENT) { |
| 206 | puts("Could not find a valid setup.bin for x86\n"); |
| 207 | return 1; |
| 208 | } |
| 209 | /* Kernel entry point is the setup.bin */ |
| 210 | } else if (images.legacy_hdr_valid) { |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 211 | images.ep = image_get_ep(&images.legacy_hdr_os_copy); |
Simon Glass | e719d3b | 2021-09-25 19:43:20 -0600 | [diff] [blame] | 212 | #if CONFIG_IS_ENABLED(FIT) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 213 | } else if (images.fit_uname_os) { |
| 214 | int ret; |
| 215 | |
| 216 | ret = fit_image_get_entry(images.fit_hdr_os, |
| 217 | images.fit_noffset_os, &images.ep); |
| 218 | if (ret) { |
| 219 | puts("Can't get entry point property!\n"); |
| 220 | return 1; |
| 221 | } |
| 222 | #endif |
| 223 | } else if (!ep_found) { |
| 224 | puts("Could not find kernel entry point!\n"); |
| 225 | return 1; |
| 226 | } |
| 227 | |
| 228 | if (images.os.type == IH_TYPE_KERNEL_NOLOAD) { |
Simon Glass | df650d2 | 2023-02-05 15:36:23 -0700 | [diff] [blame] | 229 | if (IS_ENABLED(CONFIG_CMD_BOOTI) && |
Marek Vasut | 2142579 | 2018-06-13 06:13:33 +0200 | [diff] [blame] | 230 | images.os.arch == IH_ARCH_ARM64) { |
| 231 | ulong image_addr; |
| 232 | ulong image_size; |
| 233 | |
| 234 | ret = booti_setup(images.os.image_start, &image_addr, |
| 235 | &image_size, true); |
| 236 | if (ret != 0) |
| 237 | return 1; |
| 238 | |
| 239 | images.os.type = IH_TYPE_KERNEL; |
| 240 | images.os.load = image_addr; |
| 241 | images.ep = image_addr; |
| 242 | } else { |
| 243 | images.os.load = images.os.image_start; |
| 244 | images.ep += images.os.image_start; |
| 245 | } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 246 | } |
| 247 | |
Simon Glass | 5b539a0 | 2016-02-24 09:14:42 -0700 | [diff] [blame] | 248 | images.os.start = map_to_sysmem(os_hdr); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | |
Karl Apsite | d686ce9 | 2015-05-21 09:52:49 -0400 | [diff] [blame] | 253 | /** |
| 254 | * bootm_find_images - wrapper to find and locate various images |
| 255 | * @flag: Ignored Argument |
| 256 | * @argc: command argument count |
| 257 | * @argv: command argument list |
Tero Kristo | 0608694 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 258 | * @start: OS image start address |
| 259 | * @size: OS image size |
Karl Apsite | d686ce9 | 2015-05-21 09:52:49 -0400 | [diff] [blame] | 260 | * |
| 261 | * boot_find_images() will attempt to load an available ramdisk, |
| 262 | * flattened device tree, as well as specifically marked |
| 263 | * "loadable" images (loadables are FIT only) |
| 264 | * |
| 265 | * Note: bootm_find_images will skip an image if it is not found |
| 266 | * |
| 267 | * @return: |
| 268 | * 0, if all existing images were loaded correctly |
| 269 | * 1, if an image is found but corrupted, or invalid |
| 270 | */ |
Tero Kristo | 0608694 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 271 | int bootm_find_images(int flag, int argc, char *const argv[], ulong start, |
| 272 | ulong size) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 273 | { |
| 274 | int ret; |
| 275 | |
| 276 | /* find ramdisk */ |
| 277 | ret = boot_get_ramdisk(argc, argv, &images, IH_INITRD_ARCH, |
| 278 | &images.rd_start, &images.rd_end); |
| 279 | if (ret) { |
| 280 | puts("Ramdisk image is corrupt or invalid\n"); |
| 281 | return 1; |
| 282 | } |
| 283 | |
Tero Kristo | 0608694 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 284 | /* check if ramdisk overlaps OS image */ |
| 285 | if (images.rd_start && (((ulong)images.rd_start >= start && |
Jaehoon Chung | 80ffb81 | 2020-10-21 14:17:03 +0900 | [diff] [blame] | 286 | (ulong)images.rd_start < start + size) || |
| 287 | ((ulong)images.rd_end > start && |
| 288 | (ulong)images.rd_end <= start + size) || |
| 289 | ((ulong)images.rd_start < start && |
| 290 | (ulong)images.rd_end >= start + size))) { |
Tero Kristo | 0608694 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 291 | printf("ERROR: RD image overlaps OS image (OS=0x%lx..0x%lx)\n", |
| 292 | start, start + size); |
| 293 | return 1; |
| 294 | } |
| 295 | |
Simon Glass | 85c057e | 2021-09-25 19:43:21 -0600 | [diff] [blame] | 296 | #if CONFIG_IS_ENABLED(OF_LIBFDT) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 297 | /* find flattened device tree */ |
| 298 | ret = boot_get_fdt(flag, argc, argv, IH_ARCH_DEFAULT, &images, |
| 299 | &images.ft_addr, &images.ft_len); |
| 300 | if (ret) { |
| 301 | puts("Could not find a valid device tree\n"); |
| 302 | return 1; |
| 303 | } |
Tero Kristo | 0608694 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 304 | |
| 305 | /* check if FDT overlaps OS image */ |
| 306 | if (images.ft_addr && |
| 307 | (((ulong)images.ft_addr >= start && |
Pali Rohár | 779a7b69 | 2022-08-27 14:48:10 +0200 | [diff] [blame] | 308 | (ulong)images.ft_addr < start + size) || |
Tero Kristo | 0608694 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 309 | ((ulong)images.ft_addr + images.ft_len >= start && |
Pali Rohár | 779a7b69 | 2022-08-27 14:48:10 +0200 | [diff] [blame] | 310 | (ulong)images.ft_addr + images.ft_len < start + size))) { |
Tero Kristo | 0608694 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 311 | printf("ERROR: FDT image overlaps OS image (OS=0x%lx..0x%lx)\n", |
| 312 | start, start + size); |
| 313 | return 1; |
| 314 | } |
| 315 | |
Simon Glass | e2d49d9 | 2023-02-05 15:36:30 -0700 | [diff] [blame] | 316 | if (IS_ENABLED(CONFIG_CMD_FDT)) |
Simon Goldschmidt | 6127ac0 | 2018-12-17 20:14:42 +0100 | [diff] [blame] | 317 | set_working_fdt_addr(map_to_sysmem(images.ft_addr)); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 318 | #endif |
| 319 | |
Simon Glass | e719d3b | 2021-09-25 19:43:20 -0600 | [diff] [blame] | 320 | #if CONFIG_IS_ENABLED(FIT) |
Simon Glass | bc0c4db | 2021-09-25 07:03:20 -0600 | [diff] [blame] | 321 | if (IS_ENABLED(CONFIG_FPGA)) { |
| 322 | /* find bitstreams */ |
| 323 | ret = boot_get_fpga(argc, argv, &images, IH_ARCH_DEFAULT, |
| 324 | NULL, NULL); |
| 325 | if (ret) { |
| 326 | printf("FPGA image is corrupted or invalid\n"); |
| 327 | return 1; |
| 328 | } |
Michal Simek | ebae78b | 2016-05-17 14:03:50 +0200 | [diff] [blame] | 329 | } |
Michal Simek | ebae78b | 2016-05-17 14:03:50 +0200 | [diff] [blame] | 330 | |
Karl Apsite | 1b21c28 | 2015-05-21 09:52:48 -0400 | [diff] [blame] | 331 | /* find all of the loadables */ |
| 332 | ret = boot_get_loadable(argc, argv, &images, IH_ARCH_DEFAULT, |
| 333 | NULL, NULL); |
| 334 | if (ret) { |
| 335 | printf("Loadable(s) is corrupt or invalid\n"); |
| 336 | return 1; |
| 337 | } |
Karl Apsite | 1b21c28 | 2015-05-21 09:52:48 -0400 | [diff] [blame] | 338 | #endif |
| 339 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 340 | return 0; |
| 341 | } |
| 342 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 343 | static int bootm_find_other(struct cmd_tbl *cmdtp, int flag, int argc, |
| 344 | char *const argv[]) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 345 | { |
| 346 | if (((images.os.type == IH_TYPE_KERNEL) || |
| 347 | (images.os.type == IH_TYPE_KERNEL_NOLOAD) || |
| 348 | (images.os.type == IH_TYPE_MULTI)) && |
| 349 | (images.os.os == IH_OS_LINUX || |
| 350 | images.os.os == IH_OS_VXWORKS)) |
Tero Kristo | 0608694 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 351 | return bootm_find_images(flag, argc, argv, 0, 0); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 352 | |
| 353 | return 0; |
| 354 | } |
Simon Glass | 10ae419 | 2014-12-02 13:17:30 -0700 | [diff] [blame] | 355 | #endif /* USE_HOSTC */ |
| 356 | |
Julius Werner | 47ef986 | 2019-07-24 19:37:54 -0700 | [diff] [blame] | 357 | #if !defined(USE_HOSTCC) || defined(CONFIG_FIT_SIGNATURE) |
Simon Glass | 4f6e6d7 | 2014-12-02 13:17:37 -0700 | [diff] [blame] | 358 | /** |
| 359 | * handle_decomp_error() - display a decompression error |
| 360 | * |
| 361 | * This function tries to produce a useful message. In the case where the |
| 362 | * uncompressed size is the same as the available space, we can assume that |
| 363 | * the image is too large for the buffer. |
| 364 | * |
| 365 | * @comp_type: Compression type being used (IH_COMP_...) |
| 366 | * @uncomp_size: Number of bytes uncompressed |
Tom Rini | f3c2f99 | 2022-06-25 19:29:46 -0400 | [diff] [blame] | 367 | * @buf_size: Number of bytes the decompresion buffer was |
Julius Werner | 47ef986 | 2019-07-24 19:37:54 -0700 | [diff] [blame] | 368 | * @ret: errno error code received from compression library |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 369 | * Return: Appropriate BOOTM_ERR_ error code |
Simon Glass | 4f6e6d7 | 2014-12-02 13:17:37 -0700 | [diff] [blame] | 370 | */ |
Tom Rini | f3c2f99 | 2022-06-25 19:29:46 -0400 | [diff] [blame] | 371 | static int handle_decomp_error(int comp_type, size_t uncomp_size, |
| 372 | size_t buf_size, int ret) |
Simon Glass | 10ae419 | 2014-12-02 13:17:30 -0700 | [diff] [blame] | 373 | { |
Simon Glass | 4f6e6d7 | 2014-12-02 13:17:37 -0700 | [diff] [blame] | 374 | const char *name = genimg_get_comp_name(comp_type); |
| 375 | |
Julius Werner | 47ef986 | 2019-07-24 19:37:54 -0700 | [diff] [blame] | 376 | /* ENOSYS means unimplemented compression type, don't reset. */ |
| 377 | if (ret == -ENOSYS) |
| 378 | return BOOTM_ERR_UNIMPLEMENTED; |
| 379 | |
Tom Rini | f3c2f99 | 2022-06-25 19:29:46 -0400 | [diff] [blame] | 380 | if (uncomp_size >= buf_size) |
Simon Glass | 4f6e6d7 | 2014-12-02 13:17:37 -0700 | [diff] [blame] | 381 | printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n"); |
Simon Glass | 10ae419 | 2014-12-02 13:17:30 -0700 | [diff] [blame] | 382 | else |
Simon Glass | 4f6e6d7 | 2014-12-02 13:17:37 -0700 | [diff] [blame] | 383 | printf("%s: uncompress error %d\n", name, ret); |
| 384 | |
| 385 | /* |
| 386 | * The decompression routines are now safe, so will not write beyond |
| 387 | * their bounds. Probably it is not necessary to reset, but maintain |
| 388 | * the current behaviour for now. |
| 389 | */ |
| 390 | printf("Must RESET board to recover\n"); |
Simon Glass | 10ae419 | 2014-12-02 13:17:30 -0700 | [diff] [blame] | 391 | #ifndef USE_HOSTCC |
| 392 | bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE); |
| 393 | #endif |
| 394 | |
| 395 | return BOOTM_ERR_RESET; |
| 396 | } |
Julius Werner | 47ef986 | 2019-07-24 19:37:54 -0700 | [diff] [blame] | 397 | #endif |
Simon Glass | 686f3bb | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 398 | |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 399 | #ifndef USE_HOSTCC |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 400 | static int bootm_load_os(struct bootm_headers *images, int boot_progress) |
Simon Glass | 686f3bb | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 401 | { |
Simon Glass | 74578f5 | 2022-09-06 20:26:51 -0600 | [diff] [blame] | 402 | struct image_info os = images->os; |
Simon Glass | 686f3bb | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 403 | ulong load = os.load; |
Tom Rini | 6c96f5d | 2018-05-01 12:32:37 -0400 | [diff] [blame] | 404 | ulong load_end; |
Simon Glass | 686f3bb | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 405 | ulong blob_start = os.start; |
| 406 | ulong blob_end = os.end; |
| 407 | ulong image_start = os.image_start; |
| 408 | ulong image_len = os.image_len; |
Bryan O'Donoghue | 600388e | 2018-04-15 11:48:17 +0100 | [diff] [blame] | 409 | ulong flush_start = ALIGN_DOWN(load, ARCH_DMA_MINALIGN); |
Simon Glass | 686f3bb | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 410 | bool no_overlap; |
| 411 | void *load_buf, *image_buf; |
| 412 | int err; |
| 413 | |
| 414 | load_buf = map_sysmem(load, 0); |
| 415 | image_buf = map_sysmem(os.image_start, image_len); |
Julius Werner | 47ef986 | 2019-07-24 19:37:54 -0700 | [diff] [blame] | 416 | err = image_decomp(os.comp, load, os.image_start, os.type, |
| 417 | load_buf, image_buf, image_len, |
| 418 | CONFIG_SYS_BOOTM_LEN, &load_end); |
Simon Glass | 686f3bb | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 419 | if (err) { |
Tom Rini | f3c2f99 | 2022-06-25 19:29:46 -0400 | [diff] [blame] | 420 | err = handle_decomp_error(os.comp, load_end - load, |
| 421 | CONFIG_SYS_BOOTM_LEN, err); |
Simon Glass | 686f3bb | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 422 | bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE); |
| 423 | return err; |
| 424 | } |
Heinrich Schuchardt | 6d29e0d | 2020-08-30 11:34:12 +0200 | [diff] [blame] | 425 | /* We need the decompressed image size in the next steps */ |
| 426 | images->os.image_len = load_end - load; |
Bryan O'Donoghue | 600388e | 2018-04-15 11:48:17 +0100 | [diff] [blame] | 427 | |
Trent Piepho | 92e51d0 | 2019-03-27 23:50:09 +0000 | [diff] [blame] | 428 | flush_cache(flush_start, ALIGN(load_end, ARCH_DMA_MINALIGN) - flush_start); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 429 | |
Tom Rini | 6c96f5d | 2018-05-01 12:32:37 -0400 | [diff] [blame] | 430 | debug(" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, load_end); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 431 | bootstage_mark(BOOTSTAGE_ID_KERNEL_LOADED); |
| 432 | |
Simon Glass | 686f3bb | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 433 | no_overlap = (os.comp == IH_COMP_NONE && load == image_start); |
| 434 | |
Tom Rini | 6c96f5d | 2018-05-01 12:32:37 -0400 | [diff] [blame] | 435 | if (!no_overlap && load < blob_end && load_end > blob_start) { |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 436 | debug("images.os.start = 0x%lX, images.os.end = 0x%lx\n", |
| 437 | blob_start, blob_end); |
| 438 | debug("images.os.load = 0x%lx, load_end = 0x%lx\n", load, |
Tom Rini | 6c96f5d | 2018-05-01 12:32:37 -0400 | [diff] [blame] | 439 | load_end); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 440 | |
| 441 | /* Check what type of image this is. */ |
| 442 | if (images->legacy_hdr_valid) { |
| 443 | if (image_get_type(&images->legacy_hdr_os_copy) |
| 444 | == IH_TYPE_MULTI) |
| 445 | puts("WARNING: legacy format multi component image overwritten\n"); |
| 446 | return BOOTM_ERR_OVERLAP; |
| 447 | } else { |
| 448 | puts("ERROR: new format image overwritten - must RESET the board to recover\n"); |
| 449 | bootstage_error(BOOTSTAGE_ID_OVERWRITTEN); |
| 450 | return BOOTM_ERR_RESET; |
| 451 | } |
| 452 | } |
| 453 | |
Tom Rini | 6c96f5d | 2018-05-01 12:32:37 -0400 | [diff] [blame] | 454 | lmb_reserve(&images->lmb, images->os.load, (load_end - |
| 455 | images->os.load)); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 456 | return 0; |
| 457 | } |
| 458 | |
| 459 | /** |
| 460 | * bootm_disable_interrupts() - Disable interrupts in preparation for load/boot |
| 461 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 462 | * Return: interrupt flag (0 if interrupts were disabled, non-zero if they were |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 463 | * enabled) |
| 464 | */ |
| 465 | ulong bootm_disable_interrupts(void) |
| 466 | { |
| 467 | ulong iflag; |
| 468 | |
| 469 | /* |
| 470 | * We have reached the point of no return: we are going to |
| 471 | * overwrite all exception vector code, so we cannot easily |
| 472 | * recover from any failures any more... |
| 473 | */ |
| 474 | iflag = disable_interrupts(); |
| 475 | #ifdef CONFIG_NETCONSOLE |
| 476 | /* Stop the ethernet stack if NetConsole could have left it up */ |
| 477 | eth_halt(); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 478 | #endif |
| 479 | |
| 480 | #if defined(CONFIG_CMD_USB) |
| 481 | /* |
| 482 | * turn off USB to prevent the host controller from writing to the |
| 483 | * SDRAM while Linux is booting. This could happen (at least for OHCI |
| 484 | * controller), because the HCCA (Host Controller Communication Area) |
| 485 | * lies within the SDRAM and the host controller writes continously to |
| 486 | * this area (as busmaster!). The HccaFrameNumber is for example |
| 487 | * updated every 1 ms within the HCCA structure in SDRAM! For more |
| 488 | * details see the OpenHCI specification. |
| 489 | */ |
| 490 | usb_stop(); |
| 491 | #endif |
| 492 | return iflag; |
| 493 | } |
| 494 | |
Simon Glass | 7a8a429 | 2020-11-05 10:33:42 -0700 | [diff] [blame] | 495 | #define CONSOLE_ARG "console=" |
Sean Anderson | 15bdcd4 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 496 | #define NULL_CONSOLE (CONSOLE_ARG "ttynull") |
| 497 | #define CONSOLE_ARG_SIZE sizeof(NULL_CONSOLE) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 498 | |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 499 | /** |
| 500 | * fixup_silent_linux() - Handle silencing the linux boot if required |
| 501 | * |
| 502 | * This uses the silent_linux envvar to control whether to add/set a "console=" |
| 503 | * parameter to the command line |
| 504 | * |
| 505 | * @buf: Buffer containing the string to process |
| 506 | * @maxlen: Maximum length of buffer |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 507 | * Return: 0 if OK, -ENOSPC if @maxlen is too small |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 508 | */ |
| 509 | static int fixup_silent_linux(char *buf, int maxlen) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 510 | { |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 511 | int want_silent; |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 512 | char *cmdline; |
| 513 | int size; |
Simon Glass | 07a8886 | 2020-11-05 10:33:38 -0700 | [diff] [blame] | 514 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 515 | /* |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 516 | * Move the input string to the end of buffer. The output string will be |
| 517 | * built up at the start. |
| 518 | */ |
| 519 | size = strlen(buf) + 1; |
| 520 | if (size * 2 > maxlen) |
| 521 | return -ENOSPC; |
| 522 | cmdline = buf + maxlen - size; |
| 523 | memmove(cmdline, buf, size); |
| 524 | /* |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 525 | * Only fix cmdline when requested. The environment variable can be: |
| 526 | * |
| 527 | * no - we never fixup |
| 528 | * yes - we always fixup |
| 529 | * unset - we rely on the console silent flag |
| 530 | */ |
Simon Glass | 22c34c2 | 2017-08-03 12:22:13 -0600 | [diff] [blame] | 531 | want_silent = env_get_yesno("silent_linux"); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 532 | if (want_silent == 0) |
Simon Glass | 2eab017 | 2020-11-05 10:33:39 -0700 | [diff] [blame] | 533 | return 0; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 534 | else if (want_silent == -1 && !(gd->flags & GD_FLG_SILENT)) |
Simon Glass | 2eab017 | 2020-11-05 10:33:39 -0700 | [diff] [blame] | 535 | return 0; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 536 | |
| 537 | debug("before silent fix-up: %s\n", cmdline); |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 538 | if (*cmdline) { |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 539 | char *start = strstr(cmdline, CONSOLE_ARG); |
| 540 | |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 541 | /* Check space for maximum possible new command line */ |
| 542 | if (size + CONSOLE_ARG_SIZE > maxlen) |
Simon Glass | 2eab017 | 2020-11-05 10:33:39 -0700 | [diff] [blame] | 543 | return -ENOSPC; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 544 | |
| 545 | if (start) { |
| 546 | char *end = strchr(start, ' '); |
Simon Glass | 7a8a429 | 2020-11-05 10:33:42 -0700 | [diff] [blame] | 547 | int start_bytes; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 548 | |
Sean Anderson | 15bdcd4 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 549 | start_bytes = start - cmdline; |
Simon Glass | 7a8a429 | 2020-11-05 10:33:42 -0700 | [diff] [blame] | 550 | strncpy(buf, cmdline, start_bytes); |
Sean Anderson | 15bdcd4 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 551 | strncpy(buf + start_bytes, NULL_CONSOLE, CONSOLE_ARG_SIZE); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 552 | if (end) |
Sean Anderson | 15bdcd4 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 553 | strcpy(buf + start_bytes + CONSOLE_ARG_SIZE - 1, end); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 554 | else |
Sean Anderson | 15bdcd4 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 555 | buf[start_bytes + CONSOLE_ARG_SIZE] = '\0'; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 556 | } else { |
Sean Anderson | 15bdcd4 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 557 | sprintf(buf, "%s %s", cmdline, NULL_CONSOLE); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 558 | } |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 559 | if (buf + strlen(buf) >= cmdline) |
| 560 | return -ENOSPC; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 561 | } else { |
Sean Anderson | 15bdcd4 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 562 | if (maxlen < CONSOLE_ARG_SIZE) |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 563 | return -ENOSPC; |
Sean Anderson | 15bdcd4 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 564 | strcpy(buf, NULL_CONSOLE); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 565 | } |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 566 | debug("after silent fix-up: %s\n", buf); |
| 567 | |
| 568 | return 0; |
| 569 | } |
| 570 | |
Simon Glass | 529e208 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 571 | /** |
| 572 | * process_subst() - Handle substitution of ${...} fields in the environment |
| 573 | * |
| 574 | * Handle variable substitution in the provided buffer |
| 575 | * |
| 576 | * @buf: Buffer containing the string to process |
| 577 | * @maxlen: Maximum length of buffer |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 578 | * Return: 0 if OK, -ENOSPC if @maxlen is too small |
Simon Glass | 529e208 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 579 | */ |
| 580 | static int process_subst(char *buf, int maxlen) |
| 581 | { |
| 582 | char *cmdline; |
| 583 | int size; |
| 584 | int ret; |
| 585 | |
| 586 | /* Move to end of buffer */ |
| 587 | size = strlen(buf) + 1; |
| 588 | cmdline = buf + maxlen - size; |
| 589 | if (buf + size > cmdline) |
| 590 | return -ENOSPC; |
| 591 | memmove(cmdline, buf, size); |
| 592 | |
| 593 | ret = cli_simple_process_macros(cmdline, buf, cmdline - buf); |
| 594 | |
| 595 | return ret; |
| 596 | } |
| 597 | |
Simon Glass | b4e1b6d | 2020-11-05 10:33:45 -0700 | [diff] [blame] | 598 | int bootm_process_cmdline(char *buf, int maxlen, int flags) |
| 599 | { |
| 600 | int ret; |
| 601 | |
| 602 | /* Check config first to enable compiler to eliminate code */ |
| 603 | if (IS_ENABLED(CONFIG_SILENT_CONSOLE) && |
| 604 | !IS_ENABLED(CONFIG_SILENT_U_BOOT_ONLY) && |
| 605 | (flags & BOOTM_CL_SILENT)) { |
| 606 | ret = fixup_silent_linux(buf, maxlen); |
| 607 | if (ret) |
| 608 | return log_msg_ret("silent", ret); |
| 609 | } |
Simon Glass | ed8603d | 2021-03-15 18:11:23 +1300 | [diff] [blame] | 610 | if (IS_ENABLED(CONFIG_BOOTARGS_SUBST) && IS_ENABLED(CONFIG_CMDLINE) && |
| 611 | (flags & BOOTM_CL_SUBST)) { |
Simon Glass | 529e208 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 612 | ret = process_subst(buf, maxlen); |
| 613 | if (ret) |
Simon Glass | cac744e | 2021-02-06 09:57:35 -0700 | [diff] [blame] | 614 | return log_msg_ret("subst", ret); |
Simon Glass | 529e208 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 615 | } |
Simon Glass | b4e1b6d | 2020-11-05 10:33:45 -0700 | [diff] [blame] | 616 | |
| 617 | return 0; |
| 618 | } |
| 619 | |
Simon Glass | 63660dc | 2020-11-05 10:33:44 -0700 | [diff] [blame] | 620 | int bootm_process_cmdline_env(int flags) |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 621 | { |
| 622 | const int maxlen = MAX_CMDLINE_SIZE; |
Simon Glass | 63660dc | 2020-11-05 10:33:44 -0700 | [diff] [blame] | 623 | bool do_silent; |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 624 | const char *env; |
| 625 | char *buf; |
| 626 | int ret; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 627 | |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 628 | /* First check if any action is needed */ |
| 629 | do_silent = IS_ENABLED(CONFIG_SILENT_CONSOLE) && |
Simon Glass | 63660dc | 2020-11-05 10:33:44 -0700 | [diff] [blame] | 630 | !IS_ENABLED(CONFIG_SILENT_U_BOOT_ONLY) && (flags & BOOTM_CL_SILENT); |
Simon Glass | 529e208 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 631 | if (!do_silent && !IS_ENABLED(CONFIG_BOOTARGS_SUBST)) |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 632 | return 0; |
| 633 | |
| 634 | env = env_get("bootargs"); |
| 635 | if (env && strlen(env) >= maxlen) |
| 636 | return -E2BIG; |
| 637 | buf = malloc(maxlen); |
| 638 | if (!buf) |
| 639 | return -ENOMEM; |
| 640 | if (env) |
| 641 | strcpy(buf, env); |
| 642 | else |
| 643 | *buf = '\0'; |
Simon Glass | b4e1b6d | 2020-11-05 10:33:45 -0700 | [diff] [blame] | 644 | ret = bootm_process_cmdline(buf, maxlen, flags); |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 645 | if (!ret) { |
| 646 | ret = env_set("bootargs", buf); |
| 647 | |
| 648 | /* |
| 649 | * If buf is "" and bootargs does not exist, this will produce |
| 650 | * an error trying to delete bootargs. Ignore it |
| 651 | */ |
| 652 | if (ret == -ENOENT) |
| 653 | ret = 0; |
| 654 | } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 655 | free(buf); |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 656 | if (ret) |
| 657 | return log_msg_ret("env", ret); |
Simon Glass | 2eab017 | 2020-11-05 10:33:39 -0700 | [diff] [blame] | 658 | |
| 659 | return 0; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 660 | } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 661 | |
| 662 | /** |
| 663 | * Execute selected states of the bootm command. |
| 664 | * |
| 665 | * Note the arguments to this state must be the first argument, Any 'bootm' |
| 666 | * or sub-command arguments must have already been taken. |
| 667 | * |
| 668 | * Note that if states contains more than one flag it MUST contain |
| 669 | * BOOTM_STATE_START, since this handles and consumes the command line args. |
| 670 | * |
| 671 | * Also note that aside from boot_os_fn functions and bootm_load_os no other |
| 672 | * functions we store the return value of in 'ret' may use a negative return |
| 673 | * value, without special handling. |
| 674 | * |
| 675 | * @param cmdtp Pointer to bootm command table entry |
| 676 | * @param flag Command flags (CMD_FLAG_...) |
| 677 | * @param argc Number of subcommand arguments (0 = no arguments) |
| 678 | * @param argv Arguments |
| 679 | * @param states Mask containing states to run (BOOTM_STATE_...) |
| 680 | * @param images Image header information |
| 681 | * @param boot_progress 1 to show boot progress, 0 to not do this |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 682 | * Return: 0 if ok, something else on error. Some errors will cause this |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 683 | * function to perform a reboot! If states contains BOOTM_STATE_OS_GO |
| 684 | * then the intent is to boot an OS, so this function will not return |
| 685 | * unless the image type is standalone. |
| 686 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 687 | int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc, |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 688 | char *const argv[], int states, struct bootm_headers *images, |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 689 | int boot_progress) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 690 | { |
| 691 | boot_os_fn *boot_fn; |
| 692 | ulong iflag = 0; |
| 693 | int ret = 0, need_boot_fn; |
| 694 | |
| 695 | images->state |= states; |
| 696 | |
| 697 | /* |
| 698 | * Work through the states and see how far we get. We stop on |
| 699 | * any error. |
| 700 | */ |
| 701 | if (states & BOOTM_STATE_START) |
| 702 | ret = bootm_start(cmdtp, flag, argc, argv); |
| 703 | |
Philippe Reynes | ae1f2ca | 2022-03-28 22:57:00 +0200 | [diff] [blame] | 704 | if (!ret && (states & BOOTM_STATE_PRE_LOAD)) |
| 705 | ret = bootm_pre_load(cmdtp, flag, argc, argv); |
| 706 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 707 | if (!ret && (states & BOOTM_STATE_FINDOS)) |
| 708 | ret = bootm_find_os(cmdtp, flag, argc, argv); |
| 709 | |
Zubair Lutfullah Kakakhel | 31eb47d | 2016-09-09 09:18:58 +0100 | [diff] [blame] | 710 | if (!ret && (states & BOOTM_STATE_FINDOTHER)) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 711 | ret = bootm_find_other(cmdtp, flag, argc, argv); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 712 | |
| 713 | /* Load the OS */ |
| 714 | if (!ret && (states & BOOTM_STATE_LOADOS)) { |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 715 | iflag = bootm_disable_interrupts(); |
Tom Rini | 6c96f5d | 2018-05-01 12:32:37 -0400 | [diff] [blame] | 716 | ret = bootm_load_os(images, 0); |
| 717 | if (ret && ret != BOOTM_ERR_OVERLAP) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 718 | goto err; |
| 719 | else if (ret == BOOTM_ERR_OVERLAP) |
| 720 | ret = 0; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | /* Relocate the ramdisk */ |
| 724 | #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH |
| 725 | if (!ret && (states & BOOTM_STATE_RAMDISK)) { |
| 726 | ulong rd_len = images->rd_end - images->rd_start; |
| 727 | |
| 728 | ret = boot_ramdisk_high(&images->lmb, images->rd_start, |
| 729 | rd_len, &images->initrd_start, &images->initrd_end); |
| 730 | if (!ret) { |
Simon Glass | 4d949a2 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 731 | env_set_hex("initrd_start", images->initrd_start); |
| 732 | env_set_hex("initrd_end", images->initrd_end); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 733 | } |
| 734 | } |
| 735 | #endif |
Simon Glass | 85c057e | 2021-09-25 19:43:21 -0600 | [diff] [blame] | 736 | #if CONFIG_IS_ENABLED(OF_LIBFDT) && defined(CONFIG_LMB) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 737 | if (!ret && (states & BOOTM_STATE_FDT)) { |
| 738 | boot_fdt_add_mem_rsv_regions(&images->lmb, images->ft_addr); |
| 739 | ret = boot_relocate_fdt(&images->lmb, &images->ft_addr, |
| 740 | &images->ft_len); |
| 741 | } |
| 742 | #endif |
| 743 | |
| 744 | /* From now on, we need the OS boot function */ |
| 745 | if (ret) |
| 746 | return ret; |
| 747 | boot_fn = bootm_os_get_boot_func(images->os.os); |
| 748 | need_boot_fn = states & (BOOTM_STATE_OS_CMDLINE | |
| 749 | BOOTM_STATE_OS_BD_T | BOOTM_STATE_OS_PREP | |
| 750 | BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO); |
| 751 | if (boot_fn == NULL && need_boot_fn) { |
| 752 | if (iflag) |
| 753 | enable_interrupts(); |
| 754 | printf("ERROR: booting os '%s' (%d) is not supported\n", |
| 755 | genimg_get_os_name(images->os.os), images->os.os); |
| 756 | bootstage_error(BOOTSTAGE_ID_CHECK_BOOT_OS); |
| 757 | return 1; |
| 758 | } |
| 759 | |
Hector Palacios | 8f9cc4c | 2016-07-11 12:34:37 +0200 | [diff] [blame] | 760 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 761 | /* Call various other states that are not generally used */ |
| 762 | if (!ret && (states & BOOTM_STATE_OS_CMDLINE)) |
| 763 | ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, images); |
| 764 | if (!ret && (states & BOOTM_STATE_OS_BD_T)) |
| 765 | ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, images); |
Hector Palacios | 8f9cc4c | 2016-07-11 12:34:37 +0200 | [diff] [blame] | 766 | if (!ret && (states & BOOTM_STATE_OS_PREP)) { |
Simon Glass | 529e208 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 767 | ret = bootm_process_cmdline_env(images->os.os == IH_OS_LINUX); |
Simon Glass | d87002f | 2020-11-05 10:33:41 -0700 | [diff] [blame] | 768 | if (ret) { |
| 769 | printf("Cmdline setup failed (err=%d)\n", ret); |
| 770 | ret = CMD_RET_FAILURE; |
| 771 | goto err; |
Simon Glass | 2eab017 | 2020-11-05 10:33:39 -0700 | [diff] [blame] | 772 | } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 773 | ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, images); |
Hector Palacios | 8f9cc4c | 2016-07-11 12:34:37 +0200 | [diff] [blame] | 774 | } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 775 | |
| 776 | #ifdef CONFIG_TRACE |
| 777 | /* Pretend to run the OS, then run a user command */ |
| 778 | if (!ret && (states & BOOTM_STATE_OS_FAKE_GO)) { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 779 | char *cmd_list = env_get("fakegocmd"); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 780 | |
| 781 | ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_FAKE_GO, |
| 782 | images, boot_fn); |
| 783 | if (!ret && cmd_list) |
| 784 | ret = run_command_list(cmd_list, -1, flag); |
| 785 | } |
| 786 | #endif |
| 787 | |
| 788 | /* Check for unsupported subcommand. */ |
| 789 | if (ret) { |
Simon Glass | b90cf90 | 2022-10-11 09:47:07 -0600 | [diff] [blame] | 790 | printf("subcommand failed (err=%d)\n", ret); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 791 | return ret; |
| 792 | } |
| 793 | |
| 794 | /* Now run the OS! We hope this doesn't return */ |
| 795 | if (!ret && (states & BOOTM_STATE_OS_GO)) |
| 796 | ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_GO, |
| 797 | images, boot_fn); |
| 798 | |
| 799 | /* Deal with any fallout */ |
| 800 | err: |
| 801 | if (iflag) |
| 802 | enable_interrupts(); |
| 803 | |
| 804 | if (ret == BOOTM_ERR_UNIMPLEMENTED) |
| 805 | bootstage_error(BOOTSTAGE_ID_DECOMP_UNIMPL); |
| 806 | else if (ret == BOOTM_ERR_RESET) |
| 807 | do_reset(cmdtp, flag, argc, argv); |
| 808 | |
| 809 | return ret; |
| 810 | } |
| 811 | |
Tom Rini | c220bd9 | 2019-05-23 07:14:07 -0400 | [diff] [blame] | 812 | #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 813 | /** |
| 814 | * image_get_kernel - verify legacy format kernel image |
| 815 | * @img_addr: in RAM address of the legacy format image to be verified |
| 816 | * @verify: data CRC verification flag |
| 817 | * |
| 818 | * image_get_kernel() verifies legacy image integrity and returns pointer to |
| 819 | * legacy image header if image verification was completed successfully. |
| 820 | * |
| 821 | * returns: |
| 822 | * pointer to a legacy image header if valid image was found |
| 823 | * otherwise return NULL |
| 824 | */ |
Simon Glass | bb7d3bb | 2022-09-06 20:26:52 -0600 | [diff] [blame] | 825 | static struct legacy_img_hdr *image_get_kernel(ulong img_addr, int verify) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 826 | { |
Simon Glass | bb7d3bb | 2022-09-06 20:26:52 -0600 | [diff] [blame] | 827 | struct legacy_img_hdr *hdr = (struct legacy_img_hdr *)img_addr; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 828 | |
| 829 | if (!image_check_magic(hdr)) { |
| 830 | puts("Bad Magic Number\n"); |
| 831 | bootstage_error(BOOTSTAGE_ID_CHECK_MAGIC); |
| 832 | return NULL; |
| 833 | } |
| 834 | bootstage_mark(BOOTSTAGE_ID_CHECK_HEADER); |
| 835 | |
| 836 | if (!image_check_hcrc(hdr)) { |
| 837 | puts("Bad Header Checksum\n"); |
| 838 | bootstage_error(BOOTSTAGE_ID_CHECK_HEADER); |
| 839 | return NULL; |
| 840 | } |
| 841 | |
| 842 | bootstage_mark(BOOTSTAGE_ID_CHECK_CHECKSUM); |
| 843 | image_print_contents(hdr); |
| 844 | |
| 845 | if (verify) { |
| 846 | puts(" Verifying Checksum ... "); |
| 847 | if (!image_check_dcrc(hdr)) { |
| 848 | printf("Bad Data CRC\n"); |
| 849 | bootstage_error(BOOTSTAGE_ID_CHECK_CHECKSUM); |
| 850 | return NULL; |
| 851 | } |
| 852 | puts("OK\n"); |
| 853 | } |
| 854 | bootstage_mark(BOOTSTAGE_ID_CHECK_ARCH); |
| 855 | |
| 856 | if (!image_check_target_arch(hdr)) { |
| 857 | printf("Unsupported Architecture 0x%x\n", image_get_arch(hdr)); |
| 858 | bootstage_error(BOOTSTAGE_ID_CHECK_ARCH); |
| 859 | return NULL; |
| 860 | } |
| 861 | return hdr; |
| 862 | } |
| 863 | #endif |
| 864 | |
| 865 | /** |
| 866 | * boot_get_kernel - find kernel image |
| 867 | * @os_data: pointer to a ulong variable, will hold os data start address |
| 868 | * @os_len: pointer to a ulong variable, will hold os data length |
| 869 | * |
| 870 | * boot_get_kernel() tries to find a kernel image, verifies its integrity |
| 871 | * and locates kernel data. |
| 872 | * |
| 873 | * returns: |
| 874 | * pointer to image header if valid image was found, plus kernel start |
| 875 | * address and length, otherwise NULL |
| 876 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 877 | static const void *boot_get_kernel(struct cmd_tbl *cmdtp, int flag, int argc, |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 878 | char *const argv[], struct bootm_headers *images, |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 879 | ulong *os_data, ulong *os_len) |
| 880 | { |
Tom Rini | c220bd9 | 2019-05-23 07:14:07 -0400 | [diff] [blame] | 881 | #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) |
Simon Glass | bb7d3bb | 2022-09-06 20:26:52 -0600 | [diff] [blame] | 882 | struct legacy_img_hdr *hdr; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 883 | #endif |
| 884 | ulong img_addr; |
| 885 | const void *buf; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 886 | const char *fit_uname_config = NULL; |
| 887 | const char *fit_uname_kernel = NULL; |
Simon Glass | e719d3b | 2021-09-25 19:43:20 -0600 | [diff] [blame] | 888 | #if CONFIG_IS_ENABLED(FIT) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 889 | int os_noffset; |
| 890 | #endif |
| 891 | |
Bryan Wu | c82ea37 | 2014-08-15 16:51:39 -0700 | [diff] [blame] | 892 | img_addr = genimg_get_kernel_addr_fit(argc < 1 ? NULL : argv[0], |
| 893 | &fit_uname_config, |
| 894 | &fit_uname_kernel); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 895 | |
Simon Glass | 88b6f92 | 2023-02-05 15:36:24 -0700 | [diff] [blame] | 896 | if (IS_ENABLED(CONFIG_CMD_BOOTM_PRE_LOAD)) |
Philippe Reynes | ae1f2ca | 2022-03-28 22:57:00 +0200 | [diff] [blame] | 897 | img_addr += image_load_offset; |
| 898 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 899 | bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC); |
| 900 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 901 | /* check image type, for FIT images get FIT kernel node */ |
| 902 | *os_data = *os_len = 0; |
| 903 | buf = map_sysmem(img_addr, 0); |
| 904 | switch (genimg_get_format(buf)) { |
Tom Rini | c220bd9 | 2019-05-23 07:14:07 -0400 | [diff] [blame] | 905 | #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 906 | case IMAGE_FORMAT_LEGACY: |
| 907 | printf("## Booting kernel from Legacy Image at %08lx ...\n", |
| 908 | img_addr); |
| 909 | hdr = image_get_kernel(img_addr, images->verify); |
| 910 | if (!hdr) |
| 911 | return NULL; |
| 912 | bootstage_mark(BOOTSTAGE_ID_CHECK_IMAGETYPE); |
| 913 | |
| 914 | /* get os_data and os_len */ |
| 915 | switch (image_get_type(hdr)) { |
| 916 | case IH_TYPE_KERNEL: |
| 917 | case IH_TYPE_KERNEL_NOLOAD: |
| 918 | *os_data = image_get_data(hdr); |
| 919 | *os_len = image_get_data_size(hdr); |
| 920 | break; |
| 921 | case IH_TYPE_MULTI: |
| 922 | image_multi_getimg(hdr, 0, os_data, os_len); |
| 923 | break; |
| 924 | case IH_TYPE_STANDALONE: |
| 925 | *os_data = image_get_data(hdr); |
| 926 | *os_len = image_get_data_size(hdr); |
| 927 | break; |
| 928 | default: |
| 929 | printf("Wrong Image Type for %s command\n", |
| 930 | cmdtp->name); |
| 931 | bootstage_error(BOOTSTAGE_ID_CHECK_IMAGETYPE); |
| 932 | return NULL; |
| 933 | } |
| 934 | |
| 935 | /* |
| 936 | * copy image header to allow for image overwrites during |
| 937 | * kernel decompression. |
| 938 | */ |
| 939 | memmove(&images->legacy_hdr_os_copy, hdr, |
Simon Glass | bb7d3bb | 2022-09-06 20:26:52 -0600 | [diff] [blame] | 940 | sizeof(struct legacy_img_hdr)); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 941 | |
| 942 | /* save pointer to image header */ |
| 943 | images->legacy_hdr_os = hdr; |
| 944 | |
| 945 | images->legacy_hdr_valid = 1; |
| 946 | bootstage_mark(BOOTSTAGE_ID_DECOMP_IMAGE); |
| 947 | break; |
| 948 | #endif |
Simon Glass | e719d3b | 2021-09-25 19:43:20 -0600 | [diff] [blame] | 949 | #if CONFIG_IS_ENABLED(FIT) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 950 | case IMAGE_FORMAT_FIT: |
Simon Glass | a0c0b63 | 2014-06-12 07:24:47 -0600 | [diff] [blame] | 951 | os_noffset = fit_image_load(images, img_addr, |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 952 | &fit_uname_kernel, &fit_uname_config, |
| 953 | IH_ARCH_DEFAULT, IH_TYPE_KERNEL, |
| 954 | BOOTSTAGE_ID_FIT_KERNEL_START, |
| 955 | FIT_LOAD_IGNORED, os_data, os_len); |
| 956 | if (os_noffset < 0) |
| 957 | return NULL; |
| 958 | |
| 959 | images->fit_hdr_os = map_sysmem(img_addr, 0); |
| 960 | images->fit_uname_os = fit_uname_kernel; |
| 961 | images->fit_uname_cfg = fit_uname_config; |
| 962 | images->fit_noffset_os = os_noffset; |
| 963 | break; |
| 964 | #endif |
| 965 | #ifdef CONFIG_ANDROID_BOOT_IMAGE |
| 966 | case IMAGE_FORMAT_ANDROID: |
| 967 | printf("## Booting Android Image at 0x%08lx ...\n", img_addr); |
Simon Glass | 9504010 | 2014-06-12 07:24:48 -0600 | [diff] [blame] | 968 | if (android_image_get_kernel(buf, images->verify, |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 969 | os_data, os_len)) |
| 970 | return NULL; |
| 971 | break; |
| 972 | #endif |
| 973 | default: |
| 974 | printf("Wrong Image Format for %s command\n", cmdtp->name); |
| 975 | bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO); |
| 976 | return NULL; |
| 977 | } |
| 978 | |
| 979 | debug(" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n", |
| 980 | *os_data, *os_len, *os_len); |
| 981 | |
| 982 | return buf; |
| 983 | } |
Heinrich Schuchardt | aa0b11b | 2019-01-08 18:13:06 +0100 | [diff] [blame] | 984 | |
| 985 | /** |
| 986 | * switch_to_non_secure_mode() - switch to non-secure mode |
| 987 | * |
| 988 | * This routine is overridden by architectures requiring this feature. |
| 989 | */ |
| 990 | void __weak switch_to_non_secure_mode(void) |
| 991 | { |
| 992 | } |
| 993 | |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 994 | #else /* USE_HOSTCC */ |
| 995 | |
Fabrice Fontaine | d00d6b5 | 2019-05-03 22:37:05 +0200 | [diff] [blame] | 996 | #if defined(CONFIG_FIT_SIGNATURE) |
Simon Glass | 81d1387 | 2020-03-18 11:44:02 -0600 | [diff] [blame] | 997 | static int bootm_host_load_image(const void *fit, int req_image_type, |
| 998 | int cfg_noffset) |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 999 | { |
| 1000 | const char *fit_uname_config = NULL; |
| 1001 | ulong data, len; |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 1002 | struct bootm_headers images; |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1003 | int noffset; |
Tom Rini | f3c2f99 | 2022-06-25 19:29:46 -0400 | [diff] [blame] | 1004 | ulong load_end, buf_size; |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1005 | uint8_t image_type; |
Daniel Golle | 905d4b7 | 2022-08-27 04:14:42 +0100 | [diff] [blame] | 1006 | uint8_t image_comp; |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1007 | void *load_buf; |
| 1008 | int ret; |
| 1009 | |
Simon Glass | 81d1387 | 2020-03-18 11:44:02 -0600 | [diff] [blame] | 1010 | fit_uname_config = fdt_get_name(fit, cfg_noffset, NULL); |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1011 | memset(&images, '\0', sizeof(images)); |
| 1012 | images.verify = 1; |
| 1013 | noffset = fit_image_load(&images, (ulong)fit, |
| 1014 | NULL, &fit_uname_config, |
| 1015 | IH_ARCH_DEFAULT, req_image_type, -1, |
| 1016 | FIT_LOAD_IGNORED, &data, &len); |
| 1017 | if (noffset < 0) |
| 1018 | return noffset; |
| 1019 | if (fit_image_get_type(fit, noffset, &image_type)) { |
| 1020 | puts("Can't get image type!\n"); |
| 1021 | return -EINVAL; |
| 1022 | } |
| 1023 | |
Daniel Golle | 2ebfd22 | 2022-08-27 04:17:28 +0100 | [diff] [blame] | 1024 | if (fit_image_get_comp(fit, noffset, &image_comp)) |
| 1025 | image_comp = IH_COMP_NONE; |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1026 | |
| 1027 | /* Allow the image to expand by a factor of 4, should be safe */ |
Tom Rini | f3c2f99 | 2022-06-25 19:29:46 -0400 | [diff] [blame] | 1028 | buf_size = (1 << 20) + len * 4; |
| 1029 | load_buf = malloc(buf_size); |
Daniel Golle | 905d4b7 | 2022-08-27 04:14:42 +0100 | [diff] [blame] | 1030 | ret = image_decomp(image_comp, 0, data, image_type, load_buf, |
Tom Rini | f3c2f99 | 2022-06-25 19:29:46 -0400 | [diff] [blame] | 1031 | (void *)data, len, buf_size, &load_end); |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1032 | free(load_buf); |
Simon Glass | 5aeccc2 | 2014-12-02 13:17:33 -0700 | [diff] [blame] | 1033 | |
Julius Werner | 47ef986 | 2019-07-24 19:37:54 -0700 | [diff] [blame] | 1034 | if (ret) { |
Daniel Golle | 905d4b7 | 2022-08-27 04:14:42 +0100 | [diff] [blame] | 1035 | ret = handle_decomp_error(image_comp, load_end - 0, buf_size, ret); |
Julius Werner | 47ef986 | 2019-07-24 19:37:54 -0700 | [diff] [blame] | 1036 | if (ret != BOOTM_ERR_UNIMPLEMENTED) |
| 1037 | return ret; |
| 1038 | } |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1039 | |
| 1040 | return 0; |
| 1041 | } |
| 1042 | |
| 1043 | int bootm_host_load_images(const void *fit, int cfg_noffset) |
| 1044 | { |
| 1045 | static uint8_t image_types[] = { |
| 1046 | IH_TYPE_KERNEL, |
| 1047 | IH_TYPE_FLATDT, |
| 1048 | IH_TYPE_RAMDISK, |
| 1049 | }; |
| 1050 | int err = 0; |
| 1051 | int i; |
| 1052 | |
| 1053 | for (i = 0; i < ARRAY_SIZE(image_types); i++) { |
| 1054 | int ret; |
| 1055 | |
Simon Glass | 81d1387 | 2020-03-18 11:44:02 -0600 | [diff] [blame] | 1056 | ret = bootm_host_load_image(fit, image_types[i], cfg_noffset); |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1057 | if (!err && ret && ret != -ENOENT) |
| 1058 | err = ret; |
| 1059 | } |
| 1060 | |
| 1061 | /* Return the first error we found */ |
| 1062 | return err; |
| 1063 | } |
Fabrice Fontaine | d00d6b5 | 2019-05-03 22:37:05 +0200 | [diff] [blame] | 1064 | #endif |
Simon Glass | 0232ba7 | 2014-06-12 07:24:51 -0600 | [diff] [blame] | 1065 | |
| 1066 | #endif /* ndef USE_HOSTCC */ |