Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | b639640 | 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 | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
Simon Glass | ea51a62 | 2014-06-12 07:24:51 -0600 | [diff] [blame] | 7 | #ifndef USE_HOSTCC |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 8 | #include <common.h> |
Simon Glass | a48336e | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 9 | #include <bootm.h> |
Simon Glass | ea51a62 | 2014-06-12 07:24:51 -0600 | [diff] [blame] | 10 | #include <bootstage.h> |
Simon Glass | 51bb338 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 11 | #include <cli.h> |
Simon Glass | be59514 | 2023-09-27 08:22:37 -0600 | [diff] [blame] | 12 | #include <command.h> |
Simon Glass | 1eb69ae | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 13 | #include <cpu_func.h> |
Simon Glass | c7694dd | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 14 | #include <env.h> |
Simon Glass | 90268b8 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 15 | #include <errno.h> |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 16 | #include <fdt_support.h> |
Simon Glass | 36bf446 | 2019-11-14 12:57:42 -0700 | [diff] [blame] | 17 | #include <irq_func.h> |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 18 | #include <lmb.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 19 | #include <log.h> |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 20 | #include <malloc.h> |
Joe Hershberger | 0eb25b6 | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 21 | #include <mapmem.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 22 | #include <net.h> |
| 23 | #include <asm/cache.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 24 | #include <asm/global_data.h> |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 25 | #include <asm/io.h> |
Simon Glass | b6386f3 | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 26 | #include <linux/sizes.h> |
Eddie James | dec166d | 2023-10-24 10:43:50 -0500 | [diff] [blame] | 27 | #include <tpm-v2.h> |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 28 | #if defined(CONFIG_CMD_USB) |
| 29 | #include <usb.h> |
| 30 | #endif |
Simon Glass | ea51a62 | 2014-06-12 07:24:51 -0600 | [diff] [blame] | 31 | #else |
| 32 | #include "mkimage.h" |
| 33 | #endif |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 34 | |
Simon Glass | ea51a62 | 2014-06-12 07:24:51 -0600 | [diff] [blame] | 35 | #include <bootm.h> |
| 36 | #include <image.h> |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 37 | |
Simon Glass | b6386f3 | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 38 | #define MAX_CMDLINE_SIZE SZ_4K |
| 39 | |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 40 | #define IH_INITRD_ARCH IH_ARCH_DEFAULT |
| 41 | |
Simon Glass | ea51a62 | 2014-06-12 07:24:51 -0600 | [diff] [blame] | 42 | #ifndef USE_HOSTCC |
| 43 | |
| 44 | DECLARE_GLOBAL_DATA_PTR; |
| 45 | |
Simon Glass | d9d7c20 | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 46 | struct bootm_headers images; /* pointers to os/initrd/fdt images */ |
Tom Rini | 5db2890 | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 47 | |
Simon Glass | 329da48 | 2018-05-16 09:42:25 -0600 | [diff] [blame] | 48 | __weak void board_quiesce_devices(void) |
| 49 | { |
| 50 | } |
| 51 | |
Simon Glass | 7f3b1ee | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 52 | #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) |
| 53 | /** |
| 54 | * image_get_kernel - verify legacy format kernel image |
| 55 | * @img_addr: in RAM address of the legacy format image to be verified |
| 56 | * @verify: data CRC verification flag |
| 57 | * |
| 58 | * image_get_kernel() verifies legacy image integrity and returns pointer to |
| 59 | * legacy image header if image verification was completed successfully. |
| 60 | * |
| 61 | * returns: |
| 62 | * pointer to a legacy image header if valid image was found |
| 63 | * otherwise return NULL |
| 64 | */ |
| 65 | static struct legacy_img_hdr *image_get_kernel(ulong img_addr, int verify) |
| 66 | { |
| 67 | struct legacy_img_hdr *hdr = (struct legacy_img_hdr *)img_addr; |
| 68 | |
| 69 | if (!image_check_magic(hdr)) { |
| 70 | puts("Bad Magic Number\n"); |
| 71 | bootstage_error(BOOTSTAGE_ID_CHECK_MAGIC); |
| 72 | return NULL; |
| 73 | } |
| 74 | bootstage_mark(BOOTSTAGE_ID_CHECK_HEADER); |
| 75 | |
| 76 | if (!image_check_hcrc(hdr)) { |
| 77 | puts("Bad Header Checksum\n"); |
| 78 | bootstage_error(BOOTSTAGE_ID_CHECK_HEADER); |
| 79 | return NULL; |
| 80 | } |
| 81 | |
| 82 | bootstage_mark(BOOTSTAGE_ID_CHECK_CHECKSUM); |
| 83 | image_print_contents(hdr); |
| 84 | |
| 85 | if (verify) { |
| 86 | puts(" Verifying Checksum ... "); |
| 87 | if (!image_check_dcrc(hdr)) { |
| 88 | printf("Bad Data CRC\n"); |
| 89 | bootstage_error(BOOTSTAGE_ID_CHECK_CHECKSUM); |
| 90 | return NULL; |
| 91 | } |
| 92 | puts("OK\n"); |
| 93 | } |
| 94 | bootstage_mark(BOOTSTAGE_ID_CHECK_ARCH); |
| 95 | |
| 96 | if (!image_check_target_arch(hdr)) { |
| 97 | printf("Unsupported Architecture 0x%x\n", image_get_arch(hdr)); |
| 98 | bootstage_error(BOOTSTAGE_ID_CHECK_ARCH); |
| 99 | return NULL; |
| 100 | } |
| 101 | return hdr; |
| 102 | } |
| 103 | #endif |
| 104 | |
| 105 | /** |
Simon Glass | 820110c | 2023-11-18 14:04:58 -0700 | [diff] [blame] | 106 | * boot_get_kernel() - find kernel image |
| 107 | * |
Simon Glass | 820110c | 2023-11-18 14:04:58 -0700 | [diff] [blame] | 108 | * @addr_fit: first argument to bootm: address, fit configuration, etc. |
Simon Glass | 7f3b1ee | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 109 | * @os_data: pointer to a ulong variable, will hold os data start address |
| 110 | * @os_len: pointer to a ulong variable, will hold os data length |
Simon Glass | 820110c | 2023-11-18 14:04:58 -0700 | [diff] [blame] | 111 | * address and length, otherwise NULL |
| 112 | * pointer to image header if valid image was found, plus kernel start |
Simon Glass | 7721e71 | 2023-11-18 14:05:00 -0700 | [diff] [blame] | 113 | * @kernp: image header if valid image was found, otherwise NULL |
Simon Glass | 7f3b1ee | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 114 | * |
| 115 | * boot_get_kernel() tries to find a kernel image, verifies its integrity |
| 116 | * and locates kernel data. |
| 117 | * |
Simon Glass | b13e948 | 2023-11-18 14:05:04 -0700 | [diff] [blame] | 118 | * Return: 0 on success, -ve on error. -EPROTOTYPE means that the image is in |
| 119 | * a wrong or unsupported format |
Simon Glass | 7f3b1ee | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 120 | */ |
Simon Glass | b13e948 | 2023-11-18 14:05:04 -0700 | [diff] [blame] | 121 | static int boot_get_kernel(const char *addr_fit, struct bootm_headers *images, |
| 122 | ulong *os_data, ulong *os_len, const void **kernp) |
Simon Glass | 7f3b1ee | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 123 | { |
| 124 | #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) |
| 125 | struct legacy_img_hdr *hdr; |
| 126 | #endif |
| 127 | ulong img_addr; |
| 128 | const void *buf; |
Simon Glass | 530cc47 | 2023-11-18 14:04:57 -0700 | [diff] [blame] | 129 | const char *fit_uname_config = NULL, *fit_uname_kernel = NULL; |
Simon Glass | 7f3b1ee | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 130 | #if CONFIG_IS_ENABLED(FIT) |
| 131 | int os_noffset; |
| 132 | #endif |
| 133 | |
| 134 | #ifdef CONFIG_ANDROID_BOOT_IMAGE |
| 135 | const void *boot_img; |
| 136 | const void *vendor_boot_img; |
| 137 | #endif |
Simon Glass | 820110c | 2023-11-18 14:04:58 -0700 | [diff] [blame] | 138 | img_addr = genimg_get_kernel_addr_fit(addr_fit, &fit_uname_config, |
Simon Glass | 7f3b1ee | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 139 | &fit_uname_kernel); |
| 140 | |
| 141 | if (IS_ENABLED(CONFIG_CMD_BOOTM_PRE_LOAD)) |
| 142 | img_addr += image_load_offset; |
| 143 | |
| 144 | bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC); |
| 145 | |
| 146 | /* check image type, for FIT images get FIT kernel node */ |
| 147 | *os_data = *os_len = 0; |
| 148 | buf = map_sysmem(img_addr, 0); |
| 149 | switch (genimg_get_format(buf)) { |
| 150 | #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) |
| 151 | case IMAGE_FORMAT_LEGACY: |
| 152 | printf("## Booting kernel from Legacy Image at %08lx ...\n", |
| 153 | img_addr); |
| 154 | hdr = image_get_kernel(img_addr, images->verify); |
| 155 | if (!hdr) |
Simon Glass | 7721e71 | 2023-11-18 14:05:00 -0700 | [diff] [blame] | 156 | return -EINVAL; |
Simon Glass | 7f3b1ee | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 157 | bootstage_mark(BOOTSTAGE_ID_CHECK_IMAGETYPE); |
| 158 | |
| 159 | /* get os_data and os_len */ |
| 160 | switch (image_get_type(hdr)) { |
| 161 | case IH_TYPE_KERNEL: |
| 162 | case IH_TYPE_KERNEL_NOLOAD: |
| 163 | *os_data = image_get_data(hdr); |
| 164 | *os_len = image_get_data_size(hdr); |
| 165 | break; |
| 166 | case IH_TYPE_MULTI: |
| 167 | image_multi_getimg(hdr, 0, os_data, os_len); |
| 168 | break; |
| 169 | case IH_TYPE_STANDALONE: |
| 170 | *os_data = image_get_data(hdr); |
| 171 | *os_len = image_get_data_size(hdr); |
| 172 | break; |
| 173 | default: |
Simon Glass | 7f3b1ee | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 174 | bootstage_error(BOOTSTAGE_ID_CHECK_IMAGETYPE); |
Simon Glass | 7721e71 | 2023-11-18 14:05:00 -0700 | [diff] [blame] | 175 | return -EPROTOTYPE; |
Simon Glass | 7f3b1ee | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /* |
| 179 | * copy image header to allow for image overwrites during |
| 180 | * kernel decompression. |
| 181 | */ |
| 182 | memmove(&images->legacy_hdr_os_copy, hdr, |
| 183 | sizeof(struct legacy_img_hdr)); |
| 184 | |
| 185 | /* save pointer to image header */ |
| 186 | images->legacy_hdr_os = hdr; |
| 187 | |
| 188 | images->legacy_hdr_valid = 1; |
| 189 | bootstage_mark(BOOTSTAGE_ID_DECOMP_IMAGE); |
| 190 | break; |
| 191 | #endif |
| 192 | #if CONFIG_IS_ENABLED(FIT) |
| 193 | case IMAGE_FORMAT_FIT: |
| 194 | os_noffset = fit_image_load(images, img_addr, |
| 195 | &fit_uname_kernel, &fit_uname_config, |
| 196 | IH_ARCH_DEFAULT, IH_TYPE_KERNEL, |
| 197 | BOOTSTAGE_ID_FIT_KERNEL_START, |
| 198 | FIT_LOAD_IGNORED, os_data, os_len); |
| 199 | if (os_noffset < 0) |
Simon Glass | 7721e71 | 2023-11-18 14:05:00 -0700 | [diff] [blame] | 200 | return -ENOENT; |
Simon Glass | 7f3b1ee | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 201 | |
| 202 | images->fit_hdr_os = map_sysmem(img_addr, 0); |
| 203 | images->fit_uname_os = fit_uname_kernel; |
| 204 | images->fit_uname_cfg = fit_uname_config; |
| 205 | images->fit_noffset_os = os_noffset; |
| 206 | break; |
| 207 | #endif |
| 208 | #ifdef CONFIG_ANDROID_BOOT_IMAGE |
Simon Glass | 7721e71 | 2023-11-18 14:05:00 -0700 | [diff] [blame] | 209 | case IMAGE_FORMAT_ANDROID: { |
| 210 | int ret; |
| 211 | |
Simon Glass | 7f3b1ee | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 212 | boot_img = buf; |
| 213 | vendor_boot_img = NULL; |
| 214 | if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) { |
| 215 | boot_img = map_sysmem(get_abootimg_addr(), 0); |
| 216 | vendor_boot_img = map_sysmem(get_avendor_bootimg_addr(), 0); |
| 217 | } |
| 218 | printf("## Booting Android Image at 0x%08lx ...\n", img_addr); |
Simon Glass | 7721e71 | 2023-11-18 14:05:00 -0700 | [diff] [blame] | 219 | ret = android_image_get_kernel(boot_img, vendor_boot_img, |
| 220 | images->verify, os_data, os_len); |
Simon Glass | 7f3b1ee | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 221 | if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) { |
| 222 | unmap_sysmem(vendor_boot_img); |
| 223 | unmap_sysmem(boot_img); |
| 224 | } |
Simon Glass | 4f77169 | 2023-11-18 14:05:01 -0700 | [diff] [blame] | 225 | if (ret) |
| 226 | return ret; |
Simon Glass | 7f3b1ee | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 227 | break; |
Simon Glass | 7721e71 | 2023-11-18 14:05:00 -0700 | [diff] [blame] | 228 | } |
Simon Glass | 7f3b1ee | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 229 | #endif |
| 230 | default: |
Simon Glass | bdfa1b6 | 2023-11-18 14:05:03 -0700 | [diff] [blame] | 231 | bootstage_error(BOOTSTAGE_ID_CHECK_IMAGETYPE); |
Simon Glass | b13e948 | 2023-11-18 14:05:04 -0700 | [diff] [blame] | 232 | return -EPROTOTYPE; |
Simon Glass | 7f3b1ee | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | debug(" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n", |
| 236 | *os_data, *os_len, *os_len); |
Simon Glass | 7721e71 | 2023-11-18 14:05:00 -0700 | [diff] [blame] | 237 | *kernp = buf; |
Simon Glass | 7f3b1ee | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 238 | |
Simon Glass | 7721e71 | 2023-11-18 14:05:00 -0700 | [diff] [blame] | 239 | return 0; |
Simon Glass | 7f3b1ee | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 242 | #ifdef CONFIG_LMB |
Simon Glass | d9d7c20 | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 243 | static void boot_start_lmb(struct bootm_headers *images) |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 244 | { |
| 245 | ulong mem_start; |
| 246 | phys_size_t mem_size; |
| 247 | |
Simon Glass | 723806c | 2017-08-03 12:22:15 -0600 | [diff] [blame] | 248 | mem_start = env_get_bootm_low(); |
| 249 | mem_size = env_get_bootm_size(); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 250 | |
Simon Goldschmidt | 9cc2323 | 2019-01-26 22:13:04 +0100 | [diff] [blame] | 251 | lmb_init_and_reserve_range(&images->lmb, (phys_addr_t)mem_start, |
| 252 | mem_size, NULL); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 253 | } |
| 254 | #else |
| 255 | #define lmb_reserve(lmb, base, size) |
Simon Glass | d9d7c20 | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 256 | static inline void boot_start_lmb(struct bootm_headers *images) { } |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 257 | #endif |
| 258 | |
Simon Glass | a50e886 | 2023-11-18 14:04:54 -0700 | [diff] [blame] | 259 | static int bootm_start(void) |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 260 | { |
| 261 | memset((void *)&images, 0, sizeof(images)); |
Simon Glass | bfebc8c | 2017-08-03 12:22:13 -0600 | [diff] [blame] | 262 | images.verify = env_get_yesno("verify"); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 263 | |
| 264 | boot_start_lmb(&images); |
| 265 | |
| 266 | bootstage_mark_name(BOOTSTAGE_ID_BOOTM_START, "bootm_start"); |
| 267 | images.state = BOOTM_STATE_START; |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
Simon Glass | 921070b | 2023-11-18 14:04:55 -0700 | [diff] [blame] | 272 | static ulong bootm_data_addr(const char *addr_str) |
Philippe Reynes | 9d46e63 | 2022-03-28 22:57:00 +0200 | [diff] [blame] | 273 | { |
| 274 | ulong addr; |
| 275 | |
Simon Glass | 921070b | 2023-11-18 14:04:55 -0700 | [diff] [blame] | 276 | if (addr_str) |
| 277 | addr = hextoul(addr_str, NULL); |
Philippe Reynes | 9d46e63 | 2022-03-28 22:57:00 +0200 | [diff] [blame] | 278 | else |
| 279 | addr = image_load_addr; |
| 280 | |
| 281 | return addr; |
| 282 | } |
| 283 | |
Simon Glass | 921070b | 2023-11-18 14:04:55 -0700 | [diff] [blame] | 284 | /** |
| 285 | * bootm_pre_load() - Handle the pre-load processing |
| 286 | * |
| 287 | * This can be used to do a full signature check of the image, for example. |
| 288 | * It calls image_pre_load() with the data address of the image to check. |
| 289 | * |
| 290 | * @addr_str: String containing load address in hex, or NULL to use |
| 291 | * image_load_addr |
| 292 | * Return: 0 if OK, CMD_RET_FAILURE on failure |
| 293 | */ |
| 294 | static int bootm_pre_load(const char *addr_str) |
Philippe Reynes | 9d46e63 | 2022-03-28 22:57:00 +0200 | [diff] [blame] | 295 | { |
Simon Glass | 921070b | 2023-11-18 14:04:55 -0700 | [diff] [blame] | 296 | ulong data_addr = bootm_data_addr(addr_str); |
Philippe Reynes | 9d46e63 | 2022-03-28 22:57:00 +0200 | [diff] [blame] | 297 | int ret = 0; |
| 298 | |
Simon Glass | 494bcf1 | 2023-02-05 15:36:24 -0700 | [diff] [blame] | 299 | if (IS_ENABLED(CONFIG_CMD_BOOTM_PRE_LOAD)) |
Philippe Reynes | 9d46e63 | 2022-03-28 22:57:00 +0200 | [diff] [blame] | 300 | ret = image_pre_load(data_addr); |
| 301 | |
| 302 | if (ret) |
| 303 | ret = CMD_RET_FAILURE; |
| 304 | |
| 305 | return ret; |
| 306 | } |
| 307 | |
Simon Glass | 3e3bd5b | 2023-11-18 14:05:05 -0700 | [diff] [blame] | 308 | /** |
| 309 | * bootm_find_os(): Find the OS to boot |
| 310 | * |
| 311 | * @cmd_name: Command name that started this boot, e.g. "bootm" |
| 312 | * @addr_fit: Address and/or FIT specifier (first arg of bootm command) |
| 313 | * Return: 0 on success, -ve on error |
| 314 | */ |
| 315 | static int bootm_find_os(const char *cmd_name, const char *addr_fit) |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 316 | { |
| 317 | const void *os_hdr; |
Safae Ouajih | 636da20 | 2023-02-06 00:50:17 +0100 | [diff] [blame] | 318 | #ifdef CONFIG_ANDROID_BOOT_IMAGE |
| 319 | const void *vendor_boot_img; |
| 320 | const void *boot_img; |
| 321 | #endif |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 322 | bool ep_found = false; |
Simon Glass | 90268b8 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 323 | int ret; |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 324 | |
| 325 | /* get kernel image header, start address and length */ |
Simon Glass | 3e3bd5b | 2023-11-18 14:05:05 -0700 | [diff] [blame] | 326 | ret = boot_get_kernel(addr_fit, &images, &images.os.image_start, |
Simon Glass | b13e948 | 2023-11-18 14:05:04 -0700 | [diff] [blame] | 327 | &images.os.image_len, &os_hdr); |
Simon Glass | 4c76f5e | 2023-11-18 14:05:02 -0700 | [diff] [blame] | 328 | if (ret) { |
Simon Glass | b13e948 | 2023-11-18 14:05:04 -0700 | [diff] [blame] | 329 | if (ret == -EPROTOTYPE) |
Simon Glass | 3e3bd5b | 2023-11-18 14:05:05 -0700 | [diff] [blame] | 330 | printf("Wrong Image Type for %s command\n", cmd_name); |
Simon Glass | b13e948 | 2023-11-18 14:05:04 -0700 | [diff] [blame] | 331 | |
Simon Glass | 4c76f5e | 2023-11-18 14:05:02 -0700 | [diff] [blame] | 332 | printf("ERROR %dE: can't get kernel image!\n", ret); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 333 | return 1; |
| 334 | } |
| 335 | |
| 336 | /* get image parameters */ |
| 337 | switch (genimg_get_format(os_hdr)) { |
Tom Rini | c76c93a | 2019-05-23 07:14:07 -0400 | [diff] [blame] | 338 | #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 339 | case IMAGE_FORMAT_LEGACY: |
| 340 | images.os.type = image_get_type(os_hdr); |
| 341 | images.os.comp = image_get_comp(os_hdr); |
| 342 | images.os.os = image_get_os(os_hdr); |
| 343 | |
| 344 | images.os.end = image_get_image_end(os_hdr); |
| 345 | images.os.load = image_get_load(os_hdr); |
Simon Glass | 90268b8 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 346 | images.os.arch = image_get_arch(os_hdr); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 347 | break; |
| 348 | #endif |
Simon Glass | bf371b4 | 2021-09-25 19:43:20 -0600 | [diff] [blame] | 349 | #if CONFIG_IS_ENABLED(FIT) |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 350 | case IMAGE_FORMAT_FIT: |
| 351 | if (fit_image_get_type(images.fit_hdr_os, |
| 352 | images.fit_noffset_os, |
| 353 | &images.os.type)) { |
| 354 | puts("Can't get image type!\n"); |
| 355 | bootstage_error(BOOTSTAGE_ID_FIT_TYPE); |
| 356 | return 1; |
| 357 | } |
| 358 | |
| 359 | if (fit_image_get_comp(images.fit_hdr_os, |
| 360 | images.fit_noffset_os, |
| 361 | &images.os.comp)) { |
| 362 | puts("Can't get image compression!\n"); |
| 363 | bootstage_error(BOOTSTAGE_ID_FIT_COMPRESSION); |
| 364 | return 1; |
| 365 | } |
| 366 | |
| 367 | if (fit_image_get_os(images.fit_hdr_os, images.fit_noffset_os, |
| 368 | &images.os.os)) { |
| 369 | puts("Can't get image OS!\n"); |
| 370 | bootstage_error(BOOTSTAGE_ID_FIT_OS); |
| 371 | return 1; |
| 372 | } |
| 373 | |
Simon Glass | 90268b8 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 374 | if (fit_image_get_arch(images.fit_hdr_os, |
| 375 | images.fit_noffset_os, |
| 376 | &images.os.arch)) { |
| 377 | puts("Can't get image ARCH!\n"); |
| 378 | return 1; |
| 379 | } |
| 380 | |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 381 | images.os.end = fit_get_end(images.fit_hdr_os); |
| 382 | |
| 383 | if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os, |
| 384 | &images.os.load)) { |
| 385 | puts("Can't get image load address!\n"); |
| 386 | bootstage_error(BOOTSTAGE_ID_FIT_LOADADDR); |
| 387 | return 1; |
| 388 | } |
| 389 | break; |
| 390 | #endif |
| 391 | #ifdef CONFIG_ANDROID_BOOT_IMAGE |
| 392 | case IMAGE_FORMAT_ANDROID: |
Safae Ouajih | 636da20 | 2023-02-06 00:50:17 +0100 | [diff] [blame] | 393 | boot_img = os_hdr; |
| 394 | vendor_boot_img = NULL; |
| 395 | if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) { |
| 396 | boot_img = map_sysmem(get_abootimg_addr(), 0); |
| 397 | vendor_boot_img = map_sysmem(get_avendor_bootimg_addr(), 0); |
| 398 | } |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 399 | images.os.type = IH_TYPE_KERNEL; |
Safae Ouajih | 636da20 | 2023-02-06 00:50:17 +0100 | [diff] [blame] | 400 | images.os.comp = android_image_get_kcomp(boot_img, vendor_boot_img); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 401 | images.os.os = IH_OS_LINUX; |
Safae Ouajih | 636da20 | 2023-02-06 00:50:17 +0100 | [diff] [blame] | 402 | images.os.end = android_image_get_end(boot_img, vendor_boot_img); |
| 403 | images.os.load = android_image_get_kload(boot_img, vendor_boot_img); |
Ahmad Draidi | 86f4695 | 2014-10-23 20:50:07 +0300 | [diff] [blame] | 404 | images.ep = images.os.load; |
| 405 | ep_found = true; |
Safae Ouajih | 636da20 | 2023-02-06 00:50:17 +0100 | [diff] [blame] | 406 | if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) { |
| 407 | unmap_sysmem(vendor_boot_img); |
| 408 | unmap_sysmem(boot_img); |
| 409 | } |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 410 | break; |
| 411 | #endif |
| 412 | default: |
| 413 | puts("ERROR: unknown image format type!\n"); |
| 414 | return 1; |
| 415 | } |
| 416 | |
Simon Glass | 90268b8 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 417 | /* If we have a valid setup.bin, we will use that for entry (x86) */ |
Simon Glass | 5bda35c | 2014-10-10 08:21:57 -0600 | [diff] [blame] | 418 | if (images.os.arch == IH_ARCH_I386 || |
| 419 | images.os.arch == IH_ARCH_X86_64) { |
Simon Glass | 90268b8 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 420 | ulong len; |
| 421 | |
| 422 | ret = boot_get_setup(&images, IH_ARCH_I386, &images.ep, &len); |
| 423 | if (ret < 0 && ret != -ENOENT) { |
| 424 | puts("Could not find a valid setup.bin for x86\n"); |
| 425 | return 1; |
| 426 | } |
| 427 | /* Kernel entry point is the setup.bin */ |
| 428 | } else if (images.legacy_hdr_valid) { |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 429 | images.ep = image_get_ep(&images.legacy_hdr_os_copy); |
Simon Glass | bf371b4 | 2021-09-25 19:43:20 -0600 | [diff] [blame] | 430 | #if CONFIG_IS_ENABLED(FIT) |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 431 | } else if (images.fit_uname_os) { |
| 432 | int ret; |
| 433 | |
| 434 | ret = fit_image_get_entry(images.fit_hdr_os, |
| 435 | images.fit_noffset_os, &images.ep); |
| 436 | if (ret) { |
| 437 | puts("Can't get entry point property!\n"); |
| 438 | return 1; |
| 439 | } |
| 440 | #endif |
| 441 | } else if (!ep_found) { |
| 442 | puts("Could not find kernel entry point!\n"); |
| 443 | return 1; |
| 444 | } |
| 445 | |
| 446 | if (images.os.type == IH_TYPE_KERNEL_NOLOAD) { |
Simon Glass | bb07cdb | 2023-11-19 07:43:33 -0700 | [diff] [blame] | 447 | images.os.load = images.os.image_start; |
| 448 | images.ep += images.os.image_start; |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 449 | } |
| 450 | |
Simon Glass | 7a80de4 | 2016-02-24 09:14:42 -0700 | [diff] [blame] | 451 | images.os.start = map_to_sysmem(os_hdr); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 452 | |
| 453 | return 0; |
| 454 | } |
| 455 | |
Simon Glass | 65f0bfe | 2023-11-18 14:05:17 -0700 | [diff] [blame] | 456 | /** |
| 457 | * check_overlap() - Check if an image overlaps the OS |
| 458 | * |
| 459 | * @name: Name of image to check (used to print error) |
| 460 | * @base: Base address of image |
| 461 | * @end: End address of image (+1) |
| 462 | * @os_start: Start of OS |
| 463 | * @os_size: Size of OS in bytes |
| 464 | * Return: 0 if OK, -EXDEV if the image overlaps the OS |
| 465 | */ |
| 466 | static int check_overlap(const char *name, ulong base, ulong end, |
| 467 | ulong os_start, ulong os_size) |
| 468 | { |
| 469 | ulong os_end; |
| 470 | |
| 471 | if (!base) |
| 472 | return 0; |
| 473 | os_end = os_start + os_size; |
| 474 | |
| 475 | if ((base >= os_start && base < os_end) || |
| 476 | (end > os_start && end <= os_end) || |
| 477 | (base < os_start && end >= os_end)) { |
| 478 | printf("ERROR: %s image overlaps OS image (OS=%lx..%lx)\n", |
| 479 | name, os_start, os_end); |
| 480 | |
| 481 | return -EXDEV; |
| 482 | } |
| 483 | |
| 484 | return 0; |
| 485 | } |
| 486 | |
Simon Glass | 3ac85bd | 2023-11-18 14:05:16 -0700 | [diff] [blame] | 487 | int bootm_find_images(ulong img_addr, const char *conf_ramdisk, |
| 488 | const char *conf_fdt, ulong start, ulong size) |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 489 | { |
Simon Glass | 3ac85bd | 2023-11-18 14:05:16 -0700 | [diff] [blame] | 490 | const char *select = conf_ramdisk; |
Simon Glass | 46aee25 | 2023-11-18 14:05:13 -0700 | [diff] [blame] | 491 | char addr_str[17]; |
Simon Glass | ba5e3f7 | 2023-11-18 14:05:09 -0700 | [diff] [blame] | 492 | void *buf; |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 493 | int ret; |
| 494 | |
Simon Glass | 8eda15b | 2023-11-18 14:05:06 -0700 | [diff] [blame] | 495 | if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE)) { |
Simon Glass | 8eda15b | 2023-11-18 14:05:06 -0700 | [diff] [blame] | 496 | /* Look for an Android boot image */ |
| 497 | buf = map_sysmem(images.os.start, 0); |
Simon Glass | 46aee25 | 2023-11-18 14:05:13 -0700 | [diff] [blame] | 498 | if (buf && genimg_get_format(buf) == IMAGE_FORMAT_ANDROID) { |
| 499 | strcpy(addr_str, simple_xtoa(img_addr)); |
| 500 | select = addr_str; |
| 501 | } |
Simon Glass | 8eda15b | 2023-11-18 14:05:06 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Simon Glass | 3ac85bd | 2023-11-18 14:05:16 -0700 | [diff] [blame] | 504 | if (conf_ramdisk) |
| 505 | select = conf_ramdisk; |
Simon Glass | 8eda15b | 2023-11-18 14:05:06 -0700 | [diff] [blame] | 506 | |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 507 | /* find ramdisk */ |
Simon Glass | 8eda15b | 2023-11-18 14:05:06 -0700 | [diff] [blame] | 508 | ret = boot_get_ramdisk(select, &images, IH_INITRD_ARCH, |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 509 | &images.rd_start, &images.rd_end); |
| 510 | if (ret) { |
| 511 | puts("Ramdisk image is corrupt or invalid\n"); |
| 512 | return 1; |
| 513 | } |
| 514 | |
Tero Kristo | fbde758 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 515 | /* check if ramdisk overlaps OS image */ |
Simon Glass | 65f0bfe | 2023-11-18 14:05:17 -0700 | [diff] [blame] | 516 | if (check_overlap("RD", images.rd_start, images.rd_end, start, size)) |
Tero Kristo | fbde758 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 517 | return 1; |
Tero Kristo | fbde758 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 518 | |
Simon Glass | 972d524 | 2023-11-18 14:05:08 -0700 | [diff] [blame] | 519 | if (CONFIG_IS_ENABLED(OF_LIBFDT)) { |
Simon Glass | ba5e3f7 | 2023-11-18 14:05:09 -0700 | [diff] [blame] | 520 | buf = map_sysmem(img_addr, 0); |
| 521 | |
Simon Glass | 972d524 | 2023-11-18 14:05:08 -0700 | [diff] [blame] | 522 | /* find flattened device tree */ |
Simon Glass | 3ac85bd | 2023-11-18 14:05:16 -0700 | [diff] [blame] | 523 | ret = boot_get_fdt(buf, conf_fdt, IH_ARCH_DEFAULT, &images, |
| 524 | &images.ft_addr, &images.ft_len); |
Simon Glass | 972d524 | 2023-11-18 14:05:08 -0700 | [diff] [blame] | 525 | if (ret) { |
| 526 | puts("Could not find a valid device tree\n"); |
| 527 | return 1; |
| 528 | } |
Tero Kristo | fbde758 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 529 | |
Simon Glass | 972d524 | 2023-11-18 14:05:08 -0700 | [diff] [blame] | 530 | /* check if FDT overlaps OS image */ |
Simon Glass | 65f0bfe | 2023-11-18 14:05:17 -0700 | [diff] [blame] | 531 | if (check_overlap("FDT", map_to_sysmem(images.ft_addr), |
| 532 | images.ft_len, start, size)) |
Simon Glass | 972d524 | 2023-11-18 14:05:08 -0700 | [diff] [blame] | 533 | return 1; |
Tero Kristo | fbde758 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 534 | |
Simon Glass | 972d524 | 2023-11-18 14:05:08 -0700 | [diff] [blame] | 535 | if (IS_ENABLED(CONFIG_CMD_FDT)) |
| 536 | set_working_fdt_addr(map_to_sysmem(images.ft_addr)); |
| 537 | } |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 538 | |
Simon Glass | bf371b4 | 2021-09-25 19:43:20 -0600 | [diff] [blame] | 539 | #if CONFIG_IS_ENABLED(FIT) |
Simon Glass | 4ed37ab | 2021-09-25 07:03:20 -0600 | [diff] [blame] | 540 | if (IS_ENABLED(CONFIG_FPGA)) { |
| 541 | /* find bitstreams */ |
Simon Glass | 745367b | 2023-11-18 14:05:11 -0700 | [diff] [blame] | 542 | ret = boot_get_fpga(&images); |
Simon Glass | 4ed37ab | 2021-09-25 07:03:20 -0600 | [diff] [blame] | 543 | if (ret) { |
| 544 | printf("FPGA image is corrupted or invalid\n"); |
| 545 | return 1; |
| 546 | } |
Michal Simek | 62afc60 | 2016-05-17 14:03:50 +0200 | [diff] [blame] | 547 | } |
Michal Simek | 62afc60 | 2016-05-17 14:03:50 +0200 | [diff] [blame] | 548 | |
Karl Apsite | 84a07db | 2015-05-21 09:52:48 -0400 | [diff] [blame] | 549 | /* find all of the loadables */ |
Simon Glass | 9645628 | 2023-11-18 14:05:12 -0700 | [diff] [blame] | 550 | ret = boot_get_loadable(&images); |
Karl Apsite | 84a07db | 2015-05-21 09:52:48 -0400 | [diff] [blame] | 551 | if (ret) { |
| 552 | printf("Loadable(s) is corrupt or invalid\n"); |
| 553 | return 1; |
| 554 | } |
Karl Apsite | 84a07db | 2015-05-21 09:52:48 -0400 | [diff] [blame] | 555 | #endif |
| 556 | |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 557 | return 0; |
| 558 | } |
| 559 | |
Simon Glass | 984e6fe | 2023-11-18 14:05:18 -0700 | [diff] [blame] | 560 | static int bootm_find_other(ulong img_addr, const char *conf_ramdisk, |
| 561 | const char *conf_fdt) |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 562 | { |
Simon Glass | e2fc90e | 2023-11-18 14:05:14 -0700 | [diff] [blame] | 563 | if ((images.os.type == IH_TYPE_KERNEL || |
| 564 | images.os.type == IH_TYPE_KERNEL_NOLOAD || |
| 565 | images.os.type == IH_TYPE_MULTI) && |
| 566 | (images.os.os == IH_OS_LINUX || images.os.os == IH_OS_VXWORKS || |
Simon Glass | 3ac85bd | 2023-11-18 14:05:16 -0700 | [diff] [blame] | 567 | images.os.os == IH_OS_EFI || images.os.os == IH_OS_TEE)) { |
Simon Glass | 984e6fe | 2023-11-18 14:05:18 -0700 | [diff] [blame] | 568 | return bootm_find_images(img_addr, conf_ramdisk, conf_fdt, 0, |
| 569 | 0); |
Simon Glass | 3ac85bd | 2023-11-18 14:05:16 -0700 | [diff] [blame] | 570 | } |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 571 | |
| 572 | return 0; |
| 573 | } |
Simon Glass | 40e5975 | 2014-12-02 13:17:30 -0700 | [diff] [blame] | 574 | #endif /* USE_HOSTC */ |
| 575 | |
Julius Werner | 2090854 | 2019-07-24 19:37:54 -0700 | [diff] [blame] | 576 | #if !defined(USE_HOSTCC) || defined(CONFIG_FIT_SIGNATURE) |
Simon Glass | 3086c05 | 2014-12-02 13:17:37 -0700 | [diff] [blame] | 577 | /** |
| 578 | * handle_decomp_error() - display a decompression error |
| 579 | * |
| 580 | * This function tries to produce a useful message. In the case where the |
| 581 | * uncompressed size is the same as the available space, we can assume that |
| 582 | * the image is too large for the buffer. |
| 583 | * |
| 584 | * @comp_type: Compression type being used (IH_COMP_...) |
| 585 | * @uncomp_size: Number of bytes uncompressed |
Tom Rini | c45568c | 2022-06-25 19:29:46 -0400 | [diff] [blame] | 586 | * @buf_size: Number of bytes the decompresion buffer was |
Julius Werner | 2090854 | 2019-07-24 19:37:54 -0700 | [diff] [blame] | 587 | * @ret: errno error code received from compression library |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 588 | * Return: Appropriate BOOTM_ERR_ error code |
Simon Glass | 3086c05 | 2014-12-02 13:17:37 -0700 | [diff] [blame] | 589 | */ |
Tom Rini | c45568c | 2022-06-25 19:29:46 -0400 | [diff] [blame] | 590 | static int handle_decomp_error(int comp_type, size_t uncomp_size, |
| 591 | size_t buf_size, int ret) |
Simon Glass | 40e5975 | 2014-12-02 13:17:30 -0700 | [diff] [blame] | 592 | { |
Simon Glass | 3086c05 | 2014-12-02 13:17:37 -0700 | [diff] [blame] | 593 | const char *name = genimg_get_comp_name(comp_type); |
| 594 | |
Julius Werner | 2090854 | 2019-07-24 19:37:54 -0700 | [diff] [blame] | 595 | /* ENOSYS means unimplemented compression type, don't reset. */ |
| 596 | if (ret == -ENOSYS) |
| 597 | return BOOTM_ERR_UNIMPLEMENTED; |
| 598 | |
Tom Rini | c45568c | 2022-06-25 19:29:46 -0400 | [diff] [blame] | 599 | if (uncomp_size >= buf_size) |
Simon Glass | 3086c05 | 2014-12-02 13:17:37 -0700 | [diff] [blame] | 600 | printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n"); |
Simon Glass | 40e5975 | 2014-12-02 13:17:30 -0700 | [diff] [blame] | 601 | else |
Simon Glass | 3086c05 | 2014-12-02 13:17:37 -0700 | [diff] [blame] | 602 | printf("%s: uncompress error %d\n", name, ret); |
| 603 | |
| 604 | /* |
| 605 | * The decompression routines are now safe, so will not write beyond |
| 606 | * their bounds. Probably it is not necessary to reset, but maintain |
| 607 | * the current behaviour for now. |
| 608 | */ |
| 609 | printf("Must RESET board to recover\n"); |
Simon Glass | 40e5975 | 2014-12-02 13:17:30 -0700 | [diff] [blame] | 610 | #ifndef USE_HOSTCC |
| 611 | bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE); |
| 612 | #endif |
| 613 | |
| 614 | return BOOTM_ERR_RESET; |
| 615 | } |
Julius Werner | 2090854 | 2019-07-24 19:37:54 -0700 | [diff] [blame] | 616 | #endif |
Simon Glass | 2b164f1 | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 617 | |
Simon Glass | ce1400f | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 618 | #ifndef USE_HOSTCC |
Simon Glass | d9d7c20 | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 619 | static int bootm_load_os(struct bootm_headers *images, int boot_progress) |
Simon Glass | 2b164f1 | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 620 | { |
Simon Glass | da79b2f | 2022-09-06 20:26:51 -0600 | [diff] [blame] | 621 | struct image_info os = images->os; |
Simon Glass | 2b164f1 | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 622 | ulong load = os.load; |
Tom Rini | cc95535 | 2018-05-01 12:32:37 -0400 | [diff] [blame] | 623 | ulong load_end; |
Simon Glass | 2b164f1 | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 624 | ulong blob_start = os.start; |
| 625 | ulong blob_end = os.end; |
| 626 | ulong image_start = os.image_start; |
| 627 | ulong image_len = os.image_len; |
Bryan O'Donoghue | bbac922 | 2018-04-15 11:48:17 +0100 | [diff] [blame] | 628 | ulong flush_start = ALIGN_DOWN(load, ARCH_DMA_MINALIGN); |
Simon Glass | 2b164f1 | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 629 | bool no_overlap; |
| 630 | void *load_buf, *image_buf; |
| 631 | int err; |
| 632 | |
Simon Glass | 69544c4 | 2023-11-19 07:43:34 -0700 | [diff] [blame] | 633 | /* |
| 634 | * For a "noload" compressed kernel we need to allocate a buffer large |
| 635 | * enough to decompress in to and use that as the load address now. |
| 636 | * Assume that the kernel compression is at most a factor of 4 since |
| 637 | * zstd almost achieves that. |
| 638 | * Use an alignment of 2MB since this might help arm64 |
| 639 | */ |
| 640 | if (os.type == IH_TYPE_KERNEL_NOLOAD && os.comp != IH_COMP_NONE) { |
| 641 | ulong req_size = ALIGN(image_len * 4, SZ_1M); |
| 642 | |
| 643 | load = lmb_alloc(&images->lmb, req_size, SZ_2M); |
| 644 | if (!load) |
| 645 | return 1; |
| 646 | os.load = load; |
| 647 | debug("Allocated %lx bytes at %lx for kernel (size %lx) decompression\n", |
| 648 | req_size, load, image_len); |
| 649 | } |
| 650 | |
Simon Glass | 2b164f1 | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 651 | load_buf = map_sysmem(load, 0); |
| 652 | image_buf = map_sysmem(os.image_start, image_len); |
Julius Werner | 2090854 | 2019-07-24 19:37:54 -0700 | [diff] [blame] | 653 | err = image_decomp(os.comp, load, os.image_start, os.type, |
| 654 | load_buf, image_buf, image_len, |
| 655 | CONFIG_SYS_BOOTM_LEN, &load_end); |
Simon Glass | 2b164f1 | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 656 | if (err) { |
Tom Rini | c45568c | 2022-06-25 19:29:46 -0400 | [diff] [blame] | 657 | err = handle_decomp_error(os.comp, load_end - load, |
| 658 | CONFIG_SYS_BOOTM_LEN, err); |
Simon Glass | 2b164f1 | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 659 | bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE); |
| 660 | return err; |
| 661 | } |
Heinrich Schuchardt | 21d3946 | 2020-08-30 11:34:12 +0200 | [diff] [blame] | 662 | /* We need the decompressed image size in the next steps */ |
| 663 | images->os.image_len = load_end - load; |
Bryan O'Donoghue | bbac922 | 2018-04-15 11:48:17 +0100 | [diff] [blame] | 664 | |
Trent Piepho | b4353b3 | 2019-03-27 23:50:09 +0000 | [diff] [blame] | 665 | flush_cache(flush_start, ALIGN(load_end, ARCH_DMA_MINALIGN) - flush_start); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 666 | |
Tom Rini | cc95535 | 2018-05-01 12:32:37 -0400 | [diff] [blame] | 667 | debug(" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, load_end); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 668 | bootstage_mark(BOOTSTAGE_ID_KERNEL_LOADED); |
| 669 | |
Simon Glass | 2b164f1 | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 670 | no_overlap = (os.comp == IH_COMP_NONE && load == image_start); |
| 671 | |
Tom Rini | cc95535 | 2018-05-01 12:32:37 -0400 | [diff] [blame] | 672 | if (!no_overlap && load < blob_end && load_end > blob_start) { |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 673 | debug("images.os.start = 0x%lX, images.os.end = 0x%lx\n", |
| 674 | blob_start, blob_end); |
| 675 | debug("images.os.load = 0x%lx, load_end = 0x%lx\n", load, |
Tom Rini | cc95535 | 2018-05-01 12:32:37 -0400 | [diff] [blame] | 676 | load_end); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 677 | |
| 678 | /* Check what type of image this is. */ |
| 679 | if (images->legacy_hdr_valid) { |
| 680 | if (image_get_type(&images->legacy_hdr_os_copy) |
| 681 | == IH_TYPE_MULTI) |
| 682 | puts("WARNING: legacy format multi component image overwritten\n"); |
| 683 | return BOOTM_ERR_OVERLAP; |
| 684 | } else { |
| 685 | puts("ERROR: new format image overwritten - must RESET the board to recover\n"); |
| 686 | bootstage_error(BOOTSTAGE_ID_OVERWRITTEN); |
| 687 | return BOOTM_ERR_RESET; |
| 688 | } |
| 689 | } |
| 690 | |
Simon Glass | bb07cdb | 2023-11-19 07:43:33 -0700 | [diff] [blame] | 691 | if (IS_ENABLED(CONFIG_CMD_BOOTI) && images->os.arch == IH_ARCH_ARM64 && |
| 692 | images->os.os == IH_OS_LINUX) { |
| 693 | ulong relocated_addr; |
| 694 | ulong image_size; |
| 695 | int ret; |
| 696 | |
| 697 | ret = booti_setup(load, &relocated_addr, &image_size, false); |
| 698 | if (ret) { |
| 699 | printf("Failed to prep arm64 kernel (err=%d)\n", ret); |
| 700 | return BOOTM_ERR_RESET; |
| 701 | } |
| 702 | |
| 703 | /* Handle BOOTM_STATE_LOADOS */ |
| 704 | if (relocated_addr != load) { |
| 705 | printf("Moving Image from 0x%lx to 0x%lx, end=%lx\n", |
| 706 | load, relocated_addr, |
| 707 | relocated_addr + image_size); |
| 708 | memmove((void *)relocated_addr, load_buf, image_size); |
| 709 | } |
| 710 | |
| 711 | images->ep = relocated_addr; |
| 712 | images->os.start = relocated_addr; |
| 713 | images->os.end = relocated_addr + image_size; |
| 714 | } |
| 715 | |
Tom Rini | cc95535 | 2018-05-01 12:32:37 -0400 | [diff] [blame] | 716 | lmb_reserve(&images->lmb, images->os.load, (load_end - |
| 717 | images->os.load)); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 718 | return 0; |
| 719 | } |
| 720 | |
| 721 | /** |
| 722 | * bootm_disable_interrupts() - Disable interrupts in preparation for load/boot |
| 723 | * |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 724 | * Return: interrupt flag (0 if interrupts were disabled, non-zero if they were |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 725 | * enabled) |
| 726 | */ |
| 727 | ulong bootm_disable_interrupts(void) |
| 728 | { |
| 729 | ulong iflag; |
| 730 | |
| 731 | /* |
| 732 | * We have reached the point of no return: we are going to |
| 733 | * overwrite all exception vector code, so we cannot easily |
| 734 | * recover from any failures any more... |
| 735 | */ |
| 736 | iflag = disable_interrupts(); |
| 737 | #ifdef CONFIG_NETCONSOLE |
| 738 | /* Stop the ethernet stack if NetConsole could have left it up */ |
| 739 | eth_halt(); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 740 | #endif |
| 741 | |
| 742 | #if defined(CONFIG_CMD_USB) |
| 743 | /* |
| 744 | * turn off USB to prevent the host controller from writing to the |
| 745 | * SDRAM while Linux is booting. This could happen (at least for OHCI |
| 746 | * controller), because the HCCA (Host Controller Communication Area) |
| 747 | * lies within the SDRAM and the host controller writes continously to |
| 748 | * this area (as busmaster!). The HccaFrameNumber is for example |
| 749 | * updated every 1 ms within the HCCA structure in SDRAM! For more |
| 750 | * details see the OpenHCI specification. |
| 751 | */ |
| 752 | usb_stop(); |
| 753 | #endif |
| 754 | return iflag; |
| 755 | } |
| 756 | |
Simon Glass | 6cd92b1 | 2020-11-05 10:33:42 -0700 | [diff] [blame] | 757 | #define CONSOLE_ARG "console=" |
Sean Anderson | ba9aa40 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 758 | #define NULL_CONSOLE (CONSOLE_ARG "ttynull") |
| 759 | #define CONSOLE_ARG_SIZE sizeof(NULL_CONSOLE) |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 760 | |
Simon Glass | b6386f3 | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 761 | /** |
| 762 | * fixup_silent_linux() - Handle silencing the linux boot if required |
| 763 | * |
| 764 | * This uses the silent_linux envvar to control whether to add/set a "console=" |
| 765 | * parameter to the command line |
| 766 | * |
| 767 | * @buf: Buffer containing the string to process |
| 768 | * @maxlen: Maximum length of buffer |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 769 | * Return: 0 if OK, -ENOSPC if @maxlen is too small |
Simon Glass | b6386f3 | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 770 | */ |
| 771 | static int fixup_silent_linux(char *buf, int maxlen) |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 772 | { |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 773 | int want_silent; |
Simon Glass | b6386f3 | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 774 | char *cmdline; |
| 775 | int size; |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 776 | |
Simon Glass | b6386f3 | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 777 | /* |
| 778 | * Move the input string to the end of buffer. The output string will be |
| 779 | * built up at the start. |
| 780 | */ |
| 781 | size = strlen(buf) + 1; |
| 782 | if (size * 2 > maxlen) |
| 783 | return -ENOSPC; |
| 784 | cmdline = buf + maxlen - size; |
| 785 | memmove(cmdline, buf, size); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 786 | /* |
| 787 | * Only fix cmdline when requested. The environment variable can be: |
| 788 | * |
| 789 | * no - we never fixup |
| 790 | * yes - we always fixup |
| 791 | * unset - we rely on the console silent flag |
| 792 | */ |
Simon Glass | bfebc8c | 2017-08-03 12:22:13 -0600 | [diff] [blame] | 793 | want_silent = env_get_yesno("silent_linux"); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 794 | if (want_silent == 0) |
Simon Glass | 4ae4264 | 2020-11-05 10:33:39 -0700 | [diff] [blame] | 795 | return 0; |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 796 | else if (want_silent == -1 && !(gd->flags & GD_FLG_SILENT)) |
Simon Glass | 4ae4264 | 2020-11-05 10:33:39 -0700 | [diff] [blame] | 797 | return 0; |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 798 | |
| 799 | debug("before silent fix-up: %s\n", cmdline); |
Simon Glass | b6386f3 | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 800 | if (*cmdline) { |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 801 | char *start = strstr(cmdline, CONSOLE_ARG); |
| 802 | |
Simon Glass | b6386f3 | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 803 | /* Check space for maximum possible new command line */ |
| 804 | if (size + CONSOLE_ARG_SIZE > maxlen) |
Simon Glass | 4ae4264 | 2020-11-05 10:33:39 -0700 | [diff] [blame] | 805 | return -ENOSPC; |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 806 | |
| 807 | if (start) { |
| 808 | char *end = strchr(start, ' '); |
Simon Glass | 6cd92b1 | 2020-11-05 10:33:42 -0700 | [diff] [blame] | 809 | int start_bytes; |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 810 | |
Sean Anderson | ba9aa40 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 811 | start_bytes = start - cmdline; |
Simon Glass | 6cd92b1 | 2020-11-05 10:33:42 -0700 | [diff] [blame] | 812 | strncpy(buf, cmdline, start_bytes); |
Sean Anderson | ba9aa40 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 813 | strncpy(buf + start_bytes, NULL_CONSOLE, CONSOLE_ARG_SIZE); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 814 | if (end) |
Sean Anderson | ba9aa40 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 815 | strcpy(buf + start_bytes + CONSOLE_ARG_SIZE - 1, end); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 816 | else |
Sean Anderson | ba9aa40 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 817 | buf[start_bytes + CONSOLE_ARG_SIZE] = '\0'; |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 818 | } else { |
Sean Anderson | ba9aa40 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 819 | sprintf(buf, "%s %s", cmdline, NULL_CONSOLE); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 820 | } |
Simon Glass | b6386f3 | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 821 | if (buf + strlen(buf) >= cmdline) |
| 822 | return -ENOSPC; |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 823 | } else { |
Sean Anderson | ba9aa40 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 824 | if (maxlen < CONSOLE_ARG_SIZE) |
Simon Glass | b6386f3 | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 825 | return -ENOSPC; |
Sean Anderson | ba9aa40 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 826 | strcpy(buf, NULL_CONSOLE); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 827 | } |
Simon Glass | b6386f3 | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 828 | debug("after silent fix-up: %s\n", buf); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 829 | |
Simon Glass | b6386f3 | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 830 | return 0; |
| 831 | } |
| 832 | |
Simon Glass | 51bb338 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 833 | /** |
| 834 | * process_subst() - Handle substitution of ${...} fields in the environment |
| 835 | * |
| 836 | * Handle variable substitution in the provided buffer |
| 837 | * |
| 838 | * @buf: Buffer containing the string to process |
| 839 | * @maxlen: Maximum length of buffer |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 840 | * Return: 0 if OK, -ENOSPC if @maxlen is too small |
Simon Glass | 51bb338 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 841 | */ |
| 842 | static int process_subst(char *buf, int maxlen) |
| 843 | { |
| 844 | char *cmdline; |
| 845 | int size; |
| 846 | int ret; |
| 847 | |
| 848 | /* Move to end of buffer */ |
| 849 | size = strlen(buf) + 1; |
| 850 | cmdline = buf + maxlen - size; |
| 851 | if (buf + size > cmdline) |
| 852 | return -ENOSPC; |
| 853 | memmove(cmdline, buf, size); |
| 854 | |
| 855 | ret = cli_simple_process_macros(cmdline, buf, cmdline - buf); |
| 856 | |
| 857 | return ret; |
| 858 | } |
| 859 | |
Simon Glass | 4448fe8 | 2020-11-05 10:33:45 -0700 | [diff] [blame] | 860 | int bootm_process_cmdline(char *buf, int maxlen, int flags) |
| 861 | { |
| 862 | int ret; |
| 863 | |
| 864 | /* Check config first to enable compiler to eliminate code */ |
| 865 | if (IS_ENABLED(CONFIG_SILENT_CONSOLE) && |
| 866 | !IS_ENABLED(CONFIG_SILENT_U_BOOT_ONLY) && |
| 867 | (flags & BOOTM_CL_SILENT)) { |
| 868 | ret = fixup_silent_linux(buf, maxlen); |
| 869 | if (ret) |
| 870 | return log_msg_ret("silent", ret); |
| 871 | } |
Simon Glass | a8d6962 | 2021-03-15 18:11:23 +1300 | [diff] [blame] | 872 | if (IS_ENABLED(CONFIG_BOOTARGS_SUBST) && IS_ENABLED(CONFIG_CMDLINE) && |
| 873 | (flags & BOOTM_CL_SUBST)) { |
Simon Glass | 51bb338 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 874 | ret = process_subst(buf, maxlen); |
| 875 | if (ret) |
Simon Glass | 185756e | 2021-02-06 09:57:35 -0700 | [diff] [blame] | 876 | return log_msg_ret("subst", ret); |
Simon Glass | 51bb338 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 877 | } |
Simon Glass | 4448fe8 | 2020-11-05 10:33:45 -0700 | [diff] [blame] | 878 | |
| 879 | return 0; |
| 880 | } |
| 881 | |
Simon Glass | b3c0167 | 2020-11-05 10:33:44 -0700 | [diff] [blame] | 882 | int bootm_process_cmdline_env(int flags) |
Simon Glass | b6386f3 | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 883 | { |
| 884 | const int maxlen = MAX_CMDLINE_SIZE; |
Simon Glass | b3c0167 | 2020-11-05 10:33:44 -0700 | [diff] [blame] | 885 | bool do_silent; |
Simon Glass | b6386f3 | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 886 | const char *env; |
| 887 | char *buf; |
| 888 | int ret; |
| 889 | |
| 890 | /* First check if any action is needed */ |
| 891 | do_silent = IS_ENABLED(CONFIG_SILENT_CONSOLE) && |
Simon Glass | b3c0167 | 2020-11-05 10:33:44 -0700 | [diff] [blame] | 892 | !IS_ENABLED(CONFIG_SILENT_U_BOOT_ONLY) && (flags & BOOTM_CL_SILENT); |
Simon Glass | 51bb338 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 893 | if (!do_silent && !IS_ENABLED(CONFIG_BOOTARGS_SUBST)) |
Simon Glass | b6386f3 | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 894 | return 0; |
| 895 | |
| 896 | env = env_get("bootargs"); |
| 897 | if (env && strlen(env) >= maxlen) |
| 898 | return -E2BIG; |
| 899 | buf = malloc(maxlen); |
| 900 | if (!buf) |
| 901 | return -ENOMEM; |
| 902 | if (env) |
| 903 | strcpy(buf, env); |
| 904 | else |
| 905 | *buf = '\0'; |
Simon Glass | 4448fe8 | 2020-11-05 10:33:45 -0700 | [diff] [blame] | 906 | ret = bootm_process_cmdline(buf, maxlen, flags); |
Simon Glass | b6386f3 | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 907 | if (!ret) { |
| 908 | ret = env_set("bootargs", buf); |
| 909 | |
| 910 | /* |
| 911 | * If buf is "" and bootargs does not exist, this will produce |
| 912 | * an error trying to delete bootargs. Ignore it |
| 913 | */ |
| 914 | if (ret == -ENOENT) |
| 915 | ret = 0; |
| 916 | } |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 917 | free(buf); |
Simon Glass | b6386f3 | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 918 | if (ret) |
| 919 | return log_msg_ret("env", ret); |
Simon Glass | 4ae4264 | 2020-11-05 10:33:39 -0700 | [diff] [blame] | 920 | |
| 921 | return 0; |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 922 | } |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 923 | |
Eddie James | dec166d | 2023-10-24 10:43:50 -0500 | [diff] [blame] | 924 | int bootm_measure(struct bootm_headers *images) |
| 925 | { |
| 926 | int ret = 0; |
| 927 | |
| 928 | /* Skip measurement if EFI is going to do it */ |
| 929 | if (images->os.os == IH_OS_EFI && |
| 930 | IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL) && |
| 931 | IS_ENABLED(CONFIG_BOOTM_EFI)) |
| 932 | return ret; |
| 933 | |
| 934 | if (IS_ENABLED(CONFIG_MEASURED_BOOT)) { |
| 935 | struct tcg2_event_log elog; |
| 936 | struct udevice *dev; |
| 937 | void *initrd_buf; |
| 938 | void *image_buf; |
| 939 | const char *s; |
| 940 | u32 rd_len; |
| 941 | bool ign; |
| 942 | |
| 943 | elog.log_size = 0; |
| 944 | ign = IS_ENABLED(CONFIG_MEASURE_IGNORE_LOG); |
| 945 | ret = tcg2_measurement_init(&dev, &elog, ign); |
| 946 | if (ret) |
| 947 | return ret; |
| 948 | |
| 949 | image_buf = map_sysmem(images->os.image_start, |
| 950 | images->os.image_len); |
| 951 | ret = tcg2_measure_data(dev, &elog, 8, images->os.image_len, |
| 952 | image_buf, EV_COMPACT_HASH, |
| 953 | strlen("linux") + 1, (u8 *)"linux"); |
| 954 | if (ret) |
| 955 | goto unmap_image; |
| 956 | |
| 957 | rd_len = images->rd_end - images->rd_start; |
| 958 | initrd_buf = map_sysmem(images->rd_start, rd_len); |
| 959 | ret = tcg2_measure_data(dev, &elog, 9, rd_len, initrd_buf, |
| 960 | EV_COMPACT_HASH, strlen("initrd") + 1, |
| 961 | (u8 *)"initrd"); |
| 962 | if (ret) |
| 963 | goto unmap_initrd; |
| 964 | |
| 965 | if (IS_ENABLED(CONFIG_MEASURE_DEVICETREE)) { |
| 966 | ret = tcg2_measure_data(dev, &elog, 0, images->ft_len, |
| 967 | (u8 *)images->ft_addr, |
| 968 | EV_TABLE_OF_DEVICES, |
| 969 | strlen("dts") + 1, |
| 970 | (u8 *)"dts"); |
| 971 | if (ret) |
| 972 | goto unmap_initrd; |
| 973 | } |
| 974 | |
| 975 | s = env_get("bootargs"); |
| 976 | if (!s) |
| 977 | s = ""; |
| 978 | ret = tcg2_measure_data(dev, &elog, 1, strlen(s) + 1, (u8 *)s, |
| 979 | EV_PLATFORM_CONFIG_FLAGS, |
| 980 | strlen(s) + 1, (u8 *)s); |
| 981 | |
| 982 | unmap_initrd: |
| 983 | unmap_sysmem(initrd_buf); |
| 984 | |
| 985 | unmap_image: |
| 986 | unmap_sysmem(image_buf); |
| 987 | tcg2_measurement_term(dev, &elog, ret != 0); |
| 988 | } |
| 989 | |
| 990 | return ret; |
| 991 | } |
| 992 | |
Simon Glass | b5d397f | 2023-12-15 20:14:19 -0700 | [diff] [blame] | 993 | int bootm_run_states(struct bootm_info *bmi, int states) |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 994 | { |
Simon Glass | a6c4916 | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 995 | struct bootm_headers *images = bmi->images; |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 996 | boot_os_fn *boot_fn; |
| 997 | ulong iflag = 0; |
| 998 | int ret = 0, need_boot_fn; |
| 999 | |
| 1000 | images->state |= states; |
| 1001 | |
| 1002 | /* |
| 1003 | * Work through the states and see how far we get. We stop on |
| 1004 | * any error. |
| 1005 | */ |
| 1006 | if (states & BOOTM_STATE_START) |
Simon Glass | a50e886 | 2023-11-18 14:04:54 -0700 | [diff] [blame] | 1007 | ret = bootm_start(); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1008 | |
Philippe Reynes | 9d46e63 | 2022-03-28 22:57:00 +0200 | [diff] [blame] | 1009 | if (!ret && (states & BOOTM_STATE_PRE_LOAD)) |
Simon Glass | a6c4916 | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 1010 | ret = bootm_pre_load(bmi->addr_img); |
Philippe Reynes | 9d46e63 | 2022-03-28 22:57:00 +0200 | [diff] [blame] | 1011 | |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1012 | if (!ret && (states & BOOTM_STATE_FINDOS)) |
Simon Glass | a6c4916 | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 1013 | ret = bootm_find_os(bmi->cmd_name, bmi->addr_img); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1014 | |
Simon Glass | 984e6fe | 2023-11-18 14:05:18 -0700 | [diff] [blame] | 1015 | if (!ret && (states & BOOTM_STATE_FINDOTHER)) { |
| 1016 | ulong img_addr; |
| 1017 | |
Simon Glass | a6c4916 | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 1018 | img_addr = bmi->addr_img ? hextoul(bmi->addr_img, NULL) |
| 1019 | : image_load_addr; |
| 1020 | ret = bootm_find_other(img_addr, bmi->conf_ramdisk, |
| 1021 | bmi->conf_fdt); |
Simon Glass | 984e6fe | 2023-11-18 14:05:18 -0700 | [diff] [blame] | 1022 | } |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1023 | |
Eddie James | dec166d | 2023-10-24 10:43:50 -0500 | [diff] [blame] | 1024 | if (IS_ENABLED(CONFIG_MEASURED_BOOT) && !ret && |
| 1025 | (states & BOOTM_STATE_MEASURE)) |
| 1026 | bootm_measure(images); |
| 1027 | |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1028 | /* Load the OS */ |
| 1029 | if (!ret && (states & BOOTM_STATE_LOADOS)) { |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1030 | iflag = bootm_disable_interrupts(); |
Tom Rini | cc95535 | 2018-05-01 12:32:37 -0400 | [diff] [blame] | 1031 | ret = bootm_load_os(images, 0); |
| 1032 | if (ret && ret != BOOTM_ERR_OVERLAP) |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1033 | goto err; |
| 1034 | else if (ret == BOOTM_ERR_OVERLAP) |
| 1035 | ret = 0; |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | /* Relocate the ramdisk */ |
| 1039 | #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH |
| 1040 | if (!ret && (states & BOOTM_STATE_RAMDISK)) { |
| 1041 | ulong rd_len = images->rd_end - images->rd_start; |
| 1042 | |
| 1043 | ret = boot_ramdisk_high(&images->lmb, images->rd_start, |
| 1044 | rd_len, &images->initrd_start, &images->initrd_end); |
| 1045 | if (!ret) { |
Simon Glass | 018f530 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 1046 | env_set_hex("initrd_start", images->initrd_start); |
| 1047 | env_set_hex("initrd_end", images->initrd_end); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1048 | } |
| 1049 | } |
| 1050 | #endif |
Simon Glass | 0c303f9 | 2021-09-25 19:43:21 -0600 | [diff] [blame] | 1051 | #if CONFIG_IS_ENABLED(OF_LIBFDT) && defined(CONFIG_LMB) |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1052 | if (!ret && (states & BOOTM_STATE_FDT)) { |
| 1053 | boot_fdt_add_mem_rsv_regions(&images->lmb, images->ft_addr); |
| 1054 | ret = boot_relocate_fdt(&images->lmb, &images->ft_addr, |
| 1055 | &images->ft_len); |
| 1056 | } |
| 1057 | #endif |
| 1058 | |
| 1059 | /* From now on, we need the OS boot function */ |
| 1060 | if (ret) |
| 1061 | return ret; |
| 1062 | boot_fn = bootm_os_get_boot_func(images->os.os); |
| 1063 | need_boot_fn = states & (BOOTM_STATE_OS_CMDLINE | |
| 1064 | BOOTM_STATE_OS_BD_T | BOOTM_STATE_OS_PREP | |
| 1065 | BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO); |
| 1066 | if (boot_fn == NULL && need_boot_fn) { |
| 1067 | if (iflag) |
| 1068 | enable_interrupts(); |
| 1069 | printf("ERROR: booting os '%s' (%d) is not supported\n", |
| 1070 | genimg_get_os_name(images->os.os), images->os.os); |
| 1071 | bootstage_error(BOOTSTAGE_ID_CHECK_BOOT_OS); |
| 1072 | return 1; |
| 1073 | } |
| 1074 | |
| 1075 | /* Call various other states that are not generally used */ |
| 1076 | if (!ret && (states & BOOTM_STATE_OS_CMDLINE)) |
Simon Glass | a6c4916 | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 1077 | ret = boot_fn(BOOTM_STATE_OS_CMDLINE, bmi); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1078 | if (!ret && (states & BOOTM_STATE_OS_BD_T)) |
Simon Glass | a6c4916 | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 1079 | ret = boot_fn(BOOTM_STATE_OS_BD_T, bmi); |
Hector Palacios | 19e8649 | 2016-07-11 12:34:37 +0200 | [diff] [blame] | 1080 | if (!ret && (states & BOOTM_STATE_OS_PREP)) { |
Piotr Kubik | 7481632 | 2023-11-24 17:30:46 +0100 | [diff] [blame] | 1081 | int flags = 0; |
| 1082 | /* For Linux OS do all substitutions at console processing */ |
| 1083 | if (images->os.os == IH_OS_LINUX) |
| 1084 | flags = BOOTM_CL_ALL; |
| 1085 | ret = bootm_process_cmdline_env(flags); |
Simon Glass | d9477a0 | 2020-11-05 10:33:41 -0700 | [diff] [blame] | 1086 | if (ret) { |
| 1087 | printf("Cmdline setup failed (err=%d)\n", ret); |
| 1088 | ret = CMD_RET_FAILURE; |
| 1089 | goto err; |
Simon Glass | 4ae4264 | 2020-11-05 10:33:39 -0700 | [diff] [blame] | 1090 | } |
Simon Glass | a6c4916 | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 1091 | ret = boot_fn(BOOTM_STATE_OS_PREP, bmi); |
Hector Palacios | 19e8649 | 2016-07-11 12:34:37 +0200 | [diff] [blame] | 1092 | } |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1093 | |
| 1094 | #ifdef CONFIG_TRACE |
| 1095 | /* Pretend to run the OS, then run a user command */ |
| 1096 | if (!ret && (states & BOOTM_STATE_OS_FAKE_GO)) { |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 1097 | char *cmd_list = env_get("fakegocmd"); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1098 | |
Simon Glass | 725ddf1 | 2023-12-15 20:14:20 -0700 | [diff] [blame] | 1099 | ret = boot_selected_os(BOOTM_STATE_OS_FAKE_GO, bmi, boot_fn); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1100 | if (!ret && cmd_list) |
Simon Glass | a6c4916 | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 1101 | ret = run_command_list(cmd_list, -1, 0); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1102 | } |
| 1103 | #endif |
| 1104 | |
| 1105 | /* Check for unsupported subcommand. */ |
| 1106 | if (ret) { |
Simon Glass | 13819f0 | 2022-10-11 09:47:07 -0600 | [diff] [blame] | 1107 | printf("subcommand failed (err=%d)\n", ret); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1108 | return ret; |
| 1109 | } |
| 1110 | |
| 1111 | /* Now run the OS! We hope this doesn't return */ |
| 1112 | if (!ret && (states & BOOTM_STATE_OS_GO)) |
Simon Glass | 725ddf1 | 2023-12-15 20:14:20 -0700 | [diff] [blame] | 1113 | ret = boot_selected_os(BOOTM_STATE_OS_GO, bmi, boot_fn); |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1114 | |
| 1115 | /* Deal with any fallout */ |
| 1116 | err: |
| 1117 | if (iflag) |
| 1118 | enable_interrupts(); |
| 1119 | |
Simon Glass | 6443a3d | 2023-12-15 20:14:10 -0700 | [diff] [blame] | 1120 | if (ret == BOOTM_ERR_UNIMPLEMENTED) { |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1121 | bootstage_error(BOOTSTAGE_ID_DECOMP_UNIMPL); |
Simon Glass | 6443a3d | 2023-12-15 20:14:10 -0700 | [diff] [blame] | 1122 | } else if (ret == BOOTM_ERR_RESET) { |
| 1123 | printf("Resetting the board...\n"); |
| 1124 | reset_cpu(); |
| 1125 | } |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1126 | |
| 1127 | return ret; |
| 1128 | } |
| 1129 | |
Simon Glass | d37086a | 2023-12-15 20:14:26 -0700 | [diff] [blame] | 1130 | int boot_run(struct bootm_info *bmi, const char *cmd, int extra_states) |
Simon Glass | e1a24c0 | 2023-12-15 20:14:21 -0700 | [diff] [blame] | 1131 | { |
| 1132 | int states; |
| 1133 | |
Simon Glass | d37086a | 2023-12-15 20:14:26 -0700 | [diff] [blame] | 1134 | bmi->cmd_name = cmd; |
| 1135 | states = BOOTM_STATE_MEASURE | BOOTM_STATE_OS_PREP | |
| 1136 | BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO; |
Simon Glass | e1a24c0 | 2023-12-15 20:14:21 -0700 | [diff] [blame] | 1137 | if (IS_ENABLED(CONFIG_SYS_BOOT_RAMDISK_HIGH)) |
| 1138 | states |= BOOTM_STATE_RAMDISK; |
Simon Glass | d37086a | 2023-12-15 20:14:26 -0700 | [diff] [blame] | 1139 | states |= extra_states; |
Simon Glass | e1a24c0 | 2023-12-15 20:14:21 -0700 | [diff] [blame] | 1140 | |
| 1141 | return bootm_run_states(bmi, states); |
| 1142 | } |
| 1143 | |
Simon Glass | d37086a | 2023-12-15 20:14:26 -0700 | [diff] [blame] | 1144 | int bootm_run(struct bootm_info *bmi) |
| 1145 | { |
| 1146 | return boot_run(bmi, "bootm", BOOTM_STATE_START | BOOTM_STATE_FINDOS | |
| 1147 | BOOTM_STATE_PRE_LOAD | BOOTM_STATE_FINDOTHER | |
| 1148 | BOOTM_STATE_LOADOS); |
| 1149 | } |
| 1150 | |
Simon Glass | 3405c9b | 2023-12-15 20:14:23 -0700 | [diff] [blame] | 1151 | int bootz_run(struct bootm_info *bmi) |
| 1152 | { |
Simon Glass | d37086a | 2023-12-15 20:14:26 -0700 | [diff] [blame] | 1153 | return boot_run(bmi, "bootz", 0); |
Simon Glass | 3405c9b | 2023-12-15 20:14:23 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
Simon Glass | e7683c3 | 2023-12-15 20:14:25 -0700 | [diff] [blame] | 1156 | int booti_run(struct bootm_info *bmi) |
| 1157 | { |
Simon Glass | d37086a | 2023-12-15 20:14:26 -0700 | [diff] [blame] | 1158 | return boot_run(bmi, "booti", 0); |
Simon Glass | e7683c3 | 2023-12-15 20:14:25 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
Simon Glass | daffb0b | 2023-07-30 11:17:02 -0600 | [diff] [blame] | 1161 | int bootm_boot_start(ulong addr, const char *cmdline) |
| 1162 | { |
Simon Glass | daffb0b | 2023-07-30 11:17:02 -0600 | [diff] [blame] | 1163 | char addr_str[30]; |
Simon Glass | a6c4916 | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 1164 | struct bootm_info bmi; |
Simon Glass | daffb0b | 2023-07-30 11:17:02 -0600 | [diff] [blame] | 1165 | int states; |
| 1166 | int ret; |
| 1167 | |
Simon Glass | daffb0b | 2023-07-30 11:17:02 -0600 | [diff] [blame] | 1168 | states = BOOTM_STATE_START | BOOTM_STATE_FINDOS | BOOTM_STATE_PRE_LOAD | |
| 1169 | BOOTM_STATE_FINDOTHER | BOOTM_STATE_LOADOS | |
| 1170 | BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | |
| 1171 | BOOTM_STATE_OS_GO; |
| 1172 | if (IS_ENABLED(CONFIG_SYS_BOOT_RAMDISK_HIGH)) |
| 1173 | states |= BOOTM_STATE_RAMDISK; |
| 1174 | if (IS_ENABLED(CONFIG_PPC) || IS_ENABLED(CONFIG_MIPS)) |
| 1175 | states |= BOOTM_STATE_OS_CMDLINE; |
| 1176 | images.state |= states; |
| 1177 | |
| 1178 | snprintf(addr_str, sizeof(addr_str), "%lx", addr); |
| 1179 | |
| 1180 | ret = env_set("bootargs", cmdline); |
| 1181 | if (ret) { |
| 1182 | printf("Failed to set cmdline\n"); |
| 1183 | return ret; |
| 1184 | } |
Simon Glass | a6c4916 | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 1185 | bootm_init(&bmi); |
| 1186 | bmi.addr_img = addr_str; |
| 1187 | bmi.cmd_name = "bootm"; |
Simon Glass | b5d397f | 2023-12-15 20:14:19 -0700 | [diff] [blame] | 1188 | ret = bootm_run_states(&bmi, states); |
Simon Glass | daffb0b | 2023-07-30 11:17:02 -0600 | [diff] [blame] | 1189 | |
| 1190 | return ret; |
| 1191 | } |
| 1192 | |
Simon Glass | c2211ff | 2023-12-15 20:14:14 -0700 | [diff] [blame] | 1193 | void bootm_init(struct bootm_info *bmi) |
| 1194 | { |
| 1195 | memset(bmi, '\0', sizeof(struct bootm_info)); |
| 1196 | bmi->boot_progress = true; |
| 1197 | if (IS_ENABLED(CONFIG_CMD_BOOTM)) |
| 1198 | bmi->images = &images; |
| 1199 | } |
| 1200 | |
Heinrich Schuchardt | f6c6df7 | 2019-01-08 18:13:06 +0100 | [diff] [blame] | 1201 | /** |
| 1202 | * switch_to_non_secure_mode() - switch to non-secure mode |
| 1203 | * |
| 1204 | * This routine is overridden by architectures requiring this feature. |
| 1205 | */ |
| 1206 | void __weak switch_to_non_secure_mode(void) |
| 1207 | { |
| 1208 | } |
| 1209 | |
Simon Glass | ce1400f | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1210 | #else /* USE_HOSTCC */ |
| 1211 | |
Fabrice Fontaine | 93e0788 | 2019-05-03 22:37:05 +0200 | [diff] [blame] | 1212 | #if defined(CONFIG_FIT_SIGNATURE) |
Simon Glass | 8a9d037 | 2020-03-18 11:44:02 -0600 | [diff] [blame] | 1213 | static int bootm_host_load_image(const void *fit, int req_image_type, |
| 1214 | int cfg_noffset) |
Simon Glass | ce1400f | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1215 | { |
| 1216 | const char *fit_uname_config = NULL; |
| 1217 | ulong data, len; |
Simon Glass | d9d7c20 | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 1218 | struct bootm_headers images; |
Simon Glass | ce1400f | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1219 | int noffset; |
Tom Rini | c45568c | 2022-06-25 19:29:46 -0400 | [diff] [blame] | 1220 | ulong load_end, buf_size; |
Simon Glass | ce1400f | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1221 | uint8_t image_type; |
Daniel Golle | 0cd57f2 | 2022-08-27 04:14:42 +0100 | [diff] [blame] | 1222 | uint8_t image_comp; |
Simon Glass | ce1400f | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1223 | void *load_buf; |
| 1224 | int ret; |
| 1225 | |
Simon Glass | 8a9d037 | 2020-03-18 11:44:02 -0600 | [diff] [blame] | 1226 | fit_uname_config = fdt_get_name(fit, cfg_noffset, NULL); |
Simon Glass | ce1400f | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1227 | memset(&images, '\0', sizeof(images)); |
| 1228 | images.verify = 1; |
| 1229 | noffset = fit_image_load(&images, (ulong)fit, |
| 1230 | NULL, &fit_uname_config, |
| 1231 | IH_ARCH_DEFAULT, req_image_type, -1, |
| 1232 | FIT_LOAD_IGNORED, &data, &len); |
| 1233 | if (noffset < 0) |
| 1234 | return noffset; |
| 1235 | if (fit_image_get_type(fit, noffset, &image_type)) { |
| 1236 | puts("Can't get image type!\n"); |
| 1237 | return -EINVAL; |
| 1238 | } |
| 1239 | |
Daniel Golle | 88de6c5 | 2022-08-27 04:17:28 +0100 | [diff] [blame] | 1240 | if (fit_image_get_comp(fit, noffset, &image_comp)) |
| 1241 | image_comp = IH_COMP_NONE; |
Simon Glass | ce1400f | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1242 | |
| 1243 | /* Allow the image to expand by a factor of 4, should be safe */ |
Tom Rini | c45568c | 2022-06-25 19:29:46 -0400 | [diff] [blame] | 1244 | buf_size = (1 << 20) + len * 4; |
| 1245 | load_buf = malloc(buf_size); |
Daniel Golle | 0cd57f2 | 2022-08-27 04:14:42 +0100 | [diff] [blame] | 1246 | ret = image_decomp(image_comp, 0, data, image_type, load_buf, |
Tom Rini | c45568c | 2022-06-25 19:29:46 -0400 | [diff] [blame] | 1247 | (void *)data, len, buf_size, &load_end); |
Simon Glass | ce1400f | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1248 | free(load_buf); |
Simon Glass | 081cc19 | 2014-12-02 13:17:33 -0700 | [diff] [blame] | 1249 | |
Julius Werner | 2090854 | 2019-07-24 19:37:54 -0700 | [diff] [blame] | 1250 | if (ret) { |
Daniel Golle | 0cd57f2 | 2022-08-27 04:14:42 +0100 | [diff] [blame] | 1251 | ret = handle_decomp_error(image_comp, load_end - 0, buf_size, ret); |
Julius Werner | 2090854 | 2019-07-24 19:37:54 -0700 | [diff] [blame] | 1252 | if (ret != BOOTM_ERR_UNIMPLEMENTED) |
| 1253 | return ret; |
| 1254 | } |
Simon Glass | ce1400f | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1255 | |
| 1256 | return 0; |
| 1257 | } |
| 1258 | |
| 1259 | int bootm_host_load_images(const void *fit, int cfg_noffset) |
| 1260 | { |
| 1261 | static uint8_t image_types[] = { |
| 1262 | IH_TYPE_KERNEL, |
| 1263 | IH_TYPE_FLATDT, |
| 1264 | IH_TYPE_RAMDISK, |
| 1265 | }; |
| 1266 | int err = 0; |
| 1267 | int i; |
| 1268 | |
| 1269 | for (i = 0; i < ARRAY_SIZE(image_types); i++) { |
| 1270 | int ret; |
| 1271 | |
Simon Glass | 8a9d037 | 2020-03-18 11:44:02 -0600 | [diff] [blame] | 1272 | ret = bootm_host_load_image(fit, image_types[i], cfg_noffset); |
Simon Glass | ce1400f | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1273 | if (!err && ret && ret != -ENOENT) |
| 1274 | err = ret; |
| 1275 | } |
| 1276 | |
| 1277 | /* Return the first error we found */ |
| 1278 | return err; |
| 1279 | } |
Fabrice Fontaine | 93e0788 | 2019-05-03 22:37:05 +0200 | [diff] [blame] | 1280 | #endif |
Simon Glass | ea51a62 | 2014-06-12 07:24:51 -0600 | [diff] [blame] | 1281 | |
| 1282 | #endif /* ndef USE_HOSTCC */ |