xref: /rk3399_rockchip-uboot/include/image.h (revision f2413b2f2f5a571b162d8d7c0c67fb2b3c99a0e4)
15b1d7137Swdenk /*
2b97a2a0aSMarian Balakowicz  * (C) Copyright 2008 Semihalf
3b97a2a0aSMarian Balakowicz  *
4f08abe31SWolfgang Denk  * (C) Copyright 2000-2005
55b1d7137Swdenk  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
65b1d7137Swdenk  *
71a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
8f08abe31SWolfgang Denk  ********************************************************************
9f08abe31SWolfgang Denk  * NOTE: This header file defines an interface to U-Boot. Including
10f08abe31SWolfgang Denk  * this (unmodified) header file in another file is considered normal
11f08abe31SWolfgang Denk  * use of U-Boot, and does *not* fall under the heading of "derived
12f08abe31SWolfgang Denk  * work".
13f08abe31SWolfgang Denk  ********************************************************************
145b1d7137Swdenk  */
155b1d7137Swdenk 
165b1d7137Swdenk #ifndef __IMAGE_H__
175b1d7137Swdenk #define __IMAGE_H__
185b1d7137Swdenk 
1937566090SMike Frysinger #include "compiler.h"
202f220500SKim Phillips #include <asm/byteorder.h>
2137566090SMike Frysinger 
2213d06981SSimon Glass /* Define this to avoid #ifdefs later on */
2313d06981SSimon Glass struct lmb;
2413d06981SSimon Glass 
2537566090SMike Frysinger #ifdef USE_HOSTCC
2626e355d1SJörg Krause #include <sys/types.h>
279d25438fSBartlomiej Sieka 
289d25438fSBartlomiej Sieka /* new uImage format support enabled on host */
2973223f0eSSimon Glass #define IMAGE_ENABLE_FIT	1
30aa34fbc0SSimon Glass #define IMAGE_ENABLE_OF_LIBFDT	1
319d25438fSBartlomiej Sieka #define CONFIG_FIT_VERBOSE	1 /* enable fit_format_{error,warning}() */
320db7f685STom Rini #define CONFIG_FIT_ENABLE_SHA256_SUPPORT
33089df18bSTom Rini #define CONFIG_SHA1
34089df18bSTom Rini #define CONFIG_SHA256
359d25438fSBartlomiej Sieka 
36ab9efc66SSimon Glass #define IMAGE_ENABLE_IGNORE	0
371fe7d938SSimon Glass #define IMAGE_INDENT_STRING	""
38ab9efc66SSimon Glass 
39def0819eSWolfgang Denk #else
40def0819eSWolfgang Denk 
41def0819eSWolfgang Denk #include <lmb.h>
42def0819eSWolfgang Denk #include <asm/u-boot.h>
435daa1c18SMike Frysinger #include <command.h>
44def0819eSWolfgang Denk 
45ab9efc66SSimon Glass /* Take notice of the 'ignore' property for hashes */
46ab9efc66SSimon Glass #define IMAGE_ENABLE_IGNORE	1
471fe7d938SSimon Glass #define IMAGE_INDENT_STRING	"   "
48ab9efc66SSimon Glass 
4973223f0eSSimon Glass #define IMAGE_ENABLE_FIT	CONFIG_IS_ENABLED(FIT)
50aa34fbc0SSimon Glass #define IMAGE_ENABLE_OF_LIBFDT	CONFIG_IS_ENABLED(OF_LIBFDT)
5173223f0eSSimon Glass 
529d25438fSBartlomiej Sieka #endif /* USE_HOSTCC */
53d5934ad7SMarian Balakowicz 
5473223f0eSSimon Glass #if IMAGE_ENABLE_FIT
551de7bb4fSMichael van der Westhuizen #include <hash.h>
560e00a84cSMasahiro Yamada #include <linux/libfdt.h>
575dfb5213SMarian Balakowicz #include <fdt_support.h>
5887ebee39SSimon Glass # ifdef CONFIG_SPL_BUILD
596f41751fSMasahiro Yamada #  ifdef CONFIG_SPL_CRC32_SUPPORT
606f41751fSMasahiro Yamada #   define IMAGE_ENABLE_CRC32	1
616f41751fSMasahiro Yamada #  endif
626f41751fSMasahiro Yamada #  ifdef CONFIG_SPL_MD5_SUPPORT
636f41751fSMasahiro Yamada #   define IMAGE_ENABLE_MD5	1
646f41751fSMasahiro Yamada #  endif
656f41751fSMasahiro Yamada #  ifdef CONFIG_SPL_SHA1_SUPPORT
666f41751fSMasahiro Yamada #   define IMAGE_ENABLE_SHA1	1
676f41751fSMasahiro Yamada #  endif
6887ebee39SSimon Glass # else
6987ebee39SSimon Glass #  define CONFIG_CRC32		/* FIT images need CRC32 support */
7087ebee39SSimon Glass #  define IMAGE_ENABLE_CRC32	1
7187ebee39SSimon Glass #  define IMAGE_ENABLE_MD5	1
7287ebee39SSimon Glass #  define IMAGE_ENABLE_SHA1	1
736f41751fSMasahiro Yamada # endif
746f41751fSMasahiro Yamada 
756f41751fSMasahiro Yamada #ifndef IMAGE_ENABLE_CRC32
766f41751fSMasahiro Yamada #define IMAGE_ENABLE_CRC32	0
776f41751fSMasahiro Yamada #endif
786f41751fSMasahiro Yamada 
796f41751fSMasahiro Yamada #ifndef IMAGE_ENABLE_MD5
806f41751fSMasahiro Yamada #define IMAGE_ENABLE_MD5	0
816f41751fSMasahiro Yamada #endif
826f41751fSMasahiro Yamada 
836f41751fSMasahiro Yamada #ifndef IMAGE_ENABLE_SHA1
846f41751fSMasahiro Yamada #define IMAGE_ENABLE_SHA1	0
856f41751fSMasahiro Yamada #endif
866f41751fSMasahiro Yamada 
870db7f685STom Rini #if defined(CONFIG_FIT_ENABLE_SHA256_SUPPORT) || \
880db7f685STom Rini 	defined(CONFIG_SPL_SHA256_SUPPORT)
890db7f685STom Rini #define IMAGE_ENABLE_SHA256	1
900db7f685STom Rini #else
916f41751fSMasahiro Yamada #define IMAGE_ENABLE_SHA256	0
926f41751fSMasahiro Yamada #endif
936f41751fSMasahiro Yamada 
9473223f0eSSimon Glass #endif /* IMAGE_ENABLE_FIT */
9513d06981SSimon Glass 
966f41751fSMasahiro Yamada #ifdef CONFIG_SYS_BOOT_GET_CMDLINE
976f41751fSMasahiro Yamada # define IMAGE_BOOT_GET_CMDLINE		1
986f41751fSMasahiro Yamada #else
996f41751fSMasahiro Yamada # define IMAGE_BOOT_GET_CMDLINE		0
1006f41751fSMasahiro Yamada #endif
1016f41751fSMasahiro Yamada 
1026f41751fSMasahiro Yamada #ifdef CONFIG_OF_BOARD_SETUP
1036f41751fSMasahiro Yamada # define IMAGE_OF_BOARD_SETUP		1
1046f41751fSMasahiro Yamada #else
1056f41751fSMasahiro Yamada # define IMAGE_OF_BOARD_SETUP		0
1066f41751fSMasahiro Yamada #endif
1076f41751fSMasahiro Yamada 
1086f41751fSMasahiro Yamada #ifdef CONFIG_OF_SYSTEM_SETUP
1096f41751fSMasahiro Yamada # define IMAGE_OF_SYSTEM_SETUP	1
1106f41751fSMasahiro Yamada #else
1116f41751fSMasahiro Yamada # define IMAGE_OF_SYSTEM_SETUP	0
1126f41751fSMasahiro Yamada #endif
113c654b517SSimon Glass 
11456d7ab74SSimon Glass enum ih_category {
11556d7ab74SSimon Glass 	IH_ARCH,
11656d7ab74SSimon Glass 	IH_COMP,
11756d7ab74SSimon Glass 	IH_OS,
11856d7ab74SSimon Glass 	IH_TYPE,
11956d7ab74SSimon Glass 
12056d7ab74SSimon Glass 	IH_COUNT,
12156d7ab74SSimon Glass };
12256d7ab74SSimon Glass 
1235b1d7137Swdenk /*
1245b1d7137Swdenk  * Operating System Codes
125ff87b081SMasahiro Yamada  *
126ff87b081SMasahiro Yamada  * The following are exposed to uImage header.
127ff87b081SMasahiro Yamada  * Do not change values for backward compatibility.
1285b1d7137Swdenk  */
129555f45d8SSimon Glass enum {
130555f45d8SSimon Glass 	IH_OS_INVALID		= 0,	/* Invalid OS	*/
131555f45d8SSimon Glass 	IH_OS_OPENBSD,			/* OpenBSD	*/
132555f45d8SSimon Glass 	IH_OS_NETBSD,			/* NetBSD	*/
133555f45d8SSimon Glass 	IH_OS_FREEBSD,			/* FreeBSD	*/
134555f45d8SSimon Glass 	IH_OS_4_4BSD,			/* 4.4BSD	*/
135555f45d8SSimon Glass 	IH_OS_LINUX,			/* Linux	*/
136555f45d8SSimon Glass 	IH_OS_SVR4,			/* SVR4		*/
137555f45d8SSimon Glass 	IH_OS_ESIX,			/* Esix		*/
138555f45d8SSimon Glass 	IH_OS_SOLARIS,			/* Solaris	*/
139555f45d8SSimon Glass 	IH_OS_IRIX,			/* Irix		*/
140555f45d8SSimon Glass 	IH_OS_SCO,			/* SCO		*/
141555f45d8SSimon Glass 	IH_OS_DELL,			/* Dell		*/
142555f45d8SSimon Glass 	IH_OS_NCR,			/* NCR		*/
143555f45d8SSimon Glass 	IH_OS_LYNXOS,			/* LynxOS	*/
144555f45d8SSimon Glass 	IH_OS_VXWORKS,			/* VxWorks	*/
145555f45d8SSimon Glass 	IH_OS_PSOS,			/* pSOS		*/
146555f45d8SSimon Glass 	IH_OS_QNX,			/* QNX		*/
147555f45d8SSimon Glass 	IH_OS_U_BOOT,			/* Firmware	*/
148555f45d8SSimon Glass 	IH_OS_RTEMS,			/* RTEMS	*/
149555f45d8SSimon Glass 	IH_OS_ARTOS,			/* ARTOS	*/
150555f45d8SSimon Glass 	IH_OS_UNITY,			/* Unity OS	*/
151555f45d8SSimon Glass 	IH_OS_INTEGRITY,		/* INTEGRITY	*/
152555f45d8SSimon Glass 	IH_OS_OSE,			/* OSE		*/
153555f45d8SSimon Glass 	IH_OS_PLAN9,			/* Plan 9	*/
154555f45d8SSimon Glass 	IH_OS_OPENRTOS,		/* OpenRTOS	*/
1554233e0b1SPhilipp Tomsich 	IH_OS_ARM_TRUSTED_FIRMWARE,     /* ARM Trusted Firmware */
156820a0a12SKever Yang 	IH_OS_OP_TEE,			/* OP-TEE	*/
157555f45d8SSimon Glass 
158555f45d8SSimon Glass 	IH_OS_COUNT,
159555f45d8SSimon Glass };
1605b1d7137Swdenk 
1615b1d7137Swdenk /*
1625b1d7137Swdenk  * CPU Architecture Codes (supported by Linux)
163ff87b081SMasahiro Yamada  *
164ff87b081SMasahiro Yamada  * The following are exposed to uImage header.
165ff87b081SMasahiro Yamada  * Do not change values for backward compatibility.
1665b1d7137Swdenk  */
167555f45d8SSimon Glass enum {
168555f45d8SSimon Glass 	IH_ARCH_INVALID		= 0,	/* Invalid CPU	*/
169555f45d8SSimon Glass 	IH_ARCH_ALPHA,			/* Alpha	*/
170555f45d8SSimon Glass 	IH_ARCH_ARM,			/* ARM		*/
171555f45d8SSimon Glass 	IH_ARCH_I386,			/* Intel x86	*/
172555f45d8SSimon Glass 	IH_ARCH_IA64,			/* IA64		*/
173555f45d8SSimon Glass 	IH_ARCH_MIPS,			/* MIPS		*/
174555f45d8SSimon Glass 	IH_ARCH_MIPS64,			/* MIPS	 64 Bit */
175555f45d8SSimon Glass 	IH_ARCH_PPC,			/* PowerPC	*/
176555f45d8SSimon Glass 	IH_ARCH_S390,			/* IBM S390	*/
177555f45d8SSimon Glass 	IH_ARCH_SH,			/* SuperH	*/
178555f45d8SSimon Glass 	IH_ARCH_SPARC,			/* Sparc	*/
179555f45d8SSimon Glass 	IH_ARCH_SPARC64,		/* Sparc 64 Bit */
180555f45d8SSimon Glass 	IH_ARCH_M68K,			/* M68K		*/
181ff87b081SMasahiro Yamada 	IH_ARCH_NIOS,			/* Nios-32	*/
182555f45d8SSimon Glass 	IH_ARCH_MICROBLAZE,		/* MicroBlaze   */
183555f45d8SSimon Glass 	IH_ARCH_NIOS2,			/* Nios-II	*/
184555f45d8SSimon Glass 	IH_ARCH_BLACKFIN,		/* Blackfin	*/
185555f45d8SSimon Glass 	IH_ARCH_AVR32,			/* AVR32	*/
186555f45d8SSimon Glass 	IH_ARCH_ST200,			/* STMicroelectronics ST200  */
187555f45d8SSimon Glass 	IH_ARCH_SANDBOX,		/* Sandbox architecture (test only) */
188555f45d8SSimon Glass 	IH_ARCH_NDS32,			/* ANDES Technology - NDS32  */
189555f45d8SSimon Glass 	IH_ARCH_OPENRISC,		/* OpenRISC 1000  */
190555f45d8SSimon Glass 	IH_ARCH_ARM64,			/* ARM64	*/
191555f45d8SSimon Glass 	IH_ARCH_ARC,			/* Synopsys DesignWare ARC */
192555f45d8SSimon Glass 	IH_ARCH_X86_64,			/* AMD x86_64, Intel and Via */
193de5e5ceaSChris Zankel 	IH_ARCH_XTENSA,			/* Xtensa	*/
194555f45d8SSimon Glass 
195555f45d8SSimon Glass 	IH_ARCH_COUNT,
196555f45d8SSimon Glass };
1975b1d7137Swdenk 
1985b1d7137Swdenk /*
1995b1d7137Swdenk  * Image Types
2005b1d7137Swdenk  *
2015b1d7137Swdenk  * "Standalone Programs" are directly runnable in the environment
2025b1d7137Swdenk  *	provided by U-Boot; it is expected that (if they behave
2035b1d7137Swdenk  *	well) you can continue to work in U-Boot after return from
2045b1d7137Swdenk  *	the Standalone Program.
2055b1d7137Swdenk  * "OS Kernel Images" are usually images of some Embedded OS which
2065b1d7137Swdenk  *	will take over control completely. Usually these programs
2075b1d7137Swdenk  *	will install their own set of exception handlers, device
2085b1d7137Swdenk  *	drivers, set up the MMU, etc. - this means, that you cannot
2095b1d7137Swdenk  *	expect to re-enter U-Boot except by resetting the CPU.
2105b1d7137Swdenk  * "RAMDisk Images" are more or less just data blocks, and their
2115b1d7137Swdenk  *	parameters (address, size) are passed to an OS kernel that is
2125b1d7137Swdenk  *	being started.
2135b1d7137Swdenk  * "Multi-File Images" contain several images, typically an OS
2145b1d7137Swdenk  *	(Linux) kernel image and one or more data images like
2155b1d7137Swdenk  *	RAMDisks. This construct is useful for instance when you want
2165b1d7137Swdenk  *	to boot over the network using BOOTP etc., where the boot
2175b1d7137Swdenk  *	server provides just a single image file, but you want to get
2185b1d7137Swdenk  *	for instance an OS kernel and a RAMDisk image.
2195b1d7137Swdenk  *
2205b1d7137Swdenk  *	"Multi-File Images" start with a list of image sizes, each
2215b1d7137Swdenk  *	image size (in bytes) specified by an "uint32_t" in network
2225b1d7137Swdenk  *	byte order. This list is terminated by an "(uint32_t)0".
2235b1d7137Swdenk  *	Immediately after the terminating 0 follow the images, one by
2245b1d7137Swdenk  *	one, all aligned on "uint32_t" boundaries (size rounded up to
225e1599e83Swdenk  *	a multiple of 4 bytes - except for the last file).
2265b1d7137Swdenk  *
2275b1d7137Swdenk  * "Firmware Images" are binary images containing firmware (like
2285b1d7137Swdenk  *	U-Boot or FPGA images) which usually will be programmed to
2295b1d7137Swdenk  *	flash memory.
2305b1d7137Swdenk  *
2315b1d7137Swdenk  * "Script files" are command sequences that will be executed by
2325b1d7137Swdenk  *	U-Boot's command interpreter; this feature is especially
2335b1d7137Swdenk  *	useful when you configure U-Boot to use a real shell (hush)
23427b207fdSwdenk  *	as command interpreter (=> Shell Scripts).
235ff87b081SMasahiro Yamada  *
236ff87b081SMasahiro Yamada  * The following are exposed to uImage header.
237ff87b081SMasahiro Yamada  * Do not change values for backward compatibility.
2385b1d7137Swdenk  */
2395b1d7137Swdenk 
240555f45d8SSimon Glass enum {
241555f45d8SSimon Glass 	IH_TYPE_INVALID		= 0,	/* Invalid Image		*/
242555f45d8SSimon Glass 	IH_TYPE_STANDALONE,		/* Standalone Program		*/
243555f45d8SSimon Glass 	IH_TYPE_KERNEL,			/* OS Kernel Image		*/
244555f45d8SSimon Glass 	IH_TYPE_RAMDISK,		/* RAMDisk Image		*/
245555f45d8SSimon Glass 	IH_TYPE_MULTI,			/* Multi-File Image		*/
246555f45d8SSimon Glass 	IH_TYPE_FIRMWARE,		/* Firmware Image		*/
247555f45d8SSimon Glass 	IH_TYPE_SCRIPT,			/* Script file			*/
248555f45d8SSimon Glass 	IH_TYPE_FILESYSTEM,		/* Filesystem Image (any type)	*/
249555f45d8SSimon Glass 	IH_TYPE_FLATDT,			/* Binary Flat Device Tree Blob	*/
250555f45d8SSimon Glass 	IH_TYPE_KWBIMAGE,		/* Kirkwood Boot Image		*/
251555f45d8SSimon Glass 	IH_TYPE_IMXIMAGE,		/* Freescale IMXBoot Image	*/
252555f45d8SSimon Glass 	IH_TYPE_UBLIMAGE,		/* Davinci UBL Image		*/
253555f45d8SSimon Glass 	IH_TYPE_OMAPIMAGE,		/* TI OMAP Config Header Image	*/
254555f45d8SSimon Glass 	IH_TYPE_AISIMAGE,		/* TI Davinci AIS Image		*/
255555f45d8SSimon Glass 	/* OS Kernel Image, can run from any load address */
256555f45d8SSimon Glass 	IH_TYPE_KERNEL_NOLOAD,
257555f45d8SSimon Glass 	IH_TYPE_PBLIMAGE,		/* Freescale PBL Boot Image	*/
258555f45d8SSimon Glass 	IH_TYPE_MXSIMAGE,		/* Freescale MXSBoot Image	*/
259555f45d8SSimon Glass 	IH_TYPE_GPIMAGE,		/* TI Keystone GPHeader Image	*/
260555f45d8SSimon Glass 	IH_TYPE_ATMELIMAGE,		/* ATMEL ROM bootable Image	*/
261555f45d8SSimon Glass 	IH_TYPE_SOCFPGAIMAGE,		/* Altera SOCFPGA Preloader	*/
262555f45d8SSimon Glass 	IH_TYPE_X86_SETUP,		/* x86 setup.bin Image		*/
263555f45d8SSimon Glass 	IH_TYPE_LPC32XXIMAGE,		/* x86 setup.bin Image		*/
264555f45d8SSimon Glass 	IH_TYPE_LOADABLE,		/* A list of typeless images	*/
265555f45d8SSimon Glass 	IH_TYPE_RKIMAGE,		/* Rockchip Boot Image		*/
266555f45d8SSimon Glass 	IH_TYPE_RKSD,			/* Rockchip SD card		*/
267555f45d8SSimon Glass 	IH_TYPE_RKSPI,			/* Rockchip SPI image		*/
268555f45d8SSimon Glass 	IH_TYPE_ZYNQIMAGE,		/* Xilinx Zynq Boot Image */
269555f45d8SSimon Glass 	IH_TYPE_ZYNQMPIMAGE,		/* Xilinx ZynqMP Boot Image */
270555f45d8SSimon Glass 	IH_TYPE_FPGA,			/* FPGA Image */
271ed0c2c0aSAlbert ARIBAUD \(3ADEV\) 	IH_TYPE_VYBRIDIMAGE,	/* VYBRID .vyb Image */
2727e719ee7SAndrew F. Davis 	IH_TYPE_TEE,            /* Trusted Execution Environment OS Image */
273d21bd69bSSven Ebenfeld 	IH_TYPE_FIRMWARE_IVT,		/* Firmware Image with HABv4 IVT */
274ee0f94feSAndrew F. Davis 	IH_TYPE_PMMC,            /* TI Power Management Micro-Controller Firmware */
2756f14746bSPaweł Jarosz 	IH_TYPE_RKNAND,			/* Rockchip NAND Boot Image	*/
2765b1d7137Swdenk 
277555f45d8SSimon Glass 	IH_TYPE_COUNT,			/* Number of image types */
278555f45d8SSimon Glass };
2795b9d44dfSSimon Glass 
2805b1d7137Swdenk /*
2815b1d7137Swdenk  * Compression Types
282ff87b081SMasahiro Yamada  *
283ff87b081SMasahiro Yamada  * The following are exposed to uImage header.
284ff87b081SMasahiro Yamada  * Do not change values for backward compatibility.
2855b1d7137Swdenk  */
286555f45d8SSimon Glass enum {
287555f45d8SSimon Glass 	IH_COMP_NONE		= 0,	/*  No	 Compression Used	*/
288555f45d8SSimon Glass 	IH_COMP_GZIP,			/* gzip	 Compression Used	*/
289555f45d8SSimon Glass 	IH_COMP_BZIP2,			/* bzip2 Compression Used	*/
290555f45d8SSimon Glass 	IH_COMP_LZMA,			/* lzma  Compression Used	*/
291555f45d8SSimon Glass 	IH_COMP_LZO,			/* lzo   Compression Used	*/
292555f45d8SSimon Glass 	IH_COMP_LZ4,			/* lz4   Compression Used	*/
293008aee87SAndy Yan 	IH_COMP_ZIMAGE,			/* zImage Decompressed itself   */
294555f45d8SSimon Glass 
295555f45d8SSimon Glass 	IH_COMP_COUNT,
296555f45d8SSimon Glass };
2975b1d7137Swdenk 
2985b1d7137Swdenk #define IH_MAGIC	0x27051956	/* Image Magic Number		*/
2995b1d7137Swdenk #define IH_NMLEN		32	/* Image Name Length		*/
3005b1d7137Swdenk 
3011411fb37SFabio Estevam /* Reused from common.h */
3021411fb37SFabio Estevam #define ROUND(a, b)		(((a) + (b) - 1) & ~((b) - 1))
3031411fb37SFabio Estevam 
3045b1d7137Swdenk /*
3059a4daad0SMarian Balakowicz  * Legacy format image header,
3069a4daad0SMarian Balakowicz  * all data in network byte order (aka natural aka bigendian).
3075b1d7137Swdenk  */
3085b1d7137Swdenk typedef struct image_header {
3092f220500SKim Phillips 	__be32		ih_magic;	/* Image Header Magic Number	*/
3102f220500SKim Phillips 	__be32		ih_hcrc;	/* Image Header CRC Checksum	*/
3112f220500SKim Phillips 	__be32		ih_time;	/* Image Creation Timestamp	*/
3122f220500SKim Phillips 	__be32		ih_size;	/* Image Data Size		*/
3132f220500SKim Phillips 	__be32		ih_load;	/* Data	 Load  Address		*/
3142f220500SKim Phillips 	__be32		ih_ep;		/* Entry Point Address		*/
3152f220500SKim Phillips 	__be32		ih_dcrc;	/* Image Data CRC Checksum	*/
3165b1d7137Swdenk 	uint8_t		ih_os;		/* Operating System		*/
3175b1d7137Swdenk 	uint8_t		ih_arch;	/* CPU architecture		*/
3185b1d7137Swdenk 	uint8_t		ih_type;	/* Image Type			*/
3195b1d7137Swdenk 	uint8_t		ih_comp;	/* Compression Type		*/
3205b1d7137Swdenk 	uint8_t		ih_name[IH_NMLEN];	/* Image Name		*/
3215b1d7137Swdenk } image_header_t;
3225b1d7137Swdenk 
323396f635bSKumar Gala typedef struct image_info {
324396f635bSKumar Gala 	ulong		start, end;		/* start/end of blob */
325396f635bSKumar Gala 	ulong		image_start, image_len; /* start of image within blob, len of image */
326396f635bSKumar Gala 	ulong		load;			/* load addr for the image */
327396f635bSKumar Gala 	uint8_t		comp, type, os;		/* compression, type of image, os type */
32890268b87SSimon Glass 	uint8_t		arch;			/* CPU architecture */
329396f635bSKumar Gala } image_info_t;
330396f635bSKumar Gala 
331559316faSMarian Balakowicz /*
332d5934ad7SMarian Balakowicz  * Legacy and FIT format headers used by do_bootm() and do_bootm_<os>()
333d5934ad7SMarian Balakowicz  * routines.
334d5934ad7SMarian Balakowicz  */
335d5934ad7SMarian Balakowicz typedef struct bootm_headers {
336d5934ad7SMarian Balakowicz 	/*
337d5934ad7SMarian Balakowicz 	 * Legacy os image header, if it is a multi component image
3389a4daad0SMarian Balakowicz 	 * then boot_get_ramdisk() and get_fdt() will attempt to get
339d5934ad7SMarian Balakowicz 	 * data from second and third component accordingly.
340d5934ad7SMarian Balakowicz 	 */
341cb1c4896SMarian Balakowicz 	image_header_t	*legacy_hdr_os;		/* image header pointer */
342cb1c4896SMarian Balakowicz 	image_header_t	legacy_hdr_os_copy;	/* header copy */
343d5934ad7SMarian Balakowicz 	ulong		legacy_hdr_valid;
344d5934ad7SMarian Balakowicz 
34573223f0eSSimon Glass #if IMAGE_ENABLE_FIT
346f773bea8SMarian Balakowicz 	const char	*fit_uname_cfg;	/* configuration node unit name */
347f773bea8SMarian Balakowicz 
348d5934ad7SMarian Balakowicz 	void		*fit_hdr_os;	/* os FIT image header */
349eb6175edSMarian Balakowicz 	const char	*fit_uname_os;	/* os subimage node unit name */
3503dfe1101SMarian Balakowicz 	int		fit_noffset_os;	/* os subimage node offset */
351d5934ad7SMarian Balakowicz 
352d5934ad7SMarian Balakowicz 	void		*fit_hdr_rd;	/* init ramdisk FIT image header */
3533dfe1101SMarian Balakowicz 	const char	*fit_uname_rd;	/* init ramdisk subimage node unit name */
3543dfe1101SMarian Balakowicz 	int		fit_noffset_rd;	/* init ramdisk subimage node offset */
355d5934ad7SMarian Balakowicz 
356d5934ad7SMarian Balakowicz 	void		*fit_hdr_fdt;	/* FDT blob FIT image header */
3573dfe1101SMarian Balakowicz 	const char	*fit_uname_fdt;	/* FDT blob subimage node unit name */
3583dfe1101SMarian Balakowicz 	int		fit_noffset_fdt;/* FDT blob subimage node offset */
35990268b87SSimon Glass 
36090268b87SSimon Glass 	void		*fit_hdr_setup;	/* x86 setup FIT image header */
36190268b87SSimon Glass 	const char	*fit_uname_setup; /* x86 setup subimage node name */
36290268b87SSimon Glass 	int		fit_noffset_setup;/* x86 setup subimage node offset */
363d5934ad7SMarian Balakowicz #endif
3641ec73761SMarian Balakowicz 
36549c3a861SKumar Gala #ifndef USE_HOSTCC
366396f635bSKumar Gala 	image_info_t	os;		/* os image info */
367c160a954SKumar Gala 	ulong		ep;		/* entry point of OS */
368c160a954SKumar Gala 
369c4f9419cSKumar Gala 	ulong		rd_start, rd_end;/* ramdisk start/end */
370c4f9419cSKumar Gala 
37106a09918SKumar Gala 	char		*ft_addr;	/* flat dev tree address */
37206a09918SKumar Gala 	ulong		ft_len;		/* length of flat device tree */
37306a09918SKumar Gala 
37449c3a861SKumar Gala 	ulong		initrd_start;
37549c3a861SKumar Gala 	ulong		initrd_end;
37649c3a861SKumar Gala 	ulong		cmdline_start;
37749c3a861SKumar Gala 	ulong		cmdline_end;
37849c3a861SKumar Gala 	bd_t		*kbd;
37949c3a861SKumar Gala #endif
38049c3a861SKumar Gala 
38100caae6dSSimon Glass 	int		verify;		/* env_get("verify")[0] != 'n' */
38249c3a861SKumar Gala 
38349c3a861SKumar Gala #define	BOOTM_STATE_START	(0x00000001)
38435fc84faSSimon Glass #define	BOOTM_STATE_FINDOS	(0x00000002)
38535fc84faSSimon Glass #define	BOOTM_STATE_FINDOTHER	(0x00000004)
38635fc84faSSimon Glass #define	BOOTM_STATE_LOADOS	(0x00000008)
38735fc84faSSimon Glass #define	BOOTM_STATE_RAMDISK	(0x00000010)
38835fc84faSSimon Glass #define	BOOTM_STATE_FDT		(0x00000020)
38935fc84faSSimon Glass #define	BOOTM_STATE_OS_CMDLINE	(0x00000040)
39035fc84faSSimon Glass #define	BOOTM_STATE_OS_BD_T	(0x00000080)
39135fc84faSSimon Glass #define	BOOTM_STATE_OS_PREP	(0x00000100)
392d0ae31ebSSimon Glass #define	BOOTM_STATE_OS_FAKE_GO	(0x00000200)	/* 'Almost' run the OS */
393d0ae31ebSSimon Glass #define	BOOTM_STATE_OS_GO	(0x00000400)
39449c3a861SKumar Gala 	int		state;
39549c3a861SKumar Gala 
396a16028daSMike Frysinger #ifdef CONFIG_LMB
397e906cfaeSKumar Gala 	struct lmb	lmb;		/* for memory mgmt */
398e906cfaeSKumar Gala #endif
3994181c9faSJoseph Chen 
4004181c9faSJoseph Chen #ifdef CONFIG_FIT_ROLLBACK_PROTECT
4014181c9faSJoseph Chen 	u32 rollback_index;
4024181c9faSJoseph Chen #endif
403d5934ad7SMarian Balakowicz } bootm_headers_t;
404d5934ad7SMarian Balakowicz 
4051648a375SSimon Schwarz extern bootm_headers_t images;
4061648a375SSimon Schwarz 
407d5934ad7SMarian Balakowicz /*
408559316faSMarian Balakowicz  * Some systems (for example LWMON) have very short watchdog periods;
409559316faSMarian Balakowicz  * we must make sure to split long operations like memmove() or
4107590378fSBartlomiej Sieka  * checksum calculations into reasonable chunks.
411559316faSMarian Balakowicz  */
4127590378fSBartlomiej Sieka #ifndef CHUNKSZ
413559316faSMarian Balakowicz #define CHUNKSZ (64 * 1024)
4147590378fSBartlomiej Sieka #endif
4157590378fSBartlomiej Sieka 
4167590378fSBartlomiej Sieka #ifndef CHUNKSZ_CRC32
4177590378fSBartlomiej Sieka #define CHUNKSZ_CRC32 (64 * 1024)
4187590378fSBartlomiej Sieka #endif
4197590378fSBartlomiej Sieka 
4207590378fSBartlomiej Sieka #ifndef CHUNKSZ_MD5
4217590378fSBartlomiej Sieka #define CHUNKSZ_MD5 (64 * 1024)
4227590378fSBartlomiej Sieka #endif
4237590378fSBartlomiej Sieka 
4247590378fSBartlomiej Sieka #ifndef CHUNKSZ_SHA1
4257590378fSBartlomiej Sieka #define CHUNKSZ_SHA1 (64 * 1024)
4267590378fSBartlomiej Sieka #endif
427559316faSMarian Balakowicz 
42837566090SMike Frysinger #define uimage_to_cpu(x)		be32_to_cpu(x)
42937566090SMike Frysinger #define cpu_to_uimage(x)		cpu_to_be32(x)
430b97a2a0aSMarian Balakowicz 
431b029dddcSPrafulla Wadaskar /*
432b029dddcSPrafulla Wadaskar  * Translation table for entries of a specific type; used by
433b029dddcSPrafulla Wadaskar  * get_table_entry_id() and get_table_entry_name().
434b029dddcSPrafulla Wadaskar  */
435b029dddcSPrafulla Wadaskar typedef struct table_entry {
436b029dddcSPrafulla Wadaskar 	int	id;
437b029dddcSPrafulla Wadaskar 	char	*sname;		/* short (input) name to find table entry */
438b029dddcSPrafulla Wadaskar 	char	*lname;		/* long (output) name to print for messages */
439b029dddcSPrafulla Wadaskar } table_entry_t;
440b029dddcSPrafulla Wadaskar 
441b029dddcSPrafulla Wadaskar /*
442b029dddcSPrafulla Wadaskar  * get_table_entry_id() scans the translation table trying to find an
443b029dddcSPrafulla Wadaskar  * entry that matches the given short name. If a matching entry is
444b029dddcSPrafulla Wadaskar  * found, it's id is returned to the caller.
445b029dddcSPrafulla Wadaskar  */
4467edb186fSMike Frysinger int get_table_entry_id(const table_entry_t *table,
447b029dddcSPrafulla Wadaskar 		const char *table_name, const char *name);
448b029dddcSPrafulla Wadaskar /*
449b029dddcSPrafulla Wadaskar  * get_table_entry_name() scans the translation table trying to find
450b029dddcSPrafulla Wadaskar  * an entry that matches the given id. If a matching entry is found,
451b029dddcSPrafulla Wadaskar  * its long name is returned to the caller.
452b029dddcSPrafulla Wadaskar  */
4537edb186fSMike Frysinger char *get_table_entry_name(const table_entry_t *table, char *msg, int id);
454b029dddcSPrafulla Wadaskar 
455570abb0aSMarian Balakowicz const char *genimg_get_os_name(uint8_t os);
456cef2e514SSimon Glass 
457cef2e514SSimon Glass /**
458cef2e514SSimon Glass  * genimg_get_os_short_name() - get the short name for an OS
459cef2e514SSimon Glass  *
460cef2e514SSimon Glass  * @param os	OS (IH_OS_...)
461cef2e514SSimon Glass  * @return OS short name, or "unknown" if unknown
462cef2e514SSimon Glass  */
463cef2e514SSimon Glass const char *genimg_get_os_short_name(uint8_t comp);
464cef2e514SSimon Glass 
465570abb0aSMarian Balakowicz const char *genimg_get_arch_name(uint8_t arch);
466cef2e514SSimon Glass 
467cef2e514SSimon Glass /**
468cef2e514SSimon Glass  * genimg_get_arch_short_name() - get the short name for an architecture
469cef2e514SSimon Glass  *
470cef2e514SSimon Glass  * @param arch	Architecture type (IH_ARCH_...)
471cef2e514SSimon Glass  * @return architecture short name, or "unknown" if unknown
472cef2e514SSimon Glass  */
473cef2e514SSimon Glass const char *genimg_get_arch_short_name(uint8_t arch);
474cef2e514SSimon Glass 
475570abb0aSMarian Balakowicz const char *genimg_get_type_name(uint8_t type);
4765b9d44dfSSimon Glass 
4775b9d44dfSSimon Glass /**
4785b9d44dfSSimon Glass  * genimg_get_type_short_name() - get the short name for an image type
4795b9d44dfSSimon Glass  *
4805b9d44dfSSimon Glass  * @param type	Image type (IH_TYPE_...)
4815b9d44dfSSimon Glass  * @return image short name, or "unknown" if unknown
4825b9d44dfSSimon Glass  */
4835b9d44dfSSimon Glass const char *genimg_get_type_short_name(uint8_t type);
4845b9d44dfSSimon Glass 
485570abb0aSMarian Balakowicz const char *genimg_get_comp_name(uint8_t comp);
486cef2e514SSimon Glass 
487cef2e514SSimon Glass /**
488cef2e514SSimon Glass  * genimg_get_comp_short_name() - get the short name for a compression method
489cef2e514SSimon Glass  *
490cef2e514SSimon Glass  * @param comp	compression method (IH_COMP_...)
491cef2e514SSimon Glass  * @return compression method short name, or "unknown" if unknown
492cef2e514SSimon Glass  */
493cef2e514SSimon Glass const char *genimg_get_comp_short_name(uint8_t comp);
494cef2e514SSimon Glass 
4951426220bSSimon Glass /**
4961426220bSSimon Glass  * genimg_get_cat_name() - Get the name of an item in a category
4971426220bSSimon Glass  *
4981426220bSSimon Glass  * @category:	Category of item
4991426220bSSimon Glass  * @id:		Item ID
5001426220bSSimon Glass  * @return name of item, or "Unknown ..." if unknown
5011426220bSSimon Glass  */
5021426220bSSimon Glass const char *genimg_get_cat_name(enum ih_category category, uint id);
5031426220bSSimon Glass 
5041426220bSSimon Glass /**
5051426220bSSimon Glass  * genimg_get_cat_short_name() - Get the short name of an item in a category
5061426220bSSimon Glass  *
5071426220bSSimon Glass  * @category:	Category of item
5081426220bSSimon Glass  * @id:		Item ID
5091426220bSSimon Glass  * @return short name of item, or "Unknown ..." if unknown
5101426220bSSimon Glass  */
5111426220bSSimon Glass const char *genimg_get_cat_short_name(enum ih_category category, uint id);
5121426220bSSimon Glass 
5131426220bSSimon Glass /**
5141426220bSSimon Glass  * genimg_get_cat_count() - Get the number of items in a category
5151426220bSSimon Glass  *
5161426220bSSimon Glass  * @category:	Category to check
5171426220bSSimon Glass  * @return the number of items in the category (IH_xxx_COUNT)
5181426220bSSimon Glass  */
5191426220bSSimon Glass int genimg_get_cat_count(enum ih_category category);
5201426220bSSimon Glass 
5211426220bSSimon Glass /**
5221426220bSSimon Glass  * genimg_get_cat_desc() - Get the description of a category
5231426220bSSimon Glass  *
5241426220bSSimon Glass  * @return the description of a category, e.g. "architecture". This
5251426220bSSimon Glass  * effectively converts the enum to a string.
5261426220bSSimon Glass  */
5271426220bSSimon Glass const char *genimg_get_cat_desc(enum ih_category category);
5281426220bSSimon Glass 
529570abb0aSMarian Balakowicz int genimg_get_os_id(const char *name);
530570abb0aSMarian Balakowicz int genimg_get_arch_id(const char *name);
531570abb0aSMarian Balakowicz int genimg_get_type_id(const char *name);
532570abb0aSMarian Balakowicz int genimg_get_comp_id(const char *name);
533f666dea8SPrafulla Wadaskar void genimg_print_size(uint32_t size);
534570abb0aSMarian Balakowicz 
535859e92b7SSimon Glass #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || \
536859e92b7SSimon Glass 	defined(USE_HOSTCC)
537859e92b7SSimon Glass #define IMAGE_ENABLE_TIMESTAMP 1
538859e92b7SSimon Glass #else
539859e92b7SSimon Glass #define IMAGE_ENABLE_TIMESTAMP 0
540859e92b7SSimon Glass #endif
541859e92b7SSimon Glass void genimg_print_time(time_t timestamp);
542859e92b7SSimon Glass 
543782cfbb2SSimon Glass /* What to do with a image load address ('load = <> 'in the FIT) */
544782cfbb2SSimon Glass enum fit_load_op {
545782cfbb2SSimon Glass 	FIT_LOAD_IGNORED,	/* Ignore load address */
546782cfbb2SSimon Glass 	FIT_LOAD_OPTIONAL,	/* Can be provided, but optional */
547fe20a81aSSimon Glass 	FIT_LOAD_OPTIONAL_NON_ZERO,	/* Optional, a value of 0 is ignored */
548782cfbb2SSimon Glass 	FIT_LOAD_REQUIRED,	/* Must be provided */
549782cfbb2SSimon Glass };
550782cfbb2SSimon Glass 
55190268b87SSimon Glass int boot_get_setup(bootm_headers_t *images, uint8_t arch, ulong *setup_start,
55290268b87SSimon Glass 		   ulong *setup_len);
55390268b87SSimon Glass 
5549a4daad0SMarian Balakowicz #ifndef USE_HOSTCC
5559a4daad0SMarian Balakowicz /* Image format types, returned by _get_format() routine */
5569a4daad0SMarian Balakowicz #define IMAGE_FORMAT_INVALID	0x00
55721d29f7fSHeiko Schocher #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
5589a4daad0SMarian Balakowicz #define IMAGE_FORMAT_LEGACY	0x01	/* legacy image_header based format */
55921d29f7fSHeiko Schocher #endif
5609a4daad0SMarian Balakowicz #define IMAGE_FORMAT_FIT	0x02	/* new, libfdt based format */
5619ace3fc8SSebastian Siewior #define IMAGE_FORMAT_ANDROID	0x03	/* Android boot image */
5629a4daad0SMarian Balakowicz 
5636c454fedSBryan Wu ulong genimg_get_kernel_addr_fit(char * const img_addr,
5646c454fedSBryan Wu 			         const char **fit_uname_config,
5656c454fedSBryan Wu 			         const char **fit_uname_kernel);
5660f64140bSBryan Wu ulong genimg_get_kernel_addr(char * const img_addr);
56735e7b0f1SSimon Glass int genimg_get_format(const void *img_addr);
568f773bea8SMarian Balakowicz int genimg_has_config(bootm_headers_t *images);
5699a4daad0SMarian Balakowicz 
57062afc601SMichal Simek int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
57162afc601SMichal Simek 		uint8_t arch, const ulong *ld_start, ulong * const ld_len);
57254841ab5SWolfgang Denk int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
573d985c849SMarian Balakowicz 		uint8_t arch, ulong *rd_start, ulong *rd_end);
57484a07dbfSKarl Apsite 
57584a07dbfSKarl Apsite /**
57684a07dbfSKarl Apsite  * boot_get_loadable - routine to load a list of binaries to memory
57784a07dbfSKarl Apsite  * @argc: Ignored Argument
57884a07dbfSKarl Apsite  * @argv: Ignored Argument
57984a07dbfSKarl Apsite  * @images: pointer to the bootm images structure
58084a07dbfSKarl Apsite  * @arch: expected architecture for the image
58184a07dbfSKarl Apsite  * @ld_start: Ignored Argument
58284a07dbfSKarl Apsite  * @ld_len: Ignored Argument
58384a07dbfSKarl Apsite  *
58484a07dbfSKarl Apsite  * boot_get_loadable() will take the given FIT configuration, and look
58584a07dbfSKarl Apsite  * for a field named "loadables".  Loadables, is a list of elements in
58684a07dbfSKarl Apsite  * the FIT given as strings.  exe:
58784a07dbfSKarl Apsite  *   loadables = "linux_kernel@1", "fdt@2";
58884a07dbfSKarl Apsite  * this function will attempt to parse each string, and load the
58984a07dbfSKarl Apsite  * corresponding element from the FIT into memory.  Once placed,
59084a07dbfSKarl Apsite  * no aditional actions are taken.
59184a07dbfSKarl Apsite  *
59284a07dbfSKarl Apsite  * @return:
59384a07dbfSKarl Apsite  *     0, if only valid images or no images are found
59484a07dbfSKarl Apsite  *     error code, if an error occurs during fit_image_load
59584a07dbfSKarl Apsite  */
59684a07dbfSKarl Apsite int boot_get_loadable(int argc, char * const argv[], bootm_headers_t *images,
59784a07dbfSKarl Apsite 		uint8_t arch, const ulong *ld_start, ulong * const ld_len);
59884a07dbfSKarl Apsite #endif /* !USE_HOSTCC */
5999a4daad0SMarian Balakowicz 
60090268b87SSimon Glass int boot_get_setup_fit(bootm_headers_t *images, uint8_t arch,
60190268b87SSimon Glass 		       ulong *setup_start, ulong *setup_len);
60290268b87SSimon Glass 
603782cfbb2SSimon Glass /**
604988a4042SPantelis Antoniou  * boot_get_fdt_fit() - load a DTB from a FIT file (applying overlays)
605988a4042SPantelis Antoniou  *
606988a4042SPantelis Antoniou  * This deals with all aspects of loading an DTB from a FIT.
607988a4042SPantelis Antoniou  * The correct base image based on configuration will be selected, and
608988a4042SPantelis Antoniou  * then any overlays specified will be applied (as present in fit_uname_configp).
609988a4042SPantelis Antoniou  *
610988a4042SPantelis Antoniou  * @param images	Boot images structure
611988a4042SPantelis Antoniou  * @param addr		Address of FIT in memory
612988a4042SPantelis Antoniou  * @param fit_unamep	On entry this is the requested image name
613988a4042SPantelis Antoniou  *			(e.g. "kernel@1") or NULL to use the default. On exit
614988a4042SPantelis Antoniou  *			points to the selected image name
615988a4042SPantelis Antoniou  * @param fit_uname_configp	On entry this is the requested configuration
616988a4042SPantelis Antoniou  *			name (e.g. "conf@1") or NULL to use the default. On
617988a4042SPantelis Antoniou  *			exit points to the selected configuration name.
618988a4042SPantelis Antoniou  * @param arch		Expected architecture (IH_ARCH_...)
619988a4042SPantelis Antoniou  * @param datap		Returns address of loaded image
620988a4042SPantelis Antoniou  * @param lenp		Returns length of loaded image
621988a4042SPantelis Antoniou  *
622988a4042SPantelis Antoniou  * @return node offset of base image, or -ve error code on error
623988a4042SPantelis Antoniou  */
624988a4042SPantelis Antoniou int boot_get_fdt_fit(bootm_headers_t *images, ulong addr,
625988a4042SPantelis Antoniou 		   const char **fit_unamep, const char **fit_uname_configp,
626988a4042SPantelis Antoniou 		   int arch, ulong *datap, ulong *lenp);
627988a4042SPantelis Antoniou 
628988a4042SPantelis Antoniou /**
629782cfbb2SSimon Glass  * fit_image_load() - load an image from a FIT
630782cfbb2SSimon Glass  *
631782cfbb2SSimon Glass  * This deals with all aspects of loading an image from a FIT, including
632782cfbb2SSimon Glass  * selecting the right image based on configuration, verifying it, printing
633782cfbb2SSimon Glass  * out progress messages, checking the type/arch/os and optionally copying it
634782cfbb2SSimon Glass  * to the right load address.
635782cfbb2SSimon Glass  *
636126cc864SSimon Glass  * The property to look up is defined by image_type.
637126cc864SSimon Glass  *
638782cfbb2SSimon Glass  * @param images	Boot images structure
639782cfbb2SSimon Glass  * @param addr		Address of FIT in memory
640782cfbb2SSimon Glass  * @param fit_unamep	On entry this is the requested image name
641782cfbb2SSimon Glass  *			(e.g. "kernel@1") or NULL to use the default. On exit
642782cfbb2SSimon Glass  *			points to the selected image name
643f320a4d8SSimon Glass  * @param fit_uname_configp	On entry this is the requested configuration
644f320a4d8SSimon Glass  *			name (e.g. "conf@1") or NULL to use the default. On
645f320a4d8SSimon Glass  *			exit points to the selected configuration name.
646782cfbb2SSimon Glass  * @param arch		Expected architecture (IH_ARCH_...)
647782cfbb2SSimon Glass  * @param image_type	Required image type (IH_TYPE_...). If this is
648782cfbb2SSimon Glass  *			IH_TYPE_KERNEL then we allow IH_TYPE_KERNEL_NOLOAD
649782cfbb2SSimon Glass  *			also.
650782cfbb2SSimon Glass  * @param bootstage_id	ID of starting bootstage to use for progress updates.
651782cfbb2SSimon Glass  *			This will be added to the BOOTSTAGE_SUB values when
652782cfbb2SSimon Glass  *			calling bootstage_mark()
653782cfbb2SSimon Glass  * @param load_op	Decribes what to do with the load address
654782cfbb2SSimon Glass  * @param datap		Returns address of loaded image
655782cfbb2SSimon Glass  * @param lenp		Returns length of loaded image
656ce1400f6SSimon Glass  * @return node offset of image, or -ve error code on error
657782cfbb2SSimon Glass  */
658126cc864SSimon Glass int fit_image_load(bootm_headers_t *images, ulong addr,
659f320a4d8SSimon Glass 		   const char **fit_unamep, const char **fit_uname_configp,
660782cfbb2SSimon Glass 		   int arch, int image_type, int bootstage_id,
661782cfbb2SSimon Glass 		   enum fit_load_op load_op, ulong *datap, ulong *lenp);
662782cfbb2SSimon Glass 
66396f5441eSJoseph Chen int fit_image_load_index(bootm_headers_t *images, ulong addr,
66496f5441eSJoseph Chen 		   const char **fit_unamep, const char **fit_uname_configp,
66596f5441eSJoseph Chen 		   int arch, int image_type, int image_index, int bootstage_id,
66696f5441eSJoseph Chen 		   enum fit_load_op load_op, ulong *datap, ulong *lenp);
66796f5441eSJoseph Chen 
668ce1400f6SSimon Glass #ifndef USE_HOSTCC
669782cfbb2SSimon Glass /**
670782cfbb2SSimon Glass  * fit_get_node_from_config() - Look up an image a FIT by type
671782cfbb2SSimon Glass  *
672782cfbb2SSimon Glass  * This looks in the selected conf@ node (images->fit_uname_cfg) for a
673782cfbb2SSimon Glass  * particular image type (e.g. "kernel") and then finds the image that is
674782cfbb2SSimon Glass  * referred to.
675782cfbb2SSimon Glass  *
676782cfbb2SSimon Glass  * For example, for something like:
677782cfbb2SSimon Glass  *
678782cfbb2SSimon Glass  * images {
679782cfbb2SSimon Glass  *	kernel@1 {
680782cfbb2SSimon Glass  *		...
681782cfbb2SSimon Glass  *	};
682782cfbb2SSimon Glass  * };
683782cfbb2SSimon Glass  * configurations {
684782cfbb2SSimon Glass  *	conf@1 {
685782cfbb2SSimon Glass  *		kernel = "kernel@1";
686782cfbb2SSimon Glass  *	};
687782cfbb2SSimon Glass  * };
688782cfbb2SSimon Glass  *
689782cfbb2SSimon Glass  * the function will return the node offset of the kernel@1 node, assuming
690782cfbb2SSimon Glass  * that conf@1 is the chosen configuration.
691782cfbb2SSimon Glass  *
692782cfbb2SSimon Glass  * @param images	Boot images structure
693782cfbb2SSimon Glass  * @param prop_name	Property name to look up (FIT_..._PROP)
694782cfbb2SSimon Glass  * @param addr		Address of FIT in memory
695782cfbb2SSimon Glass  */
696782cfbb2SSimon Glass int fit_get_node_from_config(bootm_headers_t *images, const char *prop_name,
697782cfbb2SSimon Glass 			ulong addr);
698782cfbb2SSimon Glass 
69953f375faSSimon Glass int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
70053f375faSSimon Glass 		 bootm_headers_t *images,
70153f375faSSimon Glass 		 char **of_flat_tree, ulong *of_size);
70255b0a393SGrant Likely void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob);
703a384e3f1SJoseph Chen #ifdef CONFIG_SYSMEM
704a384e3f1SJoseph Chen int boot_fdt_add_sysmem_rsv_regions(void *fdt_blob);
7056e15146eSJoseph Chen #else
7066e15146eSJoseph Chen static inline int boot_fdt_add_sysmem_rsv_regions(void *fdt_blob) { return 0; }
707a384e3f1SJoseph Chen #endif
708590d3cacSGrant Likely int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size);
70906a09918SKumar Gala 
7109a4daad0SMarian Balakowicz int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len,
7119a4daad0SMarian Balakowicz 		  ulong *initrd_start, ulong *initrd_end);
712590d3cacSGrant Likely int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end);
713fca43cc8SJohn Rigby #ifdef CONFIG_SYS_BOOT_GET_KBD
714590d3cacSGrant Likely int boot_get_kbd(struct lmb *lmb, bd_t **kbd);
715fca43cc8SJohn Rigby #endif /* CONFIG_SYS_BOOT_GET_KBD */
716570abb0aSMarian Balakowicz #endif /* !USE_HOSTCC */
7179a4daad0SMarian Balakowicz 
7189a4daad0SMarian Balakowicz /*******************************************************************/
7199a4daad0SMarian Balakowicz /* Legacy format specific code (prefixed with image_) */
7209a4daad0SMarian Balakowicz /*******************************************************************/
72140d08d0fSJoseph Chen #define IMAGE_PARAM_INVAL	0xffffffff
72240d08d0fSJoseph Chen 
723b97a2a0aSMarian Balakowicz static inline uint32_t image_get_header_size(void)
724b97a2a0aSMarian Balakowicz {
725b97a2a0aSMarian Balakowicz 	return (sizeof(image_header_t));
726b97a2a0aSMarian Balakowicz }
727b97a2a0aSMarian Balakowicz 
728b97a2a0aSMarian Balakowicz #define image_get_hdr_l(f) \
7293a2003f6SWolfgang Denk 	static inline uint32_t image_get_##f(const image_header_t *hdr) \
730b97a2a0aSMarian Balakowicz 	{ \
7319a4daad0SMarian Balakowicz 		return uimage_to_cpu(hdr->ih_##f); \
732b97a2a0aSMarian Balakowicz 	}
733178e26d7SWolfgang Denk image_get_hdr_l(magic)		/* image_get_magic */
734178e26d7SWolfgang Denk image_get_hdr_l(hcrc)		/* image_get_hcrc */
735178e26d7SWolfgang Denk image_get_hdr_l(time)		/* image_get_time */
736178e26d7SWolfgang Denk image_get_hdr_l(size)		/* image_get_size */
737957222d7SJoseph Chen image_get_hdr_l(dcrc)		/* image_get_dcrc */
738957222d7SJoseph Chen #ifdef USE_HOSTCC
739178e26d7SWolfgang Denk image_get_hdr_l(load)		/* image_get_load */
740178e26d7SWolfgang Denk image_get_hdr_l(ep)		/* image_get_ep */
741957222d7SJoseph Chen #elif defined(CONFIG_SPL_BUILD)
742957222d7SJoseph Chen image_get_hdr_l(load)		/* image_get_load */
743957222d7SJoseph Chen image_get_hdr_l(ep)		/* image_get_ep */
744957222d7SJoseph Chen #else
745957222d7SJoseph Chen uint32_t image_get_load(const image_header_t *hdr);
746957222d7SJoseph Chen uint32_t image_get_ep(const image_header_t *hdr);
747957222d7SJoseph Chen #endif
748b97a2a0aSMarian Balakowicz 
749b97a2a0aSMarian Balakowicz #define image_get_hdr_b(f) \
7503a2003f6SWolfgang Denk 	static inline uint8_t image_get_##f(const image_header_t *hdr) \
751b97a2a0aSMarian Balakowicz 	{ \
752b97a2a0aSMarian Balakowicz 		return hdr->ih_##f; \
753b97a2a0aSMarian Balakowicz 	}
754178e26d7SWolfgang Denk image_get_hdr_b(os)		/* image_get_os */
755178e26d7SWolfgang Denk image_get_hdr_b(arch)		/* image_get_arch */
756178e26d7SWolfgang Denk image_get_hdr_b(type)		/* image_get_type */
757178e26d7SWolfgang Denk image_get_hdr_b(comp)		/* image_get_comp */
758b97a2a0aSMarian Balakowicz 
7593a2003f6SWolfgang Denk static inline char *image_get_name(const image_header_t *hdr)
760b97a2a0aSMarian Balakowicz {
761b97a2a0aSMarian Balakowicz 	return (char *)hdr->ih_name;
762b97a2a0aSMarian Balakowicz }
763b97a2a0aSMarian Balakowicz 
7643a2003f6SWolfgang Denk static inline uint32_t image_get_data_size(const image_header_t *hdr)
765b97a2a0aSMarian Balakowicz {
766b97a2a0aSMarian Balakowicz 	return image_get_size(hdr);
767b97a2a0aSMarian Balakowicz }
768f13e7b2eSMarian Balakowicz 
769f13e7b2eSMarian Balakowicz /**
770f13e7b2eSMarian Balakowicz  * image_get_data - get image payload start address
771f13e7b2eSMarian Balakowicz  * @hdr: image header
772f13e7b2eSMarian Balakowicz  *
773f13e7b2eSMarian Balakowicz  * image_get_data() returns address of the image payload. For single
774f13e7b2eSMarian Balakowicz  * component images it is image data start. For multi component
775f13e7b2eSMarian Balakowicz  * images it points to the null terminated table of sub-images sizes.
776f13e7b2eSMarian Balakowicz  *
777f13e7b2eSMarian Balakowicz  * returns:
778f13e7b2eSMarian Balakowicz  *     image payload data start address
779f13e7b2eSMarian Balakowicz  */
7803a2003f6SWolfgang Denk static inline ulong image_get_data(const image_header_t *hdr)
781f13e7b2eSMarian Balakowicz {
782f13e7b2eSMarian Balakowicz 	return ((ulong)hdr + image_get_header_size());
783f13e7b2eSMarian Balakowicz }
784f13e7b2eSMarian Balakowicz 
7853a2003f6SWolfgang Denk static inline uint32_t image_get_image_size(const image_header_t *hdr)
786b97a2a0aSMarian Balakowicz {
787b97a2a0aSMarian Balakowicz 	return (image_get_size(hdr) + image_get_header_size());
788b97a2a0aSMarian Balakowicz }
7893a2003f6SWolfgang Denk static inline ulong image_get_image_end(const image_header_t *hdr)
790b97a2a0aSMarian Balakowicz {
791f13e7b2eSMarian Balakowicz 	return ((ulong)hdr + image_get_image_size(hdr));
792b97a2a0aSMarian Balakowicz }
793b97a2a0aSMarian Balakowicz 
794b97a2a0aSMarian Balakowicz #define image_set_hdr_l(f) \
795b97a2a0aSMarian Balakowicz 	static inline void image_set_##f(image_header_t *hdr, uint32_t val) \
796b97a2a0aSMarian Balakowicz 	{ \
7979a4daad0SMarian Balakowicz 		hdr->ih_##f = cpu_to_uimage(val); \
798b97a2a0aSMarian Balakowicz 	}
799178e26d7SWolfgang Denk image_set_hdr_l(magic)		/* image_set_magic */
800178e26d7SWolfgang Denk image_set_hdr_l(hcrc)		/* image_set_hcrc */
801178e26d7SWolfgang Denk image_set_hdr_l(time)		/* image_set_time */
802178e26d7SWolfgang Denk image_set_hdr_l(size)		/* image_set_size */
803178e26d7SWolfgang Denk image_set_hdr_l(load)		/* image_set_load */
804178e26d7SWolfgang Denk image_set_hdr_l(ep)		/* image_set_ep */
805178e26d7SWolfgang Denk image_set_hdr_l(dcrc)		/* image_set_dcrc */
806b97a2a0aSMarian Balakowicz 
807b97a2a0aSMarian Balakowicz #define image_set_hdr_b(f) \
808b97a2a0aSMarian Balakowicz 	static inline void image_set_##f(image_header_t *hdr, uint8_t val) \
809b97a2a0aSMarian Balakowicz 	{ \
810b97a2a0aSMarian Balakowicz 		hdr->ih_##f = val; \
811b97a2a0aSMarian Balakowicz 	}
812178e26d7SWolfgang Denk image_set_hdr_b(os)		/* image_set_os */
813178e26d7SWolfgang Denk image_set_hdr_b(arch)		/* image_set_arch */
814178e26d7SWolfgang Denk image_set_hdr_b(type)		/* image_set_type */
815178e26d7SWolfgang Denk image_set_hdr_b(comp)		/* image_set_comp */
816b97a2a0aSMarian Balakowicz 
817b97a2a0aSMarian Balakowicz static inline void image_set_name(image_header_t *hdr, const char *name)
818b97a2a0aSMarian Balakowicz {
819b97a2a0aSMarian Balakowicz 	strncpy(image_get_name(hdr), name, IH_NMLEN);
820b97a2a0aSMarian Balakowicz }
821b97a2a0aSMarian Balakowicz 
8223a2003f6SWolfgang Denk int image_check_hcrc(const image_header_t *hdr);
8233a2003f6SWolfgang Denk int image_check_dcrc(const image_header_t *hdr);
824af13cdbcSMarian Balakowicz #ifndef USE_HOSTCC
825723806ccSSimon Glass ulong env_get_bootm_low(void);
826723806ccSSimon Glass phys_size_t env_get_bootm_size(void);
827723806ccSSimon Glass phys_size_t env_get_bootm_mapsize(void);
828af13cdbcSMarian Balakowicz #endif
829ce1400f6SSimon Glass void memmove_wd(void *to, void *from, size_t len, ulong chunksz);
830b97a2a0aSMarian Balakowicz 
8313a2003f6SWolfgang Denk static inline int image_check_magic(const image_header_t *hdr)
832b97a2a0aSMarian Balakowicz {
833b97a2a0aSMarian Balakowicz 	return (image_get_magic(hdr) == IH_MAGIC);
834b97a2a0aSMarian Balakowicz }
8353a2003f6SWolfgang Denk static inline int image_check_type(const image_header_t *hdr, uint8_t type)
836b97a2a0aSMarian Balakowicz {
837b97a2a0aSMarian Balakowicz 	return (image_get_type(hdr) == type);
838b97a2a0aSMarian Balakowicz }
8393a2003f6SWolfgang Denk static inline int image_check_arch(const image_header_t *hdr, uint8_t arch)
840b97a2a0aSMarian Balakowicz {
8414ac0a32eSAlison Wang 	return (image_get_arch(hdr) == arch) ||
8424ac0a32eSAlison Wang 		(image_get_arch(hdr) == IH_ARCH_ARM && arch == IH_ARCH_ARM64);
843b97a2a0aSMarian Balakowicz }
8443a2003f6SWolfgang Denk static inline int image_check_os(const image_header_t *hdr, uint8_t os)
845b97a2a0aSMarian Balakowicz {
846b97a2a0aSMarian Balakowicz 	return (image_get_os(hdr) == os);
847b97a2a0aSMarian Balakowicz }
848b97a2a0aSMarian Balakowicz 
8493a2003f6SWolfgang Denk ulong image_multi_count(const image_header_t *hdr);
8503a2003f6SWolfgang Denk void image_multi_getimg(const image_header_t *hdr, ulong idx,
85142b73e8eSMarian Balakowicz 			ulong *data, ulong *len);
85242b73e8eSMarian Balakowicz 
8533a2003f6SWolfgang Denk void image_print_contents(const void *hdr);
854570abb0aSMarian Balakowicz 
855b97a2a0aSMarian Balakowicz #ifndef USE_HOSTCC
8563a2003f6SWolfgang Denk static inline int image_check_target_arch(const image_header_t *hdr)
857b97a2a0aSMarian Balakowicz {
858476af299SMike Frysinger #ifndef IH_ARCH_DEFAULT
859476af299SMike Frysinger # error "please define IH_ARCH_DEFAULT in your arch asm/u-boot.h"
860b97a2a0aSMarian Balakowicz #endif
861476af299SMike Frysinger 	return image_check_arch(hdr, IH_ARCH_DEFAULT);
862b97a2a0aSMarian Balakowicz }
8635dfb5213SMarian Balakowicz #endif /* USE_HOSTCC */
8645b1d7137Swdenk 
86513d06981SSimon Glass /**
86613d06981SSimon Glass  * Set up properties in the FDT
86713d06981SSimon Glass  *
86813d06981SSimon Glass  * This sets up properties in the FDT that is to be passed to linux.
86913d06981SSimon Glass  *
87013d06981SSimon Glass  * @images:	Images information
87113d06981SSimon Glass  * @blob:	FDT to update
87213d06981SSimon Glass  * @of_size:	Size of the FDT
87313d06981SSimon Glass  * @lmb:	Points to logical memory block structure
87413d06981SSimon Glass  * @return 0 if ok, <0 on failure
87513d06981SSimon Glass  */
87613d06981SSimon Glass int image_setup_libfdt(bootm_headers_t *images, void *blob,
87713d06981SSimon Glass 		       int of_size, struct lmb *lmb);
87813d06981SSimon Glass 
87913d06981SSimon Glass /**
88013d06981SSimon Glass  * Set up the FDT to use for booting a kernel
88113d06981SSimon Glass  *
88213d06981SSimon Glass  * This performs ramdisk setup, sets up the FDT if required, and adds
88313d06981SSimon Glass  * paramters to the FDT if libfdt is available.
88413d06981SSimon Glass  *
88513d06981SSimon Glass  * @param images	Images information
88613d06981SSimon Glass  * @return 0 if ok, <0 on failure
88713d06981SSimon Glass  */
88813d06981SSimon Glass int image_setup_linux(bootm_headers_t *images);
88913d06981SSimon Glass 
890a5266d6bSSimon Glass /**
891a5266d6bSSimon Glass  * bootz_setup() - Extract stat and size of a Linux xImage
892a5266d6bSSimon Glass  *
893a5266d6bSSimon Glass  * @image: Address of image
894a5266d6bSSimon Glass  * @start: Returns start address of image
895a5266d6bSSimon Glass  * @end : Returns end address of image
896a5266d6bSSimon Glass  * @return 0 if OK, 1 if the image was not recognised
897a5266d6bSSimon Glass  */
898a5266d6bSSimon Glass int bootz_setup(ulong image, ulong *start, ulong *end);
899a5266d6bSSimon Glass 
900a5266d6bSSimon Glass 
901d5934ad7SMarian Balakowicz /*******************************************************************/
9029a4daad0SMarian Balakowicz /* New uImage format specific code (prefixed with fit_) */
903d5934ad7SMarian Balakowicz /*******************************************************************/
9045dfb5213SMarian Balakowicz 
9055dfb5213SMarian Balakowicz #define FIT_IMAGES_PATH		"/images"
9065dfb5213SMarian Balakowicz #define FIT_CONFS_PATH		"/configurations"
9075dfb5213SMarian Balakowicz 
9083e569a6bSSimon Glass /* hash/signature node */
9095dfb5213SMarian Balakowicz #define FIT_HASH_NODENAME	"hash"
9105dfb5213SMarian Balakowicz #define FIT_ALGO_PROP		"algo"
9115dfb5213SMarian Balakowicz #define FIT_VALUE_PROP		"value"
9128ac88f2dSJoe Hershberger #define FIT_IGNORE_PROP		"uboot-ignore"
9133e569a6bSSimon Glass #define FIT_SIG_NODENAME	"signature"
9145dfb5213SMarian Balakowicz 
9155dfb5213SMarian Balakowicz /* image node */
9165dfb5213SMarian Balakowicz #define FIT_DATA_PROP		"data"
917b86dc419SPeng Fan #define FIT_DATA_POSITION_PROP	"data-position"
918db1b79b8Stomas.melin@vaisala.com #define FIT_DATA_OFFSET_PROP	"data-offset"
919db1b79b8Stomas.melin@vaisala.com #define FIT_DATA_SIZE_PROP	"data-size"
9205dfb5213SMarian Balakowicz #define FIT_TIMESTAMP_PROP	"timestamp"
9215dfb5213SMarian Balakowicz #define FIT_DESC_PROP		"description"
9225dfb5213SMarian Balakowicz #define FIT_ARCH_PROP		"arch"
9235dfb5213SMarian Balakowicz #define FIT_TYPE_PROP		"type"
9245dfb5213SMarian Balakowicz #define FIT_OS_PROP		"os"
9255dfb5213SMarian Balakowicz #define FIT_COMP_PROP		"compression"
9265dfb5213SMarian Balakowicz #define FIT_ENTRY_PROP		"entry"
9275dfb5213SMarian Balakowicz #define FIT_LOAD_PROP		"load"
928d871c071SJoseph Chen #define FIT_ROLLBACK_PROP	"rollback-index"
9295dfb5213SMarian Balakowicz 
9305dfb5213SMarian Balakowicz /* configuration node */
9315dfb5213SMarian Balakowicz #define FIT_KERNEL_PROP		"kernel"
9325dfb5213SMarian Balakowicz #define FIT_RAMDISK_PROP	"ramdisk"
9335dfb5213SMarian Balakowicz #define FIT_FDT_PROP		"fdt"
934ac459efdSJoseph Chen #define FIT_MULTI_PROP		"multi"
935ecf8cd65SKarl Apsite #define FIT_LOADABLE_PROP	"loadables"
9365dfb5213SMarian Balakowicz #define FIT_DEFAULT_PROP	"default"
93790268b87SSimon Glass #define FIT_SETUP_PROP		"setup"
938ed0cea7cSMichal Simek #define FIT_FPGA_PROP		"fpga"
939c04fe8bfSMichal Simek #define FIT_FIRMWARE_PROP	"firmware"
940*f2413b2fSMarek Vasut #define FIT_STANDALONE_PROP	"standalone"
9415dfb5213SMarian Balakowicz 
9421de7bb4fSMichael van der Westhuizen #define FIT_MAX_HASH_LEN	HASH_MAX_DIGEST_SIZE
9435dfb5213SMarian Balakowicz 
944f1dcee59SSimon Glass #if IMAGE_ENABLE_FIT
945acd43290SJoseph Chen 
946acd43290SJoseph Chen #ifndef IMAGE_ALIGN_SIZE
947acd43290SJoseph Chen #define IMAGE_ALIGN_SIZE	512
948acd43290SJoseph Chen #endif
949acd43290SJoseph Chen #define FIT_ALIGN(x)		(((x)+IMAGE_ALIGN_SIZE-1)&~(IMAGE_ALIGN_SIZE-1))
950acd43290SJoseph Chen 
9517a137075SJoseph Chen /* fit rollback index file description magic */
9527a137075SJoseph Chen #define FIT_ROLLBACK_INDEX	0xf1de0001
9537a137075SJoseph Chen #define FIT_ROLLBACK_INDEX_SPL	0xf1de8002
9547a137075SJoseph Chen 
9555dfb5213SMarian Balakowicz /* cmdline argument format parsing */
956314f634bSMike Frysinger int fit_parse_conf(const char *spec, ulong addr_curr,
957f50433d6SMarian Balakowicz 		ulong *addr, const char **conf_name);
958314f634bSMike Frysinger int fit_parse_subimage(const char *spec, ulong addr_curr,
959f50433d6SMarian Balakowicz 		ulong *addr, const char **image_name);
960d5934ad7SMarian Balakowicz 
96139931f96SGuilherme Maciel Ferreira int fit_get_subimage_count(const void *fit, int images_noffset);
962edbed247SBartlomiej Sieka void fit_print_contents(const void *fit);
9635dfb5213SMarian Balakowicz void fit_image_print(const void *fit, int noffset, const char *p);
9645dfb5213SMarian Balakowicz 
9655dfb5213SMarian Balakowicz /**
9665dfb5213SMarian Balakowicz  * fit_get_end - get FIT image size
9675dfb5213SMarian Balakowicz  * @fit: pointer to the FIT format image header
9685dfb5213SMarian Balakowicz  *
9695dfb5213SMarian Balakowicz  * returns:
9705dfb5213SMarian Balakowicz  *     size of the FIT image (blob) in memory
9715dfb5213SMarian Balakowicz  */
9725dfb5213SMarian Balakowicz static inline ulong fit_get_size(const void *fit)
9735dfb5213SMarian Balakowicz {
9745dfb5213SMarian Balakowicz 	return fdt_totalsize(fit);
9755dfb5213SMarian Balakowicz }
9765dfb5213SMarian Balakowicz 
9775dfb5213SMarian Balakowicz /**
9785dfb5213SMarian Balakowicz  * fit_get_end - get FIT image end
9795dfb5213SMarian Balakowicz  * @fit: pointer to the FIT format image header
9805dfb5213SMarian Balakowicz  *
9815dfb5213SMarian Balakowicz  * returns:
9825dfb5213SMarian Balakowicz  *     end address of the FIT image (blob) in memory
9835dfb5213SMarian Balakowicz  */
9847a80de46SSimon Glass ulong fit_get_end(const void *fit);
9855dfb5213SMarian Balakowicz 
9865dfb5213SMarian Balakowicz /**
9875dfb5213SMarian Balakowicz  * fit_get_name - get FIT node name
9885dfb5213SMarian Balakowicz  * @fit: pointer to the FIT format image header
9895dfb5213SMarian Balakowicz  *
9905dfb5213SMarian Balakowicz  * returns:
9915dfb5213SMarian Balakowicz  *     NULL, on error
9925dfb5213SMarian Balakowicz  *     pointer to node name, on success
9935dfb5213SMarian Balakowicz  */
9945dfb5213SMarian Balakowicz static inline const char *fit_get_name(const void *fit_hdr,
9955dfb5213SMarian Balakowicz 		int noffset, int *len)
9965dfb5213SMarian Balakowicz {
9975dfb5213SMarian Balakowicz 	return fdt_get_name(fit_hdr, noffset, len);
9985dfb5213SMarian Balakowicz }
9995dfb5213SMarian Balakowicz 
10005dfb5213SMarian Balakowicz int fit_get_desc(const void *fit, int noffset, char **desc);
10015dfb5213SMarian Balakowicz int fit_get_timestamp(const void *fit, int noffset, time_t *timestamp);
10025dfb5213SMarian Balakowicz 
10035dfb5213SMarian Balakowicz int fit_image_get_node(const void *fit, const char *image_uname);
10045dfb5213SMarian Balakowicz int fit_image_get_os(const void *fit, int noffset, uint8_t *os);
10055dfb5213SMarian Balakowicz int fit_image_get_arch(const void *fit, int noffset, uint8_t *arch);
10065dfb5213SMarian Balakowicz int fit_image_get_type(const void *fit, int noffset, uint8_t *type);
10075dfb5213SMarian Balakowicz int fit_image_get_comp(const void *fit, int noffset, uint8_t *comp);
10085dfb5213SMarian Balakowicz int fit_image_get_load(const void *fit, int noffset, ulong *load);
10095dfb5213SMarian Balakowicz int fit_image_get_entry(const void *fit, int noffset, ulong *entry);
1010ac459efdSJoseph Chen int fit_image_set_load(const void *fit, int noffset, ulong load);
1011ac459efdSJoseph Chen int fit_image_set_entry(const void *fit, int noffset, ulong entry);
10125dfb5213SMarian Balakowicz int fit_image_get_data(const void *fit, int noffset,
10135dfb5213SMarian Balakowicz 				const void **data, size_t *size);
1014db1b79b8Stomas.melin@vaisala.com int fit_image_get_data_offset(const void *fit, int noffset, int *data_offset);
1015b86dc419SPeng Fan int fit_image_get_data_position(const void *fit, int noffset,
1016b86dc419SPeng Fan 				int *data_position);
1017db1b79b8Stomas.melin@vaisala.com int fit_image_get_data_size(const void *fit, int noffset, int *data_size);
1018d871c071SJoseph Chen int fit_image_get_rollback_index(const void *fit, int noffset, uint32_t *index);
10195dfb5213SMarian Balakowicz 
10205dfb5213SMarian Balakowicz int fit_image_hash_get_algo(const void *fit, int noffset, char **algo);
10215dfb5213SMarian Balakowicz int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value,
10225dfb5213SMarian Balakowicz 				int *value_len);
10235dfb5213SMarian Balakowicz 
10245dfb5213SMarian Balakowicz int fit_set_timestamp(void *fit, int noffset, time_t timestamp);
1025bbb467dcSSimon Glass 
1026d871c071SJoseph Chen int fit_get_image_defconf_node(const void *fit,
1027d871c071SJoseph Chen 			       int *images_noffset, int *def_noffset);
1028d871c071SJoseph Chen 
1029bbb467dcSSimon Glass /**
103056518e71SSimon Glass  * fit_add_verification_data() - add verification data to FIT image nodes
1031bbb467dcSSimon Glass  *
103256518e71SSimon Glass  * @keydir:	Directory containing keys
103356518e71SSimon Glass  * @kwydest:	FDT blob to write public key information to
103456518e71SSimon Glass  * @fit:	Pointer to the FIT format image header
103556518e71SSimon Glass  * @comment:	Comment to add to signature nodes
103656518e71SSimon Glass  * @require_keys: Mark all keys as 'required'
1037f1ca1fdeSGeorge McCollister  * @engine_id:	Engine to use for signing
103856518e71SSimon Glass  *
103956518e71SSimon Glass  * Adds hash values for all component images in the FIT blob.
104056518e71SSimon Glass  * Hashes are calculated for all component images which have hash subnodes
104156518e71SSimon Glass  * with algorithm property set to one of the supported hash algorithms.
104256518e71SSimon Glass  *
104356518e71SSimon Glass  * Also add signatures if signature nodes are present.
104456518e71SSimon Glass  *
104556518e71SSimon Glass  * returns
104656518e71SSimon Glass  *     0, on success
104756518e71SSimon Glass  *     libfdt error code, on failure
1048bbb467dcSSimon Glass  */
104956518e71SSimon Glass int fit_add_verification_data(const char *keydir, void *keydest, void *fit,
1050f1ca1fdeSGeorge McCollister 			      const char *comment, int require_keys,
1051f1ca1fdeSGeorge McCollister 			      const char *engine_id);
10525dfb5213SMarian Balakowicz 
10530833bf5eSJun Nie int fit_image_verify_with_data(const void *fit, int image_noffset,
10540833bf5eSJun Nie 			       const void *data, size_t size);
1055b8da8366SSimon Glass int fit_image_verify(const void *fit, int noffset);
1056782cfbb2SSimon Glass int fit_config_verify(const void *fit, int conf_noffset);
1057b8da8366SSimon Glass int fit_all_image_verify(const void *fit);
10585dfb5213SMarian Balakowicz int fit_image_check_os(const void *fit, int noffset, uint8_t os);
10595dfb5213SMarian Balakowicz int fit_image_check_arch(const void *fit, int noffset, uint8_t arch);
10605dfb5213SMarian Balakowicz int fit_image_check_type(const void *fit, int noffset, uint8_t type);
10615dfb5213SMarian Balakowicz int fit_image_check_comp(const void *fit, int noffset, uint8_t comp);
10625dfb5213SMarian Balakowicz int fit_check_format(const void *fit);
10635dfb5213SMarian Balakowicz 
1064d95f6ec7SGabe Black int fit_conf_find_compat(const void *fit, const void *fdt);
10655dfb5213SMarian Balakowicz int fit_conf_get_node(const void *fit, const char *conf_uname);
10667a137075SJoseph Chen int fit_rollback_index_verify(const void *fit, uint32_t rollback_fd,
10677a137075SJoseph Chen 			      uint32_t *this_index, uint32_t *min_index);
10685dfb5213SMarian Balakowicz 
1069003efd7dSSimon Glass /**
1070003efd7dSSimon Glass  * fit_conf_get_prop_node() - Get node refered to by a configuration
1071003efd7dSSimon Glass  * @fit:	FIT to check
1072003efd7dSSimon Glass  * @noffset:	Offset of conf@xxx node to check
1073003efd7dSSimon Glass  * @prop_name:	Property to read from the conf node
1074003efd7dSSimon Glass  *
1075003efd7dSSimon Glass  * The conf@ nodes contain references to other nodes, using properties
1076003efd7dSSimon Glass  * like 'kernel = "kernel@1"'. Given such a property name (e.g. "kernel"),
1077003efd7dSSimon Glass  * return the offset of the node referred to (e.g. offset of node
1078003efd7dSSimon Glass  * "/images/kernel@1".
1079003efd7dSSimon Glass  */
1080003efd7dSSimon Glass int fit_conf_get_prop_node(const void *fit, int noffset,
1081003efd7dSSimon Glass 		const char *prop_name);
1082003efd7dSSimon Glass 
1083583377c4SJoseph Chen int fit_conf_get_prop_node_index(const void *fit, int noffset,
1084583377c4SJoseph Chen 		const char *prop_name, int index);
1085583377c4SJoseph Chen 
10865dfb5213SMarian Balakowicz void fit_conf_print(const void *fit, int noffset, const char *p);
10875dfb5213SMarian Balakowicz 
108861a439a8SSimon Glass int fit_check_ramdisk(const void *fit, int os_noffset,
108961a439a8SSimon Glass 		uint8_t arch, int verify);
109061a439a8SSimon Glass 
1091604f23ddSSimon Glass int calculate_hash(const void *data, int data_len, const char *algo,
1092604f23ddSSimon Glass 			uint8_t *value, int *value_len);
1093604f23ddSSimon Glass 
1094782cfbb2SSimon Glass /*
10953e569a6bSSimon Glass  * At present we only support signing on the host, and verification on the
10963e569a6bSSimon Glass  * device
1097782cfbb2SSimon Glass  */
1098782cfbb2SSimon Glass #if defined(CONFIG_FIT_SIGNATURE)
1099782cfbb2SSimon Glass # ifdef USE_HOSTCC
11003e569a6bSSimon Glass #  define IMAGE_ENABLE_SIGN	1
110129a23f9dSHeiko Schocher #  define IMAGE_ENABLE_VERIFY	1
1102646257d1SHeiko Schocher # include  <openssl/evp.h>
1103782cfbb2SSimon Glass #else
11043e569a6bSSimon Glass #  define IMAGE_ENABLE_SIGN	0
1105782cfbb2SSimon Glass #  define IMAGE_ENABLE_VERIFY	1
1106782cfbb2SSimon Glass # endif
1107782cfbb2SSimon Glass #else
11083e569a6bSSimon Glass # define IMAGE_ENABLE_SIGN	0
1109782cfbb2SSimon Glass # define IMAGE_ENABLE_VERIFY	0
1110782cfbb2SSimon Glass #endif
1111782cfbb2SSimon Glass 
1112782cfbb2SSimon Glass #ifdef USE_HOSTCC
111329a23f9dSHeiko Schocher void *image_get_host_blob(void);
111429a23f9dSHeiko Schocher void image_set_host_blob(void *host_blob);
111529a23f9dSHeiko Schocher # define gd_fdt_blob()		image_get_host_blob()
1116782cfbb2SSimon Glass #else
1117e750e261SJoseph Chen #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_USING_KERNEL_DTB)
1118e750e261SJoseph Chen # define gd_fdt_blob()		(gd->ufdt_blob)
1119e750e261SJoseph Chen #else
1120782cfbb2SSimon Glass # define gd_fdt_blob()		(gd->fdt_blob)
1121782cfbb2SSimon Glass #endif
1122e750e261SJoseph Chen #endif
1123782cfbb2SSimon Glass 
1124782cfbb2SSimon Glass #ifdef CONFIG_FIT_BEST_MATCH
1125782cfbb2SSimon Glass #define IMAGE_ENABLE_BEST_MATCH	1
1126782cfbb2SSimon Glass #else
1127782cfbb2SSimon Glass #define IMAGE_ENABLE_BEST_MATCH	0
1128782cfbb2SSimon Glass #endif
1129782cfbb2SSimon Glass 
11303e569a6bSSimon Glass /* Information passed to the signing routines */
11313e569a6bSSimon Glass struct image_sign_info {
11323e569a6bSSimon Glass 	const char *keydir;		/* Directory conaining keys */
11333e569a6bSSimon Glass 	const char *keyname;		/* Name of key to use */
11343e569a6bSSimon Glass 	void *fit;			/* Pointer to FIT blob */
11353e569a6bSSimon Glass 	int node_offset;		/* Offset of signature node */
113683dd98e0SAndrew Duda 	const char *name;		/* Algorithm name */
113783dd98e0SAndrew Duda 	struct checksum_algo *checksum;	/* Checksum algorithm information */
113883dd98e0SAndrew Duda 	struct crypto_algo *crypto;	/* Crypto algorithm information */
11393e569a6bSSimon Glass 	const void *fdt_blob;		/* FDT containing public keys */
11403e569a6bSSimon Glass 	int required_keynode;		/* Node offset of key to use: -1=any */
11413e569a6bSSimon Glass 	const char *require_keys;	/* Value for 'required' property */
1142f1ca1fdeSGeorge McCollister 	const char *engine_id;		/* Engine to use for signing */
11433e569a6bSSimon Glass };
114473223f0eSSimon Glass #endif /* Allow struct image_region to always be defined for rsa.h */
11453e569a6bSSimon Glass 
11463e569a6bSSimon Glass /* A part of an image, used for hashing */
11473e569a6bSSimon Glass struct image_region {
11483e569a6bSSimon Glass 	const void *data;
11493e569a6bSSimon Glass 	int size;
11503e569a6bSSimon Glass };
11513e569a6bSSimon Glass 
115273223f0eSSimon Glass #if IMAGE_ENABLE_FIT
115373223f0eSSimon Glass 
1154646257d1SHeiko Schocher #if IMAGE_ENABLE_VERIFY
11552b9912e6SJeroen Hofstee # include <u-boot/rsa-checksum.h>
1156646257d1SHeiko Schocher #endif
1157646257d1SHeiko Schocher struct checksum_algo {
1158646257d1SHeiko Schocher 	const char *name;
1159646257d1SHeiko Schocher 	const int checksum_len;
1160da29f299SAndrew Duda 	const int der_len;
1161da29f299SAndrew Duda 	const uint8_t *der_prefix;
1162646257d1SHeiko Schocher #if IMAGE_ENABLE_SIGN
116329a23f9dSHeiko Schocher 	const EVP_MD *(*calculate_sign)(void);
116429a23f9dSHeiko Schocher #endif
1165b37b46f0SRuchika Gupta 	int (*calculate)(const char *name,
1166b37b46f0SRuchika Gupta 			 const struct image_region region[],
1167646257d1SHeiko Schocher 			 int region_count, uint8_t *checksum);
1168646257d1SHeiko Schocher };
1169646257d1SHeiko Schocher 
11700c1d74fdSAndrew Duda struct crypto_algo {
11713e569a6bSSimon Glass 	const char *name;		/* Name of algorithm */
11720c1d74fdSAndrew Duda 	const int key_len;
11733e569a6bSSimon Glass 
11743e569a6bSSimon Glass 	/**
11753e569a6bSSimon Glass 	 * sign() - calculate and return signature for given input data
11763e569a6bSSimon Glass 	 *
11773e569a6bSSimon Glass 	 * @info:	Specifies key and FIT information
11783e569a6bSSimon Glass 	 * @data:	Pointer to the input data
11793e569a6bSSimon Glass 	 * @data_len:	Data length
11803e569a6bSSimon Glass 	 * @sigp:	Set to an allocated buffer holding the signature
11813e569a6bSSimon Glass 	 * @sig_len:	Set to length of the calculated hash
11823e569a6bSSimon Glass 	 *
11833e569a6bSSimon Glass 	 * This computes input data signature according to selected algorithm.
11843e569a6bSSimon Glass 	 * Resulting signature value is placed in an allocated buffer, the
11853e569a6bSSimon Glass 	 * pointer is returned as *sigp. The length of the calculated
11863e569a6bSSimon Glass 	 * signature is returned via the sig_len pointer argument. The caller
11873e569a6bSSimon Glass 	 * should free *sigp.
11883e569a6bSSimon Glass 	 *
11893e569a6bSSimon Glass 	 * @return: 0, on success, -ve on error
11903e569a6bSSimon Glass 	 */
11913e569a6bSSimon Glass 	int (*sign)(struct image_sign_info *info,
11923e569a6bSSimon Glass 		    const struct image_region region[],
11933e569a6bSSimon Glass 		    int region_count, uint8_t **sigp, uint *sig_len);
11943e569a6bSSimon Glass 
11953e569a6bSSimon Glass 	/**
11963e569a6bSSimon Glass 	 * add_verify_data() - Add verification information to FDT
11973e569a6bSSimon Glass 	 *
11983e569a6bSSimon Glass 	 * Add public key information to the FDT node, suitable for
11993e569a6bSSimon Glass 	 * verification at run-time. The information added depends on the
12003e569a6bSSimon Glass 	 * algorithm being used.
12013e569a6bSSimon Glass 	 *
12023e569a6bSSimon Glass 	 * @info:	Specifies key and FIT information
12033e569a6bSSimon Glass 	 * @keydest:	Destination FDT blob for public key data
12043e569a6bSSimon Glass 	 * @return: 0, on success, -ve on error
12053e569a6bSSimon Glass 	 */
12063e569a6bSSimon Glass 	int (*add_verify_data)(struct image_sign_info *info, void *keydest);
12073e569a6bSSimon Glass 
12083e569a6bSSimon Glass 	/**
12093e569a6bSSimon Glass 	 * verify() - Verify a signature against some data
12103e569a6bSSimon Glass 	 *
12113e569a6bSSimon Glass 	 * @info:	Specifies key and FIT information
12123e569a6bSSimon Glass 	 * @data:	Pointer to the input data
12133e569a6bSSimon Glass 	 * @data_len:	Data length
12143e569a6bSSimon Glass 	 * @sig:	Signature
12153e569a6bSSimon Glass 	 * @sig_len:	Number of bytes in signature
12163e569a6bSSimon Glass 	 * @return 0 if verified, -ve on error
12173e569a6bSSimon Glass 	 */
12183e569a6bSSimon Glass 	int (*verify)(struct image_sign_info *info,
12193e569a6bSSimon Glass 		      const struct image_region region[], int region_count,
12203e569a6bSSimon Glass 		      uint8_t *sig, uint sig_len);
12210c1d74fdSAndrew Duda };
1222646257d1SHeiko Schocher 
12233e569a6bSSimon Glass /**
122483dd98e0SAndrew Duda  * image_get_checksum_algo() - Look up a checksum algorithm
12253e569a6bSSimon Glass  *
122683dd98e0SAndrew Duda  * @param full_name	Name of algorithm in the form "checksum,crypto"
12273e569a6bSSimon Glass  * @return pointer to algorithm information, or NULL if not found
12283e569a6bSSimon Glass  */
122983dd98e0SAndrew Duda struct checksum_algo *image_get_checksum_algo(const char *full_name);
123083dd98e0SAndrew Duda 
123183dd98e0SAndrew Duda /**
123283dd98e0SAndrew Duda  * image_get_crypto_algo() - Look up a cryptosystem algorithm
123383dd98e0SAndrew Duda  *
123483dd98e0SAndrew Duda  * @param full_name	Name of algorithm in the form "checksum,crypto"
123583dd98e0SAndrew Duda  * @return pointer to algorithm information, or NULL if not found
123683dd98e0SAndrew Duda  */
123783dd98e0SAndrew Duda struct crypto_algo *image_get_crypto_algo(const char *full_name);
12383e569a6bSSimon Glass 
123956518e71SSimon Glass /**
124056518e71SSimon Glass  * fit_image_verify_required_sigs() - Verify signatures marked as 'required'
124156518e71SSimon Glass  *
124256518e71SSimon Glass  * @fit:		FIT to check
124356518e71SSimon Glass  * @image_noffset:	Offset of image node to check
124456518e71SSimon Glass  * @data:		Image data to check
124556518e71SSimon Glass  * @size:		Size of image data
124656518e71SSimon Glass  * @sig_blob:		FDT containing public keys
124756518e71SSimon Glass  * @no_sigsp:		Returns 1 if no signatures were required, and
124856518e71SSimon Glass  *			therefore nothing was checked. The caller may wish
124956518e71SSimon Glass  *			to fall back to other mechanisms, or refuse to
125056518e71SSimon Glass  *			boot.
125156518e71SSimon Glass  * @return 0 if all verified ok, <0 on error
125256518e71SSimon Glass  */
125356518e71SSimon Glass int fit_image_verify_required_sigs(const void *fit, int image_noffset,
125456518e71SSimon Glass 		const char *data, size_t size, const void *sig_blob,
125556518e71SSimon Glass 		int *no_sigsp);
125656518e71SSimon Glass 
125756518e71SSimon Glass /**
125856518e71SSimon Glass  * fit_image_check_sig() - Check a single image signature node
125956518e71SSimon Glass  *
126056518e71SSimon Glass  * @fit:		FIT to check
126156518e71SSimon Glass  * @noffset:		Offset of signature node to check
126256518e71SSimon Glass  * @data:		Image data to check
126356518e71SSimon Glass  * @size:		Size of image data
126456518e71SSimon Glass  * @required_keynode:	Offset in the control FDT of the required key node,
126556518e71SSimon Glass  *			if any. If this is given, then the image wil not
126656518e71SSimon Glass  *			pass verification unless that key is used. If this is
126756518e71SSimon Glass  *			-1 then any signature will do.
126856518e71SSimon Glass  * @err_msgp:		In the event of an error, this will be pointed to a
126956518e71SSimon Glass  *			help error string to display to the user.
127056518e71SSimon Glass  * @return 0 if all verified ok, <0 on error
127156518e71SSimon Glass  */
127256518e71SSimon Glass int fit_image_check_sig(const void *fit, int noffset, const void *data,
127356518e71SSimon Glass 		size_t size, int required_keynode, char **err_msgp);
127456518e71SSimon Glass 
12754d098529SSimon Glass /**
12764d098529SSimon Glass  * fit_region_make_list() - Make a list of regions to hash
12774d098529SSimon Glass  *
12784d098529SSimon Glass  * Given a list of FIT regions (offset, size) provided by libfdt, create
12794d098529SSimon Glass  * a list of regions (void *, size) for use by the signature creationg
12804d098529SSimon Glass  * and verification code.
12814d098529SSimon Glass  *
12824d098529SSimon Glass  * @fit:		FIT image to process
12834d098529SSimon Glass  * @fdt_regions:	Regions as returned by libfdt
12844d098529SSimon Glass  * @count:		Number of regions returned by libfdt
12854d098529SSimon Glass  * @region:		Place to put list of regions (NULL to allocate it)
12864d098529SSimon Glass  * @return pointer to list of regions, or NULL if out of memory
12874d098529SSimon Glass  */
12884d098529SSimon Glass struct image_region *fit_region_make_list(const void *fit,
12894d098529SSimon Glass 		struct fdt_region *fdt_regions, int count,
12904d098529SSimon Glass 		struct image_region *region);
129156518e71SSimon Glass 
12925dfb5213SMarian Balakowicz static inline int fit_image_check_target_arch(const void *fdt, int node)
12935dfb5213SMarian Balakowicz {
129429a23f9dSHeiko Schocher #ifndef USE_HOSTCC
12957566832aSThierry Reding 	return fit_image_check_arch(fdt, node, IH_ARCH_DEFAULT);
129629a23f9dSHeiko Schocher #else
129729a23f9dSHeiko Schocher 	return 0;
129829a23f9dSHeiko Schocher #endif
12995dfb5213SMarian Balakowicz }
13005dfb5213SMarian Balakowicz 
1301d5934ad7SMarian Balakowicz #ifdef CONFIG_FIT_VERBOSE
1302d5934ad7SMarian Balakowicz #define fit_unsupported(msg)	printf("! %s:%d " \
1303d5934ad7SMarian Balakowicz 				"FIT images not supported for '%s'\n", \
1304d5934ad7SMarian Balakowicz 				__FILE__, __LINE__, (msg))
1305d5934ad7SMarian Balakowicz 
1306d5934ad7SMarian Balakowicz #define fit_unsupported_reset(msg)	printf("! %s:%d " \
1307d5934ad7SMarian Balakowicz 				"FIT images not supported for '%s' " \
1308d5934ad7SMarian Balakowicz 				"- must reset board to recover!\n", \
1309d5934ad7SMarian Balakowicz 				__FILE__, __LINE__, (msg))
1310d5934ad7SMarian Balakowicz #else
1311d5934ad7SMarian Balakowicz #define fit_unsupported(msg)
1312d5934ad7SMarian Balakowicz #define fit_unsupported_reset(msg)
1313d5934ad7SMarian Balakowicz #endif /* CONFIG_FIT_VERBOSE */
1314f50433d6SMarian Balakowicz #endif /* CONFIG_FIT */
13155ad03eb3SMarian Balakowicz 
13169ace3fc8SSebastian Siewior #if defined(CONFIG_ANDROID_BOOT_IMAGE)
13179ace3fc8SSebastian Siewior struct andr_img_hdr;
1318c092b139SJoseph Chen u32 android_bcb_msg_sector_offset(void);
1319c092b139SJoseph Chen u32 android_image_major_version(void);
13209ace3fc8SSebastian Siewior int android_image_check_header(const struct andr_img_hdr *hdr);
13219ace3fc8SSebastian Siewior int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
13229ace3fc8SSebastian Siewior 			     ulong *os_data, ulong *os_len);
13239ace3fc8SSebastian Siewior int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
13249ace3fc8SSebastian Siewior 			      ulong *rd_data, ulong *rd_len);
1325270f9eacSKever Yang int android_image_get_fdt(const struct andr_img_hdr *hdr,
1326270f9eacSKever Yang 			      ulong *rd_data);
1327008aee87SAndy Yan u32 android_image_get_comp(const struct andr_img_hdr *hdr);
13289ace3fc8SSebastian Siewior ulong android_image_get_end(const struct andr_img_hdr *hdr);
13299ace3fc8SSebastian Siewior ulong android_image_get_kload(const struct andr_img_hdr *hdr);
13304f1318b2SMichael Trimarchi void android_print_contents(const struct andr_img_hdr *hdr);
13319ace3fc8SSebastian Siewior 
1332e1b9a842SJoseph Chen void android_image_set_decomp(struct andr_img_hdr *hdr, int comp);
1333e1b9a842SJoseph Chen int android_image_parse_comp(struct andr_img_hdr *hdr, ulong *load_addr);
1334e1b9a842SJoseph Chen int android_image_memcpy_separate(struct andr_img_hdr *hdr, ulong *load_address);
133598c12997SJoseph Chen 
133676e2a5a6SAlex Deymo /** android_image_load - Load an Android Image from storage.
133776e2a5a6SAlex Deymo  *
1338008aee87SAndy Yan  * Load an Android Image based on the header size in the storage.
1339008aee87SAndy Yan  * Return the final load address, which could be a different address
1340008aee87SAndy Yan  * of argument load_address, if the Kernel Image is compressed. In case
1341008aee87SAndy Yan  * of error reading the image or if the image size needed to be read
1342008aee87SAndy Yan  * from disk is bigger than the passed |max_size| a negative number
1343008aee87SAndy Yan  * is returned.
134476e2a5a6SAlex Deymo  *
134576e2a5a6SAlex Deymo  * @dev_desc:		The device where to read the image from
134676e2a5a6SAlex Deymo  * @part_info:		The partition in |dev_desc| where to read the image from
134776e2a5a6SAlex Deymo  * @load_address:	The address where the image will be loaded
134876e2a5a6SAlex Deymo  * @max_size:		The maximum loaded size, in bytes
1349008aee87SAndy Yan  * @return the final load address or a negative number in case of error.
135076e2a5a6SAlex Deymo  */
135176e2a5a6SAlex Deymo long android_image_load(struct blk_desc *dev_desc,
135276e2a5a6SAlex Deymo 			const disk_partition_t *part_info,
135376e2a5a6SAlex Deymo 			unsigned long load_address,
135476e2a5a6SAlex Deymo 			unsigned long max_size);
135576e2a5a6SAlex Deymo 
13566527836dSJoseph Chen int android_image_load_by_partname(struct blk_desc *dev_desc,
13576527836dSJoseph Chen 				   const char *boot_partname,
13586527836dSJoseph Chen 				   unsigned long *load_address);
13599ace3fc8SSebastian Siewior #endif /* CONFIG_ANDROID_BOOT_IMAGE */
13609ace3fc8SSebastian Siewior 
1361008aee87SAndy Yan int bootm_parse_comp(const unsigned char *hdr);
1362008aee87SAndy Yan 
13634b307f23SSimon Glass /**
13644b307f23SSimon Glass  * board_fit_config_name_match() - Check for a matching board name
13654b307f23SSimon Glass  *
13664b307f23SSimon Glass  * This is used when SPL loads a FIT containing multiple device tree files
13674b307f23SSimon Glass  * and wants to work out which one to use. The description of each one is
13684b307f23SSimon Glass  * passed to this function. The description comes from the 'description' field
13694b307f23SSimon Glass  * in each (FDT) image node.
13704b307f23SSimon Glass  *
13714b307f23SSimon Glass  * @name: Device tree description
13724b307f23SSimon Glass  * @return 0 if this device tree should be used, non-zero to try the next
13734b307f23SSimon Glass  */
13744b307f23SSimon Glass int board_fit_config_name_match(const char *name);
13754b307f23SSimon Glass 
1376a5c7e41bSMadan Srinivas #if defined(CONFIG_SPL_FIT_IMAGE_POST_PROCESS) || \
1377a5c7e41bSMadan Srinivas 	defined(CONFIG_FIT_IMAGE_POST_PROCESS)
1378da74d1f3SDaniel Allred /**
1379da74d1f3SDaniel Allred  * board_fit_image_post_process() - Do any post-process on FIT binary data
1380da74d1f3SDaniel Allred  *
1381da74d1f3SDaniel Allred  * This is used to do any sort of image manipulation, verification, decryption
1382da74d1f3SDaniel Allred  * etc. in a platform or board specific way. Obviously, anything done here would
1383da74d1f3SDaniel Allred  * need to be comprehended in how the images were prepared before being injected
1384da74d1f3SDaniel Allred  * into the FIT creation (i.e. the binary blobs would have been pre-processed
1385da74d1f3SDaniel Allred  * before being added to the FIT image).
1386da74d1f3SDaniel Allred  *
1387da74d1f3SDaniel Allred  * @image: pointer to the image start pointer
1388da74d1f3SDaniel Allred  * @size: pointer to the image size
1389da74d1f3SDaniel Allred  * @return no return value (failure should be handled internally)
1390da74d1f3SDaniel Allred  */
1391da74d1f3SDaniel Allred void board_fit_image_post_process(void **p_image, size_t *p_size);
1392da74d1f3SDaniel Allred #endif /* CONFIG_SPL_FIT_IMAGE_POST_PROCESS */
1393da74d1f3SDaniel Allred 
13943863f840SCooper Jr., Franklin #define FDT_ERROR	((ulong)(-1))
13953863f840SCooper Jr., Franklin 
139692926bc8SCooper Jr., Franklin ulong fdt_getprop_u32(const void *fdt, int node, const char *prop);
13970079efa1SJean-Jacques Hiblot 
13980079efa1SJean-Jacques Hiblot /**
13990079efa1SJean-Jacques Hiblot  * fit_find_config_node() - Find the node for the best DTB in a FIT image
14000079efa1SJean-Jacques Hiblot  *
14010079efa1SJean-Jacques Hiblot  * A FIT image contains one or more DTBs. This function parses the
14020079efa1SJean-Jacques Hiblot  * configurations described in the FIT images and returns the node of
14030079efa1SJean-Jacques Hiblot  * the first matching DTB. To check if a DTB matches a board, this function
14040079efa1SJean-Jacques Hiblot  * calls board_fit_config_name_match(). If no matching DTB is found, it returns
14050079efa1SJean-Jacques Hiblot  * the node described by the default configuration if it exists.
14060079efa1SJean-Jacques Hiblot  *
14070079efa1SJean-Jacques Hiblot  * @fdt: pointer to flat device tree
14080079efa1SJean-Jacques Hiblot  * @return the node if found, -ve otherwise
14090079efa1SJean-Jacques Hiblot  */
141092926bc8SCooper Jr., Franklin int fit_find_config_node(const void *fdt);
141192926bc8SCooper Jr., Franklin 
1412d7be5092SAndrew F. Davis /**
1413d7be5092SAndrew F. Davis  * Mapping of image types to function handlers to be invoked on the associated
1414d7be5092SAndrew F. Davis  * loaded images
1415d7be5092SAndrew F. Davis  *
1416d7be5092SAndrew F. Davis  * @type: Type of image, I.E. IH_TYPE_*
1417d7be5092SAndrew F. Davis  * @handler: Function to call on loaded image
1418d7be5092SAndrew F. Davis  */
1419d7be5092SAndrew F. Davis struct fit_loadable_tbl {
1420d7be5092SAndrew F. Davis 	int type;
1421d7be5092SAndrew F. Davis 	/**
1422d7be5092SAndrew F. Davis 	 * handler() - Process a loaded image
1423d7be5092SAndrew F. Davis 	 *
1424d7be5092SAndrew F. Davis 	 * @data: Pointer to start of loaded image data
1425d7be5092SAndrew F. Davis 	 * @size: Size of loaded image data
1426d7be5092SAndrew F. Davis 	 */
1427d7be5092SAndrew F. Davis 	void (*handler)(ulong data, size_t size);
1428d7be5092SAndrew F. Davis };
1429d7be5092SAndrew F. Davis 
1430d7be5092SAndrew F. Davis /*
1431d7be5092SAndrew F. Davis  * Define a FIT loadable image type handler
1432d7be5092SAndrew F. Davis  *
1433d7be5092SAndrew F. Davis  * _type is a valid uimage_type ID as defined in the "Image Type" enum above
1434d7be5092SAndrew F. Davis  * _handler is the handler function to call after this image type is loaded
1435d7be5092SAndrew F. Davis  */
1436d7be5092SAndrew F. Davis #define U_BOOT_FIT_LOADABLE_HANDLER(_type, _handler) \
1437d7be5092SAndrew F. Davis 	ll_entry_declare(struct fit_loadable_tbl, _function, fit_loadable) = { \
1438d7be5092SAndrew F. Davis 		.type = _type, \
1439d7be5092SAndrew F. Davis 		.handler = _handler, \
1440d7be5092SAndrew F. Davis 	}
1441d7be5092SAndrew F. Davis 
14425b1d7137Swdenk #endif	/* __IMAGE_H__ */
1443