]> git.ipfire.org Git - people/ms/u-boot.git/blame - tools/mkimage.h
patman: README documentation nits (unit test)
[people/ms/u-boot.git] / tools / mkimage.h
CommitLineData
b97a2a0a
MB
1/*
2 * (C) Copyright 2000-2004
3 * DENX Software Engineering
4 * Wolfgang Denk, wd@denx.de
b97a2a0a
MB
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
89a4d6b1
PW
22#ifndef _MKIIMAGE_H_
23#define _MKIIMAGE_H_
24
2f8d396b 25#include "os_support.h"
b97a2a0a
MB
26#include <errno.h>
27#include <fcntl.h>
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
b97a2a0a
MB
31#include <sys/stat.h>
32#include <time.h>
33#include <unistd.h>
a6e530f0 34#include <sha1.h>
8cf30809 35#include "fdt_host.h"
b97a2a0a 36
89a4d6b1 37#undef MKIMAGE_DEBUG
5dfb5213
MB
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
816cb037
SG
45#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
46
2434c66d
SG
47static 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
9d25438f
BS
57#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 */
89a4d6b1 62
2434c66d
SG
63#define IH_ARCH_DEFAULT IH_ARCH_INVALID
64
89a4d6b1
PW
65/*
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;
f0662105 77 int skipcpy;
89a4d6b1
PW
78 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;
5d898a00 86 char *imagename2;
89a4d6b1
PW
87 char *datafile;
88 char *imagefile;
89 char *cmdname;
80e4df8a 90 const char *keydir; /* Directory holding private keys */
e29495d3 91 const char *keydest; /* Destination .dtb for public key */
4f610427 92 const char *comment; /* Comment to add to signature node */
399c744b 93 int require_keys; /* 1 to mark signing keys as 'required' */
89a4d6b1
PW
94};
95
96/*
97 * image type specific variables and callback functions
98 */
99struct image_type_params {
100 /* name is an identification tag string for added support */
101 char *name;
102 /*
103 * header size is local to the specific image type to be supported,
104 * mkimage core treats this as number of bytes
105 */
106 uint32_t header_size;
107 /* Image type header pointer */
108 void *hdr;
109 /*
110 * There are several arguments that are passed on the command line
111 * and are registered as flags in mkimage_params structure.
112 * This callback function can be used to check the passed arguments
113 * are in-lined with the image type to be supported
114 *
115 * Returns 1 if parameter check is successful
116 */
117 int (*check_params) (struct mkimage_params *);
118 /*
119 * This function is used by list command (i.e. mkimage -l <filename>)
120 * image type verification code must be put here
121 *
122 * Returns 0 if image header verification is successful
123 * otherwise, returns respective negative error codes
124 */
125 int (*verify_header) (unsigned char *, int, struct mkimage_params *);
126 /* Prints image information abstracting from image header */
3a2003f6 127 void (*print_header) (const void *);
89a4d6b1
PW
128 /*
129 * The header or image contents need to be set as per image type to
130 * be generated using this callback function.
131 * further output file post processing (for ex. checksum calculation,
132 * padding bytes etc..) can also be done in this callback function.
133 */
134 void (*set_header) (void *, struct stat *, int,
135 struct mkimage_params *);
136 /*
137 * Some image generation support for ex (default image type) supports
138 * more than one type_ids, this callback function is used to check
139 * whether input (-T <image_type>) is supported by registered image
140 * generation/list low level code
141 */
142 int (*check_image_type) (uint8_t);
143 /* This callback function will be executed if fflag is defined */
144 int (*fflag_handle) (struct mkimage_params *);
f0662105
SB
145 /*
146 * This callback function will be executed for variable size record
147 * It is expected to build this header in memory and return its length
148 * and a pointer to it
149 */
150 int (*vrec_header) (struct mkimage_params *,
151 struct image_type_params *);
89a4d6b1
PW
152 /* pointer to the next registered entry in linked list */
153 struct image_type_params *next;
154};
155
156/*
157 * Exported functions
158 */
159void mkimage_register (struct image_type_params *tparams);
160
161/*
162 * There is a c file associated with supported image type low level code
163 * for ex. default_image.c, fit_image.c
164 * init is the only function referred by mkimage core.
165 * to avoid a single lined header file, you can define them here
166 *
167 * Supported image types init functions
168 */
5d898a00
SX
169void pbl_load_uboot(int fd, struct mkimage_params *mparams);
170void init_pbl_image_type(void);
4962e38e 171void init_ais_image_type(void);
aa0c7a86 172void init_kwb_image_type (void);
8edcde5e 173void init_imx_image_type (void);
89a4d6b1
PW
174void init_default_image_type (void);
175void init_fit_image_type (void);
7816f2cf 176void init_ubl_image_type(void);
3decb14a 177void init_omap_image_type(void);
89a4d6b1
PW
178
179#endif /* _MKIIMAGE_H_ */