4 * Written by Guilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
6 * SPDX-License-Identifier: GPL-2.0+
12 #include "os_support.h"
21 #include <u-boot/sha1.h>
24 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26 #define IH_ARCH_DEFAULT IH_ARCH_INVALID
29 * This structure defines all such variables those are initialized by
30 * mkimage and dumpimage main core and need to be referred by image
31 * type specific functions
33 struct image_tool_params {
55 const char *outfile; /* Output filename */
56 const char *keydir; /* Directory holding private keys */
57 const char *keydest; /* Destination .dtb for public key */
58 const char *comment; /* Comment to add to signature node */
59 int require_keys; /* 1 to mark signing keys as 'required' */
63 * image type specific variables and callback functions
65 struct image_type_params {
66 /* name is an identification tag string for added support */
69 * header size is local to the specific image type to be supported,
70 * mkimage core treats this as number of bytes
73 /* Image type header pointer */
76 * There are several arguments that are passed on the command line
77 * and are registered as flags in image_tool_params structure.
78 * This callback function can be used to check the passed arguments
79 * are in-lined with the image type to be supported
81 * Returns 1 if parameter check is successful
83 int (*check_params) (struct image_tool_params *);
85 * This function is used by list command (i.e. mkimage -l <filename>)
86 * image type verification code must be put here
88 * Returns 0 if image header verification is successful
89 * otherwise, returns respective negative error codes
91 int (*verify_header) (unsigned char *, int, struct image_tool_params *);
92 /* Prints image information abstracting from image header */
93 void (*print_header) (const void *);
95 * The header or image contents need to be set as per image type to
96 * be generated using this callback function.
97 * further output file post processing (for ex. checksum calculation,
98 * padding bytes etc..) can also be done in this callback function.
100 void (*set_header) (void *, struct stat *, int,
101 struct image_tool_params *);
103 * This function is used by the command to retrieve a data file from
104 * the image (i.e. dumpimage -i <image> -p <position> <data_file>).
105 * Thus the code to extract a file from an image must be put here.
107 * Returns 0 if the file was successfully retrieved from the image,
108 * or a negative value on error.
110 int (*extract_datafile) (void *, struct image_tool_params *);
112 * Some image generation support for ex (default image type) supports
113 * more than one type_ids, this callback function is used to check
114 * whether input (-T <image_type>) is supported by registered image
115 * generation/list low level code
117 int (*check_image_type) (uint8_t);
118 /* This callback function will be executed if fflag is defined */
119 int (*fflag_handle) (struct image_tool_params *);
121 * This callback function will be executed for variable size record
122 * It is expected to build this header in memory and return its length
123 * and a pointer to it by using image_type_params.header_size and
124 * image_type_params.hdr. The return value shall indicate if an
125 * additional padding should be used when copying the data image
126 * by returning the padding length.
128 int (*vrec_header) (struct image_tool_params *,
129 struct image_type_params *);
130 /* pointer to the next registered entry in linked list */
131 struct image_type_params *next;
135 * Tool registration function.
137 typedef void (*imagetool_register_t)(struct image_type_params *);
140 * Initializes all image types with the given registration callback
142 * An image tool uses this function to initialize all image types.
144 void register_image_tool(imagetool_register_t image_register);
147 * Register a image type within a tool.
148 * An image type uses this function to register itself within
151 void register_image_type(struct image_type_params *tparams);
154 * There is a c file associated with supported image type low level code
155 * for ex. default_image.c, fit_image.c
156 * init_xxx_type() is the only function referred by image tool core to avoid
157 * a single lined header file, you can define them here
159 * Supported image types init functions
161 void init_default_image_type(void);
162 void init_atmel_image_type(void);
163 void init_pbl_image_type(void);
164 void init_ais_image_type(void);
165 void init_kwb_image_type(void);
166 void init_imx_image_type(void);
167 void init_mxs_image_type(void);
168 void init_fit_image_type(void);
169 void init_ubl_image_type(void);
170 void init_omap_image_type(void);
171 void init_socfpga_image_type(void);
172 void init_gpimage_type(void);
174 void pbl_load_uboot(int fd, struct image_tool_params *mparams);
176 #endif /* _IMAGETOOL_H_ */