xref: /openbmc/u-boot/include/image.h (revision 06499e6b)
183d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */
25b1d7137Swdenk /*
3b97a2a0aSMarian Balakowicz  * (C) Copyright 2008 Semihalf
4b97a2a0aSMarian Balakowicz  *
5f08abe31SWolfgang Denk  * (C) Copyright 2000-2005
65b1d7137Swdenk  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7f08abe31SWolfgang Denk  ********************************************************************
8f08abe31SWolfgang Denk  * NOTE: This header file defines an interface to U-Boot. Including
9f08abe31SWolfgang Denk  * this (unmodified) header file in another file is considered normal
10f08abe31SWolfgang Denk  * use of U-Boot, and does *not* fall under the heading of "derived
11f08abe31SWolfgang Denk  * work".
12f08abe31SWolfgang Denk  ********************************************************************
135b1d7137Swdenk  */
145b1d7137Swdenk 
155b1d7137Swdenk #ifndef __IMAGE_H__
165b1d7137Swdenk #define __IMAGE_H__
175b1d7137Swdenk 
1837566090SMike Frysinger #include "compiler.h"
192f220500SKim Phillips #include <asm/byteorder.h>
207f13b374SMarek Vasut #include <stdbool.h>
2137566090SMike Frysinger 
2213d06981SSimon Glass /* Define this to avoid #ifdefs later on */
2313d06981SSimon Glass struct lmb;
24641599a6SMasahiro Yamada struct fdt_region;
2513d06981SSimon Glass 
2637566090SMike Frysinger #ifdef USE_HOSTCC
2726e355d1SJörg Krause #include <sys/types.h>
289d25438fSBartlomiej Sieka 
299d25438fSBartlomiej Sieka /* new uImage format support enabled on host */
3073223f0eSSimon Glass #define IMAGE_ENABLE_FIT	1
31aa34fbc0SSimon Glass #define IMAGE_ENABLE_OF_LIBFDT	1
329d25438fSBartlomiej Sieka #define CONFIG_FIT_VERBOSE	1 /* enable fit_format_{error,warning}() */
33061daa0bSPhilippe Reynes #define CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT 1
340db7f685STom Rini #define CONFIG_FIT_ENABLE_SHA256_SUPPORT
35e9221d03SReuben Dowle #define CONFIG_FIT_ENABLE_SHA384_SUPPORT
36e9221d03SReuben Dowle #define CONFIG_FIT_ENABLE_SHA512_SUPPORT
37089df18bSTom Rini #define CONFIG_SHA1
38089df18bSTom Rini #define CONFIG_SHA256
39e9221d03SReuben Dowle #define CONFIG_SHA384
40e9221d03SReuben Dowle #define CONFIG_SHA512
419d25438fSBartlomiej Sieka 
42ab9efc66SSimon Glass #define IMAGE_ENABLE_IGNORE	0
431fe7d938SSimon Glass #define IMAGE_INDENT_STRING	""
44ab9efc66SSimon Glass 
45def0819eSWolfgang Denk #else
46def0819eSWolfgang Denk 
47def0819eSWolfgang Denk #include <lmb.h>
48def0819eSWolfgang Denk #include <asm/u-boot.h>
495daa1c18SMike Frysinger #include <command.h>
50def0819eSWolfgang Denk 
51ab9efc66SSimon Glass /* Take notice of the 'ignore' property for hashes */
52ab9efc66SSimon Glass #define IMAGE_ENABLE_IGNORE	1
531fe7d938SSimon Glass #define IMAGE_INDENT_STRING	"   "
54ab9efc66SSimon Glass 
5573223f0eSSimon Glass #define IMAGE_ENABLE_FIT	CONFIG_IS_ENABLED(FIT)
56aa34fbc0SSimon Glass #define IMAGE_ENABLE_OF_LIBFDT	CONFIG_IS_ENABLED(OF_LIBFDT)
5773223f0eSSimon Glass 
589d25438fSBartlomiej Sieka #endif /* USE_HOSTCC */
59d5934ad7SMarian Balakowicz 
6073223f0eSSimon Glass #if IMAGE_ENABLE_FIT
611de7bb4fSMichael van der Westhuizen #include <hash.h>
62b08c8c48SMasahiro Yamada #include <linux/libfdt.h>
635dfb5213SMarian Balakowicz #include <fdt_support.h>
6487ebee39SSimon Glass # ifdef CONFIG_SPL_BUILD
656f41751fSMasahiro Yamada #  ifdef CONFIG_SPL_CRC32_SUPPORT
666f41751fSMasahiro Yamada #   define IMAGE_ENABLE_CRC32	1
676f41751fSMasahiro Yamada #  endif
686f41751fSMasahiro Yamada #  ifdef CONFIG_SPL_MD5_SUPPORT
696f41751fSMasahiro Yamada #   define IMAGE_ENABLE_MD5	1
706f41751fSMasahiro Yamada #  endif
716f41751fSMasahiro Yamada #  ifdef CONFIG_SPL_SHA1_SUPPORT
726f41751fSMasahiro Yamada #   define IMAGE_ENABLE_SHA1	1
736f41751fSMasahiro Yamada #  endif
7487ebee39SSimon Glass # else
7587ebee39SSimon Glass #  define CONFIG_CRC32		/* FIT images need CRC32 support */
7687ebee39SSimon Glass #  define IMAGE_ENABLE_CRC32	1
7787ebee39SSimon Glass #  define IMAGE_ENABLE_MD5	1
7887ebee39SSimon Glass #  define IMAGE_ENABLE_SHA1	1
796f41751fSMasahiro Yamada # endif
806f41751fSMasahiro Yamada 
816f41751fSMasahiro Yamada #ifndef IMAGE_ENABLE_CRC32
826f41751fSMasahiro Yamada #define IMAGE_ENABLE_CRC32	0
836f41751fSMasahiro Yamada #endif
846f41751fSMasahiro Yamada 
856f41751fSMasahiro Yamada #ifndef IMAGE_ENABLE_MD5
866f41751fSMasahiro Yamada #define IMAGE_ENABLE_MD5	0
876f41751fSMasahiro Yamada #endif
886f41751fSMasahiro Yamada 
896f41751fSMasahiro Yamada #ifndef IMAGE_ENABLE_SHA1
906f41751fSMasahiro Yamada #define IMAGE_ENABLE_SHA1	0
916f41751fSMasahiro Yamada #endif
926f41751fSMasahiro Yamada 
930db7f685STom Rini #if defined(CONFIG_FIT_ENABLE_SHA256_SUPPORT) || \
940db7f685STom Rini 	defined(CONFIG_SPL_SHA256_SUPPORT)
950db7f685STom Rini #define IMAGE_ENABLE_SHA256	1
960db7f685STom Rini #else
976f41751fSMasahiro Yamada #define IMAGE_ENABLE_SHA256	0
986f41751fSMasahiro Yamada #endif
996f41751fSMasahiro Yamada 
100e9221d03SReuben Dowle #if defined(CONFIG_FIT_ENABLE_SHA384_SUPPORT) || \
101e9221d03SReuben Dowle 	defined(CONFIG_SPL_SHA384_SUPPORT)
102e9221d03SReuben Dowle #define IMAGE_ENABLE_SHA384	1
103e9221d03SReuben Dowle #else
104e9221d03SReuben Dowle #define IMAGE_ENABLE_SHA384	0
105e9221d03SReuben Dowle #endif
106e9221d03SReuben Dowle 
107e9221d03SReuben Dowle #if defined(CONFIG_FIT_ENABLE_SHA512_SUPPORT) || \
108e9221d03SReuben Dowle 	defined(CONFIG_SPL_SHA512_SUPPORT)
109e9221d03SReuben Dowle #define IMAGE_ENABLE_SHA512	1
110e9221d03SReuben Dowle #else
111e9221d03SReuben Dowle #define IMAGE_ENABLE_SHA512	0
112e9221d03SReuben Dowle #endif
113e9221d03SReuben Dowle 
11473223f0eSSimon Glass #endif /* IMAGE_ENABLE_FIT */
11513d06981SSimon Glass 
1166f41751fSMasahiro Yamada #ifdef CONFIG_SYS_BOOT_GET_CMDLINE
1176f41751fSMasahiro Yamada # define IMAGE_BOOT_GET_CMDLINE		1
1186f41751fSMasahiro Yamada #else
1196f41751fSMasahiro Yamada # define IMAGE_BOOT_GET_CMDLINE		0
1206f41751fSMasahiro Yamada #endif
1216f41751fSMasahiro Yamada 
1226f41751fSMasahiro Yamada #ifdef CONFIG_OF_BOARD_SETUP
1236f41751fSMasahiro Yamada # define IMAGE_OF_BOARD_SETUP		1
1246f41751fSMasahiro Yamada #else
1256f41751fSMasahiro Yamada # define IMAGE_OF_BOARD_SETUP		0
1266f41751fSMasahiro Yamada #endif
1276f41751fSMasahiro Yamada 
1286f41751fSMasahiro Yamada #ifdef CONFIG_OF_SYSTEM_SETUP
1296f41751fSMasahiro Yamada # define IMAGE_OF_SYSTEM_SETUP	1
1306f41751fSMasahiro Yamada #else
1316f41751fSMasahiro Yamada # define IMAGE_OF_SYSTEM_SETUP	0
1326f41751fSMasahiro Yamada #endif
133c654b517SSimon Glass 
13456d7ab74SSimon Glass enum ih_category {
13556d7ab74SSimon Glass 	IH_ARCH,
13656d7ab74SSimon Glass 	IH_COMP,
13756d7ab74SSimon Glass 	IH_OS,
13856d7ab74SSimon Glass 	IH_TYPE,
13956d7ab74SSimon Glass 
14056d7ab74SSimon Glass 	IH_COUNT,
14156d7ab74SSimon Glass };
14256d7ab74SSimon Glass 
1435b1d7137Swdenk /*
1445b1d7137Swdenk  * Operating System Codes
145ff87b081SMasahiro Yamada  *
146ff87b081SMasahiro Yamada  * The following are exposed to uImage header.
14724431adcSStefano Babic  * New IDs *MUST* be appended at the end of the list and *NEVER*
14824431adcSStefano Babic  * inserted for backward compatibility.
1495b1d7137Swdenk  */
150555f45d8SSimon Glass enum {
151555f45d8SSimon Glass 	IH_OS_INVALID		= 0,	/* Invalid OS	*/
152555f45d8SSimon Glass 	IH_OS_OPENBSD,			/* OpenBSD	*/
153555f45d8SSimon Glass 	IH_OS_NETBSD,			/* NetBSD	*/
154555f45d8SSimon Glass 	IH_OS_FREEBSD,			/* FreeBSD	*/
155555f45d8SSimon Glass 	IH_OS_4_4BSD,			/* 4.4BSD	*/
156555f45d8SSimon Glass 	IH_OS_LINUX,			/* Linux	*/
157555f45d8SSimon Glass 	IH_OS_SVR4,			/* SVR4		*/
158555f45d8SSimon Glass 	IH_OS_ESIX,			/* Esix		*/
159555f45d8SSimon Glass 	IH_OS_SOLARIS,			/* Solaris	*/
160555f45d8SSimon Glass 	IH_OS_IRIX,			/* Irix		*/
161555f45d8SSimon Glass 	IH_OS_SCO,			/* SCO		*/
162555f45d8SSimon Glass 	IH_OS_DELL,			/* Dell		*/
163555f45d8SSimon Glass 	IH_OS_NCR,			/* NCR		*/
164555f45d8SSimon Glass 	IH_OS_LYNXOS,			/* LynxOS	*/
165555f45d8SSimon Glass 	IH_OS_VXWORKS,			/* VxWorks	*/
166555f45d8SSimon Glass 	IH_OS_PSOS,			/* pSOS		*/
167555f45d8SSimon Glass 	IH_OS_QNX,			/* QNX		*/
168555f45d8SSimon Glass 	IH_OS_U_BOOT,			/* Firmware	*/
169555f45d8SSimon Glass 	IH_OS_RTEMS,			/* RTEMS	*/
170555f45d8SSimon Glass 	IH_OS_ARTOS,			/* ARTOS	*/
171555f45d8SSimon Glass 	IH_OS_UNITY,			/* Unity OS	*/
172555f45d8SSimon Glass 	IH_OS_INTEGRITY,		/* INTEGRITY	*/
173555f45d8SSimon Glass 	IH_OS_OSE,			/* OSE		*/
174555f45d8SSimon Glass 	IH_OS_PLAN9,			/* Plan 9	*/
175555f45d8SSimon Glass 	IH_OS_OPENRTOS,		/* OpenRTOS	*/
1764914af12SPhilipp Tomsich 	IH_OS_ARM_TRUSTED_FIRMWARE,     /* ARM Trusted Firmware */
17745b55712SBryan O'Donoghue 	IH_OS_TEE,			/* Trusted Execution Environment */
178555f45d8SSimon Glass 
179555f45d8SSimon Glass 	IH_OS_COUNT,
180555f45d8SSimon Glass };
1815b1d7137Swdenk 
1825b1d7137Swdenk /*
1835b1d7137Swdenk  * CPU Architecture Codes (supported by Linux)
184ff87b081SMasahiro Yamada  *
185ff87b081SMasahiro Yamada  * The following are exposed to uImage header.
18624431adcSStefano Babic  * New IDs *MUST* be appended at the end of the list and *NEVER*
18724431adcSStefano Babic  * inserted for backward compatibility.
1885b1d7137Swdenk  */
189555f45d8SSimon Glass enum {
190555f45d8SSimon Glass 	IH_ARCH_INVALID		= 0,	/* Invalid CPU	*/
191555f45d8SSimon Glass 	IH_ARCH_ALPHA,			/* Alpha	*/
192555f45d8SSimon Glass 	IH_ARCH_ARM,			/* ARM		*/
193555f45d8SSimon Glass 	IH_ARCH_I386,			/* Intel x86	*/
194555f45d8SSimon Glass 	IH_ARCH_IA64,			/* IA64		*/
195555f45d8SSimon Glass 	IH_ARCH_MIPS,			/* MIPS		*/
196555f45d8SSimon Glass 	IH_ARCH_MIPS64,			/* MIPS	 64 Bit */
197555f45d8SSimon Glass 	IH_ARCH_PPC,			/* PowerPC	*/
198555f45d8SSimon Glass 	IH_ARCH_S390,			/* IBM S390	*/
199555f45d8SSimon Glass 	IH_ARCH_SH,			/* SuperH	*/
200555f45d8SSimon Glass 	IH_ARCH_SPARC,			/* Sparc	*/
201555f45d8SSimon Glass 	IH_ARCH_SPARC64,		/* Sparc 64 Bit */
202555f45d8SSimon Glass 	IH_ARCH_M68K,			/* M68K		*/
203ff87b081SMasahiro Yamada 	IH_ARCH_NIOS,			/* Nios-32	*/
204555f45d8SSimon Glass 	IH_ARCH_MICROBLAZE,		/* MicroBlaze   */
205555f45d8SSimon Glass 	IH_ARCH_NIOS2,			/* Nios-II	*/
206555f45d8SSimon Glass 	IH_ARCH_BLACKFIN,		/* Blackfin	*/
207555f45d8SSimon Glass 	IH_ARCH_AVR32,			/* AVR32	*/
208555f45d8SSimon Glass 	IH_ARCH_ST200,			/* STMicroelectronics ST200  */
209555f45d8SSimon Glass 	IH_ARCH_SANDBOX,		/* Sandbox architecture (test only) */
210555f45d8SSimon Glass 	IH_ARCH_NDS32,			/* ANDES Technology - NDS32  */
211555f45d8SSimon Glass 	IH_ARCH_OPENRISC,		/* OpenRISC 1000  */
212555f45d8SSimon Glass 	IH_ARCH_ARM64,			/* ARM64	*/
213555f45d8SSimon Glass 	IH_ARCH_ARC,			/* Synopsys DesignWare ARC */
214555f45d8SSimon Glass 	IH_ARCH_X86_64,			/* AMD x86_64, Intel and Via */
215de5e5ceaSChris Zankel 	IH_ARCH_XTENSA,			/* Xtensa	*/
216068feb9bSRick Chen 	IH_ARCH_RISCV,			/* RISC-V */
217555f45d8SSimon Glass 
218555f45d8SSimon Glass 	IH_ARCH_COUNT,
219555f45d8SSimon Glass };
2205b1d7137Swdenk 
2215b1d7137Swdenk /*
2225b1d7137Swdenk  * Image Types
2235b1d7137Swdenk  *
2245b1d7137Swdenk  * "Standalone Programs" are directly runnable in the environment
2255b1d7137Swdenk  *	provided by U-Boot; it is expected that (if they behave
2265b1d7137Swdenk  *	well) you can continue to work in U-Boot after return from
2275b1d7137Swdenk  *	the Standalone Program.
2285b1d7137Swdenk  * "OS Kernel Images" are usually images of some Embedded OS which
2295b1d7137Swdenk  *	will take over control completely. Usually these programs
2305b1d7137Swdenk  *	will install their own set of exception handlers, device
2315b1d7137Swdenk  *	drivers, set up the MMU, etc. - this means, that you cannot
2325b1d7137Swdenk  *	expect to re-enter U-Boot except by resetting the CPU.
2335b1d7137Swdenk  * "RAMDisk Images" are more or less just data blocks, and their
2345b1d7137Swdenk  *	parameters (address, size) are passed to an OS kernel that is
2355b1d7137Swdenk  *	being started.
2365b1d7137Swdenk  * "Multi-File Images" contain several images, typically an OS
2375b1d7137Swdenk  *	(Linux) kernel image and one or more data images like
2385b1d7137Swdenk  *	RAMDisks. This construct is useful for instance when you want
2395b1d7137Swdenk  *	to boot over the network using BOOTP etc., where the boot
2405b1d7137Swdenk  *	server provides just a single image file, but you want to get
2415b1d7137Swdenk  *	for instance an OS kernel and a RAMDisk image.
2425b1d7137Swdenk  *
2435b1d7137Swdenk  *	"Multi-File Images" start with a list of image sizes, each
2445b1d7137Swdenk  *	image size (in bytes) specified by an "uint32_t" in network
2455b1d7137Swdenk  *	byte order. This list is terminated by an "(uint32_t)0".
2465b1d7137Swdenk  *	Immediately after the terminating 0 follow the images, one by
2475b1d7137Swdenk  *	one, all aligned on "uint32_t" boundaries (size rounded up to
248e1599e83Swdenk  *	a multiple of 4 bytes - except for the last file).
2495b1d7137Swdenk  *
2505b1d7137Swdenk  * "Firmware Images" are binary images containing firmware (like
2515b1d7137Swdenk  *	U-Boot or FPGA images) which usually will be programmed to
2525b1d7137Swdenk  *	flash memory.
2535b1d7137Swdenk  *
2545b1d7137Swdenk  * "Script files" are command sequences that will be executed by
2555b1d7137Swdenk  *	U-Boot's command interpreter; this feature is especially
2565b1d7137Swdenk  *	useful when you configure U-Boot to use a real shell (hush)
25727b207fdSwdenk  *	as command interpreter (=> Shell Scripts).
258ff87b081SMasahiro Yamada  *
259ff87b081SMasahiro Yamada  * The following are exposed to uImage header.
26024431adcSStefano Babic  * New IDs *MUST* be appended at the end of the list and *NEVER*
26124431adcSStefano Babic  * inserted for backward compatibility.
2625b1d7137Swdenk  */
2635b1d7137Swdenk 
264555f45d8SSimon Glass enum {
265555f45d8SSimon Glass 	IH_TYPE_INVALID		= 0,	/* Invalid Image		*/
266555f45d8SSimon Glass 	IH_TYPE_STANDALONE,		/* Standalone Program		*/
267555f45d8SSimon Glass 	IH_TYPE_KERNEL,			/* OS Kernel Image		*/
268555f45d8SSimon Glass 	IH_TYPE_RAMDISK,		/* RAMDisk Image		*/
269555f45d8SSimon Glass 	IH_TYPE_MULTI,			/* Multi-File Image		*/
270555f45d8SSimon Glass 	IH_TYPE_FIRMWARE,		/* Firmware Image		*/
271555f45d8SSimon Glass 	IH_TYPE_SCRIPT,			/* Script file			*/
272555f45d8SSimon Glass 	IH_TYPE_FILESYSTEM,		/* Filesystem Image (any type)	*/
273555f45d8SSimon Glass 	IH_TYPE_FLATDT,			/* Binary Flat Device Tree Blob	*/
274555f45d8SSimon Glass 	IH_TYPE_KWBIMAGE,		/* Kirkwood Boot Image		*/
275555f45d8SSimon Glass 	IH_TYPE_IMXIMAGE,		/* Freescale IMXBoot Image	*/
276555f45d8SSimon Glass 	IH_TYPE_UBLIMAGE,		/* Davinci UBL Image		*/
277555f45d8SSimon Glass 	IH_TYPE_OMAPIMAGE,		/* TI OMAP Config Header Image	*/
278555f45d8SSimon Glass 	IH_TYPE_AISIMAGE,		/* TI Davinci AIS Image		*/
279555f45d8SSimon Glass 	/* OS Kernel Image, can run from any load address */
280555f45d8SSimon Glass 	IH_TYPE_KERNEL_NOLOAD,
281555f45d8SSimon Glass 	IH_TYPE_PBLIMAGE,		/* Freescale PBL Boot Image	*/
282555f45d8SSimon Glass 	IH_TYPE_MXSIMAGE,		/* Freescale MXSBoot Image	*/
283555f45d8SSimon Glass 	IH_TYPE_GPIMAGE,		/* TI Keystone GPHeader Image	*/
284555f45d8SSimon Glass 	IH_TYPE_ATMELIMAGE,		/* ATMEL ROM bootable Image	*/
285662abc4fSMarek Vasut 	IH_TYPE_SOCFPGAIMAGE,		/* Altera SOCFPGA CV/AV Preloader */
286555f45d8SSimon Glass 	IH_TYPE_X86_SETUP,		/* x86 setup.bin Image		*/
287555f45d8SSimon Glass 	IH_TYPE_LPC32XXIMAGE,		/* x86 setup.bin Image		*/
288555f45d8SSimon Glass 	IH_TYPE_LOADABLE,		/* A list of typeless images	*/
289555f45d8SSimon Glass 	IH_TYPE_RKIMAGE,		/* Rockchip Boot Image		*/
290555f45d8SSimon Glass 	IH_TYPE_RKSD,			/* Rockchip SD card		*/
291555f45d8SSimon Glass 	IH_TYPE_RKSPI,			/* Rockchip SPI image		*/
292555f45d8SSimon Glass 	IH_TYPE_ZYNQIMAGE,		/* Xilinx Zynq Boot Image */
293555f45d8SSimon Glass 	IH_TYPE_ZYNQMPIMAGE,		/* Xilinx ZynqMP Boot Image */
2946915dcf3SAlexander Graf 	IH_TYPE_ZYNQMPBIF,		/* Xilinx ZynqMP Boot Image (bif) */
295555f45d8SSimon Glass 	IH_TYPE_FPGA,			/* FPGA Image */
296ed0c2c0aSAlbert ARIBAUD \(3ADEV\) 	IH_TYPE_VYBRIDIMAGE,	/* VYBRID .vyb Image */
2977e719ee7SAndrew F. Davis 	IH_TYPE_TEE,            /* Trusted Execution Environment OS Image */
298d21bd69bSSven Ebenfeld 	IH_TYPE_FIRMWARE_IVT,		/* Firmware Image with HABv4 IVT */
2996442c964SAndrew F. Davis 	IH_TYPE_PMMC,            /* TI Power Management Micro-Controller Firmware */
30081260e33SPatrick Delaunay 	IH_TYPE_STM32IMAGE,		/* STMicroelectronics STM32 Image */
301662abc4fSMarek Vasut 	IH_TYPE_SOCFPGAIMAGE_V1,	/* Altera SOCFPGA A10 Preloader	*/
3023b975a14SRyder Lee 	IH_TYPE_MTKIMAGE,		/* MediaTek BootROM loadable Image */
30324431adcSStefano Babic 	IH_TYPE_IMX8MIMAGE,		/* Freescale IMX8MBoot Image	*/
30424431adcSStefano Babic 	IH_TYPE_IMX8IMAGE,		/* Freescale IMX8Boot Image	*/
3055b1d7137Swdenk 
306555f45d8SSimon Glass 	IH_TYPE_COUNT,			/* Number of image types */
307555f45d8SSimon Glass };
3085b9d44dfSSimon Glass 
3095b1d7137Swdenk /*
3105b1d7137Swdenk  * Compression Types
311ff87b081SMasahiro Yamada  *
312ff87b081SMasahiro Yamada  * The following are exposed to uImage header.
31324431adcSStefano Babic  * New IDs *MUST* be appended at the end of the list and *NEVER*
31424431adcSStefano Babic  * inserted for backward compatibility.
3155b1d7137Swdenk  */
316555f45d8SSimon Glass enum {
317555f45d8SSimon Glass 	IH_COMP_NONE		= 0,	/*  No	 Compression Used	*/
318555f45d8SSimon Glass 	IH_COMP_GZIP,			/* gzip	 Compression Used	*/
319555f45d8SSimon Glass 	IH_COMP_BZIP2,			/* bzip2 Compression Used	*/
320555f45d8SSimon Glass 	IH_COMP_LZMA,			/* lzma  Compression Used	*/
321555f45d8SSimon Glass 	IH_COMP_LZO,			/* lzo   Compression Used	*/
322555f45d8SSimon Glass 	IH_COMP_LZ4,			/* lz4   Compression Used	*/
323555f45d8SSimon Glass 
324555f45d8SSimon Glass 	IH_COMP_COUNT,
325555f45d8SSimon Glass };
3265b1d7137Swdenk 
3275b1d7137Swdenk #define IH_MAGIC	0x27051956	/* Image Magic Number		*/
3285b1d7137Swdenk #define IH_NMLEN		32	/* Image Name Length		*/
3295b1d7137Swdenk 
3301411fb37SFabio Estevam /* Reused from common.h */
3311411fb37SFabio Estevam #define ROUND(a, b)		(((a) + (b) - 1) & ~((b) - 1))
3321411fb37SFabio Estevam 
3335b1d7137Swdenk /*
3349a4daad0SMarian Balakowicz  * Legacy format image header,
3359a4daad0SMarian Balakowicz  * all data in network byte order (aka natural aka bigendian).
3365b1d7137Swdenk  */
3375b1d7137Swdenk typedef struct image_header {
3382f220500SKim Phillips 	__be32		ih_magic;	/* Image Header Magic Number	*/
3392f220500SKim Phillips 	__be32		ih_hcrc;	/* Image Header CRC Checksum	*/
3402f220500SKim Phillips 	__be32		ih_time;	/* Image Creation Timestamp	*/
3412f220500SKim Phillips 	__be32		ih_size;	/* Image Data Size		*/
3422f220500SKim Phillips 	__be32		ih_load;	/* Data	 Load  Address		*/
3432f220500SKim Phillips 	__be32		ih_ep;		/* Entry Point Address		*/
3442f220500SKim Phillips 	__be32		ih_dcrc;	/* Image Data CRC Checksum	*/
3455b1d7137Swdenk 	uint8_t		ih_os;		/* Operating System		*/
3465b1d7137Swdenk 	uint8_t		ih_arch;	/* CPU architecture		*/
3475b1d7137Swdenk 	uint8_t		ih_type;	/* Image Type			*/
3485b1d7137Swdenk 	uint8_t		ih_comp;	/* Compression Type		*/
3495b1d7137Swdenk 	uint8_t		ih_name[IH_NMLEN];	/* Image Name		*/
3505b1d7137Swdenk } image_header_t;
3515b1d7137Swdenk 
352396f635bSKumar Gala typedef struct image_info {
353396f635bSKumar Gala 	ulong		start, end;		/* start/end of blob */
354396f635bSKumar Gala 	ulong		image_start, image_len; /* start of image within blob, len of image */
355396f635bSKumar Gala 	ulong		load;			/* load addr for the image */
356396f635bSKumar Gala 	uint8_t		comp, type, os;		/* compression, type of image, os type */
35790268b87SSimon Glass 	uint8_t		arch;			/* CPU architecture */
358396f635bSKumar Gala } image_info_t;
359396f635bSKumar Gala 
360559316faSMarian Balakowicz /*
361d5934ad7SMarian Balakowicz  * Legacy and FIT format headers used by do_bootm() and do_bootm_<os>()
362d5934ad7SMarian Balakowicz  * routines.
363d5934ad7SMarian Balakowicz  */
364d5934ad7SMarian Balakowicz typedef struct bootm_headers {
365d5934ad7SMarian Balakowicz 	/*
366d5934ad7SMarian Balakowicz 	 * Legacy os image header, if it is a multi component image
3679a4daad0SMarian Balakowicz 	 * then boot_get_ramdisk() and get_fdt() will attempt to get
368d5934ad7SMarian Balakowicz 	 * data from second and third component accordingly.
369d5934ad7SMarian Balakowicz 	 */
370cb1c4896SMarian Balakowicz 	image_header_t	*legacy_hdr_os;		/* image header pointer */
371cb1c4896SMarian Balakowicz 	image_header_t	legacy_hdr_os_copy;	/* header copy */
372d5934ad7SMarian Balakowicz 	ulong		legacy_hdr_valid;
373d5934ad7SMarian Balakowicz 
37473223f0eSSimon Glass #if IMAGE_ENABLE_FIT
375f773bea8SMarian Balakowicz 	const char	*fit_uname_cfg;	/* configuration node unit name */
376f773bea8SMarian Balakowicz 
377d5934ad7SMarian Balakowicz 	void		*fit_hdr_os;	/* os FIT image header */
378eb6175edSMarian Balakowicz 	const char	*fit_uname_os;	/* os subimage node unit name */
3793dfe1101SMarian Balakowicz 	int		fit_noffset_os;	/* os subimage node offset */
380d5934ad7SMarian Balakowicz 
381d5934ad7SMarian Balakowicz 	void		*fit_hdr_rd;	/* init ramdisk FIT image header */
3823dfe1101SMarian Balakowicz 	const char	*fit_uname_rd;	/* init ramdisk subimage node unit name */
3833dfe1101SMarian Balakowicz 	int		fit_noffset_rd;	/* init ramdisk subimage node offset */
384d5934ad7SMarian Balakowicz 
385d5934ad7SMarian Balakowicz 	void		*fit_hdr_fdt;	/* FDT blob FIT image header */
3863dfe1101SMarian Balakowicz 	const char	*fit_uname_fdt;	/* FDT blob subimage node unit name */
3873dfe1101SMarian Balakowicz 	int		fit_noffset_fdt;/* FDT blob subimage node offset */
38890268b87SSimon Glass 
38990268b87SSimon Glass 	void		*fit_hdr_setup;	/* x86 setup FIT image header */
39090268b87SSimon Glass 	const char	*fit_uname_setup; /* x86 setup subimage node name */
39190268b87SSimon Glass 	int		fit_noffset_setup;/* x86 setup subimage node offset */
392d5934ad7SMarian Balakowicz #endif
3931ec73761SMarian Balakowicz 
39449c3a861SKumar Gala #ifndef USE_HOSTCC
395396f635bSKumar Gala 	image_info_t	os;		/* os image info */
396c160a954SKumar Gala 	ulong		ep;		/* entry point of OS */
397c160a954SKumar Gala 
398c4f9419cSKumar Gala 	ulong		rd_start, rd_end;/* ramdisk start/end */
399c4f9419cSKumar Gala 
40006a09918SKumar Gala 	char		*ft_addr;	/* flat dev tree address */
40106a09918SKumar Gala 	ulong		ft_len;		/* length of flat device tree */
40206a09918SKumar Gala 
40349c3a861SKumar Gala 	ulong		initrd_start;
40449c3a861SKumar Gala 	ulong		initrd_end;
40549c3a861SKumar Gala 	ulong		cmdline_start;
40649c3a861SKumar Gala 	ulong		cmdline_end;
40749c3a861SKumar Gala 	bd_t		*kbd;
40849c3a861SKumar Gala #endif
40949c3a861SKumar Gala 
41000caae6dSSimon Glass 	int		verify;		/* env_get("verify")[0] != 'n' */
41149c3a861SKumar Gala 
41249c3a861SKumar Gala #define	BOOTM_STATE_START	(0x00000001)
41335fc84faSSimon Glass #define	BOOTM_STATE_FINDOS	(0x00000002)
41435fc84faSSimon Glass #define	BOOTM_STATE_FINDOTHER	(0x00000004)
41535fc84faSSimon Glass #define	BOOTM_STATE_LOADOS	(0x00000008)
41635fc84faSSimon Glass #define	BOOTM_STATE_RAMDISK	(0x00000010)
41735fc84faSSimon Glass #define	BOOTM_STATE_FDT		(0x00000020)
41835fc84faSSimon Glass #define	BOOTM_STATE_OS_CMDLINE	(0x00000040)
41935fc84faSSimon Glass #define	BOOTM_STATE_OS_BD_T	(0x00000080)
42035fc84faSSimon Glass #define	BOOTM_STATE_OS_PREP	(0x00000100)
421d0ae31ebSSimon Glass #define	BOOTM_STATE_OS_FAKE_GO	(0x00000200)	/* 'Almost' run the OS */
422d0ae31ebSSimon Glass #define	BOOTM_STATE_OS_GO	(0x00000400)
423*06499e6bSEddie James #define BOOTM_STATE_MEASURE	(0x00001000)
42449c3a861SKumar Gala 	int		state;
42549c3a861SKumar Gala 
426a16028daSMike Frysinger #ifdef CONFIG_LMB
427e906cfaeSKumar Gala 	struct lmb	lmb;		/* for memory mgmt */
428e906cfaeSKumar Gala #endif
429d5934ad7SMarian Balakowicz } bootm_headers_t;
430d5934ad7SMarian Balakowicz 
4311648a375SSimon Schwarz extern bootm_headers_t images;
4321648a375SSimon Schwarz 
433d5934ad7SMarian Balakowicz /*
434559316faSMarian Balakowicz  * Some systems (for example LWMON) have very short watchdog periods;
435559316faSMarian Balakowicz  * we must make sure to split long operations like memmove() or
4367590378fSBartlomiej Sieka  * checksum calculations into reasonable chunks.
437559316faSMarian Balakowicz  */
4387590378fSBartlomiej Sieka #ifndef CHUNKSZ
439559316faSMarian Balakowicz #define CHUNKSZ (64 * 1024)
4407590378fSBartlomiej Sieka #endif
4417590378fSBartlomiej Sieka 
4427590378fSBartlomiej Sieka #ifndef CHUNKSZ_CRC32
4437590378fSBartlomiej Sieka #define CHUNKSZ_CRC32 (64 * 1024)
4447590378fSBartlomiej Sieka #endif
4457590378fSBartlomiej Sieka 
4467590378fSBartlomiej Sieka #ifndef CHUNKSZ_MD5
4477590378fSBartlomiej Sieka #define CHUNKSZ_MD5 (64 * 1024)
4487590378fSBartlomiej Sieka #endif
4497590378fSBartlomiej Sieka 
4507590378fSBartlomiej Sieka #ifndef CHUNKSZ_SHA1
4517590378fSBartlomiej Sieka #define CHUNKSZ_SHA1 (64 * 1024)
4527590378fSBartlomiej Sieka #endif
453559316faSMarian Balakowicz 
45437566090SMike Frysinger #define uimage_to_cpu(x)		be32_to_cpu(x)
45537566090SMike Frysinger #define cpu_to_uimage(x)		cpu_to_be32(x)
456b97a2a0aSMarian Balakowicz 
457b029dddcSPrafulla Wadaskar /*
458b029dddcSPrafulla Wadaskar  * Translation table for entries of a specific type; used by
459b029dddcSPrafulla Wadaskar  * get_table_entry_id() and get_table_entry_name().
460b029dddcSPrafulla Wadaskar  */
461b029dddcSPrafulla Wadaskar typedef struct table_entry {
462b029dddcSPrafulla Wadaskar 	int	id;
463b029dddcSPrafulla Wadaskar 	char	*sname;		/* short (input) name to find table entry */
464b029dddcSPrafulla Wadaskar 	char	*lname;		/* long (output) name to print for messages */
465b029dddcSPrafulla Wadaskar } table_entry_t;
466b029dddcSPrafulla Wadaskar 
467b029dddcSPrafulla Wadaskar /*
468b029dddcSPrafulla Wadaskar  * get_table_entry_id() scans the translation table trying to find an
469b029dddcSPrafulla Wadaskar  * entry that matches the given short name. If a matching entry is
470b029dddcSPrafulla Wadaskar  * found, it's id is returned to the caller.
471b029dddcSPrafulla Wadaskar  */
4727edb186fSMike Frysinger int get_table_entry_id(const table_entry_t *table,
473b029dddcSPrafulla Wadaskar 		const char *table_name, const char *name);
474b029dddcSPrafulla Wadaskar /*
475b029dddcSPrafulla Wadaskar  * get_table_entry_name() scans the translation table trying to find
476b029dddcSPrafulla Wadaskar  * an entry that matches the given id. If a matching entry is found,
477b029dddcSPrafulla Wadaskar  * its long name is returned to the caller.
478b029dddcSPrafulla Wadaskar  */
4797edb186fSMike Frysinger char *get_table_entry_name(const table_entry_t *table, char *msg, int id);
480b029dddcSPrafulla Wadaskar 
481570abb0aSMarian Balakowicz const char *genimg_get_os_name(uint8_t os);
482cef2e514SSimon Glass 
483cef2e514SSimon Glass /**
484cef2e514SSimon Glass  * genimg_get_os_short_name() - get the short name for an OS
485cef2e514SSimon Glass  *
486cef2e514SSimon Glass  * @param os	OS (IH_OS_...)
487cef2e514SSimon Glass  * @return OS short name, or "unknown" if unknown
488cef2e514SSimon Glass  */
489cef2e514SSimon Glass const char *genimg_get_os_short_name(uint8_t comp);
490cef2e514SSimon Glass 
491570abb0aSMarian Balakowicz const char *genimg_get_arch_name(uint8_t arch);
492cef2e514SSimon Glass 
493cef2e514SSimon Glass /**
494cef2e514SSimon Glass  * genimg_get_arch_short_name() - get the short name for an architecture
495cef2e514SSimon Glass  *
496cef2e514SSimon Glass  * @param arch	Architecture type (IH_ARCH_...)
497cef2e514SSimon Glass  * @return architecture short name, or "unknown" if unknown
498cef2e514SSimon Glass  */
499cef2e514SSimon Glass const char *genimg_get_arch_short_name(uint8_t arch);
500cef2e514SSimon Glass 
501570abb0aSMarian Balakowicz const char *genimg_get_type_name(uint8_t type);
5025b9d44dfSSimon Glass 
5035b9d44dfSSimon Glass /**
5045b9d44dfSSimon Glass  * genimg_get_type_short_name() - get the short name for an image type
5055b9d44dfSSimon Glass  *
5065b9d44dfSSimon Glass  * @param type	Image type (IH_TYPE_...)
5075b9d44dfSSimon Glass  * @return image short name, or "unknown" if unknown
5085b9d44dfSSimon Glass  */
5095b9d44dfSSimon Glass const char *genimg_get_type_short_name(uint8_t type);
5105b9d44dfSSimon Glass 
511570abb0aSMarian Balakowicz const char *genimg_get_comp_name(uint8_t comp);
512cef2e514SSimon Glass 
513cef2e514SSimon Glass /**
514cef2e514SSimon Glass  * genimg_get_comp_short_name() - get the short name for a compression method
515cef2e514SSimon Glass  *
516cef2e514SSimon Glass  * @param comp	compression method (IH_COMP_...)
517cef2e514SSimon Glass  * @return compression method short name, or "unknown" if unknown
518cef2e514SSimon Glass  */
519cef2e514SSimon Glass const char *genimg_get_comp_short_name(uint8_t comp);
520cef2e514SSimon Glass 
5211426220bSSimon Glass /**
5221426220bSSimon Glass  * genimg_get_cat_name() - Get the name of an item in a category
5231426220bSSimon Glass  *
5241426220bSSimon Glass  * @category:	Category of item
5251426220bSSimon Glass  * @id:		Item ID
5261426220bSSimon Glass  * @return name of item, or "Unknown ..." if unknown
5271426220bSSimon Glass  */
5281426220bSSimon Glass const char *genimg_get_cat_name(enum ih_category category, uint id);
5291426220bSSimon Glass 
5301426220bSSimon Glass /**
5311426220bSSimon Glass  * genimg_get_cat_short_name() - Get the short name of an item in a category
5321426220bSSimon Glass  *
5331426220bSSimon Glass  * @category:	Category of item
5341426220bSSimon Glass  * @id:		Item ID
5351426220bSSimon Glass  * @return short name of item, or "Unknown ..." if unknown
5361426220bSSimon Glass  */
5371426220bSSimon Glass const char *genimg_get_cat_short_name(enum ih_category category, uint id);
5381426220bSSimon Glass 
5391426220bSSimon Glass /**
5401426220bSSimon Glass  * genimg_get_cat_count() - Get the number of items in a category
5411426220bSSimon Glass  *
5421426220bSSimon Glass  * @category:	Category to check
5431426220bSSimon Glass  * @return the number of items in the category (IH_xxx_COUNT)
5441426220bSSimon Glass  */
5451426220bSSimon Glass int genimg_get_cat_count(enum ih_category category);
5461426220bSSimon Glass 
5471426220bSSimon Glass /**
5481426220bSSimon Glass  * genimg_get_cat_desc() - Get the description of a category
5491426220bSSimon Glass  *
5501426220bSSimon Glass  * @return the description of a category, e.g. "architecture". This
5511426220bSSimon Glass  * effectively converts the enum to a string.
5521426220bSSimon Glass  */
5531426220bSSimon Glass const char *genimg_get_cat_desc(enum ih_category category);
5541426220bSSimon Glass 
555570abb0aSMarian Balakowicz int genimg_get_os_id(const char *name);
556570abb0aSMarian Balakowicz int genimg_get_arch_id(const char *name);
557570abb0aSMarian Balakowicz int genimg_get_type_id(const char *name);
558570abb0aSMarian Balakowicz int genimg_get_comp_id(const char *name);
559f666dea8SPrafulla Wadaskar void genimg_print_size(uint32_t size);
560570abb0aSMarian Balakowicz 
561859e92b7SSimon Glass #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || \
562859e92b7SSimon Glass 	defined(USE_HOSTCC)
563859e92b7SSimon Glass #define IMAGE_ENABLE_TIMESTAMP 1
564859e92b7SSimon Glass #else
565859e92b7SSimon Glass #define IMAGE_ENABLE_TIMESTAMP 0
566859e92b7SSimon Glass #endif
567859e92b7SSimon Glass void genimg_print_time(time_t timestamp);
568859e92b7SSimon Glass 
569782cfbb2SSimon Glass /* What to do with a image load address ('load = <> 'in the FIT) */
570782cfbb2SSimon Glass enum fit_load_op {
571782cfbb2SSimon Glass 	FIT_LOAD_IGNORED,	/* Ignore load address */
572782cfbb2SSimon Glass 	FIT_LOAD_OPTIONAL,	/* Can be provided, but optional */
573fe20a81aSSimon Glass 	FIT_LOAD_OPTIONAL_NON_ZERO,	/* Optional, a value of 0 is ignored */
574782cfbb2SSimon Glass 	FIT_LOAD_REQUIRED,	/* Must be provided */
575782cfbb2SSimon Glass };
576782cfbb2SSimon Glass 
57790268b87SSimon Glass int boot_get_setup(bootm_headers_t *images, uint8_t arch, ulong *setup_start,
57890268b87SSimon Glass 		   ulong *setup_len);
57990268b87SSimon Glass 
5809a4daad0SMarian Balakowicz #ifndef USE_HOSTCC
5819a4daad0SMarian Balakowicz /* Image format types, returned by _get_format() routine */
5829a4daad0SMarian Balakowicz #define IMAGE_FORMAT_INVALID	0x00
58321d29f7fSHeiko Schocher #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
5849a4daad0SMarian Balakowicz #define IMAGE_FORMAT_LEGACY	0x01	/* legacy image_header based format */
58521d29f7fSHeiko Schocher #endif
5869a4daad0SMarian Balakowicz #define IMAGE_FORMAT_FIT	0x02	/* new, libfdt based format */
5879ace3fc8SSebastian Siewior #define IMAGE_FORMAT_ANDROID	0x03	/* Android boot image */
5889a4daad0SMarian Balakowicz 
5896c454fedSBryan Wu ulong genimg_get_kernel_addr_fit(char * const img_addr,
5906c454fedSBryan Wu 			         const char **fit_uname_config,
5916c454fedSBryan Wu 			         const char **fit_uname_kernel);
5920f64140bSBryan Wu ulong genimg_get_kernel_addr(char * const img_addr);
59335e7b0f1SSimon Glass int genimg_get_format(const void *img_addr);
594f773bea8SMarian Balakowicz int genimg_has_config(bootm_headers_t *images);
5959a4daad0SMarian Balakowicz 
59662afc601SMichal Simek int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
59762afc601SMichal Simek 		uint8_t arch, const ulong *ld_start, ulong * const ld_len);
59854841ab5SWolfgang Denk int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
599d985c849SMarian Balakowicz 		uint8_t arch, ulong *rd_start, ulong *rd_end);
60084a07dbfSKarl Apsite 
60184a07dbfSKarl Apsite /**
60284a07dbfSKarl Apsite  * boot_get_loadable - routine to load a list of binaries to memory
60384a07dbfSKarl Apsite  * @argc: Ignored Argument
60484a07dbfSKarl Apsite  * @argv: Ignored Argument
60584a07dbfSKarl Apsite  * @images: pointer to the bootm images structure
60684a07dbfSKarl Apsite  * @arch: expected architecture for the image
60784a07dbfSKarl Apsite  * @ld_start: Ignored Argument
60884a07dbfSKarl Apsite  * @ld_len: Ignored Argument
60984a07dbfSKarl Apsite  *
61084a07dbfSKarl Apsite  * boot_get_loadable() will take the given FIT configuration, and look
61184a07dbfSKarl Apsite  * for a field named "loadables".  Loadables, is a list of elements in
61284a07dbfSKarl Apsite  * the FIT given as strings.  exe:
613b2267e8aSAndre Przywara  *   loadables = "linux_kernel", "fdt-2";
61484a07dbfSKarl Apsite  * this function will attempt to parse each string, and load the
61584a07dbfSKarl Apsite  * corresponding element from the FIT into memory.  Once placed,
61684a07dbfSKarl Apsite  * no aditional actions are taken.
61784a07dbfSKarl Apsite  *
61884a07dbfSKarl Apsite  * @return:
61984a07dbfSKarl Apsite  *     0, if only valid images or no images are found
62084a07dbfSKarl Apsite  *     error code, if an error occurs during fit_image_load
62184a07dbfSKarl Apsite  */
62284a07dbfSKarl Apsite int boot_get_loadable(int argc, char * const argv[], bootm_headers_t *images,
62384a07dbfSKarl Apsite 		uint8_t arch, const ulong *ld_start, ulong * const ld_len);
62484a07dbfSKarl Apsite #endif /* !USE_HOSTCC */
6259a4daad0SMarian Balakowicz 
62690268b87SSimon Glass int boot_get_setup_fit(bootm_headers_t *images, uint8_t arch,
62790268b87SSimon Glass 		       ulong *setup_start, ulong *setup_len);
62890268b87SSimon Glass 
629782cfbb2SSimon Glass /**
630169043d8SPantelis Antoniou  * boot_get_fdt_fit() - load a DTB from a FIT file (applying overlays)
631169043d8SPantelis Antoniou  *
632169043d8SPantelis Antoniou  * This deals with all aspects of loading an DTB from a FIT.
633169043d8SPantelis Antoniou  * The correct base image based on configuration will be selected, and
634169043d8SPantelis Antoniou  * then any overlays specified will be applied (as present in fit_uname_configp).
635169043d8SPantelis Antoniou  *
636169043d8SPantelis Antoniou  * @param images	Boot images structure
637169043d8SPantelis Antoniou  * @param addr		Address of FIT in memory
638169043d8SPantelis Antoniou  * @param fit_unamep	On entry this is the requested image name
639b2267e8aSAndre Przywara  *			(e.g. "kernel") or NULL to use the default. On exit
640169043d8SPantelis Antoniou  *			points to the selected image name
641169043d8SPantelis Antoniou  * @param fit_uname_configp	On entry this is the requested configuration
642b2267e8aSAndre Przywara  *			name (e.g. "conf-1") or NULL to use the default. On
643169043d8SPantelis Antoniou  *			exit points to the selected configuration name.
644169043d8SPantelis Antoniou  * @param arch		Expected architecture (IH_ARCH_...)
645169043d8SPantelis Antoniou  * @param datap		Returns address of loaded image
646169043d8SPantelis Antoniou  * @param lenp		Returns length of loaded image
647169043d8SPantelis Antoniou  *
648169043d8SPantelis Antoniou  * @return node offset of base image, or -ve error code on error
649169043d8SPantelis Antoniou  */
650169043d8SPantelis Antoniou int boot_get_fdt_fit(bootm_headers_t *images, ulong addr,
651169043d8SPantelis Antoniou 		   const char **fit_unamep, const char **fit_uname_configp,
652169043d8SPantelis Antoniou 		   int arch, ulong *datap, ulong *lenp);
653169043d8SPantelis Antoniou 
654169043d8SPantelis Antoniou /**
655782cfbb2SSimon Glass  * fit_image_load() - load an image from a FIT
656782cfbb2SSimon Glass  *
657782cfbb2SSimon Glass  * This deals with all aspects of loading an image from a FIT, including
658782cfbb2SSimon Glass  * selecting the right image based on configuration, verifying it, printing
659782cfbb2SSimon Glass  * out progress messages, checking the type/arch/os and optionally copying it
660782cfbb2SSimon Glass  * to the right load address.
661782cfbb2SSimon Glass  *
662126cc864SSimon Glass  * The property to look up is defined by image_type.
663126cc864SSimon Glass  *
664782cfbb2SSimon Glass  * @param images	Boot images structure
665782cfbb2SSimon Glass  * @param addr		Address of FIT in memory
666782cfbb2SSimon Glass  * @param fit_unamep	On entry this is the requested image name
667b2267e8aSAndre Przywara  *			(e.g. "kernel") or NULL to use the default. On exit
668782cfbb2SSimon Glass  *			points to the selected image name
669f320a4d8SSimon Glass  * @param fit_uname_configp	On entry this is the requested configuration
670b2267e8aSAndre Przywara  *			name (e.g. "conf-1") or NULL to use the default. On
671f320a4d8SSimon Glass  *			exit points to the selected configuration name.
672782cfbb2SSimon Glass  * @param arch		Expected architecture (IH_ARCH_...)
673782cfbb2SSimon Glass  * @param image_type	Required image type (IH_TYPE_...). If this is
674782cfbb2SSimon Glass  *			IH_TYPE_KERNEL then we allow IH_TYPE_KERNEL_NOLOAD
675782cfbb2SSimon Glass  *			also.
676782cfbb2SSimon Glass  * @param bootstage_id	ID of starting bootstage to use for progress updates.
677782cfbb2SSimon Glass  *			This will be added to the BOOTSTAGE_SUB values when
678782cfbb2SSimon Glass  *			calling bootstage_mark()
679782cfbb2SSimon Glass  * @param load_op	Decribes what to do with the load address
680782cfbb2SSimon Glass  * @param datap		Returns address of loaded image
681782cfbb2SSimon Glass  * @param lenp		Returns length of loaded image
682ce1400f6SSimon Glass  * @return node offset of image, or -ve error code on error
683782cfbb2SSimon Glass  */
684126cc864SSimon Glass int fit_image_load(bootm_headers_t *images, ulong addr,
685f320a4d8SSimon Glass 		   const char **fit_unamep, const char **fit_uname_configp,
686782cfbb2SSimon Glass 		   int arch, int image_type, int bootstage_id,
687782cfbb2SSimon Glass 		   enum fit_load_op load_op, ulong *datap, ulong *lenp);
688782cfbb2SSimon Glass 
689ce1400f6SSimon Glass #ifndef USE_HOSTCC
690782cfbb2SSimon Glass /**
691782cfbb2SSimon Glass  * fit_get_node_from_config() - Look up an image a FIT by type
692782cfbb2SSimon Glass  *
693b2267e8aSAndre Przywara  * This looks in the selected conf- node (images->fit_uname_cfg) for a
694782cfbb2SSimon Glass  * particular image type (e.g. "kernel") and then finds the image that is
695782cfbb2SSimon Glass  * referred to.
696782cfbb2SSimon Glass  *
697782cfbb2SSimon Glass  * For example, for something like:
698782cfbb2SSimon Glass  *
699782cfbb2SSimon Glass  * images {
700b2267e8aSAndre Przywara  *	kernel {
701782cfbb2SSimon Glass  *		...
702782cfbb2SSimon Glass  *	};
703782cfbb2SSimon Glass  * };
704782cfbb2SSimon Glass  * configurations {
705b2267e8aSAndre Przywara  *	conf-1 {
706b2267e8aSAndre Przywara  *		kernel = "kernel";
707782cfbb2SSimon Glass  *	};
708782cfbb2SSimon Glass  * };
709782cfbb2SSimon Glass  *
710782cfbb2SSimon Glass  * the function will return the node offset of the kernel@1 node, assuming
711b2267e8aSAndre Przywara  * that conf-1 is the chosen configuration.
712782cfbb2SSimon Glass  *
713782cfbb2SSimon Glass  * @param images	Boot images structure
714782cfbb2SSimon Glass  * @param prop_name	Property name to look up (FIT_..._PROP)
715782cfbb2SSimon Glass  * @param addr		Address of FIT in memory
716782cfbb2SSimon Glass  */
717782cfbb2SSimon Glass int fit_get_node_from_config(bootm_headers_t *images, const char *prop_name,
718782cfbb2SSimon Glass 			ulong addr);
719782cfbb2SSimon Glass 
72053f375faSSimon Glass int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
72153f375faSSimon Glass 		 bootm_headers_t *images,
72253f375faSSimon Glass 		 char **of_flat_tree, ulong *of_size);
72355b0a393SGrant Likely void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob);
724590d3cacSGrant Likely int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size);
72506a09918SKumar Gala 
7269a4daad0SMarian Balakowicz int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len,
7279a4daad0SMarian Balakowicz 		  ulong *initrd_start, ulong *initrd_end);
728590d3cacSGrant Likely int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end);
729fca43cc8SJohn Rigby #ifdef CONFIG_SYS_BOOT_GET_KBD
730590d3cacSGrant Likely int boot_get_kbd(struct lmb *lmb, bd_t **kbd);
731fca43cc8SJohn Rigby #endif /* CONFIG_SYS_BOOT_GET_KBD */
732570abb0aSMarian Balakowicz #endif /* !USE_HOSTCC */
7339a4daad0SMarian Balakowicz 
7349a4daad0SMarian Balakowicz /*******************************************************************/
7359a4daad0SMarian Balakowicz /* Legacy format specific code (prefixed with image_) */
7369a4daad0SMarian Balakowicz /*******************************************************************/
image_get_header_size(void)737b97a2a0aSMarian Balakowicz static inline uint32_t image_get_header_size(void)
738b97a2a0aSMarian Balakowicz {
739b97a2a0aSMarian Balakowicz 	return (sizeof(image_header_t));
740b97a2a0aSMarian Balakowicz }
741b97a2a0aSMarian Balakowicz 
742b97a2a0aSMarian Balakowicz #define image_get_hdr_l(f) \
7433a2003f6SWolfgang Denk 	static inline uint32_t image_get_##f(const image_header_t *hdr) \
744b97a2a0aSMarian Balakowicz 	{ \
7459a4daad0SMarian Balakowicz 		return uimage_to_cpu(hdr->ih_##f); \
746b97a2a0aSMarian Balakowicz 	}
747178e26d7SWolfgang Denk image_get_hdr_l(magic)		/* image_get_magic */
image_get_hdr_l(hcrc)748178e26d7SWolfgang Denk image_get_hdr_l(hcrc)		/* image_get_hcrc */
749178e26d7SWolfgang Denk image_get_hdr_l(time)		/* image_get_time */
750178e26d7SWolfgang Denk image_get_hdr_l(size)		/* image_get_size */
751178e26d7SWolfgang Denk image_get_hdr_l(load)		/* image_get_load */
752178e26d7SWolfgang Denk image_get_hdr_l(ep)		/* image_get_ep */
753178e26d7SWolfgang Denk image_get_hdr_l(dcrc)		/* image_get_dcrc */
754b97a2a0aSMarian Balakowicz 
755b97a2a0aSMarian Balakowicz #define image_get_hdr_b(f) \
7563a2003f6SWolfgang Denk 	static inline uint8_t image_get_##f(const image_header_t *hdr) \
757b97a2a0aSMarian Balakowicz 	{ \
758b97a2a0aSMarian Balakowicz 		return hdr->ih_##f; \
759b97a2a0aSMarian Balakowicz 	}
760178e26d7SWolfgang Denk image_get_hdr_b(os)		/* image_get_os */
761178e26d7SWolfgang Denk image_get_hdr_b(arch)		/* image_get_arch */
762178e26d7SWolfgang Denk image_get_hdr_b(type)		/* image_get_type */
763178e26d7SWolfgang Denk image_get_hdr_b(comp)		/* image_get_comp */
764b97a2a0aSMarian Balakowicz 
7653a2003f6SWolfgang Denk static inline char *image_get_name(const image_header_t *hdr)
766b97a2a0aSMarian Balakowicz {
767b97a2a0aSMarian Balakowicz 	return (char *)hdr->ih_name;
768b97a2a0aSMarian Balakowicz }
769b97a2a0aSMarian Balakowicz 
image_get_data_size(const image_header_t * hdr)7703a2003f6SWolfgang Denk static inline uint32_t image_get_data_size(const image_header_t *hdr)
771b97a2a0aSMarian Balakowicz {
772b97a2a0aSMarian Balakowicz 	return image_get_size(hdr);
773b97a2a0aSMarian Balakowicz }
774f13e7b2eSMarian Balakowicz 
775f13e7b2eSMarian Balakowicz /**
776f13e7b2eSMarian Balakowicz  * image_get_data - get image payload start address
777f13e7b2eSMarian Balakowicz  * @hdr: image header
778f13e7b2eSMarian Balakowicz  *
779f13e7b2eSMarian Balakowicz  * image_get_data() returns address of the image payload. For single
780f13e7b2eSMarian Balakowicz  * component images it is image data start. For multi component
781f13e7b2eSMarian Balakowicz  * images it points to the null terminated table of sub-images sizes.
782f13e7b2eSMarian Balakowicz  *
783f13e7b2eSMarian Balakowicz  * returns:
784f13e7b2eSMarian Balakowicz  *     image payload data start address
785f13e7b2eSMarian Balakowicz  */
image_get_data(const image_header_t * hdr)7863a2003f6SWolfgang Denk static inline ulong image_get_data(const image_header_t *hdr)
787f13e7b2eSMarian Balakowicz {
788f13e7b2eSMarian Balakowicz 	return ((ulong)hdr + image_get_header_size());
789f13e7b2eSMarian Balakowicz }
790f13e7b2eSMarian Balakowicz 
image_get_image_size(const image_header_t * hdr)7913a2003f6SWolfgang Denk static inline uint32_t image_get_image_size(const image_header_t *hdr)
792b97a2a0aSMarian Balakowicz {
793b97a2a0aSMarian Balakowicz 	return (image_get_size(hdr) + image_get_header_size());
794b97a2a0aSMarian Balakowicz }
image_get_image_end(const image_header_t * hdr)7953a2003f6SWolfgang Denk static inline ulong image_get_image_end(const image_header_t *hdr)
796b97a2a0aSMarian Balakowicz {
797f13e7b2eSMarian Balakowicz 	return ((ulong)hdr + image_get_image_size(hdr));
798b97a2a0aSMarian Balakowicz }
799b97a2a0aSMarian Balakowicz 
800b97a2a0aSMarian Balakowicz #define image_set_hdr_l(f) \
801b97a2a0aSMarian Balakowicz 	static inline void image_set_##f(image_header_t *hdr, uint32_t val) \
802b97a2a0aSMarian Balakowicz 	{ \
8039a4daad0SMarian Balakowicz 		hdr->ih_##f = cpu_to_uimage(val); \
804b97a2a0aSMarian Balakowicz 	}
805178e26d7SWolfgang Denk image_set_hdr_l(magic)		/* image_set_magic */
image_set_hdr_l(hcrc)806178e26d7SWolfgang Denk image_set_hdr_l(hcrc)		/* image_set_hcrc */
807178e26d7SWolfgang Denk image_set_hdr_l(time)		/* image_set_time */
808178e26d7SWolfgang Denk image_set_hdr_l(size)		/* image_set_size */
809178e26d7SWolfgang Denk image_set_hdr_l(load)		/* image_set_load */
810178e26d7SWolfgang Denk image_set_hdr_l(ep)		/* image_set_ep */
811178e26d7SWolfgang Denk image_set_hdr_l(dcrc)		/* image_set_dcrc */
812b97a2a0aSMarian Balakowicz 
813b97a2a0aSMarian Balakowicz #define image_set_hdr_b(f) \
814b97a2a0aSMarian Balakowicz 	static inline void image_set_##f(image_header_t *hdr, uint8_t val) \
815b97a2a0aSMarian Balakowicz 	{ \
816b97a2a0aSMarian Balakowicz 		hdr->ih_##f = val; \
817b97a2a0aSMarian Balakowicz 	}
818178e26d7SWolfgang Denk image_set_hdr_b(os)		/* image_set_os */
819178e26d7SWolfgang Denk image_set_hdr_b(arch)		/* image_set_arch */
820178e26d7SWolfgang Denk image_set_hdr_b(type)		/* image_set_type */
821178e26d7SWolfgang Denk image_set_hdr_b(comp)		/* image_set_comp */
822b97a2a0aSMarian Balakowicz 
823b97a2a0aSMarian Balakowicz static inline void image_set_name(image_header_t *hdr, const char *name)
824b97a2a0aSMarian Balakowicz {
82516cdd95aSSimon Glass 	/*
82616cdd95aSSimon Glass 	 * This is equivalent to: strncpy(image_get_name(hdr), name, IH_NMLEN);
82716cdd95aSSimon Glass 	 *
82816cdd95aSSimon Glass 	 * Use the tortured code below to avoid a warning with gcc 12. We do not
82916cdd95aSSimon Glass 	 * want to include a nul terminator if the name is of length IH_NMLEN
83016cdd95aSSimon Glass 	 */
83116cdd95aSSimon Glass 	memcpy(image_get_name(hdr), name, strnlen(name, IH_NMLEN));
832b97a2a0aSMarian Balakowicz }
833b97a2a0aSMarian Balakowicz 
8343a2003f6SWolfgang Denk int image_check_hcrc(const image_header_t *hdr);
8353a2003f6SWolfgang Denk int image_check_dcrc(const image_header_t *hdr);
836af13cdbcSMarian Balakowicz #ifndef USE_HOSTCC
837723806ccSSimon Glass ulong env_get_bootm_low(void);
838723806ccSSimon Glass phys_size_t env_get_bootm_size(void);
839723806ccSSimon Glass phys_size_t env_get_bootm_mapsize(void);
840af13cdbcSMarian Balakowicz #endif
841ce1400f6SSimon Glass void memmove_wd(void *to, void *from, size_t len, ulong chunksz);
842b97a2a0aSMarian Balakowicz 
image_check_magic(const image_header_t * hdr)8433a2003f6SWolfgang Denk static inline int image_check_magic(const image_header_t *hdr)
844b97a2a0aSMarian Balakowicz {
845b97a2a0aSMarian Balakowicz 	return (image_get_magic(hdr) == IH_MAGIC);
846b97a2a0aSMarian Balakowicz }
image_check_type(const image_header_t * hdr,uint8_t type)8473a2003f6SWolfgang Denk static inline int image_check_type(const image_header_t *hdr, uint8_t type)
848b97a2a0aSMarian Balakowicz {
849b97a2a0aSMarian Balakowicz 	return (image_get_type(hdr) == type);
850b97a2a0aSMarian Balakowicz }
image_check_arch(const image_header_t * hdr,uint8_t arch)8513a2003f6SWolfgang Denk static inline int image_check_arch(const image_header_t *hdr, uint8_t arch)
852b97a2a0aSMarian Balakowicz {
8534ac0a32eSAlison Wang 	return (image_get_arch(hdr) == arch) ||
8544ac0a32eSAlison Wang 		(image_get_arch(hdr) == IH_ARCH_ARM && arch == IH_ARCH_ARM64);
855b97a2a0aSMarian Balakowicz }
image_check_os(const image_header_t * hdr,uint8_t os)8563a2003f6SWolfgang Denk static inline int image_check_os(const image_header_t *hdr, uint8_t os)
857b97a2a0aSMarian Balakowicz {
858b97a2a0aSMarian Balakowicz 	return (image_get_os(hdr) == os);
859b97a2a0aSMarian Balakowicz }
860b97a2a0aSMarian Balakowicz 
8613a2003f6SWolfgang Denk ulong image_multi_count(const image_header_t *hdr);
8623a2003f6SWolfgang Denk void image_multi_getimg(const image_header_t *hdr, ulong idx,
86342b73e8eSMarian Balakowicz 			ulong *data, ulong *len);
86442b73e8eSMarian Balakowicz 
8653a2003f6SWolfgang Denk void image_print_contents(const void *hdr);
866570abb0aSMarian Balakowicz 
867b97a2a0aSMarian Balakowicz #ifndef USE_HOSTCC
image_check_target_arch(const image_header_t * hdr)8683a2003f6SWolfgang Denk static inline int image_check_target_arch(const image_header_t *hdr)
869b97a2a0aSMarian Balakowicz {
870476af299SMike Frysinger #ifndef IH_ARCH_DEFAULT
871476af299SMike Frysinger # error "please define IH_ARCH_DEFAULT in your arch asm/u-boot.h"
872b97a2a0aSMarian Balakowicz #endif
873476af299SMike Frysinger 	return image_check_arch(hdr, IH_ARCH_DEFAULT);
874b97a2a0aSMarian Balakowicz }
8755dfb5213SMarian Balakowicz #endif /* USE_HOSTCC */
8765b1d7137Swdenk 
87713d06981SSimon Glass /**
87813d06981SSimon Glass  * Set up properties in the FDT
87913d06981SSimon Glass  *
88013d06981SSimon Glass  * This sets up properties in the FDT that is to be passed to linux.
88113d06981SSimon Glass  *
88213d06981SSimon Glass  * @images:	Images information
88313d06981SSimon Glass  * @blob:	FDT to update
88413d06981SSimon Glass  * @of_size:	Size of the FDT
88513d06981SSimon Glass  * @lmb:	Points to logical memory block structure
88613d06981SSimon Glass  * @return 0 if ok, <0 on failure
88713d06981SSimon Glass  */
88813d06981SSimon Glass int image_setup_libfdt(bootm_headers_t *images, void *blob,
88913d06981SSimon Glass 		       int of_size, struct lmb *lmb);
89013d06981SSimon Glass 
89113d06981SSimon Glass /**
89213d06981SSimon Glass  * Set up the FDT to use for booting a kernel
89313d06981SSimon Glass  *
89413d06981SSimon Glass  * This performs ramdisk setup, sets up the FDT if required, and adds
89513d06981SSimon Glass  * paramters to the FDT if libfdt is available.
89613d06981SSimon Glass  *
89713d06981SSimon Glass  * @param images	Images information
89813d06981SSimon Glass  * @return 0 if ok, <0 on failure
89913d06981SSimon Glass  */
90013d06981SSimon Glass int image_setup_linux(bootm_headers_t *images);
90113d06981SSimon Glass 
902a5266d6bSSimon Glass /**
903a5266d6bSSimon Glass  * bootz_setup() - Extract stat and size of a Linux xImage
904a5266d6bSSimon Glass  *
905a5266d6bSSimon Glass  * @image: Address of image
906a5266d6bSSimon Glass  * @start: Returns start address of image
907a5266d6bSSimon Glass  * @end : Returns end address of image
908a5266d6bSSimon Glass  * @return 0 if OK, 1 if the image was not recognised
909a5266d6bSSimon Glass  */
910a5266d6bSSimon Glass int bootz_setup(ulong image, ulong *start, ulong *end);
911a5266d6bSSimon Glass 
9126808ef9aSBin Chen /**
9136808ef9aSBin Chen  * Return the correct start address and size of a Linux aarch64 Image.
9146808ef9aSBin Chen  *
9156808ef9aSBin Chen  * @image: Address of image
9166808ef9aSBin Chen  * @start: Returns start address of image
9176808ef9aSBin Chen  * @size : Returns size image
9187f13b374SMarek Vasut  * @force_reloc: Ignore image->ep field, always place image to RAM start
9196808ef9aSBin Chen  * @return 0 if OK, 1 if the image was not recognised
9206808ef9aSBin Chen  */
9217f13b374SMarek Vasut int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
9227f13b374SMarek Vasut 		bool force_reloc);
923a5266d6bSSimon Glass 
924d5934ad7SMarian Balakowicz /*******************************************************************/
9259a4daad0SMarian Balakowicz /* New uImage format specific code (prefixed with fit_) */
926d5934ad7SMarian Balakowicz /*******************************************************************/
9275dfb5213SMarian Balakowicz 
9285dfb5213SMarian Balakowicz #define FIT_IMAGES_PATH		"/images"
9295dfb5213SMarian Balakowicz #define FIT_CONFS_PATH		"/configurations"
9305dfb5213SMarian Balakowicz 
9313e569a6bSSimon Glass /* hash/signature node */
9325dfb5213SMarian Balakowicz #define FIT_HASH_NODENAME	"hash"
9335dfb5213SMarian Balakowicz #define FIT_ALGO_PROP		"algo"
9345dfb5213SMarian Balakowicz #define FIT_VALUE_PROP		"value"
9358ac88f2dSJoe Hershberger #define FIT_IGNORE_PROP		"uboot-ignore"
9363e569a6bSSimon Glass #define FIT_SIG_NODENAME	"signature"
9375dfb5213SMarian Balakowicz 
9385dfb5213SMarian Balakowicz /* image node */
9395dfb5213SMarian Balakowicz #define FIT_DATA_PROP		"data"
940a1be94b6SPeng Fan #define FIT_DATA_POSITION_PROP	"data-position"
941db1b79b8Stomas.melin@vaisala.com #define FIT_DATA_OFFSET_PROP	"data-offset"
942db1b79b8Stomas.melin@vaisala.com #define FIT_DATA_SIZE_PROP	"data-size"
9435dfb5213SMarian Balakowicz #define FIT_TIMESTAMP_PROP	"timestamp"
9445dfb5213SMarian Balakowicz #define FIT_DESC_PROP		"description"
9455dfb5213SMarian Balakowicz #define FIT_ARCH_PROP		"arch"
9465dfb5213SMarian Balakowicz #define FIT_TYPE_PROP		"type"
9475dfb5213SMarian Balakowicz #define FIT_OS_PROP		"os"
9485dfb5213SMarian Balakowicz #define FIT_COMP_PROP		"compression"
9495dfb5213SMarian Balakowicz #define FIT_ENTRY_PROP		"entry"
9505dfb5213SMarian Balakowicz #define FIT_LOAD_PROP		"load"
9515dfb5213SMarian Balakowicz 
9525dfb5213SMarian Balakowicz /* configuration node */
9535dfb5213SMarian Balakowicz #define FIT_KERNEL_PROP		"kernel"
9545dfb5213SMarian Balakowicz #define FIT_RAMDISK_PROP	"ramdisk"
9555dfb5213SMarian Balakowicz #define FIT_FDT_PROP		"fdt"
956ecf8cd65SKarl Apsite #define FIT_LOADABLE_PROP	"loadables"
9575dfb5213SMarian Balakowicz #define FIT_DEFAULT_PROP	"default"
95890268b87SSimon Glass #define FIT_SETUP_PROP		"setup"
959ed0cea7cSMichal Simek #define FIT_FPGA_PROP		"fpga"
9601f8e4bf5SMichal Simek #define FIT_FIRMWARE_PROP	"firmware"
9610298d203SMarek Vasut #define FIT_STANDALONE_PROP	"standalone"
9625dfb5213SMarian Balakowicz 
9631de7bb4fSMichael van der Westhuizen #define FIT_MAX_HASH_LEN	HASH_MAX_DIGEST_SIZE
9645dfb5213SMarian Balakowicz 
965f1dcee59SSimon Glass #if IMAGE_ENABLE_FIT
9665dfb5213SMarian Balakowicz /* cmdline argument format parsing */
967314f634bSMike Frysinger int fit_parse_conf(const char *spec, ulong addr_curr,
968f50433d6SMarian Balakowicz 		ulong *addr, const char **conf_name);
969314f634bSMike Frysinger int fit_parse_subimage(const char *spec, ulong addr_curr,
970f50433d6SMarian Balakowicz 		ulong *addr, const char **image_name);
971d5934ad7SMarian Balakowicz 
97239931f96SGuilherme Maciel Ferreira int fit_get_subimage_count(const void *fit, int images_noffset);
973edbed247SBartlomiej Sieka void fit_print_contents(const void *fit);
9745dfb5213SMarian Balakowicz void fit_image_print(const void *fit, int noffset, const char *p);
9755dfb5213SMarian Balakowicz 
9765dfb5213SMarian Balakowicz /**
9775dfb5213SMarian Balakowicz  * fit_get_end - get FIT image size
9785dfb5213SMarian Balakowicz  * @fit: pointer to the FIT format image header
9795dfb5213SMarian Balakowicz  *
9805dfb5213SMarian Balakowicz  * returns:
9815dfb5213SMarian Balakowicz  *     size of the FIT image (blob) in memory
9825dfb5213SMarian Balakowicz  */
fit_get_size(const void * fit)9835dfb5213SMarian Balakowicz static inline ulong fit_get_size(const void *fit)
9845dfb5213SMarian Balakowicz {
9855dfb5213SMarian Balakowicz 	return fdt_totalsize(fit);
9865dfb5213SMarian Balakowicz }
9875dfb5213SMarian Balakowicz 
9885dfb5213SMarian Balakowicz /**
9895dfb5213SMarian Balakowicz  * fit_get_end - get FIT image end
9905dfb5213SMarian Balakowicz  * @fit: pointer to the FIT format image header
9915dfb5213SMarian Balakowicz  *
9925dfb5213SMarian Balakowicz  * returns:
9935dfb5213SMarian Balakowicz  *     end address of the FIT image (blob) in memory
9945dfb5213SMarian Balakowicz  */
9957a80de46SSimon Glass ulong fit_get_end(const void *fit);
9965dfb5213SMarian Balakowicz 
9975dfb5213SMarian Balakowicz /**
9985dfb5213SMarian Balakowicz  * fit_get_name - get FIT node name
9995dfb5213SMarian Balakowicz  * @fit: pointer to the FIT format image header
10005dfb5213SMarian Balakowicz  *
10015dfb5213SMarian Balakowicz  * returns:
10025dfb5213SMarian Balakowicz  *     NULL, on error
10035dfb5213SMarian Balakowicz  *     pointer to node name, on success
10045dfb5213SMarian Balakowicz  */
fit_get_name(const void * fit_hdr,int noffset,int * len)10055dfb5213SMarian Balakowicz static inline const char *fit_get_name(const void *fit_hdr,
10065dfb5213SMarian Balakowicz 		int noffset, int *len)
10075dfb5213SMarian Balakowicz {
10085dfb5213SMarian Balakowicz 	return fdt_get_name(fit_hdr, noffset, len);
10095dfb5213SMarian Balakowicz }
10105dfb5213SMarian Balakowicz 
10115dfb5213SMarian Balakowicz int fit_get_desc(const void *fit, int noffset, char **desc);
10125dfb5213SMarian Balakowicz int fit_get_timestamp(const void *fit, int noffset, time_t *timestamp);
10135dfb5213SMarian Balakowicz 
10145dfb5213SMarian Balakowicz int fit_image_get_node(const void *fit, const char *image_uname);
10155dfb5213SMarian Balakowicz int fit_image_get_os(const void *fit, int noffset, uint8_t *os);
10165dfb5213SMarian Balakowicz int fit_image_get_arch(const void *fit, int noffset, uint8_t *arch);
10175dfb5213SMarian Balakowicz int fit_image_get_type(const void *fit, int noffset, uint8_t *type);
10185dfb5213SMarian Balakowicz int fit_image_get_comp(const void *fit, int noffset, uint8_t *comp);
10195dfb5213SMarian Balakowicz int fit_image_get_load(const void *fit, int noffset, ulong *load);
10205dfb5213SMarian Balakowicz int fit_image_get_entry(const void *fit, int noffset, ulong *entry);
10215dfb5213SMarian Balakowicz int fit_image_get_data(const void *fit, int noffset,
10225dfb5213SMarian Balakowicz 				const void **data, size_t *size);
1023db1b79b8Stomas.melin@vaisala.com int fit_image_get_data_offset(const void *fit, int noffset, int *data_offset);
1024a1be94b6SPeng Fan int fit_image_get_data_position(const void *fit, int noffset,
1025a1be94b6SPeng Fan 				int *data_position);
1026db1b79b8Stomas.melin@vaisala.com int fit_image_get_data_size(const void *fit, int noffset, int *data_size);
1027c3c86388SKelvin Cheung int fit_image_get_data_and_size(const void *fit, int noffset,
1028c3c86388SKelvin Cheung 				const void **data, size_t *size);
10295dfb5213SMarian Balakowicz 
10305dfb5213SMarian Balakowicz int fit_image_hash_get_algo(const void *fit, int noffset, char **algo);
10315dfb5213SMarian Balakowicz int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value,
10325dfb5213SMarian Balakowicz 				int *value_len);
10335dfb5213SMarian Balakowicz 
10345dfb5213SMarian Balakowicz int fit_set_timestamp(void *fit, int noffset, time_t timestamp);
1035bbb467dcSSimon Glass 
1036bbb467dcSSimon Glass /**
103756518e71SSimon Glass  * fit_add_verification_data() - add verification data to FIT image nodes
1038bbb467dcSSimon Glass  *
103956518e71SSimon Glass  * @keydir:	Directory containing keys
104056518e71SSimon Glass  * @kwydest:	FDT blob to write public key information to
104156518e71SSimon Glass  * @fit:	Pointer to the FIT format image header
104256518e71SSimon Glass  * @comment:	Comment to add to signature nodes
104356518e71SSimon Glass  * @require_keys: Mark all keys as 'required'
1044f1ca1fdeSGeorge McCollister  * @engine_id:	Engine to use for signing
1045795f452eSAlex Kiernan  * @cmdname:	Command name used when reporting errors
104656518e71SSimon Glass  *
104756518e71SSimon Glass  * Adds hash values for all component images in the FIT blob.
104856518e71SSimon Glass  * Hashes are calculated for all component images which have hash subnodes
104956518e71SSimon Glass  * with algorithm property set to one of the supported hash algorithms.
105056518e71SSimon Glass  *
105156518e71SSimon Glass  * Also add signatures if signature nodes are present.
105256518e71SSimon Glass  *
105356518e71SSimon Glass  * returns
105456518e71SSimon Glass  *     0, on success
105556518e71SSimon Glass  *     libfdt error code, on failure
1056bbb467dcSSimon Glass  */
105756518e71SSimon Glass int fit_add_verification_data(const char *keydir, void *keydest, void *fit,
1058f1ca1fdeSGeorge McCollister 			      const char *comment, int require_keys,
1059795f452eSAlex Kiernan 			      const char *engine_id, const char *cmdname);
10605dfb5213SMarian Balakowicz 
10615c643db4SJun Nie int fit_image_verify_with_data(const void *fit, int image_noffset,
10625c643db4SJun Nie 			       const void *data, size_t size);
1063b8da8366SSimon Glass int fit_image_verify(const void *fit, int noffset);
1064782cfbb2SSimon Glass int fit_config_verify(const void *fit, int conf_noffset);
1065b8da8366SSimon Glass int fit_all_image_verify(const void *fit);
10665dfb5213SMarian Balakowicz int fit_image_check_os(const void *fit, int noffset, uint8_t os);
10675dfb5213SMarian Balakowicz int fit_image_check_arch(const void *fit, int noffset, uint8_t arch);
10685dfb5213SMarian Balakowicz int fit_image_check_type(const void *fit, int noffset, uint8_t type);
10695dfb5213SMarian Balakowicz int fit_image_check_comp(const void *fit, int noffset, uint8_t comp);
10705dfb5213SMarian Balakowicz int fit_check_format(const void *fit);
10715dfb5213SMarian Balakowicz 
1072d95f6ec7SGabe Black int fit_conf_find_compat(const void *fit, const void *fdt);
10735dfb5213SMarian Balakowicz int fit_conf_get_node(const void *fit, const char *conf_uname);
10745dfb5213SMarian Balakowicz 
1075003efd7dSSimon Glass /**
1076003efd7dSSimon Glass  * fit_conf_get_prop_node() - Get node refered to by a configuration
1077003efd7dSSimon Glass  * @fit:	FIT to check
1078003efd7dSSimon Glass  * @noffset:	Offset of conf@xxx node to check
1079003efd7dSSimon Glass  * @prop_name:	Property to read from the conf node
1080003efd7dSSimon Glass  *
1081b2267e8aSAndre Przywara  * The conf- nodes contain references to other nodes, using properties
1082b2267e8aSAndre Przywara  * like 'kernel = "kernel"'. Given such a property name (e.g. "kernel"),
1083003efd7dSSimon Glass  * return the offset of the node referred to (e.g. offset of node
1084b2267e8aSAndre Przywara  * "/images/kernel".
1085003efd7dSSimon Glass  */
1086003efd7dSSimon Glass int fit_conf_get_prop_node(const void *fit, int noffset,
1087003efd7dSSimon Glass 		const char *prop_name);
1088003efd7dSSimon Glass 
108961a439a8SSimon Glass int fit_check_ramdisk(const void *fit, int os_noffset,
109061a439a8SSimon Glass 		uint8_t arch, int verify);
109161a439a8SSimon Glass 
1092604f23ddSSimon Glass int calculate_hash(const void *data, int data_len, const char *algo,
1093604f23ddSSimon Glass 			uint8_t *value, int *value_len);
1094604f23ddSSimon Glass 
1095782cfbb2SSimon Glass /*
10963e569a6bSSimon Glass  * At present we only support signing on the host, and verification on the
10973e569a6bSSimon Glass  * device
1098782cfbb2SSimon Glass  */
1099782cfbb2SSimon Glass #if defined(CONFIG_FIT_SIGNATURE)
1100782cfbb2SSimon Glass # ifdef USE_HOSTCC
11013e569a6bSSimon Glass #  define IMAGE_ENABLE_SIGN	1
110229a23f9dSHeiko Schocher #  define IMAGE_ENABLE_VERIFY	1
1103646257d1SHeiko Schocher # include  <openssl/evp.h>
1104782cfbb2SSimon Glass #else
11053e569a6bSSimon Glass #  define IMAGE_ENABLE_SIGN	0
1106782cfbb2SSimon Glass #  define IMAGE_ENABLE_VERIFY	1
1107782cfbb2SSimon Glass # endif
1108782cfbb2SSimon Glass #else
11093e569a6bSSimon Glass # define IMAGE_ENABLE_SIGN	0
1110782cfbb2SSimon Glass # define IMAGE_ENABLE_VERIFY	0
1111782cfbb2SSimon Glass #endif
1112782cfbb2SSimon Glass 
1113782cfbb2SSimon Glass #ifdef USE_HOSTCC
111429a23f9dSHeiko Schocher void *image_get_host_blob(void);
111529a23f9dSHeiko Schocher void image_set_host_blob(void *host_blob);
111629a23f9dSHeiko Schocher # define gd_fdt_blob()		image_get_host_blob()
1117782cfbb2SSimon Glass #else
1118782cfbb2SSimon Glass # define gd_fdt_blob()		(gd->fdt_blob)
1119782cfbb2SSimon Glass #endif
1120782cfbb2SSimon Glass 
1121782cfbb2SSimon Glass #ifdef CONFIG_FIT_BEST_MATCH
1122782cfbb2SSimon Glass #define IMAGE_ENABLE_BEST_MATCH	1
1123782cfbb2SSimon Glass #else
1124782cfbb2SSimon Glass #define IMAGE_ENABLE_BEST_MATCH	0
1125782cfbb2SSimon Glass #endif
1126782cfbb2SSimon Glass 
11273e569a6bSSimon Glass /* Information passed to the signing routines */
11283e569a6bSSimon Glass struct image_sign_info {
11293e569a6bSSimon Glass 	const char *keydir;		/* Directory conaining keys */
11303e569a6bSSimon Glass 	const char *keyname;		/* Name of key to use */
11313e569a6bSSimon Glass 	void *fit;			/* Pointer to FIT blob */
11323e569a6bSSimon Glass 	int node_offset;		/* Offset of signature node */
113383dd98e0SAndrew Duda 	const char *name;		/* Algorithm name */
113483dd98e0SAndrew Duda 	struct checksum_algo *checksum;	/* Checksum algorithm information */
113520031567SPhilippe Reynes 	struct padding_algo *padding;	/* Padding algorithm information */
113683dd98e0SAndrew Duda 	struct crypto_algo *crypto;	/* Crypto algorithm information */
11373e569a6bSSimon Glass 	const void *fdt_blob;		/* FDT containing public keys */
11383e569a6bSSimon Glass 	int required_keynode;		/* Node offset of key to use: -1=any */
11393e569a6bSSimon Glass 	const char *require_keys;	/* Value for 'required' property */
1140f1ca1fdeSGeorge McCollister 	const char *engine_id;		/* Engine to use for signing */
11413e569a6bSSimon Glass };
114273223f0eSSimon Glass #endif /* Allow struct image_region to always be defined for rsa.h */
11433e569a6bSSimon Glass 
11443e569a6bSSimon Glass /* A part of an image, used for hashing */
11453e569a6bSSimon Glass struct image_region {
11463e569a6bSSimon Glass 	const void *data;
11473e569a6bSSimon Glass 	int size;
11483e569a6bSSimon Glass };
11493e569a6bSSimon Glass 
115073223f0eSSimon Glass #if IMAGE_ENABLE_FIT
115173223f0eSSimon Glass 
1152646257d1SHeiko Schocher #if IMAGE_ENABLE_VERIFY
11532b9912e6SJeroen Hofstee # include <u-boot/rsa-checksum.h>
1154646257d1SHeiko Schocher #endif
1155646257d1SHeiko Schocher struct checksum_algo {
1156646257d1SHeiko Schocher 	const char *name;
1157646257d1SHeiko Schocher 	const int checksum_len;
1158da29f299SAndrew Duda 	const int der_len;
1159da29f299SAndrew Duda 	const uint8_t *der_prefix;
1160646257d1SHeiko Schocher #if IMAGE_ENABLE_SIGN
116129a23f9dSHeiko Schocher 	const EVP_MD *(*calculate_sign)(void);
116229a23f9dSHeiko Schocher #endif
1163b37b46f0SRuchika Gupta 	int (*calculate)(const char *name,
1164b37b46f0SRuchika Gupta 			 const struct image_region region[],
1165646257d1SHeiko Schocher 			 int region_count, uint8_t *checksum);
1166646257d1SHeiko Schocher };
1167646257d1SHeiko Schocher 
11680c1d74fdSAndrew Duda struct crypto_algo {
11693e569a6bSSimon Glass 	const char *name;		/* Name of algorithm */
11700c1d74fdSAndrew Duda 	const int key_len;
11713e569a6bSSimon Glass 
11723e569a6bSSimon Glass 	/**
11733e569a6bSSimon Glass 	 * sign() - calculate and return signature for given input data
11743e569a6bSSimon Glass 	 *
11753e569a6bSSimon Glass 	 * @info:	Specifies key and FIT information
11763e569a6bSSimon Glass 	 * @data:	Pointer to the input data
11773e569a6bSSimon Glass 	 * @data_len:	Data length
11783e569a6bSSimon Glass 	 * @sigp:	Set to an allocated buffer holding the signature
11793e569a6bSSimon Glass 	 * @sig_len:	Set to length of the calculated hash
11803e569a6bSSimon Glass 	 *
11813e569a6bSSimon Glass 	 * This computes input data signature according to selected algorithm.
11823e569a6bSSimon Glass 	 * Resulting signature value is placed in an allocated buffer, the
11833e569a6bSSimon Glass 	 * pointer is returned as *sigp. The length of the calculated
11843e569a6bSSimon Glass 	 * signature is returned via the sig_len pointer argument. The caller
11853e569a6bSSimon Glass 	 * should free *sigp.
11863e569a6bSSimon Glass 	 *
11873e569a6bSSimon Glass 	 * @return: 0, on success, -ve on error
11883e569a6bSSimon Glass 	 */
11893e569a6bSSimon Glass 	int (*sign)(struct image_sign_info *info,
11903e569a6bSSimon Glass 		    const struct image_region region[],
11913e569a6bSSimon Glass 		    int region_count, uint8_t **sigp, uint *sig_len);
11923e569a6bSSimon Glass 
11933e569a6bSSimon Glass 	/**
11943e569a6bSSimon Glass 	 * add_verify_data() - Add verification information to FDT
11953e569a6bSSimon Glass 	 *
11963e569a6bSSimon Glass 	 * Add public key information to the FDT node, suitable for
11973e569a6bSSimon Glass 	 * verification at run-time. The information added depends on the
11983e569a6bSSimon Glass 	 * algorithm being used.
11993e569a6bSSimon Glass 	 *
12003e569a6bSSimon Glass 	 * @info:	Specifies key and FIT information
12013e569a6bSSimon Glass 	 * @keydest:	Destination FDT blob for public key data
12023e569a6bSSimon Glass 	 * @return: 0, on success, -ve on error
12033e569a6bSSimon Glass 	 */
12043e569a6bSSimon Glass 	int (*add_verify_data)(struct image_sign_info *info, void *keydest);
12053e569a6bSSimon Glass 
12063e569a6bSSimon Glass 	/**
12073e569a6bSSimon Glass 	 * verify() - Verify a signature against some data
12083e569a6bSSimon Glass 	 *
12093e569a6bSSimon Glass 	 * @info:	Specifies key and FIT information
12103e569a6bSSimon Glass 	 * @data:	Pointer to the input data
12113e569a6bSSimon Glass 	 * @data_len:	Data length
12123e569a6bSSimon Glass 	 * @sig:	Signature
12133e569a6bSSimon Glass 	 * @sig_len:	Number of bytes in signature
12143e569a6bSSimon Glass 	 * @return 0 if verified, -ve on error
12153e569a6bSSimon Glass 	 */
12163e569a6bSSimon Glass 	int (*verify)(struct image_sign_info *info,
12173e569a6bSSimon Glass 		      const struct image_region region[], int region_count,
12183e569a6bSSimon Glass 		      uint8_t *sig, uint sig_len);
12190c1d74fdSAndrew Duda };
1220646257d1SHeiko Schocher 
122120031567SPhilippe Reynes struct padding_algo {
122220031567SPhilippe Reynes 	const char *name;
122320031567SPhilippe Reynes 	int (*verify)(struct image_sign_info *info,
122420031567SPhilippe Reynes 		      uint8_t *pad, int pad_len,
122520031567SPhilippe Reynes 		      const uint8_t *hash, int hash_len);
122620031567SPhilippe Reynes };
122720031567SPhilippe Reynes 
12283e569a6bSSimon Glass /**
122983dd98e0SAndrew Duda  * image_get_checksum_algo() - Look up a checksum algorithm
12303e569a6bSSimon Glass  *
123183dd98e0SAndrew Duda  * @param full_name	Name of algorithm in the form "checksum,crypto"
12323e569a6bSSimon Glass  * @return pointer to algorithm information, or NULL if not found
12333e569a6bSSimon Glass  */
123483dd98e0SAndrew Duda struct checksum_algo *image_get_checksum_algo(const char *full_name);
123583dd98e0SAndrew Duda 
123683dd98e0SAndrew Duda /**
123783dd98e0SAndrew Duda  * image_get_crypto_algo() - Look up a cryptosystem algorithm
123883dd98e0SAndrew Duda  *
123983dd98e0SAndrew Duda  * @param full_name	Name of algorithm in the form "checksum,crypto"
124083dd98e0SAndrew Duda  * @return pointer to algorithm information, or NULL if not found
124183dd98e0SAndrew Duda  */
124283dd98e0SAndrew Duda struct crypto_algo *image_get_crypto_algo(const char *full_name);
12433e569a6bSSimon Glass 
124456518e71SSimon Glass /**
124520031567SPhilippe Reynes  * image_get_padding_algo() - Look up a padding algorithm
124620031567SPhilippe Reynes  *
124720031567SPhilippe Reynes  * @param name		Name of padding algorithm
124820031567SPhilippe Reynes  * @return pointer to algorithm information, or NULL if not found
124920031567SPhilippe Reynes  */
125020031567SPhilippe Reynes struct padding_algo *image_get_padding_algo(const char *name);
125120031567SPhilippe Reynes 
125220031567SPhilippe Reynes /**
125356518e71SSimon Glass  * fit_image_verify_required_sigs() - Verify signatures marked as 'required'
125456518e71SSimon Glass  *
125556518e71SSimon Glass  * @fit:		FIT to check
125656518e71SSimon Glass  * @image_noffset:	Offset of image node to check
125756518e71SSimon Glass  * @data:		Image data to check
125856518e71SSimon Glass  * @size:		Size of image data
125956518e71SSimon Glass  * @sig_blob:		FDT containing public keys
126056518e71SSimon Glass  * @no_sigsp:		Returns 1 if no signatures were required, and
126156518e71SSimon Glass  *			therefore nothing was checked. The caller may wish
126256518e71SSimon Glass  *			to fall back to other mechanisms, or refuse to
126356518e71SSimon Glass  *			boot.
126456518e71SSimon Glass  * @return 0 if all verified ok, <0 on error
126556518e71SSimon Glass  */
126656518e71SSimon Glass int fit_image_verify_required_sigs(const void *fit, int image_noffset,
126756518e71SSimon Glass 		const char *data, size_t size, const void *sig_blob,
126856518e71SSimon Glass 		int *no_sigsp);
126956518e71SSimon Glass 
127056518e71SSimon Glass /**
127156518e71SSimon Glass  * fit_image_check_sig() - Check a single image signature node
127256518e71SSimon Glass  *
127356518e71SSimon Glass  * @fit:		FIT to check
127456518e71SSimon Glass  * @noffset:		Offset of signature node to check
127556518e71SSimon Glass  * @data:		Image data to check
127656518e71SSimon Glass  * @size:		Size of image data
127756518e71SSimon Glass  * @required_keynode:	Offset in the control FDT of the required key node,
127856518e71SSimon Glass  *			if any. If this is given, then the image wil not
127956518e71SSimon Glass  *			pass verification unless that key is used. If this is
128056518e71SSimon Glass  *			-1 then any signature will do.
128156518e71SSimon Glass  * @err_msgp:		In the event of an error, this will be pointed to a
128256518e71SSimon Glass  *			help error string to display to the user.
128356518e71SSimon Glass  * @return 0 if all verified ok, <0 on error
128456518e71SSimon Glass  */
128556518e71SSimon Glass int fit_image_check_sig(const void *fit, int noffset, const void *data,
128656518e71SSimon Glass 		size_t size, int required_keynode, char **err_msgp);
128756518e71SSimon Glass 
12884d098529SSimon Glass /**
12894d098529SSimon Glass  * fit_region_make_list() - Make a list of regions to hash
12904d098529SSimon Glass  *
12914d098529SSimon Glass  * Given a list of FIT regions (offset, size) provided by libfdt, create
12924d098529SSimon Glass  * a list of regions (void *, size) for use by the signature creationg
12934d098529SSimon Glass  * and verification code.
12944d098529SSimon Glass  *
12954d098529SSimon Glass  * @fit:		FIT image to process
12964d098529SSimon Glass  * @fdt_regions:	Regions as returned by libfdt
12974d098529SSimon Glass  * @count:		Number of regions returned by libfdt
12984d098529SSimon Glass  * @region:		Place to put list of regions (NULL to allocate it)
12994d098529SSimon Glass  * @return pointer to list of regions, or NULL if out of memory
13004d098529SSimon Glass  */
13014d098529SSimon Glass struct image_region *fit_region_make_list(const void *fit,
13024d098529SSimon Glass 		struct fdt_region *fdt_regions, int count,
13034d098529SSimon Glass 		struct image_region *region);
130456518e71SSimon Glass 
fit_image_check_target_arch(const void * fdt,int node)13055dfb5213SMarian Balakowicz static inline int fit_image_check_target_arch(const void *fdt, int node)
13065dfb5213SMarian Balakowicz {
130729a23f9dSHeiko Schocher #ifndef USE_HOSTCC
13087566832aSThierry Reding 	return fit_image_check_arch(fdt, node, IH_ARCH_DEFAULT);
130929a23f9dSHeiko Schocher #else
131029a23f9dSHeiko Schocher 	return 0;
131129a23f9dSHeiko Schocher #endif
13125dfb5213SMarian Balakowicz }
13135dfb5213SMarian Balakowicz 
1314d5934ad7SMarian Balakowicz #ifdef CONFIG_FIT_VERBOSE
1315d5934ad7SMarian Balakowicz #define fit_unsupported(msg)	printf("! %s:%d " \
1316d5934ad7SMarian Balakowicz 				"FIT images not supported for '%s'\n", \
1317d5934ad7SMarian Balakowicz 				__FILE__, __LINE__, (msg))
1318d5934ad7SMarian Balakowicz 
1319d5934ad7SMarian Balakowicz #define fit_unsupported_reset(msg)	printf("! %s:%d " \
1320d5934ad7SMarian Balakowicz 				"FIT images not supported for '%s' " \
1321d5934ad7SMarian Balakowicz 				"- must reset board to recover!\n", \
1322d5934ad7SMarian Balakowicz 				__FILE__, __LINE__, (msg))
1323d5934ad7SMarian Balakowicz #else
1324d5934ad7SMarian Balakowicz #define fit_unsupported(msg)
1325d5934ad7SMarian Balakowicz #define fit_unsupported_reset(msg)
1326d5934ad7SMarian Balakowicz #endif /* CONFIG_FIT_VERBOSE */
1327f50433d6SMarian Balakowicz #endif /* CONFIG_FIT */
13285ad03eb3SMarian Balakowicz 
13299ace3fc8SSebastian Siewior #if defined(CONFIG_ANDROID_BOOT_IMAGE)
13309ace3fc8SSebastian Siewior struct andr_img_hdr;
13319ace3fc8SSebastian Siewior int android_image_check_header(const struct andr_img_hdr *hdr);
13329ace3fc8SSebastian Siewior int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
13339ace3fc8SSebastian Siewior 			     ulong *os_data, ulong *os_len);
13349ace3fc8SSebastian Siewior int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
13359ace3fc8SSebastian Siewior 			      ulong *rd_data, ulong *rd_len);
133610481614SBin Chen int android_image_get_second(const struct andr_img_hdr *hdr,
133710481614SBin Chen 			      ulong *second_data, ulong *second_len);
13389ace3fc8SSebastian Siewior ulong android_image_get_end(const struct andr_img_hdr *hdr);
13399ace3fc8SSebastian Siewior ulong android_image_get_kload(const struct andr_img_hdr *hdr);
13404f1318b2SMichael Trimarchi void android_print_contents(const struct andr_img_hdr *hdr);
13419ace3fc8SSebastian Siewior 
13429ace3fc8SSebastian Siewior #endif /* CONFIG_ANDROID_BOOT_IMAGE */
13439ace3fc8SSebastian Siewior 
13444b307f23SSimon Glass /**
13454b307f23SSimon Glass  * board_fit_config_name_match() - Check for a matching board name
13464b307f23SSimon Glass  *
13474b307f23SSimon Glass  * This is used when SPL loads a FIT containing multiple device tree files
13484b307f23SSimon Glass  * and wants to work out which one to use. The description of each one is
13494b307f23SSimon Glass  * passed to this function. The description comes from the 'description' field
13504b307f23SSimon Glass  * in each (FDT) image node.
13514b307f23SSimon Glass  *
13524b307f23SSimon Glass  * @name: Device tree description
13534b307f23SSimon Glass  * @return 0 if this device tree should be used, non-zero to try the next
13544b307f23SSimon Glass  */
13554b307f23SSimon Glass int board_fit_config_name_match(const char *name);
13564b307f23SSimon Glass 
1357a5c7e41bSMadan Srinivas #if defined(CONFIG_SPL_FIT_IMAGE_POST_PROCESS) || \
1358a5c7e41bSMadan Srinivas 	defined(CONFIG_FIT_IMAGE_POST_PROCESS)
1359da74d1f3SDaniel Allred /**
1360da74d1f3SDaniel Allred  * board_fit_image_post_process() - Do any post-process on FIT binary data
1361da74d1f3SDaniel Allred  *
1362da74d1f3SDaniel Allred  * This is used to do any sort of image manipulation, verification, decryption
1363da74d1f3SDaniel Allred  * etc. in a platform or board specific way. Obviously, anything done here would
1364da74d1f3SDaniel Allred  * need to be comprehended in how the images were prepared before being injected
1365da74d1f3SDaniel Allred  * into the FIT creation (i.e. the binary blobs would have been pre-processed
1366da74d1f3SDaniel Allred  * before being added to the FIT image).
1367b7d9107fSChia-Wei Wang  * @fit: pointer to fit image
1368b7d9107fSChia-Wei Wang  * @node: offset of image node
1369da74d1f3SDaniel Allred  * @image: pointer to the image start pointer
1370da74d1f3SDaniel Allred  * @size: pointer to the image size
1371da74d1f3SDaniel Allred  * @return no return value (failure should be handled internally)
1372da74d1f3SDaniel Allred  */
1373b7d9107fSChia-Wei Wang void board_fit_image_post_process(const void *fit, int node, void **p_image, size_t *p_size);
1374da74d1f3SDaniel Allred #endif /* CONFIG_SPL_FIT_IMAGE_POST_PROCESS */
1375da74d1f3SDaniel Allred 
13763863f840SCooper Jr., Franklin #define FDT_ERROR	((ulong)(-1))
13773863f840SCooper Jr., Franklin 
137892926bc8SCooper Jr., Franklin ulong fdt_getprop_u32(const void *fdt, int node, const char *prop);
137902035d00SJean-Jacques Hiblot 
138002035d00SJean-Jacques Hiblot /**
138102035d00SJean-Jacques Hiblot  * fit_find_config_node() - Find the node for the best DTB in a FIT image
138202035d00SJean-Jacques Hiblot  *
138302035d00SJean-Jacques Hiblot  * A FIT image contains one or more DTBs. This function parses the
138402035d00SJean-Jacques Hiblot  * configurations described in the FIT images and returns the node of
138502035d00SJean-Jacques Hiblot  * the first matching DTB. To check if a DTB matches a board, this function
138602035d00SJean-Jacques Hiblot  * calls board_fit_config_name_match(). If no matching DTB is found, it returns
138702035d00SJean-Jacques Hiblot  * the node described by the default configuration if it exists.
138802035d00SJean-Jacques Hiblot  *
138902035d00SJean-Jacques Hiblot  * @fdt: pointer to flat device tree
139002035d00SJean-Jacques Hiblot  * @return the node if found, -ve otherwise
139102035d00SJean-Jacques Hiblot  */
139292926bc8SCooper Jr., Franklin int fit_find_config_node(const void *fdt);
139392926bc8SCooper Jr., Franklin 
1394d7be5092SAndrew F. Davis /**
1395d7be5092SAndrew F. Davis  * Mapping of image types to function handlers to be invoked on the associated
1396d7be5092SAndrew F. Davis  * loaded images
1397d7be5092SAndrew F. Davis  *
1398d7be5092SAndrew F. Davis  * @type: Type of image, I.E. IH_TYPE_*
1399d7be5092SAndrew F. Davis  * @handler: Function to call on loaded image
1400d7be5092SAndrew F. Davis  */
1401d7be5092SAndrew F. Davis struct fit_loadable_tbl {
1402d7be5092SAndrew F. Davis 	int type;
1403d7be5092SAndrew F. Davis 	/**
1404d7be5092SAndrew F. Davis 	 * handler() - Process a loaded image
1405d7be5092SAndrew F. Davis 	 *
1406d7be5092SAndrew F. Davis 	 * @data: Pointer to start of loaded image data
1407d7be5092SAndrew F. Davis 	 * @size: Size of loaded image data
1408d7be5092SAndrew F. Davis 	 */
1409d7be5092SAndrew F. Davis 	void (*handler)(ulong data, size_t size);
1410d7be5092SAndrew F. Davis };
1411d7be5092SAndrew F. Davis 
1412d7be5092SAndrew F. Davis /*
1413d7be5092SAndrew F. Davis  * Define a FIT loadable image type handler
1414d7be5092SAndrew F. Davis  *
1415d7be5092SAndrew F. Davis  * _type is a valid uimage_type ID as defined in the "Image Type" enum above
1416d7be5092SAndrew F. Davis  * _handler is the handler function to call after this image type is loaded
1417d7be5092SAndrew F. Davis  */
1418d7be5092SAndrew F. Davis #define U_BOOT_FIT_LOADABLE_HANDLER(_type, _handler) \
1419d7be5092SAndrew F. Davis 	ll_entry_declare(struct fit_loadable_tbl, _function, fit_loadable) = { \
1420d7be5092SAndrew F. Davis 		.type = _type, \
1421d7be5092SAndrew F. Davis 		.handler = _handler, \
1422d7be5092SAndrew F. Davis 	}
1423d7be5092SAndrew F. Davis 
14245b1d7137Swdenk #endif	/* __IMAGE_H__ */
1425