blob: 2f4b67d445314f633219502656b1828f090da83b [file] [log] [blame]
wdenk5b1d7132002-11-03 00:07:02 +00001/*
Marian Balakowiczb97a2a02008-01-08 18:14:09 +01002 * (C) Copyright 2008 Semihalf
3 *
Wolfgang Denkf08abe32005-11-25 16:38:03 +01004 * (C) Copyright 2000-2005
wdenk5b1d7132002-11-03 00:07:02 +00005 * 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
Wolfgang Denkf08abe32005-11-25 16:38:03 +010024 *
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 ********************************************************************
wdenk5b1d7132002-11-03 00:07:02 +000031 */
32
33#ifndef __IMAGE_H__
34#define __IMAGE_H__
35
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010036#include <asm/byteorder.h>
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +010037#include <command.h>
Marian Balakowicz75d3e8f2008-02-21 17:20:18 +010038
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010039#ifndef USE_HOSTCC
40#include <linux/string.h>
Marian Balakowiczceaed2b2008-01-31 13:57:17 +010041#include <asm/u-boot.h>
Marian Balakowicz75d3e8f2008-02-21 17:20:18 +010042
43/* new uImage format support enabled by default */
44#define CONFIG_FIT 1
45#define CONFIG_OF_LIBFDT 1
46
Marian Balakowiczd5934ad2008-02-04 08:28:09 +010047/* enable fit_format_error(), fit_format_warning() */
48#define CONFIG_FIT_VERBOSE 1
49
Marian Balakowicz75d3e8f2008-02-21 17:20:18 +010050#if defined(CONFIG_FIT) && !defined(CONFIG_OF_LIBFDT)
51#error "CONFIG_OF_LIBFDT not enabled, required by CONFIG_FIT!"
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010052#endif
Marian Balakowicz75d3e8f2008-02-21 17:20:18 +010053#endif /* USE_HOSTCC */
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010054
wdenk5b1d7132002-11-03 00:07:02 +000055/*
56 * Operating System Codes
57 */
58#define IH_OS_INVALID 0 /* Invalid OS */
59#define IH_OS_OPENBSD 1 /* OpenBSD */
60#define IH_OS_NETBSD 2 /* NetBSD */
61#define IH_OS_FREEBSD 3 /* FreeBSD */
62#define IH_OS_4_4BSD 4 /* 4.4BSD */
63#define IH_OS_LINUX 5 /* Linux */
64#define IH_OS_SVR4 6 /* SVR4 */
65#define IH_OS_ESIX 7 /* Esix */
66#define IH_OS_SOLARIS 8 /* Solaris */
67#define IH_OS_IRIX 9 /* Irix */
68#define IH_OS_SCO 10 /* SCO */
69#define IH_OS_DELL 11 /* Dell */
70#define IH_OS_NCR 12 /* NCR */
71#define IH_OS_LYNXOS 13 /* LynxOS */
72#define IH_OS_VXWORKS 14 /* VxWorks */
73#define IH_OS_PSOS 15 /* pSOS */
74#define IH_OS_QNX 16 /* QNX */
75#define IH_OS_U_BOOT 17 /* Firmware */
wdenkd791b1d2003-04-20 14:04:18 +000076#define IH_OS_RTEMS 18 /* RTEMS */
wdenk7f70e852003-05-20 14:25:27 +000077#define IH_OS_ARTOS 19 /* ARTOS */
wdenk27b207f2003-07-24 23:38:38 +000078#define IH_OS_UNITY 20 /* Unity OS */
wdenk5b1d7132002-11-03 00:07:02 +000079
80/*
81 * CPU Architecture Codes (supported by Linux)
82 */
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010083#define IH_ARCH_INVALID 0 /* Invalid CPU */
84#define IH_ARCH_ALPHA 1 /* Alpha */
85#define IH_ARCH_ARM 2 /* ARM */
86#define IH_ARCH_I386 3 /* Intel x86 */
87#define IH_ARCH_IA64 4 /* IA64 */
88#define IH_ARCH_MIPS 5 /* MIPS */
89#define IH_ARCH_MIPS64 6 /* MIPS 64 Bit */
90#define IH_ARCH_PPC 7 /* PowerPC */
91#define IH_ARCH_S390 8 /* IBM S390 */
92#define IH_ARCH_SH 9 /* SuperH */
93#define IH_ARCH_SPARC 10 /* Sparc */
94#define IH_ARCH_SPARC64 11 /* Sparc 64 Bit */
95#define IH_ARCH_M68K 12 /* M68K */
96#define IH_ARCH_NIOS 13 /* Nios-32 */
97#define IH_ARCH_MICROBLAZE 14 /* MicroBlaze */
98#define IH_ARCH_NIOS2 15 /* Nios-II */
99#define IH_ARCH_BLACKFIN 16 /* Blackfin */
100#define IH_ARCH_AVR32 17 /* AVR32 */
101#define IH_ARCH_ST200 18 /* STMicroelectronics ST200 */
wdenk5b1d7132002-11-03 00:07:02 +0000102
103/*
104 * Image Types
105 *
106 * "Standalone Programs" are directly runnable in the environment
107 * provided by U-Boot; it is expected that (if they behave
108 * well) you can continue to work in U-Boot after return from
109 * the Standalone Program.
110 * "OS Kernel Images" are usually images of some Embedded OS which
111 * will take over control completely. Usually these programs
112 * will install their own set of exception handlers, device
113 * drivers, set up the MMU, etc. - this means, that you cannot
114 * expect to re-enter U-Boot except by resetting the CPU.
115 * "RAMDisk Images" are more or less just data blocks, and their
116 * parameters (address, size) are passed to an OS kernel that is
117 * being started.
118 * "Multi-File Images" contain several images, typically an OS
119 * (Linux) kernel image and one or more data images like
120 * RAMDisks. This construct is useful for instance when you want
121 * to boot over the network using BOOTP etc., where the boot
122 * server provides just a single image file, but you want to get
123 * for instance an OS kernel and a RAMDisk image.
124 *
125 * "Multi-File Images" start with a list of image sizes, each
126 * image size (in bytes) specified by an "uint32_t" in network
127 * byte order. This list is terminated by an "(uint32_t)0".
128 * Immediately after the terminating 0 follow the images, one by
129 * one, all aligned on "uint32_t" boundaries (size rounded up to
wdenke1599e82004-10-10 23:27:33 +0000130 * a multiple of 4 bytes - except for the last file).
wdenk5b1d7132002-11-03 00:07:02 +0000131 *
132 * "Firmware Images" are binary images containing firmware (like
133 * U-Boot or FPGA images) which usually will be programmed to
134 * flash memory.
135 *
136 * "Script files" are command sequences that will be executed by
137 * U-Boot's command interpreter; this feature is especially
138 * useful when you configure U-Boot to use a real shell (hush)
wdenk27b207f2003-07-24 23:38:38 +0000139 * as command interpreter (=> Shell Scripts).
wdenk5b1d7132002-11-03 00:07:02 +0000140 */
141
142#define IH_TYPE_INVALID 0 /* Invalid Image */
143#define IH_TYPE_STANDALONE 1 /* Standalone Program */
144#define IH_TYPE_KERNEL 2 /* OS Kernel Image */
145#define IH_TYPE_RAMDISK 3 /* RAMDisk Image */
146#define IH_TYPE_MULTI 4 /* Multi-File Image */
147#define IH_TYPE_FIRMWARE 5 /* Firmware Image */
148#define IH_TYPE_SCRIPT 6 /* Script file */
wdenkfbe4b5c2003-10-06 21:55:32 +0000149#define IH_TYPE_FILESYSTEM 7 /* Filesystem Image (any type) */
Matthew McClintock25c751e2006-08-16 10:54:09 -0500150#define IH_TYPE_FLATDT 8 /* Binary Flat Device Tree Blob */
wdenk5b1d7132002-11-03 00:07:02 +0000151
152/*
153 * Compression Types
154 */
155#define IH_COMP_NONE 0 /* No Compression Used */
156#define IH_COMP_GZIP 1 /* gzip Compression Used */
157#define IH_COMP_BZIP2 2 /* bzip2 Compression Used */
158
159#define IH_MAGIC 0x27051956 /* Image Magic Number */
160#define IH_NMLEN 32 /* Image Name Length */
161
wdenk5b1d7132002-11-03 00:07:02 +0000162/*
163 * all data in network byte order (aka natural aka bigendian)
164 */
165
166typedef struct image_header {
167 uint32_t ih_magic; /* Image Header Magic Number */
168 uint32_t ih_hcrc; /* Image Header CRC Checksum */
169 uint32_t ih_time; /* Image Creation Timestamp */
170 uint32_t ih_size; /* Image Data Size */
171 uint32_t ih_load; /* Data Load Address */
172 uint32_t ih_ep; /* Entry Point Address */
173 uint32_t ih_dcrc; /* Image Data CRC Checksum */
174 uint8_t ih_os; /* Operating System */
175 uint8_t ih_arch; /* CPU architecture */
176 uint8_t ih_type; /* Image Type */
177 uint8_t ih_comp; /* Compression Type */
178 uint8_t ih_name[IH_NMLEN]; /* Image Name */
179} image_header_t;
180
Marian Balakowicz559316f2008-01-08 18:11:44 +0100181/*
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100182 * Legacy and FIT format headers used by do_bootm() and do_bootm_<os>()
183 * routines.
184 */
185typedef struct bootm_headers {
186 /*
187 * Legacy os image header, if it is a multi component image
188 * then get_ramdisk() and get_fdt() will attempt to get
189 * data from second and third component accordingly.
190 */
191 image_header_t *legacy_hdr_os;
192 ulong legacy_hdr_valid;
193
194#if defined(CONFIG_FIT)
195 void *fit_hdr_os; /* os FIT image header */
196 char *fit_uname_os; /* os subimage node unit name */
197
198 void *fit_hdr_rd; /* init ramdisk FIT image header */
199 char *fit_uname_rd; /* init ramdisk node unit name */
200
201#if defined(CONFIG_PPC)
202 void *fit_hdr_fdt; /* FDT blob FIT image header */
203 char *fit_uname_fdt; /* FDT blob node unit name */
204#endif
205#endif
206} bootm_headers_t;
207
208/*
Marian Balakowicz559316f2008-01-08 18:11:44 +0100209 * Some systems (for example LWMON) have very short watchdog periods;
210 * we must make sure to split long operations like memmove() or
211 * crc32() into reasonable chunks.
212 */
213#define CHUNKSZ (64 * 1024)
214
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100215#define image_to_cpu(x) ntohl(x)
216#define cpu_to_image(x) htonl(x)
wdenk5b1d7132002-11-03 00:07:02 +0000217
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100218static inline uint32_t image_get_header_size (void)
219{
220 return (sizeof (image_header_t));
221}
222
223#define image_get_hdr_l(f) \
224 static inline uint32_t image_get_##f(image_header_t *hdr) \
225 { \
226 return image_to_cpu (hdr->ih_##f); \
227 }
228image_get_hdr_l (magic);
229image_get_hdr_l (hcrc);
230image_get_hdr_l (time);
231image_get_hdr_l (size);
232image_get_hdr_l (load);
233image_get_hdr_l (ep);
234image_get_hdr_l (dcrc);
235
236#define image_get_hdr_b(f) \
237 static inline uint8_t image_get_##f(image_header_t *hdr) \
238 { \
239 return hdr->ih_##f; \
240 }
241image_get_hdr_b (os);
242image_get_hdr_b (arch);
243image_get_hdr_b (type);
244image_get_hdr_b (comp);
245
246static inline char *image_get_name (image_header_t *hdr)
247{
248 return (char *)hdr->ih_name;
249}
250
251static inline uint32_t image_get_data_size (image_header_t *hdr)
252{
253 return image_get_size (hdr);
254}
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100255
256/**
257 * image_get_data - get image payload start address
258 * @hdr: image header
259 *
260 * image_get_data() returns address of the image payload. For single
261 * component images it is image data start. For multi component
262 * images it points to the null terminated table of sub-images sizes.
263 *
264 * returns:
265 * image payload data start address
266 */
267static inline ulong image_get_data (image_header_t *hdr)
268{
269 return ((ulong)hdr + image_get_header_size ());
270}
271
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100272static inline uint32_t image_get_image_size (image_header_t *hdr)
273{
274 return (image_get_size (hdr) + image_get_header_size ());
275}
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100276static inline ulong image_get_image_end (image_header_t *hdr)
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100277{
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100278 return ((ulong)hdr + image_get_image_size (hdr));
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100279}
280
281#define image_set_hdr_l(f) \
282 static inline void image_set_##f(image_header_t *hdr, uint32_t val) \
283 { \
284 hdr->ih_##f = cpu_to_image (val); \
285 }
286image_set_hdr_l (magic);
287image_set_hdr_l (hcrc);
288image_set_hdr_l (time);
289image_set_hdr_l (size);
290image_set_hdr_l (load);
291image_set_hdr_l (ep);
292image_set_hdr_l (dcrc);
293
294#define image_set_hdr_b(f) \
295 static inline void image_set_##f(image_header_t *hdr, uint8_t val) \
296 { \
297 hdr->ih_##f = val; \
298 }
299image_set_hdr_b (os);
300image_set_hdr_b (arch);
301image_set_hdr_b (type);
302image_set_hdr_b (comp);
303
304static inline void image_set_name (image_header_t *hdr, const char *name)
305{
306 strncpy (image_get_name (hdr), name, IH_NMLEN);
307}
308
309int image_check_hcrc (image_header_t *hdr);
310int image_check_dcrc (image_header_t *hdr);
Marian Balakowiczaf13cdb2008-01-08 18:11:45 +0100311#ifndef USE_HOSTCC
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100312int image_check_dcrc_wd (image_header_t *hdr, ulong chunksize);
313int getenv_verify (void);
Marian Balakowiczaf13cdb2008-01-08 18:11:45 +0100314void memmove_wd (void *to, void *from, size_t len, ulong chunksz);
315#endif
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100316
317static inline int image_check_magic (image_header_t *hdr)
318{
319 return (image_get_magic (hdr) == IH_MAGIC);
320}
321static inline int image_check_type (image_header_t *hdr, uint8_t type)
322{
323 return (image_get_type (hdr) == type);
324}
325static inline int image_check_arch (image_header_t *hdr, uint8_t arch)
326{
327 return (image_get_arch (hdr) == arch);
328}
329static inline int image_check_os (image_header_t *hdr, uint8_t os)
330{
331 return (image_get_os (hdr) == os);
332}
333
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100334ulong image_multi_count (image_header_t *hdr);
335void image_multi_getimg (image_header_t *hdr, ulong idx,
336 ulong *data, ulong *len);
337
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100338#ifndef USE_HOSTCC
339static inline int image_check_target_arch (image_header_t *hdr)
340{
341#if defined(__ARM__)
342 if (!image_check_arch (hdr, IH_ARCH_ARM))
343#elif defined(__avr32__)
344 if (!image_check_arch (hdr, IH_ARCH_AVR32))
345#elif defined(__bfin__)
346 if (!image_check_arch (hdr, IH_ARCH_BLACKFIN))
347#elif defined(__I386__)
348 if (!image_check_arch (hdr, IH_ARCH_I386))
349#elif defined(__M68K__)
350 if (!image_check_arch (hdr, IH_ARCH_M68K))
351#elif defined(__microblaze__)
352 if (!image_check_arch (hdr, IH_ARCH_MICROBLAZE))
353#elif defined(__mips__)
354 if (!image_check_arch (hdr, IH_ARCH_MIPS))
355#elif defined(__nios__)
356 if (!image_check_arch (hdr, IH_ARCH_NIOS))
357#elif defined(__nios2__)
358 if (!image_check_arch (hdr, IH_ARCH_NIOS2))
359#elif defined(__PPC__)
360 if (!image_check_arch (hdr, IH_ARCH_PPC))
361#elif defined(__sh__)
362 if (!image_check_arch (hdr, IH_ARCH_SH))
363#else
364# error Unknown CPU type
365#endif
366 return 0;
367
368 return 1;
369}
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100370
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100371const char* image_get_os_name (uint8_t os);
372const char* image_get_arch_name (uint8_t arch);
373const char* image_get_type_name (uint8_t type);
374const char* image_get_comp_name (uint8_t comp);
Marian Balakowicz2242f532008-02-21 17:27:41 +0100375void image_print_contents (image_header_t *hdr);
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100376
Marian Balakowiczfff888a12008-02-21 17:20:19 +0100377#define IMAGE_FORMAT_INVALID 0x00
378#define IMAGE_FORMAT_LEGACY 0x01
379#define IMAGE_FORMAT_FIT 0x02
380int gen_image_get_format (void *img_addr);
381ulong gen_get_image (ulong img_addr);
382
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100383image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag,
384 int argc, char *argv[],
385 ulong rd_addr, uint8_t arch, int verify);
386
387void get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100388 bootm_headers_t *images, int verify, uint8_t arch,
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100389 ulong *rd_start, ulong *rd_end);
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100390
Marian Balakowiczceaed2b2008-01-31 13:57:17 +0100391#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +0100392ulong ramdisk_high (ulong alloc_current, ulong rd_data, ulong rd_len,
393 bd_t *kbd, ulong sp_limit, ulong sp,
394 ulong *initrd_start, ulong *initrd_end);
395
396ulong get_boot_sp_limit (ulong sp);
397ulong get_boot_cmdline (ulong alloc_current, ulong *cmd_start, ulong *cmd_end);
398ulong get_boot_kbd (ulong alloc_current, bd_t **kbd);
Marian Balakowiczceaed2b2008-01-31 13:57:17 +0100399#endif /* CONFIG_PPC || CONFIG_M68K */
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +0100400
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100401/*******************************************************************/
402/* New uImage format */
403/*******************************************************************/
Marian Balakowiczf50433d2008-02-21 17:20:20 +0100404#if defined(CONFIG_FIT)
Marian Balakowiczf50433d2008-02-21 17:20:20 +0100405inline int fit_parse_conf (const char *spec, ulong addr_curr,
406 ulong *addr, const char **conf_name);
407inline int fit_parse_subimage (const char *spec, ulong addr_curr,
408 ulong *addr, const char **image_name);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100409
410#ifdef CONFIG_FIT_VERBOSE
411#define fit_unsupported(msg) printf ("! %s:%d " \
412 "FIT images not supported for '%s'\n", \
413 __FILE__, __LINE__, (msg))
414
415#define fit_unsupported_reset(msg) printf ("! %s:%d " \
416 "FIT images not supported for '%s' " \
417 "- must reset board to recover!\n", \
418 __FILE__, __LINE__, (msg))
419#else
420#define fit_unsupported(msg)
421#define fit_unsupported_reset(msg)
422#endif /* CONFIG_FIT_VERBOSE */
423
Marian Balakowiczf50433d2008-02-21 17:20:20 +0100424#endif /* CONFIG_FIT */
425
Marian Balakowiczceaed2b2008-01-31 13:57:17 +0100426#endif /* USE_HOSTCC */
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100427
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100428#endif /* __IMAGE_H__ */