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