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