blob: ab8baf8f056fdde53fe107feb16d2127c4366a4b [file] [log] [blame]
Marian Balakowiczb97a2a02008-01-08 18:14:09 +01001/*
2 * (C) Copyright 2000-2004
3 * DENX Software Engineering
4 * Wolfgang Denk, wd@denx.de
Marian Balakowiczb97a2a02008-01-08 18:14:09 +01005 *
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 Wadaskar89a4d6b2009-08-19 17:36:46 +053022#ifndef _MKIIMAGE_H_
23#define _MKIIMAGE_H_
24
Peter Tyser2f8d3962009-03-13 18:54:51 -050025#include "os_support.h"
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010026#include <errno.h>
27#include <fcntl.h>
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010031#include <sys/stat.h>
32#include <time.h>
33#include <unistd.h>
Bartlomiej Siekaa6e530f2008-02-29 16:00:23 +010034#include <sha1.h>
Bartlomiej Sieka8cf30802008-02-29 16:00:24 +010035#include "fdt_host.h"
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010036
Prafulla Wadaskar89a4d6b2009-08-19 17:36:46 +053037#undef MKIMAGE_DEBUG
Marian Balakowicz5dfb5212008-02-29 21:24:06 +010038
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 Glass816cb032013-05-07 06:11:49 +000045#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
46
Simon Glass2434c662013-05-16 13:53:20 +000047static inline void *map_sysmem(ulong paddr, unsigned long len)
48{
49 return (void *)(uintptr_t)paddr;
50}
51
52static inline ulong map_to_sysmem(void *ptr)
53{
54 return (ulong)(uintptr_t)ptr;
55}
56
Bartlomiej Sieka9d254382008-03-11 12:34:47 +010057#define MKIMAGE_TMPFILE_SUFFIX ".tmp"
58#define MKIMAGE_MAX_TMPFILE_LEN 256
59#define MKIMAGE_DEFAULT_DTC_OPTIONS "-I dts -O dtb -p 500"
60#define MKIMAGE_MAX_DTC_CMDLINE_LEN 512
61#define MKIMAGE_DTC "dtc" /* assume dtc is in $PATH */
Prafulla Wadaskar89a4d6b2009-08-19 17:36:46 +053062
Simon Glass2434c662013-05-16 13:53:20 +000063#define IH_ARCH_DEFAULT IH_ARCH_INVALID
64
Prafulla Wadaskar89a4d6b2009-08-19 17:36:46 +053065/*
66 * This structure defines all such variables those are initialized by
67 * mkimage main core and need to be referred by image type specific
68 * functions
69 */
70struct mkimage_params {
71 int dflag;
72 int eflag;
73 int fflag;
74 int lflag;
75 int vflag;
76 int xflag;
Stefano Babicf0662102011-09-15 23:50:16 +000077 int skipcpy;
Prafulla Wadaskar89a4d6b2009-08-19 17:36:46 +053078 int os;
79 int arch;
80 int type;
81 int comp;
82 char *dtc;
83 unsigned int addr;
84 unsigned int ep;
85 char *imagename;
Shaohui Xie5d898a02012-08-10 02:49:35 +000086 char *imagename2;
Prafulla Wadaskar89a4d6b2009-08-19 17:36:46 +053087 char *datafile;
88 char *imagefile;
89 char *cmdname;
Simon Glass80e4df82013-06-13 15:10:03 -070090 const char *keydir; /* Directory holding private keys */
Simon Glasse29495d2013-06-13 15:10:04 -070091 const char *keydest; /* Destination .dtb for public key */
Simon Glass4f610422013-06-13 15:10:06 -070092 const char *comment; /* Comment to add to signature node */
Prafulla Wadaskar89a4d6b2009-08-19 17:36:46 +053093};
94
95/*
96 * image type specific variables and callback functions
97 */
98struct image_type_params {
99 /* name is an identification tag string for added support */
100 char *name;
101 /*
102 * header size is local to the specific image type to be supported,
103 * mkimage core treats this as number of bytes
104 */
105 uint32_t header_size;
106 /* Image type header pointer */
107 void *hdr;
108 /*
109 * There are several arguments that are passed on the command line
110 * and are registered as flags in mkimage_params structure.
111 * This callback function can be used to check the passed arguments
112 * are in-lined with the image type to be supported
113 *
114 * Returns 1 if parameter check is successful
115 */
116 int (*check_params) (struct mkimage_params *);
117 /*
118 * This function is used by list command (i.e. mkimage -l <filename>)
119 * image type verification code must be put here
120 *
121 * Returns 0 if image header verification is successful
122 * otherwise, returns respective negative error codes
123 */
124 int (*verify_header) (unsigned char *, int, struct mkimage_params *);
125 /* Prints image information abstracting from image header */
Wolfgang Denk3a2003f2009-08-19 11:42:56 +0200126 void (*print_header) (const void *);
Prafulla Wadaskar89a4d6b2009-08-19 17:36:46 +0530127 /*
128 * The header or image contents need to be set as per image type to
129 * be generated using this callback function.
130 * further output file post processing (for ex. checksum calculation,
131 * padding bytes etc..) can also be done in this callback function.
132 */
133 void (*set_header) (void *, struct stat *, int,
134 struct mkimage_params *);
135 /*
136 * Some image generation support for ex (default image type) supports
137 * more than one type_ids, this callback function is used to check
138 * whether input (-T <image_type>) is supported by registered image
139 * generation/list low level code
140 */
141 int (*check_image_type) (uint8_t);
142 /* This callback function will be executed if fflag is defined */
143 int (*fflag_handle) (struct mkimage_params *);
Stefano Babicf0662102011-09-15 23:50:16 +0000144 /*
145 * This callback function will be executed for variable size record
146 * It is expected to build this header in memory and return its length
147 * and a pointer to it
148 */
149 int (*vrec_header) (struct mkimage_params *,
150 struct image_type_params *);
Prafulla Wadaskar89a4d6b2009-08-19 17:36:46 +0530151 /* pointer to the next registered entry in linked list */
152 struct image_type_params *next;
153};
154
155/*
156 * Exported functions
157 */
158void mkimage_register (struct image_type_params *tparams);
159
160/*
161 * There is a c file associated with supported image type low level code
162 * for ex. default_image.c, fit_image.c
163 * init is the only function referred by mkimage core.
164 * to avoid a single lined header file, you can define them here
165 *
166 * Supported image types init functions
167 */
Shaohui Xie5d898a02012-08-10 02:49:35 +0000168void pbl_load_uboot(int fd, struct mkimage_params *mparams);
169void init_pbl_image_type(void);
Stefano Babic4962e382011-10-17 00:07:43 +0000170void init_ais_image_type(void);
Prafulla Wadaskaraa0c7a82009-09-07 15:05:02 +0530171void init_kwb_image_type (void);
Stefano Babic8edcde52010-01-20 18:19:10 +0100172void init_imx_image_type (void);
Prafulla Wadaskar89a4d6b2009-08-19 17:36:46 +0530173void init_default_image_type (void);
174void init_fit_image_type (void);
Heiko Schocher7816f2c2011-07-16 00:06:42 +0000175void init_ubl_image_type(void);
John Rigby3decb142011-07-21 09:10:30 -0400176void init_omap_image_type(void);
Prafulla Wadaskar89a4d6b2009-08-19 17:36:46 +0530177
178#endif /* _MKIIMAGE_H_ */