Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000-2004 |
| 3 | * DENX Software Engineering |
| 4 | * Wolfgang Denk, wd@denx.de |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 5 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
Prafulla Wadaskar | 89a4d6b | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 9 | #ifndef _MKIIMAGE_H_ |
| 10 | #define _MKIIMAGE_H_ |
| 11 | |
Peter Tyser | 2f8d396 | 2009-03-13 18:54:51 -0500 | [diff] [blame] | 12 | #include "os_support.h" |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 13 | #include <errno.h> |
| 14 | #include <fcntl.h> |
| 15 | #include <stdio.h> |
| 16 | #include <stdlib.h> |
| 17 | #include <string.h> |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 18 | #include <sys/stat.h> |
| 19 | #include <time.h> |
| 20 | #include <unistd.h> |
Bartlomiej Sieka | a6e530f | 2008-02-29 16:00:23 +0100 | [diff] [blame] | 21 | #include <sha1.h> |
Bartlomiej Sieka | 8cf3080 | 2008-02-29 16:00:24 +0100 | [diff] [blame] | 22 | #include "fdt_host.h" |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 23 | |
Prafulla Wadaskar | 89a4d6b | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 24 | #undef MKIMAGE_DEBUG |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 25 | |
| 26 | #ifdef MKIMAGE_DEBUG |
| 27 | #define debug(fmt,args...) printf (fmt ,##args) |
| 28 | #else |
| 29 | #define debug(fmt,args...) |
| 30 | #endif /* MKIMAGE_DEBUG */ |
| 31 | |
Simon Glass | 816cb03 | 2013-05-07 06:11:49 +0000 | [diff] [blame] | 32 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
| 33 | |
Simon Glass | 2434c66 | 2013-05-16 13:53:20 +0000 | [diff] [blame] | 34 | static inline void *map_sysmem(ulong paddr, unsigned long len) |
| 35 | { |
| 36 | return (void *)(uintptr_t)paddr; |
| 37 | } |
| 38 | |
| 39 | static inline ulong map_to_sysmem(void *ptr) |
| 40 | { |
| 41 | return (ulong)(uintptr_t)ptr; |
| 42 | } |
| 43 | |
Bartlomiej Sieka | 9d25438 | 2008-03-11 12:34:47 +0100 | [diff] [blame] | 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 */ |
Prafulla Wadaskar | 89a4d6b | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 49 | |
Simon Glass | 2434c66 | 2013-05-16 13:53:20 +0000 | [diff] [blame] | 50 | #define IH_ARCH_DEFAULT IH_ARCH_INVALID |
| 51 | |
Prafulla Wadaskar | 89a4d6b | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 52 | /* |
| 53 | * This structure defines all such variables those are initialized by |
| 54 | * mkimage main core and need to be referred by image type specific |
| 55 | * functions |
| 56 | */ |
| 57 | struct mkimage_params { |
| 58 | int dflag; |
| 59 | int eflag; |
| 60 | int fflag; |
| 61 | int lflag; |
| 62 | int vflag; |
| 63 | int xflag; |
Stefano Babic | f066210 | 2011-09-15 23:50:16 +0000 | [diff] [blame] | 64 | int skipcpy; |
Prafulla Wadaskar | 89a4d6b | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 65 | int os; |
| 66 | int arch; |
| 67 | int type; |
| 68 | int comp; |
| 69 | char *dtc; |
| 70 | unsigned int addr; |
| 71 | unsigned int ep; |
| 72 | char *imagename; |
Shaohui Xie | 5d898a0 | 2012-08-10 02:49:35 +0000 | [diff] [blame] | 73 | char *imagename2; |
Prafulla Wadaskar | 89a4d6b | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 74 | char *datafile; |
| 75 | char *imagefile; |
| 76 | char *cmdname; |
Simon Glass | 80e4df8 | 2013-06-13 15:10:03 -0700 | [diff] [blame] | 77 | const char *keydir; /* Directory holding private keys */ |
Simon Glass | e29495d | 2013-06-13 15:10:04 -0700 | [diff] [blame] | 78 | const char *keydest; /* Destination .dtb for public key */ |
Simon Glass | 4f61042 | 2013-06-13 15:10:06 -0700 | [diff] [blame] | 79 | const char *comment; /* Comment to add to signature node */ |
Simon Glass | 399c744 | 2013-06-13 15:10:07 -0700 | [diff] [blame] | 80 | int require_keys; /* 1 to mark signing keys as 'required' */ |
Prafulla Wadaskar | 89a4d6b | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | /* |
| 84 | * image type specific variables and callback functions |
| 85 | */ |
| 86 | struct image_type_params { |
| 87 | /* name is an identification tag string for added support */ |
| 88 | char *name; |
| 89 | /* |
| 90 | * header size is local to the specific image type to be supported, |
| 91 | * mkimage core treats this as number of bytes |
| 92 | */ |
| 93 | uint32_t header_size; |
| 94 | /* Image type header pointer */ |
| 95 | void *hdr; |
| 96 | /* |
| 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 |
| 101 | * |
| 102 | * Returns 1 if parameter check is successful |
| 103 | */ |
| 104 | int (*check_params) (struct mkimage_params *); |
| 105 | /* |
| 106 | * This function is used by list command (i.e. mkimage -l <filename>) |
| 107 | * image type verification code must be put here |
| 108 | * |
| 109 | * Returns 0 if image header verification is successful |
| 110 | * otherwise, returns respective negative error codes |
| 111 | */ |
| 112 | int (*verify_header) (unsigned char *, int, struct mkimage_params *); |
| 113 | /* Prints image information abstracting from image header */ |
Wolfgang Denk | 3a2003f | 2009-08-19 11:42:56 +0200 | [diff] [blame] | 114 | void (*print_header) (const void *); |
Prafulla Wadaskar | 89a4d6b | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 115 | /* |
| 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. |
| 120 | */ |
| 121 | void (*set_header) (void *, struct stat *, int, |
| 122 | struct mkimage_params *); |
| 123 | /* |
| 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 |
| 128 | */ |
| 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 *); |
Stefano Babic | f066210 | 2011-09-15 23:50:16 +0000 | [diff] [blame] | 132 | /* |
| 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 |
Stefano Babic | 9bac0bb | 2013-08-19 19:03:19 +0200 | [diff] [blame] | 135 | * and a pointer to it by using image_type_params.header_size and |
| 136 | * image_type_params.hdr. The return value shall indicate if an |
| 137 | * additional padding should be used when copying the data image |
| 138 | * by returning the padding length. |
Stefano Babic | f066210 | 2011-09-15 23:50:16 +0000 | [diff] [blame] | 139 | */ |
| 140 | int (*vrec_header) (struct mkimage_params *, |
| 141 | struct image_type_params *); |
Prafulla Wadaskar | 89a4d6b | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 142 | /* pointer to the next registered entry in linked list */ |
| 143 | struct image_type_params *next; |
| 144 | }; |
| 145 | |
| 146 | /* |
| 147 | * Exported functions |
| 148 | */ |
| 149 | void mkimage_register (struct image_type_params *tparams); |
| 150 | |
| 151 | /* |
| 152 | * There is a c file associated with supported image type low level code |
| 153 | * for ex. default_image.c, fit_image.c |
| 154 | * init is the only function referred by mkimage core. |
| 155 | * to avoid a single lined header file, you can define them here |
| 156 | * |
| 157 | * Supported image types init functions |
| 158 | */ |
Shaohui Xie | 5d898a0 | 2012-08-10 02:49:35 +0000 | [diff] [blame] | 159 | void pbl_load_uboot(int fd, struct mkimage_params *mparams); |
| 160 | void init_pbl_image_type(void); |
Stefano Babic | 4962e38 | 2011-10-17 00:07:43 +0000 | [diff] [blame] | 161 | void init_ais_image_type(void); |
Prafulla Wadaskar | aa0c7a8 | 2009-09-07 15:05:02 +0530 | [diff] [blame] | 162 | void init_kwb_image_type (void); |
Stefano Babic | 8edcde5 | 2010-01-20 18:19:10 +0100 | [diff] [blame] | 163 | void init_imx_image_type (void); |
Marek Vasut | bce8837 | 2013-08-26 20:43:33 +0200 | [diff] [blame] | 164 | void init_mxs_image_type(void); |
Prafulla Wadaskar | 89a4d6b | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 165 | void init_default_image_type (void); |
| 166 | void init_fit_image_type (void); |
Heiko Schocher | 7816f2c | 2011-07-16 00:06:42 +0000 | [diff] [blame] | 167 | void init_ubl_image_type(void); |
John Rigby | 3decb14 | 2011-07-21 09:10:30 -0400 | [diff] [blame] | 168 | void init_omap_image_type(void); |
Prafulla Wadaskar | 89a4d6b | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 169 | |
| 170 | #endif /* _MKIIMAGE_H_ */ |