2 * (C) Copyright 2008 Semihalf
4 * (C) Copyright 2000-2005
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 * See file CREDITS for list of people who contributed to this
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.
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.
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,
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
30 ********************************************************************
36 #include <asm/byteorder.h>
40 #include <linux/string.h>
41 #include <asm/u-boot.h>
43 /* new uImage format support enabled by default */
45 #define CONFIG_OF_LIBFDT 1
47 /* enable fit_format_error(), fit_format_warning() */
48 #define CONFIG_FIT_VERBOSE 1
50 #if defined(CONFIG_FIT) && !defined(CONFIG_OF_LIBFDT)
51 #error "CONFIG_OF_LIBFDT not enabled, required by CONFIG_FIT!"
53 #endif /* USE_HOSTCC */
56 * Operating System Codes
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 */
76 #define IH_OS_RTEMS 18 /* RTEMS */
77 #define IH_OS_ARTOS 19 /* ARTOS */
78 #define IH_OS_UNITY 20 /* Unity OS */
81 * CPU Architecture Codes (supported by Linux)
83 #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 */
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
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.
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
130 * a multiple of 4 bytes - except for the last file).
132 * "Firmware Images" are binary images containing firmware (like
133 * U-Boot or FPGA images) which usually will be programmed to
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)
139 * as command interpreter (=> Shell Scripts).
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 */
149 #define IH_TYPE_FILESYSTEM 7 /* Filesystem Image (any type) */
150 #define IH_TYPE_FLATDT 8 /* Binary Flat Device Tree Blob */
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 */
159 #define IH_MAGIC 0x27051956 /* Image Magic Number */
160 #define IH_NMLEN 32 /* Image Name Length */
163 * all data in network byte order (aka natural aka bigendian)
166 typedef 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 */
182 * Legacy and FIT format headers used by do_bootm() and do_bootm_<os>()
185 typedef struct bootm_headers {
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.
191 image_header_t *legacy_hdr_os;
192 ulong legacy_hdr_valid;
194 #if defined(CONFIG_FIT)
195 void *fit_hdr_os; /* os FIT image header */
196 char *fit_uname_os; /* os subimage node unit name */
198 void *fit_hdr_rd; /* init ramdisk FIT image header */
199 char *fit_uname_rd; /* init ramdisk node unit name */
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 */
205 int verify; /* getenv("verify")[0] != 'n' */
210 * Some systems (for example LWMON) have very short watchdog periods;
211 * we must make sure to split long operations like memmove() or
212 * crc32() into reasonable chunks.
214 #define CHUNKSZ (64 * 1024)
216 #define image_to_cpu(x) ntohl(x)
217 #define cpu_to_image(x) htonl(x)
219 static inline uint32_t image_get_header_size (void)
221 return (sizeof (image_header_t));
224 #define image_get_hdr_l(f) \
225 static inline uint32_t image_get_##f(image_header_t *hdr) \
227 return image_to_cpu (hdr->ih_##f); \
229 image_get_hdr_l (magic);
230 image_get_hdr_l (hcrc);
231 image_get_hdr_l (time);
232 image_get_hdr_l (size);
233 image_get_hdr_l (load);
234 image_get_hdr_l (ep);
235 image_get_hdr_l (dcrc);
237 #define image_get_hdr_b(f) \
238 static inline uint8_t image_get_##f(image_header_t *hdr) \
240 return hdr->ih_##f; \
242 image_get_hdr_b (os);
243 image_get_hdr_b (arch);
244 image_get_hdr_b (type);
245 image_get_hdr_b (comp);
247 static inline char *image_get_name (image_header_t *hdr)
249 return (char *)hdr->ih_name;
252 static inline uint32_t image_get_data_size (image_header_t *hdr)
254 return image_get_size (hdr);
258 * image_get_data - get image payload start address
261 * image_get_data() returns address of the image payload. For single
262 * component images it is image data start. For multi component
263 * images it points to the null terminated table of sub-images sizes.
266 * image payload data start address
268 static inline ulong image_get_data (image_header_t *hdr)
270 return ((ulong)hdr + image_get_header_size ());
273 static inline uint32_t image_get_image_size (image_header_t *hdr)
275 return (image_get_size (hdr) + image_get_header_size ());
277 static inline ulong image_get_image_end (image_header_t *hdr)
279 return ((ulong)hdr + image_get_image_size (hdr));
282 #define image_set_hdr_l(f) \
283 static inline void image_set_##f(image_header_t *hdr, uint32_t val) \
285 hdr->ih_##f = cpu_to_image (val); \
287 image_set_hdr_l (magic);
288 image_set_hdr_l (hcrc);
289 image_set_hdr_l (time);
290 image_set_hdr_l (size);
291 image_set_hdr_l (load);
292 image_set_hdr_l (ep);
293 image_set_hdr_l (dcrc);
295 #define image_set_hdr_b(f) \
296 static inline void image_set_##f(image_header_t *hdr, uint8_t val) \
300 image_set_hdr_b (os);
301 image_set_hdr_b (arch);
302 image_set_hdr_b (type);
303 image_set_hdr_b (comp);
305 static inline void image_set_name (image_header_t *hdr, const char *name)
307 strncpy (image_get_name (hdr), name, IH_NMLEN);
310 int image_check_hcrc (image_header_t *hdr);
311 int image_check_dcrc (image_header_t *hdr);
313 int image_check_dcrc_wd (image_header_t *hdr, ulong chunksize);
314 int getenv_verify (void);
315 void memmove_wd (void *to, void *from, size_t len, ulong chunksz);
318 static inline int image_check_magic (image_header_t *hdr)
320 return (image_get_magic (hdr) == IH_MAGIC);
322 static inline int image_check_type (image_header_t *hdr, uint8_t type)
324 return (image_get_type (hdr) == type);
326 static inline int image_check_arch (image_header_t *hdr, uint8_t arch)
328 return (image_get_arch (hdr) == arch);
330 static inline int image_check_os (image_header_t *hdr, uint8_t os)
332 return (image_get_os (hdr) == os);
335 ulong image_multi_count (image_header_t *hdr);
336 void image_multi_getimg (image_header_t *hdr, ulong idx,
337 ulong *data, ulong *len);
340 static inline int image_check_target_arch (image_header_t *hdr)
343 if (!image_check_arch (hdr, IH_ARCH_ARM))
344 #elif defined(__avr32__)
345 if (!image_check_arch (hdr, IH_ARCH_AVR32))
346 #elif defined(__bfin__)
347 if (!image_check_arch (hdr, IH_ARCH_BLACKFIN))
348 #elif defined(__I386__)
349 if (!image_check_arch (hdr, IH_ARCH_I386))
350 #elif defined(__M68K__)
351 if (!image_check_arch (hdr, IH_ARCH_M68K))
352 #elif defined(__microblaze__)
353 if (!image_check_arch (hdr, IH_ARCH_MICROBLAZE))
354 #elif defined(__mips__)
355 if (!image_check_arch (hdr, IH_ARCH_MIPS))
356 #elif defined(__nios__)
357 if (!image_check_arch (hdr, IH_ARCH_NIOS))
358 #elif defined(__nios2__)
359 if (!image_check_arch (hdr, IH_ARCH_NIOS2))
360 #elif defined(__PPC__)
361 if (!image_check_arch (hdr, IH_ARCH_PPC))
362 #elif defined(__sh__)
363 if (!image_check_arch (hdr, IH_ARCH_SH))
365 # error Unknown CPU type
372 const char* image_get_os_name (uint8_t os);
373 const char* image_get_arch_name (uint8_t arch);
374 const char* image_get_type_name (uint8_t type);
375 const char* image_get_comp_name (uint8_t comp);
376 void image_print_contents (image_header_t *hdr);
378 #define IMAGE_FORMAT_INVALID 0x00
379 #define IMAGE_FORMAT_LEGACY 0x01 /* legacy image_header based format */
380 #define IMAGE_FORMAT_FIT 0x02 /* new, libfdt based format */
382 int gen_image_get_format (void *img_addr);
383 ulong gen_get_image (ulong img_addr);
385 void get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
386 bootm_headers_t *images, uint8_t arch,
387 ulong *rd_start, ulong *rd_end);
389 #if defined(CONFIG_PPC) || defined(CONFIG_M68K)
390 ulong ramdisk_high (ulong alloc_current, ulong rd_data, ulong rd_len,
391 ulong sp_limit, ulong sp,
392 ulong *initrd_start, ulong *initrd_end);
394 ulong get_boot_sp_limit (ulong sp);
395 ulong get_boot_cmdline (ulong alloc_current, ulong *cmd_start, ulong *cmd_end);
396 ulong get_boot_kbd (ulong alloc_current, bd_t **kbd);
397 #endif /* CONFIG_PPC || CONFIG_M68K */
399 /*******************************************************************/
400 /* New uImage format */
401 /*******************************************************************/
402 #if defined(CONFIG_FIT)
403 inline int fit_parse_conf (const char *spec, ulong addr_curr,
404 ulong *addr, const char **conf_name);
405 inline int fit_parse_subimage (const char *spec, ulong addr_curr,
406 ulong *addr, const char **image_name);
408 #ifdef CONFIG_FIT_VERBOSE
409 #define fit_unsupported(msg) printf ("! %s:%d " \
410 "FIT images not supported for '%s'\n", \
411 __FILE__, __LINE__, (msg))
413 #define fit_unsupported_reset(msg) printf ("! %s:%d " \
414 "FIT images not supported for '%s' " \
415 "- must reset board to recover!\n", \
416 __FILE__, __LINE__, (msg))
418 #define fit_unsupported(msg)
419 #define fit_unsupported_reset(msg)
420 #endif /* CONFIG_FIT_VERBOSE */
422 #endif /* CONFIG_FIT */
424 #endif /* USE_HOSTCC */
426 #endif /* __IMAGE_H__ */