blob: 0c601bbc45d6e1063b710a83a739a5d9f0bf43d5 [file] [log] [blame]
Marian Balakowiczb97a2a02008-01-08 18:14:09 +01001/*
2 * (C) Copyright 2008 Semihalf
3 *
4 * (C) Copyright 2000-2006
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
24 */
Marian Balakowiczceaed2b2008-01-31 13:57:17 +010025
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010026#ifndef USE_HOSTCC
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +010027#include <common.h>
28#include <watchdog.h>
29
30#ifdef CONFIG_SHOW_BOOT_PROGRESS
31#include <status_led.h>
32#endif
33
34#ifdef CONFIG_HAS_DATAFLASH
35#include <dataflash.h>
36#endif
37
Marian Balakowicz95d449a2008-05-13 15:53:29 +020038#ifdef CONFIG_LOGBUFFER
39#include <logbuff.h>
40#endif
41
Marian Balakowicz2242f532008-02-21 17:27:41 +010042#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
43#include <rtc.h>
44#endif
45
Marian Balakowicz5dfb5212008-02-29 21:24:06 +010046#include <image.h>
47
Stephen Warren712fbcf2011-10-18 11:11:49 +000048#if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
Marian Balakowiczfff888a12008-02-21 17:20:19 +010049#include <fdt.h>
50#include <libfdt.h>
51#include <fdt_support.h>
Marian Balakowiczc8779642008-03-12 10:12:37 +010052#endif
53
54#if defined(CONFIG_FIT)
Andy Fleming20a14a42008-04-02 16:19:07 -050055#include <u-boot/md5.h>
Marian Balakowicz5dfb5212008-02-29 21:24:06 +010056#include <sha1.h>
Marian Balakowiczc8779642008-03-12 10:12:37 +010057
Stephen Warren712fbcf2011-10-18 11:11:49 +000058static int fit_check_ramdisk(const void *fit, int os_noffset,
Marian Balakowiczc8779642008-03-12 10:12:37 +010059 uint8_t arch, int verify);
Marian Balakowiczfff888a12008-02-21 17:20:19 +010060#endif
61
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +010062#ifdef CONFIG_CMD_BDI
Wolfgang Denk54841ab2010-06-28 22:00:46 +020063extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +010064#endif
65
66DECLARE_GLOBAL_DATA_PTR;
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +010067
Stephen Warren712fbcf2011-10-18 11:11:49 +000068static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch,
Marian Balakowiczd985c842008-03-12 10:14:38 +010069 int verify);
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010070#else
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +010071#include "mkimage.h"
Andy Fleming20a14a42008-04-02 16:19:07 -050072#include <u-boot/md5.h>
Marian Balakowicz5dfb5212008-02-29 21:24:06 +010073#include <time.h>
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010074#include <image.h>
Marian Balakowicz5dfb5212008-02-29 21:24:06 +010075#endif /* !USE_HOSTCC*/
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010076
Mike Frysinger7edb1862010-10-20 07:17:39 -040077static const table_entry_t uimage_arch[] = {
Marian Balakowicz570abb02008-02-29 15:59:59 +010078 { IH_ARCH_INVALID, NULL, "Invalid ARCH", },
79 { IH_ARCH_ALPHA, "alpha", "Alpha", },
80 { IH_ARCH_ARM, "arm", "ARM", },
81 { IH_ARCH_I386, "x86", "Intel x86", },
82 { IH_ARCH_IA64, "ia64", "IA64", },
83 { IH_ARCH_M68K, "m68k", "M68K", },
84 { IH_ARCH_MICROBLAZE, "microblaze", "MicroBlaze", },
85 { IH_ARCH_MIPS, "mips", "MIPS", },
86 { IH_ARCH_MIPS64, "mips64", "MIPS 64 Bit", },
Marian Balakowicz570abb02008-02-29 15:59:59 +010087 { IH_ARCH_NIOS2, "nios2", "NIOS II", },
Grant Ericksone419e122008-05-04 16:45:01 -070088 { IH_ARCH_PPC, "powerpc", "PowerPC", },
Marian Balakowicz570abb02008-02-29 15:59:59 +010089 { IH_ARCH_PPC, "ppc", "PowerPC", },
90 { IH_ARCH_S390, "s390", "IBM S390", },
91 { IH_ARCH_SH, "sh", "SuperH", },
92 { IH_ARCH_SPARC, "sparc", "SPARC", },
93 { IH_ARCH_SPARC64, "sparc64", "SPARC 64 Bit", },
94 { IH_ARCH_BLACKFIN, "blackfin", "Blackfin", },
95 { IH_ARCH_AVR32, "avr32", "AVR32", },
Macpaul Lin64d61462011-10-19 20:41:09 +000096 { IH_ARCH_NDS32, "nds32", "NDS32", },
Stefan Kristiansson3ddcacc2011-11-26 19:04:50 +000097 { IH_ARCH_OPENRISC, "or1k", "OpenRISC 1000",},
Marian Balakowicz570abb02008-02-29 15:59:59 +010098 { -1, "", "", },
99};
100
Mike Frysinger7edb1862010-10-20 07:17:39 -0400101static const table_entry_t uimage_os[] = {
Marian Balakowicz570abb02008-02-29 15:59:59 +0100102 { IH_OS_INVALID, NULL, "Invalid OS", },
Marian Balakowicz570abb02008-02-29 15:59:59 +0100103 { IH_OS_LINUX, "linux", "Linux", },
104#if defined(CONFIG_LYNXKDI) || defined(USE_HOSTCC)
105 { IH_OS_LYNXOS, "lynxos", "LynxOS", },
106#endif
107 { IH_OS_NETBSD, "netbsd", "NetBSD", },
Torkel Lundgren3df61952010-09-28 11:05:36 +0200108 { IH_OS_OSE, "ose", "Enea OSE", },
Marian Balakowicz570abb02008-02-29 15:59:59 +0100109 { IH_OS_RTEMS, "rtems", "RTEMS", },
110 { IH_OS_U_BOOT, "u-boot", "U-Boot", },
111#if defined(CONFIG_CMD_ELF) || defined(USE_HOSTCC)
112 { IH_OS_QNX, "qnx", "QNX", },
113 { IH_OS_VXWORKS, "vxworks", "VxWorks", },
114#endif
Peter Tyserf5ed9e32008-09-08 14:56:49 -0500115#if defined(CONFIG_INTEGRITY) || defined(USE_HOSTCC)
116 { IH_OS_INTEGRITY,"integrity", "INTEGRITY", },
117#endif
Marian Balakowicz570abb02008-02-29 15:59:59 +0100118#ifdef USE_HOSTCC
119 { IH_OS_4_4BSD, "4_4bsd", "4_4BSD", },
120 { IH_OS_DELL, "dell", "Dell", },
121 { IH_OS_ESIX, "esix", "Esix", },
122 { IH_OS_FREEBSD, "freebsd", "FreeBSD", },
123 { IH_OS_IRIX, "irix", "Irix", },
124 { IH_OS_NCR, "ncr", "NCR", },
125 { IH_OS_OPENBSD, "openbsd", "OpenBSD", },
126 { IH_OS_PSOS, "psos", "pSOS", },
127 { IH_OS_SCO, "sco", "SCO", },
128 { IH_OS_SOLARIS, "solaris", "Solaris", },
129 { IH_OS_SVR4, "svr4", "SVR4", },
130#endif
131 { -1, "", "", },
132};
133
Mike Frysinger7edb1862010-10-20 07:17:39 -0400134static const table_entry_t uimage_type[] = {
Stefano Babic4962e382011-10-17 00:07:43 +0000135 { IH_TYPE_AISIMAGE, "aisimage", "Davinci AIS image",},
Marian Balakowicz570abb02008-02-29 15:59:59 +0100136 { IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image", },
137 { IH_TYPE_FIRMWARE, "firmware", "Firmware", },
John Rigby3decb142011-07-21 09:10:30 -0400138 { IH_TYPE_FLATDT, "flat_dt", "Flat Device Tree", },
Marian Balakowicz570abb02008-02-29 15:59:59 +0100139 { IH_TYPE_KERNEL, "kernel", "Kernel Image", },
Stephen Warrenb9b50e82011-11-10 13:17:53 -0700140 { IH_TYPE_KERNEL_NOLOAD, "kernel_noload", "Kernel Image (no loading done)", },
Stefano Babic4962e382011-10-17 00:07:43 +0000141 { IH_TYPE_KWBIMAGE, "kwbimage", "Kirkwood Boot Image",},
142 { IH_TYPE_IMXIMAGE, "imximage", "Freescale i.MX Boot Image",},
143 { IH_TYPE_INVALID, NULL, "Invalid Image", },
Marian Balakowicz570abb02008-02-29 15:59:59 +0100144 { IH_TYPE_MULTI, "multi", "Multi-File Image", },
Stefano Babic4962e382011-10-17 00:07:43 +0000145 { IH_TYPE_OMAPIMAGE, "omapimage", "TI OMAP SPL With GP CH",},
Shaohui Xie5d898a02012-08-10 02:49:35 +0000146 { IH_TYPE_PBLIMAGE, "pblimage", "Freescale PBL Boot Image",},
Marian Balakowicz570abb02008-02-29 15:59:59 +0100147 { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", },
148 { IH_TYPE_SCRIPT, "script", "Script", },
149 { IH_TYPE_STANDALONE, "standalone", "Standalone Program", },
Heiko Schocher7816f2c2011-07-16 00:06:42 +0000150 { IH_TYPE_UBLIMAGE, "ublimage", "Davinci UBL image",},
Marian Balakowicz570abb02008-02-29 15:59:59 +0100151 { -1, "", "", },
152};
153
Mike Frysinger7edb1862010-10-20 07:17:39 -0400154static const table_entry_t uimage_comp[] = {
Marian Balakowicz570abb02008-02-29 15:59:59 +0100155 { IH_COMP_NONE, "none", "uncompressed", },
156 { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", },
157 { IH_COMP_GZIP, "gzip", "gzip compressed", },
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200158 { IH_COMP_LZMA, "lzma", "lzma compressed", },
Peter Korsgaard20dde482009-11-19 11:37:51 +0100159 { IH_COMP_LZO, "lzo", "lzo compressed", },
Marian Balakowicz570abb02008-02-29 15:59:59 +0100160 { -1, "", "", },
161};
162
Stephen Warren712fbcf2011-10-18 11:11:49 +0000163uint32_t crc32(uint32_t, const unsigned char *, uint);
164uint32_t crc32_wd(uint32_t, const unsigned char *, uint, uint);
Marian Balakowicz570abb02008-02-29 15:59:59 +0100165#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
Stephen Warren712fbcf2011-10-18 11:11:49 +0000166static void genimg_print_time(time_t timestamp);
Marian Balakowicz570abb02008-02-29 15:59:59 +0100167#endif
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100168
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100169/*****************************************************************************/
170/* Legacy format routines */
171/*****************************************************************************/
Stephen Warren712fbcf2011-10-18 11:11:49 +0000172int image_check_hcrc(const image_header_t *hdr)
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100173{
174 ulong hcrc;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000175 ulong len = image_get_header_size();
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100176 image_header_t header;
177
178 /* Copy header so we can blank CRC field for re-calculation */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000179 memmove(&header, (char *)hdr, image_get_header_size());
180 image_set_hcrc(&header, 0);
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100181
Stephen Warren712fbcf2011-10-18 11:11:49 +0000182 hcrc = crc32(0, (unsigned char *)&header, len);
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100183
Stephen Warren712fbcf2011-10-18 11:11:49 +0000184 return (hcrc == image_get_hcrc(hdr));
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100185}
186
Stephen Warren712fbcf2011-10-18 11:11:49 +0000187int image_check_dcrc(const image_header_t *hdr)
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100188{
Stephen Warren712fbcf2011-10-18 11:11:49 +0000189 ulong data = image_get_data(hdr);
190 ulong len = image_get_data_size(hdr);
191 ulong dcrc = crc32_wd(0, (unsigned char *)data, len, CHUNKSZ_CRC32);
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100192
Stephen Warren712fbcf2011-10-18 11:11:49 +0000193 return (dcrc == image_get_dcrc(hdr));
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100194}
195
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100196/**
197 * image_multi_count - get component (sub-image) count
198 * @hdr: pointer to the header of the multi component image
199 *
200 * image_multi_count() returns number of components in a multi
201 * component image.
202 *
203 * Note: no checking of the image type is done, caller must pass
204 * a valid multi component image.
205 *
206 * returns:
207 * number of components
208 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000209ulong image_multi_count(const image_header_t *hdr)
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100210{
211 ulong i, count = 0;
Marian Balakowiczdf6f1b82008-02-29 16:00:06 +0100212 uint32_t *size;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100213
214 /* get start of the image payload, which in case of multi
215 * component images that points to a table of component sizes */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000216 size = (uint32_t *)image_get_data(hdr);
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100217
218 /* count non empty slots */
219 for (i = 0; size[i]; ++i)
220 count++;
221
222 return count;
223}
224
225/**
226 * image_multi_getimg - get component data address and size
227 * @hdr: pointer to the header of the multi component image
228 * @idx: index of the requested component
229 * @data: pointer to a ulong variable, will hold component data address
230 * @len: pointer to a ulong variable, will hold component size
231 *
232 * image_multi_getimg() returns size and data address for the requested
233 * component in a multi component image.
234 *
235 * Note: no checking of the image type is done, caller must pass
236 * a valid multi component image.
237 *
238 * returns:
239 * data address and size of the component, if idx is valid
240 * 0 in data and len, if idx is out of range
241 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000242void image_multi_getimg(const image_header_t *hdr, ulong idx,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100243 ulong *data, ulong *len)
244{
245 int i;
Marian Balakowiczdf6f1b82008-02-29 16:00:06 +0100246 uint32_t *size;
Nick Spence02b9b222008-05-10 14:02:04 -0700247 ulong offset, count, img_data;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100248
249 /* get number of component */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000250 count = image_multi_count(hdr);
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100251
252 /* get start of the image payload, which in case of multi
253 * component images that points to a table of component sizes */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000254 size = (uint32_t *)image_get_data(hdr);
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100255
256 /* get address of the proper component data start, which means
257 * skipping sizes table (add 1 for last, null entry) */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000258 img_data = image_get_data(hdr) + (count + 1) * sizeof(uint32_t);
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100259
260 if (idx < count) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000261 *len = uimage_to_cpu(size[idx]);
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100262 offset = 0;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100263
264 /* go over all indices preceding requested component idx */
265 for (i = 0; i < idx; i++) {
Nick Spence02b9b222008-05-10 14:02:04 -0700266 /* add up i-th component size, rounding up to 4 bytes */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000267 offset += (uimage_to_cpu(size[i]) + 3) & ~3 ;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100268 }
269
270 /* calculate idx-th component data address */
Nick Spence02b9b222008-05-10 14:02:04 -0700271 *data = img_data + offset;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100272 } else {
273 *len = 0;
274 *data = 0;
275 }
276}
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100277
Stephen Warren712fbcf2011-10-18 11:11:49 +0000278static void image_print_type(const image_header_t *hdr)
Marian Balakowicz2242f532008-02-21 17:27:41 +0100279{
280 const char *os, *arch, *type, *comp;
281
Stephen Warren712fbcf2011-10-18 11:11:49 +0000282 os = genimg_get_os_name(image_get_os(hdr));
283 arch = genimg_get_arch_name(image_get_arch(hdr));
284 type = genimg_get_type_name(image_get_type(hdr));
285 comp = genimg_get_comp_name(image_get_comp(hdr));
Marian Balakowicz2242f532008-02-21 17:27:41 +0100286
Stephen Warren712fbcf2011-10-18 11:11:49 +0000287 printf("%s %s %s (%s)\n", arch, os, type, comp);
Marian Balakowicz2242f532008-02-21 17:27:41 +0100288}
289
Marian Balakowicz5dfb5212008-02-29 21:24:06 +0100290/**
Bartlomiej Siekaedbed242008-04-18 12:39:23 +0200291 * image_print_contents - prints out the contents of the legacy format image
Wolfgang Denk3a2003f2009-08-19 11:42:56 +0200292 * @ptr: pointer to the legacy format image header
Marian Balakowicz5dfb5212008-02-29 21:24:06 +0100293 * @p: pointer to prefix string
294 *
Bartlomiej Siekaedbed242008-04-18 12:39:23 +0200295 * image_print_contents() formats a multi line legacy image contents description.
Marian Balakowicz5dfb5212008-02-29 21:24:06 +0100296 * The routine prints out all header fields followed by the size/offset data
297 * for MULTI/SCRIPT images.
298 *
299 * returns:
300 * no returned results
301 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000302void image_print_contents(const void *ptr)
Marian Balakowicz2242f532008-02-21 17:27:41 +0100303{
Wolfgang Denk3a2003f2009-08-19 11:42:56 +0200304 const image_header_t *hdr = (const image_header_t *)ptr;
Bartlomiej Siekaedbed242008-04-18 12:39:23 +0200305 const char *p;
306
307#ifdef USE_HOSTCC
308 p = "";
309#else
310 p = " ";
311#endif
312
Stephen Warren712fbcf2011-10-18 11:11:49 +0000313 printf("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name(hdr));
Marian Balakowicz570abb02008-02-29 15:59:59 +0100314#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
Stephen Warren712fbcf2011-10-18 11:11:49 +0000315 printf("%sCreated: ", p);
316 genimg_print_time((time_t)image_get_time(hdr));
Marian Balakowicz2242f532008-02-21 17:27:41 +0100317#endif
Stephen Warren712fbcf2011-10-18 11:11:49 +0000318 printf("%sImage Type: ", p);
319 image_print_type(hdr);
320 printf("%sData Size: ", p);
321 genimg_print_size(image_get_data_size(hdr));
322 printf("%sLoad Address: %08x\n", p, image_get_load(hdr));
323 printf("%sEntry Point: %08x\n", p, image_get_ep(hdr));
Marian Balakowicz2242f532008-02-21 17:27:41 +0100324
Stephen Warren712fbcf2011-10-18 11:11:49 +0000325 if (image_check_type(hdr, IH_TYPE_MULTI) ||
326 image_check_type(hdr, IH_TYPE_SCRIPT)) {
Marian Balakowicz2242f532008-02-21 17:27:41 +0100327 int i;
328 ulong data, len;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000329 ulong count = image_multi_count(hdr);
Marian Balakowicz2242f532008-02-21 17:27:41 +0100330
Stephen Warren712fbcf2011-10-18 11:11:49 +0000331 printf("%sContents:\n", p);
Marian Balakowicz2242f532008-02-21 17:27:41 +0100332 for (i = 0; i < count; i++) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000333 image_multi_getimg(hdr, i, &data, &len);
Marian Balakowicz570abb02008-02-29 15:59:59 +0100334
Stephen Warren712fbcf2011-10-18 11:11:49 +0000335 printf("%s Image %d: ", p, i);
336 genimg_print_size(len);
Marian Balakowicz570abb02008-02-29 15:59:59 +0100337
Stephen Warren712fbcf2011-10-18 11:11:49 +0000338 if (image_check_type(hdr, IH_TYPE_SCRIPT) && i > 0) {
Marian Balakowicz570abb02008-02-29 15:59:59 +0100339 /*
340 * the user may need to know offsets
341 * if planning to do something with
342 * multiple files
343 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000344 printf("%s Offset = 0x%08lx\n", p, data);
Marian Balakowicz570abb02008-02-29 15:59:59 +0100345 }
Marian Balakowicz2242f532008-02-21 17:27:41 +0100346 }
347 }
348}
349
Marian Balakowicz570abb02008-02-29 15:59:59 +0100350
351#ifndef USE_HOSTCC
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100352/**
353 * image_get_ramdisk - get and verify ramdisk image
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100354 * @rd_addr: ramdisk image start address
355 * @arch: expected ramdisk architecture
356 * @verify: checksum verification flag
357 *
358 * image_get_ramdisk() returns a pointer to the verified ramdisk image
359 * header. Routine receives image start address and expected architecture
360 * flag. Verification done covers data and header integrity and os/type/arch
361 * fields checking.
362 *
363 * If dataflash support is enabled routine checks for dataflash addresses
364 * and handles required dataflash reads.
365 *
366 * returns:
367 * pointer to a ramdisk image header, if image was found and valid
Kumar Gala274cea22008-02-27 21:51:46 -0600368 * otherwise, return NULL
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100369 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000370static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch,
Marian Balakowiczd985c842008-03-12 10:14:38 +0100371 int verify)
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100372{
Wolfgang Denk3a2003f2009-08-19 11:42:56 +0200373 const image_header_t *rd_hdr = (const image_header_t *)rd_addr;
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100374
Stephen Warren712fbcf2011-10-18 11:11:49 +0000375 if (!image_check_magic(rd_hdr)) {
376 puts("Bad Magic Number\n");
Simon Glass770605e2012-02-13 13:51:18 +0000377 bootstage_error(BOOTSTAGE_ID_RD_MAGIC);
Kumar Gala274cea22008-02-27 21:51:46 -0600378 return NULL;
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100379 }
380
Stephen Warren712fbcf2011-10-18 11:11:49 +0000381 if (!image_check_hcrc(rd_hdr)) {
382 puts("Bad Header Checksum\n");
Simon Glass770605e2012-02-13 13:51:18 +0000383 bootstage_error(BOOTSTAGE_ID_RD_HDR_CHECKSUM);
Kumar Gala274cea22008-02-27 21:51:46 -0600384 return NULL;
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100385 }
386
Simon Glass770605e2012-02-13 13:51:18 +0000387 bootstage_mark(BOOTSTAGE_ID_RD_MAGIC);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000388 image_print_contents(rd_hdr);
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100389
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100390 if (verify) {
391 puts(" Verifying Checksum ... ");
Stephen Warren712fbcf2011-10-18 11:11:49 +0000392 if (!image_check_dcrc(rd_hdr)) {
393 puts("Bad Data CRC\n");
Simon Glass770605e2012-02-13 13:51:18 +0000394 bootstage_error(BOOTSTAGE_ID_RD_CHECKSUM);
Kumar Gala274cea22008-02-27 21:51:46 -0600395 return NULL;
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100396 }
397 puts("OK\n");
398 }
399
Simon Glass770605e2012-02-13 13:51:18 +0000400 bootstage_mark(BOOTSTAGE_ID_RD_HDR_CHECKSUM);
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100401
Stephen Warren712fbcf2011-10-18 11:11:49 +0000402 if (!image_check_os(rd_hdr, IH_OS_LINUX) ||
403 !image_check_arch(rd_hdr, arch) ||
404 !image_check_type(rd_hdr, IH_TYPE_RAMDISK)) {
405 printf("No Linux %s Ramdisk Image\n",
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100406 genimg_get_arch_name(arch));
Simon Glass770605e2012-02-13 13:51:18 +0000407 bootstage_error(BOOTSTAGE_ID_RAMDISK);
Kumar Gala274cea22008-02-27 21:51:46 -0600408 return NULL;
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100409 }
410
411 return rd_hdr;
412}
Marian Balakowicz570abb02008-02-29 15:59:59 +0100413#endif /* !USE_HOSTCC */
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100414
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100415/*****************************************************************************/
416/* Shared dual-format routines */
417/*****************************************************************************/
Marian Balakowicz570abb02008-02-29 15:59:59 +0100418#ifndef USE_HOSTCC
Stephen Warren712fbcf2011-10-18 11:11:49 +0000419int getenv_yesno(char *var)
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100420{
Stephen Warren712fbcf2011-10-18 11:11:49 +0000421 char *s = getenv(var);
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100422 return (s && (*s == 'n')) ? 0 : 1;
423}
424
425ulong getenv_bootm_low(void)
426{
Stephen Warren712fbcf2011-10-18 11:11:49 +0000427 char *s = getenv("bootm_low");
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100428 if (s) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000429 ulong tmp = simple_strtoul(s, NULL, 16);
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100430 return tmp;
431 }
432
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200433#if defined(CONFIG_SYS_SDRAM_BASE)
434 return CONFIG_SYS_SDRAM_BASE;
Marian Balakowiczafe45c82008-03-12 12:14:15 +0100435#elif defined(CONFIG_ARM)
436 return gd->bd->bi_dram[0].start;
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100437#else
438 return 0;
439#endif
440}
441
Becky Bruce391fd932008-06-09 20:37:18 -0500442phys_size_t getenv_bootm_size(void)
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100443{
Matthew McClintockc519fac2010-07-08 10:11:08 -0500444 phys_size_t tmp;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000445 char *s = getenv("bootm_size");
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100446 if (s) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000447 tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100448 return tmp;
449 }
Matthew McClintockc519fac2010-07-08 10:11:08 -0500450 s = getenv("bootm_low");
451 if (s)
Stephen Warren712fbcf2011-10-18 11:11:49 +0000452 tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
Matthew McClintockc519fac2010-07-08 10:11:08 -0500453 else
454 tmp = 0;
455
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100456
Marian Balakowiczafe45c82008-03-12 12:14:15 +0100457#if defined(CONFIG_ARM)
Matthew McClintockc519fac2010-07-08 10:11:08 -0500458 return gd->bd->bi_dram[0].size - tmp;
Marian Balakowiczafe45c82008-03-12 12:14:15 +0100459#else
Matthew McClintockc519fac2010-07-08 10:11:08 -0500460 return gd->bd->bi_memsize - tmp;
Marian Balakowiczafe45c82008-03-12 12:14:15 +0100461#endif
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100462}
463
Grant Likelyc3624e62011-03-28 09:58:43 +0000464phys_size_t getenv_bootm_mapsize(void)
465{
466 phys_size_t tmp;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000467 char *s = getenv("bootm_mapsize");
Grant Likelyc3624e62011-03-28 09:58:43 +0000468 if (s) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000469 tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
Grant Likelyc3624e62011-03-28 09:58:43 +0000470 return tmp;
471 }
472
473#if defined(CONFIG_SYS_BOOTMAPSZ)
474 return CONFIG_SYS_BOOTMAPSZ;
475#else
476 return getenv_bootm_size();
477#endif
478}
479
Stephen Warren712fbcf2011-10-18 11:11:49 +0000480void memmove_wd(void *to, void *from, size_t len, ulong chunksz)
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100481{
Larry Johnson54fa2c52010-04-20 08:09:43 -0400482 if (to == from)
483 return;
484
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100485#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
486 while (len > 0) {
487 size_t tail = (len > chunksz) ? chunksz : len;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000488 WATCHDOG_RESET();
489 memmove(to, from, tail);
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100490 to += tail;
491 from += tail;
492 len -= tail;
493 }
494#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000495 memmove(to, from, len);
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100496#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
497}
Marian Balakowicz570abb02008-02-29 15:59:59 +0100498#endif /* !USE_HOSTCC */
499
Stephen Warren712fbcf2011-10-18 11:11:49 +0000500void genimg_print_size(uint32_t size)
Marian Balakowicz570abb02008-02-29 15:59:59 +0100501{
502#ifndef USE_HOSTCC
Stephen Warren712fbcf2011-10-18 11:11:49 +0000503 printf("%d Bytes = ", size);
504 print_size(size, "\n");
Marian Balakowicz570abb02008-02-29 15:59:59 +0100505#else
Stephen Warren712fbcf2011-10-18 11:11:49 +0000506 printf("%d Bytes = %.2f kB = %.2f MB\n",
Marian Balakowicz570abb02008-02-29 15:59:59 +0100507 size, (double)size / 1.024e3,
508 (double)size / 1.048576e6);
509#endif
510}
511
512#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
Stephen Warren712fbcf2011-10-18 11:11:49 +0000513static void genimg_print_time(time_t timestamp)
Marian Balakowicz570abb02008-02-29 15:59:59 +0100514{
515#ifndef USE_HOSTCC
516 struct rtc_time tm;
517
Stephen Warren712fbcf2011-10-18 11:11:49 +0000518 to_tm(timestamp, &tm);
519 printf("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
Marian Balakowicz570abb02008-02-29 15:59:59 +0100520 tm.tm_year, tm.tm_mon, tm.tm_mday,
521 tm.tm_hour, tm.tm_min, tm.tm_sec);
522#else
Stephen Warren712fbcf2011-10-18 11:11:49 +0000523 printf("%s", ctime(&timestamp));
Marian Balakowicz570abb02008-02-29 15:59:59 +0100524#endif
525}
526#endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */
527
528/**
529 * get_table_entry_name - translate entry id to long name
530 * @table: pointer to a translation table for entries of a specific type
531 * @msg: message to be returned when translation fails
532 * @id: entry id to be translated
533 *
534 * get_table_entry_name() will go over translation table trying to find
535 * entry that matches given id. If matching entry is found, its long
536 * name is returned to the caller.
537 *
538 * returns:
539 * long entry name if translation succeeds
540 * msg otherwise
541 */
Mike Frysinger7edb1862010-10-20 07:17:39 -0400542char *get_table_entry_name(const table_entry_t *table, char *msg, int id)
Marian Balakowicz570abb02008-02-29 15:59:59 +0100543{
544 for (; table->id >= 0; ++table) {
545 if (table->id == id)
Wolfgang Denk2e5167c2010-10-28 20:00:11 +0200546#if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC)
Scott Woode3d1ac72009-04-02 16:15:10 -0500547 return table->lname;
548#else
549 return table->lname + gd->reloc_off;
550#endif
Marian Balakowicz570abb02008-02-29 15:59:59 +0100551 }
552 return (msg);
553}
554
Stephen Warren712fbcf2011-10-18 11:11:49 +0000555const char *genimg_get_os_name(uint8_t os)
Marian Balakowicz570abb02008-02-29 15:59:59 +0100556{
Stephen Warren712fbcf2011-10-18 11:11:49 +0000557 return (get_table_entry_name(uimage_os, "Unknown OS", os));
Marian Balakowicz570abb02008-02-29 15:59:59 +0100558}
559
Stephen Warren712fbcf2011-10-18 11:11:49 +0000560const char *genimg_get_arch_name(uint8_t arch)
Marian Balakowicz570abb02008-02-29 15:59:59 +0100561{
Stephen Warren712fbcf2011-10-18 11:11:49 +0000562 return (get_table_entry_name(uimage_arch, "Unknown Architecture",
563 arch));
Marian Balakowicz570abb02008-02-29 15:59:59 +0100564}
565
Stephen Warren712fbcf2011-10-18 11:11:49 +0000566const char *genimg_get_type_name(uint8_t type)
Marian Balakowicz570abb02008-02-29 15:59:59 +0100567{
Stephen Warren712fbcf2011-10-18 11:11:49 +0000568 return (get_table_entry_name(uimage_type, "Unknown Image", type));
Marian Balakowicz570abb02008-02-29 15:59:59 +0100569}
570
Stephen Warren712fbcf2011-10-18 11:11:49 +0000571const char *genimg_get_comp_name(uint8_t comp)
Marian Balakowicz570abb02008-02-29 15:59:59 +0100572{
Stephen Warren712fbcf2011-10-18 11:11:49 +0000573 return (get_table_entry_name(uimage_comp, "Unknown Compression",
574 comp));
Marian Balakowicz570abb02008-02-29 15:59:59 +0100575}
576
577/**
578 * get_table_entry_id - translate short entry name to id
579 * @table: pointer to a translation table for entries of a specific type
580 * @table_name: to be used in case of error
581 * @name: entry short name to be translated
582 *
583 * get_table_entry_id() will go over translation table trying to find
584 * entry that matches given short name. If matching entry is found,
585 * its id returned to the caller.
586 *
587 * returns:
588 * entry id if translation succeeds
589 * -1 otherwise
590 */
Mike Frysinger7edb1862010-10-20 07:17:39 -0400591int get_table_entry_id(const table_entry_t *table,
Marian Balakowicz570abb02008-02-29 15:59:59 +0100592 const char *table_name, const char *name)
593{
Mike Frysinger7edb1862010-10-20 07:17:39 -0400594 const table_entry_t *t;
Marian Balakowicz570abb02008-02-29 15:59:59 +0100595#ifdef USE_HOSTCC
596 int first = 1;
597
598 for (t = table; t->id >= 0; ++t) {
599 if (t->sname && strcasecmp(t->sname, name) == 0)
Stephen Warren712fbcf2011-10-18 11:11:49 +0000600 return(t->id);
Marian Balakowicz570abb02008-02-29 15:59:59 +0100601 }
602
Stephen Warren712fbcf2011-10-18 11:11:49 +0000603 fprintf(stderr, "\nInvalid %s Type - valid names are", table_name);
Marian Balakowicz570abb02008-02-29 15:59:59 +0100604 for (t = table; t->id >= 0; ++t) {
605 if (t->sname == NULL)
606 continue;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000607 fprintf(stderr, "%c %s", (first) ? ':' : ',', t->sname);
Marian Balakowicz570abb02008-02-29 15:59:59 +0100608 first = 0;
609 }
Stephen Warren712fbcf2011-10-18 11:11:49 +0000610 fprintf(stderr, "\n");
Marian Balakowicz570abb02008-02-29 15:59:59 +0100611#else
612 for (t = table; t->id >= 0; ++t) {
Wolfgang Denk2e5167c2010-10-28 20:00:11 +0200613#ifdef CONFIG_NEEDS_MANUAL_RELOC
Scott Woode3d1ac72009-04-02 16:15:10 -0500614 if (t->sname && strcmp(t->sname + gd->reloc_off, name) == 0)
Wolfgang Denk2e5167c2010-10-28 20:00:11 +0200615#else
616 if (t->sname && strcmp(t->sname, name) == 0)
Peter Tyser521af042009-09-21 11:20:36 -0500617#endif
Marian Balakowicz570abb02008-02-29 15:59:59 +0100618 return (t->id);
619 }
Stephen Warren712fbcf2011-10-18 11:11:49 +0000620 debug("Invalid %s Type: %s\n", table_name, name);
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100621#endif /* USE_HOSTCC */
Marian Balakowicz570abb02008-02-29 15:59:59 +0100622 return (-1);
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100623}
624
Stephen Warren712fbcf2011-10-18 11:11:49 +0000625int genimg_get_os_id(const char *name)
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100626{
Stephen Warren712fbcf2011-10-18 11:11:49 +0000627 return (get_table_entry_id(uimage_os, "OS", name));
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100628}
629
Stephen Warren712fbcf2011-10-18 11:11:49 +0000630int genimg_get_arch_id(const char *name)
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100631{
Stephen Warren712fbcf2011-10-18 11:11:49 +0000632 return (get_table_entry_id(uimage_arch, "CPU", name));
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100633}
634
Stephen Warren712fbcf2011-10-18 11:11:49 +0000635int genimg_get_type_id(const char *name)
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100636{
Stephen Warren712fbcf2011-10-18 11:11:49 +0000637 return (get_table_entry_id(uimage_type, "Image", name));
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100638}
639
Stephen Warren712fbcf2011-10-18 11:11:49 +0000640int genimg_get_comp_id(const char *name)
Marian Balakowicz570abb02008-02-29 15:59:59 +0100641{
Stephen Warren712fbcf2011-10-18 11:11:49 +0000642 return (get_table_entry_id(uimage_comp, "Compression", name));
Marian Balakowicz570abb02008-02-29 15:59:59 +0100643}
644
645#ifndef USE_HOSTCC
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100646/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100647 * genimg_get_format - get image format type
648 * @img_addr: image start address
649 *
650 * genimg_get_format() checks whether provided address points to a valid
651 * legacy or FIT image.
652 *
653 * New uImage format and FDT blob are based on a libfdt. FDT blob
654 * may be passed directly or embedded in a FIT image. In both situations
655 * genimg_get_format() must be able to dectect libfdt header.
656 *
657 * returns:
658 * image format type or IMAGE_FORMAT_INVALID if no image is present
659 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000660int genimg_get_format(void *img_addr)
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100661{
Wolfgang Denk3a2003f2009-08-19 11:42:56 +0200662 ulong format = IMAGE_FORMAT_INVALID;
663 const image_header_t *hdr;
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100664#if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
Wolfgang Denk3a2003f2009-08-19 11:42:56 +0200665 char *fit_hdr;
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100666#endif
667
Wolfgang Denk3a2003f2009-08-19 11:42:56 +0200668 hdr = (const image_header_t *)img_addr;
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100669 if (image_check_magic(hdr))
670 format = IMAGE_FORMAT_LEGACY;
671#if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
672 else {
673 fit_hdr = (char *)img_addr;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000674 if (fdt_check_header(fit_hdr) == 0)
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100675 format = IMAGE_FORMAT_FIT;
676 }
677#endif
678
679 return format;
680}
681
682/**
683 * genimg_get_image - get image from special storage (if necessary)
684 * @img_addr: image start address
685 *
686 * genimg_get_image() checks if provided image start adddress is located
687 * in a dataflash storage. If so, image is moved to a system RAM memory.
688 *
689 * returns:
690 * image start address after possible relocation from special storage
691 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000692ulong genimg_get_image(ulong img_addr)
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100693{
694 ulong ram_addr = img_addr;
695
696#ifdef CONFIG_HAS_DATAFLASH
697 ulong h_size, d_size;
698
Stephen Warren712fbcf2011-10-18 11:11:49 +0000699 if (addr_dataflash(img_addr)) {
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100700 /* ger RAM address */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200701 ram_addr = CONFIG_SYS_LOAD_ADDR;
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100702
703 /* get header size */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000704 h_size = image_get_header_size();
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100705#if defined(CONFIG_FIT)
706 if (sizeof(struct fdt_header) > h_size)
707 h_size = sizeof(struct fdt_header);
708#endif
709
710 /* read in header */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000711 debug(" Reading image header from dataflash address "
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100712 "%08lx to RAM address %08lx\n", img_addr, ram_addr);
713
Stephen Warren712fbcf2011-10-18 11:11:49 +0000714 read_dataflash(img_addr, h_size, (char *)ram_addr);
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100715
716 /* get data size */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000717 switch (genimg_get_format((void *)ram_addr)) {
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100718 case IMAGE_FORMAT_LEGACY:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000719 d_size = image_get_data_size(
720 (const image_header_t *)ram_addr);
721 debug(" Legacy format image found at 0x%08lx, "
722 "size 0x%08lx\n",
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100723 ram_addr, d_size);
724 break;
725#if defined(CONFIG_FIT)
726 case IMAGE_FORMAT_FIT:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000727 d_size = fit_get_size((const void *)ram_addr) - h_size;
728 debug(" FIT/FDT format image found at 0x%08lx, "
729 "size 0x%08lx\n",
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100730 ram_addr, d_size);
731 break;
732#endif
733 default:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000734 printf(" No valid image found at 0x%08lx\n",
735 img_addr);
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100736 return ram_addr;
737 }
738
739 /* read in image data */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000740 debug(" Reading image remaining data from dataflash address "
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100741 "%08lx to RAM address %08lx\n", img_addr + h_size,
742 ram_addr + h_size);
743
Stephen Warren712fbcf2011-10-18 11:11:49 +0000744 read_dataflash(img_addr + h_size, d_size,
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100745 (char *)(ram_addr + h_size));
746
747 }
748#endif /* CONFIG_HAS_DATAFLASH */
749
750 return ram_addr;
751}
752
753/**
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100754 * fit_has_config - check if there is a valid FIT configuration
755 * @images: pointer to the bootm command headers structure
756 *
757 * fit_has_config() checks if there is a FIT configuration in use
758 * (if FTI support is present).
759 *
760 * returns:
761 * 0, no FIT support or no configuration found
762 * 1, configuration found
763 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000764int genimg_has_config(bootm_headers_t *images)
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100765{
766#if defined(CONFIG_FIT)
767 if (images->fit_uname_cfg)
768 return 1;
769#endif
770 return 0;
771}
772
773/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100774 * boot_get_ramdisk - main ramdisk handling routine
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100775 * @argc: command argument count
776 * @argv: command argument list
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100777 * @images: pointer to the bootm images structure
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100778 * @arch: expected ramdisk architecture
779 * @rd_start: pointer to a ulong variable, will hold ramdisk start address
780 * @rd_end: pointer to a ulong variable, will hold ramdisk end
781 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100782 * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100783 * Curently supported are the following ramdisk sources:
784 * - multicomponent kernel/ramdisk image,
785 * - commandline provided address of decicated ramdisk image.
786 *
787 * returns:
Marian Balakowiczd985c842008-03-12 10:14:38 +0100788 * 0, if ramdisk image was found and valid, or skiped
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100789 * rd_start and rd_end are set to ramdisk start/end addresses if
790 * ramdisk image is found and valid
Marian Balakowiczd985c842008-03-12 10:14:38 +0100791 *
Kumar Galaea86b9e2008-08-29 19:08:29 -0500792 * 1, if ramdisk image is found but corrupted, or invalid
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100793 * rd_start and rd_end are set to 0 if no ramdisk exists
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100794 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000795int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
Marian Balakowiczd985c842008-03-12 10:14:38 +0100796 uint8_t arch, ulong *rd_start, ulong *rd_end)
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100797{
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100798 ulong rd_addr, rd_load;
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100799 ulong rd_data, rd_len;
Wolfgang Denk3a2003f2009-08-19 11:42:56 +0200800 const image_header_t *rd_hdr;
Marek Vasut57d40ab2012-03-30 23:19:10 +0200801#ifdef CONFIG_SUPPORT_RAW_INITRD
Marek Vasut017e1f32012-03-18 11:47:58 +0000802 char *end;
Marek Vasut57d40ab2012-03-30 23:19:10 +0200803#endif
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100804#if defined(CONFIG_FIT)
805 void *fit_hdr;
806 const char *fit_uname_config = NULL;
807 const char *fit_uname_ramdisk = NULL;
808 ulong default_addr;
Marian Balakowiczc8779642008-03-12 10:12:37 +0100809 int rd_noffset;
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100810 int cfg_noffset;
Marian Balakowiczc8779642008-03-12 10:12:37 +0100811 const void *data;
812 size_t size;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100813#endif
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100814
Marian Balakowiczc8779642008-03-12 10:12:37 +0100815 *rd_start = 0;
816 *rd_end = 0;
817
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100818 /*
819 * Look for a '-' which indicates to ignore the
820 * ramdisk argument
821 */
822 if ((argc >= 3) && (strcmp(argv[2], "-") == 0)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000823 debug("## Skipping init Ramdisk\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100824 rd_len = rd_data = 0;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000825 } else if (argc >= 3 || genimg_has_config(images)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100826#if defined(CONFIG_FIT)
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100827 if (argc >= 3) {
828 /*
829 * If the init ramdisk comes from the FIT image and
830 * the FIT image address is omitted in the command
831 * line argument, try to use os FIT image address or
832 * default load address.
833 */
834 if (images->fit_uname_os)
835 default_addr = (ulong)images->fit_hdr_os;
836 else
837 default_addr = load_addr;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100838
Stephen Warren712fbcf2011-10-18 11:11:49 +0000839 if (fit_parse_conf(argv[2], default_addr,
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100840 &rd_addr, &fit_uname_config)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000841 debug("* ramdisk: config '%s' from image at "
842 "0x%08lx\n",
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100843 fit_uname_config, rd_addr);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000844 } else if (fit_parse_subimage(argv[2], default_addr,
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100845 &rd_addr, &fit_uname_ramdisk)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000846 debug("* ramdisk: subimage '%s' from image at "
847 "0x%08lx\n",
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100848 fit_uname_ramdisk, rd_addr);
849 } else
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100850#endif
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100851 {
852 rd_addr = simple_strtoul(argv[2], NULL, 16);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000853 debug("* ramdisk: cmdline image address = "
854 "0x%08lx\n",
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100855 rd_addr);
856 }
857#if defined(CONFIG_FIT)
858 } else {
859 /* use FIT configuration provided in first bootm
860 * command argument
861 */
862 rd_addr = (ulong)images->fit_hdr_os;
863 fit_uname_config = images->fit_uname_cfg;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000864 debug("* ramdisk: using config '%s' from image "
865 "at 0x%08lx\n",
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100866 fit_uname_config, rd_addr);
867
868 /*
869 * Check whether configuration has ramdisk defined,
870 * if not, don't try to use it, quit silently.
871 */
872 fit_hdr = (void *)rd_addr;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000873 cfg_noffset = fit_conf_get_node(fit_hdr,
874 fit_uname_config);
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100875 if (cfg_noffset < 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000876 debug("* ramdisk: no such config\n");
Michal Simekc78fce62008-07-11 10:43:13 +0200877 return 1;
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100878 }
879
Stephen Warren712fbcf2011-10-18 11:11:49 +0000880 rd_noffset = fit_conf_get_ramdisk_node(fit_hdr,
881 cfg_noffset);
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100882 if (rd_noffset < 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000883 debug("* ramdisk: no ramdisk in config\n");
Peter Tyser41266c92008-08-05 10:51:57 -0500884 return 0;
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100885 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100886 }
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100887#endif
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100888
889 /* copy from dataflash if needed */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000890 rd_addr = genimg_get_image(rd_addr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100891
892 /*
893 * Check if there is an initrd image at the
894 * address provided in the second bootm argument
895 * check image type, for FIT images get FIT node.
896 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000897 switch (genimg_get_format((void *)rd_addr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100898 case IMAGE_FORMAT_LEGACY:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000899 printf("## Loading init Ramdisk from Legacy "
Marian Balakowiczc8779642008-03-12 10:12:37 +0100900 "Image at %08lx ...\n", rd_addr);
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100901
Simon Glass770605e2012-02-13 13:51:18 +0000902 bootstage_mark(BOOTSTAGE_ID_CHECK_RAMDISK);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000903 rd_hdr = image_get_ramdisk(rd_addr, arch,
Marian Balakowiczd985c842008-03-12 10:14:38 +0100904 images->verify);
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100905
Marian Balakowiczc8779642008-03-12 10:12:37 +0100906 if (rd_hdr == NULL)
Kumar Gala274cea22008-02-27 21:51:46 -0600907 return 1;
Kumar Gala274cea22008-02-27 21:51:46 -0600908
Stephen Warren712fbcf2011-10-18 11:11:49 +0000909 rd_data = image_get_data(rd_hdr);
910 rd_len = image_get_data_size(rd_hdr);
911 rd_load = image_get_load(rd_hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100912 break;
913#if defined(CONFIG_FIT)
914 case IMAGE_FORMAT_FIT:
915 fit_hdr = (void *)rd_addr;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000916 printf("## Loading init Ramdisk from FIT "
Marian Balakowiczc8779642008-03-12 10:12:37 +0100917 "Image at %08lx ...\n", rd_addr);
918
Simon Glass770605e2012-02-13 13:51:18 +0000919 bootstage_mark(BOOTSTAGE_ID_FIT_RD_FORMAT);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000920 if (!fit_check_format(fit_hdr)) {
921 puts("Bad FIT ramdisk image format!\n");
Simon Glass770605e2012-02-13 13:51:18 +0000922 bootstage_error(
Simon Glassaacc8c12011-12-10 11:08:02 +0000923 BOOTSTAGE_ID_FIT_RD_FORMAT);
Michal Simekc78fce62008-07-11 10:43:13 +0200924 return 1;
Marian Balakowiczc8779642008-03-12 10:12:37 +0100925 }
Simon Glass770605e2012-02-13 13:51:18 +0000926 bootstage_mark(BOOTSTAGE_ID_FIT_RD_FORMAT_OK);
Marian Balakowiczc8779642008-03-12 10:12:37 +0100927
928 if (!fit_uname_ramdisk) {
929 /*
930 * no ramdisk image node unit name, try to get config
931 * node first. If config unit node name is NULL
932 * fit_conf_get_node() will try to find default config node
933 */
Simon Glass770605e2012-02-13 13:51:18 +0000934 bootstage_mark(
Simon Glassaacc8c12011-12-10 11:08:02 +0000935 BOOTSTAGE_ID_FIT_RD_NO_UNIT_NAME);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000936 cfg_noffset = fit_conf_get_node(fit_hdr,
937 fit_uname_config);
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100938 if (cfg_noffset < 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000939 puts("Could not find configuration "
940 "node\n");
Simon Glass770605e2012-02-13 13:51:18 +0000941 bootstage_error(
Simon Glassaacc8c12011-12-10 11:08:02 +0000942 BOOTSTAGE_ID_FIT_RD_NO_UNIT_NAME);
Michal Simekc78fce62008-07-11 10:43:13 +0200943 return 1;
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100944 }
Stephen Warren712fbcf2011-10-18 11:11:49 +0000945 fit_uname_config = fdt_get_name(fit_hdr,
946 cfg_noffset, NULL);
947 printf(" Using '%s' configuration\n",
948 fit_uname_config);
Marian Balakowiczc8779642008-03-12 10:12:37 +0100949
Stephen Warren712fbcf2011-10-18 11:11:49 +0000950 rd_noffset = fit_conf_get_ramdisk_node(fit_hdr,
951 cfg_noffset);
952 fit_uname_ramdisk = fit_get_name(fit_hdr,
953 rd_noffset, NULL);
Marian Balakowiczc8779642008-03-12 10:12:37 +0100954 } else {
955 /* get ramdisk component image node offset */
Simon Glass770605e2012-02-13 13:51:18 +0000956 bootstage_mark(
Simon Glassaacc8c12011-12-10 11:08:02 +0000957 BOOTSTAGE_ID_FIT_RD_UNIT_NAME);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000958 rd_noffset = fit_image_get_node(fit_hdr,
959 fit_uname_ramdisk);
Marian Balakowiczc8779642008-03-12 10:12:37 +0100960 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100961 if (rd_noffset < 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000962 puts("Could not find subimage node\n");
Simon Glass770605e2012-02-13 13:51:18 +0000963 bootstage_error(BOOTSTAGE_ID_FIT_RD_SUBNODE);
Michal Simekc78fce62008-07-11 10:43:13 +0200964 return 1;
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100965 }
Marian Balakowiczc8779642008-03-12 10:12:37 +0100966
Stephen Warren712fbcf2011-10-18 11:11:49 +0000967 printf(" Trying '%s' ramdisk subimage\n",
968 fit_uname_ramdisk);
Marian Balakowiczc8779642008-03-12 10:12:37 +0100969
Simon Glass770605e2012-02-13 13:51:18 +0000970 bootstage_mark(BOOTSTAGE_ID_FIT_RD_CHECK);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000971 if (!fit_check_ramdisk(fit_hdr, rd_noffset, arch,
972 images->verify))
Michal Simekc78fce62008-07-11 10:43:13 +0200973 return 1;
Marian Balakowiczc8779642008-03-12 10:12:37 +0100974
975 /* get ramdisk image data address and length */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000976 if (fit_image_get_data(fit_hdr, rd_noffset, &data,
977 &size)) {
978 puts("Could not find ramdisk subimage data!\n");
Simon Glass770605e2012-02-13 13:51:18 +0000979 bootstage_error(BOOTSTAGE_ID_FIT_RD_GET_DATA);
Michal Simekc78fce62008-07-11 10:43:13 +0200980 return 1;
Marian Balakowiczc8779642008-03-12 10:12:37 +0100981 }
Simon Glass770605e2012-02-13 13:51:18 +0000982 bootstage_mark(BOOTSTAGE_ID_FIT_RD_GET_DATA_OK);
Marian Balakowiczc8779642008-03-12 10:12:37 +0100983
984 rd_data = (ulong)data;
985 rd_len = size;
986
Stephen Warren712fbcf2011-10-18 11:11:49 +0000987 if (fit_image_get_load(fit_hdr, rd_noffset, &rd_load)) {
988 puts("Can't get ramdisk subimage load "
989 "address!\n");
Simon Glass770605e2012-02-13 13:51:18 +0000990 bootstage_error(BOOTSTAGE_ID_FIT_RD_LOAD);
Michal Simekc78fce62008-07-11 10:43:13 +0200991 return 1;
Marian Balakowiczc8779642008-03-12 10:12:37 +0100992 }
Simon Glass770605e2012-02-13 13:51:18 +0000993 bootstage_mark(BOOTSTAGE_ID_FIT_RD_LOAD);
Marian Balakowiczc8779642008-03-12 10:12:37 +0100994
995 images->fit_hdr_rd = fit_hdr;
996 images->fit_uname_rd = fit_uname_ramdisk;
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100997 images->fit_noffset_rd = rd_noffset;
Marian Balakowiczc8779642008-03-12 10:12:37 +0100998 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100999#endif
1000 default:
Marek Vasut017e1f32012-03-18 11:47:58 +00001001#ifdef CONFIG_SUPPORT_RAW_INITRD
1002 if (argc >= 3 && (end = strchr(argv[2], ':'))) {
1003 rd_len = simple_strtoul(++end, NULL, 16);
1004 rd_data = rd_addr;
1005 } else
1006#endif
1007 {
1008 puts("Wrong Ramdisk Image Format\n");
1009 rd_data = rd_len = rd_load = 0;
1010 return 1;
1011 }
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +01001012 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001013 } else if (images->legacy_hdr_valid &&
Stephen Warren712fbcf2011-10-18 11:11:49 +00001014 image_check_type(&images->legacy_hdr_os_copy,
1015 IH_TYPE_MULTI)) {
1016
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001017 /*
1018 * Now check if we have a legacy mult-component image,
1019 * get second entry data start address and len.
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +01001020 */
Simon Glass770605e2012-02-13 13:51:18 +00001021 bootstage_mark(BOOTSTAGE_ID_RAMDISK);
Stephen Warren712fbcf2011-10-18 11:11:49 +00001022 printf("## Loading init Ramdisk from multi component "
Marian Balakowiczc8779642008-03-12 10:12:37 +01001023 "Legacy Image at %08lx ...\n",
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001024 (ulong)images->legacy_hdr_os);
1025
Stephen Warren712fbcf2011-10-18 11:11:49 +00001026 image_multi_getimg(images->legacy_hdr_os, 1, &rd_data, &rd_len);
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +01001027 } else {
1028 /*
1029 * no initrd image
1030 */
Simon Glass770605e2012-02-13 13:51:18 +00001031 bootstage_mark(BOOTSTAGE_ID_NO_RAMDISK);
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +01001032 rd_len = rd_data = 0;
1033 }
1034
1035 if (!rd_data) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001036 debug("## No init Ramdisk\n");
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +01001037 } else {
1038 *rd_start = rd_data;
1039 *rd_end = rd_data + rd_len;
1040 }
Stephen Warren712fbcf2011-10-18 11:11:49 +00001041 debug(" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +01001042 *rd_start, *rd_end);
Kumar Gala274cea22008-02-27 21:51:46 -06001043
1044 return 0;
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +01001045}
Marian Balakowiczceaed2b2008-01-31 13:57:17 +01001046
John Rigbyfca43cc2010-10-13 13:57:35 -06001047#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
Marian Balakowiczceaed2b2008-01-31 13:57:17 +01001048/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +01001049 * boot_ramdisk_high - relocate init ramdisk
Kumar Galae822d7f2008-02-27 21:51:49 -06001050 * @lmb: pointer to lmb handle, will be used for memory mgmt
Marian Balakowiczceaed2b2008-01-31 13:57:17 +01001051 * @rd_data: ramdisk data start address
1052 * @rd_len: ramdisk data length
Marian Balakowiczceaed2b2008-01-31 13:57:17 +01001053 * @initrd_start: pointer to a ulong variable, will hold final init ramdisk
1054 * start address (after possible relocation)
1055 * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
1056 * end address (after possible relocation)
1057 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +01001058 * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement
Marian Balakowiczceaed2b2008-01-31 13:57:17 +01001059 * variable and if requested ramdisk data is moved to a specified location.
1060 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +01001061 * Initrd_start and initrd_end are set to final (after relocation) ramdisk
1062 * start/end addresses if ramdisk image start and len were provided,
1063 * otherwise set initrd_start and initrd_end set to zeros.
1064 *
Marian Balakowiczceaed2b2008-01-31 13:57:17 +01001065 * returns:
Marian Balakowicz9a4daad2008-02-29 14:58:34 +01001066 * 0 - success
1067 * -1 - failure
Marian Balakowiczceaed2b2008-01-31 13:57:17 +01001068 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001069int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len,
Kumar Galae822d7f2008-02-27 21:51:49 -06001070 ulong *initrd_start, ulong *initrd_end)
Marian Balakowiczceaed2b2008-01-31 13:57:17 +01001071{
1072 char *s;
1073 ulong initrd_high;
1074 int initrd_copy_to_ram = 1;
1075
Stephen Warren712fbcf2011-10-18 11:11:49 +00001076 if ((s = getenv("initrd_high")) != NULL) {
Marian Balakowiczceaed2b2008-01-31 13:57:17 +01001077 /* a value of "no" or a similar string will act like 0,
1078 * turning the "load high" feature off. This is intentional.
1079 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001080 initrd_high = simple_strtoul(s, NULL, 16);
Marian Balakowiczceaed2b2008-01-31 13:57:17 +01001081 if (initrd_high == ~0)
1082 initrd_copy_to_ram = 0;
1083 } else {
1084 /* not set, no restrictions to load high */
1085 initrd_high = ~0;
1086 }
1087
Marian Balakowicz95d449a2008-05-13 15:53:29 +02001088
1089#ifdef CONFIG_LOGBUFFER
1090 /* Prevent initrd from overwriting logbuffer */
1091 lmb_reserve(lmb, logbuffer_base() - LOGBUFF_OVERHEAD, LOGBUFF_RESERVE);
1092#endif
1093
Stephen Warren712fbcf2011-10-18 11:11:49 +00001094 debug("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
Marian Balakowiczceaed2b2008-01-31 13:57:17 +01001095 initrd_high, initrd_copy_to_ram);
1096
1097 if (rd_data) {
1098 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001099 debug(" in-place initrd\n");
Marian Balakowiczceaed2b2008-01-31 13:57:17 +01001100 *initrd_start = rd_data;
1101 *initrd_end = rd_data + rd_len;
Kumar Galae822d7f2008-02-27 21:51:49 -06001102 lmb_reserve(lmb, rd_data, rd_len);
Marian Balakowiczceaed2b2008-01-31 13:57:17 +01001103 } else {
Kumar Galae822d7f2008-02-27 21:51:49 -06001104 if (initrd_high)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001105 *initrd_start = (ulong)lmb_alloc_base(lmb,
1106 rd_len, 0x1000, initrd_high);
Kumar Galae822d7f2008-02-27 21:51:49 -06001107 else
Stephen Warren712fbcf2011-10-18 11:11:49 +00001108 *initrd_start = (ulong)lmb_alloc(lmb, rd_len,
1109 0x1000);
Marian Balakowiczceaed2b2008-01-31 13:57:17 +01001110
Kumar Galae822d7f2008-02-27 21:51:49 -06001111 if (*initrd_start == 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001112 puts("ramdisk - allocation error\n");
Kumar Galae822d7f2008-02-27 21:51:49 -06001113 goto error;
Marian Balakowiczceaed2b2008-01-31 13:57:17 +01001114 }
Simon Glass770605e2012-02-13 13:51:18 +00001115 bootstage_mark(BOOTSTAGE_ID_COPY_RAMDISK);
Marian Balakowiczceaed2b2008-01-31 13:57:17 +01001116
1117 *initrd_end = *initrd_start + rd_len;
Stephen Warren712fbcf2011-10-18 11:11:49 +00001118 printf(" Loading Ramdisk to %08lx, end %08lx ... ",
Marian Balakowiczceaed2b2008-01-31 13:57:17 +01001119 *initrd_start, *initrd_end);
1120
Stephen Warren712fbcf2011-10-18 11:11:49 +00001121 memmove_wd((void *)*initrd_start,
Marian Balakowiczceaed2b2008-01-31 13:57:17 +01001122 (void *)rd_data, rd_len, CHUNKSZ);
1123
Kumar Gala3b200112011-12-07 04:42:58 +00001124#ifdef CONFIG_MP
1125 /*
1126 * Ensure the image is flushed to memory to handle
1127 * AMP boot scenarios in which we might not be
1128 * HW cache coherent
1129 */
1130 flush_cache((unsigned long)*initrd_start, rd_len);
1131#endif
Stephen Warren712fbcf2011-10-18 11:11:49 +00001132 puts("OK\n");
Marian Balakowiczceaed2b2008-01-31 13:57:17 +01001133 }
1134 } else {
1135 *initrd_start = 0;
1136 *initrd_end = 0;
1137 }
Stephen Warren712fbcf2011-10-18 11:11:49 +00001138 debug(" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
Marian Balakowiczceaed2b2008-01-31 13:57:17 +01001139 *initrd_start, *initrd_end);
Marian Balakowicz9a4daad2008-02-29 14:58:34 +01001140
Kumar Galae822d7f2008-02-27 21:51:49 -06001141 return 0;
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +01001142
Kumar Galae822d7f2008-02-27 21:51:49 -06001143error:
1144 return -1;
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +01001145}
John Rigbyfca43cc2010-10-13 13:57:35 -06001146#endif /* CONFIG_SYS_BOOT_RAMDISK_HIGH */
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +01001147
Kumar Gala06a09912008-08-15 08:24:38 -05001148#ifdef CONFIG_OF_LIBFDT
Stephen Warren712fbcf2011-10-18 11:11:49 +00001149static void fdt_error(const char *msg)
Kumar Gala06a09912008-08-15 08:24:38 -05001150{
Stephen Warren712fbcf2011-10-18 11:11:49 +00001151 puts("ERROR: ");
1152 puts(msg);
1153 puts(" - must RESET the board to recover.\n");
Kumar Gala06a09912008-08-15 08:24:38 -05001154}
1155
Stephen Warren712fbcf2011-10-18 11:11:49 +00001156static const image_header_t *image_get_fdt(ulong fdt_addr)
Kumar Gala06a09912008-08-15 08:24:38 -05001157{
Wolfgang Denk3a2003f2009-08-19 11:42:56 +02001158 const image_header_t *fdt_hdr = (const image_header_t *)fdt_addr;
Kumar Gala06a09912008-08-15 08:24:38 -05001159
Stephen Warren712fbcf2011-10-18 11:11:49 +00001160 image_print_contents(fdt_hdr);
Kumar Gala06a09912008-08-15 08:24:38 -05001161
Stephen Warren712fbcf2011-10-18 11:11:49 +00001162 puts(" Verifying Checksum ... ");
1163 if (!image_check_hcrc(fdt_hdr)) {
1164 fdt_error("fdt header checksum invalid");
Kumar Gala06a09912008-08-15 08:24:38 -05001165 return NULL;
1166 }
1167
Stephen Warren712fbcf2011-10-18 11:11:49 +00001168 if (!image_check_dcrc(fdt_hdr)) {
1169 fdt_error("fdt checksum invalid");
Kumar Gala06a09912008-08-15 08:24:38 -05001170 return NULL;
1171 }
Stephen Warren712fbcf2011-10-18 11:11:49 +00001172 puts("OK\n");
Kumar Gala06a09912008-08-15 08:24:38 -05001173
Stephen Warren712fbcf2011-10-18 11:11:49 +00001174 if (!image_check_type(fdt_hdr, IH_TYPE_FLATDT)) {
1175 fdt_error("uImage is not a fdt");
Kumar Gala06a09912008-08-15 08:24:38 -05001176 return NULL;
1177 }
Stephen Warren712fbcf2011-10-18 11:11:49 +00001178 if (image_get_comp(fdt_hdr) != IH_COMP_NONE) {
1179 fdt_error("uImage is compressed");
Kumar Gala06a09912008-08-15 08:24:38 -05001180 return NULL;
1181 }
Stephen Warren712fbcf2011-10-18 11:11:49 +00001182 if (fdt_check_header((char *)image_get_data(fdt_hdr)) != 0) {
1183 fdt_error("uImage data is not a fdt");
Kumar Gala06a09912008-08-15 08:24:38 -05001184 return NULL;
1185 }
1186 return fdt_hdr;
1187}
1188
1189/**
1190 * fit_check_fdt - verify FIT format FDT subimage
1191 * @fit_hdr: pointer to the FIT header
1192 * fdt_noffset: FDT subimage node offset within FIT image
1193 * @verify: data CRC verification flag
1194 *
1195 * fit_check_fdt() verifies integrity of the FDT subimage and from
1196 * specified FIT image.
1197 *
1198 * returns:
1199 * 1, on success
1200 * 0, on failure
1201 */
1202#if defined(CONFIG_FIT)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001203static int fit_check_fdt(const void *fit, int fdt_noffset, int verify)
Kumar Gala06a09912008-08-15 08:24:38 -05001204{
Stephen Warren712fbcf2011-10-18 11:11:49 +00001205 fit_image_print(fit, fdt_noffset, " ");
Kumar Gala06a09912008-08-15 08:24:38 -05001206
1207 if (verify) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001208 puts(" Verifying Hash Integrity ... ");
1209 if (!fit_image_check_hashes(fit, fdt_noffset)) {
1210 fdt_error("Bad Data Hash");
Kumar Gala06a09912008-08-15 08:24:38 -05001211 return 0;
1212 }
Stephen Warren712fbcf2011-10-18 11:11:49 +00001213 puts("OK\n");
Kumar Gala06a09912008-08-15 08:24:38 -05001214 }
1215
Stephen Warren712fbcf2011-10-18 11:11:49 +00001216 if (!fit_image_check_type(fit, fdt_noffset, IH_TYPE_FLATDT)) {
1217 fdt_error("Not a FDT image");
Kumar Gala06a09912008-08-15 08:24:38 -05001218 return 0;
1219 }
1220
Stephen Warren712fbcf2011-10-18 11:11:49 +00001221 if (!fit_image_check_comp(fit, fdt_noffset, IH_COMP_NONE)) {
1222 fdt_error("FDT image is compressed");
Kumar Gala06a09912008-08-15 08:24:38 -05001223 return 0;
1224 }
1225
1226 return 1;
1227}
1228#endif /* CONFIG_FIT */
1229
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001230#ifndef CONFIG_SYS_FDT_PAD
1231#define CONFIG_SYS_FDT_PAD 0x3000
Kumar Gala06a09912008-08-15 08:24:38 -05001232#endif
1233
Grant Likely55b0a392011-03-28 09:59:01 +00001234#if defined(CONFIG_OF_LIBFDT)
1235/**
1236 * boot_fdt_add_mem_rsv_regions - Mark the memreserve sections as unusable
1237 * @lmb: pointer to lmb handle, will be used for memory mgmt
1238 * @fdt_blob: pointer to fdt blob base address
1239 *
1240 * Adds the memreserve regions in the dtb to the lmb block. Adding the
1241 * memreserve regions prevents u-boot from using them to store the initrd
1242 * or the fdt blob.
1243 */
1244void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob)
1245{
1246 uint64_t addr, size;
1247 int i, total;
1248
Stephen Warren712fbcf2011-10-18 11:11:49 +00001249 if (fdt_check_header(fdt_blob) != 0)
Grant Likely55b0a392011-03-28 09:59:01 +00001250 return;
1251
1252 total = fdt_num_mem_rsv(fdt_blob);
1253 for (i = 0; i < total; i++) {
1254 if (fdt_get_mem_rsv(fdt_blob, i, &addr, &size) != 0)
1255 continue;
1256 printf(" reserving fdt memory region: addr=%llx size=%llx\n",
1257 (unsigned long long)addr, (unsigned long long)size);
1258 lmb_reserve(lmb, addr, size);
1259 }
1260}
1261
Kumar Gala06a09912008-08-15 08:24:38 -05001262/**
1263 * boot_relocate_fdt - relocate flat device tree
1264 * @lmb: pointer to lmb handle, will be used for memory mgmt
Kumar Gala06a09912008-08-15 08:24:38 -05001265 * @of_flat_tree: pointer to a char* variable, will hold fdt start address
1266 * @of_size: pointer to a ulong variable, will hold fdt length
1267 *
Timur Tabi43b08af2010-05-24 15:10:25 -05001268 * boot_relocate_fdt() allocates a region of memory within the bootmap and
1269 * relocates the of_flat_tree into that region, even if the fdt is already in
1270 * the bootmap. It also expands the size of the fdt by CONFIG_SYS_FDT_PAD
1271 * bytes.
Kumar Gala06a09912008-08-15 08:24:38 -05001272 *
1273 * of_flat_tree and of_size are set to final (after relocation) values
1274 *
1275 * returns:
1276 * 0 - success
1277 * 1 - failure
1278 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001279int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size)
Kumar Gala06a09912008-08-15 08:24:38 -05001280{
Timur Tabi43b08af2010-05-24 15:10:25 -05001281 void *fdt_blob = *of_flat_tree;
1282 void *of_start = 0;
David A. Longa28afca2011-07-09 16:40:19 -04001283 char *fdt_high;
Kumar Gala06a09912008-08-15 08:24:38 -05001284 ulong of_len = 0;
Timur Tabi43b08af2010-05-24 15:10:25 -05001285 int err;
David A. Longa28afca2011-07-09 16:40:19 -04001286 int disable_relocation = 0;
Kumar Gala06a09912008-08-15 08:24:38 -05001287
1288 /* nothing to do */
1289 if (*of_size == 0)
1290 return 0;
1291
Stephen Warren712fbcf2011-10-18 11:11:49 +00001292 if (fdt_check_header(fdt_blob) != 0) {
1293 fdt_error("image is not a fdt");
Kumar Gala06a09912008-08-15 08:24:38 -05001294 goto error;
1295 }
1296
Timur Tabi43b08af2010-05-24 15:10:25 -05001297 /* position on a 4K boundary before the alloc_current */
1298 /* Pad the FDT by a specified amount */
1299 of_len = *of_size + CONFIG_SYS_FDT_PAD;
David A. Longa28afca2011-07-09 16:40:19 -04001300
1301 /* If fdt_high is set use it to select the relocation address */
1302 fdt_high = getenv("fdt_high");
1303 if (fdt_high) {
1304 void *desired_addr = (void *)simple_strtoul(fdt_high, NULL, 16);
1305
1306 if (((ulong) desired_addr) == ~0UL) {
1307 /* All ones means use fdt in place */
Shawn Guofa34f6b2012-01-09 21:54:08 +00001308 of_start = fdt_blob;
1309 lmb_reserve(lmb, (ulong)of_start, of_len);
David A. Longa28afca2011-07-09 16:40:19 -04001310 disable_relocation = 1;
Shawn Guofa34f6b2012-01-09 21:54:08 +00001311 } else if (desired_addr) {
David A. Longa28afca2011-07-09 16:40:19 -04001312 of_start =
1313 (void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000,
Shawn Guofa34f6b2012-01-09 21:54:08 +00001314 (ulong)desired_addr);
1315 if (of_start == 0) {
David A. Longa28afca2011-07-09 16:40:19 -04001316 puts("Failed using fdt_high value for Device Tree");
1317 goto error;
1318 }
1319 } else {
1320 of_start =
Matthew McClintock1bb5e902011-07-18 13:08:05 +00001321 (void *)(ulong) lmb_alloc(lmb, of_len, 0x1000);
David A. Longa28afca2011-07-09 16:40:19 -04001322 }
1323 } else {
1324 of_start =
1325 (void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000,
1326 getenv_bootm_mapsize()
1327 + getenv_bootm_low());
1328 }
Kumar Gala06a09912008-08-15 08:24:38 -05001329
Timur Tabi43b08af2010-05-24 15:10:25 -05001330 if (of_start == 0) {
1331 puts("device tree - allocation error\n");
1332 goto error;
Kumar Gala06a09912008-08-15 08:24:38 -05001333 }
1334
David A. Longa28afca2011-07-09 16:40:19 -04001335 if (disable_relocation) {
1336 /* We assume there is space after the existing fdt to use for padding */
1337 fdt_set_totalsize(of_start, of_len);
1338 printf(" Using Device Tree in place at %p, end %p\n",
1339 of_start, of_start + of_len - 1);
1340 } else {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001341 debug("## device tree at %p ... %p (len=%ld [0x%lX])\n",
David A. Longa28afca2011-07-09 16:40:19 -04001342 fdt_blob, fdt_blob + *of_size - 1, of_len, of_len);
Timur Tabi43b08af2010-05-24 15:10:25 -05001343
Stephen Warren712fbcf2011-10-18 11:11:49 +00001344 printf(" Loading Device Tree to %p, end %p ... ",
David A. Longa28afca2011-07-09 16:40:19 -04001345 of_start, of_start + of_len - 1);
Timur Tabi43b08af2010-05-24 15:10:25 -05001346
Stephen Warren712fbcf2011-10-18 11:11:49 +00001347 err = fdt_open_into(fdt_blob, of_start, of_len);
David A. Longa28afca2011-07-09 16:40:19 -04001348 if (err != 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001349 fdt_error("fdt move failed");
David A. Longa28afca2011-07-09 16:40:19 -04001350 goto error;
1351 }
Stephen Warren712fbcf2011-10-18 11:11:49 +00001352 puts("OK\n");
Timur Tabi43b08af2010-05-24 15:10:25 -05001353 }
Timur Tabi43b08af2010-05-24 15:10:25 -05001354
1355 *of_flat_tree = of_start;
1356 *of_size = of_len;
1357
Kumar Gala54f9c862008-08-15 08:24:39 -05001358 set_working_fdt_addr(*of_flat_tree);
Kumar Gala06a09912008-08-15 08:24:38 -05001359 return 0;
1360
1361error:
1362 return 1;
1363}
Grant Likelyed59e582011-03-28 09:58:49 +00001364#endif /* CONFIG_OF_LIBFDT */
Kumar Gala06a09912008-08-15 08:24:38 -05001365
1366/**
1367 * boot_get_fdt - main fdt handling routine
1368 * @argc: command argument count
1369 * @argv: command argument list
1370 * @images: pointer to the bootm images structure
1371 * @of_flat_tree: pointer to a char* variable, will hold fdt start address
1372 * @of_size: pointer to a ulong variable, will hold fdt length
1373 *
1374 * boot_get_fdt() is responsible for finding a valid flat device tree image.
1375 * Curently supported are the following ramdisk sources:
1376 * - multicomponent kernel/ramdisk image,
1377 * - commandline provided address of decicated ramdisk image.
1378 *
1379 * returns:
1380 * 0, if fdt image was found and valid, or skipped
1381 * of_flat_tree and of_size are set to fdt start address and length if
1382 * fdt image is found and valid
1383 *
1384 * 1, if fdt image is found but corrupted
1385 * of_flat_tree and of_size are set to 0 if no fdt exists
1386 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001387int boot_get_fdt(int flag, int argc, char * const argv[],
1388 bootm_headers_t *images, char **of_flat_tree, ulong *of_size)
Kumar Gala06a09912008-08-15 08:24:38 -05001389{
Wolfgang Denk3a2003f2009-08-19 11:42:56 +02001390 const image_header_t *fdt_hdr;
Kumar Gala06a09912008-08-15 08:24:38 -05001391 ulong fdt_addr;
Kumar Gala06a09912008-08-15 08:24:38 -05001392 char *fdt_blob = NULL;
Stephen Warrene37ae402011-11-01 06:28:21 +00001393 ulong image_start, image_data, image_end;
Kumar Gala06a09912008-08-15 08:24:38 -05001394 ulong load_start, load_end;
1395#if defined(CONFIG_FIT)
1396 void *fit_hdr;
1397 const char *fit_uname_config = NULL;
1398 const char *fit_uname_fdt = NULL;
1399 ulong default_addr;
1400 int cfg_noffset;
1401 int fdt_noffset;
1402 const void *data;
1403 size_t size;
1404#endif
1405
1406 *of_flat_tree = NULL;
1407 *of_size = 0;
1408
Stephen Warren712fbcf2011-10-18 11:11:49 +00001409 if (argc > 3 || genimg_has_config(images)) {
Kumar Gala06a09912008-08-15 08:24:38 -05001410#if defined(CONFIG_FIT)
1411 if (argc > 3) {
1412 /*
1413 * If the FDT blob comes from the FIT image and the
1414 * FIT image address is omitted in the command line
1415 * argument, try to use ramdisk or os FIT image
1416 * address or default load address.
1417 */
1418 if (images->fit_uname_rd)
1419 default_addr = (ulong)images->fit_hdr_rd;
1420 else if (images->fit_uname_os)
1421 default_addr = (ulong)images->fit_hdr_os;
1422 else
1423 default_addr = load_addr;
1424
Stephen Warren712fbcf2011-10-18 11:11:49 +00001425 if (fit_parse_conf(argv[3], default_addr,
Kumar Gala06a09912008-08-15 08:24:38 -05001426 &fdt_addr, &fit_uname_config)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001427 debug("* fdt: config '%s' from image at "
1428 "0x%08lx\n",
Kumar Gala06a09912008-08-15 08:24:38 -05001429 fit_uname_config, fdt_addr);
Stephen Warren712fbcf2011-10-18 11:11:49 +00001430 } else if (fit_parse_subimage(argv[3], default_addr,
Kumar Gala06a09912008-08-15 08:24:38 -05001431 &fdt_addr, &fit_uname_fdt)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001432 debug("* fdt: subimage '%s' from image at "
1433 "0x%08lx\n",
Kumar Gala06a09912008-08-15 08:24:38 -05001434 fit_uname_fdt, fdt_addr);
1435 } else
1436#endif
1437 {
1438 fdt_addr = simple_strtoul(argv[3], NULL, 16);
Stephen Warren712fbcf2011-10-18 11:11:49 +00001439 debug("* fdt: cmdline image address = "
1440 "0x%08lx\n",
Kumar Gala06a09912008-08-15 08:24:38 -05001441 fdt_addr);
1442 }
1443#if defined(CONFIG_FIT)
1444 } else {
1445 /* use FIT configuration provided in first bootm
1446 * command argument
1447 */
1448 fdt_addr = (ulong)images->fit_hdr_os;
1449 fit_uname_config = images->fit_uname_cfg;
Stephen Warren712fbcf2011-10-18 11:11:49 +00001450 debug("* fdt: using config '%s' from image "
1451 "at 0x%08lx\n",
Kumar Gala06a09912008-08-15 08:24:38 -05001452 fit_uname_config, fdt_addr);
1453
1454 /*
1455 * Check whether configuration has FDT blob defined,
1456 * if not quit silently.
1457 */
1458 fit_hdr = (void *)fdt_addr;
Stephen Warren712fbcf2011-10-18 11:11:49 +00001459 cfg_noffset = fit_conf_get_node(fit_hdr,
Kumar Gala06a09912008-08-15 08:24:38 -05001460 fit_uname_config);
1461 if (cfg_noffset < 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001462 debug("* fdt: no such config\n");
Kumar Gala06a09912008-08-15 08:24:38 -05001463 return 0;
1464 }
1465
Stephen Warren712fbcf2011-10-18 11:11:49 +00001466 fdt_noffset = fit_conf_get_fdt_node(fit_hdr,
Kumar Gala06a09912008-08-15 08:24:38 -05001467 cfg_noffset);
1468 if (fdt_noffset < 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001469 debug("* fdt: no fdt in config\n");
Kumar Gala06a09912008-08-15 08:24:38 -05001470 return 0;
1471 }
1472 }
1473#endif
1474
Stephen Warren712fbcf2011-10-18 11:11:49 +00001475 debug("## Checking for 'FDT'/'FDT Image' at %08lx\n",
Kumar Gala06a09912008-08-15 08:24:38 -05001476 fdt_addr);
1477
1478 /* copy from dataflash if needed */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001479 fdt_addr = genimg_get_image(fdt_addr);
Kumar Gala06a09912008-08-15 08:24:38 -05001480
1481 /*
1482 * Check if there is an FDT image at the
1483 * address provided in the second bootm argument
1484 * check image type, for FIT images get a FIT node.
1485 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001486 switch (genimg_get_format((void *)fdt_addr)) {
Kumar Gala06a09912008-08-15 08:24:38 -05001487 case IMAGE_FORMAT_LEGACY:
1488 /* verify fdt_addr points to a valid image header */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001489 printf("## Flattened Device Tree from Legacy Image "
1490 "at %08lx\n",
Kumar Gala06a09912008-08-15 08:24:38 -05001491 fdt_addr);
Stephen Warren712fbcf2011-10-18 11:11:49 +00001492 fdt_hdr = image_get_fdt(fdt_addr);
Kumar Gala06a09912008-08-15 08:24:38 -05001493 if (!fdt_hdr)
1494 goto error;
1495
1496 /*
1497 * move image data to the load address,
1498 * make sure we don't overwrite initial image
1499 */
1500 image_start = (ulong)fdt_hdr;
Stephen Warrene37ae402011-11-01 06:28:21 +00001501 image_data = (ulong)image_get_data(fdt_hdr);
Stephen Warren712fbcf2011-10-18 11:11:49 +00001502 image_end = image_get_image_end(fdt_hdr);
Kumar Gala06a09912008-08-15 08:24:38 -05001503
Stephen Warren712fbcf2011-10-18 11:11:49 +00001504 load_start = image_get_load(fdt_hdr);
1505 load_end = load_start + image_get_data_size(fdt_hdr);
Kumar Gala06a09912008-08-15 08:24:38 -05001506
Stephen Warrene37ae402011-11-01 06:28:21 +00001507 if (load_start == image_start ||
1508 load_start == image_data) {
1509 fdt_blob = (char *)image_data;
1510 break;
1511 }
1512
Kumar Gala06a09912008-08-15 08:24:38 -05001513 if ((load_start < image_end) && (load_end > image_start)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001514 fdt_error("fdt overwritten");
Kumar Gala06a09912008-08-15 08:24:38 -05001515 goto error;
1516 }
1517
Stephen Warren712fbcf2011-10-18 11:11:49 +00001518 debug(" Loading FDT from 0x%08lx to 0x%08lx\n",
Stephen Warrene37ae402011-11-01 06:28:21 +00001519 image_data, load_start);
Kumar Gala06a09912008-08-15 08:24:38 -05001520
Stephen Warren712fbcf2011-10-18 11:11:49 +00001521 memmove((void *)load_start,
Stephen Warrene37ae402011-11-01 06:28:21 +00001522 (void *)image_data,
Stephen Warren712fbcf2011-10-18 11:11:49 +00001523 image_get_data_size(fdt_hdr));
Kumar Gala06a09912008-08-15 08:24:38 -05001524
1525 fdt_blob = (char *)load_start;
1526 break;
1527 case IMAGE_FORMAT_FIT:
1528 /*
1529 * This case will catch both: new uImage format
1530 * (libfdt based) and raw FDT blob (also libfdt
1531 * based).
1532 */
1533#if defined(CONFIG_FIT)
1534 /* check FDT blob vs FIT blob */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001535 if (fit_check_format((const void *)fdt_addr)) {
Kumar Gala06a09912008-08-15 08:24:38 -05001536 /*
1537 * FIT image
1538 */
1539 fit_hdr = (void *)fdt_addr;
Stephen Warren712fbcf2011-10-18 11:11:49 +00001540 printf("## Flattened Device Tree from FIT "
1541 "Image at %08lx\n",
Kumar Gala06a09912008-08-15 08:24:38 -05001542 fdt_addr);
1543
1544 if (!fit_uname_fdt) {
1545 /*
1546 * no FDT blob image node unit name,
1547 * try to get config node first. If
1548 * config unit node name is NULL
1549 * fit_conf_get_node() will try to
1550 * find default config node
1551 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001552 cfg_noffset = fit_conf_get_node(fit_hdr,
Kumar Gala06a09912008-08-15 08:24:38 -05001553 fit_uname_config);
1554
1555 if (cfg_noffset < 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001556 fdt_error("Could not find "
1557 "configuration "
1558 "node\n");
Kumar Gala06a09912008-08-15 08:24:38 -05001559 goto error;
1560 }
1561
Stephen Warren712fbcf2011-10-18 11:11:49 +00001562 fit_uname_config = fdt_get_name(fit_hdr,
Kumar Gala06a09912008-08-15 08:24:38 -05001563 cfg_noffset, NULL);
Stephen Warren712fbcf2011-10-18 11:11:49 +00001564 printf(" Using '%s' configuration\n",
Kumar Gala06a09912008-08-15 08:24:38 -05001565 fit_uname_config);
1566
Stephen Warren712fbcf2011-10-18 11:11:49 +00001567 fdt_noffset = fit_conf_get_fdt_node(
1568 fit_hdr,
Kumar Gala06a09912008-08-15 08:24:38 -05001569 cfg_noffset);
Stephen Warren712fbcf2011-10-18 11:11:49 +00001570 fit_uname_fdt = fit_get_name(fit_hdr,
Kumar Gala06a09912008-08-15 08:24:38 -05001571 fdt_noffset, NULL);
1572 } else {
1573 /* get FDT component image node offset */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001574 fdt_noffset = fit_image_get_node(
1575 fit_hdr,
1576 fit_uname_fdt);
Kumar Gala06a09912008-08-15 08:24:38 -05001577 }
1578 if (fdt_noffset < 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001579 fdt_error("Could not find subimage "
1580 "node\n");
Kumar Gala06a09912008-08-15 08:24:38 -05001581 goto error;
1582 }
1583
Stephen Warren712fbcf2011-10-18 11:11:49 +00001584 printf(" Trying '%s' FDT blob subimage\n",
Kumar Gala06a09912008-08-15 08:24:38 -05001585 fit_uname_fdt);
1586
Stephen Warren712fbcf2011-10-18 11:11:49 +00001587 if (!fit_check_fdt(fit_hdr, fdt_noffset,
Kumar Gala06a09912008-08-15 08:24:38 -05001588 images->verify))
1589 goto error;
1590
1591 /* get ramdisk image data address and length */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001592 if (fit_image_get_data(fit_hdr, fdt_noffset,
Kumar Gala06a09912008-08-15 08:24:38 -05001593 &data, &size)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001594 fdt_error("Could not find FDT "
1595 "subimage data");
Kumar Gala06a09912008-08-15 08:24:38 -05001596 goto error;
1597 }
1598
1599 /* verift that image data is a proper FDT blob */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001600 if (fdt_check_header((char *)data) != 0) {
1601 fdt_error("Subimage data is not a FTD");
Kumar Gala06a09912008-08-15 08:24:38 -05001602 goto error;
1603 }
1604
1605 /*
1606 * move image data to the load address,
1607 * make sure we don't overwrite initial image
1608 */
1609 image_start = (ulong)fit_hdr;
Stephen Warren712fbcf2011-10-18 11:11:49 +00001610 image_end = fit_get_end(fit_hdr);
Kumar Gala06a09912008-08-15 08:24:38 -05001611
Stephen Warren712fbcf2011-10-18 11:11:49 +00001612 if (fit_image_get_load(fit_hdr, fdt_noffset,
Kumar Gala06a09912008-08-15 08:24:38 -05001613 &load_start) == 0) {
1614 load_end = load_start + size;
1615
1616 if ((load_start < image_end) &&
1617 (load_end > image_start)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001618 fdt_error("FDT overwritten");
Kumar Gala06a09912008-08-15 08:24:38 -05001619 goto error;
1620 }
1621
Stephen Warren712fbcf2011-10-18 11:11:49 +00001622 printf(" Loading FDT from 0x%08lx "
1623 "to 0x%08lx\n",
1624 (ulong)data,
1625 load_start);
Kumar Gala06a09912008-08-15 08:24:38 -05001626
Stephen Warren712fbcf2011-10-18 11:11:49 +00001627 memmove((void *)load_start,
Kumar Gala06a09912008-08-15 08:24:38 -05001628 (void *)data, size);
1629
1630 fdt_blob = (char *)load_start;
1631 } else {
1632 fdt_blob = (char *)data;
1633 }
1634
1635 images->fit_hdr_fdt = fit_hdr;
1636 images->fit_uname_fdt = fit_uname_fdt;
1637 images->fit_noffset_fdt = fdt_noffset;
1638 break;
1639 } else
1640#endif
1641 {
1642 /*
1643 * FDT blob
1644 */
1645 fdt_blob = (char *)fdt_addr;
Stephen Warren712fbcf2011-10-18 11:11:49 +00001646 debug("* fdt: raw FDT blob\n");
1647 printf("## Flattened Device Tree blob at "
1648 "%08lx\n", (long)fdt_blob);
Kumar Gala06a09912008-08-15 08:24:38 -05001649 }
1650 break;
1651 default:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001652 puts("ERROR: Did not find a cmdline Flattened Device "
1653 "Tree\n");
Kumar Gala06a09912008-08-15 08:24:38 -05001654 goto error;
1655 }
1656
Simon Glass0ec2ce42011-09-23 06:22:04 +00001657 printf(" Booting using the fdt blob at 0x%p\n", fdt_blob);
Kumar Gala06a09912008-08-15 08:24:38 -05001658
1659 } else if (images->legacy_hdr_valid &&
Stephen Warren712fbcf2011-10-18 11:11:49 +00001660 image_check_type(&images->legacy_hdr_os_copy,
1661 IH_TYPE_MULTI)) {
Kumar Gala06a09912008-08-15 08:24:38 -05001662
1663 ulong fdt_data, fdt_len;
1664
1665 /*
1666 * Now check if we have a legacy multi-component image,
1667 * get second entry data start address and len.
1668 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001669 printf("## Flattened Device Tree from multi "
Kumar Gala06a09912008-08-15 08:24:38 -05001670 "component Image at %08lX\n",
1671 (ulong)images->legacy_hdr_os);
1672
Stephen Warren712fbcf2011-10-18 11:11:49 +00001673 image_multi_getimg(images->legacy_hdr_os, 2, &fdt_data,
1674 &fdt_len);
Kumar Gala06a09912008-08-15 08:24:38 -05001675 if (fdt_len) {
1676
1677 fdt_blob = (char *)fdt_data;
Simon Glass0ec2ce42011-09-23 06:22:04 +00001678 printf(" Booting using the fdt at 0x%p\n", fdt_blob);
Kumar Gala06a09912008-08-15 08:24:38 -05001679
Stephen Warren712fbcf2011-10-18 11:11:49 +00001680 if (fdt_check_header(fdt_blob) != 0) {
1681 fdt_error("image is not a fdt");
Kumar Gala06a09912008-08-15 08:24:38 -05001682 goto error;
1683 }
1684
John Rigbyd1263fc2010-10-13 13:57:32 -06001685 if (fdt_totalsize(fdt_blob) != fdt_len) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001686 fdt_error("fdt size != image size");
Kumar Gala06a09912008-08-15 08:24:38 -05001687 goto error;
1688 }
1689 } else {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001690 debug("## No Flattened Device Tree\n");
Kumar Gala06a09912008-08-15 08:24:38 -05001691 return 0;
1692 }
1693 } else {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001694 debug("## No Flattened Device Tree\n");
Kumar Gala06a09912008-08-15 08:24:38 -05001695 return 0;
1696 }
1697
1698 *of_flat_tree = fdt_blob;
John Rigbyd1263fc2010-10-13 13:57:32 -06001699 *of_size = fdt_totalsize(fdt_blob);
Stephen Warren712fbcf2011-10-18 11:11:49 +00001700 debug(" of_flat_tree at 0x%08lx size 0x%08lx\n",
Andrew Klossner52514692008-08-21 07:12:26 -07001701 (ulong)*of_flat_tree, *of_size);
Kumar Gala06a09912008-08-15 08:24:38 -05001702
1703 return 0;
1704
1705error:
1706 *of_flat_tree = 0;
1707 *of_size = 0;
1708 return 1;
1709}
1710#endif /* CONFIG_OF_LIBFDT */
1711
John Rigbyfca43cc2010-10-13 13:57:35 -06001712#ifdef CONFIG_SYS_BOOT_GET_CMDLINE
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +01001713/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +01001714 * boot_get_cmdline - allocate and initialize kernel cmdline
Kumar Galae822d7f2008-02-27 21:51:49 -06001715 * @lmb: pointer to lmb handle, will be used for memory mgmt
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +01001716 * @cmd_start: pointer to a ulong variable, will hold cmdline start
1717 * @cmd_end: pointer to a ulong variable, will hold cmdline end
1718 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +01001719 * boot_get_cmdline() allocates space for kernel command line below
Grant Likely590d3ca2011-03-28 09:58:34 +00001720 * BOOTMAPSZ + getenv_bootm_low() address. If "bootargs" U-boot environemnt
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +01001721 * variable is present its contents is copied to allocated kernel
1722 * command line.
1723 *
1724 * returns:
Kumar Galae822d7f2008-02-27 21:51:49 -06001725 * 0 - success
1726 * -1 - failure
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +01001727 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001728int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end)
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +01001729{
1730 char *cmdline;
1731 char *s;
1732
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001733 cmdline = (char *)(ulong)lmb_alloc_base(lmb, CONFIG_SYS_BARGSIZE, 0xf,
Grant Likelyc3624e62011-03-28 09:58:43 +00001734 getenv_bootm_mapsize() + getenv_bootm_low());
Kumar Galae822d7f2008-02-27 21:51:49 -06001735
1736 if (cmdline == NULL)
1737 return -1;
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +01001738
1739 if ((s = getenv("bootargs")) == NULL)
1740 s = "";
1741
1742 strcpy(cmdline, s);
1743
1744 *cmd_start = (ulong) & cmdline[0];
1745 *cmd_end = *cmd_start + strlen(cmdline);
1746
Stephen Warren712fbcf2011-10-18 11:11:49 +00001747 debug("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +01001748
Kumar Galae822d7f2008-02-27 21:51:49 -06001749 return 0;
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +01001750}
John Rigbyfca43cc2010-10-13 13:57:35 -06001751#endif /* CONFIG_SYS_BOOT_GET_CMDLINE */
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +01001752
John Rigbyfca43cc2010-10-13 13:57:35 -06001753#ifdef CONFIG_SYS_BOOT_GET_KBD
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +01001754/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +01001755 * boot_get_kbd - allocate and initialize kernel copy of board info
Kumar Galae822d7f2008-02-27 21:51:49 -06001756 * @lmb: pointer to lmb handle, will be used for memory mgmt
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +01001757 * @kbd: double pointer to board info data
1758 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +01001759 * boot_get_kbd() allocates space for kernel copy of board info data below
Grant Likely590d3ca2011-03-28 09:58:34 +00001760 * BOOTMAPSZ + getenv_bootm_low() address and kernel board info is initialized
1761 * with the current u-boot board info data.
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +01001762 *
1763 * returns:
Kumar Galae822d7f2008-02-27 21:51:49 -06001764 * 0 - success
1765 * -1 - failure
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +01001766 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001767int boot_get_kbd(struct lmb *lmb, bd_t **kbd)
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +01001768{
Becky Bruce391fd932008-06-09 20:37:18 -05001769 *kbd = (bd_t *)(ulong)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
Grant Likelyc3624e62011-03-28 09:58:43 +00001770 getenv_bootm_mapsize() + getenv_bootm_low());
Kumar Galae822d7f2008-02-27 21:51:49 -06001771 if (*kbd == NULL)
1772 return -1;
1773
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +01001774 **kbd = *(gd->bd);
1775
Stephen Warren712fbcf2011-10-18 11:11:49 +00001776 debug("## kernel board info at 0x%08lx\n", (ulong)*kbd);
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +01001777
1778#if defined(DEBUG) && defined(CONFIG_CMD_BDI)
1779 do_bdinfo(NULL, 0, 0, NULL);
1780#endif
1781
Kumar Galae822d7f2008-02-27 21:51:49 -06001782 return 0;
Marian Balakowiczceaed2b2008-01-31 13:57:17 +01001783}
John Rigbyfca43cc2010-10-13 13:57:35 -06001784#endif /* CONFIG_SYS_BOOT_GET_KBD */
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001785#endif /* !USE_HOSTCC */
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +01001786
Marian Balakowiczf50433d2008-02-21 17:20:20 +01001787#if defined(CONFIG_FIT)
1788/*****************************************************************************/
1789/* New uImage format routines */
1790/*****************************************************************************/
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001791#ifndef USE_HOSTCC
Stephen Warren712fbcf2011-10-18 11:11:49 +00001792static int fit_parse_spec(const char *spec, char sepc, ulong addr_curr,
Marian Balakowiczf50433d2008-02-21 17:20:20 +01001793 ulong *addr, const char **name)
1794{
1795 const char *sep;
1796
1797 *addr = addr_curr;
1798 *name = NULL;
1799
Stephen Warren712fbcf2011-10-18 11:11:49 +00001800 sep = strchr(spec, sepc);
Marian Balakowiczf50433d2008-02-21 17:20:20 +01001801 if (sep) {
1802 if (sep - spec > 0)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001803 *addr = simple_strtoul(spec, NULL, 16);
Marian Balakowiczf50433d2008-02-21 17:20:20 +01001804
1805 *name = sep + 1;
1806 return 1;
1807 }
1808
1809 return 0;
1810}
1811
1812/**
1813 * fit_parse_conf - parse FIT configuration spec
1814 * @spec: input string, containing configuration spec
1815 * @add_curr: current image address (to be used as a possible default)
1816 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1817 * configuration
1818 * @conf_name double pointer to a char, will hold pointer to a configuration
1819 * unit name
1820 *
1821 * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
1822 * where <addr> is a FIT image address that contains configuration
1823 * with a <conf> unit name.
1824 *
1825 * Address part is optional, and if omitted default add_curr will
1826 * be used instead.
1827 *
1828 * returns:
1829 * 1 if spec is a valid configuration string,
1830 * addr and conf_name are set accordingly
1831 * 0 otherwise
1832 */
Mike Frysinger314f6342012-04-22 06:59:06 +00001833int fit_parse_conf(const char *spec, ulong addr_curr,
Marian Balakowiczf50433d2008-02-21 17:20:20 +01001834 ulong *addr, const char **conf_name)
1835{
Stephen Warren712fbcf2011-10-18 11:11:49 +00001836 return fit_parse_spec(spec, '#', addr_curr, addr, conf_name);
Marian Balakowiczf50433d2008-02-21 17:20:20 +01001837}
1838
1839/**
1840 * fit_parse_subimage - parse FIT subimage spec
1841 * @spec: input string, containing subimage spec
1842 * @add_curr: current image address (to be used as a possible default)
1843 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1844 * subimage
1845 * @image_name: double pointer to a char, will hold pointer to a subimage name
1846 *
1847 * fit_parse_subimage() expects subimage spec in the for of
1848 * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
1849 * subimage with a <subimg> unit name.
1850 *
1851 * Address part is optional, and if omitted default add_curr will
1852 * be used instead.
1853 *
1854 * returns:
1855 * 1 if spec is a valid subimage string,
1856 * addr and image_name are set accordingly
1857 * 0 otherwise
1858 */
Mike Frysinger314f6342012-04-22 06:59:06 +00001859int fit_parse_subimage(const char *spec, ulong addr_curr,
Marian Balakowiczf50433d2008-02-21 17:20:20 +01001860 ulong *addr, const char **image_name)
1861{
Stephen Warren712fbcf2011-10-18 11:11:49 +00001862 return fit_parse_spec(spec, ':', addr_curr, addr, image_name);
Marian Balakowiczf50433d2008-02-21 17:20:20 +01001863}
Marian Balakowicz570abb02008-02-29 15:59:59 +01001864#endif /* !USE_HOSTCC */
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001865
Stephen Warren712fbcf2011-10-18 11:11:49 +00001866static void fit_get_debug(const void *fit, int noffset,
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001867 char *prop_name, int err)
1868{
Stephen Warren712fbcf2011-10-18 11:11:49 +00001869 debug("Can't get '%s' property from FIT 0x%08lx, "
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001870 "node: offset %d, name %s (%s)\n",
1871 prop_name, (ulong)fit, noffset,
Stephen Warren712fbcf2011-10-18 11:11:49 +00001872 fit_get_name(fit, noffset, NULL),
1873 fdt_strerror(err));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001874}
1875
1876/**
Bartlomiej Siekaedbed242008-04-18 12:39:23 +02001877 * fit_print_contents - prints out the contents of the FIT format image
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001878 * @fit: pointer to the FIT format image header
1879 * @p: pointer to prefix string
1880 *
Bartlomiej Siekaedbed242008-04-18 12:39:23 +02001881 * fit_print_contents() formats a multi line FIT image contents description.
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001882 * The routine prints out FIT image properties (root node level) follwed by
1883 * the details of each component image.
1884 *
1885 * returns:
1886 * no returned results
1887 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001888void fit_print_contents(const void *fit)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001889{
1890 char *desc;
1891 char *uname;
1892 int images_noffset;
1893 int confs_noffset;
1894 int noffset;
1895 int ndepth;
1896 int count = 0;
1897 int ret;
Bartlomiej Siekaedbed242008-04-18 12:39:23 +02001898 const char *p;
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001899#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1900 time_t timestamp;
1901#endif
1902
Bartlomiej Siekaedbed242008-04-18 12:39:23 +02001903#ifdef USE_HOSTCC
1904 p = "";
1905#else
1906 p = " ";
1907#endif
1908
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001909 /* Root node properties */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001910 ret = fit_get_desc(fit, 0, &desc);
1911 printf("%sFIT description: ", p);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001912 if (ret)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001913 printf("unavailable\n");
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001914 else
Stephen Warren712fbcf2011-10-18 11:11:49 +00001915 printf("%s\n", desc);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001916
1917#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001918 ret = fit_get_timestamp(fit, 0, &timestamp);
1919 printf("%sCreated: ", p);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001920 if (ret)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001921 printf("unavailable\n");
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001922 else
Stephen Warren712fbcf2011-10-18 11:11:49 +00001923 genimg_print_time(timestamp);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001924#endif
1925
1926 /* Find images parent node offset */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001927 images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001928 if (images_noffset < 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001929 printf("Can't find images parent node '%s' (%s)\n",
1930 FIT_IMAGES_PATH, fdt_strerror(images_noffset));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001931 return;
1932 }
1933
1934 /* Process its subnodes, print out component images details */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001935 for (ndepth = 0, count = 0,
1936 noffset = fdt_next_node(fit, images_noffset, &ndepth);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001937 (noffset >= 0) && (ndepth > 0);
Stephen Warren712fbcf2011-10-18 11:11:49 +00001938 noffset = fdt_next_node(fit, noffset, &ndepth)) {
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001939 if (ndepth == 1) {
1940 /*
1941 * Direct child node of the images parent node,
1942 * i.e. component image node.
1943 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001944 printf("%s Image %u (%s)\n", p, count++,
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001945 fit_get_name(fit, noffset, NULL));
1946
Stephen Warren712fbcf2011-10-18 11:11:49 +00001947 fit_image_print(fit, noffset, p);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001948 }
1949 }
1950
1951 /* Find configurations parent node offset */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001952 confs_noffset = fdt_path_offset(fit, FIT_CONFS_PATH);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001953 if (confs_noffset < 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001954 debug("Can't get configurations parent node '%s' (%s)\n",
1955 FIT_CONFS_PATH, fdt_strerror(confs_noffset));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001956 return;
1957 }
1958
1959 /* get default configuration unit name from default property */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001960 uname = (char *)fdt_getprop(fit, noffset, FIT_DEFAULT_PROP, NULL);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001961 if (uname)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001962 printf("%s Default Configuration: '%s'\n", p, uname);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001963
1964 /* Process its subnodes, print out configurations details */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001965 for (ndepth = 0, count = 0,
1966 noffset = fdt_next_node(fit, confs_noffset, &ndepth);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001967 (noffset >= 0) && (ndepth > 0);
Stephen Warren712fbcf2011-10-18 11:11:49 +00001968 noffset = fdt_next_node(fit, noffset, &ndepth)) {
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001969 if (ndepth == 1) {
1970 /*
1971 * Direct child node of the configurations parent node,
1972 * i.e. configuration node.
1973 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001974 printf("%s Configuration %u (%s)\n", p, count++,
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001975 fit_get_name(fit, noffset, NULL));
1976
Stephen Warren712fbcf2011-10-18 11:11:49 +00001977 fit_conf_print(fit, noffset, p);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001978 }
1979 }
1980}
1981
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001982/**
1983 * fit_image_print - prints out the FIT component image details
1984 * @fit: pointer to the FIT format image header
1985 * @image_noffset: offset of the component image node
1986 * @p: pointer to prefix string
1987 *
1988 * fit_image_print() lists all mandatory properies for the processed component
Bartlomiej Siekafbc87dc2008-10-01 15:26:32 +02001989 * image. If present, hash nodes are printed out as well. Load
1990 * address for images of type firmware is also printed out. Since the load
1991 * address is not mandatory for firmware images, it will be output as
1992 * "unavailable" when not present.
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001993 *
1994 * returns:
1995 * no returned results
1996 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001997void fit_image_print(const void *fit, int image_noffset, const char *p)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01001998{
1999 char *desc;
2000 uint8_t type, arch, os, comp;
2001 size_t size;
2002 ulong load, entry;
2003 const void *data;
2004 int noffset;
2005 int ndepth;
2006 int ret;
2007
2008 /* Mandatory properties */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002009 ret = fit_get_desc(fit, image_noffset, &desc);
2010 printf("%s Description: ", p);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002011 if (ret)
Stephen Warren712fbcf2011-10-18 11:11:49 +00002012 printf("unavailable\n");
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002013 else
Stephen Warren712fbcf2011-10-18 11:11:49 +00002014 printf("%s\n", desc);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002015
Stephen Warren712fbcf2011-10-18 11:11:49 +00002016 fit_image_get_type(fit, image_noffset, &type);
2017 printf("%s Type: %s\n", p, genimg_get_type_name(type));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002018
Stephen Warren712fbcf2011-10-18 11:11:49 +00002019 fit_image_get_comp(fit, image_noffset, &comp);
2020 printf("%s Compression: %s\n", p, genimg_get_comp_name(comp));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002021
Stephen Warren712fbcf2011-10-18 11:11:49 +00002022 ret = fit_image_get_data(fit, image_noffset, &data, &size);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002023
2024#ifndef USE_HOSTCC
Stephen Warren712fbcf2011-10-18 11:11:49 +00002025 printf("%s Data Start: ", p);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002026 if (ret)
Stephen Warren712fbcf2011-10-18 11:11:49 +00002027 printf("unavailable\n");
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002028 else
Stephen Warren712fbcf2011-10-18 11:11:49 +00002029 printf("0x%08lx\n", (ulong)data);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002030#endif
2031
Stephen Warren712fbcf2011-10-18 11:11:49 +00002032 printf("%s Data Size: ", p);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002033 if (ret)
Stephen Warren712fbcf2011-10-18 11:11:49 +00002034 printf("unavailable\n");
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002035 else
Stephen Warren712fbcf2011-10-18 11:11:49 +00002036 genimg_print_size(size);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002037
2038 /* Remaining, type dependent properties */
2039 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
2040 (type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) ||
2041 (type == IH_TYPE_FLATDT)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002042 fit_image_get_arch(fit, image_noffset, &arch);
2043 printf("%s Architecture: %s\n", p, genimg_get_arch_name(arch));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002044 }
2045
2046 if (type == IH_TYPE_KERNEL) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002047 fit_image_get_os(fit, image_noffset, &os);
2048 printf("%s OS: %s\n", p, genimg_get_os_name(os));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002049 }
2050
Bartlomiej Siekafbc87dc2008-10-01 15:26:32 +02002051 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
2052 (type == IH_TYPE_FIRMWARE)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002053 ret = fit_image_get_load(fit, image_noffset, &load);
2054 printf("%s Load Address: ", p);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002055 if (ret)
Stephen Warren712fbcf2011-10-18 11:11:49 +00002056 printf("unavailable\n");
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002057 else
Stephen Warren712fbcf2011-10-18 11:11:49 +00002058 printf("0x%08lx\n", load);
Bartlomiej Siekafbc87dc2008-10-01 15:26:32 +02002059 }
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002060
Bartlomiej Siekafbc87dc2008-10-01 15:26:32 +02002061 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002062 fit_image_get_entry(fit, image_noffset, &entry);
2063 printf("%s Entry Point: ", p);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002064 if (ret)
Stephen Warren712fbcf2011-10-18 11:11:49 +00002065 printf("unavailable\n");
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002066 else
Stephen Warren712fbcf2011-10-18 11:11:49 +00002067 printf("0x%08lx\n", entry);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002068 }
2069
2070 /* Process all hash subnodes of the component image node */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002071 for (ndepth = 0, noffset = fdt_next_node(fit, image_noffset, &ndepth);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002072 (noffset >= 0) && (ndepth > 0);
Stephen Warren712fbcf2011-10-18 11:11:49 +00002073 noffset = fdt_next_node(fit, noffset, &ndepth)) {
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002074 if (ndepth == 1) {
2075 /* Direct child node of the component image node */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002076 fit_image_print_hash(fit, noffset, p);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002077 }
2078 }
2079}
2080
2081/**
2082 * fit_image_print_hash - prints out the hash node details
2083 * @fit: pointer to the FIT format image header
2084 * @noffset: offset of the hash node
2085 * @p: pointer to prefix string
2086 *
2087 * fit_image_print_hash() lists properies for the processed hash node
2088 *
2089 * returns:
2090 * no returned results
2091 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002092void fit_image_print_hash(const void *fit, int noffset, const char *p)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002093{
2094 char *algo;
2095 uint8_t *value;
2096 int value_len;
2097 int i, ret;
2098
2099 /*
2100 * Check subnode name, must be equal to "hash".
2101 * Multiple hash nodes require unique unit node
2102 * names, e.g. hash@1, hash@2, etc.
2103 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002104 if (strncmp(fit_get_name(fit, noffset, NULL),
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002105 FIT_HASH_NODENAME,
2106 strlen(FIT_HASH_NODENAME)) != 0)
2107 return;
2108
Stephen Warren712fbcf2011-10-18 11:11:49 +00002109 debug("%s Hash node: '%s'\n", p,
2110 fit_get_name(fit, noffset, NULL));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002111
Stephen Warren712fbcf2011-10-18 11:11:49 +00002112 printf("%s Hash algo: ", p);
2113 if (fit_image_hash_get_algo(fit, noffset, &algo)) {
2114 printf("invalid/unsupported\n");
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002115 return;
2116 }
Stephen Warren712fbcf2011-10-18 11:11:49 +00002117 printf("%s\n", algo);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002118
Stephen Warren712fbcf2011-10-18 11:11:49 +00002119 ret = fit_image_hash_get_value(fit, noffset, &value,
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002120 &value_len);
Stephen Warren712fbcf2011-10-18 11:11:49 +00002121 printf("%s Hash value: ", p);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002122 if (ret) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002123 printf("unavailable\n");
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002124 } else {
2125 for (i = 0; i < value_len; i++)
Stephen Warren712fbcf2011-10-18 11:11:49 +00002126 printf("%02x", value[i]);
2127 printf("\n");
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002128 }
2129
Stephen Warren712fbcf2011-10-18 11:11:49 +00002130 debug("%s Hash len: %d\n", p, value_len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002131}
2132
2133/**
2134 * fit_get_desc - get node description property
2135 * @fit: pointer to the FIT format image header
2136 * @noffset: node offset
2137 * @desc: double pointer to the char, will hold pointer to the descrption
2138 *
2139 * fit_get_desc() reads description property from a given node, if
2140 * description is found pointer to it is returened in third call argument.
2141 *
2142 * returns:
2143 * 0, on success
2144 * -1, on failure
2145 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002146int fit_get_desc(const void *fit, int noffset, char **desc)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002147{
2148 int len;
2149
Stephen Warren712fbcf2011-10-18 11:11:49 +00002150 *desc = (char *)fdt_getprop(fit, noffset, FIT_DESC_PROP, &len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002151 if (*desc == NULL) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002152 fit_get_debug(fit, noffset, FIT_DESC_PROP, len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002153 return -1;
2154 }
2155
2156 return 0;
2157}
2158
2159/**
2160 * fit_get_timestamp - get node timestamp property
2161 * @fit: pointer to the FIT format image header
2162 * @noffset: node offset
2163 * @timestamp: pointer to the time_t, will hold read timestamp
2164 *
2165 * fit_get_timestamp() reads timestamp poperty from given node, if timestamp
2166 * is found and has a correct size its value is retured in third call
2167 * argument.
2168 *
2169 * returns:
2170 * 0, on success
2171 * -1, on property read failure
2172 * -2, on wrong timestamp size
2173 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002174int fit_get_timestamp(const void *fit, int noffset, time_t *timestamp)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002175{
2176 int len;
2177 const void *data;
2178
Stephen Warren712fbcf2011-10-18 11:11:49 +00002179 data = fdt_getprop(fit, noffset, FIT_TIMESTAMP_PROP, &len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002180 if (data == NULL) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002181 fit_get_debug(fit, noffset, FIT_TIMESTAMP_PROP, len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002182 return -1;
2183 }
Stephen Warren712fbcf2011-10-18 11:11:49 +00002184 if (len != sizeof(uint32_t)) {
2185 debug("FIT timestamp with incorrect size of (%u)\n", len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002186 return -2;
2187 }
2188
Stephen Warren712fbcf2011-10-18 11:11:49 +00002189 *timestamp = uimage_to_cpu(*((uint32_t *)data));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002190 return 0;
2191}
2192
2193/**
2194 * fit_image_get_node - get node offset for component image of a given unit name
2195 * @fit: pointer to the FIT format image header
2196 * @image_uname: component image node unit name
2197 *
2198 * fit_image_get_node() finds a component image (withing the '/images'
2199 * node) of a provided unit name. If image is found its node offset is
2200 * returned to the caller.
2201 *
2202 * returns:
2203 * image node offset when found (>=0)
2204 * negative number on failure (FDT_ERR_* code)
2205 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002206int fit_image_get_node(const void *fit, const char *image_uname)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002207{
2208 int noffset, images_noffset;
2209
Stephen Warren712fbcf2011-10-18 11:11:49 +00002210 images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002211 if (images_noffset < 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002212 debug("Can't find images parent node '%s' (%s)\n",
2213 FIT_IMAGES_PATH, fdt_strerror(images_noffset));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002214 return images_noffset;
2215 }
2216
Stephen Warren712fbcf2011-10-18 11:11:49 +00002217 noffset = fdt_subnode_offset(fit, images_noffset, image_uname);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002218 if (noffset < 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002219 debug("Can't get node offset for image unit name: '%s' (%s)\n",
2220 image_uname, fdt_strerror(noffset));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002221 }
2222
2223 return noffset;
2224}
2225
2226/**
2227 * fit_image_get_os - get os id for a given component image node
2228 * @fit: pointer to the FIT format image header
2229 * @noffset: component image node offset
2230 * @os: pointer to the uint8_t, will hold os numeric id
2231 *
2232 * fit_image_get_os() finds os property in a given component image node.
2233 * If the property is found, its (string) value is translated to the numeric
2234 * id which is returned to the caller.
2235 *
2236 * returns:
2237 * 0, on success
2238 * -1, on failure
2239 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002240int fit_image_get_os(const void *fit, int noffset, uint8_t *os)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002241{
2242 int len;
2243 const void *data;
2244
2245 /* Get OS name from property data */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002246 data = fdt_getprop(fit, noffset, FIT_OS_PROP, &len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002247 if (data == NULL) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002248 fit_get_debug(fit, noffset, FIT_OS_PROP, len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002249 *os = -1;
2250 return -1;
2251 }
2252
2253 /* Translate OS name to id */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002254 *os = genimg_get_os_id(data);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002255 return 0;
2256}
2257
2258/**
2259 * fit_image_get_arch - get arch id for a given component image node
2260 * @fit: pointer to the FIT format image header
2261 * @noffset: component image node offset
2262 * @arch: pointer to the uint8_t, will hold arch numeric id
2263 *
2264 * fit_image_get_arch() finds arch property in a given component image node.
2265 * If the property is found, its (string) value is translated to the numeric
2266 * id which is returned to the caller.
2267 *
2268 * returns:
2269 * 0, on success
2270 * -1, on failure
2271 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002272int fit_image_get_arch(const void *fit, int noffset, uint8_t *arch)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002273{
2274 int len;
2275 const void *data;
2276
2277 /* Get architecture name from property data */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002278 data = fdt_getprop(fit, noffset, FIT_ARCH_PROP, &len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002279 if (data == NULL) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002280 fit_get_debug(fit, noffset, FIT_ARCH_PROP, len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002281 *arch = -1;
2282 return -1;
2283 }
2284
2285 /* Translate architecture name to id */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002286 *arch = genimg_get_arch_id(data);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002287 return 0;
2288}
2289
2290/**
2291 * fit_image_get_type - get type id for a given component image node
2292 * @fit: pointer to the FIT format image header
2293 * @noffset: component image node offset
2294 * @type: pointer to the uint8_t, will hold type numeric id
2295 *
2296 * fit_image_get_type() finds type property in a given component image node.
2297 * If the property is found, its (string) value is translated to the numeric
2298 * id which is returned to the caller.
2299 *
2300 * returns:
2301 * 0, on success
2302 * -1, on failure
2303 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002304int fit_image_get_type(const void *fit, int noffset, uint8_t *type)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002305{
2306 int len;
2307 const void *data;
2308
2309 /* Get image type name from property data */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002310 data = fdt_getprop(fit, noffset, FIT_TYPE_PROP, &len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002311 if (data == NULL) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002312 fit_get_debug(fit, noffset, FIT_TYPE_PROP, len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002313 *type = -1;
2314 return -1;
2315 }
2316
2317 /* Translate image type name to id */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002318 *type = genimg_get_type_id(data);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002319 return 0;
2320}
2321
2322/**
2323 * fit_image_get_comp - get comp id for a given component image node
2324 * @fit: pointer to the FIT format image header
2325 * @noffset: component image node offset
2326 * @comp: pointer to the uint8_t, will hold comp numeric id
2327 *
2328 * fit_image_get_comp() finds comp property in a given component image node.
2329 * If the property is found, its (string) value is translated to the numeric
2330 * id which is returned to the caller.
2331 *
2332 * returns:
2333 * 0, on success
2334 * -1, on failure
2335 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002336int fit_image_get_comp(const void *fit, int noffset, uint8_t *comp)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002337{
2338 int len;
2339 const void *data;
2340
2341 /* Get compression name from property data */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002342 data = fdt_getprop(fit, noffset, FIT_COMP_PROP, &len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002343 if (data == NULL) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002344 fit_get_debug(fit, noffset, FIT_COMP_PROP, len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002345 *comp = -1;
2346 return -1;
2347 }
2348
2349 /* Translate compression name to id */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002350 *comp = genimg_get_comp_id(data);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002351 return 0;
2352}
2353
2354/**
2355 * fit_image_get_load - get load address property for a given component image node
2356 * @fit: pointer to the FIT format image header
2357 * @noffset: component image node offset
2358 * @load: pointer to the uint32_t, will hold load address
2359 *
2360 * fit_image_get_load() finds load address property in a given component image node.
2361 * If the property is found, its value is returned to the caller.
2362 *
2363 * returns:
2364 * 0, on success
2365 * -1, on failure
2366 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002367int fit_image_get_load(const void *fit, int noffset, ulong *load)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002368{
2369 int len;
2370 const uint32_t *data;
2371
Stephen Warren712fbcf2011-10-18 11:11:49 +00002372 data = fdt_getprop(fit, noffset, FIT_LOAD_PROP, &len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002373 if (data == NULL) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002374 fit_get_debug(fit, noffset, FIT_LOAD_PROP, len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002375 return -1;
2376 }
2377
Stephen Warren712fbcf2011-10-18 11:11:49 +00002378 *load = uimage_to_cpu(*data);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002379 return 0;
2380}
2381
2382/**
2383 * fit_image_get_entry - get entry point address property for a given component image node
2384 * @fit: pointer to the FIT format image header
2385 * @noffset: component image node offset
2386 * @entry: pointer to the uint32_t, will hold entry point address
2387 *
2388 * fit_image_get_entry() finds entry point address property in a given component image node.
2389 * If the property is found, its value is returned to the caller.
2390 *
2391 * returns:
2392 * 0, on success
2393 * -1, on failure
2394 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002395int fit_image_get_entry(const void *fit, int noffset, ulong *entry)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002396{
2397 int len;
2398 const uint32_t *data;
2399
Stephen Warren712fbcf2011-10-18 11:11:49 +00002400 data = fdt_getprop(fit, noffset, FIT_ENTRY_PROP, &len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002401 if (data == NULL) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002402 fit_get_debug(fit, noffset, FIT_ENTRY_PROP, len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002403 return -1;
2404 }
2405
Stephen Warren712fbcf2011-10-18 11:11:49 +00002406 *entry = uimage_to_cpu(*data);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002407 return 0;
2408}
2409
2410/**
2411 * fit_image_get_data - get data property and its size for a given component image node
2412 * @fit: pointer to the FIT format image header
2413 * @noffset: component image node offset
2414 * @data: double pointer to void, will hold data property's data address
2415 * @size: pointer to size_t, will hold data property's data size
2416 *
2417 * fit_image_get_data() finds data property in a given component image node.
2418 * If the property is found its data start address and size are returned to
2419 * the caller.
2420 *
2421 * returns:
2422 * 0, on success
2423 * -1, on failure
2424 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002425int fit_image_get_data(const void *fit, int noffset,
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002426 const void **data, size_t *size)
2427{
2428 int len;
2429
Stephen Warren712fbcf2011-10-18 11:11:49 +00002430 *data = fdt_getprop(fit, noffset, FIT_DATA_PROP, &len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002431 if (*data == NULL) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002432 fit_get_debug(fit, noffset, FIT_DATA_PROP, len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002433 *size = 0;
2434 return -1;
2435 }
2436
2437 *size = len;
2438 return 0;
2439}
2440
2441/**
2442 * fit_image_hash_get_algo - get hash algorithm name
2443 * @fit: pointer to the FIT format image header
2444 * @noffset: hash node offset
2445 * @algo: double pointer to char, will hold pointer to the algorithm name
2446 *
2447 * fit_image_hash_get_algo() finds hash algorithm property in a given hash node.
2448 * If the property is found its data start address is returned to the caller.
2449 *
2450 * returns:
2451 * 0, on success
2452 * -1, on failure
2453 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002454int fit_image_hash_get_algo(const void *fit, int noffset, char **algo)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002455{
2456 int len;
2457
Stephen Warren712fbcf2011-10-18 11:11:49 +00002458 *algo = (char *)fdt_getprop(fit, noffset, FIT_ALGO_PROP, &len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002459 if (*algo == NULL) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002460 fit_get_debug(fit, noffset, FIT_ALGO_PROP, len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002461 return -1;
2462 }
2463
2464 return 0;
2465}
2466
2467/**
2468 * fit_image_hash_get_value - get hash value and length
2469 * @fit: pointer to the FIT format image header
2470 * @noffset: hash node offset
2471 * @value: double pointer to uint8_t, will hold address of a hash value data
2472 * @value_len: pointer to an int, will hold hash data length
2473 *
2474 * fit_image_hash_get_value() finds hash value property in a given hash node.
2475 * If the property is found its data start address and size are returned to
2476 * the caller.
2477 *
2478 * returns:
2479 * 0, on success
2480 * -1, on failure
2481 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002482int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value,
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002483 int *value_len)
2484{
2485 int len;
2486
Stephen Warren712fbcf2011-10-18 11:11:49 +00002487 *value = (uint8_t *)fdt_getprop(fit, noffset, FIT_VALUE_PROP, &len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002488 if (*value == NULL) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002489 fit_get_debug(fit, noffset, FIT_VALUE_PROP, len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002490 *value_len = 0;
2491 return -1;
2492 }
2493
2494 *value_len = len;
2495 return 0;
2496}
2497
2498/**
2499 * fit_set_timestamp - set node timestamp property
2500 * @fit: pointer to the FIT format image header
2501 * @noffset: node offset
2502 * @timestamp: timestamp value to be set
2503 *
2504 * fit_set_timestamp() attempts to set timestamp property in the requested
2505 * node and returns operation status to the caller.
2506 *
2507 * returns:
2508 * 0, on success
2509 * -1, on property read failure
2510 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002511int fit_set_timestamp(void *fit, int noffset, time_t timestamp)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002512{
2513 uint32_t t;
2514 int ret;
2515
Stephen Warren712fbcf2011-10-18 11:11:49 +00002516 t = cpu_to_uimage(timestamp);
2517 ret = fdt_setprop(fit, noffset, FIT_TIMESTAMP_PROP, &t,
2518 sizeof(uint32_t));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002519 if (ret) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002520 printf("Can't set '%s' property for '%s' node (%s)\n",
2521 FIT_TIMESTAMP_PROP, fit_get_name(fit, noffset, NULL),
2522 fdt_strerror(ret));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002523 return -1;
2524 }
2525
2526 return 0;
2527}
2528
2529/**
2530 * calculate_hash - calculate and return hash for provided input data
2531 * @data: pointer to the input data
2532 * @data_len: data length
2533 * @algo: requested hash algorithm
2534 * @value: pointer to the char, will hold hash value data (caller must
2535 * allocate enough free space)
2536 * value_len: length of the calculated hash
2537 *
2538 * calculate_hash() computes input data hash according to the requested algorithm.
2539 * Resulting hash value is placed in caller provided 'value' buffer, length
2540 * of the calculated hash is returned via value_len pointer argument.
2541 *
2542 * returns:
2543 * 0, on success
2544 * -1, when algo is unsupported
2545 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002546static int calculate_hash(const void *data, int data_len, const char *algo,
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002547 uint8_t *value, int *value_len)
2548{
Stephen Warren712fbcf2011-10-18 11:11:49 +00002549 if (strcmp(algo, "crc32") == 0) {
2550 *((uint32_t *)value) = crc32_wd(0, data, data_len,
Bartlomiej Sieka75903782008-04-25 13:54:02 +02002551 CHUNKSZ_CRC32);
Stephen Warren712fbcf2011-10-18 11:11:49 +00002552 *((uint32_t *)value) = cpu_to_uimage(*((uint32_t *)value));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002553 *value_len = 4;
Stephen Warren712fbcf2011-10-18 11:11:49 +00002554 } else if (strcmp(algo, "sha1") == 0) {
2555 sha1_csum_wd((unsigned char *) data, data_len,
Bartlomiej Sieka75903782008-04-25 13:54:02 +02002556 (unsigned char *) value, CHUNKSZ_SHA1);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002557 *value_len = 20;
Stephen Warren712fbcf2011-10-18 11:11:49 +00002558 } else if (strcmp(algo, "md5") == 0) {
2559 md5_wd((unsigned char *)data, data_len, value, CHUNKSZ_MD5);
Bartlomiej Sieka766529f2008-03-14 16:22:34 +01002560 *value_len = 16;
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002561 } else {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002562 debug("Unsupported hash alogrithm\n");
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002563 return -1;
2564 }
2565 return 0;
2566}
2567
2568#ifdef USE_HOSTCC
2569/**
2570 * fit_set_hashes - process FIT component image nodes and calculate hashes
2571 * @fit: pointer to the FIT format image header
2572 *
2573 * fit_set_hashes() adds hash values for all component images in the FIT blob.
2574 * Hashes are calculated for all component images which have hash subnodes
2575 * with algorithm property set to one of the supported hash algorithms.
2576 *
2577 * returns
2578 * 0, on success
2579 * libfdt error code, on failure
2580 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002581int fit_set_hashes(void *fit)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002582{
2583 int images_noffset;
2584 int noffset;
2585 int ndepth;
2586 int ret;
2587
2588 /* Find images parent node offset */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002589 images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002590 if (images_noffset < 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002591 printf("Can't find images parent node '%s' (%s)\n",
2592 FIT_IMAGES_PATH, fdt_strerror(images_noffset));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002593 return images_noffset;
2594 }
2595
2596 /* Process its subnodes, print out component images details */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002597 for (ndepth = 0, noffset = fdt_next_node(fit, images_noffset, &ndepth);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002598 (noffset >= 0) && (ndepth > 0);
Stephen Warren712fbcf2011-10-18 11:11:49 +00002599 noffset = fdt_next_node(fit, noffset, &ndepth)) {
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002600 if (ndepth == 1) {
2601 /*
2602 * Direct child node of the images parent node,
2603 * i.e. component image node.
2604 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002605 ret = fit_image_set_hashes(fit, noffset);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002606 if (ret)
2607 return ret;
2608 }
2609 }
2610
2611 return 0;
2612}
2613
2614/**
2615 * fit_image_set_hashes - calculate/set hashes for given component image node
2616 * @fit: pointer to the FIT format image header
2617 * @image_noffset: requested component image node
2618 *
2619 * fit_image_set_hashes() adds hash values for an component image node. All
2620 * existing hash subnodes are checked, if algorithm property is set to one of
2621 * the supported hash algorithms, hash value is computed and corresponding
2622 * hash node property is set, for example:
2623 *
2624 * Input component image node structure:
2625 *
2626 * o image@1 (at image_noffset)
2627 * | - data = [binary data]
2628 * o hash@1
2629 * |- algo = "sha1"
2630 *
2631 * Output component image node structure:
2632 *
2633 * o image@1 (at image_noffset)
2634 * | - data = [binary data]
2635 * o hash@1
2636 * |- algo = "sha1"
2637 * |- value = sha1(data)
2638 *
2639 * returns:
2640 * 0 on sucess
2641 * <0 on failure
2642 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002643int fit_image_set_hashes(void *fit, int image_noffset)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002644{
2645 const void *data;
2646 size_t size;
2647 char *algo;
2648 uint8_t value[FIT_MAX_HASH_LEN];
2649 int value_len;
2650 int noffset;
2651 int ndepth;
2652
2653 /* Get image data and data length */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002654 if (fit_image_get_data(fit, image_noffset, &data, &size)) {
2655 printf("Can't get image data/size\n");
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002656 return -1;
2657 }
2658
2659 /* Process all hash subnodes of the component image node */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002660 for (ndepth = 0, noffset = fdt_next_node(fit, image_noffset, &ndepth);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002661 (noffset >= 0) && (ndepth > 0);
Stephen Warren712fbcf2011-10-18 11:11:49 +00002662 noffset = fdt_next_node(fit, noffset, &ndepth)) {
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002663 if (ndepth == 1) {
2664 /* Direct child node of the component image node */
2665
2666 /*
2667 * Check subnode name, must be equal to "hash".
2668 * Multiple hash nodes require unique unit node
2669 * names, e.g. hash@1, hash@2, etc.
2670 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002671 if (strncmp(fit_get_name(fit, noffset, NULL),
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002672 FIT_HASH_NODENAME,
2673 strlen(FIT_HASH_NODENAME)) != 0) {
2674 /* Not a hash subnode, skip it */
2675 continue;
2676 }
2677
Stephen Warren712fbcf2011-10-18 11:11:49 +00002678 if (fit_image_hash_get_algo(fit, noffset, &algo)) {
2679 printf("Can't get hash algo property for "
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002680 "'%s' hash node in '%s' image node\n",
Stephen Warren712fbcf2011-10-18 11:11:49 +00002681 fit_get_name(fit, noffset, NULL),
2682 fit_get_name(fit, image_noffset, NULL));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002683 return -1;
2684 }
2685
Stephen Warren712fbcf2011-10-18 11:11:49 +00002686 if (calculate_hash(data, size, algo, value,
2687 &value_len)) {
2688 printf("Unsupported hash algorithm (%s) for "
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002689 "'%s' hash node in '%s' image node\n",
Stephen Warren712fbcf2011-10-18 11:11:49 +00002690 algo, fit_get_name(fit, noffset, NULL),
2691 fit_get_name(fit, image_noffset,
2692 NULL));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002693 return -1;
2694 }
2695
Stephen Warren712fbcf2011-10-18 11:11:49 +00002696 if (fit_image_hash_set_value(fit, noffset, value,
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002697 value_len)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002698 printf("Can't set hash value for "
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002699 "'%s' hash node in '%s' image node\n",
Stephen Warren712fbcf2011-10-18 11:11:49 +00002700 fit_get_name(fit, noffset, NULL),
2701 fit_get_name(fit, image_noffset, NULL));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002702 return -1;
2703 }
2704 }
2705 }
2706
2707 return 0;
2708}
2709
2710/**
2711 * fit_image_hash_set_value - set hash value in requested has node
2712 * @fit: pointer to the FIT format image header
2713 * @noffset: hash node offset
2714 * @value: hash value to be set
2715 * @value_len: hash value length
2716 *
2717 * fit_image_hash_set_value() attempts to set hash value in a node at offset
2718 * given and returns operation status to the caller.
2719 *
2720 * returns
2721 * 0, on success
2722 * -1, on failure
2723 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002724int fit_image_hash_set_value(void *fit, int noffset, uint8_t *value,
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002725 int value_len)
2726{
2727 int ret;
2728
Stephen Warren712fbcf2011-10-18 11:11:49 +00002729 ret = fdt_setprop(fit, noffset, FIT_VALUE_PROP, value, value_len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002730 if (ret) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002731 printf("Can't set hash '%s' property for '%s' node(%s)\n",
2732 FIT_VALUE_PROP, fit_get_name(fit, noffset, NULL),
2733 fdt_strerror(ret));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002734 return -1;
2735 }
2736
2737 return 0;
2738}
2739#endif /* USE_HOSTCC */
2740
2741/**
2742 * fit_image_check_hashes - verify data intergity
2743 * @fit: pointer to the FIT format image header
2744 * @image_noffset: component image node offset
2745 *
2746 * fit_image_check_hashes() goes over component image hash nodes,
2747 * re-calculates each data hash and compares with the value stored in hash
2748 * node.
2749 *
2750 * returns:
2751 * 1, if all hashes are valid
2752 * 0, otherwise (or on error)
2753 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002754int fit_image_check_hashes(const void *fit, int image_noffset)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002755{
2756 const void *data;
2757 size_t size;
2758 char *algo;
2759 uint8_t *fit_value;
2760 int fit_value_len;
2761 uint8_t value[FIT_MAX_HASH_LEN];
2762 int value_len;
2763 int noffset;
2764 int ndepth;
2765 char *err_msg = "";
2766
2767 /* Get image data and data length */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002768 if (fit_image_get_data(fit, image_noffset, &data, &size)) {
2769 printf("Can't get image data/size\n");
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002770 return 0;
2771 }
2772
2773 /* Process all hash subnodes of the component image node */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002774 for (ndepth = 0, noffset = fdt_next_node(fit, image_noffset, &ndepth);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002775 (noffset >= 0) && (ndepth > 0);
Stephen Warren712fbcf2011-10-18 11:11:49 +00002776 noffset = fdt_next_node(fit, noffset, &ndepth)) {
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002777 if (ndepth == 1) {
2778 /* Direct child node of the component image node */
2779
2780 /*
2781 * Check subnode name, must be equal to "hash".
2782 * Multiple hash nodes require unique unit node
2783 * names, e.g. hash@1, hash@2, etc.
2784 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002785 if (strncmp(fit_get_name(fit, noffset, NULL),
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002786 FIT_HASH_NODENAME,
2787 strlen(FIT_HASH_NODENAME)) != 0)
2788 continue;
2789
Stephen Warren712fbcf2011-10-18 11:11:49 +00002790 if (fit_image_hash_get_algo(fit, noffset, &algo)) {
Bartlomiej Sieka919f5502008-09-09 12:58:15 +02002791 err_msg = " error!\nCan't get hash algo "
2792 "property";
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002793 goto error;
2794 }
Stephen Warren712fbcf2011-10-18 11:11:49 +00002795 printf("%s", algo);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002796
Stephen Warren712fbcf2011-10-18 11:11:49 +00002797 if (fit_image_hash_get_value(fit, noffset, &fit_value,
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002798 &fit_value_len)) {
Bartlomiej Sieka919f5502008-09-09 12:58:15 +02002799 err_msg = " error!\nCan't get hash value "
2800 "property";
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002801 goto error;
2802 }
2803
Stephen Warren712fbcf2011-10-18 11:11:49 +00002804 if (calculate_hash(data, size, algo, value,
2805 &value_len)) {
2806 err_msg = " error!\n"
2807 "Unsupported hash algorithm";
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002808 goto error;
2809 }
2810
2811 if (value_len != fit_value_len) {
Bartlomiej Sieka919f5502008-09-09 12:58:15 +02002812 err_msg = " error !\nBad hash value len";
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002813 goto error;
Stephen Warren712fbcf2011-10-18 11:11:49 +00002814 } else if (memcmp(value, fit_value, value_len) != 0) {
Bartlomiej Sieka919f5502008-09-09 12:58:15 +02002815 err_msg = " error!\nBad hash value";
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002816 goto error;
2817 }
Stephen Warren712fbcf2011-10-18 11:11:49 +00002818 printf("+ ");
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002819 }
2820 }
2821
2822 return 1;
2823
2824error:
Stephen Warren712fbcf2011-10-18 11:11:49 +00002825 printf("%s for '%s' hash node in '%s' image node\n",
2826 err_msg, fit_get_name(fit, noffset, NULL),
2827 fit_get_name(fit, image_noffset, NULL));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002828 return 0;
2829}
2830
2831/**
Bartlomiej Sieka919f5502008-09-09 12:58:15 +02002832 * fit_all_image_check_hashes - verify data intergity for all images
2833 * @fit: pointer to the FIT format image header
2834 *
2835 * fit_all_image_check_hashes() goes over all images in the FIT and
2836 * for every images checks if all it's hashes are valid.
2837 *
2838 * returns:
2839 * 1, if all hashes of all images are valid
2840 * 0, otherwise (or on error)
2841 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002842int fit_all_image_check_hashes(const void *fit)
Bartlomiej Sieka919f5502008-09-09 12:58:15 +02002843{
2844 int images_noffset;
2845 int noffset;
2846 int ndepth;
2847 int count;
2848
2849 /* Find images parent node offset */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002850 images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
Bartlomiej Sieka919f5502008-09-09 12:58:15 +02002851 if (images_noffset < 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00002852 printf("Can't find images parent node '%s' (%s)\n",
2853 FIT_IMAGES_PATH, fdt_strerror(images_noffset));
Bartlomiej Sieka919f5502008-09-09 12:58:15 +02002854 return 0;
2855 }
2856
2857 /* Process all image subnodes, check hashes for each */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002858 printf("## Checking hash(es) for FIT Image at %08lx ...\n",
Bartlomiej Sieka919f5502008-09-09 12:58:15 +02002859 (ulong)fit);
2860 for (ndepth = 0, count = 0,
Stephen Warren712fbcf2011-10-18 11:11:49 +00002861 noffset = fdt_next_node(fit, images_noffset, &ndepth);
Bartlomiej Sieka919f5502008-09-09 12:58:15 +02002862 (noffset >= 0) && (ndepth > 0);
Stephen Warren712fbcf2011-10-18 11:11:49 +00002863 noffset = fdt_next_node(fit, noffset, &ndepth)) {
Bartlomiej Sieka919f5502008-09-09 12:58:15 +02002864 if (ndepth == 1) {
2865 /*
2866 * Direct child node of the images parent node,
2867 * i.e. component image node.
2868 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002869 printf(" Hash(es) for Image %u (%s): ", count++,
2870 fit_get_name(fit, noffset, NULL));
Bartlomiej Sieka919f5502008-09-09 12:58:15 +02002871
Stephen Warren712fbcf2011-10-18 11:11:49 +00002872 if (!fit_image_check_hashes(fit, noffset))
Bartlomiej Sieka919f5502008-09-09 12:58:15 +02002873 return 0;
Stephen Warren712fbcf2011-10-18 11:11:49 +00002874 printf("\n");
Bartlomiej Sieka919f5502008-09-09 12:58:15 +02002875 }
2876 }
2877 return 1;
2878}
2879
2880/**
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002881 * fit_image_check_os - check whether image node is of a given os type
2882 * @fit: pointer to the FIT format image header
2883 * @noffset: component image node offset
2884 * @os: requested image os
2885 *
2886 * fit_image_check_os() reads image os property and compares its numeric
2887 * id with the requested os. Comparison result is returned to the caller.
2888 *
2889 * returns:
2890 * 1 if image is of given os type
2891 * 0 otherwise (or on error)
2892 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002893int fit_image_check_os(const void *fit, int noffset, uint8_t os)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002894{
2895 uint8_t image_os;
2896
Stephen Warren712fbcf2011-10-18 11:11:49 +00002897 if (fit_image_get_os(fit, noffset, &image_os))
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002898 return 0;
2899 return (os == image_os);
2900}
2901
2902/**
2903 * fit_image_check_arch - check whether image node is of a given arch
2904 * @fit: pointer to the FIT format image header
2905 * @noffset: component image node offset
2906 * @arch: requested imagearch
2907 *
2908 * fit_image_check_arch() reads image arch property and compares its numeric
2909 * id with the requested arch. Comparison result is returned to the caller.
2910 *
2911 * returns:
2912 * 1 if image is of given arch
2913 * 0 otherwise (or on error)
2914 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002915int fit_image_check_arch(const void *fit, int noffset, uint8_t arch)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002916{
2917 uint8_t image_arch;
2918
Stephen Warren712fbcf2011-10-18 11:11:49 +00002919 if (fit_image_get_arch(fit, noffset, &image_arch))
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002920 return 0;
2921 return (arch == image_arch);
2922}
2923
2924/**
2925 * fit_image_check_type - check whether image node is of a given type
2926 * @fit: pointer to the FIT format image header
2927 * @noffset: component image node offset
2928 * @type: requested image type
2929 *
2930 * fit_image_check_type() reads image type property and compares its numeric
2931 * id with the requested type. Comparison result is returned to the caller.
2932 *
2933 * returns:
2934 * 1 if image is of given type
2935 * 0 otherwise (or on error)
2936 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002937int fit_image_check_type(const void *fit, int noffset, uint8_t type)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002938{
2939 uint8_t image_type;
2940
Stephen Warren712fbcf2011-10-18 11:11:49 +00002941 if (fit_image_get_type(fit, noffset, &image_type))
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002942 return 0;
2943 return (type == image_type);
2944}
2945
2946/**
2947 * fit_image_check_comp - check whether image node uses given compression
2948 * @fit: pointer to the FIT format image header
2949 * @noffset: component image node offset
2950 * @comp: requested image compression type
2951 *
2952 * fit_image_check_comp() reads image compression property and compares its
2953 * numeric id with the requested compression type. Comparison result is
2954 * returned to the caller.
2955 *
2956 * returns:
2957 * 1 if image uses requested compression
2958 * 0 otherwise (or on error)
2959 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002960int fit_image_check_comp(const void *fit, int noffset, uint8_t comp)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002961{
2962 uint8_t image_comp;
2963
Stephen Warren712fbcf2011-10-18 11:11:49 +00002964 if (fit_image_get_comp(fit, noffset, &image_comp))
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002965 return 0;
2966 return (comp == image_comp);
2967}
2968
2969/**
2970 * fit_check_format - sanity check FIT image format
2971 * @fit: pointer to the FIT format image header
2972 *
2973 * fit_check_format() runs a basic sanity FIT image verification.
2974 * Routine checks for mandatory properties, nodes, etc.
2975 *
2976 * returns:
2977 * 1, on success
2978 * 0, on failure
2979 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002980int fit_check_format(const void *fit)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002981{
2982 /* mandatory / node 'description' property */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002983 if (fdt_getprop(fit, 0, FIT_DESC_PROP, NULL) == NULL) {
2984 debug("Wrong FIT format: no description\n");
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002985 return 0;
2986 }
2987
2988#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
2989 /* mandatory / node 'timestamp' property */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002990 if (fdt_getprop(fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) {
2991 debug("Wrong FIT format: no timestamp\n");
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002992 return 0;
2993 }
2994#endif
2995
2996 /* mandatory subimages parent '/images' node */
Stephen Warren712fbcf2011-10-18 11:11:49 +00002997 if (fdt_path_offset(fit, FIT_IMAGES_PATH) < 0) {
2998 debug("Wrong FIT format: no images parent node\n");
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01002999 return 0;
3000 }
3001
3002 return 1;
3003}
3004
3005/**
3006 * fit_conf_get_node - get node offset for configuration of a given unit name
3007 * @fit: pointer to the FIT format image header
3008 * @conf_uname: configuration node unit name
3009 *
3010 * fit_conf_get_node() finds a configuration (withing the '/configurations'
3011 * parant node) of a provided unit name. If configuration is found its node offset
3012 * is returned to the caller.
3013 *
3014 * When NULL is provided in second argument fit_conf_get_node() will search
3015 * for a default configuration node instead. Default configuration node unit name
3016 * is retrived from FIT_DEFAULT_PROP property of the '/configurations' node.
3017 *
3018 * returns:
3019 * configuration node offset when found (>=0)
3020 * negative number on failure (FDT_ERR_* code)
3021 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00003022int fit_conf_get_node(const void *fit, const char *conf_uname)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003023{
3024 int noffset, confs_noffset;
3025 int len;
3026
Stephen Warren712fbcf2011-10-18 11:11:49 +00003027 confs_noffset = fdt_path_offset(fit, FIT_CONFS_PATH);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003028 if (confs_noffset < 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00003029 debug("Can't find configurations parent node '%s' (%s)\n",
3030 FIT_CONFS_PATH, fdt_strerror(confs_noffset));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003031 return confs_noffset;
3032 }
3033
3034 if (conf_uname == NULL) {
3035 /* get configuration unit name from the default property */
Stephen Warren712fbcf2011-10-18 11:11:49 +00003036 debug("No configuration specified, trying default...\n");
3037 conf_uname = (char *)fdt_getprop(fit, confs_noffset,
3038 FIT_DEFAULT_PROP, &len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003039 if (conf_uname == NULL) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00003040 fit_get_debug(fit, confs_noffset, FIT_DEFAULT_PROP,
3041 len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003042 return len;
3043 }
Stephen Warren712fbcf2011-10-18 11:11:49 +00003044 debug("Found default configuration: '%s'\n", conf_uname);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003045 }
3046
Stephen Warren712fbcf2011-10-18 11:11:49 +00003047 noffset = fdt_subnode_offset(fit, confs_noffset, conf_uname);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003048 if (noffset < 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00003049 debug("Can't get node offset for configuration unit name: "
3050 "'%s' (%s)\n",
3051 conf_uname, fdt_strerror(noffset));
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003052 }
3053
3054 return noffset;
3055}
3056
Stephen Warren712fbcf2011-10-18 11:11:49 +00003057static int __fit_conf_get_prop_node(const void *fit, int noffset,
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003058 const char *prop_name)
3059{
3060 char *uname;
3061 int len;
3062
3063 /* get kernel image unit name from configuration kernel property */
Stephen Warren712fbcf2011-10-18 11:11:49 +00003064 uname = (char *)fdt_getprop(fit, noffset, prop_name, &len);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003065 if (uname == NULL)
3066 return len;
3067
Stephen Warren712fbcf2011-10-18 11:11:49 +00003068 return fit_image_get_node(fit, uname);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003069}
3070
3071/**
3072 * fit_conf_get_kernel_node - get kernel image node offset that corresponds to
3073 * a given configuration
3074 * @fit: pointer to the FIT format image header
3075 * @noffset: configuration node offset
3076 *
3077 * fit_conf_get_kernel_node() retrives kernel image node unit name from
3078 * configuration FIT_KERNEL_PROP property and translates it to the node
3079 * offset.
3080 *
3081 * returns:
3082 * image node offset when found (>=0)
3083 * negative number on failure (FDT_ERR_* code)
3084 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00003085int fit_conf_get_kernel_node(const void *fit, int noffset)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003086{
Stephen Warren712fbcf2011-10-18 11:11:49 +00003087 return __fit_conf_get_prop_node(fit, noffset, FIT_KERNEL_PROP);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003088}
3089
3090/**
3091 * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to
3092 * a given configuration
3093 * @fit: pointer to the FIT format image header
3094 * @noffset: configuration node offset
3095 *
3096 * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from
3097 * configuration FIT_KERNEL_PROP property and translates it to the node
3098 * offset.
3099 *
3100 * returns:
3101 * image node offset when found (>=0)
3102 * negative number on failure (FDT_ERR_* code)
3103 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00003104int fit_conf_get_ramdisk_node(const void *fit, int noffset)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003105{
Stephen Warren712fbcf2011-10-18 11:11:49 +00003106 return __fit_conf_get_prop_node(fit, noffset, FIT_RAMDISK_PROP);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003107}
3108
3109/**
3110 * fit_conf_get_fdt_node - get fdt image node offset that corresponds to
3111 * a given configuration
3112 * @fit: pointer to the FIT format image header
3113 * @noffset: configuration node offset
3114 *
3115 * fit_conf_get_fdt_node() retrives fdt image node unit name from
3116 * configuration FIT_KERNEL_PROP property and translates it to the node
3117 * offset.
3118 *
3119 * returns:
3120 * image node offset when found (>=0)
3121 * negative number on failure (FDT_ERR_* code)
3122 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00003123int fit_conf_get_fdt_node(const void *fit, int noffset)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003124{
Stephen Warren712fbcf2011-10-18 11:11:49 +00003125 return __fit_conf_get_prop_node(fit, noffset, FIT_FDT_PROP);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003126}
3127
3128/**
3129 * fit_conf_print - prints out the FIT configuration details
3130 * @fit: pointer to the FIT format image header
Marian Balakowiczf773bea2008-03-12 10:35:46 +01003131 * @noffset: offset of the configuration node
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003132 * @p: pointer to prefix string
3133 *
3134 * fit_conf_print() lists all mandatory properies for the processed
3135 * configuration node.
3136 *
3137 * returns:
3138 * no returned results
3139 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00003140void fit_conf_print(const void *fit, int noffset, const char *p)
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003141{
3142 char *desc;
3143 char *uname;
3144 int ret;
3145
3146 /* Mandatory properties */
Stephen Warren712fbcf2011-10-18 11:11:49 +00003147 ret = fit_get_desc(fit, noffset, &desc);
3148 printf("%s Description: ", p);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003149 if (ret)
Stephen Warren712fbcf2011-10-18 11:11:49 +00003150 printf("unavailable\n");
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003151 else
Stephen Warren712fbcf2011-10-18 11:11:49 +00003152 printf("%s\n", desc);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003153
Stephen Warren712fbcf2011-10-18 11:11:49 +00003154 uname = (char *)fdt_getprop(fit, noffset, FIT_KERNEL_PROP, NULL);
3155 printf("%s Kernel: ", p);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003156 if (uname == NULL)
Stephen Warren712fbcf2011-10-18 11:11:49 +00003157 printf("unavailable\n");
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003158 else
Stephen Warren712fbcf2011-10-18 11:11:49 +00003159 printf("%s\n", uname);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003160
3161 /* Optional properties */
Stephen Warren712fbcf2011-10-18 11:11:49 +00003162 uname = (char *)fdt_getprop(fit, noffset, FIT_RAMDISK_PROP, NULL);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003163 if (uname)
Stephen Warren712fbcf2011-10-18 11:11:49 +00003164 printf("%s Init Ramdisk: %s\n", p, uname);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003165
Stephen Warren712fbcf2011-10-18 11:11:49 +00003166 uname = (char *)fdt_getprop(fit, noffset, FIT_FDT_PROP, NULL);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003167 if (uname)
Stephen Warren712fbcf2011-10-18 11:11:49 +00003168 printf("%s FDT: %s\n", p, uname);
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003169}
Marian Balakowiczc8779642008-03-12 10:12:37 +01003170
3171/**
3172 * fit_check_ramdisk - verify FIT format ramdisk subimage
3173 * @fit_hdr: pointer to the FIT ramdisk header
3174 * @rd_noffset: ramdisk subimage node offset within FIT image
3175 * @arch: requested ramdisk image architecture type
3176 * @verify: data CRC verification flag
3177 *
3178 * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from
3179 * specified FIT image.
3180 *
3181 * returns:
3182 * 1, on success
3183 * 0, on failure
3184 */
3185#ifndef USE_HOSTCC
Stephen Warren712fbcf2011-10-18 11:11:49 +00003186static int fit_check_ramdisk(const void *fit, int rd_noffset, uint8_t arch,
3187 int verify)
Marian Balakowiczc8779642008-03-12 10:12:37 +01003188{
Stephen Warren712fbcf2011-10-18 11:11:49 +00003189 fit_image_print(fit, rd_noffset, " ");
Marian Balakowiczc8779642008-03-12 10:12:37 +01003190
3191 if (verify) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00003192 puts(" Verifying Hash Integrity ... ");
3193 if (!fit_image_check_hashes(fit, rd_noffset)) {
3194 puts("Bad Data Hash\n");
Simon Glass770605e2012-02-13 13:51:18 +00003195 bootstage_error(BOOTSTAGE_ID_FIT_RD_HASH);
Marian Balakowiczc8779642008-03-12 10:12:37 +01003196 return 0;
3197 }
Stephen Warren712fbcf2011-10-18 11:11:49 +00003198 puts("OK\n");
Marian Balakowiczc8779642008-03-12 10:12:37 +01003199 }
3200
Simon Glass770605e2012-02-13 13:51:18 +00003201 bootstage_mark(BOOTSTAGE_ID_FIT_RD_CHECK_ALL);
Stephen Warren712fbcf2011-10-18 11:11:49 +00003202 if (!fit_image_check_os(fit, rd_noffset, IH_OS_LINUX) ||
3203 !fit_image_check_arch(fit, rd_noffset, arch) ||
3204 !fit_image_check_type(fit, rd_noffset, IH_TYPE_RAMDISK)) {
3205 printf("No Linux %s Ramdisk Image\n",
Marian Balakowiczc8779642008-03-12 10:12:37 +01003206 genimg_get_arch_name(arch));
Simon Glass770605e2012-02-13 13:51:18 +00003207 bootstage_error(BOOTSTAGE_ID_FIT_RD_CHECK_ALL);
Marian Balakowiczc8779642008-03-12 10:12:37 +01003208 return 0;
3209 }
3210
Simon Glass770605e2012-02-13 13:51:18 +00003211 bootstage_mark(BOOTSTAGE_ID_FIT_RD_CHECK_ALL_OK);
Marian Balakowiczc8779642008-03-12 10:12:37 +01003212 return 1;
3213}
3214#endif /* USE_HOSTCC */
Marian Balakowicz5dfb5212008-02-29 21:24:06 +01003215#endif /* CONFIG_FIT */