2 * (C) Copyright 2000-2004
3 * DENX Software Engineering
4 * Wolfgang Denk, wd@denx.de
6 * SPDX-License-Identifier: GPL-2.0+
12 #include "os_support.h"
27 #define debug(fmt,args...) printf (fmt ,##args)
29 #define debug(fmt,args...)
30 #endif /* MKIMAGE_DEBUG */
32 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
34 static inline void *map_sysmem(ulong paddr, unsigned long len)
36 return (void *)(uintptr_t)paddr;
39 static inline ulong map_to_sysmem(void *ptr)
41 return (ulong)(uintptr_t)ptr;
44 #define MKIMAGE_TMPFILE_SUFFIX ".tmp"
45 #define MKIMAGE_MAX_TMPFILE_LEN 256
46 #define MKIMAGE_DEFAULT_DTC_OPTIONS "-I dts -O dtb -p 500"
47 #define MKIMAGE_MAX_DTC_CMDLINE_LEN 512
48 #define MKIMAGE_DTC "dtc" /* assume dtc is in $PATH */
50 #define IH_ARCH_DEFAULT IH_ARCH_INVALID
53 * This structure defines all such variables those are initialized by
54 * mkimage main core and need to be referred by image type specific
57 struct mkimage_params {
77 const char *keydir; /* Directory holding private keys */
78 const char *keydest; /* Destination .dtb for public key */
79 const char *comment; /* Comment to add to signature node */
80 int require_keys; /* 1 to mark signing keys as 'required' */
84 * image type specific variables and callback functions
86 struct image_type_params {
87 /* name is an identification tag string for added support */
90 * header size is local to the specific image type to be supported,
91 * mkimage core treats this as number of bytes
94 /* Image type header pointer */
97 * There are several arguments that are passed on the command line
98 * and are registered as flags in mkimage_params structure.
99 * This callback function can be used to check the passed arguments
100 * are in-lined with the image type to be supported
102 * Returns 1 if parameter check is successful
104 int (*check_params) (struct mkimage_params *);
106 * This function is used by list command (i.e. mkimage -l <filename>)
107 * image type verification code must be put here
109 * Returns 0 if image header verification is successful
110 * otherwise, returns respective negative error codes
112 int (*verify_header) (unsigned char *, int, struct mkimage_params *);
113 /* Prints image information abstracting from image header */
114 void (*print_header) (const void *);
116 * The header or image contents need to be set as per image type to
117 * be generated using this callback function.
118 * further output file post processing (for ex. checksum calculation,
119 * padding bytes etc..) can also be done in this callback function.
121 void (*set_header) (void *, struct stat *, int,
122 struct mkimage_params *);
124 * Some image generation support for ex (default image type) supports
125 * more than one type_ids, this callback function is used to check
126 * whether input (-T <image_type>) is supported by registered image
127 * generation/list low level code
129 int (*check_image_type) (uint8_t);
130 /* This callback function will be executed if fflag is defined */
131 int (*fflag_handle) (struct mkimage_params *);
133 * This callback function will be executed for variable size record
134 * It is expected to build this header in memory and return its length
135 * and a pointer to it
137 int (*vrec_header) (struct mkimage_params *,
138 struct image_type_params *);
139 /* pointer to the next registered entry in linked list */
140 struct image_type_params *next;
146 void mkimage_register (struct image_type_params *tparams);
149 * There is a c file associated with supported image type low level code
150 * for ex. default_image.c, fit_image.c
151 * init is the only function referred by mkimage core.
152 * to avoid a single lined header file, you can define them here
154 * Supported image types init functions
156 void pbl_load_uboot(int fd, struct mkimage_params *mparams);
157 void init_pbl_image_type(void);
158 void init_ais_image_type(void);
159 void init_kwb_image_type (void);
160 void init_imx_image_type (void);
161 void init_default_image_type (void);
162 void init_fit_image_type (void);
163 void init_ubl_image_type(void);
164 void init_omap_image_type(void);
166 #endif /* _MKIIMAGE_H_ */