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 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; either version 2 of |
| 9 | * the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 19 | * MA 02111-1307 USA |
| 20 | */ |
| 21 | |
Prafulla Wadaskar | 89a4d6b | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 22 | #ifndef _MKIIMAGE_H_ |
| 23 | #define _MKIIMAGE_H_ |
| 24 | |
Peter Tyser | 2f8d396 | 2009-03-13 18:54:51 -0500 | [diff] [blame] | 25 | #include "os_support.h" |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 26 | #include <errno.h> |
| 27 | #include <fcntl.h> |
| 28 | #include <stdio.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <string.h> |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 31 | #include <sys/stat.h> |
| 32 | #include <time.h> |
| 33 | #include <unistd.h> |
Bartlomiej Sieka | a6e530f | 2008-02-29 16:00:23 +0100 | [diff] [blame] | 34 | #include <sha1.h> |
Bartlomiej Sieka | 8cf3080 | 2008-02-29 16:00:24 +0100 | [diff] [blame] | 35 | #include "fdt_host.h" |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 36 | |
Prafulla Wadaskar | 89a4d6b | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 37 | #undef MKIMAGE_DEBUG |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 38 | |
| 39 | #ifdef MKIMAGE_DEBUG |
| 40 | #define debug(fmt,args...) printf (fmt ,##args) |
| 41 | #else |
| 42 | #define debug(fmt,args...) |
| 43 | #endif /* MKIMAGE_DEBUG */ |
| 44 | |
Bartlomiej Sieka | 9d25438 | 2008-03-11 12:34:47 +0100 | [diff] [blame] | 45 | #define MKIMAGE_TMPFILE_SUFFIX ".tmp" |
| 46 | #define MKIMAGE_MAX_TMPFILE_LEN 256 |
| 47 | #define MKIMAGE_DEFAULT_DTC_OPTIONS "-I dts -O dtb -p 500" |
| 48 | #define MKIMAGE_MAX_DTC_CMDLINE_LEN 512 |
| 49 | #define MKIMAGE_DTC "dtc" /* assume dtc is in $PATH */ |
Prafulla Wadaskar | 89a4d6b | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 50 | |
| 51 | /* |
| 52 | * This structure defines all such variables those are initialized by |
| 53 | * mkimage main core and need to be referred by image type specific |
| 54 | * functions |
| 55 | */ |
| 56 | struct mkimage_params { |
| 57 | int dflag; |
| 58 | int eflag; |
| 59 | int fflag; |
| 60 | int lflag; |
| 61 | int vflag; |
| 62 | int xflag; |
| 63 | int os; |
| 64 | int arch; |
| 65 | int type; |
| 66 | int comp; |
| 67 | char *dtc; |
| 68 | unsigned int addr; |
| 69 | unsigned int ep; |
| 70 | char *imagename; |
| 71 | char *datafile; |
| 72 | char *imagefile; |
| 73 | char *cmdname; |
| 74 | }; |
| 75 | |
| 76 | /* |
| 77 | * image type specific variables and callback functions |
| 78 | */ |
| 79 | struct image_type_params { |
| 80 | /* name is an identification tag string for added support */ |
| 81 | char *name; |
| 82 | /* |
| 83 | * header size is local to the specific image type to be supported, |
| 84 | * mkimage core treats this as number of bytes |
| 85 | */ |
| 86 | uint32_t header_size; |
| 87 | /* Image type header pointer */ |
| 88 | void *hdr; |
| 89 | /* |
| 90 | * There are several arguments that are passed on the command line |
| 91 | * and are registered as flags in mkimage_params structure. |
| 92 | * This callback function can be used to check the passed arguments |
| 93 | * are in-lined with the image type to be supported |
| 94 | * |
| 95 | * Returns 1 if parameter check is successful |
| 96 | */ |
| 97 | int (*check_params) (struct mkimage_params *); |
| 98 | /* |
| 99 | * This function is used by list command (i.e. mkimage -l <filename>) |
| 100 | * image type verification code must be put here |
| 101 | * |
| 102 | * Returns 0 if image header verification is successful |
| 103 | * otherwise, returns respective negative error codes |
| 104 | */ |
| 105 | int (*verify_header) (unsigned char *, int, struct mkimage_params *); |
| 106 | /* Prints image information abstracting from image header */ |
Wolfgang Denk | 3a2003f | 2009-08-19 11:42:56 +0200 | [diff] [blame] | 107 | void (*print_header) (const void *); |
Prafulla Wadaskar | 89a4d6b | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 108 | /* |
| 109 | * The header or image contents need to be set as per image type to |
| 110 | * be generated using this callback function. |
| 111 | * further output file post processing (for ex. checksum calculation, |
| 112 | * padding bytes etc..) can also be done in this callback function. |
| 113 | */ |
| 114 | void (*set_header) (void *, struct stat *, int, |
| 115 | struct mkimage_params *); |
| 116 | /* |
| 117 | * Some image generation support for ex (default image type) supports |
| 118 | * more than one type_ids, this callback function is used to check |
| 119 | * whether input (-T <image_type>) is supported by registered image |
| 120 | * generation/list low level code |
| 121 | */ |
| 122 | int (*check_image_type) (uint8_t); |
| 123 | /* This callback function will be executed if fflag is defined */ |
| 124 | int (*fflag_handle) (struct mkimage_params *); |
| 125 | /* pointer to the next registered entry in linked list */ |
| 126 | struct image_type_params *next; |
| 127 | }; |
| 128 | |
| 129 | /* |
| 130 | * Exported functions |
| 131 | */ |
| 132 | void mkimage_register (struct image_type_params *tparams); |
| 133 | |
| 134 | /* |
| 135 | * There is a c file associated with supported image type low level code |
| 136 | * for ex. default_image.c, fit_image.c |
| 137 | * init is the only function referred by mkimage core. |
| 138 | * to avoid a single lined header file, you can define them here |
| 139 | * |
| 140 | * Supported image types init functions |
| 141 | */ |
Prafulla Wadaskar | aa0c7a8 | 2009-09-07 15:05:02 +0530 | [diff] [blame] | 142 | void init_kwb_image_type (void); |
Stefano Babic | 8edcde5 | 2010-01-20 18:19:10 +0100 | [diff] [blame] | 143 | void init_imx_image_type (void); |
Prafulla Wadaskar | 89a4d6b | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 144 | void init_default_image_type (void); |
| 145 | void init_fit_image_type (void); |
Heiko Schocher | 7816f2c | 2011-07-16 00:06:42 +0000 | [diff] [blame] | 146 | void init_ubl_image_type(void); |
John Rigby | 3decb14 | 2011-07-21 09:10:30 -0400 | [diff] [blame] | 147 | void init_omap_image_type(void); |
Prafulla Wadaskar | 89a4d6b | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 148 | |
| 149 | #endif /* _MKIIMAGE_H_ */ |