]> git.ipfire.org Git - thirdparty/u-boot.git/blame - include/image.h
[new uImage] Add gen_get_image() routine
[thirdparty/u-boot.git] / include / image.h
CommitLineData
5b1d7137 1/*
b97a2a0a
MB
2 * (C) Copyright 2008 Semihalf
3 *
f08abe31 4 * (C) Copyright 2000-2005
5b1d7137
WD
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
f08abe31
WD
24 *
25 ********************************************************************
26 * NOTE: This header file defines an interface to U-Boot. Including
27 * this (unmodified) header file in another file is considered normal
28 * use of U-Boot, and does *not* fall under the heading of "derived
29 * work".
30 ********************************************************************
5b1d7137
WD
31 */
32
33#ifndef __IMAGE_H__
34#define __IMAGE_H__
35
b97a2a0a 36#include <asm/byteorder.h>
5ad03eb3 37#include <command.h>
75d3e8fb 38
b97a2a0a
MB
39#ifndef USE_HOSTCC
40#include <linux/string.h>
ceaed2b1 41#include <asm/u-boot.h>
75d3e8fb
MB
42
43/* new uImage format support enabled by default */
44#define CONFIG_FIT 1
45#define CONFIG_OF_LIBFDT 1
46
47#if defined(CONFIG_FIT) && !defined(CONFIG_OF_LIBFDT)
48#error "CONFIG_OF_LIBFDT not enabled, required by CONFIG_FIT!"
b97a2a0a 49#endif
75d3e8fb 50#endif /* USE_HOSTCC */
b97a2a0a 51
5b1d7137
WD
52/*
53 * Operating System Codes
54 */
55#define IH_OS_INVALID 0 /* Invalid OS */
56#define IH_OS_OPENBSD 1 /* OpenBSD */
57#define IH_OS_NETBSD 2 /* NetBSD */
58#define IH_OS_FREEBSD 3 /* FreeBSD */
59#define IH_OS_4_4BSD 4 /* 4.4BSD */
60#define IH_OS_LINUX 5 /* Linux */
61#define IH_OS_SVR4 6 /* SVR4 */
62#define IH_OS_ESIX 7 /* Esix */
63#define IH_OS_SOLARIS 8 /* Solaris */
64#define IH_OS_IRIX 9 /* Irix */
65#define IH_OS_SCO 10 /* SCO */
66#define IH_OS_DELL 11 /* Dell */
67#define IH_OS_NCR 12 /* NCR */
68#define IH_OS_LYNXOS 13 /* LynxOS */
69#define IH_OS_VXWORKS 14 /* VxWorks */
70#define IH_OS_PSOS 15 /* pSOS */
71#define IH_OS_QNX 16 /* QNX */
72#define IH_OS_U_BOOT 17 /* Firmware */
d791b1dc 73#define IH_OS_RTEMS 18 /* RTEMS */
7f70e853 74#define IH_OS_ARTOS 19 /* ARTOS */
27b207fd 75#define IH_OS_UNITY 20 /* Unity OS */
5b1d7137
WD
76
77/*
78 * CPU Architecture Codes (supported by Linux)
79 */
b97a2a0a
MB
80#define IH_ARCH_INVALID 0 /* Invalid CPU */
81#define IH_ARCH_ALPHA 1 /* Alpha */
82#define IH_ARCH_ARM 2 /* ARM */
83#define IH_ARCH_I386 3 /* Intel x86 */
84#define IH_ARCH_IA64 4 /* IA64 */
85#define IH_ARCH_MIPS 5 /* MIPS */
86#define IH_ARCH_MIPS64 6 /* MIPS 64 Bit */
87#define IH_ARCH_PPC 7 /* PowerPC */
88#define IH_ARCH_S390 8 /* IBM S390 */
89#define IH_ARCH_SH 9 /* SuperH */
90#define IH_ARCH_SPARC 10 /* Sparc */
91#define IH_ARCH_SPARC64 11 /* Sparc 64 Bit */
92#define IH_ARCH_M68K 12 /* M68K */
93#define IH_ARCH_NIOS 13 /* Nios-32 */
94#define IH_ARCH_MICROBLAZE 14 /* MicroBlaze */
95#define IH_ARCH_NIOS2 15 /* Nios-II */
96#define IH_ARCH_BLACKFIN 16 /* Blackfin */
97#define IH_ARCH_AVR32 17 /* AVR32 */
98#define IH_ARCH_ST200 18 /* STMicroelectronics ST200 */
5b1d7137
WD
99
100/*
101 * Image Types
102 *
103 * "Standalone Programs" are directly runnable in the environment
104 * provided by U-Boot; it is expected that (if they behave
105 * well) you can continue to work in U-Boot after return from
106 * the Standalone Program.
107 * "OS Kernel Images" are usually images of some Embedded OS which
108 * will take over control completely. Usually these programs
109 * will install their own set of exception handlers, device
110 * drivers, set up the MMU, etc. - this means, that you cannot
111 * expect to re-enter U-Boot except by resetting the CPU.
112 * "RAMDisk Images" are more or less just data blocks, and their
113 * parameters (address, size) are passed to an OS kernel that is
114 * being started.
115 * "Multi-File Images" contain several images, typically an OS
116 * (Linux) kernel image and one or more data images like
117 * RAMDisks. This construct is useful for instance when you want
118 * to boot over the network using BOOTP etc., where the boot
119 * server provides just a single image file, but you want to get
120 * for instance an OS kernel and a RAMDisk image.
121 *
122 * "Multi-File Images" start with a list of image sizes, each
123 * image size (in bytes) specified by an "uint32_t" in network
124 * byte order. This list is terminated by an "(uint32_t)0".
125 * Immediately after the terminating 0 follow the images, one by
126 * one, all aligned on "uint32_t" boundaries (size rounded up to
e1599e83 127 * a multiple of 4 bytes - except for the last file).
5b1d7137
WD
128 *
129 * "Firmware Images" are binary images containing firmware (like
130 * U-Boot or FPGA images) which usually will be programmed to
131 * flash memory.
132 *
133 * "Script files" are command sequences that will be executed by
134 * U-Boot's command interpreter; this feature is especially
135 * useful when you configure U-Boot to use a real shell (hush)
27b207fd 136 * as command interpreter (=> Shell Scripts).
5b1d7137
WD
137 */
138
139#define IH_TYPE_INVALID 0 /* Invalid Image */
140#define IH_TYPE_STANDALONE 1 /* Standalone Program */
141#define IH_TYPE_KERNEL 2 /* OS Kernel Image */
142#define IH_TYPE_RAMDISK 3 /* RAMDisk Image */
143#define IH_TYPE_MULTI 4 /* Multi-File Image */
144#define IH_TYPE_FIRMWARE 5 /* Firmware Image */
145#define IH_TYPE_SCRIPT 6 /* Script file */
fbe4b5cb 146#define IH_TYPE_FILESYSTEM 7 /* Filesystem Image (any type) */
25c751e9 147#define IH_TYPE_FLATDT 8 /* Binary Flat Device Tree Blob */
5b1d7137
WD
148
149/*
150 * Compression Types
151 */
152#define IH_COMP_NONE 0 /* No Compression Used */
153#define IH_COMP_GZIP 1 /* gzip Compression Used */
154#define IH_COMP_BZIP2 2 /* bzip2 Compression Used */
155
156#define IH_MAGIC 0x27051956 /* Image Magic Number */
157#define IH_NMLEN 32 /* Image Name Length */
158
5b1d7137
WD
159/*
160 * all data in network byte order (aka natural aka bigendian)
161 */
162
163typedef struct image_header {
164 uint32_t ih_magic; /* Image Header Magic Number */
165 uint32_t ih_hcrc; /* Image Header CRC Checksum */
166 uint32_t ih_time; /* Image Creation Timestamp */
167 uint32_t ih_size; /* Image Data Size */
168 uint32_t ih_load; /* Data Load Address */
169 uint32_t ih_ep; /* Entry Point Address */
170 uint32_t ih_dcrc; /* Image Data CRC Checksum */
171 uint8_t ih_os; /* Operating System */
172 uint8_t ih_arch; /* CPU architecture */
173 uint8_t ih_type; /* Image Type */
174 uint8_t ih_comp; /* Compression Type */
175 uint8_t ih_name[IH_NMLEN]; /* Image Name */
176} image_header_t;
177
559316fa
MB
178/*
179 * Some systems (for example LWMON) have very short watchdog periods;
180 * we must make sure to split long operations like memmove() or
181 * crc32() into reasonable chunks.
182 */
183#define CHUNKSZ (64 * 1024)
184
b97a2a0a
MB
185#define image_to_cpu(x) ntohl(x)
186#define cpu_to_image(x) htonl(x)
187
188static inline uint32_t image_get_header_size (void)
189{
190 return (sizeof (image_header_t));
191}
192
193#define image_get_hdr_l(f) \
194 static inline uint32_t image_get_##f(image_header_t *hdr) \
195 { \
196 return image_to_cpu (hdr->ih_##f); \
197 }
198image_get_hdr_l (magic);
199image_get_hdr_l (hcrc);
200image_get_hdr_l (time);
201image_get_hdr_l (size);
202image_get_hdr_l (load);
203image_get_hdr_l (ep);
204image_get_hdr_l (dcrc);
205
206#define image_get_hdr_b(f) \
207 static inline uint8_t image_get_##f(image_header_t *hdr) \
208 { \
209 return hdr->ih_##f; \
210 }
211image_get_hdr_b (os);
212image_get_hdr_b (arch);
213image_get_hdr_b (type);
214image_get_hdr_b (comp);
215
216static inline char *image_get_name (image_header_t *hdr)
217{
218 return (char *)hdr->ih_name;
219}
220
221static inline uint32_t image_get_data_size (image_header_t *hdr)
222{
223 return image_get_size (hdr);
224}
f13e7b2e
MB
225
226/**
227 * image_get_data - get image payload start address
228 * @hdr: image header
229 *
230 * image_get_data() returns address of the image payload. For single
231 * component images it is image data start. For multi component
232 * images it points to the null terminated table of sub-images sizes.
233 *
234 * returns:
235 * image payload data start address
236 */
237static inline ulong image_get_data (image_header_t *hdr)
238{
239 return ((ulong)hdr + image_get_header_size ());
240}
241
b97a2a0a
MB
242static inline uint32_t image_get_image_size (image_header_t *hdr)
243{
244 return (image_get_size (hdr) + image_get_header_size ());
245}
f13e7b2e 246static inline ulong image_get_image_end (image_header_t *hdr)
b97a2a0a 247{
f13e7b2e 248 return ((ulong)hdr + image_get_image_size (hdr));
b97a2a0a
MB
249}
250
251#define image_set_hdr_l(f) \
252 static inline void image_set_##f(image_header_t *hdr, uint32_t val) \
253 { \
254 hdr->ih_##f = cpu_to_image (val); \
255 }
256image_set_hdr_l (magic);
257image_set_hdr_l (hcrc);
258image_set_hdr_l (time);
259image_set_hdr_l (size);
260image_set_hdr_l (load);
261image_set_hdr_l (ep);
262image_set_hdr_l (dcrc);
263
264#define image_set_hdr_b(f) \
265 static inline void image_set_##f(image_header_t *hdr, uint8_t val) \
266 { \
267 hdr->ih_##f = val; \
268 }
269image_set_hdr_b (os);
270image_set_hdr_b (arch);
271image_set_hdr_b (type);
272image_set_hdr_b (comp);
273
274static inline void image_set_name (image_header_t *hdr, const char *name)
275{
276 strncpy (image_get_name (hdr), name, IH_NMLEN);
277}
278
279int image_check_hcrc (image_header_t *hdr);
280int image_check_dcrc (image_header_t *hdr);
af13cdbc 281#ifndef USE_HOSTCC
b97a2a0a
MB
282int image_check_dcrc_wd (image_header_t *hdr, ulong chunksize);
283int getenv_verify (void);
af13cdbc
MB
284void memmove_wd (void *to, void *from, size_t len, ulong chunksz);
285#endif
b97a2a0a
MB
286
287static inline int image_check_magic (image_header_t *hdr)
288{
289 return (image_get_magic (hdr) == IH_MAGIC);
290}
291static inline int image_check_type (image_header_t *hdr, uint8_t type)
292{
293 return (image_get_type (hdr) == type);
294}
295static inline int image_check_arch (image_header_t *hdr, uint8_t arch)
296{
297 return (image_get_arch (hdr) == arch);
298}
299static inline int image_check_os (image_header_t *hdr, uint8_t os)
300{
301 return (image_get_os (hdr) == os);
302}
303
42b73e8e
MB
304ulong image_multi_count (image_header_t *hdr);
305void image_multi_getimg (image_header_t *hdr, ulong idx,
306 ulong *data, ulong *len);
307
b97a2a0a
MB
308#ifndef USE_HOSTCC
309static inline int image_check_target_arch (image_header_t *hdr)
310{
311#if defined(__ARM__)
312 if (!image_check_arch (hdr, IH_ARCH_ARM))
313#elif defined(__avr32__)
314 if (!image_check_arch (hdr, IH_ARCH_AVR32))
315#elif defined(__bfin__)
316 if (!image_check_arch (hdr, IH_ARCH_BLACKFIN))
317#elif defined(__I386__)
318 if (!image_check_arch (hdr, IH_ARCH_I386))
319#elif defined(__M68K__)
320 if (!image_check_arch (hdr, IH_ARCH_M68K))
321#elif defined(__microblaze__)
322 if (!image_check_arch (hdr, IH_ARCH_MICROBLAZE))
323#elif defined(__mips__)
324 if (!image_check_arch (hdr, IH_ARCH_MIPS))
325#elif defined(__nios__)
326 if (!image_check_arch (hdr, IH_ARCH_NIOS))
327#elif defined(__nios2__)
328 if (!image_check_arch (hdr, IH_ARCH_NIOS2))
329#elif defined(__PPC__)
330 if (!image_check_arch (hdr, IH_ARCH_PPC))
331#elif defined(__sh__)
332 if (!image_check_arch (hdr, IH_ARCH_SH))
333#else
334# error Unknown CPU type
335#endif
336 return 0;
337
338 return 1;
339}
5b1d7137 340
42b73e8e
MB
341const char* image_get_os_name (uint8_t os);
342const char* image_get_arch_name (uint8_t arch);
343const char* image_get_type_name (uint8_t type);
344const char* image_get_comp_name (uint8_t comp);
5ad03eb3 345
fff888a1
MB
346#define IMAGE_FORMAT_INVALID 0x00
347#define IMAGE_FORMAT_LEGACY 0x01
348#define IMAGE_FORMAT_FIT 0x02
349int gen_image_get_format (void *img_addr);
350ulong gen_get_image (ulong img_addr);
351
5ad03eb3
MB
352image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag,
353 int argc, char *argv[],
354 ulong rd_addr, uint8_t arch, int verify);
355
356void get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
357 image_header_t *hdr, int verify, uint8_t arch,
358 ulong *rd_start, ulong *rd_end);
f13e7b2e 359
ceaed2b1 360#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
b6b0fe64
MB
361ulong ramdisk_high (ulong alloc_current, ulong rd_data, ulong rd_len,
362 bd_t *kbd, ulong sp_limit, ulong sp,
363 ulong *initrd_start, ulong *initrd_end);
364
365ulong get_boot_sp_limit (ulong sp);
366ulong get_boot_cmdline (ulong alloc_current, ulong *cmd_start, ulong *cmd_end);
367ulong get_boot_kbd (ulong alloc_current, bd_t **kbd);
ceaed2b1 368#endif /* CONFIG_PPC || CONFIG_M68K */
b6b0fe64 369
ceaed2b1 370#endif /* USE_HOSTCC */
5ad03eb3 371
f13e7b2e 372#endif /* __IMAGE_H__ */