mkimage.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * (C) Copyright 2000-2004
  3. * DENX Software Engineering
  4. * Wolfgang Denk, wd@denx.de
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #ifndef _MKIIMAGE_H_
  9. #define _MKIIMAGE_H_
  10. #include "os_support.h"
  11. #include <errno.h>
  12. #include <fcntl.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <sys/stat.h>
  17. #include <time.h>
  18. #include <unistd.h>
  19. #include <sha1.h>
  20. #include "fdt_host.h"
  21. #undef MKIMAGE_DEBUG
  22. #ifdef MKIMAGE_DEBUG
  23. #define debug(fmt,args...) printf (fmt ,##args)
  24. #else
  25. #define debug(fmt,args...)
  26. #endif /* MKIMAGE_DEBUG */
  27. #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  28. static inline void *map_sysmem(ulong paddr, unsigned long len)
  29. {
  30. return (void *)(uintptr_t)paddr;
  31. }
  32. static inline ulong map_to_sysmem(void *ptr)
  33. {
  34. return (ulong)(uintptr_t)ptr;
  35. }
  36. #define MKIMAGE_TMPFILE_SUFFIX ".tmp"
  37. #define MKIMAGE_MAX_TMPFILE_LEN 256
  38. #define MKIMAGE_DEFAULT_DTC_OPTIONS "-I dts -O dtb -p 500"
  39. #define MKIMAGE_MAX_DTC_CMDLINE_LEN 512
  40. #define MKIMAGE_DTC "dtc" /* assume dtc is in $PATH */
  41. #define IH_ARCH_DEFAULT IH_ARCH_INVALID
  42. /*
  43. * This structure defines all such variables those are initialized by
  44. * mkimage main core and need to be referred by image type specific
  45. * functions
  46. */
  47. struct mkimage_params {
  48. int dflag;
  49. int eflag;
  50. int fflag;
  51. int lflag;
  52. int vflag;
  53. int xflag;
  54. int skipcpy;
  55. int os;
  56. int arch;
  57. int type;
  58. int comp;
  59. char *dtc;
  60. unsigned int addr;
  61. unsigned int ep;
  62. char *imagename;
  63. char *imagename2;
  64. char *datafile;
  65. char *imagefile;
  66. char *cmdname;
  67. const char *keydir; /* Directory holding private keys */
  68. const char *keydest; /* Destination .dtb for public key */
  69. const char *comment; /* Comment to add to signature node */
  70. int require_keys; /* 1 to mark signing keys as 'required' */
  71. };
  72. /*
  73. * image type specific variables and callback functions
  74. */
  75. struct image_type_params {
  76. /* name is an identification tag string for added support */
  77. char *name;
  78. /*
  79. * header size is local to the specific image type to be supported,
  80. * mkimage core treats this as number of bytes
  81. */
  82. uint32_t header_size;
  83. /* Image type header pointer */
  84. void *hdr;
  85. /*
  86. * There are several arguments that are passed on the command line
  87. * and are registered as flags in mkimage_params structure.
  88. * This callback function can be used to check the passed arguments
  89. * are in-lined with the image type to be supported
  90. *
  91. * Returns 1 if parameter check is successful
  92. */
  93. int (*check_params) (struct mkimage_params *);
  94. /*
  95. * This function is used by list command (i.e. mkimage -l <filename>)
  96. * image type verification code must be put here
  97. *
  98. * Returns 0 if image header verification is successful
  99. * otherwise, returns respective negative error codes
  100. */
  101. int (*verify_header) (unsigned char *, int, struct mkimage_params *);
  102. /* Prints image information abstracting from image header */
  103. void (*print_header) (const void *);
  104. /*
  105. * The header or image contents need to be set as per image type to
  106. * be generated using this callback function.
  107. * further output file post processing (for ex. checksum calculation,
  108. * padding bytes etc..) can also be done in this callback function.
  109. */
  110. void (*set_header) (void *, struct stat *, int,
  111. struct mkimage_params *);
  112. /*
  113. * Some image generation support for ex (default image type) supports
  114. * more than one type_ids, this callback function is used to check
  115. * whether input (-T <image_type>) is supported by registered image
  116. * generation/list low level code
  117. */
  118. int (*check_image_type) (uint8_t);
  119. /* This callback function will be executed if fflag is defined */
  120. int (*fflag_handle) (struct mkimage_params *);
  121. /*
  122. * This callback function will be executed for variable size record
  123. * It is expected to build this header in memory and return its length
  124. * and a pointer to it by using image_type_params.header_size and
  125. * image_type_params.hdr. The return value shall indicate if an
  126. * additional padding should be used when copying the data image
  127. * by returning the padding length.
  128. */
  129. int (*vrec_header) (struct mkimage_params *,
  130. struct image_type_params *);
  131. /* pointer to the next registered entry in linked list */
  132. struct image_type_params *next;
  133. };
  134. /*
  135. * Exported functions
  136. */
  137. void mkimage_register (struct image_type_params *tparams);
  138. /*
  139. * There is a c file associated with supported image type low level code
  140. * for ex. default_image.c, fit_image.c
  141. * init is the only function referred by mkimage core.
  142. * to avoid a single lined header file, you can define them here
  143. *
  144. * Supported image types init functions
  145. */
  146. void pbl_load_uboot(int fd, struct mkimage_params *mparams);
  147. void init_pbl_image_type(void);
  148. void init_ais_image_type(void);
  149. void init_kwb_image_type (void);
  150. void init_imx_image_type (void);
  151. void init_mxs_image_type(void);
  152. void init_default_image_type (void);
  153. void init_fit_image_type (void);
  154. void init_ubl_image_type(void);
  155. void init_omap_image_type(void);
  156. #endif /* _MKIIMAGE_H_ */