image.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /*
  2. * (C) Copyright 2008 Semihalf
  3. *
  4. * (C) Copyright 2000-2005
  5. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. *
  25. ********************************************************************
  26. * NOTE: This header file defines an interface to U-Boot. Including
  27. * this (unmodified) header file in another file is considered normal
  28. * use of U-Boot, and does *not* fall under the heading of "derived
  29. * work".
  30. ********************************************************************
  31. */
  32. #ifndef __IMAGE_H__
  33. #define __IMAGE_H__
  34. #include "compiler.h"
  35. #include <asm/byteorder.h>
  36. #ifdef USE_HOSTCC
  37. /* new uImage format support enabled on host */
  38. #define CONFIG_FIT 1
  39. #define CONFIG_OF_LIBFDT 1
  40. #define CONFIG_FIT_VERBOSE 1 /* enable fit_format_{error,warning}() */
  41. #else
  42. #include <lmb.h>
  43. #include <asm/u-boot.h>
  44. #include <command.h>
  45. #endif /* USE_HOSTCC */
  46. #if defined(CONFIG_FIT)
  47. #include <libfdt.h>
  48. #include <fdt_support.h>
  49. #define CONFIG_MD5 /* FIT images need MD5 support */
  50. #define CONFIG_SHA1 /* and SHA1 */
  51. #endif
  52. /*
  53. * Operating System Codes
  54. */
  55. #define IH_OS_INVALID 0 /* Invalid OS */
  56. #define IH_OS_OPENBSD 1 /* OpenBSD */
  57. #define IH_OS_NETBSD 2 /* NetBSD */
  58. #define IH_OS_FREEBSD 3 /* FreeBSD */
  59. #define IH_OS_4_4BSD 4 /* 4.4BSD */
  60. #define IH_OS_LINUX 5 /* Linux */
  61. #define IH_OS_SVR4 6 /* SVR4 */
  62. #define IH_OS_ESIX 7 /* Esix */
  63. #define IH_OS_SOLARIS 8 /* Solaris */
  64. #define IH_OS_IRIX 9 /* Irix */
  65. #define IH_OS_SCO 10 /* SCO */
  66. #define IH_OS_DELL 11 /* Dell */
  67. #define IH_OS_NCR 12 /* NCR */
  68. #define IH_OS_LYNXOS 13 /* LynxOS */
  69. #define IH_OS_VXWORKS 14 /* VxWorks */
  70. #define IH_OS_PSOS 15 /* pSOS */
  71. #define IH_OS_QNX 16 /* QNX */
  72. #define IH_OS_U_BOOT 17 /* Firmware */
  73. #define IH_OS_RTEMS 18 /* RTEMS */
  74. #define IH_OS_ARTOS 19 /* ARTOS */
  75. #define IH_OS_UNITY 20 /* Unity OS */
  76. #define IH_OS_INTEGRITY 21 /* INTEGRITY */
  77. #define IH_OS_OSE 22 /* OSE */
  78. #define IH_OS_PLAN9 23 /* Plan 9 */
  79. /*
  80. * CPU Architecture Codes (supported by Linux)
  81. */
  82. #define IH_ARCH_INVALID 0 /* Invalid CPU */
  83. #define IH_ARCH_ALPHA 1 /* Alpha */
  84. #define IH_ARCH_ARM 2 /* ARM */
  85. #define IH_ARCH_I386 3 /* Intel x86 */
  86. #define IH_ARCH_IA64 4 /* IA64 */
  87. #define IH_ARCH_MIPS 5 /* MIPS */
  88. #define IH_ARCH_MIPS64 6 /* MIPS 64 Bit */
  89. #define IH_ARCH_PPC 7 /* PowerPC */
  90. #define IH_ARCH_S390 8 /* IBM S390 */
  91. #define IH_ARCH_SH 9 /* SuperH */
  92. #define IH_ARCH_SPARC 10 /* Sparc */
  93. #define IH_ARCH_SPARC64 11 /* Sparc 64 Bit */
  94. #define IH_ARCH_M68K 12 /* M68K */
  95. #define IH_ARCH_MICROBLAZE 14 /* MicroBlaze */
  96. #define IH_ARCH_NIOS2 15 /* Nios-II */
  97. #define IH_ARCH_BLACKFIN 16 /* Blackfin */
  98. #define IH_ARCH_AVR32 17 /* AVR32 */
  99. #define IH_ARCH_ST200 18 /* STMicroelectronics ST200 */
  100. #define IH_ARCH_SANDBOX 19 /* Sandbox architecture (test only) */
  101. #define IH_ARCH_NDS32 20 /* ANDES Technology - NDS32 */
  102. #define IH_ARCH_OPENRISC 21 /* OpenRISC 1000 */
  103. /*
  104. * Image Types
  105. *
  106. * "Standalone Programs" are directly runnable in the environment
  107. * provided by U-Boot; it is expected that (if they behave
  108. * well) you can continue to work in U-Boot after return from
  109. * the Standalone Program.
  110. * "OS Kernel Images" are usually images of some Embedded OS which
  111. * will take over control completely. Usually these programs
  112. * will install their own set of exception handlers, device
  113. * drivers, set up the MMU, etc. - this means, that you cannot
  114. * expect to re-enter U-Boot except by resetting the CPU.
  115. * "RAMDisk Images" are more or less just data blocks, and their
  116. * parameters (address, size) are passed to an OS kernel that is
  117. * being started.
  118. * "Multi-File Images" contain several images, typically an OS
  119. * (Linux) kernel image and one or more data images like
  120. * RAMDisks. This construct is useful for instance when you want
  121. * to boot over the network using BOOTP etc., where the boot
  122. * server provides just a single image file, but you want to get
  123. * for instance an OS kernel and a RAMDisk image.
  124. *
  125. * "Multi-File Images" start with a list of image sizes, each
  126. * image size (in bytes) specified by an "uint32_t" in network
  127. * byte order. This list is terminated by an "(uint32_t)0".
  128. * Immediately after the terminating 0 follow the images, one by
  129. * one, all aligned on "uint32_t" boundaries (size rounded up to
  130. * a multiple of 4 bytes - except for the last file).
  131. *
  132. * "Firmware Images" are binary images containing firmware (like
  133. * U-Boot or FPGA images) which usually will be programmed to
  134. * flash memory.
  135. *
  136. * "Script files" are command sequences that will be executed by
  137. * U-Boot's command interpreter; this feature is especially
  138. * useful when you configure U-Boot to use a real shell (hush)
  139. * as command interpreter (=> Shell Scripts).
  140. */
  141. #define IH_TYPE_INVALID 0 /* Invalid Image */
  142. #define IH_TYPE_STANDALONE 1 /* Standalone Program */
  143. #define IH_TYPE_KERNEL 2 /* OS Kernel Image */
  144. #define IH_TYPE_RAMDISK 3 /* RAMDisk Image */
  145. #define IH_TYPE_MULTI 4 /* Multi-File Image */
  146. #define IH_TYPE_FIRMWARE 5 /* Firmware Image */
  147. #define IH_TYPE_SCRIPT 6 /* Script file */
  148. #define IH_TYPE_FILESYSTEM 7 /* Filesystem Image (any type) */
  149. #define IH_TYPE_FLATDT 8 /* Binary Flat Device Tree Blob */
  150. #define IH_TYPE_KWBIMAGE 9 /* Kirkwood Boot Image */
  151. #define IH_TYPE_IMXIMAGE 10 /* Freescale IMXBoot Image */
  152. #define IH_TYPE_UBLIMAGE 11 /* Davinci UBL Image */
  153. #define IH_TYPE_OMAPIMAGE 12 /* TI OMAP Config Header Image */
  154. #define IH_TYPE_AISIMAGE 13 /* TI Davinci AIS Image */
  155. #define IH_TYPE_KERNEL_NOLOAD 14 /* OS Kernel Image, can run from any load address */
  156. #define IH_TYPE_PBLIMAGE 15 /* Freescale PBL Boot Image */
  157. /*
  158. * Compression Types
  159. */
  160. #define IH_COMP_NONE 0 /* No Compression Used */
  161. #define IH_COMP_GZIP 1 /* gzip Compression Used */
  162. #define IH_COMP_BZIP2 2 /* bzip2 Compression Used */
  163. #define IH_COMP_LZMA 3 /* lzma Compression Used */
  164. #define IH_COMP_LZO 4 /* lzo Compression Used */
  165. #define IH_MAGIC 0x27051956 /* Image Magic Number */
  166. #define IH_NMLEN 32 /* Image Name Length */
  167. /* Reused from common.h */
  168. #define ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1))
  169. /*
  170. * Legacy format image header,
  171. * all data in network byte order (aka natural aka bigendian).
  172. */
  173. typedef struct image_header {
  174. __be32 ih_magic; /* Image Header Magic Number */
  175. __be32 ih_hcrc; /* Image Header CRC Checksum */
  176. __be32 ih_time; /* Image Creation Timestamp */
  177. __be32 ih_size; /* Image Data Size */
  178. __be32 ih_load; /* Data Load Address */
  179. __be32 ih_ep; /* Entry Point Address */
  180. __be32 ih_dcrc; /* Image Data CRC Checksum */
  181. uint8_t ih_os; /* Operating System */
  182. uint8_t ih_arch; /* CPU architecture */
  183. uint8_t ih_type; /* Image Type */
  184. uint8_t ih_comp; /* Compression Type */
  185. uint8_t ih_name[IH_NMLEN]; /* Image Name */
  186. } image_header_t;
  187. typedef struct image_info {
  188. ulong start, end; /* start/end of blob */
  189. ulong image_start, image_len; /* start of image within blob, len of image */
  190. ulong load; /* load addr for the image */
  191. uint8_t comp, type, os; /* compression, type of image, os type */
  192. } image_info_t;
  193. /*
  194. * Legacy and FIT format headers used by do_bootm() and do_bootm_<os>()
  195. * routines.
  196. */
  197. typedef struct bootm_headers {
  198. /*
  199. * Legacy os image header, if it is a multi component image
  200. * then boot_get_ramdisk() and get_fdt() will attempt to get
  201. * data from second and third component accordingly.
  202. */
  203. image_header_t *legacy_hdr_os; /* image header pointer */
  204. image_header_t legacy_hdr_os_copy; /* header copy */
  205. ulong legacy_hdr_valid;
  206. #if defined(CONFIG_FIT)
  207. const char *fit_uname_cfg; /* configuration node unit name */
  208. void *fit_hdr_os; /* os FIT image header */
  209. const char *fit_uname_os; /* os subimage node unit name */
  210. int fit_noffset_os; /* os subimage node offset */
  211. void *fit_hdr_rd; /* init ramdisk FIT image header */
  212. const char *fit_uname_rd; /* init ramdisk subimage node unit name */
  213. int fit_noffset_rd; /* init ramdisk subimage node offset */
  214. void *fit_hdr_fdt; /* FDT blob FIT image header */
  215. const char *fit_uname_fdt; /* FDT blob subimage node unit name */
  216. int fit_noffset_fdt;/* FDT blob subimage node offset */
  217. #endif
  218. #ifndef USE_HOSTCC
  219. image_info_t os; /* os image info */
  220. ulong ep; /* entry point of OS */
  221. ulong rd_start, rd_end;/* ramdisk start/end */
  222. #ifdef CONFIG_OF_LIBFDT
  223. char *ft_addr; /* flat dev tree address */
  224. #endif
  225. ulong ft_len; /* length of flat device tree */
  226. ulong initrd_start;
  227. ulong initrd_end;
  228. ulong cmdline_start;
  229. ulong cmdline_end;
  230. bd_t *kbd;
  231. #endif
  232. int verify; /* getenv("verify")[0] != 'n' */
  233. #define BOOTM_STATE_START (0x00000001)
  234. #define BOOTM_STATE_LOADOS (0x00000002)
  235. #define BOOTM_STATE_RAMDISK (0x00000004)
  236. #define BOOTM_STATE_FDT (0x00000008)
  237. #define BOOTM_STATE_OS_CMDLINE (0x00000010)
  238. #define BOOTM_STATE_OS_BD_T (0x00000020)
  239. #define BOOTM_STATE_OS_PREP (0x00000040)
  240. #define BOOTM_STATE_OS_GO (0x00000080)
  241. int state;
  242. #ifdef CONFIG_LMB
  243. struct lmb lmb; /* for memory mgmt */
  244. #endif
  245. } bootm_headers_t;
  246. extern bootm_headers_t images;
  247. /*
  248. * Some systems (for example LWMON) have very short watchdog periods;
  249. * we must make sure to split long operations like memmove() or
  250. * checksum calculations into reasonable chunks.
  251. */
  252. #ifndef CHUNKSZ
  253. #define CHUNKSZ (64 * 1024)
  254. #endif
  255. #ifndef CHUNKSZ_CRC32
  256. #define CHUNKSZ_CRC32 (64 * 1024)
  257. #endif
  258. #ifndef CHUNKSZ_MD5
  259. #define CHUNKSZ_MD5 (64 * 1024)
  260. #endif
  261. #ifndef CHUNKSZ_SHA1
  262. #define CHUNKSZ_SHA1 (64 * 1024)
  263. #endif
  264. #define uimage_to_cpu(x) be32_to_cpu(x)
  265. #define cpu_to_uimage(x) cpu_to_be32(x)
  266. /*
  267. * Translation table for entries of a specific type; used by
  268. * get_table_entry_id() and get_table_entry_name().
  269. */
  270. typedef struct table_entry {
  271. int id;
  272. char *sname; /* short (input) name to find table entry */
  273. char *lname; /* long (output) name to print for messages */
  274. } table_entry_t;
  275. /*
  276. * get_table_entry_id() scans the translation table trying to find an
  277. * entry that matches the given short name. If a matching entry is
  278. * found, it's id is returned to the caller.
  279. */
  280. int get_table_entry_id(const table_entry_t *table,
  281. const char *table_name, const char *name);
  282. /*
  283. * get_table_entry_name() scans the translation table trying to find
  284. * an entry that matches the given id. If a matching entry is found,
  285. * its long name is returned to the caller.
  286. */
  287. char *get_table_entry_name(const table_entry_t *table, char *msg, int id);
  288. const char *genimg_get_os_name(uint8_t os);
  289. const char *genimg_get_arch_name(uint8_t arch);
  290. const char *genimg_get_type_name(uint8_t type);
  291. const char *genimg_get_comp_name(uint8_t comp);
  292. int genimg_get_os_id(const char *name);
  293. int genimg_get_arch_id(const char *name);
  294. int genimg_get_type_id(const char *name);
  295. int genimg_get_comp_id(const char *name);
  296. void genimg_print_size(uint32_t size);
  297. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || \
  298. defined(USE_HOSTCC)
  299. #define IMAGE_ENABLE_TIMESTAMP 1
  300. #else
  301. #define IMAGE_ENABLE_TIMESTAMP 0
  302. #endif
  303. void genimg_print_time(time_t timestamp);
  304. #ifndef USE_HOSTCC
  305. /* Image format types, returned by _get_format() routine */
  306. #define IMAGE_FORMAT_INVALID 0x00
  307. #define IMAGE_FORMAT_LEGACY 0x01 /* legacy image_header based format */
  308. #define IMAGE_FORMAT_FIT 0x02 /* new, libfdt based format */
  309. int genimg_get_format(void *img_addr);
  310. int genimg_has_config(bootm_headers_t *images);
  311. ulong genimg_get_image(ulong img_addr);
  312. int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
  313. uint8_t arch, ulong *rd_start, ulong *rd_end);
  314. #ifdef CONFIG_OF_LIBFDT
  315. int boot_get_fdt(int flag, int argc, char * const argv[],
  316. bootm_headers_t *images, char **of_flat_tree, ulong *of_size);
  317. void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob);
  318. int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size);
  319. #endif
  320. #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  321. int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len,
  322. ulong *initrd_start, ulong *initrd_end);
  323. #endif /* CONFIG_SYS_BOOT_RAMDISK_HIGH */
  324. #ifdef CONFIG_SYS_BOOT_GET_CMDLINE
  325. int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end);
  326. #endif /* CONFIG_SYS_BOOT_GET_CMDLINE */
  327. #ifdef CONFIG_SYS_BOOT_GET_KBD
  328. int boot_get_kbd(struct lmb *lmb, bd_t **kbd);
  329. #endif /* CONFIG_SYS_BOOT_GET_KBD */
  330. #endif /* !USE_HOSTCC */
  331. /*******************************************************************/
  332. /* Legacy format specific code (prefixed with image_) */
  333. /*******************************************************************/
  334. static inline uint32_t image_get_header_size(void)
  335. {
  336. return (sizeof(image_header_t));
  337. }
  338. #define image_get_hdr_l(f) \
  339. static inline uint32_t image_get_##f(const image_header_t *hdr) \
  340. { \
  341. return uimage_to_cpu(hdr->ih_##f); \
  342. }
  343. image_get_hdr_l(magic) /* image_get_magic */
  344. image_get_hdr_l(hcrc) /* image_get_hcrc */
  345. image_get_hdr_l(time) /* image_get_time */
  346. image_get_hdr_l(size) /* image_get_size */
  347. image_get_hdr_l(load) /* image_get_load */
  348. image_get_hdr_l(ep) /* image_get_ep */
  349. image_get_hdr_l(dcrc) /* image_get_dcrc */
  350. #define image_get_hdr_b(f) \
  351. static inline uint8_t image_get_##f(const image_header_t *hdr) \
  352. { \
  353. return hdr->ih_##f; \
  354. }
  355. image_get_hdr_b(os) /* image_get_os */
  356. image_get_hdr_b(arch) /* image_get_arch */
  357. image_get_hdr_b(type) /* image_get_type */
  358. image_get_hdr_b(comp) /* image_get_comp */
  359. static inline char *image_get_name(const image_header_t *hdr)
  360. {
  361. return (char *)hdr->ih_name;
  362. }
  363. static inline uint32_t image_get_data_size(const image_header_t *hdr)
  364. {
  365. return image_get_size(hdr);
  366. }
  367. /**
  368. * image_get_data - get image payload start address
  369. * @hdr: image header
  370. *
  371. * image_get_data() returns address of the image payload. For single
  372. * component images it is image data start. For multi component
  373. * images it points to the null terminated table of sub-images sizes.
  374. *
  375. * returns:
  376. * image payload data start address
  377. */
  378. static inline ulong image_get_data(const image_header_t *hdr)
  379. {
  380. return ((ulong)hdr + image_get_header_size());
  381. }
  382. static inline uint32_t image_get_image_size(const image_header_t *hdr)
  383. {
  384. return (image_get_size(hdr) + image_get_header_size());
  385. }
  386. static inline ulong image_get_image_end(const image_header_t *hdr)
  387. {
  388. return ((ulong)hdr + image_get_image_size(hdr));
  389. }
  390. #define image_set_hdr_l(f) \
  391. static inline void image_set_##f(image_header_t *hdr, uint32_t val) \
  392. { \
  393. hdr->ih_##f = cpu_to_uimage(val); \
  394. }
  395. image_set_hdr_l(magic) /* image_set_magic */
  396. image_set_hdr_l(hcrc) /* image_set_hcrc */
  397. image_set_hdr_l(time) /* image_set_time */
  398. image_set_hdr_l(size) /* image_set_size */
  399. image_set_hdr_l(load) /* image_set_load */
  400. image_set_hdr_l(ep) /* image_set_ep */
  401. image_set_hdr_l(dcrc) /* image_set_dcrc */
  402. #define image_set_hdr_b(f) \
  403. static inline void image_set_##f(image_header_t *hdr, uint8_t val) \
  404. { \
  405. hdr->ih_##f = val; \
  406. }
  407. image_set_hdr_b(os) /* image_set_os */
  408. image_set_hdr_b(arch) /* image_set_arch */
  409. image_set_hdr_b(type) /* image_set_type */
  410. image_set_hdr_b(comp) /* image_set_comp */
  411. static inline void image_set_name(image_header_t *hdr, const char *name)
  412. {
  413. strncpy(image_get_name(hdr), name, IH_NMLEN);
  414. }
  415. int image_check_hcrc(const image_header_t *hdr);
  416. int image_check_dcrc(const image_header_t *hdr);
  417. #ifndef USE_HOSTCC
  418. ulong getenv_bootm_low(void);
  419. phys_size_t getenv_bootm_size(void);
  420. phys_size_t getenv_bootm_mapsize(void);
  421. void memmove_wd(void *to, void *from, size_t len, ulong chunksz);
  422. #endif
  423. static inline int image_check_magic(const image_header_t *hdr)
  424. {
  425. return (image_get_magic(hdr) == IH_MAGIC);
  426. }
  427. static inline int image_check_type(const image_header_t *hdr, uint8_t type)
  428. {
  429. return (image_get_type(hdr) == type);
  430. }
  431. static inline int image_check_arch(const image_header_t *hdr, uint8_t arch)
  432. {
  433. return (image_get_arch(hdr) == arch);
  434. }
  435. static inline int image_check_os(const image_header_t *hdr, uint8_t os)
  436. {
  437. return (image_get_os(hdr) == os);
  438. }
  439. ulong image_multi_count(const image_header_t *hdr);
  440. void image_multi_getimg(const image_header_t *hdr, ulong idx,
  441. ulong *data, ulong *len);
  442. void image_print_contents(const void *hdr);
  443. #ifndef USE_HOSTCC
  444. static inline int image_check_target_arch(const image_header_t *hdr)
  445. {
  446. #ifndef IH_ARCH_DEFAULT
  447. # error "please define IH_ARCH_DEFAULT in your arch asm/u-boot.h"
  448. #endif
  449. return image_check_arch(hdr, IH_ARCH_DEFAULT);
  450. }
  451. #endif /* USE_HOSTCC */
  452. /*******************************************************************/
  453. /* New uImage format specific code (prefixed with fit_) */
  454. /*******************************************************************/
  455. #if defined(CONFIG_FIT)
  456. #define FIT_IMAGES_PATH "/images"
  457. #define FIT_CONFS_PATH "/configurations"
  458. /* hash node */
  459. #define FIT_HASH_NODENAME "hash"
  460. #define FIT_ALGO_PROP "algo"
  461. #define FIT_VALUE_PROP "value"
  462. #define FIT_IGNORE_PROP "uboot-ignore"
  463. /* image node */
  464. #define FIT_DATA_PROP "data"
  465. #define FIT_TIMESTAMP_PROP "timestamp"
  466. #define FIT_DESC_PROP "description"
  467. #define FIT_ARCH_PROP "arch"
  468. #define FIT_TYPE_PROP "type"
  469. #define FIT_OS_PROP "os"
  470. #define FIT_COMP_PROP "compression"
  471. #define FIT_ENTRY_PROP "entry"
  472. #define FIT_LOAD_PROP "load"
  473. /* configuration node */
  474. #define FIT_KERNEL_PROP "kernel"
  475. #define FIT_RAMDISK_PROP "ramdisk"
  476. #define FIT_FDT_PROP "fdt"
  477. #define FIT_DEFAULT_PROP "default"
  478. #define FIT_MAX_HASH_LEN 20 /* max(crc32_len(4), sha1_len(20)) */
  479. /* cmdline argument format parsing */
  480. int fit_parse_conf(const char *spec, ulong addr_curr,
  481. ulong *addr, const char **conf_name);
  482. int fit_parse_subimage(const char *spec, ulong addr_curr,
  483. ulong *addr, const char **image_name);
  484. void fit_print_contents(const void *fit);
  485. void fit_image_print(const void *fit, int noffset, const char *p);
  486. void fit_image_print_hash(const void *fit, int noffset, const char *p);
  487. /**
  488. * fit_get_end - get FIT image size
  489. * @fit: pointer to the FIT format image header
  490. *
  491. * returns:
  492. * size of the FIT image (blob) in memory
  493. */
  494. static inline ulong fit_get_size(const void *fit)
  495. {
  496. return fdt_totalsize(fit);
  497. }
  498. /**
  499. * fit_get_end - get FIT image end
  500. * @fit: pointer to the FIT format image header
  501. *
  502. * returns:
  503. * end address of the FIT image (blob) in memory
  504. */
  505. static inline ulong fit_get_end(const void *fit)
  506. {
  507. return (ulong)fit + fdt_totalsize(fit);
  508. }
  509. /**
  510. * fit_get_name - get FIT node name
  511. * @fit: pointer to the FIT format image header
  512. *
  513. * returns:
  514. * NULL, on error
  515. * pointer to node name, on success
  516. */
  517. static inline const char *fit_get_name(const void *fit_hdr,
  518. int noffset, int *len)
  519. {
  520. return fdt_get_name(fit_hdr, noffset, len);
  521. }
  522. int fit_get_desc(const void *fit, int noffset, char **desc);
  523. int fit_get_timestamp(const void *fit, int noffset, time_t *timestamp);
  524. int fit_image_get_node(const void *fit, const char *image_uname);
  525. int fit_image_get_os(const void *fit, int noffset, uint8_t *os);
  526. int fit_image_get_arch(const void *fit, int noffset, uint8_t *arch);
  527. int fit_image_get_type(const void *fit, int noffset, uint8_t *type);
  528. int fit_image_get_comp(const void *fit, int noffset, uint8_t *comp);
  529. int fit_image_get_load(const void *fit, int noffset, ulong *load);
  530. int fit_image_get_entry(const void *fit, int noffset, ulong *entry);
  531. int fit_image_get_data(const void *fit, int noffset,
  532. const void **data, size_t *size);
  533. int fit_image_hash_get_algo(const void *fit, int noffset, char **algo);
  534. int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value,
  535. int *value_len);
  536. #ifndef USE_HOSTCC
  537. int fit_image_hash_get_ignore(const void *fit, int noffset, int *ignore);
  538. #endif
  539. int fit_set_timestamp(void *fit, int noffset, time_t timestamp);
  540. int fit_set_hashes(void *fit);
  541. int fit_image_set_hashes(void *fit, int image_noffset);
  542. int fit_image_hash_set_value(void *fit, int noffset, uint8_t *value,
  543. int value_len);
  544. int fit_image_check_hashes(const void *fit, int noffset);
  545. int fit_all_image_check_hashes(const void *fit);
  546. int fit_image_check_os(const void *fit, int noffset, uint8_t os);
  547. int fit_image_check_arch(const void *fit, int noffset, uint8_t arch);
  548. int fit_image_check_type(const void *fit, int noffset, uint8_t type);
  549. int fit_image_check_comp(const void *fit, int noffset, uint8_t comp);
  550. int fit_check_format(const void *fit);
  551. int fit_conf_find_compat(const void *fit, const void *fdt);
  552. int fit_conf_get_node(const void *fit, const char *conf_uname);
  553. int fit_conf_get_kernel_node(const void *fit, int noffset);
  554. int fit_conf_get_ramdisk_node(const void *fit, int noffset);
  555. int fit_conf_get_fdt_node(const void *fit, int noffset);
  556. void fit_conf_print(const void *fit, int noffset, const char *p);
  557. int fit_check_ramdisk(const void *fit, int os_noffset,
  558. uint8_t arch, int verify);
  559. int calculate_hash(const void *data, int data_len, const char *algo,
  560. uint8_t *value, int *value_len);
  561. #ifndef USE_HOSTCC
  562. static inline int fit_image_check_target_arch(const void *fdt, int node)
  563. {
  564. return fit_image_check_arch(fdt, node, IH_ARCH_DEFAULT);
  565. }
  566. #endif /* USE_HOSTCC */
  567. #ifdef CONFIG_FIT_VERBOSE
  568. #define fit_unsupported(msg) printf("! %s:%d " \
  569. "FIT images not supported for '%s'\n", \
  570. __FILE__, __LINE__, (msg))
  571. #define fit_unsupported_reset(msg) printf("! %s:%d " \
  572. "FIT images not supported for '%s' " \
  573. "- must reset board to recover!\n", \
  574. __FILE__, __LINE__, (msg))
  575. #else
  576. #define fit_unsupported(msg)
  577. #define fit_unsupported_reset(msg)
  578. #endif /* CONFIG_FIT_VERBOSE */
  579. #endif /* CONFIG_FIT */
  580. #endif /* __IMAGE_H__ */