image.h 41 KB

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