image.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  1. /*
  2. * (C) Copyright 2008 Semihalf
  3. *
  4. * (C) Copyright 2000-2005
  5. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. ********************************************************************
  9. * NOTE: This header file defines an interface to U-Boot. Including
  10. * this (unmodified) header file in another file is considered normal
  11. * use of U-Boot, and does *not* fall under the heading of "derived
  12. * work".
  13. ********************************************************************
  14. */
  15. #ifndef __IMAGE_H__
  16. #define __IMAGE_H__
  17. #include "compiler.h"
  18. #include <asm/byteorder.h>
  19. /* Define this to avoid #ifdefs later on */
  20. struct lmb;
  21. #ifdef USE_HOSTCC
  22. #include <sys/types.h>
  23. /* new uImage format support enabled on host */
  24. #define IMAGE_ENABLE_FIT 1
  25. #define IMAGE_ENABLE_OF_LIBFDT 1
  26. #define CONFIG_FIT_VERBOSE 1 /* enable fit_format_{error,warning}() */
  27. #define IMAGE_ENABLE_IGNORE 0
  28. #define IMAGE_INDENT_STRING ""
  29. #else
  30. #include <lmb.h>
  31. #include <asm/u-boot.h>
  32. #include <command.h>
  33. /* Take notice of the 'ignore' property for hashes */
  34. #define IMAGE_ENABLE_IGNORE 1
  35. #define IMAGE_INDENT_STRING " "
  36. #define IMAGE_ENABLE_FIT CONFIG_IS_ENABLED(FIT)
  37. #define IMAGE_ENABLE_OF_LIBFDT CONFIG_IS_ENABLED(OF_LIBFDT)
  38. #endif /* USE_HOSTCC */
  39. #if IMAGE_ENABLE_FIT
  40. #include <hash.h>
  41. #include <libfdt.h>
  42. #include <fdt_support.h>
  43. # ifdef CONFIG_SPL_BUILD
  44. # ifdef CONFIG_SPL_CRC32_SUPPORT
  45. # define IMAGE_ENABLE_CRC32 1
  46. # endif
  47. # ifdef CONFIG_SPL_MD5_SUPPORT
  48. # define IMAGE_ENABLE_MD5 1
  49. # endif
  50. # ifdef CONFIG_SPL_SHA1_SUPPORT
  51. # define IMAGE_ENABLE_SHA1 1
  52. # endif
  53. # ifdef CONFIG_SPL_SHA256_SUPPORT
  54. # define IMAGE_ENABLE_SHA256 1
  55. # endif
  56. # else
  57. # define CONFIG_CRC32 /* FIT images need CRC32 support */
  58. # define CONFIG_MD5 /* and MD5 */
  59. # define CONFIG_SHA1 /* and SHA1 */
  60. # define CONFIG_SHA256 /* and SHA256 */
  61. # define IMAGE_ENABLE_CRC32 1
  62. # define IMAGE_ENABLE_MD5 1
  63. # define IMAGE_ENABLE_SHA1 1
  64. # define IMAGE_ENABLE_SHA256 1
  65. # endif
  66. #ifdef CONFIG_FIT_DISABLE_SHA256
  67. #undef CONFIG_SHA256
  68. #undef IMAGE_ENABLE_SHA256
  69. #endif
  70. #ifndef IMAGE_ENABLE_CRC32
  71. #define IMAGE_ENABLE_CRC32 0
  72. #endif
  73. #ifndef IMAGE_ENABLE_MD5
  74. #define IMAGE_ENABLE_MD5 0
  75. #endif
  76. #ifndef IMAGE_ENABLE_SHA1
  77. #define IMAGE_ENABLE_SHA1 0
  78. #endif
  79. #ifndef IMAGE_ENABLE_SHA256
  80. #define IMAGE_ENABLE_SHA256 0
  81. #endif
  82. #endif /* IMAGE_ENABLE_FIT */
  83. #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  84. # define IMAGE_ENABLE_RAMDISK_HIGH 1
  85. #else
  86. # define IMAGE_ENABLE_RAMDISK_HIGH 0
  87. #endif
  88. #ifdef CONFIG_SYS_BOOT_GET_CMDLINE
  89. # define IMAGE_BOOT_GET_CMDLINE 1
  90. #else
  91. # define IMAGE_BOOT_GET_CMDLINE 0
  92. #endif
  93. #ifdef CONFIG_OF_BOARD_SETUP
  94. # define IMAGE_OF_BOARD_SETUP 1
  95. #else
  96. # define IMAGE_OF_BOARD_SETUP 0
  97. #endif
  98. #ifdef CONFIG_OF_SYSTEM_SETUP
  99. # define IMAGE_OF_SYSTEM_SETUP 1
  100. #else
  101. # define IMAGE_OF_SYSTEM_SETUP 0
  102. #endif
  103. /*
  104. * Operating System Codes
  105. */
  106. #define IH_OS_INVALID 0 /* Invalid OS */
  107. #define IH_OS_OPENBSD 1 /* OpenBSD */
  108. #define IH_OS_NETBSD 2 /* NetBSD */
  109. #define IH_OS_FREEBSD 3 /* FreeBSD */
  110. #define IH_OS_4_4BSD 4 /* 4.4BSD */
  111. #define IH_OS_LINUX 5 /* Linux */
  112. #define IH_OS_SVR4 6 /* SVR4 */
  113. #define IH_OS_ESIX 7 /* Esix */
  114. #define IH_OS_SOLARIS 8 /* Solaris */
  115. #define IH_OS_IRIX 9 /* Irix */
  116. #define IH_OS_SCO 10 /* SCO */
  117. #define IH_OS_DELL 11 /* Dell */
  118. #define IH_OS_NCR 12 /* NCR */
  119. #define IH_OS_LYNXOS 13 /* LynxOS */
  120. #define IH_OS_VXWORKS 14 /* VxWorks */
  121. #define IH_OS_PSOS 15 /* pSOS */
  122. #define IH_OS_QNX 16 /* QNX */
  123. #define IH_OS_U_BOOT 17 /* Firmware */
  124. #define IH_OS_RTEMS 18 /* RTEMS */
  125. #define IH_OS_ARTOS 19 /* ARTOS */
  126. #define IH_OS_UNITY 20 /* Unity OS */
  127. #define IH_OS_INTEGRITY 21 /* INTEGRITY */
  128. #define IH_OS_OSE 22 /* OSE */
  129. #define IH_OS_PLAN9 23 /* Plan 9 */
  130. #define IH_OS_OPENRTOS 24 /* OpenRTOS */
  131. /*
  132. * CPU Architecture Codes (supported by Linux)
  133. */
  134. #define IH_ARCH_INVALID 0 /* Invalid CPU */
  135. #define IH_ARCH_ALPHA 1 /* Alpha */
  136. #define IH_ARCH_ARM 2 /* ARM */
  137. #define IH_ARCH_I386 3 /* Intel x86 */
  138. #define IH_ARCH_IA64 4 /* IA64 */
  139. #define IH_ARCH_MIPS 5 /* MIPS */
  140. #define IH_ARCH_MIPS64 6 /* MIPS 64 Bit */
  141. #define IH_ARCH_PPC 7 /* PowerPC */
  142. #define IH_ARCH_S390 8 /* IBM S390 */
  143. #define IH_ARCH_SH 9 /* SuperH */
  144. #define IH_ARCH_SPARC 10 /* Sparc */
  145. #define IH_ARCH_SPARC64 11 /* Sparc 64 Bit */
  146. #define IH_ARCH_M68K 12 /* M68K */
  147. #define IH_ARCH_MICROBLAZE 14 /* MicroBlaze */
  148. #define IH_ARCH_NIOS2 15 /* Nios-II */
  149. #define IH_ARCH_BLACKFIN 16 /* Blackfin */
  150. #define IH_ARCH_AVR32 17 /* AVR32 */
  151. #define IH_ARCH_ST200 18 /* STMicroelectronics ST200 */
  152. #define IH_ARCH_SANDBOX 19 /* Sandbox architecture (test only) */
  153. #define IH_ARCH_NDS32 20 /* ANDES Technology - NDS32 */
  154. #define IH_ARCH_OPENRISC 21 /* OpenRISC 1000 */
  155. #define IH_ARCH_ARM64 22 /* ARM64 */
  156. #define IH_ARCH_ARC 23 /* Synopsys DesignWare ARC */
  157. #define IH_ARCH_X86_64 24 /* AMD x86_64, Intel and Via */
  158. /*
  159. * Image Types
  160. *
  161. * "Standalone Programs" are directly runnable in the environment
  162. * provided by U-Boot; it is expected that (if they behave
  163. * well) you can continue to work in U-Boot after return from
  164. * the Standalone Program.
  165. * "OS Kernel Images" are usually images of some Embedded OS which
  166. * will take over control completely. Usually these programs
  167. * will install their own set of exception handlers, device
  168. * drivers, set up the MMU, etc. - this means, that you cannot
  169. * expect to re-enter U-Boot except by resetting the CPU.
  170. * "RAMDisk Images" are more or less just data blocks, and their
  171. * parameters (address, size) are passed to an OS kernel that is
  172. * being started.
  173. * "Multi-File Images" contain several images, typically an OS
  174. * (Linux) kernel image and one or more data images like
  175. * RAMDisks. This construct is useful for instance when you want
  176. * to boot over the network using BOOTP etc., where the boot
  177. * server provides just a single image file, but you want to get
  178. * for instance an OS kernel and a RAMDisk image.
  179. *
  180. * "Multi-File Images" start with a list of image sizes, each
  181. * image size (in bytes) specified by an "uint32_t" in network
  182. * byte order. This list is terminated by an "(uint32_t)0".
  183. * Immediately after the terminating 0 follow the images, one by
  184. * one, all aligned on "uint32_t" boundaries (size rounded up to
  185. * a multiple of 4 bytes - except for the last file).
  186. *
  187. * "Firmware Images" are binary images containing firmware (like
  188. * U-Boot or FPGA images) which usually will be programmed to
  189. * flash memory.
  190. *
  191. * "Script files" are command sequences that will be executed by
  192. * U-Boot's command interpreter; this feature is especially
  193. * useful when you configure U-Boot to use a real shell (hush)
  194. * as command interpreter (=> Shell Scripts).
  195. */
  196. #define IH_TYPE_INVALID 0 /* Invalid Image */
  197. #define IH_TYPE_STANDALONE 1 /* Standalone Program */
  198. #define IH_TYPE_KERNEL 2 /* OS Kernel Image */
  199. #define IH_TYPE_RAMDISK 3 /* RAMDisk Image */
  200. #define IH_TYPE_MULTI 4 /* Multi-File Image */
  201. #define IH_TYPE_FIRMWARE 5 /* Firmware Image */
  202. #define IH_TYPE_SCRIPT 6 /* Script file */
  203. #define IH_TYPE_FILESYSTEM 7 /* Filesystem Image (any type) */
  204. #define IH_TYPE_FLATDT 8 /* Binary Flat Device Tree Blob */
  205. #define IH_TYPE_KWBIMAGE 9 /* Kirkwood Boot Image */
  206. #define IH_TYPE_IMXIMAGE 10 /* Freescale IMXBoot Image */
  207. #define IH_TYPE_UBLIMAGE 11 /* Davinci UBL Image */
  208. #define IH_TYPE_OMAPIMAGE 12 /* TI OMAP Config Header Image */
  209. #define IH_TYPE_AISIMAGE 13 /* TI Davinci AIS Image */
  210. #define IH_TYPE_KERNEL_NOLOAD 14 /* OS Kernel Image, can run from any load address */
  211. #define IH_TYPE_PBLIMAGE 15 /* Freescale PBL Boot Image */
  212. #define IH_TYPE_MXSIMAGE 16 /* Freescale MXSBoot Image */
  213. #define IH_TYPE_GPIMAGE 17 /* TI Keystone GPHeader Image */
  214. #define IH_TYPE_ATMELIMAGE 18 /* ATMEL ROM bootable Image */
  215. #define IH_TYPE_SOCFPGAIMAGE 19 /* Altera SOCFPGA Preloader */
  216. #define IH_TYPE_X86_SETUP 20 /* x86 setup.bin Image */
  217. #define IH_TYPE_LPC32XXIMAGE 21 /* x86 setup.bin Image */
  218. #define IH_TYPE_LOADABLE 22 /* A list of typeless images */
  219. #define IH_TYPE_RKIMAGE 23 /* Rockchip Boot Image */
  220. #define IH_TYPE_RKSD 24 /* Rockchip SD card */
  221. #define IH_TYPE_RKSPI 25 /* Rockchip SPI image */
  222. #define IH_TYPE_ZYNQIMAGE 26 /* Xilinx Zynq Boot Image */
  223. #define IH_TYPE_COUNT 27 /* Number of image types */
  224. /*
  225. * Compression Types
  226. */
  227. #define IH_COMP_NONE 0 /* No Compression Used */
  228. #define IH_COMP_GZIP 1 /* gzip Compression Used */
  229. #define IH_COMP_BZIP2 2 /* bzip2 Compression Used */
  230. #define IH_COMP_LZMA 3 /* lzma Compression Used */
  231. #define IH_COMP_LZO 4 /* lzo Compression Used */
  232. #define IH_COMP_LZ4 5 /* lz4 Compression Used */
  233. #define IH_MAGIC 0x27051956 /* Image Magic Number */
  234. #define IH_NMLEN 32 /* Image Name Length */
  235. /* Reused from common.h */
  236. #define ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1))
  237. /*
  238. * Legacy format image header,
  239. * all data in network byte order (aka natural aka bigendian).
  240. */
  241. typedef struct image_header {
  242. __be32 ih_magic; /* Image Header Magic Number */
  243. __be32 ih_hcrc; /* Image Header CRC Checksum */
  244. __be32 ih_time; /* Image Creation Timestamp */
  245. __be32 ih_size; /* Image Data Size */
  246. __be32 ih_load; /* Data Load Address */
  247. __be32 ih_ep; /* Entry Point Address */
  248. __be32 ih_dcrc; /* Image Data CRC Checksum */
  249. uint8_t ih_os; /* Operating System */
  250. uint8_t ih_arch; /* CPU architecture */
  251. uint8_t ih_type; /* Image Type */
  252. uint8_t ih_comp; /* Compression Type */
  253. uint8_t ih_name[IH_NMLEN]; /* Image Name */
  254. } image_header_t;
  255. typedef struct image_info {
  256. ulong start, end; /* start/end of blob */
  257. ulong image_start, image_len; /* start of image within blob, len of image */
  258. ulong load; /* load addr for the image */
  259. uint8_t comp, type, os; /* compression, type of image, os type */
  260. uint8_t arch; /* CPU architecture */
  261. } image_info_t;
  262. /*
  263. * Legacy and FIT format headers used by do_bootm() and do_bootm_<os>()
  264. * routines.
  265. */
  266. typedef struct bootm_headers {
  267. /*
  268. * Legacy os image header, if it is a multi component image
  269. * then boot_get_ramdisk() and get_fdt() will attempt to get
  270. * data from second and third component accordingly.
  271. */
  272. image_header_t *legacy_hdr_os; /* image header pointer */
  273. image_header_t legacy_hdr_os_copy; /* header copy */
  274. ulong legacy_hdr_valid;
  275. #if IMAGE_ENABLE_FIT
  276. const char *fit_uname_cfg; /* configuration node unit name */
  277. void *fit_hdr_os; /* os FIT image header */
  278. const char *fit_uname_os; /* os subimage node unit name */
  279. int fit_noffset_os; /* os subimage node offset */
  280. void *fit_hdr_rd; /* init ramdisk FIT image header */
  281. const char *fit_uname_rd; /* init ramdisk subimage node unit name */
  282. int fit_noffset_rd; /* init ramdisk subimage node offset */
  283. void *fit_hdr_fdt; /* FDT blob FIT image header */
  284. const char *fit_uname_fdt; /* FDT blob subimage node unit name */
  285. int fit_noffset_fdt;/* FDT blob subimage node offset */
  286. void *fit_hdr_setup; /* x86 setup FIT image header */
  287. const char *fit_uname_setup; /* x86 setup subimage node name */
  288. int fit_noffset_setup;/* x86 setup subimage node offset */
  289. #endif
  290. #ifndef USE_HOSTCC
  291. image_info_t os; /* os image info */
  292. ulong ep; /* entry point of OS */
  293. ulong rd_start, rd_end;/* ramdisk start/end */
  294. char *ft_addr; /* flat dev tree address */
  295. ulong ft_len; /* length of flat device tree */
  296. ulong initrd_start;
  297. ulong initrd_end;
  298. ulong cmdline_start;
  299. ulong cmdline_end;
  300. bd_t *kbd;
  301. #endif
  302. int verify; /* getenv("verify")[0] != 'n' */
  303. #define BOOTM_STATE_START (0x00000001)
  304. #define BOOTM_STATE_FINDOS (0x00000002)
  305. #define BOOTM_STATE_FINDOTHER (0x00000004)
  306. #define BOOTM_STATE_LOADOS (0x00000008)
  307. #define BOOTM_STATE_RAMDISK (0x00000010)
  308. #define BOOTM_STATE_FDT (0x00000020)
  309. #define BOOTM_STATE_OS_CMDLINE (0x00000040)
  310. #define BOOTM_STATE_OS_BD_T (0x00000080)
  311. #define BOOTM_STATE_OS_PREP (0x00000100)
  312. #define BOOTM_STATE_OS_FAKE_GO (0x00000200) /* 'Almost' run the OS */
  313. #define BOOTM_STATE_OS_GO (0x00000400)
  314. int state;
  315. #ifdef CONFIG_LMB
  316. struct lmb lmb; /* for memory mgmt */
  317. #endif
  318. } bootm_headers_t;
  319. extern bootm_headers_t images;
  320. /*
  321. * Some systems (for example LWMON) have very short watchdog periods;
  322. * we must make sure to split long operations like memmove() or
  323. * checksum calculations into reasonable chunks.
  324. */
  325. #ifndef CHUNKSZ
  326. #define CHUNKSZ (64 * 1024)
  327. #endif
  328. #ifndef CHUNKSZ_CRC32
  329. #define CHUNKSZ_CRC32 (64 * 1024)
  330. #endif
  331. #ifndef CHUNKSZ_MD5
  332. #define CHUNKSZ_MD5 (64 * 1024)
  333. #endif
  334. #ifndef CHUNKSZ_SHA1
  335. #define CHUNKSZ_SHA1 (64 * 1024)
  336. #endif
  337. #define uimage_to_cpu(x) be32_to_cpu(x)
  338. #define cpu_to_uimage(x) cpu_to_be32(x)
  339. /*
  340. * Translation table for entries of a specific type; used by
  341. * get_table_entry_id() and get_table_entry_name().
  342. */
  343. typedef struct table_entry {
  344. int id;
  345. char *sname; /* short (input) name to find table entry */
  346. char *lname; /* long (output) name to print for messages */
  347. } table_entry_t;
  348. /*
  349. * get_table_entry_id() scans the translation table trying to find an
  350. * entry that matches the given short name. If a matching entry is
  351. * found, it's id is returned to the caller.
  352. */
  353. int get_table_entry_id(const table_entry_t *table,
  354. const char *table_name, const char *name);
  355. /*
  356. * get_table_entry_name() scans the translation table trying to find
  357. * an entry that matches the given id. If a matching entry is found,
  358. * its long name is returned to the caller.
  359. */
  360. char *get_table_entry_name(const table_entry_t *table, char *msg, int id);
  361. const char *genimg_get_os_name(uint8_t os);
  362. /**
  363. * genimg_get_os_short_name() - get the short name for an OS
  364. *
  365. * @param os OS (IH_OS_...)
  366. * @return OS short name, or "unknown" if unknown
  367. */
  368. const char *genimg_get_os_short_name(uint8_t comp);
  369. const char *genimg_get_arch_name(uint8_t arch);
  370. /**
  371. * genimg_get_arch_short_name() - get the short name for an architecture
  372. *
  373. * @param arch Architecture type (IH_ARCH_...)
  374. * @return architecture short name, or "unknown" if unknown
  375. */
  376. const char *genimg_get_arch_short_name(uint8_t arch);
  377. const char *genimg_get_type_name(uint8_t type);
  378. /**
  379. * genimg_get_type_short_name() - get the short name for an image type
  380. *
  381. * @param type Image type (IH_TYPE_...)
  382. * @return image short name, or "unknown" if unknown
  383. */
  384. const char *genimg_get_type_short_name(uint8_t type);
  385. const char *genimg_get_comp_name(uint8_t comp);
  386. /**
  387. * genimg_get_comp_short_name() - get the short name for a compression method
  388. *
  389. * @param comp compression method (IH_COMP_...)
  390. * @return compression method short name, or "unknown" if unknown
  391. */
  392. const char *genimg_get_comp_short_name(uint8_t comp);
  393. int genimg_get_os_id(const char *name);
  394. int genimg_get_arch_id(const char *name);
  395. int genimg_get_type_id(const char *name);
  396. int genimg_get_comp_id(const char *name);
  397. void genimg_print_size(uint32_t size);
  398. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || \
  399. defined(USE_HOSTCC)
  400. #define IMAGE_ENABLE_TIMESTAMP 1
  401. #else
  402. #define IMAGE_ENABLE_TIMESTAMP 0
  403. #endif
  404. void genimg_print_time(time_t timestamp);
  405. /* What to do with a image load address ('load = <> 'in the FIT) */
  406. enum fit_load_op {
  407. FIT_LOAD_IGNORED, /* Ignore load address */
  408. FIT_LOAD_OPTIONAL, /* Can be provided, but optional */
  409. FIT_LOAD_OPTIONAL_NON_ZERO, /* Optional, a value of 0 is ignored */
  410. FIT_LOAD_REQUIRED, /* Must be provided */
  411. };
  412. int boot_get_setup(bootm_headers_t *images, uint8_t arch, ulong *setup_start,
  413. ulong *setup_len);
  414. #ifndef USE_HOSTCC
  415. /* Image format types, returned by _get_format() routine */
  416. #define IMAGE_FORMAT_INVALID 0x00
  417. #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
  418. #define IMAGE_FORMAT_LEGACY 0x01 /* legacy image_header based format */
  419. #endif
  420. #define IMAGE_FORMAT_FIT 0x02 /* new, libfdt based format */
  421. #define IMAGE_FORMAT_ANDROID 0x03 /* Android boot image */
  422. ulong genimg_get_kernel_addr_fit(char * const img_addr,
  423. const char **fit_uname_config,
  424. const char **fit_uname_kernel);
  425. ulong genimg_get_kernel_addr(char * const img_addr);
  426. int genimg_get_format(const void *img_addr);
  427. int genimg_has_config(bootm_headers_t *images);
  428. ulong genimg_get_image(ulong img_addr);
  429. int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
  430. uint8_t arch, ulong *rd_start, ulong *rd_end);
  431. /**
  432. * boot_get_loadable - routine to load a list of binaries to memory
  433. * @argc: Ignored Argument
  434. * @argv: Ignored Argument
  435. * @images: pointer to the bootm images structure
  436. * @arch: expected architecture for the image
  437. * @ld_start: Ignored Argument
  438. * @ld_len: Ignored Argument
  439. *
  440. * boot_get_loadable() will take the given FIT configuration, and look
  441. * for a field named "loadables". Loadables, is a list of elements in
  442. * the FIT given as strings. exe:
  443. * loadables = "linux_kernel@1", "fdt@2";
  444. * this function will attempt to parse each string, and load the
  445. * corresponding element from the FIT into memory. Once placed,
  446. * no aditional actions are taken.
  447. *
  448. * @return:
  449. * 0, if only valid images or no images are found
  450. * error code, if an error occurs during fit_image_load
  451. */
  452. int boot_get_loadable(int argc, char * const argv[], bootm_headers_t *images,
  453. uint8_t arch, const ulong *ld_start, ulong * const ld_len);
  454. #endif /* !USE_HOSTCC */
  455. int boot_get_setup_fit(bootm_headers_t *images, uint8_t arch,
  456. ulong *setup_start, ulong *setup_len);
  457. /**
  458. * fit_image_load() - load an image from a FIT
  459. *
  460. * This deals with all aspects of loading an image from a FIT, including
  461. * selecting the right image based on configuration, verifying it, printing
  462. * out progress messages, checking the type/arch/os and optionally copying it
  463. * to the right load address.
  464. *
  465. * The property to look up is defined by image_type.
  466. *
  467. * @param images Boot images structure
  468. * @param addr Address of FIT in memory
  469. * @param fit_unamep On entry this is the requested image name
  470. * (e.g. "kernel@1") or NULL to use the default. On exit
  471. * points to the selected image name
  472. * @param fit_uname_configp On entry this is the requested configuration
  473. * name (e.g. "conf@1") or NULL to use the default. On
  474. * exit points to the selected configuration name.
  475. * @param arch Expected architecture (IH_ARCH_...)
  476. * @param image_type Required image type (IH_TYPE_...). If this is
  477. * IH_TYPE_KERNEL then we allow IH_TYPE_KERNEL_NOLOAD
  478. * also.
  479. * @param bootstage_id ID of starting bootstage to use for progress updates.
  480. * This will be added to the BOOTSTAGE_SUB values when
  481. * calling bootstage_mark()
  482. * @param load_op Decribes what to do with the load address
  483. * @param datap Returns address of loaded image
  484. * @param lenp Returns length of loaded image
  485. * @return node offset of image, or -ve error code on error
  486. */
  487. int fit_image_load(bootm_headers_t *images, ulong addr,
  488. const char **fit_unamep, const char **fit_uname_configp,
  489. int arch, int image_type, int bootstage_id,
  490. enum fit_load_op load_op, ulong *datap, ulong *lenp);
  491. #ifndef USE_HOSTCC
  492. /**
  493. * fit_get_node_from_config() - Look up an image a FIT by type
  494. *
  495. * This looks in the selected conf@ node (images->fit_uname_cfg) for a
  496. * particular image type (e.g. "kernel") and then finds the image that is
  497. * referred to.
  498. *
  499. * For example, for something like:
  500. *
  501. * images {
  502. * kernel@1 {
  503. * ...
  504. * };
  505. * };
  506. * configurations {
  507. * conf@1 {
  508. * kernel = "kernel@1";
  509. * };
  510. * };
  511. *
  512. * the function will return the node offset of the kernel@1 node, assuming
  513. * that conf@1 is the chosen configuration.
  514. *
  515. * @param images Boot images structure
  516. * @param prop_name Property name to look up (FIT_..._PROP)
  517. * @param addr Address of FIT in memory
  518. */
  519. int fit_get_node_from_config(bootm_headers_t *images, const char *prop_name,
  520. ulong addr);
  521. int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
  522. bootm_headers_t *images,
  523. char **of_flat_tree, ulong *of_size);
  524. void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob);
  525. int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size);
  526. int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len,
  527. ulong *initrd_start, ulong *initrd_end);
  528. int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end);
  529. #ifdef CONFIG_SYS_BOOT_GET_KBD
  530. int boot_get_kbd(struct lmb *lmb, bd_t **kbd);
  531. #endif /* CONFIG_SYS_BOOT_GET_KBD */
  532. #endif /* !USE_HOSTCC */
  533. /*******************************************************************/
  534. /* Legacy format specific code (prefixed with image_) */
  535. /*******************************************************************/
  536. static inline uint32_t image_get_header_size(void)
  537. {
  538. return (sizeof(image_header_t));
  539. }
  540. #define image_get_hdr_l(f) \
  541. static inline uint32_t image_get_##f(const image_header_t *hdr) \
  542. { \
  543. return uimage_to_cpu(hdr->ih_##f); \
  544. }
  545. image_get_hdr_l(magic) /* image_get_magic */
  546. image_get_hdr_l(hcrc) /* image_get_hcrc */
  547. image_get_hdr_l(time) /* image_get_time */
  548. image_get_hdr_l(size) /* image_get_size */
  549. image_get_hdr_l(load) /* image_get_load */
  550. image_get_hdr_l(ep) /* image_get_ep */
  551. image_get_hdr_l(dcrc) /* image_get_dcrc */
  552. #define image_get_hdr_b(f) \
  553. static inline uint8_t image_get_##f(const image_header_t *hdr) \
  554. { \
  555. return hdr->ih_##f; \
  556. }
  557. image_get_hdr_b(os) /* image_get_os */
  558. image_get_hdr_b(arch) /* image_get_arch */
  559. image_get_hdr_b(type) /* image_get_type */
  560. image_get_hdr_b(comp) /* image_get_comp */
  561. static inline char *image_get_name(const image_header_t *hdr)
  562. {
  563. return (char *)hdr->ih_name;
  564. }
  565. static inline uint32_t image_get_data_size(const image_header_t *hdr)
  566. {
  567. return image_get_size(hdr);
  568. }
  569. /**
  570. * image_get_data - get image payload start address
  571. * @hdr: image header
  572. *
  573. * image_get_data() returns address of the image payload. For single
  574. * component images it is image data start. For multi component
  575. * images it points to the null terminated table of sub-images sizes.
  576. *
  577. * returns:
  578. * image payload data start address
  579. */
  580. static inline ulong image_get_data(const image_header_t *hdr)
  581. {
  582. return ((ulong)hdr + image_get_header_size());
  583. }
  584. static inline uint32_t image_get_image_size(const image_header_t *hdr)
  585. {
  586. return (image_get_size(hdr) + image_get_header_size());
  587. }
  588. static inline ulong image_get_image_end(const image_header_t *hdr)
  589. {
  590. return ((ulong)hdr + image_get_image_size(hdr));
  591. }
  592. #define image_set_hdr_l(f) \
  593. static inline void image_set_##f(image_header_t *hdr, uint32_t val) \
  594. { \
  595. hdr->ih_##f = cpu_to_uimage(val); \
  596. }
  597. image_set_hdr_l(magic) /* image_set_magic */
  598. image_set_hdr_l(hcrc) /* image_set_hcrc */
  599. image_set_hdr_l(time) /* image_set_time */
  600. image_set_hdr_l(size) /* image_set_size */
  601. image_set_hdr_l(load) /* image_set_load */
  602. image_set_hdr_l(ep) /* image_set_ep */
  603. image_set_hdr_l(dcrc) /* image_set_dcrc */
  604. #define image_set_hdr_b(f) \
  605. static inline void image_set_##f(image_header_t *hdr, uint8_t val) \
  606. { \
  607. hdr->ih_##f = val; \
  608. }
  609. image_set_hdr_b(os) /* image_set_os */
  610. image_set_hdr_b(arch) /* image_set_arch */
  611. image_set_hdr_b(type) /* image_set_type */
  612. image_set_hdr_b(comp) /* image_set_comp */
  613. static inline void image_set_name(image_header_t *hdr, const char *name)
  614. {
  615. strncpy(image_get_name(hdr), name, IH_NMLEN);
  616. }
  617. int image_check_hcrc(const image_header_t *hdr);
  618. int image_check_dcrc(const image_header_t *hdr);
  619. #ifndef USE_HOSTCC
  620. ulong getenv_bootm_low(void);
  621. phys_size_t getenv_bootm_size(void);
  622. phys_size_t getenv_bootm_mapsize(void);
  623. #endif
  624. void memmove_wd(void *to, void *from, size_t len, ulong chunksz);
  625. static inline int image_check_magic(const image_header_t *hdr)
  626. {
  627. return (image_get_magic(hdr) == IH_MAGIC);
  628. }
  629. static inline int image_check_type(const image_header_t *hdr, uint8_t type)
  630. {
  631. return (image_get_type(hdr) == type);
  632. }
  633. static inline int image_check_arch(const image_header_t *hdr, uint8_t arch)
  634. {
  635. return (image_get_arch(hdr) == arch);
  636. }
  637. static inline int image_check_os(const image_header_t *hdr, uint8_t os)
  638. {
  639. return (image_get_os(hdr) == os);
  640. }
  641. ulong image_multi_count(const image_header_t *hdr);
  642. void image_multi_getimg(const image_header_t *hdr, ulong idx,
  643. ulong *data, ulong *len);
  644. void image_print_contents(const void *hdr);
  645. #ifndef USE_HOSTCC
  646. static inline int image_check_target_arch(const image_header_t *hdr)
  647. {
  648. #ifndef IH_ARCH_DEFAULT
  649. # error "please define IH_ARCH_DEFAULT in your arch asm/u-boot.h"
  650. #endif
  651. return image_check_arch(hdr, IH_ARCH_DEFAULT);
  652. }
  653. #endif /* USE_HOSTCC */
  654. /**
  655. * Set up properties in the FDT
  656. *
  657. * This sets up properties in the FDT that is to be passed to linux.
  658. *
  659. * @images: Images information
  660. * @blob: FDT to update
  661. * @of_size: Size of the FDT
  662. * @lmb: Points to logical memory block structure
  663. * @return 0 if ok, <0 on failure
  664. */
  665. int image_setup_libfdt(bootm_headers_t *images, void *blob,
  666. int of_size, struct lmb *lmb);
  667. /**
  668. * Set up the FDT to use for booting a kernel
  669. *
  670. * This performs ramdisk setup, sets up the FDT if required, and adds
  671. * paramters to the FDT if libfdt is available.
  672. *
  673. * @param images Images information
  674. * @return 0 if ok, <0 on failure
  675. */
  676. int image_setup_linux(bootm_headers_t *images);
  677. /**
  678. * bootz_setup() - Extract stat and size of a Linux xImage
  679. *
  680. * @image: Address of image
  681. * @start: Returns start address of image
  682. * @end : Returns end address of image
  683. * @return 0 if OK, 1 if the image was not recognised
  684. */
  685. int bootz_setup(ulong image, ulong *start, ulong *end);
  686. /*******************************************************************/
  687. /* New uImage format specific code (prefixed with fit_) */
  688. /*******************************************************************/
  689. #define FIT_IMAGES_PATH "/images"
  690. #define FIT_CONFS_PATH "/configurations"
  691. /* hash/signature node */
  692. #define FIT_HASH_NODENAME "hash"
  693. #define FIT_ALGO_PROP "algo"
  694. #define FIT_VALUE_PROP "value"
  695. #define FIT_IGNORE_PROP "uboot-ignore"
  696. #define FIT_SIG_NODENAME "signature"
  697. /* image node */
  698. #define FIT_DATA_PROP "data"
  699. #define FIT_TIMESTAMP_PROP "timestamp"
  700. #define FIT_DESC_PROP "description"
  701. #define FIT_ARCH_PROP "arch"
  702. #define FIT_TYPE_PROP "type"
  703. #define FIT_OS_PROP "os"
  704. #define FIT_COMP_PROP "compression"
  705. #define FIT_ENTRY_PROP "entry"
  706. #define FIT_LOAD_PROP "load"
  707. /* configuration node */
  708. #define FIT_KERNEL_PROP "kernel"
  709. #define FIT_RAMDISK_PROP "ramdisk"
  710. #define FIT_FDT_PROP "fdt"
  711. #define FIT_LOADABLE_PROP "loadables"
  712. #define FIT_DEFAULT_PROP "default"
  713. #define FIT_SETUP_PROP "setup"
  714. #define FIT_MAX_HASH_LEN HASH_MAX_DIGEST_SIZE
  715. #if IMAGE_ENABLE_FIT
  716. /* cmdline argument format parsing */
  717. int fit_parse_conf(const char *spec, ulong addr_curr,
  718. ulong *addr, const char **conf_name);
  719. int fit_parse_subimage(const char *spec, ulong addr_curr,
  720. ulong *addr, const char **image_name);
  721. int fit_get_subimage_count(const void *fit, int images_noffset);
  722. void fit_print_contents(const void *fit);
  723. void fit_image_print(const void *fit, int noffset, const char *p);
  724. /**
  725. * fit_get_end - get FIT image size
  726. * @fit: pointer to the FIT format image header
  727. *
  728. * returns:
  729. * size of the FIT image (blob) in memory
  730. */
  731. static inline ulong fit_get_size(const void *fit)
  732. {
  733. return fdt_totalsize(fit);
  734. }
  735. /**
  736. * fit_get_end - get FIT image end
  737. * @fit: pointer to the FIT format image header
  738. *
  739. * returns:
  740. * end address of the FIT image (blob) in memory
  741. */
  742. ulong fit_get_end(const void *fit);
  743. /**
  744. * fit_get_name - get FIT node name
  745. * @fit: pointer to the FIT format image header
  746. *
  747. * returns:
  748. * NULL, on error
  749. * pointer to node name, on success
  750. */
  751. static inline const char *fit_get_name(const void *fit_hdr,
  752. int noffset, int *len)
  753. {
  754. return fdt_get_name(fit_hdr, noffset, len);
  755. }
  756. int fit_get_desc(const void *fit, int noffset, char **desc);
  757. int fit_get_timestamp(const void *fit, int noffset, time_t *timestamp);
  758. int fit_image_get_node(const void *fit, const char *image_uname);
  759. int fit_image_get_os(const void *fit, int noffset, uint8_t *os);
  760. int fit_image_get_arch(const void *fit, int noffset, uint8_t *arch);
  761. int fit_image_get_type(const void *fit, int noffset, uint8_t *type);
  762. int fit_image_get_comp(const void *fit, int noffset, uint8_t *comp);
  763. int fit_image_get_load(const void *fit, int noffset, ulong *load);
  764. int fit_image_get_entry(const void *fit, int noffset, ulong *entry);
  765. int fit_image_get_data(const void *fit, int noffset,
  766. const void **data, size_t *size);
  767. int fit_image_hash_get_algo(const void *fit, int noffset, char **algo);
  768. int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value,
  769. int *value_len);
  770. int fit_set_timestamp(void *fit, int noffset, time_t timestamp);
  771. /**
  772. * fit_add_verification_data() - add verification data to FIT image nodes
  773. *
  774. * @keydir: Directory containing keys
  775. * @kwydest: FDT blob to write public key information to
  776. * @fit: Pointer to the FIT format image header
  777. * @comment: Comment to add to signature nodes
  778. * @require_keys: Mark all keys as 'required'
  779. *
  780. * Adds hash values for all component images in the FIT blob.
  781. * Hashes are calculated for all component images which have hash subnodes
  782. * with algorithm property set to one of the supported hash algorithms.
  783. *
  784. * Also add signatures if signature nodes are present.
  785. *
  786. * returns
  787. * 0, on success
  788. * libfdt error code, on failure
  789. */
  790. int fit_add_verification_data(const char *keydir, void *keydest, void *fit,
  791. const char *comment, int require_keys);
  792. int fit_image_verify(const void *fit, int noffset);
  793. int fit_config_verify(const void *fit, int conf_noffset);
  794. int fit_all_image_verify(const void *fit);
  795. int fit_image_check_os(const void *fit, int noffset, uint8_t os);
  796. int fit_image_check_arch(const void *fit, int noffset, uint8_t arch);
  797. int fit_image_check_type(const void *fit, int noffset, uint8_t type);
  798. int fit_image_check_comp(const void *fit, int noffset, uint8_t comp);
  799. int fit_check_format(const void *fit);
  800. int fit_conf_find_compat(const void *fit, const void *fdt);
  801. int fit_conf_get_node(const void *fit, const char *conf_uname);
  802. /**
  803. * fit_conf_get_prop_node() - Get node refered to by a configuration
  804. * @fit: FIT to check
  805. * @noffset: Offset of conf@xxx node to check
  806. * @prop_name: Property to read from the conf node
  807. *
  808. * The conf@ nodes contain references to other nodes, using properties
  809. * like 'kernel = "kernel@1"'. Given such a property name (e.g. "kernel"),
  810. * return the offset of the node referred to (e.g. offset of node
  811. * "/images/kernel@1".
  812. */
  813. int fit_conf_get_prop_node(const void *fit, int noffset,
  814. const char *prop_name);
  815. void fit_conf_print(const void *fit, int noffset, const char *p);
  816. int fit_check_ramdisk(const void *fit, int os_noffset,
  817. uint8_t arch, int verify);
  818. int calculate_hash(const void *data, int data_len, const char *algo,
  819. uint8_t *value, int *value_len);
  820. /*
  821. * At present we only support signing on the host, and verification on the
  822. * device
  823. */
  824. #if defined(CONFIG_FIT_SIGNATURE)
  825. # ifdef USE_HOSTCC
  826. # define IMAGE_ENABLE_SIGN 1
  827. # define IMAGE_ENABLE_VERIFY 1
  828. # include <openssl/evp.h>
  829. #else
  830. # define IMAGE_ENABLE_SIGN 0
  831. # define IMAGE_ENABLE_VERIFY 1
  832. # endif
  833. #else
  834. # define IMAGE_ENABLE_SIGN 0
  835. # define IMAGE_ENABLE_VERIFY 0
  836. #endif
  837. #ifdef USE_HOSTCC
  838. void *image_get_host_blob(void);
  839. void image_set_host_blob(void *host_blob);
  840. # define gd_fdt_blob() image_get_host_blob()
  841. #else
  842. # define gd_fdt_blob() (gd->fdt_blob)
  843. #endif
  844. #ifdef CONFIG_FIT_BEST_MATCH
  845. #define IMAGE_ENABLE_BEST_MATCH 1
  846. #else
  847. #define IMAGE_ENABLE_BEST_MATCH 0
  848. #endif
  849. /* Information passed to the signing routines */
  850. struct image_sign_info {
  851. const char *keydir; /* Directory conaining keys */
  852. const char *keyname; /* Name of key to use */
  853. void *fit; /* Pointer to FIT blob */
  854. int node_offset; /* Offset of signature node */
  855. struct image_sig_algo *algo; /* Algorithm information */
  856. const void *fdt_blob; /* FDT containing public keys */
  857. int required_keynode; /* Node offset of key to use: -1=any */
  858. const char *require_keys; /* Value for 'required' property */
  859. };
  860. #endif /* Allow struct image_region to always be defined for rsa.h */
  861. /* A part of an image, used for hashing */
  862. struct image_region {
  863. const void *data;
  864. int size;
  865. };
  866. #if IMAGE_ENABLE_FIT
  867. #if IMAGE_ENABLE_VERIFY
  868. # include <u-boot/rsa-checksum.h>
  869. #endif
  870. struct checksum_algo {
  871. const char *name;
  872. const int checksum_len;
  873. const int pad_len;
  874. #if IMAGE_ENABLE_SIGN
  875. const EVP_MD *(*calculate_sign)(void);
  876. #endif
  877. int (*calculate)(const char *name,
  878. const struct image_region region[],
  879. int region_count, uint8_t *checksum);
  880. const uint8_t *rsa_padding;
  881. };
  882. struct image_sig_algo {
  883. const char *name; /* Name of algorithm */
  884. /**
  885. * sign() - calculate and return signature for given input data
  886. *
  887. * @info: Specifies key and FIT information
  888. * @data: Pointer to the input data
  889. * @data_len: Data length
  890. * @sigp: Set to an allocated buffer holding the signature
  891. * @sig_len: Set to length of the calculated hash
  892. *
  893. * This computes input data signature according to selected algorithm.
  894. * Resulting signature value is placed in an allocated buffer, the
  895. * pointer is returned as *sigp. The length of the calculated
  896. * signature is returned via the sig_len pointer argument. The caller
  897. * should free *sigp.
  898. *
  899. * @return: 0, on success, -ve on error
  900. */
  901. int (*sign)(struct image_sign_info *info,
  902. const struct image_region region[],
  903. int region_count, uint8_t **sigp, uint *sig_len);
  904. /**
  905. * add_verify_data() - Add verification information to FDT
  906. *
  907. * Add public key information to the FDT node, suitable for
  908. * verification at run-time. The information added depends on the
  909. * algorithm being used.
  910. *
  911. * @info: Specifies key and FIT information
  912. * @keydest: Destination FDT blob for public key data
  913. * @return: 0, on success, -ve on error
  914. */
  915. int (*add_verify_data)(struct image_sign_info *info, void *keydest);
  916. /**
  917. * verify() - Verify a signature against some data
  918. *
  919. * @info: Specifies key and FIT information
  920. * @data: Pointer to the input data
  921. * @data_len: Data length
  922. * @sig: Signature
  923. * @sig_len: Number of bytes in signature
  924. * @return 0 if verified, -ve on error
  925. */
  926. int (*verify)(struct image_sign_info *info,
  927. const struct image_region region[], int region_count,
  928. uint8_t *sig, uint sig_len);
  929. /* pointer to checksum algorithm */
  930. struct checksum_algo *checksum;
  931. };
  932. /**
  933. * image_get_sig_algo() - Look up a signature algortihm
  934. *
  935. * @param name Name of algorithm
  936. * @return pointer to algorithm information, or NULL if not found
  937. */
  938. struct image_sig_algo *image_get_sig_algo(const char *name);
  939. /**
  940. * fit_image_verify_required_sigs() - Verify signatures marked as 'required'
  941. *
  942. * @fit: FIT to check
  943. * @image_noffset: Offset of image node to check
  944. * @data: Image data to check
  945. * @size: Size of image data
  946. * @sig_blob: FDT containing public keys
  947. * @no_sigsp: Returns 1 if no signatures were required, and
  948. * therefore nothing was checked. The caller may wish
  949. * to fall back to other mechanisms, or refuse to
  950. * boot.
  951. * @return 0 if all verified ok, <0 on error
  952. */
  953. int fit_image_verify_required_sigs(const void *fit, int image_noffset,
  954. const char *data, size_t size, const void *sig_blob,
  955. int *no_sigsp);
  956. /**
  957. * fit_image_check_sig() - Check a single image signature node
  958. *
  959. * @fit: FIT to check
  960. * @noffset: Offset of signature node to check
  961. * @data: Image data to check
  962. * @size: Size of image data
  963. * @required_keynode: Offset in the control FDT of the required key node,
  964. * if any. If this is given, then the image wil not
  965. * pass verification unless that key is used. If this is
  966. * -1 then any signature will do.
  967. * @err_msgp: In the event of an error, this will be pointed to a
  968. * help error string to display to the user.
  969. * @return 0 if all verified ok, <0 on error
  970. */
  971. int fit_image_check_sig(const void *fit, int noffset, const void *data,
  972. size_t size, int required_keynode, char **err_msgp);
  973. /**
  974. * fit_region_make_list() - Make a list of regions to hash
  975. *
  976. * Given a list of FIT regions (offset, size) provided by libfdt, create
  977. * a list of regions (void *, size) for use by the signature creationg
  978. * and verification code.
  979. *
  980. * @fit: FIT image to process
  981. * @fdt_regions: Regions as returned by libfdt
  982. * @count: Number of regions returned by libfdt
  983. * @region: Place to put list of regions (NULL to allocate it)
  984. * @return pointer to list of regions, or NULL if out of memory
  985. */
  986. struct image_region *fit_region_make_list(const void *fit,
  987. struct fdt_region *fdt_regions, int count,
  988. struct image_region *region);
  989. static inline int fit_image_check_target_arch(const void *fdt, int node)
  990. {
  991. #ifndef USE_HOSTCC
  992. return fit_image_check_arch(fdt, node, IH_ARCH_DEFAULT);
  993. #else
  994. return 0;
  995. #endif
  996. }
  997. #ifdef CONFIG_FIT_VERBOSE
  998. #define fit_unsupported(msg) printf("! %s:%d " \
  999. "FIT images not supported for '%s'\n", \
  1000. __FILE__, __LINE__, (msg))
  1001. #define fit_unsupported_reset(msg) printf("! %s:%d " \
  1002. "FIT images not supported for '%s' " \
  1003. "- must reset board to recover!\n", \
  1004. __FILE__, __LINE__, (msg))
  1005. #else
  1006. #define fit_unsupported(msg)
  1007. #define fit_unsupported_reset(msg)
  1008. #endif /* CONFIG_FIT_VERBOSE */
  1009. #endif /* CONFIG_FIT */
  1010. #if defined(CONFIG_ANDROID_BOOT_IMAGE)
  1011. struct andr_img_hdr;
  1012. int android_image_check_header(const struct andr_img_hdr *hdr);
  1013. int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
  1014. ulong *os_data, ulong *os_len);
  1015. int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
  1016. ulong *rd_data, ulong *rd_len);
  1017. ulong android_image_get_end(const struct andr_img_hdr *hdr);
  1018. ulong android_image_get_kload(const struct andr_img_hdr *hdr);
  1019. #endif /* CONFIG_ANDROID_BOOT_IMAGE */
  1020. /**
  1021. * board_fit_config_name_match() - Check for a matching board name
  1022. *
  1023. * This is used when SPL loads a FIT containing multiple device tree files
  1024. * and wants to work out which one to use. The description of each one is
  1025. * passed to this function. The description comes from the 'description' field
  1026. * in each (FDT) image node.
  1027. *
  1028. * @name: Device tree description
  1029. * @return 0 if this device tree should be used, non-zero to try the next
  1030. */
  1031. int board_fit_config_name_match(const char *name);
  1032. #endif /* __IMAGE_H__ */