image.h 39 KB

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