image.h 22 KB

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