image.h 23 KB

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