Marian Balakowicz | 41d71ed | 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 | 41d71ed | 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 | fabf3cf | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 22 | #ifndef _MKIIMAGE_H_ |
| 23 | #define _MKIIMAGE_H_ |
| 24 | |
Peter Tyser | b06976d | 2009-03-13 18:54:51 -0500 | [diff] [blame] | 25 | #include "os_support.h" |
Marian Balakowicz | 41d71ed | 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 | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 31 | #include <sys/stat.h> |
| 32 | #include <time.h> |
| 33 | #include <unistd.h> |
Bartlomiej Sieka | 6bfe92f | 2008-02-29 16:00:23 +0100 | [diff] [blame] | 34 | #include <sha1.h> |
Bartlomiej Sieka | 6125086 | 2008-02-29 16:00:24 +0100 | [diff] [blame] | 35 | #include "fdt_host.h" |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 36 | |
Prafulla Wadaskar | fabf3cf | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 37 | #undef MKIMAGE_DEBUG |
Marian Balakowicz | e227fbb | 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 | |
Simon Glass | aa183f4 | 2013-05-07 06:11:49 +0000 | [diff] [blame] | 45 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
| 46 | |
Bartlomiej Sieka | d7816fb | 2008-03-11 12:34:47 +0100 | [diff] [blame] | 47 | #define MKIMAGE_TMPFILE_SUFFIX ".tmp" |
| 48 | #define MKIMAGE_MAX_TMPFILE_LEN 256 |
| 49 | #define MKIMAGE_DEFAULT_DTC_OPTIONS "-I dts -O dtb -p 500" |
| 50 | #define MKIMAGE_MAX_DTC_CMDLINE_LEN 512 |
| 51 | #define MKIMAGE_DTC "dtc" /* assume dtc is in $PATH */ |
Prafulla Wadaskar | fabf3cf | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 52 | |
| 53 | /* |
| 54 | * This structure defines all such variables those are initialized by |
| 55 | * mkimage main core and need to be referred by image type specific |
| 56 | * functions |
| 57 | */ |
| 58 | struct mkimage_params { |
| 59 | int dflag; |
| 60 | int eflag; |
| 61 | int fflag; |
| 62 | int lflag; |
| 63 | int vflag; |
| 64 | int xflag; |
Stefano Babic | 4a96330 | 2011-09-15 23:50:16 +0000 | [diff] [blame] | 65 | int skipcpy; |
Prafulla Wadaskar | fabf3cf | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 66 | int os; |
| 67 | int arch; |
| 68 | int type; |
| 69 | int comp; |
| 70 | char *dtc; |
| 71 | unsigned int addr; |
| 72 | unsigned int ep; |
| 73 | char *imagename; |
Shaohui Xie | ea65fd8 | 2012-08-10 02:49:35 +0000 | [diff] [blame] | 74 | char *imagename2; |
Prafulla Wadaskar | fabf3cf | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 75 | char *datafile; |
| 76 | char *imagefile; |
| 77 | char *cmdname; |
| 78 | }; |
| 79 | |
| 80 | /* |
| 81 | * image type specific variables and callback functions |
| 82 | */ |
| 83 | struct image_type_params { |
| 84 | /* name is an identification tag string for added support */ |
| 85 | char *name; |
| 86 | /* |
| 87 | * header size is local to the specific image type to be supported, |
| 88 | * mkimage core treats this as number of bytes |
| 89 | */ |
| 90 | uint32_t header_size; |
| 91 | /* Image type header pointer */ |
| 92 | void *hdr; |
| 93 | /* |
| 94 | * There are several arguments that are passed on the command line |
| 95 | * and are registered as flags in mkimage_params structure. |
| 96 | * This callback function can be used to check the passed arguments |
| 97 | * are in-lined with the image type to be supported |
| 98 | * |
| 99 | * Returns 1 if parameter check is successful |
| 100 | */ |
| 101 | int (*check_params) (struct mkimage_params *); |
| 102 | /* |
| 103 | * This function is used by list command (i.e. mkimage -l <filename>) |
| 104 | * image type verification code must be put here |
| 105 | * |
| 106 | * Returns 0 if image header verification is successful |
| 107 | * otherwise, returns respective negative error codes |
| 108 | */ |
| 109 | int (*verify_header) (unsigned char *, int, struct mkimage_params *); |
| 110 | /* Prints image information abstracting from image header */ |
Wolfgang Denk | 3b50677 | 2009-08-19 11:42:56 +0200 | [diff] [blame] | 111 | void (*print_header) (const void *); |
Prafulla Wadaskar | fabf3cf | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 112 | /* |
| 113 | * The header or image contents need to be set as per image type to |
| 114 | * be generated using this callback function. |
| 115 | * further output file post processing (for ex. checksum calculation, |
| 116 | * padding bytes etc..) can also be done in this callback function. |
| 117 | */ |
| 118 | void (*set_header) (void *, struct stat *, int, |
| 119 | struct mkimage_params *); |
| 120 | /* |
| 121 | * Some image generation support for ex (default image type) supports |
| 122 | * more than one type_ids, this callback function is used to check |
| 123 | * whether input (-T <image_type>) is supported by registered image |
| 124 | * generation/list low level code |
| 125 | */ |
| 126 | int (*check_image_type) (uint8_t); |
| 127 | /* This callback function will be executed if fflag is defined */ |
| 128 | int (*fflag_handle) (struct mkimage_params *); |
Stefano Babic | 4a96330 | 2011-09-15 23:50:16 +0000 | [diff] [blame] | 129 | /* |
| 130 | * This callback function will be executed for variable size record |
| 131 | * It is expected to build this header in memory and return its length |
| 132 | * and a pointer to it |
| 133 | */ |
| 134 | int (*vrec_header) (struct mkimage_params *, |
| 135 | struct image_type_params *); |
Prafulla Wadaskar | fabf3cf | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 136 | /* pointer to the next registered entry in linked list */ |
| 137 | struct image_type_params *next; |
| 138 | }; |
| 139 | |
| 140 | /* |
| 141 | * Exported functions |
| 142 | */ |
| 143 | void mkimage_register (struct image_type_params *tparams); |
| 144 | |
| 145 | /* |
| 146 | * There is a c file associated with supported image type low level code |
| 147 | * for ex. default_image.c, fit_image.c |
| 148 | * init is the only function referred by mkimage core. |
| 149 | * to avoid a single lined header file, you can define them here |
| 150 | * |
| 151 | * Supported image types init functions |
| 152 | */ |
Shaohui Xie | ea65fd8 | 2012-08-10 02:49:35 +0000 | [diff] [blame] | 153 | void pbl_load_uboot(int fd, struct mkimage_params *mparams); |
| 154 | void init_pbl_image_type(void); |
Stefano Babic | 3885551 | 2011-10-17 00:07:43 +0000 | [diff] [blame] | 155 | void init_ais_image_type(void); |
Prafulla Wadaskar | 0732941 | 2009-09-07 15:05:02 +0530 | [diff] [blame] | 156 | void init_kwb_image_type (void); |
Stefano Babic | 7b07f09 | 2010-01-20 18:19:10 +0100 | [diff] [blame] | 157 | void init_imx_image_type (void); |
Prafulla Wadaskar | fabf3cf | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 158 | void init_default_image_type (void); |
| 159 | void init_fit_image_type (void); |
Heiko Schocher | 58cb84d | 2011-07-16 00:06:42 +0000 | [diff] [blame] | 160 | void init_ubl_image_type(void); |
John Rigby | 34d12a1 | 2011-07-21 09:10:30 -0400 | [diff] [blame] | 161 | void init_omap_image_type(void); |
Prafulla Wadaskar | fabf3cf | 2009-08-19 17:36:46 +0530 | [diff] [blame] | 162 | |
| 163 | #endif /* _MKIIMAGE_H_ */ |