image.h 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (C) Copyright 2008 Semihalf
  4. *
  5. * (C) Copyright 2000-2005
  6. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  7. ********************************************************************
  8. * NOTE: This header file defines an interface to U-Boot. Including
  9. * this (unmodified) header file in another file is considered normal
  10. * use of U-Boot, and does *not* fall under the heading of "derived
  11. * work".
  12. ********************************************************************
  13. */
  14. #ifndef __IMAGE_H__
  15. #define __IMAGE_H__
  16. #include "compiler.h"
  17. #include <asm/byteorder.h>
  18. #include <stdbool.h>
  19. /* Define this to avoid #ifdefs later on */
  20. struct lmb;
  21. struct fdt_region;
  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 CONFIG_FIT_ENABLE_RSASSA_PSS_SUPPORT 1
  29. #define CONFIG_FIT_ENABLE_SHA256_SUPPORT
  30. #define CONFIG_FIT_ENABLE_SHA384_SUPPORT
  31. #define CONFIG_FIT_ENABLE_SHA512_SUPPORT
  32. #define CONFIG_SHA1
  33. #define CONFIG_SHA256
  34. #define CONFIG_SHA384
  35. #define CONFIG_SHA512
  36. #define IMAGE_ENABLE_IGNORE 0
  37. #define IMAGE_INDENT_STRING ""
  38. #else
  39. #include <lmb.h>
  40. #include <asm/u-boot.h>
  41. #include <command.h>
  42. /* Take notice of the 'ignore' property for hashes */
  43. #define IMAGE_ENABLE_IGNORE 1
  44. #define IMAGE_INDENT_STRING " "
  45. #define IMAGE_ENABLE_FIT CONFIG_IS_ENABLED(FIT)
  46. #define IMAGE_ENABLE_OF_LIBFDT CONFIG_IS_ENABLED(OF_LIBFDT)
  47. #endif /* USE_HOSTCC */
  48. #if IMAGE_ENABLE_FIT
  49. #include <hash.h>
  50. #include <linux/libfdt.h>
  51. #include <fdt_support.h>
  52. # ifdef CONFIG_SPL_BUILD
  53. # ifdef CONFIG_SPL_CRC32_SUPPORT
  54. # define IMAGE_ENABLE_CRC32 1
  55. # endif
  56. # ifdef CONFIG_SPL_MD5_SUPPORT
  57. # define IMAGE_ENABLE_MD5 1
  58. # endif
  59. # ifdef CONFIG_SPL_SHA1_SUPPORT
  60. # define IMAGE_ENABLE_SHA1 1
  61. # endif
  62. # else
  63. # define IMAGE_ENABLE_CRC32 1
  64. # define IMAGE_ENABLE_MD5 1
  65. # define IMAGE_ENABLE_SHA1 1
  66. # endif
  67. #ifndef IMAGE_ENABLE_CRC32
  68. #define IMAGE_ENABLE_CRC32 0
  69. #endif
  70. #ifndef IMAGE_ENABLE_MD5
  71. #define IMAGE_ENABLE_MD5 0
  72. #endif
  73. #ifndef IMAGE_ENABLE_SHA1
  74. #define IMAGE_ENABLE_SHA1 0
  75. #endif
  76. #if defined(CONFIG_FIT_ENABLE_SHA256_SUPPORT) || \
  77. defined(CONFIG_SPL_SHA256_SUPPORT)
  78. #define IMAGE_ENABLE_SHA256 1
  79. #else
  80. #define IMAGE_ENABLE_SHA256 0
  81. #endif
  82. #if defined(CONFIG_FIT_ENABLE_SHA384_SUPPORT) || \
  83. defined(CONFIG_SPL_SHA384_SUPPORT)
  84. #define IMAGE_ENABLE_SHA384 1
  85. #else
  86. #define IMAGE_ENABLE_SHA384 0
  87. #endif
  88. #if defined(CONFIG_FIT_ENABLE_SHA512_SUPPORT) || \
  89. defined(CONFIG_SPL_SHA512_SUPPORT)
  90. #define IMAGE_ENABLE_SHA512 1
  91. #else
  92. #define IMAGE_ENABLE_SHA512 0
  93. #endif
  94. #endif /* IMAGE_ENABLE_FIT */
  95. #ifdef CONFIG_SYS_BOOT_GET_CMDLINE
  96. # define IMAGE_BOOT_GET_CMDLINE 1
  97. #else
  98. # define IMAGE_BOOT_GET_CMDLINE 0
  99. #endif
  100. #ifdef CONFIG_OF_BOARD_SETUP
  101. # define IMAGE_OF_BOARD_SETUP 1
  102. #else
  103. # define IMAGE_OF_BOARD_SETUP 0
  104. #endif
  105. #ifdef CONFIG_OF_SYSTEM_SETUP
  106. # define IMAGE_OF_SYSTEM_SETUP 1
  107. #else
  108. # define IMAGE_OF_SYSTEM_SETUP 0
  109. #endif
  110. extern ulong image_load_addr; /* Default Load Address */
  111. extern ulong image_save_addr; /* Default Save Address */
  112. extern ulong image_save_size; /* Default Save Size */
  113. /* An invalid size, meaning that the image size is not known */
  114. #define IMAGE_SIZE_INVAL (-1UL)
  115. enum ih_category {
  116. IH_ARCH,
  117. IH_COMP,
  118. IH_OS,
  119. IH_TYPE,
  120. IH_COUNT,
  121. };
  122. /*
  123. * Operating System Codes
  124. *
  125. * The following are exposed to uImage header.
  126. * New IDs *MUST* be appended at the end of the list and *NEVER*
  127. * inserted for backward compatibility.
  128. */
  129. enum {
  130. IH_OS_INVALID = 0, /* Invalid OS */
  131. IH_OS_OPENBSD, /* OpenBSD */
  132. IH_OS_NETBSD, /* NetBSD */
  133. IH_OS_FREEBSD, /* FreeBSD */
  134. IH_OS_4_4BSD, /* 4.4BSD */
  135. IH_OS_LINUX, /* Linux */
  136. IH_OS_SVR4, /* SVR4 */
  137. IH_OS_ESIX, /* Esix */
  138. IH_OS_SOLARIS, /* Solaris */
  139. IH_OS_IRIX, /* Irix */
  140. IH_OS_SCO, /* SCO */
  141. IH_OS_DELL, /* Dell */
  142. IH_OS_NCR, /* NCR */
  143. IH_OS_LYNXOS, /* LynxOS */
  144. IH_OS_VXWORKS, /* VxWorks */
  145. IH_OS_PSOS, /* pSOS */
  146. IH_OS_QNX, /* QNX */
  147. IH_OS_U_BOOT, /* Firmware */
  148. IH_OS_RTEMS, /* RTEMS */
  149. IH_OS_ARTOS, /* ARTOS */
  150. IH_OS_UNITY, /* Unity OS */
  151. IH_OS_INTEGRITY, /* INTEGRITY */
  152. IH_OS_OSE, /* OSE */
  153. IH_OS_PLAN9, /* Plan 9 */
  154. IH_OS_OPENRTOS, /* OpenRTOS */
  155. IH_OS_ARM_TRUSTED_FIRMWARE, /* ARM Trusted Firmware */
  156. IH_OS_TEE, /* Trusted Execution Environment */
  157. IH_OS_OPENSBI, /* RISC-V OpenSBI */
  158. IH_OS_EFI, /* EFI Firmware (e.g. GRUB2) */
  159. IH_OS_COUNT,
  160. };
  161. /*
  162. * CPU Architecture Codes (supported by Linux)
  163. *
  164. * The following are exposed to uImage header.
  165. * New IDs *MUST* be appended at the end of the list and *NEVER*
  166. * inserted for backward compatibility.
  167. */
  168. enum {
  169. IH_ARCH_INVALID = 0, /* Invalid CPU */
  170. IH_ARCH_ALPHA, /* Alpha */
  171. IH_ARCH_ARM, /* ARM */
  172. IH_ARCH_I386, /* Intel x86 */
  173. IH_ARCH_IA64, /* IA64 */
  174. IH_ARCH_MIPS, /* MIPS */
  175. IH_ARCH_MIPS64, /* MIPS 64 Bit */
  176. IH_ARCH_PPC, /* PowerPC */
  177. IH_ARCH_S390, /* IBM S390 */
  178. IH_ARCH_SH, /* SuperH */
  179. IH_ARCH_SPARC, /* Sparc */
  180. IH_ARCH_SPARC64, /* Sparc 64 Bit */
  181. IH_ARCH_M68K, /* M68K */
  182. IH_ARCH_NIOS, /* Nios-32 */
  183. IH_ARCH_MICROBLAZE, /* MicroBlaze */
  184. IH_ARCH_NIOS2, /* Nios-II */
  185. IH_ARCH_BLACKFIN, /* Blackfin */
  186. IH_ARCH_AVR32, /* AVR32 */
  187. IH_ARCH_ST200, /* STMicroelectronics ST200 */
  188. IH_ARCH_SANDBOX, /* Sandbox architecture (test only) */
  189. IH_ARCH_NDS32, /* ANDES Technology - NDS32 */
  190. IH_ARCH_OPENRISC, /* OpenRISC 1000 */
  191. IH_ARCH_ARM64, /* ARM64 */
  192. IH_ARCH_ARC, /* Synopsys DesignWare ARC */
  193. IH_ARCH_X86_64, /* AMD x86_64, Intel and Via */
  194. IH_ARCH_XTENSA, /* Xtensa */
  195. IH_ARCH_RISCV, /* RISC-V */
  196. IH_ARCH_COUNT,
  197. };
  198. /*
  199. * Image Types
  200. *
  201. * "Standalone Programs" are directly runnable in the environment
  202. * provided by U-Boot; it is expected that (if they behave
  203. * well) you can continue to work in U-Boot after return from
  204. * the Standalone Program.
  205. * "OS Kernel Images" are usually images of some Embedded OS which
  206. * will take over control completely. Usually these programs
  207. * will install their own set of exception handlers, device
  208. * drivers, set up the MMU, etc. - this means, that you cannot
  209. * expect to re-enter U-Boot except by resetting the CPU.
  210. * "RAMDisk Images" are more or less just data blocks, and their
  211. * parameters (address, size) are passed to an OS kernel that is
  212. * being started.
  213. * "Multi-File Images" contain several images, typically an OS
  214. * (Linux) kernel image and one or more data images like
  215. * RAMDisks. This construct is useful for instance when you want
  216. * to boot over the network using BOOTP etc., where the boot
  217. * server provides just a single image file, but you want to get
  218. * for instance an OS kernel and a RAMDisk image.
  219. *
  220. * "Multi-File Images" start with a list of image sizes, each
  221. * image size (in bytes) specified by an "uint32_t" in network
  222. * byte order. This list is terminated by an "(uint32_t)0".
  223. * Immediately after the terminating 0 follow the images, one by
  224. * one, all aligned on "uint32_t" boundaries (size rounded up to
  225. * a multiple of 4 bytes - except for the last file).
  226. *
  227. * "Firmware Images" are binary images containing firmware (like
  228. * U-Boot or FPGA images) which usually will be programmed to
  229. * flash memory.
  230. *
  231. * "Script files" are command sequences that will be executed by
  232. * U-Boot's command interpreter; this feature is especially
  233. * useful when you configure U-Boot to use a real shell (hush)
  234. * as command interpreter (=> Shell Scripts).
  235. *
  236. * The following are exposed to uImage header.
  237. * New IDs *MUST* be appended at the end of the list and *NEVER*
  238. * inserted for backward compatibility.
  239. */
  240. enum {
  241. IH_TYPE_INVALID = 0, /* Invalid Image */
  242. IH_TYPE_STANDALONE, /* Standalone Program */
  243. IH_TYPE_KERNEL, /* OS Kernel Image */
  244. IH_TYPE_RAMDISK, /* RAMDisk Image */
  245. IH_TYPE_MULTI, /* Multi-File Image */
  246. IH_TYPE_FIRMWARE, /* Firmware Image */
  247. IH_TYPE_SCRIPT, /* Script file */
  248. IH_TYPE_FILESYSTEM, /* Filesystem Image (any type) */
  249. IH_TYPE_FLATDT, /* Binary Flat Device Tree Blob */
  250. IH_TYPE_KWBIMAGE, /* Kirkwood Boot Image */
  251. IH_TYPE_IMXIMAGE, /* Freescale IMXBoot Image */
  252. IH_TYPE_UBLIMAGE, /* Davinci UBL Image */
  253. IH_TYPE_OMAPIMAGE, /* TI OMAP Config Header Image */
  254. IH_TYPE_AISIMAGE, /* TI Davinci AIS Image */
  255. /* OS Kernel Image, can run from any load address */
  256. IH_TYPE_KERNEL_NOLOAD,
  257. IH_TYPE_PBLIMAGE, /* Freescale PBL Boot Image */
  258. IH_TYPE_MXSIMAGE, /* Freescale MXSBoot Image */
  259. IH_TYPE_GPIMAGE, /* TI Keystone GPHeader Image */
  260. IH_TYPE_ATMELIMAGE, /* ATMEL ROM bootable Image */
  261. IH_TYPE_SOCFPGAIMAGE, /* Altera SOCFPGA CV/AV Preloader */
  262. IH_TYPE_X86_SETUP, /* x86 setup.bin Image */
  263. IH_TYPE_LPC32XXIMAGE, /* x86 setup.bin Image */
  264. IH_TYPE_LOADABLE, /* A list of typeless images */
  265. IH_TYPE_RKIMAGE, /* Rockchip Boot Image */
  266. IH_TYPE_RKSD, /* Rockchip SD card */
  267. IH_TYPE_RKSPI, /* Rockchip SPI image */
  268. IH_TYPE_ZYNQIMAGE, /* Xilinx Zynq Boot Image */
  269. IH_TYPE_ZYNQMPIMAGE, /* Xilinx ZynqMP Boot Image */
  270. IH_TYPE_ZYNQMPBIF, /* Xilinx ZynqMP Boot Image (bif) */
  271. IH_TYPE_FPGA, /* FPGA Image */
  272. IH_TYPE_VYBRIDIMAGE, /* VYBRID .vyb Image */
  273. IH_TYPE_TEE, /* Trusted Execution Environment OS Image */
  274. IH_TYPE_FIRMWARE_IVT, /* Firmware Image with HABv4 IVT */
  275. IH_TYPE_PMMC, /* TI Power Management Micro-Controller Firmware */
  276. IH_TYPE_STM32IMAGE, /* STMicroelectronics STM32 Image */
  277. IH_TYPE_SOCFPGAIMAGE_V1, /* Altera SOCFPGA A10 Preloader */
  278. IH_TYPE_MTKIMAGE, /* MediaTek BootROM loadable Image */
  279. IH_TYPE_IMX8MIMAGE, /* Freescale IMX8MBoot Image */
  280. IH_TYPE_IMX8IMAGE, /* Freescale IMX8Boot Image */
  281. IH_TYPE_COPRO, /* Coprocessor Image for remoteproc*/
  282. IH_TYPE_SUNXI_EGON, /* Allwinner eGON Boot Image */
  283. IH_TYPE_COUNT, /* Number of image types */
  284. };
  285. /*
  286. * Compression Types
  287. *
  288. * The following are exposed to uImage header.
  289. * New IDs *MUST* be appended at the end of the list and *NEVER*
  290. * inserted for backward compatibility.
  291. */
  292. enum {
  293. IH_COMP_NONE = 0, /* No Compression Used */
  294. IH_COMP_GZIP, /* gzip Compression Used */
  295. IH_COMP_BZIP2, /* bzip2 Compression Used */
  296. IH_COMP_LZMA, /* lzma Compression Used */
  297. IH_COMP_LZO, /* lzo Compression Used */
  298. IH_COMP_LZ4, /* lz4 Compression Used */
  299. IH_COMP_ZSTD, /* zstd Compression Used */
  300. IH_COMP_COUNT,
  301. };
  302. #define LZ4F_MAGIC 0x184D2204 /* LZ4 Magic Number */
  303. #define IH_MAGIC 0x27051956 /* Image Magic Number */
  304. #define IH_NMLEN 32 /* Image Name Length */
  305. /* Reused from common.h */
  306. #define ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1))
  307. /*
  308. * Legacy format image header,
  309. * all data in network byte order (aka natural aka bigendian).
  310. */
  311. typedef struct image_header {
  312. uint32_t ih_magic; /* Image Header Magic Number */
  313. uint32_t ih_hcrc; /* Image Header CRC Checksum */
  314. uint32_t ih_time; /* Image Creation Timestamp */
  315. uint32_t ih_size; /* Image Data Size */
  316. uint32_t ih_load; /* Data Load Address */
  317. uint32_t ih_ep; /* Entry Point Address */
  318. uint32_t ih_dcrc; /* Image Data CRC Checksum */
  319. uint8_t ih_os; /* Operating System */
  320. uint8_t ih_arch; /* CPU architecture */
  321. uint8_t ih_type; /* Image Type */
  322. uint8_t ih_comp; /* Compression Type */
  323. uint8_t ih_name[IH_NMLEN]; /* Image Name */
  324. } image_header_t;
  325. typedef struct image_info {
  326. ulong start, end; /* start/end of blob */
  327. ulong image_start, image_len; /* start of image within blob, len of image */
  328. ulong load; /* load addr for the image */
  329. uint8_t comp, type, os; /* compression, type of image, os type */
  330. uint8_t arch; /* CPU architecture */
  331. } image_info_t;
  332. /*
  333. * Legacy and FIT format headers used by do_bootm() and do_bootm_<os>()
  334. * routines.
  335. */
  336. typedef struct bootm_headers {
  337. /*
  338. * Legacy os image header, if it is a multi component image
  339. * then boot_get_ramdisk() and get_fdt() will attempt to get
  340. * data from second and third component accordingly.
  341. */
  342. image_header_t *legacy_hdr_os; /* image header pointer */
  343. image_header_t legacy_hdr_os_copy; /* header copy */
  344. ulong legacy_hdr_valid;
  345. #if IMAGE_ENABLE_FIT
  346. const char *fit_uname_cfg; /* configuration node unit name */
  347. void *fit_hdr_os; /* os FIT image header */
  348. const char *fit_uname_os; /* os subimage node unit name */
  349. int fit_noffset_os; /* os subimage node offset */
  350. void *fit_hdr_rd; /* init ramdisk FIT image header */
  351. const char *fit_uname_rd; /* init ramdisk subimage node unit name */
  352. int fit_noffset_rd; /* init ramdisk subimage node offset */
  353. void *fit_hdr_fdt; /* FDT blob FIT image header */
  354. const char *fit_uname_fdt; /* FDT blob subimage node unit name */
  355. int fit_noffset_fdt;/* FDT blob subimage node offset */
  356. void *fit_hdr_setup; /* x86 setup FIT image header */
  357. const char *fit_uname_setup; /* x86 setup subimage node name */
  358. int fit_noffset_setup;/* x86 setup subimage node offset */
  359. #endif
  360. #ifndef USE_HOSTCC
  361. image_info_t os; /* os image info */
  362. ulong ep; /* entry point of OS */
  363. ulong rd_start, rd_end;/* ramdisk start/end */
  364. char *ft_addr; /* flat dev tree address */
  365. ulong ft_len; /* length of flat device tree */
  366. ulong initrd_start;
  367. ulong initrd_end;
  368. ulong cmdline_start;
  369. ulong cmdline_end;
  370. struct bd_info *kbd;
  371. #endif
  372. int verify; /* env_get("verify")[0] != 'n' */
  373. #define BOOTM_STATE_START (0x00000001)
  374. #define BOOTM_STATE_FINDOS (0x00000002)
  375. #define BOOTM_STATE_FINDOTHER (0x00000004)
  376. #define BOOTM_STATE_LOADOS (0x00000008)
  377. #define BOOTM_STATE_RAMDISK (0x00000010)
  378. #define BOOTM_STATE_FDT (0x00000020)
  379. #define BOOTM_STATE_OS_CMDLINE (0x00000040)
  380. #define BOOTM_STATE_OS_BD_T (0x00000080)
  381. #define BOOTM_STATE_OS_PREP (0x00000100)
  382. #define BOOTM_STATE_OS_FAKE_GO (0x00000200) /* 'Almost' run the OS */
  383. #define BOOTM_STATE_OS_GO (0x00000400)
  384. int state;
  385. #ifdef CONFIG_LMB
  386. struct lmb lmb; /* for memory mgmt */
  387. #endif
  388. } bootm_headers_t;
  389. extern bootm_headers_t images;
  390. /*
  391. * Some systems (for example LWMON) have very short watchdog periods;
  392. * we must make sure to split long operations like memmove() or
  393. * checksum calculations into reasonable chunks.
  394. */
  395. #ifndef CHUNKSZ
  396. #define CHUNKSZ (64 * 1024)
  397. #endif
  398. #ifndef CHUNKSZ_CRC32
  399. #define CHUNKSZ_CRC32 (64 * 1024)
  400. #endif
  401. #ifndef CHUNKSZ_MD5
  402. #define CHUNKSZ_MD5 (64 * 1024)
  403. #endif
  404. #ifndef CHUNKSZ_SHA1
  405. #define CHUNKSZ_SHA1 (64 * 1024)
  406. #endif
  407. #define uimage_to_cpu(x) be32_to_cpu(x)
  408. #define cpu_to_uimage(x) cpu_to_be32(x)
  409. /*
  410. * Translation table for entries of a specific type; used by
  411. * get_table_entry_id() and get_table_entry_name().
  412. */
  413. typedef struct table_entry {
  414. int id;
  415. char *sname; /* short (input) name to find table entry */
  416. char *lname; /* long (output) name to print for messages */
  417. } table_entry_t;
  418. /*
  419. * Compression type and magic number mapping table.
  420. */
  421. struct comp_magic_map {
  422. int comp_id;
  423. const char *name;
  424. unsigned char magic[2];
  425. };
  426. /*
  427. * get_table_entry_id() scans the translation table trying to find an
  428. * entry that matches the given short name. If a matching entry is
  429. * found, it's id is returned to the caller.
  430. */
  431. int get_table_entry_id(const table_entry_t *table,
  432. const char *table_name, const char *name);
  433. /*
  434. * get_table_entry_name() scans the translation table trying to find
  435. * an entry that matches the given id. If a matching entry is found,
  436. * its long name is returned to the caller.
  437. */
  438. char *get_table_entry_name(const table_entry_t *table, char *msg, int id);
  439. const char *genimg_get_os_name(uint8_t os);
  440. /**
  441. * genimg_get_os_short_name() - get the short name for an OS
  442. *
  443. * @param os OS (IH_OS_...)
  444. * @return OS short name, or "unknown" if unknown
  445. */
  446. const char *genimg_get_os_short_name(uint8_t comp);
  447. const char *genimg_get_arch_name(uint8_t arch);
  448. /**
  449. * genimg_get_arch_short_name() - get the short name for an architecture
  450. *
  451. * @param arch Architecture type (IH_ARCH_...)
  452. * @return architecture short name, or "unknown" if unknown
  453. */
  454. const char *genimg_get_arch_short_name(uint8_t arch);
  455. const char *genimg_get_type_name(uint8_t type);
  456. /**
  457. * genimg_get_type_short_name() - get the short name for an image type
  458. *
  459. * @param type Image type (IH_TYPE_...)
  460. * @return image short name, or "unknown" if unknown
  461. */
  462. const char *genimg_get_type_short_name(uint8_t type);
  463. const char *genimg_get_comp_name(uint8_t comp);
  464. /**
  465. * genimg_get_comp_short_name() - get the short name for a compression method
  466. *
  467. * @param comp compression method (IH_COMP_...)
  468. * @return compression method short name, or "unknown" if unknown
  469. */
  470. const char *genimg_get_comp_short_name(uint8_t comp);
  471. /**
  472. * genimg_get_cat_name() - Get the name of an item in a category
  473. *
  474. * @category: Category of item
  475. * @id: Item ID
  476. * @return name of item, or "Unknown ..." if unknown
  477. */
  478. const char *genimg_get_cat_name(enum ih_category category, uint id);
  479. /**
  480. * genimg_get_cat_short_name() - Get the short name of an item in a category
  481. *
  482. * @category: Category of item
  483. * @id: Item ID
  484. * @return short name of item, or "Unknown ..." if unknown
  485. */
  486. const char *genimg_get_cat_short_name(enum ih_category category, uint id);
  487. /**
  488. * genimg_get_cat_count() - Get the number of items in a category
  489. *
  490. * @category: Category to check
  491. * @return the number of items in the category (IH_xxx_COUNT)
  492. */
  493. int genimg_get_cat_count(enum ih_category category);
  494. /**
  495. * genimg_get_cat_desc() - Get the description of a category
  496. *
  497. * @category: Category to check
  498. * @return the description of a category, e.g. "architecture". This
  499. * effectively converts the enum to a string.
  500. */
  501. const char *genimg_get_cat_desc(enum ih_category category);
  502. /**
  503. * genimg_cat_has_id() - Check whether a category has an item
  504. *
  505. * @category: Category to check
  506. * @id: Item ID
  507. * @return true or false as to whether a category has an item
  508. */
  509. bool genimg_cat_has_id(enum ih_category category, uint id);
  510. int genimg_get_os_id(const char *name);
  511. int genimg_get_arch_id(const char *name);
  512. int genimg_get_type_id(const char *name);
  513. int genimg_get_comp_id(const char *name);
  514. void genimg_print_size(uint32_t size);
  515. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || \
  516. defined(USE_HOSTCC)
  517. #define IMAGE_ENABLE_TIMESTAMP 1
  518. #else
  519. #define IMAGE_ENABLE_TIMESTAMP 0
  520. #endif
  521. void genimg_print_time(time_t timestamp);
  522. /* What to do with a image load address ('load = <> 'in the FIT) */
  523. enum fit_load_op {
  524. FIT_LOAD_IGNORED, /* Ignore load address */
  525. FIT_LOAD_OPTIONAL, /* Can be provided, but optional */
  526. FIT_LOAD_OPTIONAL_NON_ZERO, /* Optional, a value of 0 is ignored */
  527. FIT_LOAD_REQUIRED, /* Must be provided */
  528. };
  529. int boot_get_setup(bootm_headers_t *images, uint8_t arch, ulong *setup_start,
  530. ulong *setup_len);
  531. #ifndef USE_HOSTCC
  532. /* Image format types, returned by _get_format() routine */
  533. #define IMAGE_FORMAT_INVALID 0x00
  534. #if defined(CONFIG_LEGACY_IMAGE_FORMAT)
  535. #define IMAGE_FORMAT_LEGACY 0x01 /* legacy image_header based format */
  536. #endif
  537. #define IMAGE_FORMAT_FIT 0x02 /* new, libfdt based format */
  538. #define IMAGE_FORMAT_ANDROID 0x03 /* Android boot image */
  539. ulong genimg_get_kernel_addr_fit(char * const img_addr,
  540. const char **fit_uname_config,
  541. const char **fit_uname_kernel);
  542. ulong genimg_get_kernel_addr(char * const img_addr);
  543. int genimg_get_format(const void *img_addr);
  544. int genimg_has_config(bootm_headers_t *images);
  545. int boot_get_fpga(int argc, char *const argv[], bootm_headers_t *images,
  546. uint8_t arch, const ulong *ld_start, ulong * const ld_len);
  547. int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images,
  548. uint8_t arch, ulong *rd_start, ulong *rd_end);
  549. /**
  550. * boot_get_loadable - routine to load a list of binaries to memory
  551. * @argc: Ignored Argument
  552. * @argv: Ignored Argument
  553. * @images: pointer to the bootm images structure
  554. * @arch: expected architecture for the image
  555. * @ld_start: Ignored Argument
  556. * @ld_len: Ignored Argument
  557. *
  558. * boot_get_loadable() will take the given FIT configuration, and look
  559. * for a field named "loadables". Loadables, is a list of elements in
  560. * the FIT given as strings. exe:
  561. * loadables = "linux_kernel", "fdt-2";
  562. * this function will attempt to parse each string, and load the
  563. * corresponding element from the FIT into memory. Once placed,
  564. * no aditional actions are taken.
  565. *
  566. * @return:
  567. * 0, if only valid images or no images are found
  568. * error code, if an error occurs during fit_image_load
  569. */
  570. int boot_get_loadable(int argc, char *const argv[], bootm_headers_t *images,
  571. uint8_t arch, const ulong *ld_start, ulong *const ld_len);
  572. #endif /* !USE_HOSTCC */
  573. int boot_get_setup_fit(bootm_headers_t *images, uint8_t arch,
  574. ulong *setup_start, ulong *setup_len);
  575. /**
  576. * boot_get_fdt_fit() - load a DTB from a FIT file (applying overlays)
  577. *
  578. * This deals with all aspects of loading an DTB from a FIT.
  579. * The correct base image based on configuration will be selected, and
  580. * then any overlays specified will be applied (as present in fit_uname_configp).
  581. *
  582. * @param images Boot images structure
  583. * @param addr Address of FIT in memory
  584. * @param fit_unamep On entry this is the requested image name
  585. * (e.g. "kernel") or NULL to use the default. On exit
  586. * points to the selected image name
  587. * @param fit_uname_configp On entry this is the requested configuration
  588. * name (e.g. "conf-1") or NULL to use the default. On
  589. * exit points to the selected configuration name.
  590. * @param arch Expected architecture (IH_ARCH_...)
  591. * @param datap Returns address of loaded image
  592. * @param lenp Returns length of loaded image
  593. *
  594. * @return node offset of base image, or -ve error code on error
  595. */
  596. int boot_get_fdt_fit(bootm_headers_t *images, ulong addr,
  597. const char **fit_unamep, const char **fit_uname_configp,
  598. int arch, ulong *datap, ulong *lenp);
  599. /**
  600. * fit_image_load() - load an image from a FIT
  601. *
  602. * This deals with all aspects of loading an image from a FIT, including
  603. * selecting the right image based on configuration, verifying it, printing
  604. * out progress messages, checking the type/arch/os and optionally copying it
  605. * to the right load address.
  606. *
  607. * The property to look up is defined by image_type.
  608. *
  609. * @param images Boot images structure
  610. * @param addr Address of FIT in memory
  611. * @param fit_unamep On entry this is the requested image name
  612. * (e.g. "kernel") or NULL to use the default. On exit
  613. * points to the selected image name
  614. * @param fit_uname_configp On entry this is the requested configuration
  615. * name (e.g. "conf-1") or NULL to use the default. On
  616. * exit points to the selected configuration name.
  617. * @param arch Expected architecture (IH_ARCH_...)
  618. * @param image_type Required image type (IH_TYPE_...). If this is
  619. * IH_TYPE_KERNEL then we allow IH_TYPE_KERNEL_NOLOAD
  620. * also.
  621. * @param bootstage_id ID of starting bootstage to use for progress updates.
  622. * This will be added to the BOOTSTAGE_SUB values when
  623. * calling bootstage_mark()
  624. * @param load_op Decribes what to do with the load address
  625. * @param datap Returns address of loaded image
  626. * @param lenp Returns length of loaded image
  627. * @return node offset of image, or -ve error code on error
  628. */
  629. int fit_image_load(bootm_headers_t *images, ulong addr,
  630. const char **fit_unamep, const char **fit_uname_configp,
  631. int arch, int image_type, int bootstage_id,
  632. enum fit_load_op load_op, ulong *datap, ulong *lenp);
  633. /**
  634. * image_source_script() - Execute a script
  635. *
  636. * Executes a U-Boot script at a particular address in memory. The script should
  637. * have a header (FIT or legacy) with the script type (IH_TYPE_SCRIPT).
  638. *
  639. * @addr: Address of script
  640. * @fit_uname: FIT subimage name
  641. * @return result code (enum command_ret_t)
  642. */
  643. int image_source_script(ulong addr, const char *fit_uname);
  644. #ifndef USE_HOSTCC
  645. /**
  646. * fit_get_node_from_config() - Look up an image a FIT by type
  647. *
  648. * This looks in the selected conf- node (images->fit_uname_cfg) for a
  649. * particular image type (e.g. "kernel") and then finds the image that is
  650. * referred to.
  651. *
  652. * For example, for something like:
  653. *
  654. * images {
  655. * kernel {
  656. * ...
  657. * };
  658. * };
  659. * configurations {
  660. * conf-1 {
  661. * kernel = "kernel";
  662. * };
  663. * };
  664. *
  665. * the function will return the node offset of the kernel@1 node, assuming
  666. * that conf-1 is the chosen configuration.
  667. *
  668. * @param images Boot images structure
  669. * @param prop_name Property name to look up (FIT_..._PROP)
  670. * @param addr Address of FIT in memory
  671. */
  672. int fit_get_node_from_config(bootm_headers_t *images, const char *prop_name,
  673. ulong addr);
  674. int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch,
  675. bootm_headers_t *images,
  676. char **of_flat_tree, ulong *of_size);
  677. void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob);
  678. int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size);
  679. int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len,
  680. ulong *initrd_start, ulong *initrd_end);
  681. int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end);
  682. #ifdef CONFIG_SYS_BOOT_GET_KBD
  683. int boot_get_kbd(struct lmb *lmb, struct bd_info **kbd);
  684. #endif /* CONFIG_SYS_BOOT_GET_KBD */
  685. #endif /* !USE_HOSTCC */
  686. /*******************************************************************/
  687. /* Legacy format specific code (prefixed with image_) */
  688. /*******************************************************************/
  689. static inline uint32_t image_get_header_size(void)
  690. {
  691. return (sizeof(image_header_t));
  692. }
  693. #define image_get_hdr_l(f) \
  694. static inline uint32_t image_get_##f(const image_header_t *hdr) \
  695. { \
  696. return uimage_to_cpu(hdr->ih_##f); \
  697. }
  698. image_get_hdr_l(magic) /* image_get_magic */
  699. image_get_hdr_l(hcrc) /* image_get_hcrc */
  700. image_get_hdr_l(time) /* image_get_time */
  701. image_get_hdr_l(size) /* image_get_size */
  702. image_get_hdr_l(load) /* image_get_load */
  703. image_get_hdr_l(ep) /* image_get_ep */
  704. image_get_hdr_l(dcrc) /* image_get_dcrc */
  705. #define image_get_hdr_b(f) \
  706. static inline uint8_t image_get_##f(const image_header_t *hdr) \
  707. { \
  708. return hdr->ih_##f; \
  709. }
  710. image_get_hdr_b(os) /* image_get_os */
  711. image_get_hdr_b(arch) /* image_get_arch */
  712. image_get_hdr_b(type) /* image_get_type */
  713. image_get_hdr_b(comp) /* image_get_comp */
  714. static inline char *image_get_name(const image_header_t *hdr)
  715. {
  716. return (char *)hdr->ih_name;
  717. }
  718. static inline uint32_t image_get_data_size(const image_header_t *hdr)
  719. {
  720. return image_get_size(hdr);
  721. }
  722. /**
  723. * image_get_data - get image payload start address
  724. * @hdr: image header
  725. *
  726. * image_get_data() returns address of the image payload. For single
  727. * component images it is image data start. For multi component
  728. * images it points to the null terminated table of sub-images sizes.
  729. *
  730. * returns:
  731. * image payload data start address
  732. */
  733. static inline ulong image_get_data(const image_header_t *hdr)
  734. {
  735. return ((ulong)hdr + image_get_header_size());
  736. }
  737. static inline uint32_t image_get_image_size(const image_header_t *hdr)
  738. {
  739. return (image_get_size(hdr) + image_get_header_size());
  740. }
  741. static inline ulong image_get_image_end(const image_header_t *hdr)
  742. {
  743. return ((ulong)hdr + image_get_image_size(hdr));
  744. }
  745. #define image_set_hdr_l(f) \
  746. static inline void image_set_##f(image_header_t *hdr, uint32_t val) \
  747. { \
  748. hdr->ih_##f = cpu_to_uimage(val); \
  749. }
  750. image_set_hdr_l(magic) /* image_set_magic */
  751. image_set_hdr_l(hcrc) /* image_set_hcrc */
  752. image_set_hdr_l(time) /* image_set_time */
  753. image_set_hdr_l(size) /* image_set_size */
  754. image_set_hdr_l(load) /* image_set_load */
  755. image_set_hdr_l(ep) /* image_set_ep */
  756. image_set_hdr_l(dcrc) /* image_set_dcrc */
  757. #define image_set_hdr_b(f) \
  758. static inline void image_set_##f(image_header_t *hdr, uint8_t val) \
  759. { \
  760. hdr->ih_##f = val; \
  761. }
  762. image_set_hdr_b(os) /* image_set_os */
  763. image_set_hdr_b(arch) /* image_set_arch */
  764. image_set_hdr_b(type) /* image_set_type */
  765. image_set_hdr_b(comp) /* image_set_comp */
  766. static inline void image_set_name(image_header_t *hdr, const char *name)
  767. {
  768. strncpy(image_get_name(hdr), name, IH_NMLEN);
  769. }
  770. int image_check_hcrc(const image_header_t *hdr);
  771. int image_check_dcrc(const image_header_t *hdr);
  772. #ifndef USE_HOSTCC
  773. ulong env_get_bootm_low(void);
  774. phys_size_t env_get_bootm_size(void);
  775. phys_size_t env_get_bootm_mapsize(void);
  776. #endif
  777. void memmove_wd(void *to, void *from, size_t len, ulong chunksz);
  778. static inline int image_check_magic(const image_header_t *hdr)
  779. {
  780. return (image_get_magic(hdr) == IH_MAGIC);
  781. }
  782. static inline int image_check_type(const image_header_t *hdr, uint8_t type)
  783. {
  784. return (image_get_type(hdr) == type);
  785. }
  786. static inline int image_check_arch(const image_header_t *hdr, uint8_t arch)
  787. {
  788. #ifndef USE_HOSTCC
  789. /* Let's assume that sandbox can load any architecture */
  790. if (IS_ENABLED(CONFIG_SANDBOX))
  791. return true;
  792. #endif
  793. return (image_get_arch(hdr) == arch) ||
  794. (image_get_arch(hdr) == IH_ARCH_ARM && arch == IH_ARCH_ARM64);
  795. }
  796. static inline int image_check_os(const image_header_t *hdr, uint8_t os)
  797. {
  798. return (image_get_os(hdr) == os);
  799. }
  800. ulong image_multi_count(const image_header_t *hdr);
  801. void image_multi_getimg(const image_header_t *hdr, ulong idx,
  802. ulong *data, ulong *len);
  803. void image_print_contents(const void *hdr);
  804. #ifndef USE_HOSTCC
  805. static inline int image_check_target_arch(const image_header_t *hdr)
  806. {
  807. #ifndef IH_ARCH_DEFAULT
  808. # error "please define IH_ARCH_DEFAULT in your arch asm/u-boot.h"
  809. #endif
  810. return image_check_arch(hdr, IH_ARCH_DEFAULT);
  811. }
  812. #endif /* USE_HOSTCC */
  813. /**
  814. * image_decomp_type() - Find out compression type of an image
  815. *
  816. * @buf: Address in U-Boot memory where image is loaded.
  817. * @len: Length of the compressed image.
  818. * @return compression type or IH_COMP_NONE if not compressed.
  819. *
  820. * Note: Only following compression types are supported now.
  821. * lzo, lzma, gzip, bzip2
  822. */
  823. int image_decomp_type(const unsigned char *buf, ulong len);
  824. /**
  825. * image_decomp() - decompress an image
  826. *
  827. * @comp: Compression algorithm that is used (IH_COMP_...)
  828. * @load: Destination load address in U-Boot memory
  829. * @image_start Image start address (where we are decompressing from)
  830. * @type: OS type (IH_OS_...)
  831. * @load_bug: Place to decompress to
  832. * @image_buf: Address to decompress from
  833. * @image_len: Number of bytes in @image_buf to decompress
  834. * @unc_len: Available space for decompression
  835. * @return 0 if OK, -ve on error (BOOTM_ERR_...)
  836. */
  837. int image_decomp(int comp, ulong load, ulong image_start, int type,
  838. void *load_buf, void *image_buf, ulong image_len,
  839. uint unc_len, ulong *load_end);
  840. /**
  841. * Set up properties in the FDT
  842. *
  843. * This sets up properties in the FDT that is to be passed to linux.
  844. *
  845. * @images: Images information
  846. * @blob: FDT to update
  847. * @of_size: Size of the FDT
  848. * @lmb: Points to logical memory block structure
  849. * @return 0 if ok, <0 on failure
  850. */
  851. int image_setup_libfdt(bootm_headers_t *images, void *blob,
  852. int of_size, struct lmb *lmb);
  853. /**
  854. * Set up the FDT to use for booting a kernel
  855. *
  856. * This performs ramdisk setup, sets up the FDT if required, and adds
  857. * paramters to the FDT if libfdt is available.
  858. *
  859. * @param images Images information
  860. * @return 0 if ok, <0 on failure
  861. */
  862. int image_setup_linux(bootm_headers_t *images);
  863. /**
  864. * bootz_setup() - Extract stat and size of a Linux xImage
  865. *
  866. * @image: Address of image
  867. * @start: Returns start address of image
  868. * @end : Returns end address of image
  869. * @return 0 if OK, 1 if the image was not recognised
  870. */
  871. int bootz_setup(ulong image, ulong *start, ulong *end);
  872. /**
  873. * Return the correct start address and size of a Linux aarch64 Image.
  874. *
  875. * @image: Address of image
  876. * @start: Returns start address of image
  877. * @size : Returns size image
  878. * @force_reloc: Ignore image->ep field, always place image to RAM start
  879. * @return 0 if OK, 1 if the image was not recognised
  880. */
  881. int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
  882. bool force_reloc);
  883. /*******************************************************************/
  884. /* New uImage format specific code (prefixed with fit_) */
  885. /*******************************************************************/
  886. #define FIT_IMAGES_PATH "/images"
  887. #define FIT_CONFS_PATH "/configurations"
  888. /* hash/signature/key node */
  889. #define FIT_HASH_NODENAME "hash"
  890. #define FIT_ALGO_PROP "algo"
  891. #define FIT_VALUE_PROP "value"
  892. #define FIT_IGNORE_PROP "uboot-ignore"
  893. #define FIT_SIG_NODENAME "signature"
  894. #define FIT_KEY_REQUIRED "required"
  895. #define FIT_KEY_HINT "key-name-hint"
  896. /* cipher node */
  897. #define FIT_CIPHER_NODENAME "cipher"
  898. #define FIT_ALGO_PROP "algo"
  899. /* image node */
  900. #define FIT_DATA_PROP "data"
  901. #define FIT_DATA_POSITION_PROP "data-position"
  902. #define FIT_DATA_OFFSET_PROP "data-offset"
  903. #define FIT_DATA_SIZE_PROP "data-size"
  904. #define FIT_TIMESTAMP_PROP "timestamp"
  905. #define FIT_DESC_PROP "description"
  906. #define FIT_ARCH_PROP "arch"
  907. #define FIT_TYPE_PROP "type"
  908. #define FIT_OS_PROP "os"
  909. #define FIT_COMP_PROP "compression"
  910. #define FIT_ENTRY_PROP "entry"
  911. #define FIT_LOAD_PROP "load"
  912. /* configuration node */
  913. #define FIT_KERNEL_PROP "kernel"
  914. #define FIT_RAMDISK_PROP "ramdisk"
  915. #define FIT_FDT_PROP "fdt"
  916. #define FIT_LOADABLE_PROP "loadables"
  917. #define FIT_DEFAULT_PROP "default"
  918. #define FIT_SETUP_PROP "setup"
  919. #define FIT_FPGA_PROP "fpga"
  920. #define FIT_FIRMWARE_PROP "firmware"
  921. #define FIT_STANDALONE_PROP "standalone"
  922. #define FIT_MAX_HASH_LEN HASH_MAX_DIGEST_SIZE
  923. #if IMAGE_ENABLE_FIT
  924. /* cmdline argument format parsing */
  925. int fit_parse_conf(const char *spec, ulong addr_curr,
  926. ulong *addr, const char **conf_name);
  927. int fit_parse_subimage(const char *spec, ulong addr_curr,
  928. ulong *addr, const char **image_name);
  929. int fit_get_subimage_count(const void *fit, int images_noffset);
  930. void fit_print_contents(const void *fit);
  931. void fit_image_print(const void *fit, int noffset, const char *p);
  932. /**
  933. * fit_get_end - get FIT image size
  934. * @fit: pointer to the FIT format image header
  935. *
  936. * returns:
  937. * size of the FIT image (blob) in memory
  938. */
  939. static inline ulong fit_get_size(const void *fit)
  940. {
  941. return fdt_totalsize(fit);
  942. }
  943. /**
  944. * fit_get_end - get FIT image end
  945. * @fit: pointer to the FIT format image header
  946. *
  947. * returns:
  948. * end address of the FIT image (blob) in memory
  949. */
  950. ulong fit_get_end(const void *fit);
  951. /**
  952. * fit_get_name - get FIT node name
  953. * @fit: pointer to the FIT format image header
  954. *
  955. * returns:
  956. * NULL, on error
  957. * pointer to node name, on success
  958. */
  959. static inline const char *fit_get_name(const void *fit_hdr,
  960. int noffset, int *len)
  961. {
  962. return fdt_get_name(fit_hdr, noffset, len);
  963. }
  964. int fit_get_desc(const void *fit, int noffset, char **desc);
  965. int fit_get_timestamp(const void *fit, int noffset, time_t *timestamp);
  966. int fit_image_get_node(const void *fit, const char *image_uname);
  967. int fit_image_get_os(const void *fit, int noffset, uint8_t *os);
  968. int fit_image_get_arch(const void *fit, int noffset, uint8_t *arch);
  969. int fit_image_get_type(const void *fit, int noffset, uint8_t *type);
  970. int fit_image_get_comp(const void *fit, int noffset, uint8_t *comp);
  971. int fit_image_get_load(const void *fit, int noffset, ulong *load);
  972. int fit_image_get_entry(const void *fit, int noffset, ulong *entry);
  973. int fit_image_get_data(const void *fit, int noffset,
  974. const void **data, size_t *size);
  975. int fit_image_get_data_offset(const void *fit, int noffset, int *data_offset);
  976. int fit_image_get_data_position(const void *fit, int noffset,
  977. int *data_position);
  978. int fit_image_get_data_size(const void *fit, int noffset, int *data_size);
  979. int fit_image_get_data_size_unciphered(const void *fit, int noffset,
  980. size_t *data_size);
  981. int fit_image_get_data_and_size(const void *fit, int noffset,
  982. const void **data, size_t *size);
  983. int fit_image_hash_get_algo(const void *fit, int noffset, char **algo);
  984. int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value,
  985. int *value_len);
  986. int fit_set_timestamp(void *fit, int noffset, time_t timestamp);
  987. int fit_cipher_data(const char *keydir, void *keydest, void *fit,
  988. const char *comment, int require_keys,
  989. const char *engine_id, const char *cmdname);
  990. /**
  991. * fit_add_verification_data() - add verification data to FIT image nodes
  992. *
  993. * @keydir: Directory containing keys
  994. * @kwydest: FDT blob to write public key information to
  995. * @fit: Pointer to the FIT format image header
  996. * @comment: Comment to add to signature nodes
  997. * @require_keys: Mark all keys as 'required'
  998. * @engine_id: Engine to use for signing
  999. * @cmdname: Command name used when reporting errors
  1000. *
  1001. * Adds hash values for all component images in the FIT blob.
  1002. * Hashes are calculated for all component images which have hash subnodes
  1003. * with algorithm property set to one of the supported hash algorithms.
  1004. *
  1005. * Also add signatures if signature nodes are present.
  1006. *
  1007. * returns
  1008. * 0, on success
  1009. * libfdt error code, on failure
  1010. */
  1011. int fit_add_verification_data(const char *keydir, const char *keyfile,
  1012. void *keydest, void *fit, const char *comment,
  1013. int require_keys, const char *engine_id,
  1014. const char *cmdname);
  1015. int fit_image_verify_with_data(const void *fit, int image_noffset,
  1016. const void *data, size_t size);
  1017. int fit_image_verify(const void *fit, int noffset);
  1018. int fit_config_verify(const void *fit, int conf_noffset);
  1019. int fit_all_image_verify(const void *fit);
  1020. int fit_config_decrypt(const void *fit, int conf_noffset);
  1021. int fit_image_check_os(const void *fit, int noffset, uint8_t os);
  1022. int fit_image_check_arch(const void *fit, int noffset, uint8_t arch);
  1023. int fit_image_check_type(const void *fit, int noffset, uint8_t type);
  1024. int fit_image_check_comp(const void *fit, int noffset, uint8_t comp);
  1025. /**
  1026. * fit_check_format() - Check that the FIT is valid
  1027. *
  1028. * This performs various checks on the FIT to make sure it is suitable for
  1029. * use, looking for mandatory properties, nodes, etc.
  1030. *
  1031. * If FIT_FULL_CHECK is enabled, it also runs it through libfdt to make
  1032. * sure that there are no strange tags or broken nodes in the FIT.
  1033. *
  1034. * @fit: pointer to the FIT format image header
  1035. * @return 0 if OK, -ENOEXEC if not an FDT file, -EINVAL if the full FDT check
  1036. * failed (e.g. due to bad structure), -ENOMSG if the description is
  1037. * missing, -EBADMSG if the timestamp is missing, -ENOENT if the /images
  1038. * path is missing
  1039. */
  1040. int fit_check_format(const void *fit, ulong size);
  1041. int fit_conf_find_compat(const void *fit, const void *fdt);
  1042. /**
  1043. * fit_conf_get_node - get node offset for configuration of a given unit name
  1044. * @fit: pointer to the FIT format image header
  1045. * @conf_uname: configuration node unit name (NULL to use default)
  1046. *
  1047. * fit_conf_get_node() finds a configuration (within the '/configurations'
  1048. * parent node) of a provided unit name. If configuration is found its node
  1049. * offset is returned to the caller.
  1050. *
  1051. * When NULL is provided in second argument fit_conf_get_node() will search
  1052. * for a default configuration node instead. Default configuration node unit
  1053. * name is retrieved from FIT_DEFAULT_PROP property of the '/configurations'
  1054. * node.
  1055. *
  1056. * returns:
  1057. * configuration node offset when found (>=0)
  1058. * negative number on failure (FDT_ERR_* code)
  1059. */
  1060. int fit_conf_get_node(const void *fit, const char *conf_uname);
  1061. int fit_conf_get_prop_node_count(const void *fit, int noffset,
  1062. const char *prop_name);
  1063. int fit_conf_get_prop_node_index(const void *fit, int noffset,
  1064. const char *prop_name, int index);
  1065. /**
  1066. * fit_conf_get_prop_node() - Get node refered to by a configuration
  1067. * @fit: FIT to check
  1068. * @noffset: Offset of conf@xxx node to check
  1069. * @prop_name: Property to read from the conf node
  1070. *
  1071. * The conf- nodes contain references to other nodes, using properties
  1072. * like 'kernel = "kernel"'. Given such a property name (e.g. "kernel"),
  1073. * return the offset of the node referred to (e.g. offset of node
  1074. * "/images/kernel".
  1075. */
  1076. int fit_conf_get_prop_node(const void *fit, int noffset,
  1077. const char *prop_name);
  1078. int fit_check_ramdisk(const void *fit, int os_noffset,
  1079. uint8_t arch, int verify);
  1080. #endif /* IMAGE_ENABLE_FIT */
  1081. int calculate_hash(const void *data, int data_len, const char *algo,
  1082. uint8_t *value, int *value_len);
  1083. /*
  1084. * At present we only support signing on the host, and verification on the
  1085. * device
  1086. */
  1087. #if defined(USE_HOSTCC)
  1088. # if defined(CONFIG_FIT_SIGNATURE)
  1089. # define IMAGE_ENABLE_SIGN 1
  1090. # define IMAGE_ENABLE_VERIFY 1
  1091. # define IMAGE_ENABLE_VERIFY_ECDSA 1
  1092. # define FIT_IMAGE_ENABLE_VERIFY 1
  1093. # include <openssl/evp.h>
  1094. # else
  1095. # define IMAGE_ENABLE_SIGN 0
  1096. # define IMAGE_ENABLE_VERIFY 0
  1097. # define IMAGE_ENABLE_VERIFY_ECDSA 0
  1098. # define FIT_IMAGE_ENABLE_VERIFY 0
  1099. # endif
  1100. #else
  1101. # define IMAGE_ENABLE_SIGN 0
  1102. # define IMAGE_ENABLE_VERIFY CONFIG_IS_ENABLED(RSA_VERIFY)
  1103. # define IMAGE_ENABLE_VERIFY_ECDSA 0
  1104. # define FIT_IMAGE_ENABLE_VERIFY CONFIG_IS_ENABLED(FIT_SIGNATURE)
  1105. #endif
  1106. #if IMAGE_ENABLE_FIT
  1107. #ifdef USE_HOSTCC
  1108. void *image_get_host_blob(void);
  1109. void image_set_host_blob(void *host_blob);
  1110. # define gd_fdt_blob() image_get_host_blob()
  1111. #else
  1112. # define gd_fdt_blob() (gd->fdt_blob)
  1113. #endif
  1114. #ifdef CONFIG_FIT_BEST_MATCH
  1115. #define IMAGE_ENABLE_BEST_MATCH 1
  1116. #else
  1117. #define IMAGE_ENABLE_BEST_MATCH 0
  1118. #endif
  1119. #endif /* IMAGE_ENABLE_FIT */
  1120. /*
  1121. * Information passed to the signing routines
  1122. *
  1123. * Either 'keydir', 'keyname', or 'keyfile' can be NULL. However, either
  1124. * 'keyfile', or both 'keydir' and 'keyname' should have valid values. If
  1125. * neither are valid, some operations might fail with EINVAL.
  1126. */
  1127. struct image_sign_info {
  1128. const char *keydir; /* Directory conaining keys */
  1129. const char *keyname; /* Name of key to use */
  1130. const char *keyfile; /* Filename of private or public key */
  1131. void *fit; /* Pointer to FIT blob */
  1132. int node_offset; /* Offset of signature node */
  1133. const char *name; /* Algorithm name */
  1134. struct checksum_algo *checksum; /* Checksum algorithm information */
  1135. struct padding_algo *padding; /* Padding algorithm information */
  1136. struct crypto_algo *crypto; /* Crypto algorithm information */
  1137. const void *fdt_blob; /* FDT containing public keys */
  1138. int required_keynode; /* Node offset of key to use: -1=any */
  1139. const char *require_keys; /* Value for 'required' property */
  1140. const char *engine_id; /* Engine to use for signing */
  1141. /*
  1142. * Note: the following two fields are always valid even w/o
  1143. * RSA_VERIFY_WITH_PKEY in order to make sure this structure is
  1144. * the same on target and host. Otherwise, vboot test may fail.
  1145. */
  1146. const void *key; /* Pointer to public key in DER */
  1147. int keylen; /* Length of public key */
  1148. };
  1149. /* A part of an image, used for hashing */
  1150. struct image_region {
  1151. const void *data;
  1152. int size;
  1153. };
  1154. #if IMAGE_ENABLE_VERIFY
  1155. # include <u-boot/hash-checksum.h>
  1156. #endif
  1157. struct checksum_algo {
  1158. const char *name;
  1159. const int checksum_len;
  1160. const int der_len;
  1161. const uint8_t *der_prefix;
  1162. #if IMAGE_ENABLE_SIGN
  1163. const EVP_MD *(*calculate_sign)(void);
  1164. #endif
  1165. int (*calculate)(const char *name,
  1166. const struct image_region region[],
  1167. int region_count, uint8_t *checksum);
  1168. };
  1169. struct crypto_algo {
  1170. const char *name; /* Name of algorithm */
  1171. const int key_len;
  1172. /**
  1173. * sign() - calculate and return signature for given input data
  1174. *
  1175. * @info: Specifies key and FIT information
  1176. * @data: Pointer to the input data
  1177. * @data_len: Data length
  1178. * @sigp: Set to an allocated buffer holding the signature
  1179. * @sig_len: Set to length of the calculated hash
  1180. *
  1181. * This computes input data signature according to selected algorithm.
  1182. * Resulting signature value is placed in an allocated buffer, the
  1183. * pointer is returned as *sigp. The length of the calculated
  1184. * signature is returned via the sig_len pointer argument. The caller
  1185. * should free *sigp.
  1186. *
  1187. * @return: 0, on success, -ve on error
  1188. */
  1189. int (*sign)(struct image_sign_info *info,
  1190. const struct image_region region[],
  1191. int region_count, uint8_t **sigp, uint *sig_len);
  1192. /**
  1193. * add_verify_data() - Add verification information to FDT
  1194. *
  1195. * Add public key information to the FDT node, suitable for
  1196. * verification at run-time. The information added depends on the
  1197. * algorithm being used.
  1198. *
  1199. * @info: Specifies key and FIT information
  1200. * @keydest: Destination FDT blob for public key data
  1201. * @return: 0, on success, -ve on error
  1202. */
  1203. int (*add_verify_data)(struct image_sign_info *info, void *keydest);
  1204. /**
  1205. * verify() - Verify a signature against some data
  1206. *
  1207. * @info: Specifies key and FIT information
  1208. * @data: Pointer to the input data
  1209. * @data_len: Data length
  1210. * @sig: Signature
  1211. * @sig_len: Number of bytes in signature
  1212. * @return 0 if verified, -ve on error
  1213. */
  1214. int (*verify)(struct image_sign_info *info,
  1215. const struct image_region region[], int region_count,
  1216. uint8_t *sig, uint sig_len);
  1217. };
  1218. struct padding_algo {
  1219. const char *name;
  1220. int (*verify)(struct image_sign_info *info,
  1221. uint8_t *pad, int pad_len,
  1222. const uint8_t *hash, int hash_len);
  1223. };
  1224. /**
  1225. * image_get_checksum_algo() - Look up a checksum algorithm
  1226. *
  1227. * @param full_name Name of algorithm in the form "checksum,crypto"
  1228. * @return pointer to algorithm information, or NULL if not found
  1229. */
  1230. struct checksum_algo *image_get_checksum_algo(const char *full_name);
  1231. /**
  1232. * image_get_crypto_algo() - Look up a cryptosystem algorithm
  1233. *
  1234. * @param full_name Name of algorithm in the form "checksum,crypto"
  1235. * @return pointer to algorithm information, or NULL if not found
  1236. */
  1237. struct crypto_algo *image_get_crypto_algo(const char *full_name);
  1238. /**
  1239. * image_get_padding_algo() - Look up a padding algorithm
  1240. *
  1241. * @param name Name of padding algorithm
  1242. * @return pointer to algorithm information, or NULL if not found
  1243. */
  1244. struct padding_algo *image_get_padding_algo(const char *name);
  1245. #if IMAGE_ENABLE_FIT
  1246. /**
  1247. * fit_image_verify_required_sigs() - Verify signatures marked as 'required'
  1248. *
  1249. * @fit: FIT to check
  1250. * @image_noffset: Offset of image node to check
  1251. * @data: Image data to check
  1252. * @size: Size of image data
  1253. * @sig_blob: FDT containing public keys
  1254. * @no_sigsp: Returns 1 if no signatures were required, and
  1255. * therefore nothing was checked. The caller may wish
  1256. * to fall back to other mechanisms, or refuse to
  1257. * boot.
  1258. * @return 0 if all verified ok, <0 on error
  1259. */
  1260. int fit_image_verify_required_sigs(const void *fit, int image_noffset,
  1261. const char *data, size_t size, const void *sig_blob,
  1262. int *no_sigsp);
  1263. /**
  1264. * fit_image_check_sig() - Check a single image signature node
  1265. *
  1266. * @fit: FIT to check
  1267. * @noffset: Offset of signature node to check
  1268. * @data: Image data to check
  1269. * @size: Size of image data
  1270. * @required_keynode: Offset in the control FDT of the required key node,
  1271. * if any. If this is given, then the image wil not
  1272. * pass verification unless that key is used. If this is
  1273. * -1 then any signature will do.
  1274. * @err_msgp: In the event of an error, this will be pointed to a
  1275. * help error string to display to the user.
  1276. * @return 0 if all verified ok, <0 on error
  1277. */
  1278. int fit_image_check_sig(const void *fit, int noffset, const void *data,
  1279. size_t size, int required_keynode, char **err_msgp);
  1280. int fit_image_decrypt_data(const void *fit,
  1281. int image_noffset, int cipher_noffset,
  1282. const void *data, size_t size,
  1283. void **data_unciphered, size_t *size_unciphered);
  1284. /**
  1285. * fit_region_make_list() - Make a list of regions to hash
  1286. *
  1287. * Given a list of FIT regions (offset, size) provided by libfdt, create
  1288. * a list of regions (void *, size) for use by the signature creationg
  1289. * and verification code.
  1290. *
  1291. * @fit: FIT image to process
  1292. * @fdt_regions: Regions as returned by libfdt
  1293. * @count: Number of regions returned by libfdt
  1294. * @region: Place to put list of regions (NULL to allocate it)
  1295. * @return pointer to list of regions, or NULL if out of memory
  1296. */
  1297. struct image_region *fit_region_make_list(const void *fit,
  1298. struct fdt_region *fdt_regions, int count,
  1299. struct image_region *region);
  1300. static inline int fit_image_check_target_arch(const void *fdt, int node)
  1301. {
  1302. #ifndef USE_HOSTCC
  1303. return fit_image_check_arch(fdt, node, IH_ARCH_DEFAULT);
  1304. #else
  1305. return 0;
  1306. #endif
  1307. }
  1308. /*
  1309. * At present we only support ciphering on the host, and unciphering on the
  1310. * device
  1311. */
  1312. #if defined(USE_HOSTCC)
  1313. # if defined(CONFIG_FIT_CIPHER)
  1314. # define IMAGE_ENABLE_ENCRYPT 1
  1315. # define IMAGE_ENABLE_DECRYPT 1
  1316. # include <openssl/evp.h>
  1317. # else
  1318. # define IMAGE_ENABLE_ENCRYPT 0
  1319. # define IMAGE_ENABLE_DECRYPT 0
  1320. # endif
  1321. #else
  1322. # define IMAGE_ENABLE_ENCRYPT 0
  1323. # define IMAGE_ENABLE_DECRYPT CONFIG_IS_ENABLED(FIT_CIPHER)
  1324. #endif
  1325. /* Information passed to the ciphering routines */
  1326. struct image_cipher_info {
  1327. const char *keydir; /* Directory containing keys */
  1328. const char *keyname; /* Name of key to use */
  1329. const char *ivname; /* Name of IV to use */
  1330. const void *fit; /* Pointer to FIT blob */
  1331. int node_noffset; /* Offset of the cipher node */
  1332. const char *name; /* Algorithm name */
  1333. struct cipher_algo *cipher; /* Cipher algorithm information */
  1334. const void *fdt_blob; /* FDT containing key and IV */
  1335. const void *key; /* Value of the key */
  1336. const void *iv; /* Value of the IV */
  1337. size_t size_unciphered; /* Size of the unciphered data */
  1338. };
  1339. struct cipher_algo {
  1340. const char *name; /* Name of algorithm */
  1341. int key_len; /* Length of the key */
  1342. int iv_len; /* Length of the IV */
  1343. #if IMAGE_ENABLE_ENCRYPT
  1344. const EVP_CIPHER * (*calculate_type)(void);
  1345. #endif
  1346. int (*encrypt)(struct image_cipher_info *info,
  1347. const unsigned char *data, int data_len,
  1348. unsigned char **cipher, int *cipher_len);
  1349. int (*add_cipher_data)(struct image_cipher_info *info,
  1350. void *keydest, void *fit, int node_noffset);
  1351. int (*decrypt)(struct image_cipher_info *info,
  1352. const void *cipher, size_t cipher_len,
  1353. void **data, size_t *data_len);
  1354. };
  1355. int fit_image_cipher_get_algo(const void *fit, int noffset, char **algo);
  1356. struct cipher_algo *image_get_cipher_algo(const char *full_name);
  1357. #ifdef CONFIG_FIT_VERBOSE
  1358. #define fit_unsupported(msg) printf("! %s:%d " \
  1359. "FIT images not supported for '%s'\n", \
  1360. __FILE__, __LINE__, (msg))
  1361. #define fit_unsupported_reset(msg) printf("! %s:%d " \
  1362. "FIT images not supported for '%s' " \
  1363. "- must reset board to recover!\n", \
  1364. __FILE__, __LINE__, (msg))
  1365. #else
  1366. #define fit_unsupported(msg)
  1367. #define fit_unsupported_reset(msg)
  1368. #endif /* CONFIG_FIT_VERBOSE */
  1369. #endif /* CONFIG_FIT */
  1370. #if !defined(USE_HOSTCC)
  1371. #if defined(CONFIG_ANDROID_BOOT_IMAGE)
  1372. struct andr_img_hdr;
  1373. int android_image_check_header(const struct andr_img_hdr *hdr);
  1374. int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
  1375. ulong *os_data, ulong *os_len);
  1376. int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
  1377. ulong *rd_data, ulong *rd_len);
  1378. int android_image_get_second(const struct andr_img_hdr *hdr,
  1379. ulong *second_data, ulong *second_len);
  1380. bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size);
  1381. bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr,
  1382. u32 *size);
  1383. ulong android_image_get_end(const struct andr_img_hdr *hdr);
  1384. ulong android_image_get_kload(const struct andr_img_hdr *hdr);
  1385. ulong android_image_get_kcomp(const struct andr_img_hdr *hdr);
  1386. void android_print_contents(const struct andr_img_hdr *hdr);
  1387. #if !defined(CONFIG_SPL_BUILD)
  1388. bool android_image_print_dtb_contents(ulong hdr_addr);
  1389. #endif
  1390. #endif /* CONFIG_ANDROID_BOOT_IMAGE */
  1391. #endif /* !USE_HOSTCC */
  1392. /**
  1393. * board_fit_config_name_match() - Check for a matching board name
  1394. *
  1395. * This is used when SPL loads a FIT containing multiple device tree files
  1396. * and wants to work out which one to use. The description of each one is
  1397. * passed to this function. The description comes from the 'description' field
  1398. * in each (FDT) image node.
  1399. *
  1400. * @name: Device tree description
  1401. * @return 0 if this device tree should be used, non-zero to try the next
  1402. */
  1403. int board_fit_config_name_match(const char *name);
  1404. /**
  1405. * board_fit_image_post_process() - Do any post-process on FIT binary data
  1406. *
  1407. * This is used to do any sort of image manipulation, verification, decryption
  1408. * etc. in a platform or board specific way. Obviously, anything done here would
  1409. * need to be comprehended in how the images were prepared before being injected
  1410. * into the FIT creation (i.e. the binary blobs would have been pre-processed
  1411. * before being added to the FIT image).
  1412. *
  1413. * @image: pointer to the image start pointer
  1414. * @size: pointer to the image size
  1415. * @return no return value (failure should be handled internally)
  1416. */
  1417. void board_fit_image_post_process(void **p_image, size_t *p_size);
  1418. #define FDT_ERROR ((ulong)(-1))
  1419. ulong fdt_getprop_u32(const void *fdt, int node, const char *prop);
  1420. /**
  1421. * fit_find_config_node() - Find the node for the best DTB in a FIT image
  1422. *
  1423. * A FIT image contains one or more DTBs. This function parses the
  1424. * configurations described in the FIT images and returns the node of
  1425. * the first matching DTB. To check if a DTB matches a board, this function
  1426. * calls board_fit_config_name_match(). If no matching DTB is found, it returns
  1427. * the node described by the default configuration if it exists.
  1428. *
  1429. * @fdt: pointer to flat device tree
  1430. * @return the node if found, -ve otherwise
  1431. */
  1432. int fit_find_config_node(const void *fdt);
  1433. /**
  1434. * Mapping of image types to function handlers to be invoked on the associated
  1435. * loaded images
  1436. *
  1437. * @type: Type of image, I.E. IH_TYPE_*
  1438. * @handler: Function to call on loaded image
  1439. */
  1440. struct fit_loadable_tbl {
  1441. int type;
  1442. /**
  1443. * handler() - Process a loaded image
  1444. *
  1445. * @data: Pointer to start of loaded image data
  1446. * @size: Size of loaded image data
  1447. */
  1448. void (*handler)(ulong data, size_t size);
  1449. };
  1450. /*
  1451. * Define a FIT loadable image type handler
  1452. *
  1453. * _type is a valid uimage_type ID as defined in the "Image Type" enum above
  1454. * _handler is the handler function to call after this image type is loaded
  1455. */
  1456. #define U_BOOT_FIT_LOADABLE_HANDLER(_type, _handler) \
  1457. ll_entry_declare(struct fit_loadable_tbl, _function, fit_loadable) = { \
  1458. .type = _type, \
  1459. .handler = _handler, \
  1460. }
  1461. /**
  1462. * fit_update - update storage with FIT image
  1463. * @fit: Pointer to FIT image
  1464. *
  1465. * Update firmware on storage using FIT image as input.
  1466. * The storage area to be update will be identified by the name
  1467. * in FIT and matching it to "dfu_alt_info" variable.
  1468. *
  1469. * Return: 0 on success, non-zero otherwise
  1470. */
  1471. int fit_update(const void *fit);
  1472. #endif /* __IMAGE_H__ */