PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/u-boot-2014.07/tools/imagetool.h

https://gitlab.com/pine64-android/brandy
C Header | 175 lines | 75 code | 12 blank | 88 comment | 0 complexity | d8c806b44ceeba64ee9baa29328450e5 MD5 | raw file
  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 <u-boot/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 iflag;
  33. int lflag;
  34. int pflag;
  35. int vflag;
  36. int xflag;
  37. int skipcpy;
  38. int os;
  39. int arch;
  40. int type;
  41. int comp;
  42. char *dtc;
  43. unsigned int addr;
  44. unsigned int ep;
  45. char *imagename;
  46. char *imagename2;
  47. char *datafile;
  48. char *imagefile;
  49. char *cmdname;
  50. const char *outfile; /* Output filename */
  51. const char *keydir; /* Directory holding private keys */
  52. const char *keydest; /* Destination .dtb for public key */
  53. const char *comment; /* Comment to add to signature node */
  54. int require_keys; /* 1 to mark signing keys as 'required' */
  55. };
  56. /*
  57. * image type specific variables and callback functions
  58. */
  59. struct image_type_params {
  60. /* name is an identification tag string for added support */
  61. char *name;
  62. /*
  63. * header size is local to the specific image type to be supported,
  64. * mkimage core treats this as number of bytes
  65. */
  66. uint32_t header_size;
  67. /* Image type header pointer */
  68. void *hdr;
  69. /*
  70. * There are several arguments that are passed on the command line
  71. * and are registered as flags in image_tool_params structure.
  72. * This callback function can be used to check the passed arguments
  73. * are in-lined with the image type to be supported
  74. *
  75. * Returns 1 if parameter check is successful
  76. */
  77. int (*check_params) (struct image_tool_params *);
  78. /*
  79. * This function is used by list command (i.e. mkimage -l <filename>)
  80. * image type verification code must be put here
  81. *
  82. * Returns 0 if image header verification is successful
  83. * otherwise, returns respective negative error codes
  84. */
  85. int (*verify_header) (unsigned char *, int, struct image_tool_params *);
  86. /* Prints image information abstracting from image header */
  87. void (*print_header) (const void *);
  88. /*
  89. * The header or image contents need to be set as per image type to
  90. * be generated using this callback function.
  91. * further output file post processing (for ex. checksum calculation,
  92. * padding bytes etc..) can also be done in this callback function.
  93. */
  94. void (*set_header) (void *, struct stat *, int,
  95. struct image_tool_params *);
  96. /*
  97. * This function is used by the command to retrieve a data file from
  98. * the image (i.e. dumpimage -i <image> -p <position> <data_file>).
  99. * Thus the code to extract a file from an image must be put here.
  100. *
  101. * Returns 0 if the file was successfully retrieved from the image,
  102. * or a negative value on error.
  103. */
  104. int (*extract_datafile) (void *, struct image_tool_params *);
  105. /*
  106. * Some image generation support for ex (default image type) supports
  107. * more than one type_ids, this callback function is used to check
  108. * whether input (-T <image_type>) is supported by registered image
  109. * generation/list low level code
  110. */
  111. int (*check_image_type) (uint8_t);
  112. /* This callback function will be executed if fflag is defined */
  113. int (*fflag_handle) (struct image_tool_params *);
  114. /*
  115. * This callback function will be executed for variable size record
  116. * It is expected to build this header in memory and return its length
  117. * and a pointer to it by using image_type_params.header_size and
  118. * image_type_params.hdr. The return value shall indicate if an
  119. * additional padding should be used when copying the data image
  120. * by returning the padding length.
  121. */
  122. int (*vrec_header) (struct image_tool_params *,
  123. struct image_type_params *);
  124. /* pointer to the next registered entry in linked list */
  125. struct image_type_params *next;
  126. };
  127. /*
  128. * Tool registration function.
  129. */
  130. typedef void (*imagetool_register_t)(struct image_type_params *);
  131. /*
  132. * Initializes all image types with the given registration callback
  133. * function.
  134. * An image tool uses this function to initialize all image types.
  135. */
  136. void register_image_tool(imagetool_register_t image_register);
  137. /*
  138. * Register a image type within a tool.
  139. * An image type uses this function to register itself within
  140. * all tools.
  141. */
  142. void register_image_type(struct image_type_params *tparams);
  143. /*
  144. * There is a c file associated with supported image type low level code
  145. * for ex. default_image.c, fit_image.c
  146. * init_xxx_type() is the only function referred by image tool core to avoid
  147. * a single lined header file, you can define them here
  148. *
  149. * Supported image types init functions
  150. */
  151. void init_default_image_type(void);
  152. void init_atmel_image_type(void);
  153. void init_pbl_image_type(void);
  154. void init_ais_image_type(void);
  155. void init_kwb_image_type(void);
  156. void init_imx_image_type(void);
  157. void init_mxs_image_type(void);
  158. void init_fit_image_type(void);
  159. void init_ubl_image_type(void);
  160. void init_omap_image_type(void);
  161. void init_gpimage_type(void);
  162. void pbl_load_uboot(int fd, struct image_tool_params *mparams);
  163. #endif /* _IMAGETOOL_H_ */