imagetool.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * (C) Copyright 2013
  3. *
  4. * Written by Guilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #ifndef _IMAGETOOL_H_
  9. #define _IMAGETOOL_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. #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  22. #define IH_ARCH_DEFAULT IH_ARCH_INVALID
  23. /*
  24. * This structure defines all such variables those are initialized by
  25. * mkimage and dumpimage main core and need to be referred by image
  26. * type specific functions
  27. */
  28. struct image_tool_params {
  29. int dflag;
  30. int eflag;
  31. int fflag;
  32. int lflag;
  33. int vflag;
  34. int xflag;
  35. int skipcpy;
  36. int os;
  37. int arch;
  38. int type;
  39. int comp;
  40. char *dtc;
  41. unsigned int addr;
  42. unsigned int ep;
  43. char *imagename;
  44. char *imagename2;
  45. char *datafile;
  46. char *imagefile;
  47. char *cmdname;
  48. const char *keydir; /* Directory holding private keys */
  49. const char *keydest; /* Destination .dtb for public key */
  50. const char *comment; /* Comment to add to signature node */
  51. int require_keys; /* 1 to mark signing keys as 'required' */
  52. };
  53. /*
  54. * image type specific variables and callback functions
  55. */
  56. struct image_type_params {
  57. /* name is an identification tag string for added support */
  58. char *name;
  59. /*
  60. * header size is local to the specific image type to be supported,
  61. * mkimage core treats this as number of bytes
  62. */
  63. uint32_t header_size;
  64. /* Image type header pointer */
  65. void *hdr;
  66. /*
  67. * There are several arguments that are passed on the command line
  68. * and are registered as flags in image_tool_params structure.
  69. * This callback function can be used to check the passed arguments
  70. * are in-lined with the image type to be supported
  71. *
  72. * Returns 1 if parameter check is successful
  73. */
  74. int (*check_params) (struct image_tool_params *);
  75. /*
  76. * This function is used by list command (i.e. mkimage -l <filename>)
  77. * image type verification code must be put here
  78. *
  79. * Returns 0 if image header verification is successful
  80. * otherwise, returns respective negative error codes
  81. */
  82. int (*verify_header) (unsigned char *, int, struct image_tool_params *);
  83. /* Prints image information abstracting from image header */
  84. void (*print_header) (const void *);
  85. /*
  86. * The header or image contents need to be set as per image type to
  87. * be generated using this callback function.
  88. * further output file post processing (for ex. checksum calculation,
  89. * padding bytes etc..) can also be done in this callback function.
  90. */
  91. void (*set_header) (void *, struct stat *, int,
  92. struct image_tool_params *);
  93. /*
  94. * Some image generation support for ex (default image type) supports
  95. * more than one type_ids, this callback function is used to check
  96. * whether input (-T <image_type>) is supported by registered image
  97. * generation/list low level code
  98. */
  99. int (*check_image_type) (uint8_t);
  100. /* This callback function will be executed if fflag is defined */
  101. int (*fflag_handle) (struct image_tool_params *);
  102. /*
  103. * This callback function will be executed for variable size record
  104. * It is expected to build this header in memory and return its length
  105. * and a pointer to it by using image_type_params.header_size and
  106. * image_type_params.hdr. The return value shall indicate if an
  107. * additional padding should be used when copying the data image
  108. * by returning the padding length.
  109. */
  110. int (*vrec_header) (struct image_tool_params *,
  111. struct image_type_params *);
  112. /* pointer to the next registered entry in linked list */
  113. struct image_type_params *next;
  114. };
  115. /*
  116. * Tool registration function.
  117. */
  118. typedef void (*imagetool_register_t)(struct image_type_params *);
  119. /*
  120. * Initializes all image types with the given registration callback
  121. * function.
  122. * An image tool uses this function to initialize all image types.
  123. */
  124. void register_image_tool(imagetool_register_t image_register);
  125. /*
  126. * Register a image type within a tool.
  127. * An image type uses this function to register itself within
  128. * all tools.
  129. */
  130. void register_image_type(struct image_type_params *tparams);
  131. /*
  132. * There is a c file associated with supported image type low level code
  133. * for ex. default_image.c, fit_image.c
  134. * init_xxx_type() is the only function referred by image tool core to avoid
  135. * a single lined header file, you can define them here
  136. *
  137. * Supported image types init functions
  138. */
  139. void init_default_image_type(void);
  140. void init_pbl_image_type(void);
  141. void init_ais_image_type(void);
  142. void init_kwb_image_type(void);
  143. void init_imx_image_type(void);
  144. void init_mxs_image_type(void);
  145. void init_fit_image_type(void);
  146. void init_ubl_image_type(void);
  147. void init_omap_image_type(void);
  148. void pbl_load_uboot(int fd, struct image_tool_params *mparams);
  149. #endif /* _IMAGETOOL_H_ */