]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
b97a2a0a MB |
2 | /* |
3 | * (C) Copyright 2008 Semihalf | |
4 | * | |
5 | * (C) Copyright 2000-2006 | |
6 | * Wolfgang Denk, DENX Software Engineering, [email protected]. | |
b97a2a0a | 7 | */ |
ceaed2b1 | 8 | |
b97a2a0a | 9 | #ifndef USE_HOSTCC |
5ad03eb3 | 10 | #include <common.h> |
52f24238 | 11 | #include <bootstage.h> |
1eb69ae4 | 12 | #include <cpu_func.h> |
7b51b576 | 13 | #include <env.h> |
4d72caa5 | 14 | #include <lmb.h> |
f7ae49fc | 15 | #include <log.h> |
336d4615 | 16 | #include <malloc.h> |
90526e9f | 17 | #include <asm/cache.h> |
3db71108 | 18 | #include <u-boot/crc.h> |
5ad03eb3 MB |
19 | #include <watchdog.h> |
20 | ||
21 | #ifdef CONFIG_SHOW_BOOT_PROGRESS | |
22 | #include <status_led.h> | |
23 | #endif | |
24 | ||
2242f536 | 25 | #include <rtc.h> |
2242f536 | 26 | |
0c670fc1 | 27 | #include <gzip.h> |
5dfb5213 | 28 | #include <image.h> |
6c03f9e6 | 29 | #include <lz4.h> |
0eb25b61 | 30 | #include <mapmem.h> |
5dfb5213 | 31 | |
aa34fbc0 | 32 | #if IMAGE_ENABLE_FIT || IMAGE_ENABLE_OF_LIBFDT |
b08c8c48 | 33 | #include <linux/libfdt.h> |
fff888a1 | 34 | #include <fdt_support.h> |
62afc601 MS |
35 | #include <fpga.h> |
36 | #include <xilinx.h> | |
c8779648 MB |
37 | #endif |
38 | ||
20a14a42 | 39 | #include <u-boot/md5.h> |
2b9912e6 | 40 | #include <u-boot/sha1.h> |
1221ce45 | 41 | #include <linux/errno.h> |
35e7b0f1 | 42 | #include <asm/io.h> |
c8779648 | 43 | |
2090854c JW |
44 | #include <bzlib.h> |
45 | #include <linux/lzo.h> | |
46 | #include <lzma/LzmaTypes.h> | |
47 | #include <lzma/LzmaDec.h> | |
48 | #include <lzma/LzmaTools.h> | |
49 | ||
b6b0fe64 | 50 | #ifdef CONFIG_CMD_BDI |
09140113 SG |
51 | extern int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, |
52 | char *const argv[]); | |
b6b0fe64 MB |
53 | #endif |
54 | ||
55 | DECLARE_GLOBAL_DATA_PTR; | |
8a5ea3e6 | 56 | |
c76c93a3 | 57 | #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) |
712fbcf3 | 58 | static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch, |
d985c849 | 59 | int verify); |
21d29f7f | 60 | #endif |
b97a2a0a | 61 | #else |
5ad03eb3 | 62 | #include "mkimage.h" |
20a14a42 | 63 | #include <u-boot/md5.h> |
5dfb5213 | 64 | #include <time.h> |
b97a2a0a | 65 | #include <image.h> |
80402f34 HS |
66 | |
67 | #ifndef __maybe_unused | |
68 | # define __maybe_unused /* unimplemented */ | |
69 | #endif | |
5dfb5213 | 70 | #endif /* !USE_HOSTCC*/ |
b97a2a0a | 71 | |
0ccff500 | 72 | #include <u-boot/crc.h> |
5b20d141 | 73 | #include <imximage.h> |
0ccff500 | 74 | |
13d06981 SG |
75 | #ifndef CONFIG_SYS_BARGSIZE |
76 | #define CONFIG_SYS_BARGSIZE 512 | |
77 | #endif | |
78 | ||
7edb186f | 79 | static const table_entry_t uimage_arch[] = { |
30495bff | 80 | { IH_ARCH_INVALID, "invalid", "Invalid ARCH", }, |
570abb0a MB |
81 | { IH_ARCH_ALPHA, "alpha", "Alpha", }, |
82 | { IH_ARCH_ARM, "arm", "ARM", }, | |
83 | { IH_ARCH_I386, "x86", "Intel x86", }, | |
84 | { IH_ARCH_IA64, "ia64", "IA64", }, | |
85 | { IH_ARCH_M68K, "m68k", "M68K", }, | |
86 | { IH_ARCH_MICROBLAZE, "microblaze", "MicroBlaze", }, | |
87 | { IH_ARCH_MIPS, "mips", "MIPS", }, | |
88 | { IH_ARCH_MIPS64, "mips64", "MIPS 64 Bit", }, | |
570abb0a | 89 | { IH_ARCH_NIOS2, "nios2", "NIOS II", }, |
e419e12d | 90 | { IH_ARCH_PPC, "powerpc", "PowerPC", }, |
570abb0a MB |
91 | { IH_ARCH_PPC, "ppc", "PowerPC", }, |
92 | { IH_ARCH_S390, "s390", "IBM S390", }, | |
93 | { IH_ARCH_SH, "sh", "SuperH", }, | |
94 | { IH_ARCH_SPARC, "sparc", "SPARC", }, | |
95 | { IH_ARCH_SPARC64, "sparc64", "SPARC 64 Bit", }, | |
96 | { IH_ARCH_BLACKFIN, "blackfin", "Blackfin", }, | |
97 | { IH_ARCH_AVR32, "avr32", "AVR32", }, | |
64d61461 | 98 | { IH_ARCH_NDS32, "nds32", "NDS32", }, |
3ddcaccd | 99 | { IH_ARCH_OPENRISC, "or1k", "OpenRISC 1000",}, |
35e7b0f1 | 100 | { IH_ARCH_SANDBOX, "sandbox", "Sandbox", }, |
0ae76531 | 101 | { IH_ARCH_ARM64, "arm64", "AArch64", }, |
bc5d5428 | 102 | { IH_ARCH_ARC, "arc", "ARC", }, |
5bda35cf | 103 | { IH_ARCH_X86_64, "x86_64", "AMD x86_64", }, |
de5e5cea | 104 | { IH_ARCH_XTENSA, "xtensa", "Xtensa", }, |
86aa65a0 | 105 | { IH_ARCH_RISCV, "riscv", "RISC-V", }, |
570abb0a MB |
106 | { -1, "", "", }, |
107 | }; | |
108 | ||
7edb186f | 109 | static const table_entry_t uimage_os[] = { |
30495bff | 110 | { IH_OS_INVALID, "invalid", "Invalid OS", }, |
4914af12 | 111 | { IH_OS_ARM_TRUSTED_FIRMWARE, "arm-trusted-firmware", "ARM Trusted Firmware" }, |
570abb0a MB |
112 | { IH_OS_LINUX, "linux", "Linux", }, |
113 | #if defined(CONFIG_LYNXKDI) || defined(USE_HOSTCC) | |
114 | { IH_OS_LYNXOS, "lynxos", "LynxOS", }, | |
115 | #endif | |
116 | { IH_OS_NETBSD, "netbsd", "NetBSD", }, | |
3df61957 | 117 | { IH_OS_OSE, "ose", "Enea OSE", }, |
04d41409 | 118 | { IH_OS_PLAN9, "plan9", "Plan 9", }, |
570abb0a | 119 | { IH_OS_RTEMS, "rtems", "RTEMS", }, |
45b55712 | 120 | { IH_OS_TEE, "tee", "Trusted Execution Environment" }, |
570abb0a | 121 | { IH_OS_U_BOOT, "u-boot", "U-Boot", }, |
68b15e83 | 122 | { IH_OS_VXWORKS, "vxworks", "VxWorks", }, |
570abb0a MB |
123 | #if defined(CONFIG_CMD_ELF) || defined(USE_HOSTCC) |
124 | { IH_OS_QNX, "qnx", "QNX", }, | |
570abb0a | 125 | #endif |
f5ed9e39 PT |
126 | #if defined(CONFIG_INTEGRITY) || defined(USE_HOSTCC) |
127 | { IH_OS_INTEGRITY,"integrity", "INTEGRITY", }, | |
128 | #endif | |
570abb0a MB |
129 | #ifdef USE_HOSTCC |
130 | { IH_OS_4_4BSD, "4_4bsd", "4_4BSD", }, | |
131 | { IH_OS_DELL, "dell", "Dell", }, | |
132 | { IH_OS_ESIX, "esix", "Esix", }, | |
133 | { IH_OS_FREEBSD, "freebsd", "FreeBSD", }, | |
134 | { IH_OS_IRIX, "irix", "Irix", }, | |
135 | { IH_OS_NCR, "ncr", "NCR", }, | |
136 | { IH_OS_OPENBSD, "openbsd", "OpenBSD", }, | |
137 | { IH_OS_PSOS, "psos", "pSOS", }, | |
138 | { IH_OS_SCO, "sco", "SCO", }, | |
139 | { IH_OS_SOLARIS, "solaris", "Solaris", }, | |
140 | { IH_OS_SVR4, "svr4", "SVR4", }, | |
141 | #endif | |
67ddd955 MV |
142 | #if defined(CONFIG_BOOTM_OPENRTOS) || defined(USE_HOSTCC) |
143 | { IH_OS_OPENRTOS, "openrtos", "OpenRTOS", }, | |
144 | #endif | |
5e30e45c | 145 | { IH_OS_OPENSBI, "opensbi", "RISC-V OpenSBI", }, |
a031b03f | 146 | { IH_OS_EFI, "efi", "EFI Firmware" }, |
67ddd955 | 147 | |
570abb0a MB |
148 | { -1, "", "", }, |
149 | }; | |
150 | ||
7edb186f | 151 | static const table_entry_t uimage_type[] = { |
4962e38e | 152 | { IH_TYPE_AISIMAGE, "aisimage", "Davinci AIS image",}, |
570abb0a MB |
153 | { IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image", }, |
154 | { IH_TYPE_FIRMWARE, "firmware", "Firmware", }, | |
3decb14a | 155 | { IH_TYPE_FLATDT, "flat_dt", "Flat Device Tree", }, |
bf411ea9 | 156 | { IH_TYPE_GPIMAGE, "gpimage", "TI Keystone SPL Image",}, |
570abb0a | 157 | { IH_TYPE_KERNEL, "kernel", "Kernel Image", }, |
b9b50e89 | 158 | { IH_TYPE_KERNEL_NOLOAD, "kernel_noload", "Kernel Image (no loading done)", }, |
4962e38e SB |
159 | { IH_TYPE_KWBIMAGE, "kwbimage", "Kirkwood Boot Image",}, |
160 | { IH_TYPE_IMXIMAGE, "imximage", "Freescale i.MX Boot Image",}, | |
a2b96ece | 161 | { IH_TYPE_IMX8IMAGE, "imx8image", "NXP i.MX8 Boot Image",}, |
6609c266 | 162 | { IH_TYPE_IMX8MIMAGE, "imx8mimage", "NXP i.MX8M Boot Image",}, |
30495bff | 163 | { IH_TYPE_INVALID, "invalid", "Invalid Image", }, |
570abb0a | 164 | { IH_TYPE_MULTI, "multi", "Multi-File Image", }, |
4962e38e | 165 | { IH_TYPE_OMAPIMAGE, "omapimage", "TI OMAP SPL With GP CH",}, |
5d898a00 | 166 | { IH_TYPE_PBLIMAGE, "pblimage", "Freescale PBL Boot Image",}, |
570abb0a MB |
167 | { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", }, |
168 | { IH_TYPE_SCRIPT, "script", "Script", }, | |
662abc4f MV |
169 | { IH_TYPE_SOCFPGAIMAGE, "socfpgaimage", "Altera SoCFPGA CV/AV preloader",}, |
170 | { IH_TYPE_SOCFPGAIMAGE_V1, "socfpgaimage_v1", "Altera SoCFPGA A10 preloader",}, | |
570abb0a | 171 | { IH_TYPE_STANDALONE, "standalone", "Standalone Program", }, |
7816f2cf | 172 | { IH_TYPE_UBLIMAGE, "ublimage", "Davinci UBL image",}, |
bce88370 | 173 | { IH_TYPE_MXSIMAGE, "mxsimage", "Freescale MXS Boot Image",}, |
7b1a4117 | 174 | { IH_TYPE_ATMELIMAGE, "atmelimage", "ATMEL ROM-Boot Image",}, |
90268b87 | 175 | { IH_TYPE_X86_SETUP, "x86_setup", "x86 setup.bin", }, |
39f520bb | 176 | { IH_TYPE_LPC32XXIMAGE, "lpc32xximage", "LPC32XX Boot Image", }, |
a131c1f4 | 177 | { IH_TYPE_RKIMAGE, "rkimage", "Rockchip Boot Image" }, |
f9a3c278 | 178 | { IH_TYPE_RKSD, "rksd", "Rockchip SD Boot Image" }, |
10b84fe1 | 179 | { IH_TYPE_RKSPI, "rkspi", "Rockchip SPI Boot Image" }, |
ed0c2c0a | 180 | { IH_TYPE_VYBRIDIMAGE, "vybridimage", "Vybrid Boot Image", }, |
66eef1e7 | 181 | { IH_TYPE_ZYNQIMAGE, "zynqimage", "Xilinx Zynq Boot Image" }, |
d9b58b30 | 182 | { IH_TYPE_ZYNQMPIMAGE, "zynqmpimage", "Xilinx ZynqMP Boot Image" }, |
6915dcf3 | 183 | { IH_TYPE_ZYNQMPBIF, "zynqmpbif", "Xilinx ZynqMP Boot Image (bif)" }, |
ed0cea7c | 184 | { IH_TYPE_FPGA, "fpga", "FPGA Image" }, |
7e719ee7 | 185 | { IH_TYPE_TEE, "tee", "Trusted Execution Environment Image",}, |
d21bd69b | 186 | { IH_TYPE_FIRMWARE_IVT, "firmware_ivt", "Firmware with HABv4 IVT" }, |
6442c964 | 187 | { IH_TYPE_PMMC, "pmmc", "TI Power Management Micro-Controller Firmware",}, |
81260e33 | 188 | { IH_TYPE_STM32IMAGE, "stm32image", "STMicroelectronics STM32 Image" }, |
3b975a14 | 189 | { IH_TYPE_MTKIMAGE, "mtk_image", "MediaTek BootROM loadable Image" }, |
e7fabe75 | 190 | { IH_TYPE_COPRO, "copro", "Coprocessor Image"}, |
570abb0a MB |
191 | { -1, "", "", }, |
192 | }; | |
193 | ||
7edb186f | 194 | static const table_entry_t uimage_comp[] = { |
570abb0a MB |
195 | { IH_COMP_NONE, "none", "uncompressed", }, |
196 | { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", }, | |
197 | { IH_COMP_GZIP, "gzip", "gzip compressed", }, | |
fc9c1727 | 198 | { IH_COMP_LZMA, "lzma", "lzma compressed", }, |
20dde48b | 199 | { IH_COMP_LZO, "lzo", "lzo compressed", }, |
027b728d | 200 | { IH_COMP_LZ4, "lz4", "lz4 compressed", }, |
570abb0a MB |
201 | { -1, "", "", }, |
202 | }; | |
203 | ||
56d7ab74 SG |
204 | struct table_info { |
205 | const char *desc; | |
206 | int count; | |
207 | const table_entry_t *table; | |
208 | }; | |
209 | ||
155d6a35 AP |
210 | static const struct comp_magic_map image_comp[] = { |
211 | { IH_COMP_BZIP2, "bzip2", {0x42, 0x5a},}, | |
212 | { IH_COMP_GZIP, "gzip", {0x1f, 0x8b},}, | |
213 | { IH_COMP_LZMA, "lzma", {0x5d, 0x00},}, | |
214 | { IH_COMP_LZO, "lzo", {0x89, 0x4c},}, | |
215 | { IH_COMP_NONE, "none", {}, }, | |
216 | }; | |
217 | ||
56d7ab74 SG |
218 | static const struct table_info table_info[IH_COUNT] = { |
219 | { "architecture", IH_ARCH_COUNT, uimage_arch }, | |
220 | { "compression", IH_COMP_COUNT, uimage_comp }, | |
221 | { "operating system", IH_OS_COUNT, uimage_os }, | |
222 | { "image type", IH_TYPE_COUNT, uimage_type }, | |
223 | }; | |
224 | ||
9a4daad0 MB |
225 | /*****************************************************************************/ |
226 | /* Legacy format routines */ | |
227 | /*****************************************************************************/ | |
712fbcf3 | 228 | int image_check_hcrc(const image_header_t *hdr) |
b97a2a0a MB |
229 | { |
230 | ulong hcrc; | |
712fbcf3 | 231 | ulong len = image_get_header_size(); |
b97a2a0a MB |
232 | image_header_t header; |
233 | ||
234 | /* Copy header so we can blank CRC field for re-calculation */ | |
712fbcf3 SW |
235 | memmove(&header, (char *)hdr, image_get_header_size()); |
236 | image_set_hcrc(&header, 0); | |
b97a2a0a | 237 | |
712fbcf3 | 238 | hcrc = crc32(0, (unsigned char *)&header, len); |
b97a2a0a | 239 | |
712fbcf3 | 240 | return (hcrc == image_get_hcrc(hdr)); |
b97a2a0a MB |
241 | } |
242 | ||
712fbcf3 | 243 | int image_check_dcrc(const image_header_t *hdr) |
b97a2a0a | 244 | { |
712fbcf3 SW |
245 | ulong data = image_get_data(hdr); |
246 | ulong len = image_get_data_size(hdr); | |
247 | ulong dcrc = crc32_wd(0, (unsigned char *)data, len, CHUNKSZ_CRC32); | |
b97a2a0a | 248 | |
712fbcf3 | 249 | return (dcrc == image_get_dcrc(hdr)); |
b97a2a0a MB |
250 | } |
251 | ||
f13e7b2e MB |
252 | /** |
253 | * image_multi_count - get component (sub-image) count | |
254 | * @hdr: pointer to the header of the multi component image | |
255 | * | |
256 | * image_multi_count() returns number of components in a multi | |
257 | * component image. | |
258 | * | |
259 | * Note: no checking of the image type is done, caller must pass | |
260 | * a valid multi component image. | |
261 | * | |
262 | * returns: | |
263 | * number of components | |
264 | */ | |
712fbcf3 | 265 | ulong image_multi_count(const image_header_t *hdr) |
f13e7b2e MB |
266 | { |
267 | ulong i, count = 0; | |
df6f1b89 | 268 | uint32_t *size; |
f13e7b2e MB |
269 | |
270 | /* get start of the image payload, which in case of multi | |
271 | * component images that points to a table of component sizes */ | |
712fbcf3 | 272 | size = (uint32_t *)image_get_data(hdr); |
f13e7b2e MB |
273 | |
274 | /* count non empty slots */ | |
275 | for (i = 0; size[i]; ++i) | |
276 | count++; | |
277 | ||
278 | return count; | |
279 | } | |
280 | ||
281 | /** | |
282 | * image_multi_getimg - get component data address and size | |
283 | * @hdr: pointer to the header of the multi component image | |
284 | * @idx: index of the requested component | |
285 | * @data: pointer to a ulong variable, will hold component data address | |
286 | * @len: pointer to a ulong variable, will hold component size | |
287 | * | |
288 | * image_multi_getimg() returns size and data address for the requested | |
289 | * component in a multi component image. | |
290 | * | |
291 | * Note: no checking of the image type is done, caller must pass | |
292 | * a valid multi component image. | |
293 | * | |
294 | * returns: | |
295 | * data address and size of the component, if idx is valid | |
296 | * 0 in data and len, if idx is out of range | |
297 | */ | |
712fbcf3 | 298 | void image_multi_getimg(const image_header_t *hdr, ulong idx, |
f13e7b2e MB |
299 | ulong *data, ulong *len) |
300 | { | |
301 | int i; | |
df6f1b89 | 302 | uint32_t *size; |
02b9b224 | 303 | ulong offset, count, img_data; |
f13e7b2e MB |
304 | |
305 | /* get number of component */ | |
712fbcf3 | 306 | count = image_multi_count(hdr); |
f13e7b2e MB |
307 | |
308 | /* get start of the image payload, which in case of multi | |
309 | * component images that points to a table of component sizes */ | |
712fbcf3 | 310 | size = (uint32_t *)image_get_data(hdr); |
f13e7b2e MB |
311 | |
312 | /* get address of the proper component data start, which means | |
313 | * skipping sizes table (add 1 for last, null entry) */ | |
712fbcf3 | 314 | img_data = image_get_data(hdr) + (count + 1) * sizeof(uint32_t); |
f13e7b2e MB |
315 | |
316 | if (idx < count) { | |
712fbcf3 | 317 | *len = uimage_to_cpu(size[idx]); |
f13e7b2e | 318 | offset = 0; |
f13e7b2e MB |
319 | |
320 | /* go over all indices preceding requested component idx */ | |
321 | for (i = 0; i < idx; i++) { | |
02b9b224 | 322 | /* add up i-th component size, rounding up to 4 bytes */ |
712fbcf3 | 323 | offset += (uimage_to_cpu(size[i]) + 3) & ~3 ; |
f13e7b2e MB |
324 | } |
325 | ||
326 | /* calculate idx-th component data address */ | |
02b9b224 | 327 | *data = img_data + offset; |
f13e7b2e MB |
328 | } else { |
329 | *len = 0; | |
330 | *data = 0; | |
331 | } | |
332 | } | |
42b73e8e | 333 | |
712fbcf3 | 334 | static void image_print_type(const image_header_t *hdr) |
9a4daad0 | 335 | { |
80402f34 | 336 | const char __maybe_unused *os, *arch, *type, *comp; |
9a4daad0 | 337 | |
712fbcf3 SW |
338 | os = genimg_get_os_name(image_get_os(hdr)); |
339 | arch = genimg_get_arch_name(image_get_arch(hdr)); | |
340 | type = genimg_get_type_name(image_get_type(hdr)); | |
341 | comp = genimg_get_comp_name(image_get_comp(hdr)); | |
9a4daad0 | 342 | |
712fbcf3 | 343 | printf("%s %s %s (%s)\n", arch, os, type, comp); |
9a4daad0 MB |
344 | } |
345 | ||
5dfb5213 | 346 | /** |
edbed247 | 347 | * image_print_contents - prints out the contents of the legacy format image |
3a2003f6 | 348 | * @ptr: pointer to the legacy format image header |
5dfb5213 MB |
349 | * @p: pointer to prefix string |
350 | * | |
edbed247 | 351 | * image_print_contents() formats a multi line legacy image contents description. |
5dfb5213 MB |
352 | * The routine prints out all header fields followed by the size/offset data |
353 | * for MULTI/SCRIPT images. | |
354 | * | |
355 | * returns: | |
356 | * no returned results | |
357 | */ | |
712fbcf3 | 358 | void image_print_contents(const void *ptr) |
9a4daad0 | 359 | { |
3a2003f6 | 360 | const image_header_t *hdr = (const image_header_t *)ptr; |
80402f34 | 361 | const char __maybe_unused *p; |
edbed247 | 362 | |
1fe7d938 | 363 | p = IMAGE_INDENT_STRING; |
712fbcf3 | 364 | printf("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name(hdr)); |
859e92b7 SG |
365 | if (IMAGE_ENABLE_TIMESTAMP) { |
366 | printf("%sCreated: ", p); | |
367 | genimg_print_time((time_t)image_get_time(hdr)); | |
368 | } | |
712fbcf3 SW |
369 | printf("%sImage Type: ", p); |
370 | image_print_type(hdr); | |
371 | printf("%sData Size: ", p); | |
372 | genimg_print_size(image_get_data_size(hdr)); | |
373 | printf("%sLoad Address: %08x\n", p, image_get_load(hdr)); | |
374 | printf("%sEntry Point: %08x\n", p, image_get_ep(hdr)); | |
375 | ||
376 | if (image_check_type(hdr, IH_TYPE_MULTI) || | |
377 | image_check_type(hdr, IH_TYPE_SCRIPT)) { | |
9a4daad0 MB |
378 | int i; |
379 | ulong data, len; | |
712fbcf3 | 380 | ulong count = image_multi_count(hdr); |
9a4daad0 | 381 | |
712fbcf3 | 382 | printf("%sContents:\n", p); |
9a4daad0 | 383 | for (i = 0; i < count; i++) { |
712fbcf3 | 384 | image_multi_getimg(hdr, i, &data, &len); |
570abb0a | 385 | |
712fbcf3 SW |
386 | printf("%s Image %d: ", p, i); |
387 | genimg_print_size(len); | |
570abb0a | 388 | |
712fbcf3 | 389 | if (image_check_type(hdr, IH_TYPE_SCRIPT) && i > 0) { |
570abb0a MB |
390 | /* |
391 | * the user may need to know offsets | |
392 | * if planning to do something with | |
393 | * multiple files | |
394 | */ | |
712fbcf3 | 395 | printf("%s Offset = 0x%08lx\n", p, data); |
570abb0a | 396 | } |
9a4daad0 | 397 | } |
d21bd69b SE |
398 | } else if (image_check_type(hdr, IH_TYPE_FIRMWARE_IVT)) { |
399 | printf("HAB Blocks: 0x%08x 0x0000 0x%08x\n", | |
5b20d141 BML |
400 | image_get_load(hdr) - image_get_header_size(), |
401 | (int)(image_get_size(hdr) + image_get_header_size() | |
402 | + sizeof(flash_header_v2_t) - 0x2060)); | |
9a4daad0 MB |
403 | } |
404 | } | |
405 | ||
2090854c JW |
406 | /** |
407 | * print_decomp_msg() - Print a suitable decompression/loading message | |
408 | * | |
409 | * @type: OS type (IH_OS_...) | |
410 | * @comp_type: Compression type being used (IH_COMP_...) | |
411 | * @is_xip: true if the load address matches the image start | |
412 | */ | |
413 | static void print_decomp_msg(int comp_type, int type, bool is_xip) | |
414 | { | |
415 | const char *name = genimg_get_type_name(type); | |
416 | ||
417 | if (comp_type == IH_COMP_NONE) | |
418 | printf(" %s %s\n", is_xip ? "XIP" : "Loading", name); | |
419 | else | |
420 | printf(" Uncompressing %s\n", name); | |
421 | } | |
422 | ||
155d6a35 AP |
423 | int image_decomp_type(const unsigned char *buf, ulong len) |
424 | { | |
425 | const struct comp_magic_map *cmagic = image_comp; | |
426 | ||
427 | if (len < 2) | |
428 | return -EINVAL; | |
429 | ||
430 | for (; cmagic->comp_id > 0; cmagic++) { | |
431 | if (!memcmp(buf, cmagic->magic, 2)) | |
432 | break; | |
433 | } | |
434 | ||
435 | return cmagic->comp_id; | |
436 | } | |
437 | ||
2090854c JW |
438 | int image_decomp(int comp, ulong load, ulong image_start, int type, |
439 | void *load_buf, void *image_buf, ulong image_len, | |
440 | uint unc_len, ulong *load_end) | |
441 | { | |
442 | int ret = 0; | |
443 | ||
444 | *load_end = load; | |
445 | print_decomp_msg(comp, type, load == image_start); | |
446 | ||
447 | /* | |
448 | * Load the image to the right place, decompressing if needed. After | |
449 | * this, image_len will be set to the number of uncompressed bytes | |
450 | * loaded, ret will be non-zero on error. | |
451 | */ | |
452 | switch (comp) { | |
453 | case IH_COMP_NONE: | |
454 | if (load == image_start) | |
455 | break; | |
456 | if (image_len <= unc_len) | |
457 | memmove_wd(load_buf, image_buf, image_len, CHUNKSZ); | |
458 | else | |
459 | ret = -ENOSPC; | |
460 | break; | |
461 | #ifdef CONFIG_GZIP | |
462 | case IH_COMP_GZIP: { | |
463 | ret = gunzip(load_buf, unc_len, image_buf, &image_len); | |
464 | break; | |
465 | } | |
466 | #endif /* CONFIG_GZIP */ | |
467 | #ifdef CONFIG_BZIP2 | |
468 | case IH_COMP_BZIP2: { | |
469 | uint size = unc_len; | |
470 | ||
471 | /* | |
472 | * If we've got less than 4 MB of malloc() space, | |
473 | * use slower decompression algorithm which requires | |
474 | * at most 2300 KB of memory. | |
475 | */ | |
476 | ret = BZ2_bzBuffToBuffDecompress(load_buf, &size, | |
477 | image_buf, image_len, | |
478 | CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0); | |
479 | image_len = size; | |
480 | break; | |
481 | } | |
482 | #endif /* CONFIG_BZIP2 */ | |
483 | #ifdef CONFIG_LZMA | |
484 | case IH_COMP_LZMA: { | |
485 | SizeT lzma_len = unc_len; | |
486 | ||
487 | ret = lzmaBuffToBuffDecompress(load_buf, &lzma_len, | |
488 | image_buf, image_len); | |
489 | image_len = lzma_len; | |
490 | break; | |
491 | } | |
492 | #endif /* CONFIG_LZMA */ | |
493 | #ifdef CONFIG_LZO | |
494 | case IH_COMP_LZO: { | |
495 | size_t size = unc_len; | |
496 | ||
497 | ret = lzop_decompress(image_buf, image_len, load_buf, &size); | |
498 | image_len = size; | |
499 | break; | |
500 | } | |
501 | #endif /* CONFIG_LZO */ | |
502 | #ifdef CONFIG_LZ4 | |
503 | case IH_COMP_LZ4: { | |
504 | size_t size = unc_len; | |
505 | ||
506 | ret = ulz4fn(image_buf, image_len, load_buf, &size); | |
507 | image_len = size; | |
508 | break; | |
509 | } | |
510 | #endif /* CONFIG_LZ4 */ | |
511 | default: | |
512 | printf("Unimplemented compression type %d\n", comp); | |
513 | return -ENOSYS; | |
514 | } | |
515 | ||
516 | *load_end = load + image_len; | |
517 | ||
518 | return ret; | |
519 | } | |
520 | ||
570abb0a MB |
521 | |
522 | #ifndef USE_HOSTCC | |
c76c93a3 | 523 | #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) |
9a4daad0 MB |
524 | /** |
525 | * image_get_ramdisk - get and verify ramdisk image | |
9a4daad0 MB |
526 | * @rd_addr: ramdisk image start address |
527 | * @arch: expected ramdisk architecture | |
528 | * @verify: checksum verification flag | |
529 | * | |
530 | * image_get_ramdisk() returns a pointer to the verified ramdisk image | |
531 | * header. Routine receives image start address and expected architecture | |
532 | * flag. Verification done covers data and header integrity and os/type/arch | |
533 | * fields checking. | |
534 | * | |
9a4daad0 MB |
535 | * returns: |
536 | * pointer to a ramdisk image header, if image was found and valid | |
537 | * otherwise, return NULL | |
538 | */ | |
712fbcf3 | 539 | static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch, |
d985c849 | 540 | int verify) |
9a4daad0 | 541 | { |
3a2003f6 | 542 | const image_header_t *rd_hdr = (const image_header_t *)rd_addr; |
9a4daad0 | 543 | |
712fbcf3 SW |
544 | if (!image_check_magic(rd_hdr)) { |
545 | puts("Bad Magic Number\n"); | |
770605e4 | 546 | bootstage_error(BOOTSTAGE_ID_RD_MAGIC); |
9a4daad0 MB |
547 | return NULL; |
548 | } | |
549 | ||
712fbcf3 SW |
550 | if (!image_check_hcrc(rd_hdr)) { |
551 | puts("Bad Header Checksum\n"); | |
770605e4 | 552 | bootstage_error(BOOTSTAGE_ID_RD_HDR_CHECKSUM); |
9a4daad0 MB |
553 | return NULL; |
554 | } | |
555 | ||
770605e4 | 556 | bootstage_mark(BOOTSTAGE_ID_RD_MAGIC); |
712fbcf3 | 557 | image_print_contents(rd_hdr); |
9a4daad0 MB |
558 | |
559 | if (verify) { | |
560 | puts(" Verifying Checksum ... "); | |
712fbcf3 SW |
561 | if (!image_check_dcrc(rd_hdr)) { |
562 | puts("Bad Data CRC\n"); | |
770605e4 | 563 | bootstage_error(BOOTSTAGE_ID_RD_CHECKSUM); |
9a4daad0 MB |
564 | return NULL; |
565 | } | |
566 | puts("OK\n"); | |
567 | } | |
568 | ||
770605e4 | 569 | bootstage_mark(BOOTSTAGE_ID_RD_HDR_CHECKSUM); |
9a4daad0 | 570 | |
712fbcf3 SW |
571 | if (!image_check_os(rd_hdr, IH_OS_LINUX) || |
572 | !image_check_arch(rd_hdr, arch) || | |
573 | !image_check_type(rd_hdr, IH_TYPE_RAMDISK)) { | |
574 | printf("No Linux %s Ramdisk Image\n", | |
9a4daad0 | 575 | genimg_get_arch_name(arch)); |
770605e4 | 576 | bootstage_error(BOOTSTAGE_ID_RAMDISK); |
9a4daad0 MB |
577 | return NULL; |
578 | } | |
579 | ||
580 | return rd_hdr; | |
581 | } | |
21d29f7f | 582 | #endif |
570abb0a | 583 | #endif /* !USE_HOSTCC */ |
9a4daad0 MB |
584 | |
585 | /*****************************************************************************/ | |
586 | /* Shared dual-format routines */ | |
587 | /*****************************************************************************/ | |
570abb0a | 588 | #ifndef USE_HOSTCC |
bb872dd9 SG |
589 | ulong image_load_addr = CONFIG_SYS_LOAD_ADDR; /* Default Load Address */ |
590 | ulong image_save_addr; /* Default Save Address */ | |
591 | ulong image_save_size; /* Default Save Size (in bytes) */ | |
1cf0a8b2 JH |
592 | |
593 | static int on_loadaddr(const char *name, const char *value, enum env_op op, | |
594 | int flags) | |
595 | { | |
596 | switch (op) { | |
597 | case env_op_create: | |
598 | case env_op_overwrite: | |
bb872dd9 | 599 | image_load_addr = simple_strtoul(value, NULL, 16); |
1cf0a8b2 JH |
600 | break; |
601 | default: | |
602 | break; | |
603 | } | |
604 | ||
605 | return 0; | |
606 | } | |
607 | U_BOOT_ENV_CALLBACK(loadaddr, on_loadaddr); | |
608 | ||
723806cc | 609 | ulong env_get_bootm_low(void) |
9a4daad0 | 610 | { |
00caae6d | 611 | char *s = env_get("bootm_low"); |
9a4daad0 | 612 | if (s) { |
712fbcf3 | 613 | ulong tmp = simple_strtoul(s, NULL, 16); |
9a4daad0 MB |
614 | return tmp; |
615 | } | |
616 | ||
6d0f6bcf JCPV |
617 | #if defined(CONFIG_SYS_SDRAM_BASE) |
618 | return CONFIG_SYS_SDRAM_BASE; | |
a750ded4 | 619 | #elif defined(CONFIG_ARM) || defined(CONFIG_MICROBLAZE) |
afe45c87 | 620 | return gd->bd->bi_dram[0].start; |
9a4daad0 MB |
621 | #else |
622 | return 0; | |
623 | #endif | |
624 | } | |
625 | ||
723806cc | 626 | phys_size_t env_get_bootm_size(void) |
9a4daad0 | 627 | { |
0cb389dd MY |
628 | phys_size_t tmp, size; |
629 | phys_addr_t start; | |
00caae6d | 630 | char *s = env_get("bootm_size"); |
9a4daad0 | 631 | if (s) { |
712fbcf3 | 632 | tmp = (phys_size_t)simple_strtoull(s, NULL, 16); |
9a4daad0 MB |
633 | return tmp; |
634 | } | |
0cb389dd | 635 | |
a750ded4 MS |
636 | #if (defined(CONFIG_ARM) || defined(CONFIG_MICROBLAZE)) && \ |
637 | defined(CONFIG_NR_DRAM_BANKS) | |
0cb389dd MY |
638 | start = gd->bd->bi_dram[0].start; |
639 | size = gd->bd->bi_dram[0].size; | |
640 | #else | |
641 | start = gd->bd->bi_memstart; | |
642 | size = gd->bd->bi_memsize; | |
643 | #endif | |
644 | ||
00caae6d | 645 | s = env_get("bootm_low"); |
c519facc | 646 | if (s) |
712fbcf3 | 647 | tmp = (phys_size_t)simple_strtoull(s, NULL, 16); |
c519facc | 648 | else |
0cb389dd | 649 | tmp = start; |
9a4daad0 | 650 | |
0cb389dd | 651 | return size - (tmp - start); |
9a4daad0 MB |
652 | } |
653 | ||
723806cc | 654 | phys_size_t env_get_bootm_mapsize(void) |
c3624e6e GL |
655 | { |
656 | phys_size_t tmp; | |
00caae6d | 657 | char *s = env_get("bootm_mapsize"); |
c3624e6e | 658 | if (s) { |
712fbcf3 | 659 | tmp = (phys_size_t)simple_strtoull(s, NULL, 16); |
c3624e6e GL |
660 | return tmp; |
661 | } | |
662 | ||
663 | #if defined(CONFIG_SYS_BOOTMAPSZ) | |
664 | return CONFIG_SYS_BOOTMAPSZ; | |
665 | #else | |
723806cc | 666 | return env_get_bootm_size(); |
c3624e6e GL |
667 | #endif |
668 | } | |
669 | ||
712fbcf3 | 670 | void memmove_wd(void *to, void *from, size_t len, ulong chunksz) |
9a4daad0 | 671 | { |
54fa2c5b LJ |
672 | if (to == from) |
673 | return; | |
674 | ||
9a4daad0 | 675 | #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) |
22cfddc2 SZ |
676 | if (to > from) { |
677 | from += len; | |
678 | to += len; | |
679 | } | |
9a4daad0 MB |
680 | while (len > 0) { |
681 | size_t tail = (len > chunksz) ? chunksz : len; | |
712fbcf3 | 682 | WATCHDOG_RESET(); |
22cfddc2 SZ |
683 | if (to > from) { |
684 | to -= tail; | |
685 | from -= tail; | |
686 | } | |
712fbcf3 | 687 | memmove(to, from, tail); |
22cfddc2 SZ |
688 | if (to < from) { |
689 | to += tail; | |
690 | from += tail; | |
691 | } | |
9a4daad0 MB |
692 | len -= tail; |
693 | } | |
694 | #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */ | |
712fbcf3 | 695 | memmove(to, from, len); |
9a4daad0 MB |
696 | #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */ |
697 | } | |
2090854c JW |
698 | #else /* USE_HOSTCC */ |
699 | void memmove_wd(void *to, void *from, size_t len, ulong chunksz) | |
700 | { | |
701 | memmove(to, from, len); | |
702 | } | |
570abb0a | 703 | #endif /* !USE_HOSTCC */ |
9a4daad0 | 704 | |
712fbcf3 | 705 | void genimg_print_size(uint32_t size) |
42b73e8e | 706 | { |
570abb0a | 707 | #ifndef USE_HOSTCC |
712fbcf3 SW |
708 | printf("%d Bytes = ", size); |
709 | print_size(size, "\n"); | |
570abb0a | 710 | #else |
cec85d4e | 711 | printf("%d Bytes = %.2f KiB = %.2f MiB\n", |
570abb0a MB |
712 | size, (double)size / 1.024e3, |
713 | (double)size / 1.048576e6); | |
42b73e8e | 714 | #endif |
570abb0a MB |
715 | } |
716 | ||
859e92b7 SG |
717 | #if IMAGE_ENABLE_TIMESTAMP |
718 | void genimg_print_time(time_t timestamp) | |
570abb0a MB |
719 | { |
720 | #ifndef USE_HOSTCC | |
721 | struct rtc_time tm; | |
722 | ||
9f9276c3 | 723 | rtc_to_tm(timestamp, &tm); |
712fbcf3 | 724 | printf("%4d-%02d-%02d %2d:%02d:%02d UTC\n", |
570abb0a MB |
725 | tm.tm_year, tm.tm_mon, tm.tm_mday, |
726 | tm.tm_hour, tm.tm_min, tm.tm_sec); | |
727 | #else | |
712fbcf3 | 728 | printf("%s", ctime(×tamp)); |
42b73e8e | 729 | #endif |
570abb0a | 730 | } |
859e92b7 | 731 | #endif |
42b73e8e | 732 | |
5b9d44df SG |
733 | const table_entry_t *get_table_entry(const table_entry_t *table, int id) |
734 | { | |
735 | for (; table->id >= 0; ++table) { | |
736 | if (table->id == id) | |
737 | return table; | |
738 | } | |
739 | return NULL; | |
740 | } | |
741 | ||
1426220b SG |
742 | static const char *unknown_msg(enum ih_category category) |
743 | { | |
ae3de0d8 | 744 | static const char unknown_str[] = "Unknown "; |
1426220b SG |
745 | static char msg[30]; |
746 | ||
ae3de0d8 SG |
747 | strcpy(msg, unknown_str); |
748 | strncat(msg, table_info[category].desc, | |
749 | sizeof(msg) - sizeof(unknown_str)); | |
1426220b SG |
750 | |
751 | return msg; | |
752 | } | |
753 | ||
754 | /** | |
755 | * get_cat_table_entry_name - translate entry id to long name | |
756 | * @category: category to look up (enum ih_category) | |
757 | * @id: entry id to be translated | |
758 | * | |
759 | * This will scan the translation table trying to find the entry that matches | |
760 | * the given id. | |
761 | * | |
762 | * @retur long entry name if translation succeeds; error string on failure | |
763 | */ | |
764 | const char *genimg_get_cat_name(enum ih_category category, uint id) | |
765 | { | |
766 | const table_entry_t *entry; | |
767 | ||
768 | entry = get_table_entry(table_info[category].table, id); | |
769 | if (!entry) | |
770 | return unknown_msg(category); | |
771 | #if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC) | |
772 | return entry->lname; | |
773 | #else | |
774 | return entry->lname + gd->reloc_off; | |
775 | #endif | |
776 | } | |
777 | ||
778 | /** | |
779 | * get_cat_table_entry_short_name - translate entry id to short name | |
780 | * @category: category to look up (enum ih_category) | |
781 | * @id: entry id to be translated | |
782 | * | |
783 | * This will scan the translation table trying to find the entry that matches | |
784 | * the given id. | |
785 | * | |
786 | * @retur short entry name if translation succeeds; error string on failure | |
787 | */ | |
788 | const char *genimg_get_cat_short_name(enum ih_category category, uint id) | |
789 | { | |
790 | const table_entry_t *entry; | |
791 | ||
792 | entry = get_table_entry(table_info[category].table, id); | |
793 | if (!entry) | |
794 | return unknown_msg(category); | |
795 | #if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC) | |
796 | return entry->sname; | |
797 | #else | |
798 | return entry->sname + gd->reloc_off; | |
799 | #endif | |
800 | } | |
801 | ||
802 | int genimg_get_cat_count(enum ih_category category) | |
803 | { | |
804 | return table_info[category].count; | |
805 | } | |
806 | ||
807 | const char *genimg_get_cat_desc(enum ih_category category) | |
808 | { | |
809 | return table_info[category].desc; | |
810 | } | |
811 | ||
570abb0a MB |
812 | /** |
813 | * get_table_entry_name - translate entry id to long name | |
814 | * @table: pointer to a translation table for entries of a specific type | |
815 | * @msg: message to be returned when translation fails | |
816 | * @id: entry id to be translated | |
817 | * | |
818 | * get_table_entry_name() will go over translation table trying to find | |
819 | * entry that matches given id. If matching entry is found, its long | |
820 | * name is returned to the caller. | |
821 | * | |
822 | * returns: | |
823 | * long entry name if translation succeeds | |
824 | * msg otherwise | |
825 | */ | |
7edb186f | 826 | char *get_table_entry_name(const table_entry_t *table, char *msg, int id) |
570abb0a | 827 | { |
5b9d44df SG |
828 | table = get_table_entry(table, id); |
829 | if (!table) | |
830 | return msg; | |
2e5167cc | 831 | #if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC) |
5b9d44df | 832 | return table->lname; |
e3d1ac7b | 833 | #else |
5b9d44df | 834 | return table->lname + gd->reloc_off; |
e3d1ac7b | 835 | #endif |
570abb0a | 836 | } |
42b73e8e | 837 | |
712fbcf3 | 838 | const char *genimg_get_os_name(uint8_t os) |
570abb0a | 839 | { |
712fbcf3 | 840 | return (get_table_entry_name(uimage_os, "Unknown OS", os)); |
42b73e8e MB |
841 | } |
842 | ||
712fbcf3 | 843 | const char *genimg_get_arch_name(uint8_t arch) |
42b73e8e | 844 | { |
712fbcf3 SW |
845 | return (get_table_entry_name(uimage_arch, "Unknown Architecture", |
846 | arch)); | |
570abb0a | 847 | } |
42b73e8e | 848 | |
712fbcf3 | 849 | const char *genimg_get_type_name(uint8_t type) |
570abb0a | 850 | { |
712fbcf3 | 851 | return (get_table_entry_name(uimage_type, "Unknown Image", type)); |
570abb0a | 852 | } |
42b73e8e | 853 | |
cef2e514 | 854 | static const char *genimg_get_short_name(const table_entry_t *table, int val) |
5b9d44df | 855 | { |
cef2e514 | 856 | table = get_table_entry(table, val); |
5b9d44df SG |
857 | if (!table) |
858 | return "unknown"; | |
859 | #if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC) | |
860 | return table->sname; | |
861 | #else | |
862 | return table->sname + gd->reloc_off; | |
863 | #endif | |
864 | } | |
865 | ||
cef2e514 SG |
866 | const char *genimg_get_type_short_name(uint8_t type) |
867 | { | |
868 | return genimg_get_short_name(uimage_type, type); | |
869 | } | |
870 | ||
712fbcf3 | 871 | const char *genimg_get_comp_name(uint8_t comp) |
570abb0a | 872 | { |
712fbcf3 SW |
873 | return (get_table_entry_name(uimage_comp, "Unknown Compression", |
874 | comp)); | |
42b73e8e MB |
875 | } |
876 | ||
cef2e514 SG |
877 | const char *genimg_get_comp_short_name(uint8_t comp) |
878 | { | |
879 | return genimg_get_short_name(uimage_comp, comp); | |
880 | } | |
881 | ||
882 | const char *genimg_get_os_short_name(uint8_t os) | |
883 | { | |
884 | return genimg_get_short_name(uimage_os, os); | |
885 | } | |
886 | ||
887 | const char *genimg_get_arch_short_name(uint8_t arch) | |
888 | { | |
889 | return genimg_get_short_name(uimage_arch, arch); | |
890 | } | |
891 | ||
570abb0a MB |
892 | /** |
893 | * get_table_entry_id - translate short entry name to id | |
894 | * @table: pointer to a translation table for entries of a specific type | |
895 | * @table_name: to be used in case of error | |
896 | * @name: entry short name to be translated | |
897 | * | |
898 | * get_table_entry_id() will go over translation table trying to find | |
899 | * entry that matches given short name. If matching entry is found, | |
900 | * its id returned to the caller. | |
901 | * | |
902 | * returns: | |
903 | * entry id if translation succeeds | |
904 | * -1 otherwise | |
905 | */ | |
7edb186f | 906 | int get_table_entry_id(const table_entry_t *table, |
570abb0a | 907 | const char *table_name, const char *name) |
42b73e8e | 908 | { |
7edb186f | 909 | const table_entry_t *t; |
42b73e8e | 910 | |
570abb0a | 911 | for (t = table; t->id >= 0; ++t) { |
2e5167cc | 912 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
5b9d44df | 913 | if (t->sname && strcasecmp(t->sname + gd->reloc_off, name) == 0) |
2e5167cc | 914 | #else |
5b9d44df | 915 | if (t->sname && strcasecmp(t->sname, name) == 0) |
521af04d | 916 | #endif |
570abb0a MB |
917 | return (t->id); |
918 | } | |
712fbcf3 | 919 | debug("Invalid %s Type: %s\n", table_name, name); |
5b9d44df SG |
920 | |
921 | return -1; | |
570abb0a MB |
922 | } |
923 | ||
712fbcf3 | 924 | int genimg_get_os_id(const char *name) |
570abb0a | 925 | { |
712fbcf3 | 926 | return (get_table_entry_id(uimage_os, "OS", name)); |
570abb0a MB |
927 | } |
928 | ||
712fbcf3 | 929 | int genimg_get_arch_id(const char *name) |
570abb0a | 930 | { |
712fbcf3 | 931 | return (get_table_entry_id(uimage_arch, "CPU", name)); |
42b73e8e | 932 | } |
5ad03eb3 | 933 | |
712fbcf3 | 934 | int genimg_get_type_id(const char *name) |
570abb0a | 935 | { |
712fbcf3 | 936 | return (get_table_entry_id(uimage_type, "Image", name)); |
570abb0a MB |
937 | } |
938 | ||
712fbcf3 | 939 | int genimg_get_comp_id(const char *name) |
570abb0a | 940 | { |
712fbcf3 | 941 | return (get_table_entry_id(uimage_comp, "Compression", name)); |
570abb0a MB |
942 | } |
943 | ||
944 | #ifndef USE_HOSTCC | |
0f64140b | 945 | /** |
6c454fed BW |
946 | * genimg_get_kernel_addr_fit - get the real kernel address and return 2 |
947 | * FIT strings | |
0f64140b | 948 | * @img_addr: a string might contain real image address |
6c454fed BW |
949 | * @fit_uname_config: double pointer to a char, will hold pointer to a |
950 | * configuration unit name | |
951 | * @fit_uname_kernel: double pointer to a char, will hold pointer to a subimage | |
952 | * name | |
0f64140b | 953 | * |
6c454fed | 954 | * genimg_get_kernel_addr_fit get the real kernel start address from a string |
0f64140b BW |
955 | * which is normally the first argv of bootm/bootz |
956 | * | |
957 | * returns: | |
958 | * kernel start address | |
959 | */ | |
6c454fed BW |
960 | ulong genimg_get_kernel_addr_fit(char * const img_addr, |
961 | const char **fit_uname_config, | |
962 | const char **fit_uname_kernel) | |
0f64140b | 963 | { |
0f64140b BW |
964 | ulong kernel_addr; |
965 | ||
966 | /* find out kernel image address */ | |
967 | if (!img_addr) { | |
bb872dd9 | 968 | kernel_addr = image_load_addr; |
0f64140b | 969 | debug("* kernel: default image load address = 0x%08lx\n", |
bb872dd9 | 970 | image_load_addr); |
73223f0e | 971 | #if CONFIG_IS_ENABLED(FIT) |
bb872dd9 | 972 | } else if (fit_parse_conf(img_addr, image_load_addr, &kernel_addr, |
6c454fed | 973 | fit_uname_config)) { |
0f64140b | 974 | debug("* kernel: config '%s' from image at 0x%08lx\n", |
6c454fed | 975 | *fit_uname_config, kernel_addr); |
bb872dd9 | 976 | } else if (fit_parse_subimage(img_addr, image_load_addr, &kernel_addr, |
6c454fed | 977 | fit_uname_kernel)) { |
0f64140b | 978 | debug("* kernel: subimage '%s' from image at 0x%08lx\n", |
6c454fed | 979 | *fit_uname_kernel, kernel_addr); |
0f64140b BW |
980 | #endif |
981 | } else { | |
982 | kernel_addr = simple_strtoul(img_addr, NULL, 16); | |
983 | debug("* kernel: cmdline image address = 0x%08lx\n", | |
984 | kernel_addr); | |
985 | } | |
986 | ||
987 | return kernel_addr; | |
988 | } | |
989 | ||
6c454fed BW |
990 | /** |
991 | * genimg_get_kernel_addr() is the simple version of | |
992 | * genimg_get_kernel_addr_fit(). It ignores those return FIT strings | |
993 | */ | |
994 | ulong genimg_get_kernel_addr(char * const img_addr) | |
995 | { | |
996 | const char *fit_uname_config = NULL; | |
997 | const char *fit_uname_kernel = NULL; | |
998 | ||
999 | return genimg_get_kernel_addr_fit(img_addr, &fit_uname_config, | |
1000 | &fit_uname_kernel); | |
1001 | } | |
1002 | ||
fff888a1 | 1003 | /** |
9a4daad0 | 1004 | * genimg_get_format - get image format type |
fff888a1 MB |
1005 | * @img_addr: image start address |
1006 | * | |
9a4daad0 | 1007 | * genimg_get_format() checks whether provided address points to a valid |
fff888a1 MB |
1008 | * legacy or FIT image. |
1009 | * | |
4efbe9db MB |
1010 | * New uImage format and FDT blob are based on a libfdt. FDT blob |
1011 | * may be passed directly or embedded in a FIT image. In both situations | |
9a4daad0 | 1012 | * genimg_get_format() must be able to dectect libfdt header. |
4efbe9db | 1013 | * |
fff888a1 MB |
1014 | * returns: |
1015 | * image format type or IMAGE_FORMAT_INVALID if no image is present | |
1016 | */ | |
35e7b0f1 | 1017 | int genimg_get_format(const void *img_addr) |
fff888a1 | 1018 | { |
c76c93a3 | 1019 | #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) |
3a2003f6 | 1020 | const image_header_t *hdr; |
fff888a1 | 1021 | |
3a2003f6 | 1022 | hdr = (const image_header_t *)img_addr; |
fff888a1 | 1023 | if (image_check_magic(hdr)) |
21d29f7f HS |
1024 | return IMAGE_FORMAT_LEGACY; |
1025 | #endif | |
aa34fbc0 | 1026 | #if IMAGE_ENABLE_FIT || IMAGE_ENABLE_OF_LIBFDT |
21d29f7f HS |
1027 | if (fdt_check_header(img_addr) == 0) |
1028 | return IMAGE_FORMAT_FIT; | |
9ace3fc8 SS |
1029 | #endif |
1030 | #ifdef CONFIG_ANDROID_BOOT_IMAGE | |
21d29f7f HS |
1031 | if (android_image_check_header(img_addr) == 0) |
1032 | return IMAGE_FORMAT_ANDROID; | |
fff888a1 MB |
1033 | #endif |
1034 | ||
21d29f7f | 1035 | return IMAGE_FORMAT_INVALID; |
fff888a1 MB |
1036 | } |
1037 | ||
f773bea8 MB |
1038 | /** |
1039 | * fit_has_config - check if there is a valid FIT configuration | |
1040 | * @images: pointer to the bootm command headers structure | |
1041 | * | |
1042 | * fit_has_config() checks if there is a FIT configuration in use | |
1043 | * (if FTI support is present). | |
1044 | * | |
1045 | * returns: | |
1046 | * 0, no FIT support or no configuration found | |
1047 | * 1, configuration found | |
1048 | */ | |
712fbcf3 | 1049 | int genimg_has_config(bootm_headers_t *images) |
f773bea8 | 1050 | { |
73223f0e | 1051 | #if IMAGE_ENABLE_FIT |
f773bea8 MB |
1052 | if (images->fit_uname_cfg) |
1053 | return 1; | |
1054 | #endif | |
1055 | return 0; | |
1056 | } | |
1057 | ||
5ad03eb3 | 1058 | /** |
9a4daad0 | 1059 | * boot_get_ramdisk - main ramdisk handling routine |
5ad03eb3 MB |
1060 | * @argc: command argument count |
1061 | * @argv: command argument list | |
8a5ea3e6 | 1062 | * @images: pointer to the bootm images structure |
5ad03eb3 MB |
1063 | * @arch: expected ramdisk architecture |
1064 | * @rd_start: pointer to a ulong variable, will hold ramdisk start address | |
1065 | * @rd_end: pointer to a ulong variable, will hold ramdisk end | |
1066 | * | |
9a4daad0 | 1067 | * boot_get_ramdisk() is responsible for finding a valid ramdisk image. |
5ad03eb3 MB |
1068 | * Curently supported are the following ramdisk sources: |
1069 | * - multicomponent kernel/ramdisk image, | |
1070 | * - commandline provided address of decicated ramdisk image. | |
1071 | * | |
1072 | * returns: | |
d985c849 | 1073 | * 0, if ramdisk image was found and valid, or skiped |
5ad03eb3 MB |
1074 | * rd_start and rd_end are set to ramdisk start/end addresses if |
1075 | * ramdisk image is found and valid | |
d985c849 | 1076 | * |
ea86b9e6 | 1077 | * 1, if ramdisk image is found but corrupted, or invalid |
5ad03eb3 | 1078 | * rd_start and rd_end are set to 0 if no ramdisk exists |
5ad03eb3 | 1079 | */ |
09140113 SG |
1080 | int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, |
1081 | uint8_t arch, ulong *rd_start, ulong *rd_end) | |
5ad03eb3 | 1082 | { |
d5934ad7 | 1083 | ulong rd_addr, rd_load; |
5ad03eb3 | 1084 | ulong rd_data, rd_len; |
c76c93a3 | 1085 | #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) |
3a2003f6 | 1086 | const image_header_t *rd_hdr; |
21d29f7f | 1087 | #endif |
35e7b0f1 | 1088 | void *buf; |
57d40ab7 | 1089 | #ifdef CONFIG_SUPPORT_RAW_INITRD |
017e1f3f | 1090 | char *end; |
57d40ab7 | 1091 | #endif |
73223f0e | 1092 | #if IMAGE_ENABLE_FIT |
f320a4d8 | 1093 | const char *fit_uname_config = images->fit_uname_cfg; |
d5934ad7 MB |
1094 | const char *fit_uname_ramdisk = NULL; |
1095 | ulong default_addr; | |
c8779648 | 1096 | int rd_noffset; |
d5934ad7 | 1097 | #endif |
983c72f4 | 1098 | const char *select = NULL; |
5ad03eb3 | 1099 | |
c8779648 MB |
1100 | *rd_start = 0; |
1101 | *rd_end = 0; | |
1102 | ||
1fec3c5d TR |
1103 | #ifdef CONFIG_ANDROID_BOOT_IMAGE |
1104 | /* | |
1105 | * Look for an Android boot image. | |
1106 | */ | |
1107 | buf = map_sysmem(images->os.start, 0); | |
c139b5ff | 1108 | if (buf && genimg_get_format(buf) == IMAGE_FORMAT_ANDROID) |
5e218862 | 1109 | select = (argc == 0) ? env_get("loadaddr") : argv[0]; |
1fec3c5d TR |
1110 | #endif |
1111 | ||
983c72f4 SG |
1112 | if (argc >= 2) |
1113 | select = argv[1]; | |
2dd46328 | 1114 | |
d5934ad7 MB |
1115 | /* |
1116 | * Look for a '-' which indicates to ignore the | |
1117 | * ramdisk argument | |
1118 | */ | |
983c72f4 | 1119 | if (select && strcmp(select, "-") == 0) { |
712fbcf3 | 1120 | debug("## Skipping init Ramdisk\n"); |
d5934ad7 | 1121 | rd_len = rd_data = 0; |
983c72f4 | 1122 | } else if (select || genimg_has_config(images)) { |
73223f0e | 1123 | #if IMAGE_ENABLE_FIT |
983c72f4 | 1124 | if (select) { |
f773bea8 MB |
1125 | /* |
1126 | * If the init ramdisk comes from the FIT image and | |
1127 | * the FIT image address is omitted in the command | |
1128 | * line argument, try to use os FIT image address or | |
1129 | * default load address. | |
1130 | */ | |
1131 | if (images->fit_uname_os) | |
1132 | default_addr = (ulong)images->fit_hdr_os; | |
1133 | else | |
bb872dd9 | 1134 | default_addr = image_load_addr; |
f773bea8 | 1135 | |
983c72f4 SG |
1136 | if (fit_parse_conf(select, default_addr, |
1137 | &rd_addr, &fit_uname_config)) { | |
712fbcf3 SW |
1138 | debug("* ramdisk: config '%s' from image at " |
1139 | "0x%08lx\n", | |
f773bea8 | 1140 | fit_uname_config, rd_addr); |
983c72f4 | 1141 | } else if (fit_parse_subimage(select, default_addr, |
f773bea8 | 1142 | &rd_addr, &fit_uname_ramdisk)) { |
712fbcf3 SW |
1143 | debug("* ramdisk: subimage '%s' from image at " |
1144 | "0x%08lx\n", | |
f773bea8 MB |
1145 | fit_uname_ramdisk, rd_addr); |
1146 | } else | |
d5934ad7 | 1147 | #endif |
f773bea8 | 1148 | { |
983c72f4 | 1149 | rd_addr = simple_strtoul(select, NULL, 16); |
712fbcf3 SW |
1150 | debug("* ramdisk: cmdline image address = " |
1151 | "0x%08lx\n", | |
f773bea8 MB |
1152 | rd_addr); |
1153 | } | |
73223f0e | 1154 | #if IMAGE_ENABLE_FIT |
f773bea8 MB |
1155 | } else { |
1156 | /* use FIT configuration provided in first bootm | |
a51ec63b SG |
1157 | * command argument. If the property is not defined, |
1158 | * quit silently. | |
f773bea8 | 1159 | */ |
35e7b0f1 | 1160 | rd_addr = map_to_sysmem(images->fit_hdr_os); |
a51ec63b SG |
1161 | rd_noffset = fit_get_node_from_config(images, |
1162 | FIT_RAMDISK_PROP, rd_addr); | |
bd86ef11 | 1163 | if (rd_noffset == -ENOENT) |
41266c9b | 1164 | return 0; |
a51ec63b SG |
1165 | else if (rd_noffset < 0) |
1166 | return 1; | |
d5934ad7 | 1167 | } |
f773bea8 | 1168 | #endif |
d5934ad7 | 1169 | |
d5934ad7 MB |
1170 | /* |
1171 | * Check if there is an initrd image at the | |
1172 | * address provided in the second bootm argument | |
1173 | * check image type, for FIT images get FIT node. | |
1174 | */ | |
35e7b0f1 SG |
1175 | buf = map_sysmem(rd_addr, 0); |
1176 | switch (genimg_get_format(buf)) { | |
c76c93a3 | 1177 | #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) |
d5934ad7 | 1178 | case IMAGE_FORMAT_LEGACY: |
712fbcf3 | 1179 | printf("## Loading init Ramdisk from Legacy " |
c8779648 | 1180 | "Image at %08lx ...\n", rd_addr); |
5ad03eb3 | 1181 | |
770605e4 | 1182 | bootstage_mark(BOOTSTAGE_ID_CHECK_RAMDISK); |
712fbcf3 | 1183 | rd_hdr = image_get_ramdisk(rd_addr, arch, |
d985c849 | 1184 | images->verify); |
5ad03eb3 | 1185 | |
c8779648 | 1186 | if (rd_hdr == NULL) |
274cea2b | 1187 | return 1; |
274cea2b | 1188 | |
712fbcf3 SW |
1189 | rd_data = image_get_data(rd_hdr); |
1190 | rd_len = image_get_data_size(rd_hdr); | |
1191 | rd_load = image_get_load(rd_hdr); | |
d5934ad7 | 1192 | break; |
21d29f7f | 1193 | #endif |
73223f0e | 1194 | #if IMAGE_ENABLE_FIT |
d5934ad7 | 1195 | case IMAGE_FORMAT_FIT: |
126cc864 | 1196 | rd_noffset = fit_image_load(images, |
a51ec63b | 1197 | rd_addr, &fit_uname_ramdisk, |
f320a4d8 | 1198 | &fit_uname_config, arch, |
a51ec63b SG |
1199 | IH_TYPE_RAMDISK, |
1200 | BOOTSTAGE_ID_FIT_RD_START, | |
fe20a81a SG |
1201 | FIT_LOAD_OPTIONAL_NON_ZERO, |
1202 | &rd_data, &rd_len); | |
a51ec63b | 1203 | if (rd_noffset < 0) |
c78fce69 | 1204 | return 1; |
c8779648 | 1205 | |
a51ec63b | 1206 | images->fit_hdr_rd = map_sysmem(rd_addr, 0); |
c8779648 | 1207 | images->fit_uname_rd = fit_uname_ramdisk; |
3dfe1101 | 1208 | images->fit_noffset_rd = rd_noffset; |
c8779648 | 1209 | break; |
2dd46328 RH |
1210 | #endif |
1211 | #ifdef CONFIG_ANDROID_BOOT_IMAGE | |
1212 | case IMAGE_FORMAT_ANDROID: | |
1213 | android_image_get_ramdisk((void *)images->os.start, | |
1214 | &rd_data, &rd_len); | |
1215 | break; | |
d5934ad7 MB |
1216 | #endif |
1217 | default: | |
017e1f3f | 1218 | #ifdef CONFIG_SUPPORT_RAW_INITRD |
983c72f4 SG |
1219 | end = NULL; |
1220 | if (select) | |
1221 | end = strchr(select, ':'); | |
1222 | if (end) { | |
017e1f3f MV |
1223 | rd_len = simple_strtoul(++end, NULL, 16); |
1224 | rd_data = rd_addr; | |
1225 | } else | |
1226 | #endif | |
1227 | { | |
1228 | puts("Wrong Ramdisk Image Format\n"); | |
1229 | rd_data = rd_len = rd_load = 0; | |
1230 | return 1; | |
1231 | } | |
d5934ad7 | 1232 | } |
d5934ad7 | 1233 | } else if (images->legacy_hdr_valid && |
712fbcf3 SW |
1234 | image_check_type(&images->legacy_hdr_os_copy, |
1235 | IH_TYPE_MULTI)) { | |
1236 | ||
5ad03eb3 | 1237 | /* |
d5934ad7 MB |
1238 | * Now check if we have a legacy mult-component image, |
1239 | * get second entry data start address and len. | |
5ad03eb3 | 1240 | */ |
770605e4 | 1241 | bootstage_mark(BOOTSTAGE_ID_RAMDISK); |
712fbcf3 | 1242 | printf("## Loading init Ramdisk from multi component " |
c8779648 | 1243 | "Legacy Image at %08lx ...\n", |
d5934ad7 MB |
1244 | (ulong)images->legacy_hdr_os); |
1245 | ||
712fbcf3 | 1246 | image_multi_getimg(images->legacy_hdr_os, 1, &rd_data, &rd_len); |
2dd46328 | 1247 | } else { |
5ad03eb3 MB |
1248 | /* |
1249 | * no initrd image | |
1250 | */ | |
770605e4 | 1251 | bootstage_mark(BOOTSTAGE_ID_NO_RAMDISK); |
5ad03eb3 MB |
1252 | rd_len = rd_data = 0; |
1253 | } | |
1254 | ||
1255 | if (!rd_data) { | |
712fbcf3 | 1256 | debug("## No init Ramdisk\n"); |
5ad03eb3 MB |
1257 | } else { |
1258 | *rd_start = rd_data; | |
1259 | *rd_end = rd_data + rd_len; | |
1260 | } | |
712fbcf3 | 1261 | debug(" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n", |
5ad03eb3 | 1262 | *rd_start, *rd_end); |
274cea2b KG |
1263 | |
1264 | return 0; | |
5ad03eb3 | 1265 | } |
ceaed2b1 | 1266 | |
fca43cc8 | 1267 | #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH |
ceaed2b1 | 1268 | /** |
9a4daad0 | 1269 | * boot_ramdisk_high - relocate init ramdisk |
e822d7fc | 1270 | * @lmb: pointer to lmb handle, will be used for memory mgmt |
ceaed2b1 MB |
1271 | * @rd_data: ramdisk data start address |
1272 | * @rd_len: ramdisk data length | |
ceaed2b1 MB |
1273 | * @initrd_start: pointer to a ulong variable, will hold final init ramdisk |
1274 | * start address (after possible relocation) | |
1275 | * @initrd_end: pointer to a ulong variable, will hold final init ramdisk | |
1276 | * end address (after possible relocation) | |
1277 | * | |
1bce2aeb | 1278 | * boot_ramdisk_high() takes a relocation hint from "initrd_high" environment |
ceaed2b1 MB |
1279 | * variable and if requested ramdisk data is moved to a specified location. |
1280 | * | |
9a4daad0 MB |
1281 | * Initrd_start and initrd_end are set to final (after relocation) ramdisk |
1282 | * start/end addresses if ramdisk image start and len were provided, | |
1283 | * otherwise set initrd_start and initrd_end set to zeros. | |
1284 | * | |
ceaed2b1 | 1285 | * returns: |
9a4daad0 MB |
1286 | * 0 - success |
1287 | * -1 - failure | |
ceaed2b1 | 1288 | */ |
712fbcf3 | 1289 | int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len, |
e822d7fc | 1290 | ulong *initrd_start, ulong *initrd_end) |
ceaed2b1 MB |
1291 | { |
1292 | char *s; | |
1293 | ulong initrd_high; | |
1294 | int initrd_copy_to_ram = 1; | |
1295 | ||
00caae6d SG |
1296 | s = env_get("initrd_high"); |
1297 | if (s) { | |
ceaed2b1 MB |
1298 | /* a value of "no" or a similar string will act like 0, |
1299 | * turning the "load high" feature off. This is intentional. | |
1300 | */ | |
712fbcf3 | 1301 | initrd_high = simple_strtoul(s, NULL, 16); |
ceaed2b1 MB |
1302 | if (initrd_high == ~0) |
1303 | initrd_copy_to_ram = 0; | |
1304 | } else { | |
723806cc | 1305 | initrd_high = env_get_bootm_mapsize() + env_get_bootm_low(); |
ceaed2b1 MB |
1306 | } |
1307 | ||
95d449ad | 1308 | |
712fbcf3 | 1309 | debug("## initrd_high = 0x%08lx, copy_to_ram = %d\n", |
ceaed2b1 MB |
1310 | initrd_high, initrd_copy_to_ram); |
1311 | ||
1312 | if (rd_data) { | |
1313 | if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */ | |
712fbcf3 | 1314 | debug(" in-place initrd\n"); |
ceaed2b1 MB |
1315 | *initrd_start = rd_data; |
1316 | *initrd_end = rd_data + rd_len; | |
e822d7fc | 1317 | lmb_reserve(lmb, rd_data, rd_len); |
ceaed2b1 | 1318 | } else { |
e822d7fc | 1319 | if (initrd_high) |
712fbcf3 SW |
1320 | *initrd_start = (ulong)lmb_alloc_base(lmb, |
1321 | rd_len, 0x1000, initrd_high); | |
e822d7fc | 1322 | else |
712fbcf3 SW |
1323 | *initrd_start = (ulong)lmb_alloc(lmb, rd_len, |
1324 | 0x1000); | |
e822d7fc KG |
1325 | |
1326 | if (*initrd_start == 0) { | |
712fbcf3 | 1327 | puts("ramdisk - allocation error\n"); |
e822d7fc | 1328 | goto error; |
ceaed2b1 | 1329 | } |
770605e4 | 1330 | bootstage_mark(BOOTSTAGE_ID_COPY_RAMDISK); |
ceaed2b1 MB |
1331 | |
1332 | *initrd_end = *initrd_start + rd_len; | |
712fbcf3 | 1333 | printf(" Loading Ramdisk to %08lx, end %08lx ... ", |
ceaed2b1 MB |
1334 | *initrd_start, *initrd_end); |
1335 | ||
712fbcf3 | 1336 | memmove_wd((void *)*initrd_start, |
ceaed2b1 MB |
1337 | (void *)rd_data, rd_len, CHUNKSZ); |
1338 | ||
3b200110 KG |
1339 | #ifdef CONFIG_MP |
1340 | /* | |
1341 | * Ensure the image is flushed to memory to handle | |
1342 | * AMP boot scenarios in which we might not be | |
1343 | * HW cache coherent | |
1344 | */ | |
1a1e7072 HS |
1345 | flush_cache((unsigned long)*initrd_start, |
1346 | ALIGN(rd_len, ARCH_DMA_MINALIGN)); | |
3b200110 | 1347 | #endif |
712fbcf3 | 1348 | puts("OK\n"); |
ceaed2b1 MB |
1349 | } |
1350 | } else { | |
1351 | *initrd_start = 0; | |
1352 | *initrd_end = 0; | |
1353 | } | |
712fbcf3 | 1354 | debug(" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n", |
ceaed2b1 | 1355 | *initrd_start, *initrd_end); |
9a4daad0 | 1356 | |
e822d7fc | 1357 | return 0; |
b6b0fe64 | 1358 | |
e822d7fc KG |
1359 | error: |
1360 | return -1; | |
b6b0fe64 | 1361 | } |
fca43cc8 | 1362 | #endif /* CONFIG_SYS_BOOT_RAMDISK_HIGH */ |
b6b0fe64 | 1363 | |
90268b87 SG |
1364 | int boot_get_setup(bootm_headers_t *images, uint8_t arch, |
1365 | ulong *setup_start, ulong *setup_len) | |
1366 | { | |
73223f0e | 1367 | #if IMAGE_ENABLE_FIT |
90268b87 SG |
1368 | return boot_get_setup_fit(images, arch, setup_start, setup_len); |
1369 | #else | |
1370 | return -ENOENT; | |
1371 | #endif | |
1372 | } | |
1373 | ||
73223f0e | 1374 | #if IMAGE_ENABLE_FIT |
8b93a92f | 1375 | #if defined(CONFIG_FPGA) |
09140113 | 1376 | int boot_get_fpga(int argc, char *const argv[], bootm_headers_t *images, |
62afc601 MS |
1377 | uint8_t arch, const ulong *ld_start, ulong * const ld_len) |
1378 | { | |
1379 | ulong tmp_img_addr, img_data, img_len; | |
1380 | void *buf; | |
1381 | int conf_noffset; | |
1382 | int fit_img_result; | |
b02e4044 | 1383 | const char *uname, *name; |
62afc601 MS |
1384 | int err; |
1385 | int devnum = 0; /* TODO support multi fpga platforms */ | |
62afc601 MS |
1386 | |
1387 | /* Check to see if the images struct has a FIT configuration */ | |
1388 | if (!genimg_has_config(images)) { | |
1389 | debug("## FIT configuration was not specified\n"); | |
1390 | return 0; | |
1391 | } | |
1392 | ||
1393 | /* | |
1394 | * Obtain the os FIT header from the images struct | |
62afc601 MS |
1395 | */ |
1396 | tmp_img_addr = map_to_sysmem(images->fit_hdr_os); | |
62afc601 MS |
1397 | buf = map_sysmem(tmp_img_addr, 0); |
1398 | /* | |
1399 | * Check image type. For FIT images get FIT node | |
1400 | * and attempt to locate a generic binary. | |
1401 | */ | |
1402 | switch (genimg_get_format(buf)) { | |
1403 | case IMAGE_FORMAT_FIT: | |
1404 | conf_noffset = fit_conf_get_node(buf, images->fit_uname_cfg); | |
1405 | ||
b02e4044 SG |
1406 | uname = fdt_stringlist_get(buf, conf_noffset, FIT_FPGA_PROP, 0, |
1407 | NULL); | |
1408 | if (!uname) { | |
62afc601 MS |
1409 | debug("## FPGA image is not specified\n"); |
1410 | return 0; | |
1411 | } | |
1412 | fit_img_result = fit_image_load(images, | |
1413 | tmp_img_addr, | |
1414 | (const char **)&uname, | |
1415 | &(images->fit_uname_cfg), | |
1416 | arch, | |
1417 | IH_TYPE_FPGA, | |
1418 | BOOTSTAGE_ID_FPGA_INIT, | |
1419 | FIT_LOAD_OPTIONAL_NON_ZERO, | |
1420 | &img_data, &img_len); | |
1421 | ||
1422 | debug("FPGA image (%s) loaded to 0x%lx/size 0x%lx\n", | |
1423 | uname, img_data, img_len); | |
1424 | ||
1425 | if (fit_img_result < 0) { | |
1426 | /* Something went wrong! */ | |
1427 | return fit_img_result; | |
1428 | } | |
1429 | ||
8b93a92f | 1430 | if (!fpga_is_partial_data(devnum, img_len)) { |
62afc601 MS |
1431 | name = "full"; |
1432 | err = fpga_loadbitstream(devnum, (char *)img_data, | |
1433 | img_len, BIT_FULL); | |
1434 | if (err) | |
1435 | err = fpga_load(devnum, (const void *)img_data, | |
1436 | img_len, BIT_FULL); | |
1437 | } else { | |
1438 | name = "partial"; | |
1439 | err = fpga_loadbitstream(devnum, (char *)img_data, | |
1440 | img_len, BIT_PARTIAL); | |
1441 | if (err) | |
1442 | err = fpga_load(devnum, (const void *)img_data, | |
1443 | img_len, BIT_PARTIAL); | |
1444 | } | |
1445 | ||
62afc601 | 1446 | if (err) |
611a9428 MS |
1447 | return err; |
1448 | ||
1449 | printf(" Programming %s bitstream... OK\n", name); | |
62afc601 MS |
1450 | break; |
1451 | default: | |
1452 | printf("The given image format is not supported (corrupt?)\n"); | |
1453 | return 1; | |
1454 | } | |
1455 | ||
1456 | return 0; | |
1457 | } | |
1458 | #endif | |
1459 | ||
d7be5092 AD |
1460 | static void fit_loadable_process(uint8_t img_type, |
1461 | ulong img_data, | |
1462 | ulong img_len) | |
1463 | { | |
1464 | int i; | |
1465 | const unsigned int count = | |
1466 | ll_entry_count(struct fit_loadable_tbl, fit_loadable); | |
1467 | struct fit_loadable_tbl *fit_loadable_handler = | |
1468 | ll_entry_start(struct fit_loadable_tbl, fit_loadable); | |
1469 | /* For each loadable handler */ | |
1470 | for (i = 0; i < count; i++, fit_loadable_handler++) | |
1471 | /* matching this type */ | |
1472 | if (fit_loadable_handler->type == img_type) | |
1473 | /* call that handler with this image data */ | |
1474 | fit_loadable_handler->handler(img_data, img_len); | |
1475 | } | |
1476 | ||
09140113 SG |
1477 | int boot_get_loadable(int argc, char *const argv[], bootm_headers_t *images, |
1478 | uint8_t arch, const ulong *ld_start, ulong * const ld_len) | |
84a07dbf KA |
1479 | { |
1480 | /* | |
1481 | * These variables are used to hold the current image location | |
1482 | * in system memory. | |
1483 | */ | |
1484 | ulong tmp_img_addr; | |
1485 | /* | |
1486 | * These two variables are requirements for fit_image_load, but | |
1487 | * their values are not used | |
1488 | */ | |
1489 | ulong img_data, img_len; | |
1490 | void *buf; | |
1491 | int loadables_index; | |
1492 | int conf_noffset; | |
1493 | int fit_img_result; | |
b02e4044 | 1494 | const char *uname; |
d7be5092 | 1495 | uint8_t img_type; |
84a07dbf KA |
1496 | |
1497 | /* Check to see if the images struct has a FIT configuration */ | |
1498 | if (!genimg_has_config(images)) { | |
1499 | debug("## FIT configuration was not specified\n"); | |
1500 | return 0; | |
1501 | } | |
1502 | ||
1503 | /* | |
1504 | * Obtain the os FIT header from the images struct | |
84a07dbf KA |
1505 | */ |
1506 | tmp_img_addr = map_to_sysmem(images->fit_hdr_os); | |
84a07dbf KA |
1507 | buf = map_sysmem(tmp_img_addr, 0); |
1508 | /* | |
1509 | * Check image type. For FIT images get FIT node | |
1510 | * and attempt to locate a generic binary. | |
1511 | */ | |
1512 | switch (genimg_get_format(buf)) { | |
1513 | case IMAGE_FORMAT_FIT: | |
1514 | conf_noffset = fit_conf_get_node(buf, images->fit_uname_cfg); | |
1515 | ||
1516 | for (loadables_index = 0; | |
b02e4044 SG |
1517 | uname = fdt_stringlist_get(buf, conf_noffset, |
1518 | FIT_LOADABLE_PROP, loadables_index, | |
1519 | NULL), uname; | |
84a07dbf KA |
1520 | loadables_index++) |
1521 | { | |
1522 | fit_img_result = fit_image_load(images, | |
1523 | tmp_img_addr, | |
b02e4044 | 1524 | &uname, |
84a07dbf KA |
1525 | &(images->fit_uname_cfg), arch, |
1526 | IH_TYPE_LOADABLE, | |
1527 | BOOTSTAGE_ID_FIT_LOADABLE_START, | |
1528 | FIT_LOAD_OPTIONAL_NON_ZERO, | |
1529 | &img_data, &img_len); | |
1530 | if (fit_img_result < 0) { | |
1531 | /* Something went wrong! */ | |
1532 | return fit_img_result; | |
1533 | } | |
d7be5092 AD |
1534 | |
1535 | fit_img_result = fit_image_get_node(buf, uname); | |
1536 | if (fit_img_result < 0) { | |
1537 | /* Something went wrong! */ | |
1538 | return fit_img_result; | |
1539 | } | |
1540 | fit_img_result = fit_image_get_type(buf, | |
1541 | fit_img_result, | |
1542 | &img_type); | |
1543 | if (fit_img_result < 0) { | |
1544 | /* Something went wrong! */ | |
1545 | return fit_img_result; | |
1546 | } | |
1547 | ||
1548 | fit_loadable_process(img_type, img_data, img_len); | |
84a07dbf KA |
1549 | } |
1550 | break; | |
1551 | default: | |
1552 | printf("The given image format is not supported (corrupt?)\n"); | |
1553 | return 1; | |
1554 | } | |
1555 | ||
1556 | return 0; | |
1557 | } | |
1558 | #endif | |
1559 | ||
fca43cc8 | 1560 | #ifdef CONFIG_SYS_BOOT_GET_CMDLINE |
b6b0fe64 | 1561 | /** |
9a4daad0 | 1562 | * boot_get_cmdline - allocate and initialize kernel cmdline |
e822d7fc | 1563 | * @lmb: pointer to lmb handle, will be used for memory mgmt |
b6b0fe64 MB |
1564 | * @cmd_start: pointer to a ulong variable, will hold cmdline start |
1565 | * @cmd_end: pointer to a ulong variable, will hold cmdline end | |
1566 | * | |
9a4daad0 | 1567 | * boot_get_cmdline() allocates space for kernel command line below |
919d25c9 | 1568 | * BOOTMAPSZ + env_get_bootm_low() address. If "bootargs" U-Boot environment |
b6b0fe64 MB |
1569 | * variable is present its contents is copied to allocated kernel |
1570 | * command line. | |
1571 | * | |
1572 | * returns: | |
e822d7fc KG |
1573 | * 0 - success |
1574 | * -1 - failure | |
b6b0fe64 | 1575 | */ |
712fbcf3 | 1576 | int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end) |
b6b0fe64 MB |
1577 | { |
1578 | char *cmdline; | |
1579 | char *s; | |
1580 | ||
6d0f6bcf | 1581 | cmdline = (char *)(ulong)lmb_alloc_base(lmb, CONFIG_SYS_BARGSIZE, 0xf, |
723806cc | 1582 | env_get_bootm_mapsize() + env_get_bootm_low()); |
e822d7fc KG |
1583 | |
1584 | if (cmdline == NULL) | |
1585 | return -1; | |
b6b0fe64 | 1586 | |
00caae6d SG |
1587 | s = env_get("bootargs"); |
1588 | if (!s) | |
b6b0fe64 MB |
1589 | s = ""; |
1590 | ||
1591 | strcpy(cmdline, s); | |
1592 | ||
1593 | *cmd_start = (ulong) & cmdline[0]; | |
1594 | *cmd_end = *cmd_start + strlen(cmdline); | |
1595 | ||
712fbcf3 | 1596 | debug("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end); |
b6b0fe64 | 1597 | |
e822d7fc | 1598 | return 0; |
b6b0fe64 | 1599 | } |
fca43cc8 | 1600 | #endif /* CONFIG_SYS_BOOT_GET_CMDLINE */ |
b6b0fe64 | 1601 | |
fca43cc8 | 1602 | #ifdef CONFIG_SYS_BOOT_GET_KBD |
b6b0fe64 | 1603 | /** |
9a4daad0 | 1604 | * boot_get_kbd - allocate and initialize kernel copy of board info |
e822d7fc | 1605 | * @lmb: pointer to lmb handle, will be used for memory mgmt |
b6b0fe64 MB |
1606 | * @kbd: double pointer to board info data |
1607 | * | |
9a4daad0 | 1608 | * boot_get_kbd() allocates space for kernel copy of board info data below |
723806cc | 1609 | * BOOTMAPSZ + env_get_bootm_low() address and kernel board info is initialized |
590d3cac | 1610 | * with the current u-boot board info data. |
b6b0fe64 MB |
1611 | * |
1612 | * returns: | |
e822d7fc KG |
1613 | * 0 - success |
1614 | * -1 - failure | |
b6b0fe64 | 1615 | */ |
712fbcf3 | 1616 | int boot_get_kbd(struct lmb *lmb, bd_t **kbd) |
b6b0fe64 | 1617 | { |
391fd93a | 1618 | *kbd = (bd_t *)(ulong)lmb_alloc_base(lmb, sizeof(bd_t), 0xf, |
723806cc | 1619 | env_get_bootm_mapsize() + env_get_bootm_low()); |
e822d7fc KG |
1620 | if (*kbd == NULL) |
1621 | return -1; | |
1622 | ||
b6b0fe64 MB |
1623 | **kbd = *(gd->bd); |
1624 | ||
712fbcf3 | 1625 | debug("## kernel board info at 0x%08lx\n", (ulong)*kbd); |
b6b0fe64 MB |
1626 | |
1627 | #if defined(DEBUG) && defined(CONFIG_CMD_BDI) | |
1628 | do_bdinfo(NULL, 0, 0, NULL); | |
1629 | #endif | |
1630 | ||
e822d7fc | 1631 | return 0; |
ceaed2b1 | 1632 | } |
fca43cc8 | 1633 | #endif /* CONFIG_SYS_BOOT_GET_KBD */ |
13d06981 SG |
1634 | |
1635 | #ifdef CONFIG_LMB | |
1636 | int image_setup_linux(bootm_headers_t *images) | |
1637 | { | |
1638 | ulong of_size = images->ft_len; | |
1639 | char **of_flat_tree = &images->ft_addr; | |
13d06981 | 1640 | struct lmb *lmb = &images->lmb; |
13d06981 SG |
1641 | int ret; |
1642 | ||
1643 | if (IMAGE_ENABLE_OF_LIBFDT) | |
1644 | boot_fdt_add_mem_rsv_regions(lmb, *of_flat_tree); | |
1645 | ||
1646 | if (IMAGE_BOOT_GET_CMDLINE) { | |
1647 | ret = boot_get_cmdline(lmb, &images->cmdline_start, | |
1648 | &images->cmdline_end); | |
1649 | if (ret) { | |
1650 | puts("ERROR with allocation of cmdline\n"); | |
1651 | return ret; | |
1652 | } | |
1653 | } | |
13d06981 SG |
1654 | |
1655 | if (IMAGE_ENABLE_OF_LIBFDT) { | |
1656 | ret = boot_relocate_fdt(lmb, of_flat_tree, &of_size); | |
1657 | if (ret) | |
1658 | return ret; | |
1659 | } | |
1660 | ||
1661 | if (IMAGE_ENABLE_OF_LIBFDT && of_size) { | |
1662 | ret = image_setup_libfdt(images, *of_flat_tree, of_size, lmb); | |
1663 | if (ret) | |
1664 | return ret; | |
1665 | } | |
1666 | ||
1667 | return 0; | |
1668 | } | |
1669 | #endif /* CONFIG_LMB */ | |
5dfb5213 | 1670 | #endif /* !USE_HOSTCC */ |