image.h 26 KB

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