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 | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 8 | #include <bootm.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 | b3c2aa5 | 2023-09-27 08:22:37 -0600 | [diff] [blame] | 11 | #include <command.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 12 | #include <cpu_func.h> |
Simon Glass | 313112a | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 13 | #include <env.h> |
Simon Glass | 0129b52 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 14 | #include <errno.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 15 | #include <fdt_support.h> |
Simon Glass | 8f3f761 | 2019-11-14 12:57:42 -0700 | [diff] [blame] | 16 | #include <irq_func.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 17 | #include <lmb.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 18 | #include <log.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 19 | #include <malloc.h> |
Joe Hershberger | 65b905b | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 20 | #include <mapmem.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 21 | #include <net.h> |
| 22 | #include <asm/cache.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 23 | #include <asm/global_data.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 24 | #include <asm/io.h> |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 25 | #include <linux/sizes.h> |
Eddie James | 32401ba | 2023-10-24 10:43:50 -0500 | [diff] [blame] | 26 | #include <tpm-v2.h> |
Ilias Apalodimas | ca61532 | 2024-06-23 14:48:14 +0300 | [diff] [blame] | 27 | #include <tpm_tcg2.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 28 | #if defined(CONFIG_CMD_USB) |
| 29 | #include <usb.h> |
| 30 | #endif |
Simon Glass | 0232ba7 | 2014-06-12 07:24:51 -0600 | [diff] [blame] | 31 | #else |
| 32 | #include "mkimage.h" |
| 33 | #endif |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 34 | |
Simon Glass | 0232ba7 | 2014-06-12 07:24:51 -0600 | [diff] [blame] | 35 | #include <bootm.h> |
| 36 | #include <image.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 37 | |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 38 | #define MAX_CMDLINE_SIZE SZ_4K |
| 39 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 40 | #define IH_INITRD_ARCH IH_ARCH_DEFAULT |
| 41 | |
Simon Glass | 0232ba7 | 2014-06-12 07:24:51 -0600 | [diff] [blame] | 42 | #ifndef USE_HOSTCC |
| 43 | |
| 44 | DECLARE_GLOBAL_DATA_PTR; |
| 45 | |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 46 | struct bootm_headers images; /* pointers to os/initrd/fdt images */ |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 47 | |
Simon Glass | 7715b31 | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 48 | __weak void board_quiesce_devices(void) |
| 49 | { |
| 50 | } |
| 51 | |
| 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 | 8333dd5 | 2023-11-18 14:04:58 -0700 | [diff] [blame] | 106 | * boot_get_kernel() - find kernel image |
| 107 | * |
Simon Glass | 8333dd5 | 2023-11-18 14:04:58 -0700 | [diff] [blame] | 108 | * @addr_fit: first argument to bootm: address, fit configuration, etc. |
Simon Glass | 7715b31 | 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 | 8333dd5 | 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 | 9d085c1 | 2023-11-18 14:05:00 -0700 | [diff] [blame] | 113 | * @kernp: image header if valid image was found, otherwise NULL |
Simon Glass | 7715b31 | 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 | c46784c | 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 | 7715b31 | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 120 | */ |
Simon Glass | c46784c | 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 | f55305a | 2018-05-16 09:42:25 -0600 | [diff] [blame] | 123 | { |
Simon Glass | 7715b31 | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 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 | 4e8ec47 | 2023-11-18 14:04:57 -0700 | [diff] [blame] | 129 | const char *fit_uname_config = NULL, *fit_uname_kernel = NULL; |
Simon Glass | 7715b31 | 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 | 8333dd5 | 2023-11-18 14:04:58 -0700 | [diff] [blame] | 138 | img_addr = genimg_get_kernel_addr_fit(addr_fit, &fit_uname_config, |
Simon Glass | 7715b31 | 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 | 9d085c1 | 2023-11-18 14:05:00 -0700 | [diff] [blame] | 156 | return -EINVAL; |
Simon Glass | 7715b31 | 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 | 7715b31 | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 174 | bootstage_error(BOOTSTAGE_ID_CHECK_IMAGETYPE); |
Simon Glass | 9d085c1 | 2023-11-18 14:05:00 -0700 | [diff] [blame] | 175 | return -EPROTOTYPE; |
Simon Glass | 7715b31 | 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 | 9d085c1 | 2023-11-18 14:05:00 -0700 | [diff] [blame] | 200 | return -ENOENT; |
Simon Glass | 7715b31 | 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 | 9d085c1 | 2023-11-18 14:05:00 -0700 | [diff] [blame] | 209 | case IMAGE_FORMAT_ANDROID: { |
| 210 | int ret; |
| 211 | |
Simon Glass | 7715b31 | 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 | 9d085c1 | 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 | 7715b31 | 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 | ae217b3 | 2023-11-18 14:05:01 -0700 | [diff] [blame] | 225 | if (ret) |
| 226 | return ret; |
Simon Glass | 7715b31 | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 227 | break; |
Simon Glass | 9d085c1 | 2023-11-18 14:05:00 -0700 | [diff] [blame] | 228 | } |
Simon Glass | 7715b31 | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 229 | #endif |
| 230 | default: |
Simon Glass | d6d6ed8 | 2023-11-18 14:05:03 -0700 | [diff] [blame] | 231 | bootstage_error(BOOTSTAGE_ID_CHECK_IMAGETYPE); |
Simon Glass | c46784c | 2023-11-18 14:05:04 -0700 | [diff] [blame] | 232 | return -EPROTOTYPE; |
Simon Glass | 7715b31 | 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 | 9d085c1 | 2023-11-18 14:05:00 -0700 | [diff] [blame] | 237 | *kernp = buf; |
Simon Glass | 7715b31 | 2023-11-18 14:04:56 -0700 | [diff] [blame] | 238 | |
Simon Glass | 9d085c1 | 2023-11-18 14:05:00 -0700 | [diff] [blame] | 239 | return 0; |
Simon Glass | f55305a | 2018-05-16 09:42:25 -0600 | [diff] [blame] | 240 | } |
| 241 | |
Simon Glass | 5f1f4f2 | 2023-11-18 14:04:54 -0700 | [diff] [blame] | 242 | static int bootm_start(void) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 243 | { |
| 244 | memset((void *)&images, 0, sizeof(images)); |
Simon Glass | 22c34c2 | 2017-08-03 12:22:13 -0600 | [diff] [blame] | 245 | images.verify = env_get_yesno("verify"); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 246 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 247 | bootstage_mark_name(BOOTSTAGE_ID_BOOTM_START, "bootm_start"); |
| 248 | images.state = BOOTM_STATE_START; |
| 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | |
Simon Glass | 2e719d5 | 2023-11-18 14:04:55 -0700 | [diff] [blame] | 253 | static ulong bootm_data_addr(const char *addr_str) |
Philippe Reynes | ae1f2ca | 2022-03-28 22:57:00 +0200 | [diff] [blame] | 254 | { |
| 255 | ulong addr; |
| 256 | |
Simon Glass | 2e719d5 | 2023-11-18 14:04:55 -0700 | [diff] [blame] | 257 | if (addr_str) |
| 258 | addr = hextoul(addr_str, NULL); |
Philippe Reynes | ae1f2ca | 2022-03-28 22:57:00 +0200 | [diff] [blame] | 259 | else |
| 260 | addr = image_load_addr; |
| 261 | |
| 262 | return addr; |
| 263 | } |
| 264 | |
Simon Glass | 2e719d5 | 2023-11-18 14:04:55 -0700 | [diff] [blame] | 265 | /** |
| 266 | * bootm_pre_load() - Handle the pre-load processing |
| 267 | * |
| 268 | * This can be used to do a full signature check of the image, for example. |
| 269 | * It calls image_pre_load() with the data address of the image to check. |
| 270 | * |
| 271 | * @addr_str: String containing load address in hex, or NULL to use |
| 272 | * image_load_addr |
| 273 | * Return: 0 if OK, CMD_RET_FAILURE on failure |
| 274 | */ |
| 275 | static int bootm_pre_load(const char *addr_str) |
Philippe Reynes | ae1f2ca | 2022-03-28 22:57:00 +0200 | [diff] [blame] | 276 | { |
Simon Glass | 2e719d5 | 2023-11-18 14:04:55 -0700 | [diff] [blame] | 277 | ulong data_addr = bootm_data_addr(addr_str); |
Philippe Reynes | ae1f2ca | 2022-03-28 22:57:00 +0200 | [diff] [blame] | 278 | int ret = 0; |
| 279 | |
Simon Glass | 88b6f92 | 2023-02-05 15:36:24 -0700 | [diff] [blame] | 280 | if (IS_ENABLED(CONFIG_CMD_BOOTM_PRE_LOAD)) |
Philippe Reynes | ae1f2ca | 2022-03-28 22:57:00 +0200 | [diff] [blame] | 281 | ret = image_pre_load(data_addr); |
| 282 | |
| 283 | if (ret) |
| 284 | ret = CMD_RET_FAILURE; |
| 285 | |
| 286 | return ret; |
| 287 | } |
| 288 | |
Simon Glass | f3c57b6 | 2023-11-18 14:05:05 -0700 | [diff] [blame] | 289 | /** |
| 290 | * bootm_find_os(): Find the OS to boot |
| 291 | * |
| 292 | * @cmd_name: Command name that started this boot, e.g. "bootm" |
| 293 | * @addr_fit: Address and/or FIT specifier (first arg of bootm command) |
| 294 | * Return: 0 on success, -ve on error |
| 295 | */ |
| 296 | static int bootm_find_os(const char *cmd_name, const char *addr_fit) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 297 | { |
| 298 | const void *os_hdr; |
Safae Ouajih | 51c981b | 2023-02-06 00:50:17 +0100 | [diff] [blame] | 299 | #ifdef CONFIG_ANDROID_BOOT_IMAGE |
| 300 | const void *vendor_boot_img; |
| 301 | const void *boot_img; |
| 302 | #endif |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 303 | bool ep_found = false; |
Simon Glass | 0129b52 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 304 | int ret; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 305 | |
| 306 | /* get kernel image header, start address and length */ |
Simon Glass | f3c57b6 | 2023-11-18 14:05:05 -0700 | [diff] [blame] | 307 | ret = boot_get_kernel(addr_fit, &images, &images.os.image_start, |
Simon Glass | c46784c | 2023-11-18 14:05:04 -0700 | [diff] [blame] | 308 | &images.os.image_len, &os_hdr); |
Simon Glass | a5d35f9 | 2023-11-18 14:05:02 -0700 | [diff] [blame] | 309 | if (ret) { |
Simon Glass | c46784c | 2023-11-18 14:05:04 -0700 | [diff] [blame] | 310 | if (ret == -EPROTOTYPE) |
Simon Glass | f3c57b6 | 2023-11-18 14:05:05 -0700 | [diff] [blame] | 311 | printf("Wrong Image Type for %s command\n", cmd_name); |
Simon Glass | c46784c | 2023-11-18 14:05:04 -0700 | [diff] [blame] | 312 | |
Simon Glass | a5d35f9 | 2023-11-18 14:05:02 -0700 | [diff] [blame] | 313 | printf("ERROR %dE: can't get kernel image!\n", ret); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 314 | return 1; |
| 315 | } |
| 316 | |
| 317 | /* get image parameters */ |
| 318 | switch (genimg_get_format(os_hdr)) { |
Tom Rini | c220bd9 | 2019-05-23 07:14:07 -0400 | [diff] [blame] | 319 | #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 320 | case IMAGE_FORMAT_LEGACY: |
| 321 | images.os.type = image_get_type(os_hdr); |
| 322 | images.os.comp = image_get_comp(os_hdr); |
| 323 | images.os.os = image_get_os(os_hdr); |
| 324 | |
| 325 | images.os.end = image_get_image_end(os_hdr); |
| 326 | images.os.load = image_get_load(os_hdr); |
Simon Glass | 0129b52 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 327 | images.os.arch = image_get_arch(os_hdr); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 328 | break; |
| 329 | #endif |
Simon Glass | e719d3b | 2021-09-25 19:43:20 -0600 | [diff] [blame] | 330 | #if CONFIG_IS_ENABLED(FIT) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 331 | case IMAGE_FORMAT_FIT: |
| 332 | if (fit_image_get_type(images.fit_hdr_os, |
| 333 | images.fit_noffset_os, |
| 334 | &images.os.type)) { |
| 335 | puts("Can't get image type!\n"); |
| 336 | bootstage_error(BOOTSTAGE_ID_FIT_TYPE); |
| 337 | return 1; |
| 338 | } |
| 339 | |
| 340 | if (fit_image_get_comp(images.fit_hdr_os, |
| 341 | images.fit_noffset_os, |
| 342 | &images.os.comp)) { |
| 343 | puts("Can't get image compression!\n"); |
| 344 | bootstage_error(BOOTSTAGE_ID_FIT_COMPRESSION); |
| 345 | return 1; |
| 346 | } |
| 347 | |
| 348 | if (fit_image_get_os(images.fit_hdr_os, images.fit_noffset_os, |
| 349 | &images.os.os)) { |
| 350 | puts("Can't get image OS!\n"); |
| 351 | bootstage_error(BOOTSTAGE_ID_FIT_OS); |
| 352 | return 1; |
| 353 | } |
| 354 | |
Simon Glass | 0129b52 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 355 | if (fit_image_get_arch(images.fit_hdr_os, |
| 356 | images.fit_noffset_os, |
| 357 | &images.os.arch)) { |
| 358 | puts("Can't get image ARCH!\n"); |
| 359 | return 1; |
| 360 | } |
| 361 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 362 | images.os.end = fit_get_end(images.fit_hdr_os); |
| 363 | |
| 364 | if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os, |
| 365 | &images.os.load)) { |
| 366 | puts("Can't get image load address!\n"); |
| 367 | bootstage_error(BOOTSTAGE_ID_FIT_LOADADDR); |
| 368 | return 1; |
| 369 | } |
| 370 | break; |
| 371 | #endif |
| 372 | #ifdef CONFIG_ANDROID_BOOT_IMAGE |
| 373 | case IMAGE_FORMAT_ANDROID: |
Safae Ouajih | 51c981b | 2023-02-06 00:50:17 +0100 | [diff] [blame] | 374 | boot_img = os_hdr; |
| 375 | vendor_boot_img = NULL; |
| 376 | if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) { |
| 377 | boot_img = map_sysmem(get_abootimg_addr(), 0); |
| 378 | vendor_boot_img = map_sysmem(get_avendor_bootimg_addr(), 0); |
| 379 | } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 380 | images.os.type = IH_TYPE_KERNEL; |
Safae Ouajih | 51c981b | 2023-02-06 00:50:17 +0100 | [diff] [blame] | 381 | images.os.comp = android_image_get_kcomp(boot_img, vendor_boot_img); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 382 | images.os.os = IH_OS_LINUX; |
Safae Ouajih | 51c981b | 2023-02-06 00:50:17 +0100 | [diff] [blame] | 383 | images.os.end = android_image_get_end(boot_img, vendor_boot_img); |
| 384 | images.os.load = android_image_get_kload(boot_img, vendor_boot_img); |
Ahmad Draidi | 9a1cb5d | 2014-10-23 20:50:07 +0300 | [diff] [blame] | 385 | images.ep = images.os.load; |
| 386 | ep_found = true; |
Safae Ouajih | 51c981b | 2023-02-06 00:50:17 +0100 | [diff] [blame] | 387 | if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) { |
| 388 | unmap_sysmem(vendor_boot_img); |
| 389 | unmap_sysmem(boot_img); |
| 390 | } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 391 | break; |
| 392 | #endif |
| 393 | default: |
| 394 | puts("ERROR: unknown image format type!\n"); |
| 395 | return 1; |
| 396 | } |
| 397 | |
Simon Glass | 0129b52 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 398 | /* 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] | 399 | if (images.os.arch == IH_ARCH_I386 || |
| 400 | images.os.arch == IH_ARCH_X86_64) { |
Simon Glass | 0129b52 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 401 | ulong len; |
| 402 | |
| 403 | ret = boot_get_setup(&images, IH_ARCH_I386, &images.ep, &len); |
| 404 | if (ret < 0 && ret != -ENOENT) { |
| 405 | puts("Could not find a valid setup.bin for x86\n"); |
| 406 | return 1; |
| 407 | } |
| 408 | /* Kernel entry point is the setup.bin */ |
| 409 | } else if (images.legacy_hdr_valid) { |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 410 | images.ep = image_get_ep(&images.legacy_hdr_os_copy); |
Simon Glass | e719d3b | 2021-09-25 19:43:20 -0600 | [diff] [blame] | 411 | #if CONFIG_IS_ENABLED(FIT) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 412 | } else if (images.fit_uname_os) { |
| 413 | int ret; |
| 414 | |
| 415 | ret = fit_image_get_entry(images.fit_hdr_os, |
| 416 | images.fit_noffset_os, &images.ep); |
| 417 | if (ret) { |
| 418 | puts("Can't get entry point property!\n"); |
| 419 | return 1; |
| 420 | } |
| 421 | #endif |
| 422 | } else if (!ep_found) { |
| 423 | puts("Could not find kernel entry point!\n"); |
| 424 | return 1; |
| 425 | } |
| 426 | |
| 427 | if (images.os.type == IH_TYPE_KERNEL_NOLOAD) { |
Simon Glass | b1f90ca | 2023-11-19 07:43:33 -0700 | [diff] [blame] | 428 | images.os.load = images.os.image_start; |
| 429 | images.ep += images.os.image_start; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 430 | } |
| 431 | |
Simon Glass | 5b539a0 | 2016-02-24 09:14:42 -0700 | [diff] [blame] | 432 | images.os.start = map_to_sysmem(os_hdr); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 433 | |
| 434 | return 0; |
| 435 | } |
| 436 | |
Simon Glass | ab48be5 | 2023-11-18 14:05:17 -0700 | [diff] [blame] | 437 | /** |
| 438 | * check_overlap() - Check if an image overlaps the OS |
| 439 | * |
| 440 | * @name: Name of image to check (used to print error) |
| 441 | * @base: Base address of image |
| 442 | * @end: End address of image (+1) |
| 443 | * @os_start: Start of OS |
| 444 | * @os_size: Size of OS in bytes |
| 445 | * Return: 0 if OK, -EXDEV if the image overlaps the OS |
| 446 | */ |
| 447 | static int check_overlap(const char *name, ulong base, ulong end, |
| 448 | ulong os_start, ulong os_size) |
| 449 | { |
| 450 | ulong os_end; |
| 451 | |
| 452 | if (!base) |
| 453 | return 0; |
| 454 | os_end = os_start + os_size; |
| 455 | |
| 456 | if ((base >= os_start && base < os_end) || |
| 457 | (end > os_start && end <= os_end) || |
| 458 | (base < os_start && end >= os_end)) { |
| 459 | printf("ERROR: %s image overlaps OS image (OS=%lx..%lx)\n", |
| 460 | name, os_start, os_end); |
| 461 | |
| 462 | return -EXDEV; |
| 463 | } |
| 464 | |
| 465 | return 0; |
| 466 | } |
| 467 | |
Simon Glass | d46c81e | 2023-11-18 14:05:16 -0700 | [diff] [blame] | 468 | int bootm_find_images(ulong img_addr, const char *conf_ramdisk, |
| 469 | const char *conf_fdt, ulong start, ulong size) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 470 | { |
Simon Glass | d46c81e | 2023-11-18 14:05:16 -0700 | [diff] [blame] | 471 | const char *select = conf_ramdisk; |
Simon Glass | 5fb729b | 2023-11-18 14:05:13 -0700 | [diff] [blame] | 472 | char addr_str[17]; |
Simon Glass | af2c72c | 2023-11-18 14:05:09 -0700 | [diff] [blame] | 473 | void *buf; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 474 | int ret; |
| 475 | |
Simon Glass | 8eef77e | 2023-11-18 14:05:06 -0700 | [diff] [blame] | 476 | if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE)) { |
Simon Glass | 8eef77e | 2023-11-18 14:05:06 -0700 | [diff] [blame] | 477 | /* Look for an Android boot image */ |
| 478 | buf = map_sysmem(images.os.start, 0); |
Simon Glass | 5fb729b | 2023-11-18 14:05:13 -0700 | [diff] [blame] | 479 | if (buf && genimg_get_format(buf) == IMAGE_FORMAT_ANDROID) { |
| 480 | strcpy(addr_str, simple_xtoa(img_addr)); |
| 481 | select = addr_str; |
| 482 | } |
Simon Glass | 8eef77e | 2023-11-18 14:05:06 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Simon Glass | d46c81e | 2023-11-18 14:05:16 -0700 | [diff] [blame] | 485 | if (conf_ramdisk) |
| 486 | select = conf_ramdisk; |
Simon Glass | 8eef77e | 2023-11-18 14:05:06 -0700 | [diff] [blame] | 487 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 488 | /* find ramdisk */ |
Simon Glass | 8eef77e | 2023-11-18 14:05:06 -0700 | [diff] [blame] | 489 | ret = boot_get_ramdisk(select, &images, IH_INITRD_ARCH, |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 490 | &images.rd_start, &images.rd_end); |
| 491 | if (ret) { |
| 492 | puts("Ramdisk image is corrupt or invalid\n"); |
| 493 | return 1; |
| 494 | } |
| 495 | |
Tero Kristo | 0608694 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 496 | /* check if ramdisk overlaps OS image */ |
Simon Glass | ab48be5 | 2023-11-18 14:05:17 -0700 | [diff] [blame] | 497 | if (check_overlap("RD", images.rd_start, images.rd_end, start, size)) |
Tero Kristo | 0608694 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 498 | return 1; |
Tero Kristo | 0608694 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 499 | |
Simon Glass | 7f0a5a6 | 2023-11-18 14:05:08 -0700 | [diff] [blame] | 500 | if (CONFIG_IS_ENABLED(OF_LIBFDT)) { |
Simon Glass | af2c72c | 2023-11-18 14:05:09 -0700 | [diff] [blame] | 501 | buf = map_sysmem(img_addr, 0); |
| 502 | |
Simon Glass | 7f0a5a6 | 2023-11-18 14:05:08 -0700 | [diff] [blame] | 503 | /* find flattened device tree */ |
Simon Glass | d46c81e | 2023-11-18 14:05:16 -0700 | [diff] [blame] | 504 | ret = boot_get_fdt(buf, conf_fdt, IH_ARCH_DEFAULT, &images, |
| 505 | &images.ft_addr, &images.ft_len); |
Simon Glass | 7f0a5a6 | 2023-11-18 14:05:08 -0700 | [diff] [blame] | 506 | if (ret) { |
| 507 | puts("Could not find a valid device tree\n"); |
| 508 | return 1; |
| 509 | } |
Tero Kristo | 0608694 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 510 | |
Simon Glass | 7f0a5a6 | 2023-11-18 14:05:08 -0700 | [diff] [blame] | 511 | /* check if FDT overlaps OS image */ |
Simon Glass | ab48be5 | 2023-11-18 14:05:17 -0700 | [diff] [blame] | 512 | if (check_overlap("FDT", map_to_sysmem(images.ft_addr), |
| 513 | images.ft_len, start, size)) |
Simon Glass | 7f0a5a6 | 2023-11-18 14:05:08 -0700 | [diff] [blame] | 514 | return 1; |
Tero Kristo | 0608694 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 515 | |
Simon Glass | 7f0a5a6 | 2023-11-18 14:05:08 -0700 | [diff] [blame] | 516 | if (IS_ENABLED(CONFIG_CMD_FDT)) |
| 517 | set_working_fdt_addr(map_to_sysmem(images.ft_addr)); |
| 518 | } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 519 | |
Simon Glass | e719d3b | 2021-09-25 19:43:20 -0600 | [diff] [blame] | 520 | #if CONFIG_IS_ENABLED(FIT) |
Simon Glass | bc0c4db | 2021-09-25 07:03:20 -0600 | [diff] [blame] | 521 | if (IS_ENABLED(CONFIG_FPGA)) { |
| 522 | /* find bitstreams */ |
Simon Glass | 01080ab | 2023-11-18 14:05:11 -0700 | [diff] [blame] | 523 | ret = boot_get_fpga(&images); |
Simon Glass | bc0c4db | 2021-09-25 07:03:20 -0600 | [diff] [blame] | 524 | if (ret) { |
| 525 | printf("FPGA image is corrupted or invalid\n"); |
| 526 | return 1; |
| 527 | } |
Michal Simek | ebae78b | 2016-05-17 14:03:50 +0200 | [diff] [blame] | 528 | } |
Michal Simek | ebae78b | 2016-05-17 14:03:50 +0200 | [diff] [blame] | 529 | |
Karl Apsite | 1b21c28 | 2015-05-21 09:52:48 -0400 | [diff] [blame] | 530 | /* find all of the loadables */ |
Simon Glass | 4fdc559 | 2023-11-18 14:05:12 -0700 | [diff] [blame] | 531 | ret = boot_get_loadable(&images); |
Karl Apsite | 1b21c28 | 2015-05-21 09:52:48 -0400 | [diff] [blame] | 532 | if (ret) { |
| 533 | printf("Loadable(s) is corrupt or invalid\n"); |
| 534 | return 1; |
| 535 | } |
Karl Apsite | 1b21c28 | 2015-05-21 09:52:48 -0400 | [diff] [blame] | 536 | #endif |
| 537 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 538 | return 0; |
| 539 | } |
| 540 | |
Simon Glass | aba60d1 | 2023-11-18 14:05:18 -0700 | [diff] [blame] | 541 | static int bootm_find_other(ulong img_addr, const char *conf_ramdisk, |
| 542 | const char *conf_fdt) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 543 | { |
Simon Glass | 3f2dcbe | 2023-11-18 14:05:14 -0700 | [diff] [blame] | 544 | if ((images.os.type == IH_TYPE_KERNEL || |
| 545 | images.os.type == IH_TYPE_KERNEL_NOLOAD || |
| 546 | images.os.type == IH_TYPE_MULTI) && |
| 547 | (images.os.os == IH_OS_LINUX || images.os.os == IH_OS_VXWORKS || |
Simon Glass | d46c81e | 2023-11-18 14:05:16 -0700 | [diff] [blame] | 548 | images.os.os == IH_OS_EFI || images.os.os == IH_OS_TEE)) { |
Simon Glass | aba60d1 | 2023-11-18 14:05:18 -0700 | [diff] [blame] | 549 | return bootm_find_images(img_addr, conf_ramdisk, conf_fdt, 0, |
| 550 | 0); |
Simon Glass | d46c81e | 2023-11-18 14:05:16 -0700 | [diff] [blame] | 551 | } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 552 | |
| 553 | return 0; |
| 554 | } |
Simon Glass | 10ae419 | 2014-12-02 13:17:30 -0700 | [diff] [blame] | 555 | #endif /* USE_HOSTC */ |
| 556 | |
Julius Werner | 47ef986 | 2019-07-24 19:37:54 -0700 | [diff] [blame] | 557 | #if !defined(USE_HOSTCC) || defined(CONFIG_FIT_SIGNATURE) |
Simon Glass | 4f6e6d7 | 2014-12-02 13:17:37 -0700 | [diff] [blame] | 558 | /** |
| 559 | * handle_decomp_error() - display a decompression error |
| 560 | * |
| 561 | * This function tries to produce a useful message. In the case where the |
| 562 | * uncompressed size is the same as the available space, we can assume that |
| 563 | * the image is too large for the buffer. |
| 564 | * |
| 565 | * @comp_type: Compression type being used (IH_COMP_...) |
| 566 | * @uncomp_size: Number of bytes uncompressed |
Tom Rini | f3c2f99 | 2022-06-25 19:29:46 -0400 | [diff] [blame] | 567 | * @buf_size: Number of bytes the decompresion buffer was |
Julius Werner | 47ef986 | 2019-07-24 19:37:54 -0700 | [diff] [blame] | 568 | * @ret: errno error code received from compression library |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 569 | * Return: Appropriate BOOTM_ERR_ error code |
Simon Glass | 4f6e6d7 | 2014-12-02 13:17:37 -0700 | [diff] [blame] | 570 | */ |
Tom Rini | f3c2f99 | 2022-06-25 19:29:46 -0400 | [diff] [blame] | 571 | static int handle_decomp_error(int comp_type, size_t uncomp_size, |
| 572 | size_t buf_size, int ret) |
Simon Glass | 10ae419 | 2014-12-02 13:17:30 -0700 | [diff] [blame] | 573 | { |
Simon Glass | 4f6e6d7 | 2014-12-02 13:17:37 -0700 | [diff] [blame] | 574 | const char *name = genimg_get_comp_name(comp_type); |
| 575 | |
Julius Werner | 47ef986 | 2019-07-24 19:37:54 -0700 | [diff] [blame] | 576 | /* ENOSYS means unimplemented compression type, don't reset. */ |
| 577 | if (ret == -ENOSYS) |
| 578 | return BOOTM_ERR_UNIMPLEMENTED; |
| 579 | |
Tom Rini | f3c2f99 | 2022-06-25 19:29:46 -0400 | [diff] [blame] | 580 | if (uncomp_size >= buf_size) |
Simon Glass | 4f6e6d7 | 2014-12-02 13:17:37 -0700 | [diff] [blame] | 581 | printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n"); |
Simon Glass | 10ae419 | 2014-12-02 13:17:30 -0700 | [diff] [blame] | 582 | else |
Simon Glass | 4f6e6d7 | 2014-12-02 13:17:37 -0700 | [diff] [blame] | 583 | printf("%s: uncompress error %d\n", name, ret); |
| 584 | |
| 585 | /* |
| 586 | * The decompression routines are now safe, so will not write beyond |
| 587 | * their bounds. Probably it is not necessary to reset, but maintain |
| 588 | * the current behaviour for now. |
| 589 | */ |
| 590 | printf("Must RESET board to recover\n"); |
Simon Glass | 10ae419 | 2014-12-02 13:17:30 -0700 | [diff] [blame] | 591 | #ifndef USE_HOSTCC |
| 592 | bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE); |
| 593 | #endif |
| 594 | |
| 595 | return BOOTM_ERR_RESET; |
| 596 | } |
Julius Werner | 47ef986 | 2019-07-24 19:37:54 -0700 | [diff] [blame] | 597 | #endif |
Simon Glass | 686f3bb | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 598 | |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 599 | #ifndef USE_HOSTCC |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 600 | static int bootm_load_os(struct bootm_headers *images, int boot_progress) |
Simon Glass | 686f3bb | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 601 | { |
Simon Glass | 74578f5 | 2022-09-06 20:26:51 -0600 | [diff] [blame] | 602 | struct image_info os = images->os; |
Simon Glass | 686f3bb | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 603 | ulong load = os.load; |
Tom Rini | 6c96f5d | 2018-05-01 12:32:37 -0400 | [diff] [blame] | 604 | ulong load_end; |
Simon Glass | 686f3bb | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 605 | ulong blob_start = os.start; |
| 606 | ulong blob_end = os.end; |
| 607 | ulong image_start = os.image_start; |
| 608 | ulong image_len = os.image_len; |
Bryan O'Donoghue | 600388e | 2018-04-15 11:48:17 +0100 | [diff] [blame] | 609 | ulong flush_start = ALIGN_DOWN(load, ARCH_DMA_MINALIGN); |
Simon Glass | 686f3bb | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 610 | bool no_overlap; |
| 611 | void *load_buf, *image_buf; |
| 612 | int err; |
| 613 | |
Simon Glass | 50b8be3 | 2023-11-19 07:43:34 -0700 | [diff] [blame] | 614 | /* |
| 615 | * For a "noload" compressed kernel we need to allocate a buffer large |
| 616 | * enough to decompress in to and use that as the load address now. |
| 617 | * Assume that the kernel compression is at most a factor of 4 since |
| 618 | * zstd almost achieves that. |
| 619 | * Use an alignment of 2MB since this might help arm64 |
| 620 | */ |
| 621 | if (os.type == IH_TYPE_KERNEL_NOLOAD && os.comp != IH_COMP_NONE) { |
| 622 | ulong req_size = ALIGN(image_len * 4, SZ_1M); |
| 623 | |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 624 | load = lmb_alloc(req_size, SZ_2M); |
Simon Glass | 50b8be3 | 2023-11-19 07:43:34 -0700 | [diff] [blame] | 625 | if (!load) |
| 626 | return 1; |
| 627 | os.load = load; |
Simon Glass | 8728c0b | 2023-12-15 16:54:16 -0700 | [diff] [blame] | 628 | images->ep = load; |
Simon Glass | 50b8be3 | 2023-11-19 07:43:34 -0700 | [diff] [blame] | 629 | debug("Allocated %lx bytes at %lx for kernel (size %lx) decompression\n", |
| 630 | req_size, load, image_len); |
| 631 | } |
| 632 | |
Simon Glass | 686f3bb | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 633 | load_buf = map_sysmem(load, 0); |
| 634 | image_buf = map_sysmem(os.image_start, image_len); |
Julius Werner | 47ef986 | 2019-07-24 19:37:54 -0700 | [diff] [blame] | 635 | err = image_decomp(os.comp, load, os.image_start, os.type, |
| 636 | load_buf, image_buf, image_len, |
| 637 | CONFIG_SYS_BOOTM_LEN, &load_end); |
Simon Glass | 686f3bb | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 638 | if (err) { |
Tom Rini | f3c2f99 | 2022-06-25 19:29:46 -0400 | [diff] [blame] | 639 | err = handle_decomp_error(os.comp, load_end - load, |
| 640 | CONFIG_SYS_BOOTM_LEN, err); |
Simon Glass | 686f3bb | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 641 | bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE); |
| 642 | return err; |
| 643 | } |
Heinrich Schuchardt | 6d29e0d | 2020-08-30 11:34:12 +0200 | [diff] [blame] | 644 | /* We need the decompressed image size in the next steps */ |
| 645 | images->os.image_len = load_end - load; |
Bryan O'Donoghue | 600388e | 2018-04-15 11:48:17 +0100 | [diff] [blame] | 646 | |
Trent Piepho | 92e51d0 | 2019-03-27 23:50:09 +0000 | [diff] [blame] | 647 | flush_cache(flush_start, ALIGN(load_end, ARCH_DMA_MINALIGN) - flush_start); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 648 | |
Tom Rini | 6c96f5d | 2018-05-01 12:32:37 -0400 | [diff] [blame] | 649 | 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] | 650 | bootstage_mark(BOOTSTAGE_ID_KERNEL_LOADED); |
| 651 | |
Simon Glass | 686f3bb | 2014-06-12 07:24:52 -0600 | [diff] [blame] | 652 | no_overlap = (os.comp == IH_COMP_NONE && load == image_start); |
| 653 | |
Tom Rini | 6c96f5d | 2018-05-01 12:32:37 -0400 | [diff] [blame] | 654 | if (!no_overlap && load < blob_end && load_end > blob_start) { |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 655 | debug("images.os.start = 0x%lX, images.os.end = 0x%lx\n", |
| 656 | blob_start, blob_end); |
| 657 | debug("images.os.load = 0x%lx, load_end = 0x%lx\n", load, |
Tom Rini | 6c96f5d | 2018-05-01 12:32:37 -0400 | [diff] [blame] | 658 | load_end); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 659 | |
| 660 | /* Check what type of image this is. */ |
| 661 | if (images->legacy_hdr_valid) { |
| 662 | if (image_get_type(&images->legacy_hdr_os_copy) |
| 663 | == IH_TYPE_MULTI) |
| 664 | puts("WARNING: legacy format multi component image overwritten\n"); |
| 665 | return BOOTM_ERR_OVERLAP; |
| 666 | } else { |
| 667 | puts("ERROR: new format image overwritten - must RESET the board to recover\n"); |
| 668 | bootstage_error(BOOTSTAGE_ID_OVERWRITTEN); |
| 669 | return BOOTM_ERR_RESET; |
| 670 | } |
| 671 | } |
| 672 | |
Simon Glass | b1f90ca | 2023-11-19 07:43:33 -0700 | [diff] [blame] | 673 | if (IS_ENABLED(CONFIG_CMD_BOOTI) && images->os.arch == IH_ARCH_ARM64 && |
| 674 | images->os.os == IH_OS_LINUX) { |
| 675 | ulong relocated_addr; |
| 676 | ulong image_size; |
| 677 | int ret; |
| 678 | |
| 679 | ret = booti_setup(load, &relocated_addr, &image_size, false); |
| 680 | if (ret) { |
| 681 | printf("Failed to prep arm64 kernel (err=%d)\n", ret); |
| 682 | return BOOTM_ERR_RESET; |
| 683 | } |
| 684 | |
| 685 | /* Handle BOOTM_STATE_LOADOS */ |
| 686 | if (relocated_addr != load) { |
| 687 | printf("Moving Image from 0x%lx to 0x%lx, end=%lx\n", |
| 688 | load, relocated_addr, |
| 689 | relocated_addr + image_size); |
| 690 | memmove((void *)relocated_addr, load_buf, image_size); |
| 691 | } |
| 692 | |
| 693 | images->ep = relocated_addr; |
| 694 | images->os.start = relocated_addr; |
| 695 | images->os.end = relocated_addr + image_size; |
| 696 | } |
| 697 | |
Sughosh Ganu | 0b39317 | 2024-08-26 17:29:27 +0530 | [diff] [blame] | 698 | if (CONFIG_IS_ENABLED(LMB)) |
| 699 | lmb_reserve(images->os.load, (load_end - images->os.load)); |
| 700 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 701 | return 0; |
| 702 | } |
| 703 | |
| 704 | /** |
| 705 | * bootm_disable_interrupts() - Disable interrupts in preparation for load/boot |
| 706 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 707 | * 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] | 708 | * enabled) |
| 709 | */ |
| 710 | ulong bootm_disable_interrupts(void) |
| 711 | { |
| 712 | ulong iflag; |
| 713 | |
| 714 | /* |
| 715 | * We have reached the point of no return: we are going to |
| 716 | * overwrite all exception vector code, so we cannot easily |
| 717 | * recover from any failures any more... |
| 718 | */ |
| 719 | iflag = disable_interrupts(); |
| 720 | #ifdef CONFIG_NETCONSOLE |
| 721 | /* Stop the ethernet stack if NetConsole could have left it up */ |
| 722 | eth_halt(); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 723 | #endif |
| 724 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 725 | return iflag; |
| 726 | } |
| 727 | |
Simon Glass | 7a8a429 | 2020-11-05 10:33:42 -0700 | [diff] [blame] | 728 | #define CONSOLE_ARG "console=" |
Sean Anderson | 15bdcd4 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 729 | #define NULL_CONSOLE (CONSOLE_ARG "ttynull") |
| 730 | #define CONSOLE_ARG_SIZE sizeof(NULL_CONSOLE) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 731 | |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 732 | /** |
| 733 | * fixup_silent_linux() - Handle silencing the linux boot if required |
| 734 | * |
| 735 | * This uses the silent_linux envvar to control whether to add/set a "console=" |
| 736 | * parameter to the command line |
| 737 | * |
| 738 | * @buf: Buffer containing the string to process |
| 739 | * @maxlen: Maximum length of buffer |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 740 | * Return: 0 if OK, -ENOSPC if @maxlen is too small |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 741 | */ |
| 742 | static int fixup_silent_linux(char *buf, int maxlen) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 743 | { |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 744 | int want_silent; |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 745 | char *cmdline; |
| 746 | int size; |
Simon Glass | 07a8886 | 2020-11-05 10:33:38 -0700 | [diff] [blame] | 747 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 748 | /* |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 749 | * Move the input string to the end of buffer. The output string will be |
| 750 | * built up at the start. |
| 751 | */ |
| 752 | size = strlen(buf) + 1; |
| 753 | if (size * 2 > maxlen) |
| 754 | return -ENOSPC; |
| 755 | cmdline = buf + maxlen - size; |
| 756 | memmove(cmdline, buf, size); |
| 757 | /* |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 758 | * Only fix cmdline when requested. The environment variable can be: |
| 759 | * |
| 760 | * no - we never fixup |
| 761 | * yes - we always fixup |
| 762 | * unset - we rely on the console silent flag |
| 763 | */ |
Simon Glass | 22c34c2 | 2017-08-03 12:22:13 -0600 | [diff] [blame] | 764 | want_silent = env_get_yesno("silent_linux"); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 765 | if (want_silent == 0) |
Simon Glass | 2eab017 | 2020-11-05 10:33:39 -0700 | [diff] [blame] | 766 | return 0; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 767 | else if (want_silent == -1 && !(gd->flags & GD_FLG_SILENT)) |
Simon Glass | 2eab017 | 2020-11-05 10:33:39 -0700 | [diff] [blame] | 768 | return 0; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 769 | |
| 770 | debug("before silent fix-up: %s\n", cmdline); |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 771 | if (*cmdline) { |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 772 | char *start = strstr(cmdline, CONSOLE_ARG); |
| 773 | |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 774 | /* Check space for maximum possible new command line */ |
| 775 | if (size + CONSOLE_ARG_SIZE > maxlen) |
Simon Glass | 2eab017 | 2020-11-05 10:33:39 -0700 | [diff] [blame] | 776 | return -ENOSPC; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 777 | |
| 778 | if (start) { |
| 779 | char *end = strchr(start, ' '); |
Simon Glass | 7a8a429 | 2020-11-05 10:33:42 -0700 | [diff] [blame] | 780 | int start_bytes; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 781 | |
Sean Anderson | 15bdcd4 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 782 | start_bytes = start - cmdline; |
Simon Glass | 7a8a429 | 2020-11-05 10:33:42 -0700 | [diff] [blame] | 783 | strncpy(buf, cmdline, start_bytes); |
Sean Anderson | 15bdcd4 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 784 | strncpy(buf + start_bytes, NULL_CONSOLE, CONSOLE_ARG_SIZE); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 785 | if (end) |
Sean Anderson | 15bdcd4 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 786 | strcpy(buf + start_bytes + CONSOLE_ARG_SIZE - 1, end); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 787 | else |
Sean Anderson | 15bdcd4 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 788 | buf[start_bytes + CONSOLE_ARG_SIZE] = '\0'; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 789 | } else { |
Sean Anderson | 15bdcd4 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 790 | sprintf(buf, "%s %s", cmdline, NULL_CONSOLE); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 791 | } |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 792 | if (buf + strlen(buf) >= cmdline) |
| 793 | return -ENOSPC; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 794 | } else { |
Sean Anderson | 15bdcd4 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 795 | if (maxlen < CONSOLE_ARG_SIZE) |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 796 | return -ENOSPC; |
Sean Anderson | 15bdcd4 | 2022-05-19 18:26:05 -0400 | [diff] [blame] | 797 | strcpy(buf, NULL_CONSOLE); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 798 | } |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 799 | debug("after silent fix-up: %s\n", buf); |
| 800 | |
| 801 | return 0; |
| 802 | } |
| 803 | |
Simon Glass | 529e208 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 804 | /** |
| 805 | * process_subst() - Handle substitution of ${...} fields in the environment |
| 806 | * |
| 807 | * Handle variable substitution in the provided buffer |
| 808 | * |
| 809 | * @buf: Buffer containing the string to process |
| 810 | * @maxlen: Maximum length of buffer |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 811 | * Return: 0 if OK, -ENOSPC if @maxlen is too small |
Simon Glass | 529e208 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 812 | */ |
| 813 | static int process_subst(char *buf, int maxlen) |
| 814 | { |
| 815 | char *cmdline; |
| 816 | int size; |
| 817 | int ret; |
| 818 | |
| 819 | /* Move to end of buffer */ |
| 820 | size = strlen(buf) + 1; |
| 821 | cmdline = buf + maxlen - size; |
| 822 | if (buf + size > cmdline) |
| 823 | return -ENOSPC; |
| 824 | memmove(cmdline, buf, size); |
| 825 | |
| 826 | ret = cli_simple_process_macros(cmdline, buf, cmdline - buf); |
| 827 | |
| 828 | return ret; |
| 829 | } |
| 830 | |
Simon Glass | b4e1b6d | 2020-11-05 10:33:45 -0700 | [diff] [blame] | 831 | int bootm_process_cmdline(char *buf, int maxlen, int flags) |
| 832 | { |
| 833 | int ret; |
| 834 | |
| 835 | /* Check config first to enable compiler to eliminate code */ |
| 836 | if (IS_ENABLED(CONFIG_SILENT_CONSOLE) && |
| 837 | !IS_ENABLED(CONFIG_SILENT_U_BOOT_ONLY) && |
| 838 | (flags & BOOTM_CL_SILENT)) { |
| 839 | ret = fixup_silent_linux(buf, maxlen); |
| 840 | if (ret) |
| 841 | return log_msg_ret("silent", ret); |
| 842 | } |
Simon Glass | ed8603d | 2021-03-15 18:11:23 +1300 | [diff] [blame] | 843 | if (IS_ENABLED(CONFIG_BOOTARGS_SUBST) && IS_ENABLED(CONFIG_CMDLINE) && |
| 844 | (flags & BOOTM_CL_SUBST)) { |
Simon Glass | 529e208 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 845 | ret = process_subst(buf, maxlen); |
| 846 | if (ret) |
Simon Glass | cac744e | 2021-02-06 09:57:35 -0700 | [diff] [blame] | 847 | return log_msg_ret("subst", ret); |
Simon Glass | 529e208 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 848 | } |
Simon Glass | b4e1b6d | 2020-11-05 10:33:45 -0700 | [diff] [blame] | 849 | |
| 850 | return 0; |
| 851 | } |
| 852 | |
Simon Glass | 63660dc | 2020-11-05 10:33:44 -0700 | [diff] [blame] | 853 | int bootm_process_cmdline_env(int flags) |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 854 | { |
| 855 | const int maxlen = MAX_CMDLINE_SIZE; |
Simon Glass | 63660dc | 2020-11-05 10:33:44 -0700 | [diff] [blame] | 856 | bool do_silent; |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 857 | const char *env; |
| 858 | char *buf; |
| 859 | int ret; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 860 | |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 861 | /* First check if any action is needed */ |
| 862 | do_silent = IS_ENABLED(CONFIG_SILENT_CONSOLE) && |
Simon Glass | 63660dc | 2020-11-05 10:33:44 -0700 | [diff] [blame] | 863 | !IS_ENABLED(CONFIG_SILENT_U_BOOT_ONLY) && (flags & BOOTM_CL_SILENT); |
Simon Glass | 529e208 | 2020-11-05 10:33:48 -0700 | [diff] [blame] | 864 | if (!do_silent && !IS_ENABLED(CONFIG_BOOTARGS_SUBST)) |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 865 | return 0; |
| 866 | |
| 867 | env = env_get("bootargs"); |
| 868 | if (env && strlen(env) >= maxlen) |
| 869 | return -E2BIG; |
| 870 | buf = malloc(maxlen); |
| 871 | if (!buf) |
| 872 | return -ENOMEM; |
| 873 | if (env) |
| 874 | strcpy(buf, env); |
| 875 | else |
| 876 | *buf = '\0'; |
Simon Glass | b4e1b6d | 2020-11-05 10:33:45 -0700 | [diff] [blame] | 877 | ret = bootm_process_cmdline(buf, maxlen, flags); |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 878 | if (!ret) { |
| 879 | ret = env_set("bootargs", buf); |
| 880 | |
| 881 | /* |
| 882 | * If buf is "" and bootargs does not exist, this will produce |
| 883 | * an error trying to delete bootargs. Ignore it |
| 884 | */ |
| 885 | if (ret == -ENOENT) |
| 886 | ret = 0; |
| 887 | } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 888 | free(buf); |
Simon Glass | c38406e | 2020-11-05 10:33:43 -0700 | [diff] [blame] | 889 | if (ret) |
| 890 | return log_msg_ret("env", ret); |
Simon Glass | 2eab017 | 2020-11-05 10:33:39 -0700 | [diff] [blame] | 891 | |
| 892 | return 0; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 893 | } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 894 | |
Eddie James | 32401ba | 2023-10-24 10:43:50 -0500 | [diff] [blame] | 895 | int bootm_measure(struct bootm_headers *images) |
| 896 | { |
| 897 | int ret = 0; |
| 898 | |
| 899 | /* Skip measurement if EFI is going to do it */ |
| 900 | if (images->os.os == IH_OS_EFI && |
| 901 | IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL) && |
| 902 | IS_ENABLED(CONFIG_BOOTM_EFI)) |
| 903 | return ret; |
| 904 | |
| 905 | if (IS_ENABLED(CONFIG_MEASURED_BOOT)) { |
| 906 | struct tcg2_event_log elog; |
| 907 | struct udevice *dev; |
| 908 | void *initrd_buf; |
| 909 | void *image_buf; |
| 910 | const char *s; |
| 911 | u32 rd_len; |
| 912 | bool ign; |
| 913 | |
| 914 | elog.log_size = 0; |
| 915 | ign = IS_ENABLED(CONFIG_MEASURE_IGNORE_LOG); |
| 916 | ret = tcg2_measurement_init(&dev, &elog, ign); |
| 917 | if (ret) |
| 918 | return ret; |
| 919 | |
| 920 | image_buf = map_sysmem(images->os.image_start, |
| 921 | images->os.image_len); |
| 922 | ret = tcg2_measure_data(dev, &elog, 8, images->os.image_len, |
| 923 | image_buf, EV_COMPACT_HASH, |
| 924 | strlen("linux") + 1, (u8 *)"linux"); |
| 925 | if (ret) |
| 926 | goto unmap_image; |
| 927 | |
| 928 | rd_len = images->rd_end - images->rd_start; |
| 929 | initrd_buf = map_sysmem(images->rd_start, rd_len); |
| 930 | ret = tcg2_measure_data(dev, &elog, 9, rd_len, initrd_buf, |
| 931 | EV_COMPACT_HASH, strlen("initrd") + 1, |
| 932 | (u8 *)"initrd"); |
| 933 | if (ret) |
| 934 | goto unmap_initrd; |
| 935 | |
| 936 | if (IS_ENABLED(CONFIG_MEASURE_DEVICETREE)) { |
Ilias Apalodimas | c90c195 | 2024-06-14 15:09:50 +0300 | [diff] [blame] | 937 | ret = tcg2_measure_data(dev, &elog, 1, images->ft_len, |
Eddie James | 32401ba | 2023-10-24 10:43:50 -0500 | [diff] [blame] | 938 | (u8 *)images->ft_addr, |
| 939 | EV_TABLE_OF_DEVICES, |
| 940 | strlen("dts") + 1, |
| 941 | (u8 *)"dts"); |
| 942 | if (ret) |
| 943 | goto unmap_initrd; |
| 944 | } |
| 945 | |
| 946 | s = env_get("bootargs"); |
| 947 | if (!s) |
| 948 | s = ""; |
| 949 | ret = tcg2_measure_data(dev, &elog, 1, strlen(s) + 1, (u8 *)s, |
| 950 | EV_PLATFORM_CONFIG_FLAGS, |
| 951 | strlen(s) + 1, (u8 *)s); |
| 952 | |
| 953 | unmap_initrd: |
| 954 | unmap_sysmem(initrd_buf); |
| 955 | |
| 956 | unmap_image: |
| 957 | unmap_sysmem(image_buf); |
| 958 | tcg2_measurement_term(dev, &elog, ret != 0); |
| 959 | } |
| 960 | |
| 961 | return ret; |
| 962 | } |
| 963 | |
Simon Glass | d90f94f | 2023-12-15 20:14:19 -0700 | [diff] [blame] | 964 | int bootm_run_states(struct bootm_info *bmi, int states) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 965 | { |
Simon Glass | 50fa2fe | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 966 | struct bootm_headers *images = bmi->images; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 967 | boot_os_fn *boot_fn; |
| 968 | ulong iflag = 0; |
| 969 | int ret = 0, need_boot_fn; |
| 970 | |
| 971 | images->state |= states; |
| 972 | |
| 973 | /* |
| 974 | * Work through the states and see how far we get. We stop on |
| 975 | * any error. |
| 976 | */ |
| 977 | if (states & BOOTM_STATE_START) |
Simon Glass | 5f1f4f2 | 2023-11-18 14:04:54 -0700 | [diff] [blame] | 978 | ret = bootm_start(); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 979 | |
Philippe Reynes | ae1f2ca | 2022-03-28 22:57:00 +0200 | [diff] [blame] | 980 | if (!ret && (states & BOOTM_STATE_PRE_LOAD)) |
Simon Glass | 50fa2fe | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 981 | ret = bootm_pre_load(bmi->addr_img); |
Philippe Reynes | ae1f2ca | 2022-03-28 22:57:00 +0200 | [diff] [blame] | 982 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 983 | if (!ret && (states & BOOTM_STATE_FINDOS)) |
Simon Glass | 50fa2fe | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 984 | ret = bootm_find_os(bmi->cmd_name, bmi->addr_img); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 985 | |
Simon Glass | aba60d1 | 2023-11-18 14:05:18 -0700 | [diff] [blame] | 986 | if (!ret && (states & BOOTM_STATE_FINDOTHER)) { |
| 987 | ulong img_addr; |
| 988 | |
Simon Glass | 50fa2fe | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 989 | img_addr = bmi->addr_img ? hextoul(bmi->addr_img, NULL) |
| 990 | : image_load_addr; |
| 991 | ret = bootm_find_other(img_addr, bmi->conf_ramdisk, |
| 992 | bmi->conf_fdt); |
Simon Glass | aba60d1 | 2023-11-18 14:05:18 -0700 | [diff] [blame] | 993 | } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 994 | |
Eddie James | 32401ba | 2023-10-24 10:43:50 -0500 | [diff] [blame] | 995 | if (IS_ENABLED(CONFIG_MEASURED_BOOT) && !ret && |
| 996 | (states & BOOTM_STATE_MEASURE)) |
| 997 | bootm_measure(images); |
| 998 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 999 | /* Load the OS */ |
| 1000 | if (!ret && (states & BOOTM_STATE_LOADOS)) { |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1001 | iflag = bootm_disable_interrupts(); |
Tom Rini | 6c96f5d | 2018-05-01 12:32:37 -0400 | [diff] [blame] | 1002 | ret = bootm_load_os(images, 0); |
| 1003 | if (ret && ret != BOOTM_ERR_OVERLAP) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1004 | goto err; |
| 1005 | else if (ret == BOOTM_ERR_OVERLAP) |
| 1006 | ret = 0; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | /* Relocate the ramdisk */ |
| 1010 | #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH |
| 1011 | if (!ret && (states & BOOTM_STATE_RAMDISK)) { |
| 1012 | ulong rd_len = images->rd_end - images->rd_start; |
| 1013 | |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 1014 | ret = boot_ramdisk_high(images->rd_start, rd_len, |
| 1015 | &images->initrd_start, |
| 1016 | &images->initrd_end); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1017 | if (!ret) { |
Simon Glass | 4d949a2 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 1018 | env_set_hex("initrd_start", images->initrd_start); |
| 1019 | env_set_hex("initrd_end", images->initrd_end); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1020 | } |
| 1021 | } |
| 1022 | #endif |
Sughosh Ganu | 0d733f0 | 2024-08-26 17:29:22 +0530 | [diff] [blame] | 1023 | #if CONFIG_IS_ENABLED(OF_LIBFDT) && CONFIG_IS_ENABLED(LMB) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1024 | if (!ret && (states & BOOTM_STATE_FDT)) { |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 1025 | boot_fdt_add_mem_rsv_regions(images->ft_addr); |
| 1026 | ret = boot_relocate_fdt(&images->ft_addr, &images->ft_len); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1027 | } |
| 1028 | #endif |
| 1029 | |
| 1030 | /* From now on, we need the OS boot function */ |
| 1031 | if (ret) |
| 1032 | return ret; |
| 1033 | boot_fn = bootm_os_get_boot_func(images->os.os); |
| 1034 | need_boot_fn = states & (BOOTM_STATE_OS_CMDLINE | |
| 1035 | BOOTM_STATE_OS_BD_T | BOOTM_STATE_OS_PREP | |
| 1036 | BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO); |
| 1037 | if (boot_fn == NULL && need_boot_fn) { |
| 1038 | if (iflag) |
| 1039 | enable_interrupts(); |
| 1040 | printf("ERROR: booting os '%s' (%d) is not supported\n", |
| 1041 | genimg_get_os_name(images->os.os), images->os.os); |
| 1042 | bootstage_error(BOOTSTAGE_ID_CHECK_BOOT_OS); |
| 1043 | return 1; |
| 1044 | } |
| 1045 | |
| 1046 | /* Call various other states that are not generally used */ |
| 1047 | if (!ret && (states & BOOTM_STATE_OS_CMDLINE)) |
Simon Glass | 50fa2fe | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 1048 | ret = boot_fn(BOOTM_STATE_OS_CMDLINE, bmi); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1049 | if (!ret && (states & BOOTM_STATE_OS_BD_T)) |
Simon Glass | 50fa2fe | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 1050 | ret = boot_fn(BOOTM_STATE_OS_BD_T, bmi); |
Hector Palacios | 8f9cc4c | 2016-07-11 12:34:37 +0200 | [diff] [blame] | 1051 | if (!ret && (states & BOOTM_STATE_OS_PREP)) { |
Piotr Kubik | c975d8b | 2023-11-24 17:30:46 +0100 | [diff] [blame] | 1052 | int flags = 0; |
| 1053 | /* For Linux OS do all substitutions at console processing */ |
| 1054 | if (images->os.os == IH_OS_LINUX) |
| 1055 | flags = BOOTM_CL_ALL; |
| 1056 | ret = bootm_process_cmdline_env(flags); |
Simon Glass | d87002f | 2020-11-05 10:33:41 -0700 | [diff] [blame] | 1057 | if (ret) { |
| 1058 | printf("Cmdline setup failed (err=%d)\n", ret); |
| 1059 | ret = CMD_RET_FAILURE; |
| 1060 | goto err; |
Simon Glass | 2eab017 | 2020-11-05 10:33:39 -0700 | [diff] [blame] | 1061 | } |
Simon Glass | 50fa2fe | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 1062 | ret = boot_fn(BOOTM_STATE_OS_PREP, bmi); |
Hector Palacios | 8f9cc4c | 2016-07-11 12:34:37 +0200 | [diff] [blame] | 1063 | } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1064 | |
| 1065 | #ifdef CONFIG_TRACE |
| 1066 | /* Pretend to run the OS, then run a user command */ |
| 1067 | if (!ret && (states & BOOTM_STATE_OS_FAKE_GO)) { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 1068 | char *cmd_list = env_get("fakegocmd"); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1069 | |
Simon Glass | 454746d | 2023-12-15 20:14:20 -0700 | [diff] [blame] | 1070 | ret = boot_selected_os(BOOTM_STATE_OS_FAKE_GO, bmi, boot_fn); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1071 | if (!ret && cmd_list) |
Simon Glass | 50fa2fe | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 1072 | ret = run_command_list(cmd_list, -1, 0); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1073 | } |
| 1074 | #endif |
| 1075 | |
| 1076 | /* Check for unsupported subcommand. */ |
| 1077 | if (ret) { |
Simon Glass | b90cf90 | 2022-10-11 09:47:07 -0600 | [diff] [blame] | 1078 | printf("subcommand failed (err=%d)\n", ret); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1079 | return ret; |
| 1080 | } |
| 1081 | |
| 1082 | /* Now run the OS! We hope this doesn't return */ |
| 1083 | if (!ret && (states & BOOTM_STATE_OS_GO)) |
Simon Glass | 454746d | 2023-12-15 20:14:20 -0700 | [diff] [blame] | 1084 | ret = boot_selected_os(BOOTM_STATE_OS_GO, bmi, boot_fn); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1085 | |
| 1086 | /* Deal with any fallout */ |
| 1087 | err: |
| 1088 | if (iflag) |
| 1089 | enable_interrupts(); |
| 1090 | |
Simon Glass | b890c08 | 2023-12-15 20:14:10 -0700 | [diff] [blame] | 1091 | if (ret == BOOTM_ERR_UNIMPLEMENTED) { |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1092 | bootstage_error(BOOTSTAGE_ID_DECOMP_UNIMPL); |
Simon Glass | b890c08 | 2023-12-15 20:14:10 -0700 | [diff] [blame] | 1093 | } else if (ret == BOOTM_ERR_RESET) { |
| 1094 | printf("Resetting the board...\n"); |
| 1095 | reset_cpu(); |
| 1096 | } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 1097 | |
| 1098 | return ret; |
| 1099 | } |
| 1100 | |
Simon Glass | 6568e4b | 2023-12-15 20:14:26 -0700 | [diff] [blame] | 1101 | int boot_run(struct bootm_info *bmi, const char *cmd, int extra_states) |
Simon Glass | bd73cac | 2023-12-15 20:14:21 -0700 | [diff] [blame] | 1102 | { |
| 1103 | int states; |
| 1104 | |
Simon Glass | 6568e4b | 2023-12-15 20:14:26 -0700 | [diff] [blame] | 1105 | bmi->cmd_name = cmd; |
| 1106 | states = BOOTM_STATE_MEASURE | BOOTM_STATE_OS_PREP | |
| 1107 | BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO; |
Simon Glass | bd73cac | 2023-12-15 20:14:21 -0700 | [diff] [blame] | 1108 | if (IS_ENABLED(CONFIG_SYS_BOOT_RAMDISK_HIGH)) |
| 1109 | states |= BOOTM_STATE_RAMDISK; |
Simon Glass | 6568e4b | 2023-12-15 20:14:26 -0700 | [diff] [blame] | 1110 | states |= extra_states; |
Simon Glass | bd73cac | 2023-12-15 20:14:21 -0700 | [diff] [blame] | 1111 | |
| 1112 | return bootm_run_states(bmi, states); |
| 1113 | } |
| 1114 | |
Simon Glass | 6568e4b | 2023-12-15 20:14:26 -0700 | [diff] [blame] | 1115 | int bootm_run(struct bootm_info *bmi) |
Simon Glass | e176bb1 | 2023-12-15 20:14:23 -0700 | [diff] [blame] | 1116 | { |
Simon Glass | 6568e4b | 2023-12-15 20:14:26 -0700 | [diff] [blame] | 1117 | return boot_run(bmi, "bootm", BOOTM_STATE_START | BOOTM_STATE_FINDOS | |
| 1118 | BOOTM_STATE_PRE_LOAD | BOOTM_STATE_FINDOTHER | |
| 1119 | BOOTM_STATE_LOADOS); |
| 1120 | } |
Simon Glass | e176bb1 | 2023-12-15 20:14:23 -0700 | [diff] [blame] | 1121 | |
Simon Glass | 6568e4b | 2023-12-15 20:14:26 -0700 | [diff] [blame] | 1122 | int bootz_run(struct bootm_info *bmi) |
| 1123 | { |
| 1124 | return boot_run(bmi, "bootz", 0); |
Simon Glass | e176bb1 | 2023-12-15 20:14:23 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
Simon Glass | 2d043a6 | 2023-12-15 20:14:25 -0700 | [diff] [blame] | 1127 | int booti_run(struct bootm_info *bmi) |
| 1128 | { |
Simon Glass | 6568e4b | 2023-12-15 20:14:26 -0700 | [diff] [blame] | 1129 | return boot_run(bmi, "booti", 0); |
Simon Glass | 2d043a6 | 2023-12-15 20:14:25 -0700 | [diff] [blame] | 1130 | } |
| 1131 | |
Simon Glass | 1870026 | 2023-07-30 11:17:02 -0600 | [diff] [blame] | 1132 | int bootm_boot_start(ulong addr, const char *cmdline) |
| 1133 | { |
Simon Glass | 1870026 | 2023-07-30 11:17:02 -0600 | [diff] [blame] | 1134 | char addr_str[30]; |
Simon Glass | 50fa2fe | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 1135 | struct bootm_info bmi; |
Simon Glass | 1870026 | 2023-07-30 11:17:02 -0600 | [diff] [blame] | 1136 | int states; |
| 1137 | int ret; |
| 1138 | |
Simon Glass | 1870026 | 2023-07-30 11:17:02 -0600 | [diff] [blame] | 1139 | states = BOOTM_STATE_START | BOOTM_STATE_FINDOS | BOOTM_STATE_PRE_LOAD | |
| 1140 | BOOTM_STATE_FINDOTHER | BOOTM_STATE_LOADOS | |
| 1141 | BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | |
| 1142 | BOOTM_STATE_OS_GO; |
| 1143 | if (IS_ENABLED(CONFIG_SYS_BOOT_RAMDISK_HIGH)) |
| 1144 | states |= BOOTM_STATE_RAMDISK; |
| 1145 | if (IS_ENABLED(CONFIG_PPC) || IS_ENABLED(CONFIG_MIPS)) |
| 1146 | states |= BOOTM_STATE_OS_CMDLINE; |
| 1147 | images.state |= states; |
| 1148 | |
| 1149 | snprintf(addr_str, sizeof(addr_str), "%lx", addr); |
| 1150 | |
| 1151 | ret = env_set("bootargs", cmdline); |
| 1152 | if (ret) { |
| 1153 | printf("Failed to set cmdline\n"); |
| 1154 | return ret; |
| 1155 | } |
Simon Glass | 50fa2fe | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 1156 | bootm_init(&bmi); |
| 1157 | bmi.addr_img = addr_str; |
| 1158 | bmi.cmd_name = "bootm"; |
Simon Glass | d90f94f | 2023-12-15 20:14:19 -0700 | [diff] [blame] | 1159 | ret = bootm_run_states(&bmi, states); |
Simon Glass | 1870026 | 2023-07-30 11:17:02 -0600 | [diff] [blame] | 1160 | |
| 1161 | return ret; |
| 1162 | } |
| 1163 | |
Simon Glass | 112b020 | 2023-12-15 20:14:14 -0700 | [diff] [blame] | 1164 | void bootm_init(struct bootm_info *bmi) |
| 1165 | { |
| 1166 | memset(bmi, '\0', sizeof(struct bootm_info)); |
| 1167 | bmi->boot_progress = true; |
| 1168 | if (IS_ENABLED(CONFIG_CMD_BOOTM)) |
| 1169 | bmi->images = &images; |
| 1170 | } |
| 1171 | |
Heinrich Schuchardt | aa0b11b | 2019-01-08 18:13:06 +0100 | [diff] [blame] | 1172 | /** |
| 1173 | * switch_to_non_secure_mode() - switch to non-secure mode |
| 1174 | * |
| 1175 | * This routine is overridden by architectures requiring this feature. |
| 1176 | */ |
| 1177 | void __weak switch_to_non_secure_mode(void) |
| 1178 | { |
| 1179 | } |
| 1180 | |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1181 | #else /* USE_HOSTCC */ |
| 1182 | |
Fabrice Fontaine | d00d6b5 | 2019-05-03 22:37:05 +0200 | [diff] [blame] | 1183 | #if defined(CONFIG_FIT_SIGNATURE) |
Simon Glass | 81d1387 | 2020-03-18 11:44:02 -0600 | [diff] [blame] | 1184 | static int bootm_host_load_image(const void *fit, int req_image_type, |
| 1185 | int cfg_noffset) |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1186 | { |
| 1187 | const char *fit_uname_config = NULL; |
| 1188 | ulong data, len; |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 1189 | struct bootm_headers images; |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1190 | int noffset; |
Tom Rini | f3c2f99 | 2022-06-25 19:29:46 -0400 | [diff] [blame] | 1191 | ulong load_end, buf_size; |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1192 | uint8_t image_type; |
Daniel Golle | 905d4b7 | 2022-08-27 04:14:42 +0100 | [diff] [blame] | 1193 | uint8_t image_comp; |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1194 | void *load_buf; |
| 1195 | int ret; |
| 1196 | |
Simon Glass | 81d1387 | 2020-03-18 11:44:02 -0600 | [diff] [blame] | 1197 | fit_uname_config = fdt_get_name(fit, cfg_noffset, NULL); |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1198 | memset(&images, '\0', sizeof(images)); |
| 1199 | images.verify = 1; |
| 1200 | noffset = fit_image_load(&images, (ulong)fit, |
| 1201 | NULL, &fit_uname_config, |
| 1202 | IH_ARCH_DEFAULT, req_image_type, -1, |
| 1203 | FIT_LOAD_IGNORED, &data, &len); |
| 1204 | if (noffset < 0) |
| 1205 | return noffset; |
| 1206 | if (fit_image_get_type(fit, noffset, &image_type)) { |
| 1207 | puts("Can't get image type!\n"); |
| 1208 | return -EINVAL; |
| 1209 | } |
| 1210 | |
Daniel Golle | 2ebfd22 | 2022-08-27 04:17:28 +0100 | [diff] [blame] | 1211 | if (fit_image_get_comp(fit, noffset, &image_comp)) |
| 1212 | image_comp = IH_COMP_NONE; |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1213 | |
| 1214 | /* 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] | 1215 | buf_size = (1 << 20) + len * 4; |
| 1216 | load_buf = malloc(buf_size); |
Daniel Golle | 905d4b7 | 2022-08-27 04:14:42 +0100 | [diff] [blame] | 1217 | ret = image_decomp(image_comp, 0, data, image_type, load_buf, |
Tom Rini | f3c2f99 | 2022-06-25 19:29:46 -0400 | [diff] [blame] | 1218 | (void *)data, len, buf_size, &load_end); |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1219 | free(load_buf); |
Simon Glass | 5aeccc2 | 2014-12-02 13:17:33 -0700 | [diff] [blame] | 1220 | |
Julius Werner | 47ef986 | 2019-07-24 19:37:54 -0700 | [diff] [blame] | 1221 | if (ret) { |
Daniel Golle | 905d4b7 | 2022-08-27 04:14:42 +0100 | [diff] [blame] | 1222 | ret = handle_decomp_error(image_comp, load_end - 0, buf_size, ret); |
Julius Werner | 47ef986 | 2019-07-24 19:37:54 -0700 | [diff] [blame] | 1223 | if (ret != BOOTM_ERR_UNIMPLEMENTED) |
| 1224 | return ret; |
| 1225 | } |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1226 | |
| 1227 | return 0; |
| 1228 | } |
| 1229 | |
| 1230 | int bootm_host_load_images(const void *fit, int cfg_noffset) |
| 1231 | { |
| 1232 | static uint8_t image_types[] = { |
| 1233 | IH_TYPE_KERNEL, |
| 1234 | IH_TYPE_FLATDT, |
| 1235 | IH_TYPE_RAMDISK, |
| 1236 | }; |
| 1237 | int err = 0; |
| 1238 | int i; |
| 1239 | |
| 1240 | for (i = 0; i < ARRAY_SIZE(image_types); i++) { |
| 1241 | int ret; |
| 1242 | |
Simon Glass | 81d1387 | 2020-03-18 11:44:02 -0600 | [diff] [blame] | 1243 | ret = bootm_host_load_image(fit, image_types[i], cfg_noffset); |
Simon Glass | a51991d | 2014-06-12 07:24:53 -0600 | [diff] [blame] | 1244 | if (!err && ret && ret != -ENOENT) |
| 1245 | err = ret; |
| 1246 | } |
| 1247 | |
| 1248 | /* Return the first error we found */ |
| 1249 | return err; |
| 1250 | } |
Fabrice Fontaine | d00d6b5 | 2019-05-03 22:37:05 +0200 | [diff] [blame] | 1251 | #endif |
Simon Glass | 0232ba7 | 2014-06-12 07:24:51 -0600 | [diff] [blame] | 1252 | |
| 1253 | #endif /* ndef USE_HOSTCC */ |