blob: ed795521dd2c289ca344ec9f9cbd038d4000f966 [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
Kumar Gala4ed65522008-02-27 21:51:47 -060040#include <lmb.h>
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010041#include <linux/string.h>
Marian Balakowiczceaed2b2008-01-31 13:57:17 +010042#include <asm/u-boot.h>
Marian Balakowicz75d3e8f2008-02-21 17:20:18 +010043
44/* new uImage format support enabled by default */
45#define CONFIG_FIT 1
46#define CONFIG_OF_LIBFDT 1
47
Marian Balakowiczd5934ad2008-02-04 08:28:09 +010048/* enable fit_format_error(), fit_format_warning() */
49#define CONFIG_FIT_VERBOSE 1
50
Marian Balakowicz75d3e8f2008-02-21 17:20:18 +010051#if defined(CONFIG_FIT) && !defined(CONFIG_OF_LIBFDT)
52#error "CONFIG_OF_LIBFDT not enabled, required by CONFIG_FIT!"
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010053#endif
Marian Balakowicz75d3e8f2008-02-21 17:20:18 +010054#endif /* USE_HOSTCC */
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010055
wdenk5b1d7132002-11-03 00:07:02 +000056/*
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 */
wdenkd791b1d2003-04-20 14:04:18 +000077#define IH_OS_RTEMS 18 /* RTEMS */
wdenk7f70e852003-05-20 14:25:27 +000078#define IH_OS_ARTOS 19 /* ARTOS */
wdenk27b207f2003-07-24 23:38:38 +000079#define IH_OS_UNITY 20 /* Unity OS */
wdenk5b1d7132002-11-03 00:07:02 +000080
81/*
82 * CPU Architecture Codes (supported by Linux)
83 */
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010084#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 */
wdenk5b1d7132002-11-03 00:07:02 +0000103
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
wdenke1599e82004-10-10 23:27:33 +0000131 * a multiple of 4 bytes - except for the last file).
wdenk5b1d7132002-11-03 00:07:02 +0000132 *
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)
wdenk27b207f2003-07-24 23:38:38 +0000140 * as command interpreter (=> Shell Scripts).
wdenk5b1d7132002-11-03 00:07:02 +0000141 */
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 */
wdenkfbe4b5c2003-10-06 21:55:32 +0000150#define IH_TYPE_FILESYSTEM 7 /* Filesystem Image (any type) */
Matthew McClintock25c751e2006-08-16 10:54:09 -0500151#define IH_TYPE_FLATDT 8 /* Binary Flat Device Tree Blob */
wdenk5b1d7132002-11-03 00:07:02 +0000152
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
wdenk5b1d7132002-11-03 00:07:02 +0000163/*
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100164 * Legacy format image header,
165 * all data in network byte order (aka natural aka bigendian).
wdenk5b1d7132002-11-03 00:07:02 +0000166 */
wdenk5b1d7132002-11-03 00:07:02 +0000167typedef 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
Marian Balakowicz559316f2008-01-08 18:11:44 +0100182/*
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100183 * 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
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100189 * then boot_get_ramdisk() and get_fdt() will attempt to get
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100190 * 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
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100206 int verify; /* getenv("verify")[0] != 'n' */
Kumar Galaf5614e72008-02-27 21:51:48 -0600207 int autostart; /* getenv("autostart")[0] != 'n' */
Kumar Gala4ed65522008-02-27 21:51:47 -0600208 struct lmb *lmb; /* for memory mgmt */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100209#endif
210} bootm_headers_t;
211
212/*
Marian Balakowicz559316f2008-01-08 18:11:44 +0100213 * 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
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100219#define uimage_to_cpu(x) ntohl(x)
220#define cpu_to_uimage(x) htonl(x)
wdenk5b1d7132002-11-03 00:07:02 +0000221
Marian Balakowicz570abb02008-02-29 15:59:59 +0100222const char *genimg_get_os_name (uint8_t os);
223const char *genimg_get_arch_name (uint8_t arch);
224const char *genimg_get_type_name (uint8_t type);
225const char *genimg_get_comp_name (uint8_t comp);
226int genimg_get_os_id (const char *name);
227int genimg_get_arch_id (const char *name);
228int genimg_get_type_id (const char *name);
229int genimg_get_comp_id (const char *name);
230
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100231#ifndef USE_HOSTCC
232/* Image format types, returned by _get_format() routine */
233#define IMAGE_FORMAT_INVALID 0x00
234#define IMAGE_FORMAT_LEGACY 0x01 /* legacy image_header based format */
235#define IMAGE_FORMAT_FIT 0x02 /* new, libfdt based format */
236
237int genimg_get_format (void *img_addr);
238ulong genimg_get_image (ulong img_addr);
239
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100240int boot_get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
241 bootm_headers_t *images, uint8_t arch,
242 ulong *rd_start, ulong *rd_end);
243
244#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
245int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len,
246 ulong *initrd_start, ulong *initrd_end);
247
248int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end,
249 ulong bootmap_base);
250int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base);
251#endif /* CONFIG_PPC || CONFIG_M68K */
Marian Balakowicz570abb02008-02-29 15:59:59 +0100252#endif /* !USE_HOSTCC */
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100253
254/*******************************************************************/
255/* Legacy format specific code (prefixed with image_) */
256/*******************************************************************/
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100257static inline uint32_t image_get_header_size (void)
258{
259 return (sizeof (image_header_t));
260}
261
262#define image_get_hdr_l(f) \
263 static inline uint32_t image_get_##f(image_header_t *hdr) \
264 { \
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100265 return uimage_to_cpu (hdr->ih_##f); \
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100266 }
267image_get_hdr_l (magic);
268image_get_hdr_l (hcrc);
269image_get_hdr_l (time);
270image_get_hdr_l (size);
271image_get_hdr_l (load);
272image_get_hdr_l (ep);
273image_get_hdr_l (dcrc);
274
275#define image_get_hdr_b(f) \
276 static inline uint8_t image_get_##f(image_header_t *hdr) \
277 { \
278 return hdr->ih_##f; \
279 }
280image_get_hdr_b (os);
281image_get_hdr_b (arch);
282image_get_hdr_b (type);
283image_get_hdr_b (comp);
284
285static inline char *image_get_name (image_header_t *hdr)
286{
287 return (char *)hdr->ih_name;
288}
289
290static inline uint32_t image_get_data_size (image_header_t *hdr)
291{
292 return image_get_size (hdr);
293}
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100294
295/**
296 * image_get_data - get image payload start address
297 * @hdr: image header
298 *
299 * image_get_data() returns address of the image payload. For single
300 * component images it is image data start. For multi component
301 * images it points to the null terminated table of sub-images sizes.
302 *
303 * returns:
304 * image payload data start address
305 */
306static inline ulong image_get_data (image_header_t *hdr)
307{
308 return ((ulong)hdr + image_get_header_size ());
309}
310
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100311static inline uint32_t image_get_image_size (image_header_t *hdr)
312{
313 return (image_get_size (hdr) + image_get_header_size ());
314}
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100315static inline ulong image_get_image_end (image_header_t *hdr)
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100316{
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100317 return ((ulong)hdr + image_get_image_size (hdr));
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100318}
319
320#define image_set_hdr_l(f) \
321 static inline void image_set_##f(image_header_t *hdr, uint32_t val) \
322 { \
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100323 hdr->ih_##f = cpu_to_uimage (val); \
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100324 }
325image_set_hdr_l (magic);
326image_set_hdr_l (hcrc);
327image_set_hdr_l (time);
328image_set_hdr_l (size);
329image_set_hdr_l (load);
330image_set_hdr_l (ep);
331image_set_hdr_l (dcrc);
332
333#define image_set_hdr_b(f) \
334 static inline void image_set_##f(image_header_t *hdr, uint8_t val) \
335 { \
336 hdr->ih_##f = val; \
337 }
338image_set_hdr_b (os);
339image_set_hdr_b (arch);
340image_set_hdr_b (type);
341image_set_hdr_b (comp);
342
343static inline void image_set_name (image_header_t *hdr, const char *name)
344{
345 strncpy (image_get_name (hdr), name, IH_NMLEN);
346}
347
348int image_check_hcrc (image_header_t *hdr);
349int image_check_dcrc (image_header_t *hdr);
Marian Balakowiczaf13cdb2008-01-08 18:11:45 +0100350#ifndef USE_HOSTCC
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100351int image_check_dcrc_wd (image_header_t *hdr, ulong chunksize);
352int getenv_verify (void);
Kumar Galaf5614e72008-02-27 21:51:48 -0600353int getenv_autostart (void);
Kumar Galad3f2fa02008-02-27 21:51:50 -0600354ulong getenv_bootm_low(void);
355ulong getenv_bootm_size(void);
Marian Balakowiczaf13cdb2008-01-08 18:11:45 +0100356void memmove_wd (void *to, void *from, size_t len, ulong chunksz);
357#endif
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100358
359static inline int image_check_magic (image_header_t *hdr)
360{
361 return (image_get_magic (hdr) == IH_MAGIC);
362}
363static inline int image_check_type (image_header_t *hdr, uint8_t type)
364{
365 return (image_get_type (hdr) == type);
366}
367static inline int image_check_arch (image_header_t *hdr, uint8_t arch)
368{
369 return (image_get_arch (hdr) == arch);
370}
371static inline int image_check_os (image_header_t *hdr, uint8_t os)
372{
373 return (image_get_os (hdr) == os);
374}
375
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100376ulong image_multi_count (image_header_t *hdr);
377void image_multi_getimg (image_header_t *hdr, ulong idx,
378 ulong *data, ulong *len);
379
Marian Balakowicz570abb02008-02-29 15:59:59 +0100380inline void image_print_contents (image_header_t *hdr);
381inline void image_print_contents_noindent (image_header_t *hdr);
382
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100383#ifndef USE_HOSTCC
384static inline int image_check_target_arch (image_header_t *hdr)
385{
386#if defined(__ARM__)
387 if (!image_check_arch (hdr, IH_ARCH_ARM))
388#elif defined(__avr32__)
389 if (!image_check_arch (hdr, IH_ARCH_AVR32))
390#elif defined(__bfin__)
391 if (!image_check_arch (hdr, IH_ARCH_BLACKFIN))
392#elif defined(__I386__)
393 if (!image_check_arch (hdr, IH_ARCH_I386))
394#elif defined(__M68K__)
395 if (!image_check_arch (hdr, IH_ARCH_M68K))
396#elif defined(__microblaze__)
397 if (!image_check_arch (hdr, IH_ARCH_MICROBLAZE))
398#elif defined(__mips__)
399 if (!image_check_arch (hdr, IH_ARCH_MIPS))
400#elif defined(__nios__)
401 if (!image_check_arch (hdr, IH_ARCH_NIOS))
402#elif defined(__nios2__)
403 if (!image_check_arch (hdr, IH_ARCH_NIOS2))
404#elif defined(__PPC__)
405 if (!image_check_arch (hdr, IH_ARCH_PPC))
406#elif defined(__sh__)
407 if (!image_check_arch (hdr, IH_ARCH_SH))
408#else
409# error Unknown CPU type
410#endif
411 return 0;
412
413 return 1;
414}
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100415
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100416/*******************************************************************/
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100417/* New uImage format specific code (prefixed with fit_) */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100418/*******************************************************************/
Marian Balakowiczf50433d2008-02-21 17:20:20 +0100419#if defined(CONFIG_FIT)
Marian Balakowiczf50433d2008-02-21 17:20:20 +0100420inline int fit_parse_conf (const char *spec, ulong addr_curr,
421 ulong *addr, const char **conf_name);
422inline int fit_parse_subimage (const char *spec, ulong addr_curr,
423 ulong *addr, const char **image_name);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100424
425#ifdef CONFIG_FIT_VERBOSE
426#define fit_unsupported(msg) printf ("! %s:%d " \
427 "FIT images not supported for '%s'\n", \
428 __FILE__, __LINE__, (msg))
429
430#define fit_unsupported_reset(msg) printf ("! %s:%d " \
431 "FIT images not supported for '%s' " \
432 "- must reset board to recover!\n", \
433 __FILE__, __LINE__, (msg))
434#else
435#define fit_unsupported(msg)
436#define fit_unsupported_reset(msg)
437#endif /* CONFIG_FIT_VERBOSE */
Marian Balakowiczf50433d2008-02-21 17:20:20 +0100438#endif /* CONFIG_FIT */
Marian Balakowiczceaed2b2008-01-31 13:57:17 +0100439#endif /* USE_HOSTCC */
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100440
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100441#endif /* __IMAGE_H__ */