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>
23 /* define __KERNEL__ in order to get the definitions
24 * required by the linker list. This is probably not
25 * the best way to do this */
28 #include <linker_lists.h>
30 #endif /* __KERNEL__ */
34 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
36 #define IH_ARCH_DEFAULT IH_ARCH_INVALID
39 * This structure defines all such variables those are initialized by
40 * mkimage and dumpimage main core and need to be referred by image
41 * type specific functions
43 struct image_tool_params {
65 const char *outfile; /* Output filename */
66 const char *keydir; /* Directory holding private keys */
67 const char *keydest; /* Destination .dtb for public key */
68 const char *comment; /* Comment to add to signature node */
69 int require_keys; /* 1 to mark signing keys as 'required' */
73 * image type specific variables and callback functions
75 struct image_type_params {
76 /* name is an identification tag string for added support */
79 * header size is local to the specific image type to be supported,
80 * mkimage core treats this as number of bytes
83 /* Image type header pointer */
86 * There are several arguments that are passed on the command line
87 * and are registered as flags in image_tool_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
91 * Returns 1 if parameter check is successful
93 int (*check_params) (struct image_tool_params *);
95 * This function is used by list command (i.e. mkimage -l <filename>)
96 * image type verification code must be put here
98 * Returns 0 if image header verification is successful
99 * otherwise, returns respective negative error codes
101 int (*verify_header) (unsigned char *, int, struct image_tool_params *);
102 /* Prints image information abstracting from image header */
103 void (*print_header) (const void *);
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.
110 void (*set_header) (void *, struct stat *, int,
111 struct image_tool_params *);
113 * This function is used by the command to retrieve a component
114 * (sub-image) from the image (i.e. dumpimage -i <image> -p <position>
116 * Thus the code to extract a file from an image must be put here.
118 * Returns 0 if the file was successfully retrieved from the image,
119 * or a negative value on error.
121 int (*extract_subimage)(void *, struct image_tool_params *);
123 * Some image generation support for ex (default image type) supports
124 * more than one type_ids, this callback function is used to check
125 * whether input (-T <image_type>) is supported by registered image
126 * generation/list low level code
128 int (*check_image_type) (uint8_t);
129 /* This callback function will be executed if fflag is defined */
130 int (*fflag_handle) (struct image_tool_params *);
132 * This callback function will be executed for variable size record
133 * It is expected to build this header in memory and return its length
134 * and a pointer to it by using image_type_params.header_size and
135 * image_type_params.hdr. The return value shall indicate if an
136 * additional padding should be used when copying the data image
137 * by returning the padding length.
139 int (*vrec_header) (struct image_tool_params *,
140 struct image_type_params *);
144 * imagetool_get_type() - find the image type params for a given image type
146 * It scans all registers image type supports
147 * checks the input type for each supported image type
150 * returns respective image_type_params pointer if success
151 * if input type_id is not supported by any of image_type_support
154 struct image_type_params *imagetool_get_type(int type);
157 * imagetool_verify_print_header() - verifies the image header
159 * Scan registered image types and verify the image_header for each
160 * supported image type. If verification is successful, this prints
161 * the respective header.
163 * @return 0 on success, negative if input image format does not match with
164 * any of supported image types
166 int imagetool_verify_print_header(
169 struct image_type_params *tparams,
170 struct image_tool_params *params);
173 * imagetool_save_subimage - store data into a file
174 * @file_name: name of the destination file
175 * @file_data: data to be written
176 * @file_len: the amount of data to store
178 * imagetool_save_subimage() store file_len bytes of data pointed by file_data
179 * into the file name by file_name.
182 * zero in case of success or a negative value if fail.
184 int imagetool_save_subimage(
185 const char *file_name,
190 * There is a c file associated with supported image type low level code
191 * for ex. default_image.c, fit_image.c
195 void pbl_load_uboot(int fd, struct image_tool_params *mparams);
197 #define U_BOOT_IMAGE_TYPE( \
211 ll_entry_declare(struct image_type_params, _id, image_type) = { \
213 .header_size = _header_size, \
215 .check_params = _check_params, \
216 .verify_header = _verify_header, \
217 .print_header = _print_header, \
218 .set_header = _set_header, \
219 .extract_subimage = _extract_subimage, \
220 .check_image_type = _check_image_type, \
221 .fflag_handle = _fflag_handle, \
222 .vrec_header = _vrec_header \
225 #endif /* _IMAGETOOL_H_ */