Guilherme Maciel Ferreira | 8ed4d1c | 2013-12-01 12:43:10 -0700 | [diff] [blame] | 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> |
Jeroen Hofstee | bfe88fe | 2014-06-12 22:27:12 +0200 | [diff] [blame] | 21 | #include <u-boot/sha1.h> |
Guilherme Maciel Ferreira | 8ed4d1c | 2013-12-01 12:43:10 -0700 | [diff] [blame] | 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; |
Guilherme Maciel Ferreira | 5155381 | 2013-12-01 12:43:11 -0700 | [diff] [blame] | 37 | int iflag; |
Guilherme Maciel Ferreira | 8ed4d1c | 2013-12-01 12:43:10 -0700 | [diff] [blame] | 38 | int lflag; |
Guilherme Maciel Ferreira | 5155381 | 2013-12-01 12:43:11 -0700 | [diff] [blame] | 39 | int pflag; |
Guilherme Maciel Ferreira | 8ed4d1c | 2013-12-01 12:43:10 -0700 | [diff] [blame] | 40 | int vflag; |
| 41 | int xflag; |
| 42 | int skipcpy; |
| 43 | int os; |
| 44 | int arch; |
| 45 | int type; |
| 46 | int comp; |
| 47 | char *dtc; |
| 48 | unsigned int addr; |
| 49 | unsigned int ep; |
| 50 | char *imagename; |
| 51 | char *imagename2; |
| 52 | char *datafile; |
| 53 | char *imagefile; |
| 54 | char *cmdname; |
Guilherme Maciel Ferreira | 5155381 | 2013-12-01 12:43:11 -0700 | [diff] [blame] | 55 | const char *outfile; /* Output filename */ |
Guilherme Maciel Ferreira | 8ed4d1c | 2013-12-01 12:43:10 -0700 | [diff] [blame] | 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' */ |
| 60 | }; |
| 61 | |
| 62 | /* |
| 63 | * image type specific variables and callback functions |
| 64 | */ |
| 65 | struct image_type_params { |
| 66 | /* name is an identification tag string for added support */ |
| 67 | char *name; |
| 68 | /* |
| 69 | * header size is local to the specific image type to be supported, |
| 70 | * mkimage core treats this as number of bytes |
| 71 | */ |
| 72 | uint32_t header_size; |
| 73 | /* Image type header pointer */ |
| 74 | void *hdr; |
| 75 | /* |
| 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 |
| 80 | * |
| 81 | * Returns 1 if parameter check is successful |
| 82 | */ |
| 83 | int (*check_params) (struct image_tool_params *); |
| 84 | /* |
| 85 | * This function is used by list command (i.e. mkimage -l <filename>) |
| 86 | * image type verification code must be put here |
| 87 | * |
| 88 | * Returns 0 if image header verification is successful |
| 89 | * otherwise, returns respective negative error codes |
| 90 | */ |
| 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 *); |
| 94 | /* |
| 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. |
| 99 | */ |
| 100 | void (*set_header) (void *, struct stat *, int, |
| 101 | struct image_tool_params *); |
| 102 | /* |
Guilherme Maciel Ferreira | 5155381 | 2013-12-01 12:43:11 -0700 | [diff] [blame] | 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. |
| 106 | * |
| 107 | * Returns 0 if the file was successfully retrieved from the image, |
| 108 | * or a negative value on error. |
| 109 | */ |
| 110 | int (*extract_datafile) (void *, struct image_tool_params *); |
| 111 | /* |
Guilherme Maciel Ferreira | 8ed4d1c | 2013-12-01 12:43:10 -0700 | [diff] [blame] | 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 |
| 116 | */ |
| 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 *); |
| 120 | /* |
| 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. |
| 127 | */ |
| 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; |
| 132 | }; |
| 133 | |
| 134 | /* |
| 135 | * Tool registration function. |
| 136 | */ |
| 137 | typedef void (*imagetool_register_t)(struct image_type_params *); |
| 138 | |
| 139 | /* |
| 140 | * Initializes all image types with the given registration callback |
| 141 | * function. |
| 142 | * An image tool uses this function to initialize all image types. |
| 143 | */ |
| 144 | void register_image_tool(imagetool_register_t image_register); |
| 145 | |
| 146 | /* |
| 147 | * Register a image type within a tool. |
| 148 | * An image type uses this function to register itself within |
| 149 | * all tools. |
| 150 | */ |
| 151 | void register_image_type(struct image_type_params *tparams); |
| 152 | |
| 153 | /* |
| 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 |
| 158 | * |
| 159 | * Supported image types init functions |
| 160 | */ |
| 161 | void init_default_image_type(void); |
Andreas Bießmann | 7c75d3e | 2014-05-19 14:23:39 +0200 | [diff] [blame] | 162 | void init_atmel_image_type(void); |
Guilherme Maciel Ferreira | 8ed4d1c | 2013-12-01 12:43:10 -0700 | [diff] [blame] | 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); |
Charles Manning | 685e87f | 2014-03-06 15:40:50 +1300 | [diff] [blame] | 171 | void init_socfpga_image_type(void); |
Karicheri, Muralidharan | 8277793 | 2014-04-04 13:16:48 -0400 | [diff] [blame] | 172 | void init_gpimage_type(void); |
Guilherme Maciel Ferreira | 8ed4d1c | 2013-12-01 12:43:10 -0700 | [diff] [blame] | 173 | |
| 174 | void pbl_load_uboot(int fd, struct image_tool_params *mparams); |
| 175 | |
| 176 | #endif /* _IMAGETOOL_H_ */ |