]> Git Repo - J-u-boot.git/blame - include/image.h
Merge branch 'master' of git://www.denx.de/git/u-boot into new-image
[J-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, [email protected].
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 39#ifndef USE_HOSTCC
4ed6552f 40#include <lmb.h>
b97a2a0a 41#include <linux/string.h>
ceaed2b1 42#include <asm/u-boot.h>
75d3e8fb
MB
43
44/* new uImage format support enabled by default */
45#define CONFIG_FIT 1
46#define CONFIG_OF_LIBFDT 1
47
d5934ad7
MB
48/* enable fit_format_error(), fit_format_warning() */
49#define CONFIG_FIT_VERBOSE 1
50
75d3e8fb
MB
51#if defined(CONFIG_FIT) && !defined(CONFIG_OF_LIBFDT)
52#error "CONFIG_OF_LIBFDT not enabled, required by CONFIG_FIT!"
b97a2a0a 53#endif
75d3e8fb 54#endif /* USE_HOSTCC */
b97a2a0a 55
5b1d7137
WD
56/*
57 * Operating System Codes
58 */
59#define IH_OS_INVALID 0 /* Invalid OS */
60#define IH_OS_OPENBSD 1 /* OpenBSD */
61#define IH_OS_NETBSD 2 /* NetBSD */
62#define IH_OS_FREEBSD 3 /* FreeBSD */
63#define IH_OS_4_4BSD 4 /* 4.4BSD */
64#define IH_OS_LINUX 5 /* Linux */
65#define IH_OS_SVR4 6 /* SVR4 */
66#define IH_OS_ESIX 7 /* Esix */
67#define IH_OS_SOLARIS 8 /* Solaris */
68#define IH_OS_IRIX 9 /* Irix */
69#define IH_OS_SCO 10 /* SCO */
70#define IH_OS_DELL 11 /* Dell */
71#define IH_OS_NCR 12 /* NCR */
72#define IH_OS_LYNXOS 13 /* LynxOS */
73#define IH_OS_VXWORKS 14 /* VxWorks */
74#define IH_OS_PSOS 15 /* pSOS */
75#define IH_OS_QNX 16 /* QNX */
76#define IH_OS_U_BOOT 17 /* Firmware */
d791b1dc 77#define IH_OS_RTEMS 18 /* RTEMS */
7f70e853 78#define IH_OS_ARTOS 19 /* ARTOS */
27b207fd 79#define IH_OS_UNITY 20 /* Unity OS */
5b1d7137
WD
80
81/*
82 * CPU Architecture Codes (supported by Linux)
83 */
b97a2a0a
MB
84#define IH_ARCH_INVALID 0 /* Invalid CPU */
85#define IH_ARCH_ALPHA 1 /* Alpha */
86#define IH_ARCH_ARM 2 /* ARM */
87#define IH_ARCH_I386 3 /* Intel x86 */
88#define IH_ARCH_IA64 4 /* IA64 */
89#define IH_ARCH_MIPS 5 /* MIPS */
90#define IH_ARCH_MIPS64 6 /* MIPS 64 Bit */
91#define IH_ARCH_PPC 7 /* PowerPC */
92#define IH_ARCH_S390 8 /* IBM S390 */
93#define IH_ARCH_SH 9 /* SuperH */
94#define IH_ARCH_SPARC 10 /* Sparc */
95#define IH_ARCH_SPARC64 11 /* Sparc 64 Bit */
96#define IH_ARCH_M68K 12 /* M68K */
97#define IH_ARCH_NIOS 13 /* Nios-32 */
98#define IH_ARCH_MICROBLAZE 14 /* MicroBlaze */
99#define IH_ARCH_NIOS2 15 /* Nios-II */
100#define IH_ARCH_BLACKFIN 16 /* Blackfin */
101#define IH_ARCH_AVR32 17 /* AVR32 */
102#define IH_ARCH_ST200 18 /* STMicroelectronics ST200 */
5b1d7137
WD
103
104/*
105 * Image Types
106 *
107 * "Standalone Programs" are directly runnable in the environment
108 * provided by U-Boot; it is expected that (if they behave
109 * well) you can continue to work in U-Boot after return from
110 * the Standalone Program.
111 * "OS Kernel Images" are usually images of some Embedded OS which
112 * will take over control completely. Usually these programs
113 * will install their own set of exception handlers, device
114 * drivers, set up the MMU, etc. - this means, that you cannot
115 * expect to re-enter U-Boot except by resetting the CPU.
116 * "RAMDisk Images" are more or less just data blocks, and their
117 * parameters (address, size) are passed to an OS kernel that is
118 * being started.
119 * "Multi-File Images" contain several images, typically an OS
120 * (Linux) kernel image and one or more data images like
121 * RAMDisks. This construct is useful for instance when you want
122 * to boot over the network using BOOTP etc., where the boot
123 * server provides just a single image file, but you want to get
124 * for instance an OS kernel and a RAMDisk image.
125 *
126 * "Multi-File Images" start with a list of image sizes, each
127 * image size (in bytes) specified by an "uint32_t" in network
128 * byte order. This list is terminated by an "(uint32_t)0".
129 * Immediately after the terminating 0 follow the images, one by
130 * one, all aligned on "uint32_t" boundaries (size rounded up to
e1599e83 131 * a multiple of 4 bytes - except for the last file).
5b1d7137
WD
132 *
133 * "Firmware Images" are binary images containing firmware (like
134 * U-Boot or FPGA images) which usually will be programmed to
135 * flash memory.
136 *
137 * "Script files" are command sequences that will be executed by
138 * U-Boot's command interpreter; this feature is especially
139 * useful when you configure U-Boot to use a real shell (hush)
27b207fd 140 * as command interpreter (=> Shell Scripts).
5b1d7137
WD
141 */
142
143#define IH_TYPE_INVALID 0 /* Invalid Image */
144#define IH_TYPE_STANDALONE 1 /* Standalone Program */
145#define IH_TYPE_KERNEL 2 /* OS Kernel Image */
146#define IH_TYPE_RAMDISK 3 /* RAMDisk Image */
147#define IH_TYPE_MULTI 4 /* Multi-File Image */
148#define IH_TYPE_FIRMWARE 5 /* Firmware Image */
149#define IH_TYPE_SCRIPT 6 /* Script file */
fbe4b5cb 150#define IH_TYPE_FILESYSTEM 7 /* Filesystem Image (any type) */
25c751e9 151#define IH_TYPE_FLATDT 8 /* Binary Flat Device Tree Blob */
5b1d7137
WD
152
153/*
154 * Compression Types
155 */
156#define IH_COMP_NONE 0 /* No Compression Used */
157#define IH_COMP_GZIP 1 /* gzip Compression Used */
158#define IH_COMP_BZIP2 2 /* bzip2 Compression Used */
159
160#define IH_MAGIC 0x27051956 /* Image Magic Number */
161#define IH_NMLEN 32 /* Image Name Length */
162
5b1d7137
WD
163/*
164 * all data in network byte order (aka natural aka bigendian)
165 */
166
167typedef struct image_header {
168 uint32_t ih_magic; /* Image Header Magic Number */
169 uint32_t ih_hcrc; /* Image Header CRC Checksum */
170 uint32_t ih_time; /* Image Creation Timestamp */
171 uint32_t ih_size; /* Image Data Size */
172 uint32_t ih_load; /* Data Load Address */
173 uint32_t ih_ep; /* Entry Point Address */
174 uint32_t ih_dcrc; /* Image Data CRC Checksum */
175 uint8_t ih_os; /* Operating System */
176 uint8_t ih_arch; /* CPU architecture */
177 uint8_t ih_type; /* Image Type */
178 uint8_t ih_comp; /* Compression Type */
179 uint8_t ih_name[IH_NMLEN]; /* Image Name */
180} image_header_t;
181
d5934ad7
MB
182/*
183 * Legacy and FIT format headers used by do_bootm() and do_bootm_<os>()
184 * routines.
185 */
186typedef struct bootm_headers {
187 /*
188 * Legacy os image header, if it is a multi component image
189 * then get_ramdisk() and get_fdt() will attempt to get
190 * data from second and third component accordingly.
191 */
192 image_header_t *legacy_hdr_os;
193 ulong legacy_hdr_valid;
194
195#if defined(CONFIG_FIT)
196 void *fit_hdr_os; /* os FIT image header */
197 char *fit_uname_os; /* os subimage node unit name */
198
199 void *fit_hdr_rd; /* init ramdisk FIT image header */
200 char *fit_uname_rd; /* init ramdisk node unit name */
201
202#if defined(CONFIG_PPC)
203 void *fit_hdr_fdt; /* FDT blob FIT image header */
204 char *fit_uname_fdt; /* FDT blob node unit name */
205#endif
8a5ea3e6 206 int verify; /* getenv("verify")[0] != 'n' */
f5614e79 207 int autostart; /* getenv("autostart")[0] != 'n' */
4ed6552f 208 struct lmb *lmb; /* for memory mgmt */
d5934ad7
MB
209#endif
210} bootm_headers_t;
211
559316fa
MB
212/*
213 * Some systems (for example LWMON) have very short watchdog periods;
214 * we must make sure to split long operations like memmove() or
215 * crc32() into reasonable chunks.
216 */
217#define CHUNKSZ (64 * 1024)
218
b97a2a0a
MB
219#define image_to_cpu(x) ntohl(x)
220#define cpu_to_image(x) htonl(x)
221
222static inline uint32_t image_get_header_size (void)
223{
224 return (sizeof (image_header_t));
225}
226
227#define image_get_hdr_l(f) \
228 static inline uint32_t image_get_##f(image_header_t *hdr) \
229 { \
230 return image_to_cpu (hdr->ih_##f); \
231 }
232image_get_hdr_l (magic);
233image_get_hdr_l (hcrc);
234image_get_hdr_l (time);
235image_get_hdr_l (size);
236image_get_hdr_l (load);
237image_get_hdr_l (ep);
238image_get_hdr_l (dcrc);
239
240#define image_get_hdr_b(f) \
241 static inline uint8_t image_get_##f(image_header_t *hdr) \
242 { \
243 return hdr->ih_##f; \
244 }
245image_get_hdr_b (os);
246image_get_hdr_b (arch);
247image_get_hdr_b (type);
248image_get_hdr_b (comp);
249
250static inline char *image_get_name (image_header_t *hdr)
251{
252 return (char *)hdr->ih_name;
253}
254
255static inline uint32_t image_get_data_size (image_header_t *hdr)
256{
257 return image_get_size (hdr);
258}
f13e7b2e
MB
259
260/**
261 * image_get_data - get image payload start address
262 * @hdr: image header
263 *
264 * image_get_data() returns address of the image payload. For single
265 * component images it is image data start. For multi component
266 * images it points to the null terminated table of sub-images sizes.
267 *
268 * returns:
269 * image payload data start address
270 */
271static inline ulong image_get_data (image_header_t *hdr)
272{
273 return ((ulong)hdr + image_get_header_size ());
274}
275
b97a2a0a
MB
276static inline uint32_t image_get_image_size (image_header_t *hdr)
277{
278 return (image_get_size (hdr) + image_get_header_size ());
279}
f13e7b2e 280static inline ulong image_get_image_end (image_header_t *hdr)
b97a2a0a 281{
f13e7b2e 282 return ((ulong)hdr + image_get_image_size (hdr));
b97a2a0a
MB
283}
284
285#define image_set_hdr_l(f) \
286 static inline void image_set_##f(image_header_t *hdr, uint32_t val) \
287 { \
288 hdr->ih_##f = cpu_to_image (val); \
289 }
290image_set_hdr_l (magic);
291image_set_hdr_l (hcrc);
292image_set_hdr_l (time);
293image_set_hdr_l (size);
294image_set_hdr_l (load);
295image_set_hdr_l (ep);
296image_set_hdr_l (dcrc);
297
298#define image_set_hdr_b(f) \
299 static inline void image_set_##f(image_header_t *hdr, uint8_t val) \
300 { \
301 hdr->ih_##f = val; \
302 }
303image_set_hdr_b (os);
304image_set_hdr_b (arch);
305image_set_hdr_b (type);
306image_set_hdr_b (comp);
307
308static inline void image_set_name (image_header_t *hdr, const char *name)
309{
310 strncpy (image_get_name (hdr), name, IH_NMLEN);
311}
312
313int image_check_hcrc (image_header_t *hdr);
314int image_check_dcrc (image_header_t *hdr);
af13cdbc 315#ifndef USE_HOSTCC
b97a2a0a
MB
316int image_check_dcrc_wd (image_header_t *hdr, ulong chunksize);
317int getenv_verify (void);
f5614e79 318int getenv_autostart (void);
d3f2fa0d
KG
319ulong getenv_bootm_low(void);
320ulong getenv_bootm_size(void);
af13cdbc
MB
321void memmove_wd (void *to, void *from, size_t len, ulong chunksz);
322#endif
b97a2a0a
MB
323
324static inline int image_check_magic (image_header_t *hdr)
325{
326 return (image_get_magic (hdr) == IH_MAGIC);
327}
328static inline int image_check_type (image_header_t *hdr, uint8_t type)
329{
330 return (image_get_type (hdr) == type);
331}
332static inline int image_check_arch (image_header_t *hdr, uint8_t arch)
333{
334 return (image_get_arch (hdr) == arch);
335}
336static inline int image_check_os (image_header_t *hdr, uint8_t os)
337{
338 return (image_get_os (hdr) == os);
339}
340
42b73e8e
MB
341ulong image_multi_count (image_header_t *hdr);
342void image_multi_getimg (image_header_t *hdr, ulong idx,
343 ulong *data, ulong *len);
344
b97a2a0a
MB
345#ifndef USE_HOSTCC
346static inline int image_check_target_arch (image_header_t *hdr)
347{
348#if defined(__ARM__)
349 if (!image_check_arch (hdr, IH_ARCH_ARM))
350#elif defined(__avr32__)
351 if (!image_check_arch (hdr, IH_ARCH_AVR32))
352#elif defined(__bfin__)
353 if (!image_check_arch (hdr, IH_ARCH_BLACKFIN))
354#elif defined(__I386__)
355 if (!image_check_arch (hdr, IH_ARCH_I386))
356#elif defined(__M68K__)
357 if (!image_check_arch (hdr, IH_ARCH_M68K))
358#elif defined(__microblaze__)
359 if (!image_check_arch (hdr, IH_ARCH_MICROBLAZE))
360#elif defined(__mips__)
361 if (!image_check_arch (hdr, IH_ARCH_MIPS))
362#elif defined(__nios__)
363 if (!image_check_arch (hdr, IH_ARCH_NIOS))
364#elif defined(__nios2__)
365 if (!image_check_arch (hdr, IH_ARCH_NIOS2))
366#elif defined(__PPC__)
367 if (!image_check_arch (hdr, IH_ARCH_PPC))
368#elif defined(__sh__)
369 if (!image_check_arch (hdr, IH_ARCH_SH))
370#else
371# error Unknown CPU type
372#endif
373 return 0;
374
375 return 1;
376}
5b1d7137 377
42b73e8e
MB
378const char* image_get_os_name (uint8_t os);
379const char* image_get_arch_name (uint8_t arch);
380const char* image_get_type_name (uint8_t type);
381const char* image_get_comp_name (uint8_t comp);
2242f536 382void image_print_contents (image_header_t *hdr);
5ad03eb3 383
fff888a1 384#define IMAGE_FORMAT_INVALID 0x00
4efbe9db
MB
385#define IMAGE_FORMAT_LEGACY 0x01 /* legacy image_header based format */
386#define IMAGE_FORMAT_FIT 0x02 /* new, libfdt based format */
387
fff888a1
MB
388int gen_image_get_format (void *img_addr);
389ulong gen_get_image (ulong img_addr);
390
274cea2b 391int get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
8a5ea3e6 392 bootm_headers_t *images, uint8_t arch,
5ad03eb3 393 ulong *rd_start, ulong *rd_end);
f13e7b2e 394
ceaed2b1 395#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
e822d7fc
KG
396int ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len,
397 ulong *initrd_start, ulong *initrd_end);
398int get_boot_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end,
399 ulong bootmap_base);
400int get_boot_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base);
ceaed2b1 401#endif /* CONFIG_PPC || CONFIG_M68K */
b6b0fe64 402
d5934ad7
MB
403/*******************************************************************/
404/* New uImage format */
405/*******************************************************************/
f50433d6 406#if defined(CONFIG_FIT)
f50433d6
MB
407inline int fit_parse_conf (const char *spec, ulong addr_curr,
408 ulong *addr, const char **conf_name);
409inline int fit_parse_subimage (const char *spec, ulong addr_curr,
410 ulong *addr, const char **image_name);
d5934ad7
MB
411
412#ifdef CONFIG_FIT_VERBOSE
413#define fit_unsupported(msg) printf ("! %s:%d " \
414 "FIT images not supported for '%s'\n", \
415 __FILE__, __LINE__, (msg))
416
417#define fit_unsupported_reset(msg) printf ("! %s:%d " \
418 "FIT images not supported for '%s' " \
419 "- must reset board to recover!\n", \
420 __FILE__, __LINE__, (msg))
421#else
422#define fit_unsupported(msg)
423#define fit_unsupported_reset(msg)
424#endif /* CONFIG_FIT_VERBOSE */
425
f50433d6
MB
426#endif /* CONFIG_FIT */
427
ceaed2b1 428#endif /* USE_HOSTCC */
5ad03eb3 429
f13e7b2e 430#endif /* __IMAGE_H__ */
This page took 0.179417 seconds and 4 git commands to generate.