Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 1 | /* |
| 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 Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 25 | |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 26 | #ifndef USE_HOSTCC |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 27 | #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 Balakowicz | 95d449a | 2008-05-13 15:53:29 +0200 | [diff] [blame] | 38 | #ifdef CONFIG_LOGBUFFER |
| 39 | #include <logbuff.h> |
| 40 | #endif |
| 41 | |
Marian Balakowicz | 2242f53 | 2008-02-21 17:27:41 +0100 | [diff] [blame] | 42 | #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) |
| 43 | #include <rtc.h> |
| 44 | #endif |
| 45 | |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 46 | #include <image.h> |
| 47 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 48 | #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT) |
Marian Balakowicz | fff888a1 | 2008-02-21 17:20:19 +0100 | [diff] [blame] | 49 | #include <fdt.h> |
| 50 | #include <libfdt.h> |
| 51 | #include <fdt_support.h> |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 52 | #endif |
| 53 | |
| 54 | #if defined(CONFIG_FIT) |
Andy Fleming | 20a14a4 | 2008-04-02 16:19:07 -0500 | [diff] [blame] | 55 | #include <u-boot/md5.h> |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 56 | #include <sha1.h> |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 57 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 58 | static int fit_check_ramdisk(const void *fit, int os_noffset, |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 59 | uint8_t arch, int verify); |
Marian Balakowicz | fff888a1 | 2008-02-21 17:20:19 +0100 | [diff] [blame] | 60 | #endif |
| 61 | |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 62 | #ifdef CONFIG_CMD_BDI |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 63 | extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 64 | #endif |
| 65 | |
| 66 | DECLARE_GLOBAL_DATA_PTR; |
Marian Balakowicz | 8a5ea3e | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 67 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 68 | static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch, |
Marian Balakowicz | d985c84 | 2008-03-12 10:14:38 +0100 | [diff] [blame] | 69 | int verify); |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 70 | #else |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 71 | #include "mkimage.h" |
Andy Fleming | 20a14a4 | 2008-04-02 16:19:07 -0500 | [diff] [blame] | 72 | #include <u-boot/md5.h> |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 73 | #include <time.h> |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 74 | #include <image.h> |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 75 | #endif /* !USE_HOSTCC*/ |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 76 | |
Mike Frysinger | 7edb186 | 2010-10-20 07:17:39 -0400 | [diff] [blame] | 77 | static const table_entry_t uimage_arch[] = { |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 78 | { 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 Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 87 | { IH_ARCH_NIOS2, "nios2", "NIOS II", }, |
Grant Erickson | e419e12 | 2008-05-04 16:45:01 -0700 | [diff] [blame] | 88 | { IH_ARCH_PPC, "powerpc", "PowerPC", }, |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 89 | { 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 Lin | 64d6146 | 2011-10-19 20:41:09 +0000 | [diff] [blame] | 96 | { IH_ARCH_NDS32, "nds32", "NDS32", }, |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 97 | { -1, "", "", }, |
| 98 | }; |
| 99 | |
Mike Frysinger | 7edb186 | 2010-10-20 07:17:39 -0400 | [diff] [blame] | 100 | static const table_entry_t uimage_os[] = { |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 101 | { IH_OS_INVALID, NULL, "Invalid OS", }, |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 102 | { IH_OS_LINUX, "linux", "Linux", }, |
| 103 | #if defined(CONFIG_LYNXKDI) || defined(USE_HOSTCC) |
| 104 | { IH_OS_LYNXOS, "lynxos", "LynxOS", }, |
| 105 | #endif |
| 106 | { IH_OS_NETBSD, "netbsd", "NetBSD", }, |
Torkel Lundgren | 3df6195 | 2010-09-28 11:05:36 +0200 | [diff] [blame] | 107 | { IH_OS_OSE, "ose", "Enea OSE", }, |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 108 | { IH_OS_RTEMS, "rtems", "RTEMS", }, |
| 109 | { IH_OS_U_BOOT, "u-boot", "U-Boot", }, |
| 110 | #if defined(CONFIG_CMD_ELF) || defined(USE_HOSTCC) |
| 111 | { IH_OS_QNX, "qnx", "QNX", }, |
| 112 | { IH_OS_VXWORKS, "vxworks", "VxWorks", }, |
| 113 | #endif |
Peter Tyser | f5ed9e3 | 2008-09-08 14:56:49 -0500 | [diff] [blame] | 114 | #if defined(CONFIG_INTEGRITY) || defined(USE_HOSTCC) |
| 115 | { IH_OS_INTEGRITY,"integrity", "INTEGRITY", }, |
| 116 | #endif |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 117 | #ifdef USE_HOSTCC |
| 118 | { IH_OS_4_4BSD, "4_4bsd", "4_4BSD", }, |
| 119 | { IH_OS_DELL, "dell", "Dell", }, |
| 120 | { IH_OS_ESIX, "esix", "Esix", }, |
| 121 | { IH_OS_FREEBSD, "freebsd", "FreeBSD", }, |
| 122 | { IH_OS_IRIX, "irix", "Irix", }, |
| 123 | { IH_OS_NCR, "ncr", "NCR", }, |
| 124 | { IH_OS_OPENBSD, "openbsd", "OpenBSD", }, |
| 125 | { IH_OS_PSOS, "psos", "pSOS", }, |
| 126 | { IH_OS_SCO, "sco", "SCO", }, |
| 127 | { IH_OS_SOLARIS, "solaris", "Solaris", }, |
| 128 | { IH_OS_SVR4, "svr4", "SVR4", }, |
| 129 | #endif |
| 130 | { -1, "", "", }, |
| 131 | }; |
| 132 | |
Mike Frysinger | 7edb186 | 2010-10-20 07:17:39 -0400 | [diff] [blame] | 133 | static const table_entry_t uimage_type[] = { |
Stefano Babic | 4962e38 | 2011-10-17 00:07:43 +0000 | [diff] [blame] | 134 | { IH_TYPE_AISIMAGE, "aisimage", "Davinci AIS image",}, |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 135 | { IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image", }, |
| 136 | { IH_TYPE_FIRMWARE, "firmware", "Firmware", }, |
John Rigby | 3decb14 | 2011-07-21 09:10:30 -0400 | [diff] [blame] | 137 | { IH_TYPE_FLATDT, "flat_dt", "Flat Device Tree", }, |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 138 | { IH_TYPE_KERNEL, "kernel", "Kernel Image", }, |
Stephen Warren | b9b50e89 | 2011-11-10 13:17:53 -0700 | [diff] [blame] | 139 | { IH_TYPE_KERNEL_NOLOAD, "kernel_noload", "Kernel Image (no loading done)", }, |
Stefano Babic | 4962e38 | 2011-10-17 00:07:43 +0000 | [diff] [blame] | 140 | { IH_TYPE_KWBIMAGE, "kwbimage", "Kirkwood Boot Image",}, |
| 141 | { IH_TYPE_IMXIMAGE, "imximage", "Freescale i.MX Boot Image",}, |
| 142 | { IH_TYPE_INVALID, NULL, "Invalid Image", }, |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 143 | { IH_TYPE_MULTI, "multi", "Multi-File Image", }, |
Stefano Babic | 4962e38 | 2011-10-17 00:07:43 +0000 | [diff] [blame] | 144 | { IH_TYPE_OMAPIMAGE, "omapimage", "TI OMAP SPL With GP CH",}, |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 145 | { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", }, |
| 146 | { IH_TYPE_SCRIPT, "script", "Script", }, |
| 147 | { IH_TYPE_STANDALONE, "standalone", "Standalone Program", }, |
Heiko Schocher | 7816f2c | 2011-07-16 00:06:42 +0000 | [diff] [blame] | 148 | { IH_TYPE_UBLIMAGE, "ublimage", "Davinci UBL image",}, |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 149 | { -1, "", "", }, |
| 150 | }; |
| 151 | |
Mike Frysinger | 7edb186 | 2010-10-20 07:17:39 -0400 | [diff] [blame] | 152 | static const table_entry_t uimage_comp[] = { |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 153 | { IH_COMP_NONE, "none", "uncompressed", }, |
| 154 | { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", }, |
| 155 | { IH_COMP_GZIP, "gzip", "gzip compressed", }, |
Luigi 'Comio' Mantellini | fc9c172 | 2008-09-08 02:46:13 +0200 | [diff] [blame] | 156 | { IH_COMP_LZMA, "lzma", "lzma compressed", }, |
Peter Korsgaard | 20dde48 | 2009-11-19 11:37:51 +0100 | [diff] [blame] | 157 | { IH_COMP_LZO, "lzo", "lzo compressed", }, |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 158 | { -1, "", "", }, |
| 159 | }; |
| 160 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 161 | uint32_t crc32(uint32_t, const unsigned char *, uint); |
| 162 | uint32_t crc32_wd(uint32_t, const unsigned char *, uint, uint); |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 163 | #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 164 | static void genimg_print_time(time_t timestamp); |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 165 | #endif |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 166 | |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 167 | /*****************************************************************************/ |
| 168 | /* Legacy format routines */ |
| 169 | /*****************************************************************************/ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 170 | int image_check_hcrc(const image_header_t *hdr) |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 171 | { |
| 172 | ulong hcrc; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 173 | ulong len = image_get_header_size(); |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 174 | image_header_t header; |
| 175 | |
| 176 | /* Copy header so we can blank CRC field for re-calculation */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 177 | memmove(&header, (char *)hdr, image_get_header_size()); |
| 178 | image_set_hcrc(&header, 0); |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 179 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 180 | hcrc = crc32(0, (unsigned char *)&header, len); |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 181 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 182 | return (hcrc == image_get_hcrc(hdr)); |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 183 | } |
| 184 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 185 | int image_check_dcrc(const image_header_t *hdr) |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 186 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 187 | ulong data = image_get_data(hdr); |
| 188 | ulong len = image_get_data_size(hdr); |
| 189 | ulong dcrc = crc32_wd(0, (unsigned char *)data, len, CHUNKSZ_CRC32); |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 190 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 191 | return (dcrc == image_get_dcrc(hdr)); |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 192 | } |
| 193 | |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 194 | /** |
| 195 | * image_multi_count - get component (sub-image) count |
| 196 | * @hdr: pointer to the header of the multi component image |
| 197 | * |
| 198 | * image_multi_count() returns number of components in a multi |
| 199 | * component image. |
| 200 | * |
| 201 | * Note: no checking of the image type is done, caller must pass |
| 202 | * a valid multi component image. |
| 203 | * |
| 204 | * returns: |
| 205 | * number of components |
| 206 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 207 | ulong image_multi_count(const image_header_t *hdr) |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 208 | { |
| 209 | ulong i, count = 0; |
Marian Balakowicz | df6f1b8 | 2008-02-29 16:00:06 +0100 | [diff] [blame] | 210 | uint32_t *size; |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 211 | |
| 212 | /* get start of the image payload, which in case of multi |
| 213 | * component images that points to a table of component sizes */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 214 | size = (uint32_t *)image_get_data(hdr); |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 215 | |
| 216 | /* count non empty slots */ |
| 217 | for (i = 0; size[i]; ++i) |
| 218 | count++; |
| 219 | |
| 220 | return count; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * image_multi_getimg - get component data address and size |
| 225 | * @hdr: pointer to the header of the multi component image |
| 226 | * @idx: index of the requested component |
| 227 | * @data: pointer to a ulong variable, will hold component data address |
| 228 | * @len: pointer to a ulong variable, will hold component size |
| 229 | * |
| 230 | * image_multi_getimg() returns size and data address for the requested |
| 231 | * component in a multi component image. |
| 232 | * |
| 233 | * Note: no checking of the image type is done, caller must pass |
| 234 | * a valid multi component image. |
| 235 | * |
| 236 | * returns: |
| 237 | * data address and size of the component, if idx is valid |
| 238 | * 0 in data and len, if idx is out of range |
| 239 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 240 | void image_multi_getimg(const image_header_t *hdr, ulong idx, |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 241 | ulong *data, ulong *len) |
| 242 | { |
| 243 | int i; |
Marian Balakowicz | df6f1b8 | 2008-02-29 16:00:06 +0100 | [diff] [blame] | 244 | uint32_t *size; |
Nick Spence | 02b9b22 | 2008-05-10 14:02:04 -0700 | [diff] [blame] | 245 | ulong offset, count, img_data; |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 246 | |
| 247 | /* get number of component */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 248 | count = image_multi_count(hdr); |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 249 | |
| 250 | /* get start of the image payload, which in case of multi |
| 251 | * component images that points to a table of component sizes */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 252 | size = (uint32_t *)image_get_data(hdr); |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 253 | |
| 254 | /* get address of the proper component data start, which means |
| 255 | * skipping sizes table (add 1 for last, null entry) */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 256 | img_data = image_get_data(hdr) + (count + 1) * sizeof(uint32_t); |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 257 | |
| 258 | if (idx < count) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 259 | *len = uimage_to_cpu(size[idx]); |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 260 | offset = 0; |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 261 | |
| 262 | /* go over all indices preceding requested component idx */ |
| 263 | for (i = 0; i < idx; i++) { |
Nick Spence | 02b9b22 | 2008-05-10 14:02:04 -0700 | [diff] [blame] | 264 | /* add up i-th component size, rounding up to 4 bytes */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 265 | offset += (uimage_to_cpu(size[i]) + 3) & ~3 ; |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | /* calculate idx-th component data address */ |
Nick Spence | 02b9b22 | 2008-05-10 14:02:04 -0700 | [diff] [blame] | 269 | *data = img_data + offset; |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 270 | } else { |
| 271 | *len = 0; |
| 272 | *data = 0; |
| 273 | } |
| 274 | } |
Marian Balakowicz | 42b73e8 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 275 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 276 | static void image_print_type(const image_header_t *hdr) |
Marian Balakowicz | 2242f53 | 2008-02-21 17:27:41 +0100 | [diff] [blame] | 277 | { |
| 278 | const char *os, *arch, *type, *comp; |
| 279 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 280 | os = genimg_get_os_name(image_get_os(hdr)); |
| 281 | arch = genimg_get_arch_name(image_get_arch(hdr)); |
| 282 | type = genimg_get_type_name(image_get_type(hdr)); |
| 283 | comp = genimg_get_comp_name(image_get_comp(hdr)); |
Marian Balakowicz | 2242f53 | 2008-02-21 17:27:41 +0100 | [diff] [blame] | 284 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 285 | printf("%s %s %s (%s)\n", arch, os, type, comp); |
Marian Balakowicz | 2242f53 | 2008-02-21 17:27:41 +0100 | [diff] [blame] | 286 | } |
| 287 | |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 288 | /** |
Bartlomiej Sieka | edbed24 | 2008-04-18 12:39:23 +0200 | [diff] [blame] | 289 | * image_print_contents - prints out the contents of the legacy format image |
Wolfgang Denk | 3a2003f | 2009-08-19 11:42:56 +0200 | [diff] [blame] | 290 | * @ptr: pointer to the legacy format image header |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 291 | * @p: pointer to prefix string |
| 292 | * |
Bartlomiej Sieka | edbed24 | 2008-04-18 12:39:23 +0200 | [diff] [blame] | 293 | * image_print_contents() formats a multi line legacy image contents description. |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 294 | * The routine prints out all header fields followed by the size/offset data |
| 295 | * for MULTI/SCRIPT images. |
| 296 | * |
| 297 | * returns: |
| 298 | * no returned results |
| 299 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 300 | void image_print_contents(const void *ptr) |
Marian Balakowicz | 2242f53 | 2008-02-21 17:27:41 +0100 | [diff] [blame] | 301 | { |
Wolfgang Denk | 3a2003f | 2009-08-19 11:42:56 +0200 | [diff] [blame] | 302 | const image_header_t *hdr = (const image_header_t *)ptr; |
Bartlomiej Sieka | edbed24 | 2008-04-18 12:39:23 +0200 | [diff] [blame] | 303 | const char *p; |
| 304 | |
| 305 | #ifdef USE_HOSTCC |
| 306 | p = ""; |
| 307 | #else |
| 308 | p = " "; |
| 309 | #endif |
| 310 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 311 | printf("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name(hdr)); |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 312 | #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 313 | printf("%sCreated: ", p); |
| 314 | genimg_print_time((time_t)image_get_time(hdr)); |
Marian Balakowicz | 2242f53 | 2008-02-21 17:27:41 +0100 | [diff] [blame] | 315 | #endif |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 316 | printf("%sImage Type: ", p); |
| 317 | image_print_type(hdr); |
| 318 | printf("%sData Size: ", p); |
| 319 | genimg_print_size(image_get_data_size(hdr)); |
| 320 | printf("%sLoad Address: %08x\n", p, image_get_load(hdr)); |
| 321 | printf("%sEntry Point: %08x\n", p, image_get_ep(hdr)); |
Marian Balakowicz | 2242f53 | 2008-02-21 17:27:41 +0100 | [diff] [blame] | 322 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 323 | if (image_check_type(hdr, IH_TYPE_MULTI) || |
| 324 | image_check_type(hdr, IH_TYPE_SCRIPT)) { |
Marian Balakowicz | 2242f53 | 2008-02-21 17:27:41 +0100 | [diff] [blame] | 325 | int i; |
| 326 | ulong data, len; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 327 | ulong count = image_multi_count(hdr); |
Marian Balakowicz | 2242f53 | 2008-02-21 17:27:41 +0100 | [diff] [blame] | 328 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 329 | printf("%sContents:\n", p); |
Marian Balakowicz | 2242f53 | 2008-02-21 17:27:41 +0100 | [diff] [blame] | 330 | for (i = 0; i < count; i++) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 331 | image_multi_getimg(hdr, i, &data, &len); |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 332 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 333 | printf("%s Image %d: ", p, i); |
| 334 | genimg_print_size(len); |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 335 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 336 | if (image_check_type(hdr, IH_TYPE_SCRIPT) && i > 0) { |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 337 | /* |
| 338 | * the user may need to know offsets |
| 339 | * if planning to do something with |
| 340 | * multiple files |
| 341 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 342 | printf("%s Offset = 0x%08lx\n", p, data); |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 343 | } |
Marian Balakowicz | 2242f53 | 2008-02-21 17:27:41 +0100 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | } |
| 347 | |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 348 | |
| 349 | #ifndef USE_HOSTCC |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 350 | /** |
| 351 | * image_get_ramdisk - get and verify ramdisk image |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 352 | * @rd_addr: ramdisk image start address |
| 353 | * @arch: expected ramdisk architecture |
| 354 | * @verify: checksum verification flag |
| 355 | * |
| 356 | * image_get_ramdisk() returns a pointer to the verified ramdisk image |
| 357 | * header. Routine receives image start address and expected architecture |
| 358 | * flag. Verification done covers data and header integrity and os/type/arch |
| 359 | * fields checking. |
| 360 | * |
| 361 | * If dataflash support is enabled routine checks for dataflash addresses |
| 362 | * and handles required dataflash reads. |
| 363 | * |
| 364 | * returns: |
| 365 | * pointer to a ramdisk image header, if image was found and valid |
Kumar Gala | 274cea2 | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 366 | * otherwise, return NULL |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 367 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 368 | static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch, |
Marian Balakowicz | d985c84 | 2008-03-12 10:14:38 +0100 | [diff] [blame] | 369 | int verify) |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 370 | { |
Wolfgang Denk | 3a2003f | 2009-08-19 11:42:56 +0200 | [diff] [blame] | 371 | const image_header_t *rd_hdr = (const image_header_t *)rd_addr; |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 372 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 373 | if (!image_check_magic(rd_hdr)) { |
| 374 | puts("Bad Magic Number\n"); |
| 375 | show_boot_progress(-10); |
Kumar Gala | 274cea2 | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 376 | return NULL; |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 377 | } |
| 378 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 379 | if (!image_check_hcrc(rd_hdr)) { |
| 380 | puts("Bad Header Checksum\n"); |
| 381 | show_boot_progress(-11); |
Kumar Gala | 274cea2 | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 382 | return NULL; |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 383 | } |
| 384 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 385 | show_boot_progress(10); |
| 386 | image_print_contents(rd_hdr); |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 387 | |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 388 | if (verify) { |
| 389 | puts(" Verifying Checksum ... "); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 390 | if (!image_check_dcrc(rd_hdr)) { |
| 391 | puts("Bad Data CRC\n"); |
| 392 | show_boot_progress(-12); |
Kumar Gala | 274cea2 | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 393 | return NULL; |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 394 | } |
| 395 | puts("OK\n"); |
| 396 | } |
| 397 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 398 | show_boot_progress(11); |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 399 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 400 | if (!image_check_os(rd_hdr, IH_OS_LINUX) || |
| 401 | !image_check_arch(rd_hdr, arch) || |
| 402 | !image_check_type(rd_hdr, IH_TYPE_RAMDISK)) { |
| 403 | printf("No Linux %s Ramdisk Image\n", |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 404 | genimg_get_arch_name(arch)); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 405 | show_boot_progress(-13); |
Kumar Gala | 274cea2 | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 406 | return NULL; |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | return rd_hdr; |
| 410 | } |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 411 | #endif /* !USE_HOSTCC */ |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 412 | |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 413 | /*****************************************************************************/ |
| 414 | /* Shared dual-format routines */ |
| 415 | /*****************************************************************************/ |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 416 | #ifndef USE_HOSTCC |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 417 | int getenv_yesno(char *var) |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 418 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 419 | char *s = getenv(var); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 420 | return (s && (*s == 'n')) ? 0 : 1; |
| 421 | } |
| 422 | |
| 423 | ulong getenv_bootm_low(void) |
| 424 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 425 | char *s = getenv("bootm_low"); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 426 | if (s) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 427 | ulong tmp = simple_strtoul(s, NULL, 16); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 428 | return tmp; |
| 429 | } |
| 430 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 431 | #if defined(CONFIG_SYS_SDRAM_BASE) |
| 432 | return CONFIG_SYS_SDRAM_BASE; |
Marian Balakowicz | afe45c8 | 2008-03-12 12:14:15 +0100 | [diff] [blame] | 433 | #elif defined(CONFIG_ARM) |
| 434 | return gd->bd->bi_dram[0].start; |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 435 | #else |
| 436 | return 0; |
| 437 | #endif |
| 438 | } |
| 439 | |
Becky Bruce | 391fd93 | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 440 | phys_size_t getenv_bootm_size(void) |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 441 | { |
Matthew McClintock | c519fac | 2010-07-08 10:11:08 -0500 | [diff] [blame] | 442 | phys_size_t tmp; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 443 | char *s = getenv("bootm_size"); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 444 | if (s) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 445 | tmp = (phys_size_t)simple_strtoull(s, NULL, 16); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 446 | return tmp; |
| 447 | } |
Matthew McClintock | c519fac | 2010-07-08 10:11:08 -0500 | [diff] [blame] | 448 | s = getenv("bootm_low"); |
| 449 | if (s) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 450 | tmp = (phys_size_t)simple_strtoull(s, NULL, 16); |
Matthew McClintock | c519fac | 2010-07-08 10:11:08 -0500 | [diff] [blame] | 451 | else |
| 452 | tmp = 0; |
| 453 | |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 454 | |
Marian Balakowicz | afe45c8 | 2008-03-12 12:14:15 +0100 | [diff] [blame] | 455 | #if defined(CONFIG_ARM) |
Matthew McClintock | c519fac | 2010-07-08 10:11:08 -0500 | [diff] [blame] | 456 | return gd->bd->bi_dram[0].size - tmp; |
Marian Balakowicz | afe45c8 | 2008-03-12 12:14:15 +0100 | [diff] [blame] | 457 | #else |
Matthew McClintock | c519fac | 2010-07-08 10:11:08 -0500 | [diff] [blame] | 458 | return gd->bd->bi_memsize - tmp; |
Marian Balakowicz | afe45c8 | 2008-03-12 12:14:15 +0100 | [diff] [blame] | 459 | #endif |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 460 | } |
| 461 | |
Grant Likely | c3624e6 | 2011-03-28 09:58:43 +0000 | [diff] [blame] | 462 | phys_size_t getenv_bootm_mapsize(void) |
| 463 | { |
| 464 | phys_size_t tmp; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 465 | char *s = getenv("bootm_mapsize"); |
Grant Likely | c3624e6 | 2011-03-28 09:58:43 +0000 | [diff] [blame] | 466 | if (s) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 467 | tmp = (phys_size_t)simple_strtoull(s, NULL, 16); |
Grant Likely | c3624e6 | 2011-03-28 09:58:43 +0000 | [diff] [blame] | 468 | return tmp; |
| 469 | } |
| 470 | |
| 471 | #if defined(CONFIG_SYS_BOOTMAPSZ) |
| 472 | return CONFIG_SYS_BOOTMAPSZ; |
| 473 | #else |
| 474 | return getenv_bootm_size(); |
| 475 | #endif |
| 476 | } |
| 477 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 478 | void memmove_wd(void *to, void *from, size_t len, ulong chunksz) |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 479 | { |
Larry Johnson | 54fa2c5 | 2010-04-20 08:09:43 -0400 | [diff] [blame] | 480 | if (to == from) |
| 481 | return; |
| 482 | |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 483 | #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) |
| 484 | while (len > 0) { |
| 485 | size_t tail = (len > chunksz) ? chunksz : len; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 486 | WATCHDOG_RESET(); |
| 487 | memmove(to, from, tail); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 488 | to += tail; |
| 489 | from += tail; |
| 490 | len -= tail; |
| 491 | } |
| 492 | #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 493 | memmove(to, from, len); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 494 | #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */ |
| 495 | } |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 496 | #endif /* !USE_HOSTCC */ |
| 497 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 498 | void genimg_print_size(uint32_t size) |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 499 | { |
| 500 | #ifndef USE_HOSTCC |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 501 | printf("%d Bytes = ", size); |
| 502 | print_size(size, "\n"); |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 503 | #else |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 504 | printf("%d Bytes = %.2f kB = %.2f MB\n", |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 505 | size, (double)size / 1.024e3, |
| 506 | (double)size / 1.048576e6); |
| 507 | #endif |
| 508 | } |
| 509 | |
| 510 | #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 511 | static void genimg_print_time(time_t timestamp) |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 512 | { |
| 513 | #ifndef USE_HOSTCC |
| 514 | struct rtc_time tm; |
| 515 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 516 | to_tm(timestamp, &tm); |
| 517 | printf("%4d-%02d-%02d %2d:%02d:%02d UTC\n", |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 518 | tm.tm_year, tm.tm_mon, tm.tm_mday, |
| 519 | tm.tm_hour, tm.tm_min, tm.tm_sec); |
| 520 | #else |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 521 | printf("%s", ctime(×tamp)); |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 522 | #endif |
| 523 | } |
| 524 | #endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */ |
| 525 | |
| 526 | /** |
| 527 | * get_table_entry_name - translate entry id to long name |
| 528 | * @table: pointer to a translation table for entries of a specific type |
| 529 | * @msg: message to be returned when translation fails |
| 530 | * @id: entry id to be translated |
| 531 | * |
| 532 | * get_table_entry_name() will go over translation table trying to find |
| 533 | * entry that matches given id. If matching entry is found, its long |
| 534 | * name is returned to the caller. |
| 535 | * |
| 536 | * returns: |
| 537 | * long entry name if translation succeeds |
| 538 | * msg otherwise |
| 539 | */ |
Mike Frysinger | 7edb186 | 2010-10-20 07:17:39 -0400 | [diff] [blame] | 540 | char *get_table_entry_name(const table_entry_t *table, char *msg, int id) |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 541 | { |
| 542 | for (; table->id >= 0; ++table) { |
| 543 | if (table->id == id) |
Wolfgang Denk | 2e5167c | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 544 | #if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC) |
Scott Wood | e3d1ac7 | 2009-04-02 16:15:10 -0500 | [diff] [blame] | 545 | return table->lname; |
| 546 | #else |
| 547 | return table->lname + gd->reloc_off; |
| 548 | #endif |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 549 | } |
| 550 | return (msg); |
| 551 | } |
| 552 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 553 | const char *genimg_get_os_name(uint8_t os) |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 554 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 555 | return (get_table_entry_name(uimage_os, "Unknown OS", os)); |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 556 | } |
| 557 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 558 | const char *genimg_get_arch_name(uint8_t arch) |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 559 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 560 | return (get_table_entry_name(uimage_arch, "Unknown Architecture", |
| 561 | arch)); |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 562 | } |
| 563 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 564 | const char *genimg_get_type_name(uint8_t type) |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 565 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 566 | return (get_table_entry_name(uimage_type, "Unknown Image", type)); |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 567 | } |
| 568 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 569 | const char *genimg_get_comp_name(uint8_t comp) |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 570 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 571 | return (get_table_entry_name(uimage_comp, "Unknown Compression", |
| 572 | comp)); |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | /** |
| 576 | * get_table_entry_id - translate short entry name to id |
| 577 | * @table: pointer to a translation table for entries of a specific type |
| 578 | * @table_name: to be used in case of error |
| 579 | * @name: entry short name to be translated |
| 580 | * |
| 581 | * get_table_entry_id() will go over translation table trying to find |
| 582 | * entry that matches given short name. If matching entry is found, |
| 583 | * its id returned to the caller. |
| 584 | * |
| 585 | * returns: |
| 586 | * entry id if translation succeeds |
| 587 | * -1 otherwise |
| 588 | */ |
Mike Frysinger | 7edb186 | 2010-10-20 07:17:39 -0400 | [diff] [blame] | 589 | int get_table_entry_id(const table_entry_t *table, |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 590 | const char *table_name, const char *name) |
| 591 | { |
Mike Frysinger | 7edb186 | 2010-10-20 07:17:39 -0400 | [diff] [blame] | 592 | const table_entry_t *t; |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 593 | #ifdef USE_HOSTCC |
| 594 | int first = 1; |
| 595 | |
| 596 | for (t = table; t->id >= 0; ++t) { |
| 597 | if (t->sname && strcasecmp(t->sname, name) == 0) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 598 | return(t->id); |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 599 | } |
| 600 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 601 | fprintf(stderr, "\nInvalid %s Type - valid names are", table_name); |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 602 | for (t = table; t->id >= 0; ++t) { |
| 603 | if (t->sname == NULL) |
| 604 | continue; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 605 | fprintf(stderr, "%c %s", (first) ? ':' : ',', t->sname); |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 606 | first = 0; |
| 607 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 608 | fprintf(stderr, "\n"); |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 609 | #else |
| 610 | for (t = table; t->id >= 0; ++t) { |
Wolfgang Denk | 2e5167c | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 611 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
Scott Wood | e3d1ac7 | 2009-04-02 16:15:10 -0500 | [diff] [blame] | 612 | if (t->sname && strcmp(t->sname + gd->reloc_off, name) == 0) |
Wolfgang Denk | 2e5167c | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 613 | #else |
| 614 | if (t->sname && strcmp(t->sname, name) == 0) |
Peter Tyser | 521af04 | 2009-09-21 11:20:36 -0500 | [diff] [blame] | 615 | #endif |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 616 | return (t->id); |
| 617 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 618 | debug("Invalid %s Type: %s\n", table_name, name); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 619 | #endif /* USE_HOSTCC */ |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 620 | return (-1); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 621 | } |
| 622 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 623 | int genimg_get_os_id(const char *name) |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 624 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 625 | return (get_table_entry_id(uimage_os, "OS", name)); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 626 | } |
| 627 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 628 | int genimg_get_arch_id(const char *name) |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 629 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 630 | return (get_table_entry_id(uimage_arch, "CPU", name)); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 631 | } |
| 632 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 633 | int genimg_get_type_id(const char *name) |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 634 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 635 | return (get_table_entry_id(uimage_type, "Image", name)); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 636 | } |
| 637 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 638 | int genimg_get_comp_id(const char *name) |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 639 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 640 | return (get_table_entry_id(uimage_comp, "Compression", name)); |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | #ifndef USE_HOSTCC |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 644 | /** |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 645 | * genimg_get_format - get image format type |
| 646 | * @img_addr: image start address |
| 647 | * |
| 648 | * genimg_get_format() checks whether provided address points to a valid |
| 649 | * legacy or FIT image. |
| 650 | * |
| 651 | * New uImage format and FDT blob are based on a libfdt. FDT blob |
| 652 | * may be passed directly or embedded in a FIT image. In both situations |
| 653 | * genimg_get_format() must be able to dectect libfdt header. |
| 654 | * |
| 655 | * returns: |
| 656 | * image format type or IMAGE_FORMAT_INVALID if no image is present |
| 657 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 658 | int genimg_get_format(void *img_addr) |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 659 | { |
Wolfgang Denk | 3a2003f | 2009-08-19 11:42:56 +0200 | [diff] [blame] | 660 | ulong format = IMAGE_FORMAT_INVALID; |
| 661 | const image_header_t *hdr; |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 662 | #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT) |
Wolfgang Denk | 3a2003f | 2009-08-19 11:42:56 +0200 | [diff] [blame] | 663 | char *fit_hdr; |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 664 | #endif |
| 665 | |
Wolfgang Denk | 3a2003f | 2009-08-19 11:42:56 +0200 | [diff] [blame] | 666 | hdr = (const image_header_t *)img_addr; |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 667 | if (image_check_magic(hdr)) |
| 668 | format = IMAGE_FORMAT_LEGACY; |
| 669 | #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT) |
| 670 | else { |
| 671 | fit_hdr = (char *)img_addr; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 672 | if (fdt_check_header(fit_hdr) == 0) |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 673 | format = IMAGE_FORMAT_FIT; |
| 674 | } |
| 675 | #endif |
| 676 | |
| 677 | return format; |
| 678 | } |
| 679 | |
| 680 | /** |
| 681 | * genimg_get_image - get image from special storage (if necessary) |
| 682 | * @img_addr: image start address |
| 683 | * |
| 684 | * genimg_get_image() checks if provided image start adddress is located |
| 685 | * in a dataflash storage. If so, image is moved to a system RAM memory. |
| 686 | * |
| 687 | * returns: |
| 688 | * image start address after possible relocation from special storage |
| 689 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 690 | ulong genimg_get_image(ulong img_addr) |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 691 | { |
| 692 | ulong ram_addr = img_addr; |
| 693 | |
| 694 | #ifdef CONFIG_HAS_DATAFLASH |
| 695 | ulong h_size, d_size; |
| 696 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 697 | if (addr_dataflash(img_addr)) { |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 698 | /* ger RAM address */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 699 | ram_addr = CONFIG_SYS_LOAD_ADDR; |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 700 | |
| 701 | /* get header size */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 702 | h_size = image_get_header_size(); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 703 | #if defined(CONFIG_FIT) |
| 704 | if (sizeof(struct fdt_header) > h_size) |
| 705 | h_size = sizeof(struct fdt_header); |
| 706 | #endif |
| 707 | |
| 708 | /* read in header */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 709 | debug(" Reading image header from dataflash address " |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 710 | "%08lx to RAM address %08lx\n", img_addr, ram_addr); |
| 711 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 712 | read_dataflash(img_addr, h_size, (char *)ram_addr); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 713 | |
| 714 | /* get data size */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 715 | switch (genimg_get_format((void *)ram_addr)) { |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 716 | case IMAGE_FORMAT_LEGACY: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 717 | d_size = image_get_data_size( |
| 718 | (const image_header_t *)ram_addr); |
| 719 | debug(" Legacy format image found at 0x%08lx, " |
| 720 | "size 0x%08lx\n", |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 721 | ram_addr, d_size); |
| 722 | break; |
| 723 | #if defined(CONFIG_FIT) |
| 724 | case IMAGE_FORMAT_FIT: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 725 | d_size = fit_get_size((const void *)ram_addr) - h_size; |
| 726 | debug(" FIT/FDT format image found at 0x%08lx, " |
| 727 | "size 0x%08lx\n", |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 728 | ram_addr, d_size); |
| 729 | break; |
| 730 | #endif |
| 731 | default: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 732 | printf(" No valid image found at 0x%08lx\n", |
| 733 | img_addr); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 734 | return ram_addr; |
| 735 | } |
| 736 | |
| 737 | /* read in image data */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 738 | debug(" Reading image remaining data from dataflash address " |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 739 | "%08lx to RAM address %08lx\n", img_addr + h_size, |
| 740 | ram_addr + h_size); |
| 741 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 742 | read_dataflash(img_addr + h_size, d_size, |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 743 | (char *)(ram_addr + h_size)); |
| 744 | |
| 745 | } |
| 746 | #endif /* CONFIG_HAS_DATAFLASH */ |
| 747 | |
| 748 | return ram_addr; |
| 749 | } |
| 750 | |
| 751 | /** |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 752 | * fit_has_config - check if there is a valid FIT configuration |
| 753 | * @images: pointer to the bootm command headers structure |
| 754 | * |
| 755 | * fit_has_config() checks if there is a FIT configuration in use |
| 756 | * (if FTI support is present). |
| 757 | * |
| 758 | * returns: |
| 759 | * 0, no FIT support or no configuration found |
| 760 | * 1, configuration found |
| 761 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 762 | int genimg_has_config(bootm_headers_t *images) |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 763 | { |
| 764 | #if defined(CONFIG_FIT) |
| 765 | if (images->fit_uname_cfg) |
| 766 | return 1; |
| 767 | #endif |
| 768 | return 0; |
| 769 | } |
| 770 | |
| 771 | /** |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 772 | * boot_get_ramdisk - main ramdisk handling routine |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 773 | * @argc: command argument count |
| 774 | * @argv: command argument list |
Marian Balakowicz | 8a5ea3e | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 775 | * @images: pointer to the bootm images structure |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 776 | * @arch: expected ramdisk architecture |
| 777 | * @rd_start: pointer to a ulong variable, will hold ramdisk start address |
| 778 | * @rd_end: pointer to a ulong variable, will hold ramdisk end |
| 779 | * |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 780 | * boot_get_ramdisk() is responsible for finding a valid ramdisk image. |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 781 | * Curently supported are the following ramdisk sources: |
| 782 | * - multicomponent kernel/ramdisk image, |
| 783 | * - commandline provided address of decicated ramdisk image. |
| 784 | * |
| 785 | * returns: |
Marian Balakowicz | d985c84 | 2008-03-12 10:14:38 +0100 | [diff] [blame] | 786 | * 0, if ramdisk image was found and valid, or skiped |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 787 | * rd_start and rd_end are set to ramdisk start/end addresses if |
| 788 | * ramdisk image is found and valid |
Marian Balakowicz | d985c84 | 2008-03-12 10:14:38 +0100 | [diff] [blame] | 789 | * |
Kumar Gala | ea86b9e | 2008-08-29 19:08:29 -0500 | [diff] [blame] | 790 | * 1, if ramdisk image is found but corrupted, or invalid |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 791 | * rd_start and rd_end are set to 0 if no ramdisk exists |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 792 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 793 | int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images, |
Marian Balakowicz | d985c84 | 2008-03-12 10:14:38 +0100 | [diff] [blame] | 794 | uint8_t arch, ulong *rd_start, ulong *rd_end) |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 795 | { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 796 | ulong rd_addr, rd_load; |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 797 | ulong rd_data, rd_len; |
Wolfgang Denk | 3a2003f | 2009-08-19 11:42:56 +0200 | [diff] [blame] | 798 | const image_header_t *rd_hdr; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 799 | #if defined(CONFIG_FIT) |
| 800 | void *fit_hdr; |
| 801 | const char *fit_uname_config = NULL; |
| 802 | const char *fit_uname_ramdisk = NULL; |
| 803 | ulong default_addr; |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 804 | int rd_noffset; |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 805 | int cfg_noffset; |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 806 | const void *data; |
| 807 | size_t size; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 808 | #endif |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 809 | |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 810 | *rd_start = 0; |
| 811 | *rd_end = 0; |
| 812 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 813 | /* |
| 814 | * Look for a '-' which indicates to ignore the |
| 815 | * ramdisk argument |
| 816 | */ |
| 817 | if ((argc >= 3) && (strcmp(argv[2], "-") == 0)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 818 | debug("## Skipping init Ramdisk\n"); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 819 | rd_len = rd_data = 0; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 820 | } else if (argc >= 3 || genimg_has_config(images)) { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 821 | #if defined(CONFIG_FIT) |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 822 | if (argc >= 3) { |
| 823 | /* |
| 824 | * If the init ramdisk comes from the FIT image and |
| 825 | * the FIT image address is omitted in the command |
| 826 | * line argument, try to use os FIT image address or |
| 827 | * default load address. |
| 828 | */ |
| 829 | if (images->fit_uname_os) |
| 830 | default_addr = (ulong)images->fit_hdr_os; |
| 831 | else |
| 832 | default_addr = load_addr; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 833 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 834 | if (fit_parse_conf(argv[2], default_addr, |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 835 | &rd_addr, &fit_uname_config)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 836 | debug("* ramdisk: config '%s' from image at " |
| 837 | "0x%08lx\n", |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 838 | fit_uname_config, rd_addr); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 839 | } else if (fit_parse_subimage(argv[2], default_addr, |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 840 | &rd_addr, &fit_uname_ramdisk)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 841 | debug("* ramdisk: subimage '%s' from image at " |
| 842 | "0x%08lx\n", |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 843 | fit_uname_ramdisk, rd_addr); |
| 844 | } else |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 845 | #endif |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 846 | { |
| 847 | rd_addr = simple_strtoul(argv[2], NULL, 16); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 848 | debug("* ramdisk: cmdline image address = " |
| 849 | "0x%08lx\n", |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 850 | rd_addr); |
| 851 | } |
| 852 | #if defined(CONFIG_FIT) |
| 853 | } else { |
| 854 | /* use FIT configuration provided in first bootm |
| 855 | * command argument |
| 856 | */ |
| 857 | rd_addr = (ulong)images->fit_hdr_os; |
| 858 | fit_uname_config = images->fit_uname_cfg; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 859 | debug("* ramdisk: using config '%s' from image " |
| 860 | "at 0x%08lx\n", |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 861 | fit_uname_config, rd_addr); |
| 862 | |
| 863 | /* |
| 864 | * Check whether configuration has ramdisk defined, |
| 865 | * if not, don't try to use it, quit silently. |
| 866 | */ |
| 867 | fit_hdr = (void *)rd_addr; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 868 | cfg_noffset = fit_conf_get_node(fit_hdr, |
| 869 | fit_uname_config); |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 870 | if (cfg_noffset < 0) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 871 | debug("* ramdisk: no such config\n"); |
Michal Simek | c78fce6 | 2008-07-11 10:43:13 +0200 | [diff] [blame] | 872 | return 1; |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 873 | } |
| 874 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 875 | rd_noffset = fit_conf_get_ramdisk_node(fit_hdr, |
| 876 | cfg_noffset); |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 877 | if (rd_noffset < 0) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 878 | debug("* ramdisk: no ramdisk in config\n"); |
Peter Tyser | 41266c9 | 2008-08-05 10:51:57 -0500 | [diff] [blame] | 879 | return 0; |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 880 | } |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 881 | } |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 882 | #endif |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 883 | |
| 884 | /* copy from dataflash if needed */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 885 | rd_addr = genimg_get_image(rd_addr); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 886 | |
| 887 | /* |
| 888 | * Check if there is an initrd image at the |
| 889 | * address provided in the second bootm argument |
| 890 | * check image type, for FIT images get FIT node. |
| 891 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 892 | switch (genimg_get_format((void *)rd_addr)) { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 893 | case IMAGE_FORMAT_LEGACY: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 894 | printf("## Loading init Ramdisk from Legacy " |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 895 | "Image at %08lx ...\n", rd_addr); |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 896 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 897 | show_boot_progress(9); |
| 898 | rd_hdr = image_get_ramdisk(rd_addr, arch, |
Marian Balakowicz | d985c84 | 2008-03-12 10:14:38 +0100 | [diff] [blame] | 899 | images->verify); |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 900 | |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 901 | if (rd_hdr == NULL) |
Kumar Gala | 274cea2 | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 902 | return 1; |
Kumar Gala | 274cea2 | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 903 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 904 | rd_data = image_get_data(rd_hdr); |
| 905 | rd_len = image_get_data_size(rd_hdr); |
| 906 | rd_load = image_get_load(rd_hdr); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 907 | break; |
| 908 | #if defined(CONFIG_FIT) |
| 909 | case IMAGE_FORMAT_FIT: |
| 910 | fit_hdr = (void *)rd_addr; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 911 | printf("## Loading init Ramdisk from FIT " |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 912 | "Image at %08lx ...\n", rd_addr); |
| 913 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 914 | show_boot_progress(120); |
| 915 | if (!fit_check_format(fit_hdr)) { |
| 916 | puts("Bad FIT ramdisk image format!\n"); |
| 917 | show_boot_progress(-120); |
Michal Simek | c78fce6 | 2008-07-11 10:43:13 +0200 | [diff] [blame] | 918 | return 1; |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 919 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 920 | show_boot_progress(121); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 921 | |
| 922 | if (!fit_uname_ramdisk) { |
| 923 | /* |
| 924 | * no ramdisk image node unit name, try to get config |
| 925 | * node first. If config unit node name is NULL |
| 926 | * fit_conf_get_node() will try to find default config node |
| 927 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 928 | show_boot_progress(122); |
| 929 | cfg_noffset = fit_conf_get_node(fit_hdr, |
| 930 | fit_uname_config); |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 931 | if (cfg_noffset < 0) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 932 | puts("Could not find configuration " |
| 933 | "node\n"); |
| 934 | show_boot_progress(-122); |
Michal Simek | c78fce6 | 2008-07-11 10:43:13 +0200 | [diff] [blame] | 935 | return 1; |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 936 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 937 | fit_uname_config = fdt_get_name(fit_hdr, |
| 938 | cfg_noffset, NULL); |
| 939 | printf(" Using '%s' configuration\n", |
| 940 | fit_uname_config); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 941 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 942 | rd_noffset = fit_conf_get_ramdisk_node(fit_hdr, |
| 943 | cfg_noffset); |
| 944 | fit_uname_ramdisk = fit_get_name(fit_hdr, |
| 945 | rd_noffset, NULL); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 946 | } else { |
| 947 | /* get ramdisk component image node offset */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 948 | show_boot_progress(123); |
| 949 | rd_noffset = fit_image_get_node(fit_hdr, |
| 950 | fit_uname_ramdisk); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 951 | } |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 952 | if (rd_noffset < 0) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 953 | puts("Could not find subimage node\n"); |
| 954 | show_boot_progress(-124); |
Michal Simek | c78fce6 | 2008-07-11 10:43:13 +0200 | [diff] [blame] | 955 | return 1; |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 956 | } |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 957 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 958 | printf(" Trying '%s' ramdisk subimage\n", |
| 959 | fit_uname_ramdisk); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 960 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 961 | show_boot_progress(125); |
| 962 | if (!fit_check_ramdisk(fit_hdr, rd_noffset, arch, |
| 963 | images->verify)) |
Michal Simek | c78fce6 | 2008-07-11 10:43:13 +0200 | [diff] [blame] | 964 | return 1; |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 965 | |
| 966 | /* get ramdisk image data address and length */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 967 | if (fit_image_get_data(fit_hdr, rd_noffset, &data, |
| 968 | &size)) { |
| 969 | puts("Could not find ramdisk subimage data!\n"); |
| 970 | show_boot_progress(-127); |
Michal Simek | c78fce6 | 2008-07-11 10:43:13 +0200 | [diff] [blame] | 971 | return 1; |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 972 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 973 | show_boot_progress(128); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 974 | |
| 975 | rd_data = (ulong)data; |
| 976 | rd_len = size; |
| 977 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 978 | if (fit_image_get_load(fit_hdr, rd_noffset, &rd_load)) { |
| 979 | puts("Can't get ramdisk subimage load " |
| 980 | "address!\n"); |
| 981 | show_boot_progress(-129); |
Michal Simek | c78fce6 | 2008-07-11 10:43:13 +0200 | [diff] [blame] | 982 | return 1; |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 983 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 984 | show_boot_progress(129); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 985 | |
| 986 | images->fit_hdr_rd = fit_hdr; |
| 987 | images->fit_uname_rd = fit_uname_ramdisk; |
Marian Balakowicz | 3dfe110 | 2008-03-12 10:32:59 +0100 | [diff] [blame] | 988 | images->fit_noffset_rd = rd_noffset; |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 989 | break; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 990 | #endif |
| 991 | default: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 992 | puts("Wrong Ramdisk Image Format\n"); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 993 | rd_data = rd_len = rd_load = 0; |
Kumar Gala | ea86b9e | 2008-08-29 19:08:29 -0500 | [diff] [blame] | 994 | return 1; |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 995 | } |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 996 | } else if (images->legacy_hdr_valid && |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 997 | image_check_type(&images->legacy_hdr_os_copy, |
| 998 | IH_TYPE_MULTI)) { |
| 999 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1000 | /* |
| 1001 | * Now check if we have a legacy mult-component image, |
| 1002 | * get second entry data start address and len. |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 1003 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1004 | show_boot_progress(13); |
| 1005 | printf("## Loading init Ramdisk from multi component " |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 1006 | "Legacy Image at %08lx ...\n", |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1007 | (ulong)images->legacy_hdr_os); |
| 1008 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1009 | image_multi_getimg(images->legacy_hdr_os, 1, &rd_data, &rd_len); |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 1010 | } else { |
| 1011 | /* |
| 1012 | * no initrd image |
| 1013 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1014 | show_boot_progress(14); |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 1015 | rd_len = rd_data = 0; |
| 1016 | } |
| 1017 | |
| 1018 | if (!rd_data) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1019 | debug("## No init Ramdisk\n"); |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 1020 | } else { |
| 1021 | *rd_start = rd_data; |
| 1022 | *rd_end = rd_data + rd_len; |
| 1023 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1024 | debug(" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n", |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 1025 | *rd_start, *rd_end); |
Kumar Gala | 274cea2 | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 1026 | |
| 1027 | return 0; |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 1028 | } |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1029 | |
John Rigby | fca43cc | 2010-10-13 13:57:35 -0600 | [diff] [blame] | 1030 | #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1031 | /** |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1032 | * boot_ramdisk_high - relocate init ramdisk |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1033 | * @lmb: pointer to lmb handle, will be used for memory mgmt |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1034 | * @rd_data: ramdisk data start address |
| 1035 | * @rd_len: ramdisk data length |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1036 | * @initrd_start: pointer to a ulong variable, will hold final init ramdisk |
| 1037 | * start address (after possible relocation) |
| 1038 | * @initrd_end: pointer to a ulong variable, will hold final init ramdisk |
| 1039 | * end address (after possible relocation) |
| 1040 | * |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1041 | * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1042 | * variable and if requested ramdisk data is moved to a specified location. |
| 1043 | * |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1044 | * Initrd_start and initrd_end are set to final (after relocation) ramdisk |
| 1045 | * start/end addresses if ramdisk image start and len were provided, |
| 1046 | * otherwise set initrd_start and initrd_end set to zeros. |
| 1047 | * |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1048 | * returns: |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1049 | * 0 - success |
| 1050 | * -1 - failure |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1051 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1052 | int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len, |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1053 | ulong *initrd_start, ulong *initrd_end) |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1054 | { |
| 1055 | char *s; |
| 1056 | ulong initrd_high; |
| 1057 | int initrd_copy_to_ram = 1; |
| 1058 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1059 | if ((s = getenv("initrd_high")) != NULL) { |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1060 | /* a value of "no" or a similar string will act like 0, |
| 1061 | * turning the "load high" feature off. This is intentional. |
| 1062 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1063 | initrd_high = simple_strtoul(s, NULL, 16); |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1064 | if (initrd_high == ~0) |
| 1065 | initrd_copy_to_ram = 0; |
| 1066 | } else { |
| 1067 | /* not set, no restrictions to load high */ |
| 1068 | initrd_high = ~0; |
| 1069 | } |
| 1070 | |
Marian Balakowicz | 95d449a | 2008-05-13 15:53:29 +0200 | [diff] [blame] | 1071 | |
| 1072 | #ifdef CONFIG_LOGBUFFER |
| 1073 | /* Prevent initrd from overwriting logbuffer */ |
| 1074 | lmb_reserve(lmb, logbuffer_base() - LOGBUFF_OVERHEAD, LOGBUFF_RESERVE); |
| 1075 | #endif |
| 1076 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1077 | debug("## initrd_high = 0x%08lx, copy_to_ram = %d\n", |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1078 | initrd_high, initrd_copy_to_ram); |
| 1079 | |
| 1080 | if (rd_data) { |
| 1081 | if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1082 | debug(" in-place initrd\n"); |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1083 | *initrd_start = rd_data; |
| 1084 | *initrd_end = rd_data + rd_len; |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1085 | lmb_reserve(lmb, rd_data, rd_len); |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1086 | } else { |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1087 | if (initrd_high) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1088 | *initrd_start = (ulong)lmb_alloc_base(lmb, |
| 1089 | rd_len, 0x1000, initrd_high); |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1090 | else |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1091 | *initrd_start = (ulong)lmb_alloc(lmb, rd_len, |
| 1092 | 0x1000); |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1093 | |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1094 | if (*initrd_start == 0) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1095 | puts("ramdisk - allocation error\n"); |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1096 | goto error; |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1097 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1098 | show_boot_progress(12); |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1099 | |
| 1100 | *initrd_end = *initrd_start + rd_len; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1101 | printf(" Loading Ramdisk to %08lx, end %08lx ... ", |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1102 | *initrd_start, *initrd_end); |
| 1103 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1104 | memmove_wd((void *)*initrd_start, |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1105 | (void *)rd_data, rd_len, CHUNKSZ); |
| 1106 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1107 | puts("OK\n"); |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1108 | } |
| 1109 | } else { |
| 1110 | *initrd_start = 0; |
| 1111 | *initrd_end = 0; |
| 1112 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1113 | debug(" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n", |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1114 | *initrd_start, *initrd_end); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1115 | |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1116 | return 0; |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1117 | |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1118 | error: |
| 1119 | return -1; |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1120 | } |
John Rigby | fca43cc | 2010-10-13 13:57:35 -0600 | [diff] [blame] | 1121 | #endif /* CONFIG_SYS_BOOT_RAMDISK_HIGH */ |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1122 | |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1123 | #ifdef CONFIG_OF_LIBFDT |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1124 | static void fdt_error(const char *msg) |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1125 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1126 | puts("ERROR: "); |
| 1127 | puts(msg); |
| 1128 | puts(" - must RESET the board to recover.\n"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1129 | } |
| 1130 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1131 | static const image_header_t *image_get_fdt(ulong fdt_addr) |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1132 | { |
Wolfgang Denk | 3a2003f | 2009-08-19 11:42:56 +0200 | [diff] [blame] | 1133 | const image_header_t *fdt_hdr = (const image_header_t *)fdt_addr; |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1134 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1135 | image_print_contents(fdt_hdr); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1136 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1137 | puts(" Verifying Checksum ... "); |
| 1138 | if (!image_check_hcrc(fdt_hdr)) { |
| 1139 | fdt_error("fdt header checksum invalid"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1140 | return NULL; |
| 1141 | } |
| 1142 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1143 | if (!image_check_dcrc(fdt_hdr)) { |
| 1144 | fdt_error("fdt checksum invalid"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1145 | return NULL; |
| 1146 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1147 | puts("OK\n"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1148 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1149 | if (!image_check_type(fdt_hdr, IH_TYPE_FLATDT)) { |
| 1150 | fdt_error("uImage is not a fdt"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1151 | return NULL; |
| 1152 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1153 | if (image_get_comp(fdt_hdr) != IH_COMP_NONE) { |
| 1154 | fdt_error("uImage is compressed"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1155 | return NULL; |
| 1156 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1157 | if (fdt_check_header((char *)image_get_data(fdt_hdr)) != 0) { |
| 1158 | fdt_error("uImage data is not a fdt"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1159 | return NULL; |
| 1160 | } |
| 1161 | return fdt_hdr; |
| 1162 | } |
| 1163 | |
| 1164 | /** |
| 1165 | * fit_check_fdt - verify FIT format FDT subimage |
| 1166 | * @fit_hdr: pointer to the FIT header |
| 1167 | * fdt_noffset: FDT subimage node offset within FIT image |
| 1168 | * @verify: data CRC verification flag |
| 1169 | * |
| 1170 | * fit_check_fdt() verifies integrity of the FDT subimage and from |
| 1171 | * specified FIT image. |
| 1172 | * |
| 1173 | * returns: |
| 1174 | * 1, on success |
| 1175 | * 0, on failure |
| 1176 | */ |
| 1177 | #if defined(CONFIG_FIT) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1178 | static int fit_check_fdt(const void *fit, int fdt_noffset, int verify) |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1179 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1180 | fit_image_print(fit, fdt_noffset, " "); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1181 | |
| 1182 | if (verify) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1183 | puts(" Verifying Hash Integrity ... "); |
| 1184 | if (!fit_image_check_hashes(fit, fdt_noffset)) { |
| 1185 | fdt_error("Bad Data Hash"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1186 | return 0; |
| 1187 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1188 | puts("OK\n"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1189 | } |
| 1190 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1191 | if (!fit_image_check_type(fit, fdt_noffset, IH_TYPE_FLATDT)) { |
| 1192 | fdt_error("Not a FDT image"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1193 | return 0; |
| 1194 | } |
| 1195 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1196 | if (!fit_image_check_comp(fit, fdt_noffset, IH_COMP_NONE)) { |
| 1197 | fdt_error("FDT image is compressed"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1198 | return 0; |
| 1199 | } |
| 1200 | |
| 1201 | return 1; |
| 1202 | } |
| 1203 | #endif /* CONFIG_FIT */ |
| 1204 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1205 | #ifndef CONFIG_SYS_FDT_PAD |
| 1206 | #define CONFIG_SYS_FDT_PAD 0x3000 |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1207 | #endif |
| 1208 | |
Grant Likely | 55b0a39 | 2011-03-28 09:59:01 +0000 | [diff] [blame] | 1209 | #if defined(CONFIG_OF_LIBFDT) |
| 1210 | /** |
| 1211 | * boot_fdt_add_mem_rsv_regions - Mark the memreserve sections as unusable |
| 1212 | * @lmb: pointer to lmb handle, will be used for memory mgmt |
| 1213 | * @fdt_blob: pointer to fdt blob base address |
| 1214 | * |
| 1215 | * Adds the memreserve regions in the dtb to the lmb block. Adding the |
| 1216 | * memreserve regions prevents u-boot from using them to store the initrd |
| 1217 | * or the fdt blob. |
| 1218 | */ |
| 1219 | void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob) |
| 1220 | { |
| 1221 | uint64_t addr, size; |
| 1222 | int i, total; |
| 1223 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1224 | if (fdt_check_header(fdt_blob) != 0) |
Grant Likely | 55b0a39 | 2011-03-28 09:59:01 +0000 | [diff] [blame] | 1225 | return; |
| 1226 | |
| 1227 | total = fdt_num_mem_rsv(fdt_blob); |
| 1228 | for (i = 0; i < total; i++) { |
| 1229 | if (fdt_get_mem_rsv(fdt_blob, i, &addr, &size) != 0) |
| 1230 | continue; |
| 1231 | printf(" reserving fdt memory region: addr=%llx size=%llx\n", |
| 1232 | (unsigned long long)addr, (unsigned long long)size); |
| 1233 | lmb_reserve(lmb, addr, size); |
| 1234 | } |
| 1235 | } |
| 1236 | |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1237 | /** |
| 1238 | * boot_relocate_fdt - relocate flat device tree |
| 1239 | * @lmb: pointer to lmb handle, will be used for memory mgmt |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1240 | * @of_flat_tree: pointer to a char* variable, will hold fdt start address |
| 1241 | * @of_size: pointer to a ulong variable, will hold fdt length |
| 1242 | * |
Timur Tabi | 43b08af | 2010-05-24 15:10:25 -0500 | [diff] [blame] | 1243 | * boot_relocate_fdt() allocates a region of memory within the bootmap and |
| 1244 | * relocates the of_flat_tree into that region, even if the fdt is already in |
| 1245 | * the bootmap. It also expands the size of the fdt by CONFIG_SYS_FDT_PAD |
| 1246 | * bytes. |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1247 | * |
| 1248 | * of_flat_tree and of_size are set to final (after relocation) values |
| 1249 | * |
| 1250 | * returns: |
| 1251 | * 0 - success |
| 1252 | * 1 - failure |
| 1253 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1254 | int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size) |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1255 | { |
Timur Tabi | 43b08af | 2010-05-24 15:10:25 -0500 | [diff] [blame] | 1256 | void *fdt_blob = *of_flat_tree; |
| 1257 | void *of_start = 0; |
David A. Long | a28afca | 2011-07-09 16:40:19 -0400 | [diff] [blame] | 1258 | char *fdt_high; |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1259 | ulong of_len = 0; |
Timur Tabi | 43b08af | 2010-05-24 15:10:25 -0500 | [diff] [blame] | 1260 | int err; |
David A. Long | a28afca | 2011-07-09 16:40:19 -0400 | [diff] [blame] | 1261 | int disable_relocation = 0; |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1262 | |
| 1263 | /* nothing to do */ |
| 1264 | if (*of_size == 0) |
| 1265 | return 0; |
| 1266 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1267 | if (fdt_check_header(fdt_blob) != 0) { |
| 1268 | fdt_error("image is not a fdt"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1269 | goto error; |
| 1270 | } |
| 1271 | |
Timur Tabi | 43b08af | 2010-05-24 15:10:25 -0500 | [diff] [blame] | 1272 | /* position on a 4K boundary before the alloc_current */ |
| 1273 | /* Pad the FDT by a specified amount */ |
| 1274 | of_len = *of_size + CONFIG_SYS_FDT_PAD; |
David A. Long | a28afca | 2011-07-09 16:40:19 -0400 | [diff] [blame] | 1275 | |
| 1276 | /* If fdt_high is set use it to select the relocation address */ |
| 1277 | fdt_high = getenv("fdt_high"); |
| 1278 | if (fdt_high) { |
| 1279 | void *desired_addr = (void *)simple_strtoul(fdt_high, NULL, 16); |
| 1280 | |
| 1281 | if (((ulong) desired_addr) == ~0UL) { |
| 1282 | /* All ones means use fdt in place */ |
| 1283 | desired_addr = fdt_blob; |
| 1284 | disable_relocation = 1; |
| 1285 | } |
| 1286 | if (desired_addr) { |
| 1287 | of_start = |
| 1288 | (void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000, |
| 1289 | ((ulong) |
| 1290 | desired_addr) |
| 1291 | + of_len); |
| 1292 | if (desired_addr && of_start != desired_addr) { |
| 1293 | puts("Failed using fdt_high value for Device Tree"); |
| 1294 | goto error; |
| 1295 | } |
| 1296 | } else { |
| 1297 | of_start = |
Matthew McClintock | 1bb5e90 | 2011-07-18 13:08:05 +0000 | [diff] [blame] | 1298 | (void *)(ulong) lmb_alloc(lmb, of_len, 0x1000); |
David A. Long | a28afca | 2011-07-09 16:40:19 -0400 | [diff] [blame] | 1299 | } |
| 1300 | } else { |
| 1301 | of_start = |
| 1302 | (void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000, |
| 1303 | getenv_bootm_mapsize() |
| 1304 | + getenv_bootm_low()); |
| 1305 | } |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1306 | |
Timur Tabi | 43b08af | 2010-05-24 15:10:25 -0500 | [diff] [blame] | 1307 | if (of_start == 0) { |
| 1308 | puts("device tree - allocation error\n"); |
| 1309 | goto error; |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1310 | } |
| 1311 | |
David A. Long | a28afca | 2011-07-09 16:40:19 -0400 | [diff] [blame] | 1312 | if (disable_relocation) { |
| 1313 | /* We assume there is space after the existing fdt to use for padding */ |
| 1314 | fdt_set_totalsize(of_start, of_len); |
| 1315 | printf(" Using Device Tree in place at %p, end %p\n", |
| 1316 | of_start, of_start + of_len - 1); |
| 1317 | } else { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1318 | debug("## device tree at %p ... %p (len=%ld [0x%lX])\n", |
David A. Long | a28afca | 2011-07-09 16:40:19 -0400 | [diff] [blame] | 1319 | fdt_blob, fdt_blob + *of_size - 1, of_len, of_len); |
Timur Tabi | 43b08af | 2010-05-24 15:10:25 -0500 | [diff] [blame] | 1320 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1321 | printf(" Loading Device Tree to %p, end %p ... ", |
David A. Long | a28afca | 2011-07-09 16:40:19 -0400 | [diff] [blame] | 1322 | of_start, of_start + of_len - 1); |
Timur Tabi | 43b08af | 2010-05-24 15:10:25 -0500 | [diff] [blame] | 1323 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1324 | err = fdt_open_into(fdt_blob, of_start, of_len); |
David A. Long | a28afca | 2011-07-09 16:40:19 -0400 | [diff] [blame] | 1325 | if (err != 0) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1326 | fdt_error("fdt move failed"); |
David A. Long | a28afca | 2011-07-09 16:40:19 -0400 | [diff] [blame] | 1327 | goto error; |
| 1328 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1329 | puts("OK\n"); |
Timur Tabi | 43b08af | 2010-05-24 15:10:25 -0500 | [diff] [blame] | 1330 | } |
Timur Tabi | 43b08af | 2010-05-24 15:10:25 -0500 | [diff] [blame] | 1331 | |
| 1332 | *of_flat_tree = of_start; |
| 1333 | *of_size = of_len; |
| 1334 | |
Kumar Gala | 54f9c86 | 2008-08-15 08:24:39 -0500 | [diff] [blame] | 1335 | set_working_fdt_addr(*of_flat_tree); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1336 | return 0; |
| 1337 | |
| 1338 | error: |
| 1339 | return 1; |
| 1340 | } |
Grant Likely | ed59e58 | 2011-03-28 09:58:49 +0000 | [diff] [blame] | 1341 | #endif /* CONFIG_OF_LIBFDT */ |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1342 | |
| 1343 | /** |
| 1344 | * boot_get_fdt - main fdt handling routine |
| 1345 | * @argc: command argument count |
| 1346 | * @argv: command argument list |
| 1347 | * @images: pointer to the bootm images structure |
| 1348 | * @of_flat_tree: pointer to a char* variable, will hold fdt start address |
| 1349 | * @of_size: pointer to a ulong variable, will hold fdt length |
| 1350 | * |
| 1351 | * boot_get_fdt() is responsible for finding a valid flat device tree image. |
| 1352 | * Curently supported are the following ramdisk sources: |
| 1353 | * - multicomponent kernel/ramdisk image, |
| 1354 | * - commandline provided address of decicated ramdisk image. |
| 1355 | * |
| 1356 | * returns: |
| 1357 | * 0, if fdt image was found and valid, or skipped |
| 1358 | * of_flat_tree and of_size are set to fdt start address and length if |
| 1359 | * fdt image is found and valid |
| 1360 | * |
| 1361 | * 1, if fdt image is found but corrupted |
| 1362 | * of_flat_tree and of_size are set to 0 if no fdt exists |
| 1363 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1364 | int boot_get_fdt(int flag, int argc, char * const argv[], |
| 1365 | bootm_headers_t *images, char **of_flat_tree, ulong *of_size) |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1366 | { |
Wolfgang Denk | 3a2003f | 2009-08-19 11:42:56 +0200 | [diff] [blame] | 1367 | const image_header_t *fdt_hdr; |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1368 | ulong fdt_addr; |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1369 | char *fdt_blob = NULL; |
| 1370 | ulong image_start, image_end; |
| 1371 | ulong load_start, load_end; |
| 1372 | #if defined(CONFIG_FIT) |
| 1373 | void *fit_hdr; |
| 1374 | const char *fit_uname_config = NULL; |
| 1375 | const char *fit_uname_fdt = NULL; |
| 1376 | ulong default_addr; |
| 1377 | int cfg_noffset; |
| 1378 | int fdt_noffset; |
| 1379 | const void *data; |
| 1380 | size_t size; |
| 1381 | #endif |
| 1382 | |
| 1383 | *of_flat_tree = NULL; |
| 1384 | *of_size = 0; |
| 1385 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1386 | if (argc > 3 || genimg_has_config(images)) { |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1387 | #if defined(CONFIG_FIT) |
| 1388 | if (argc > 3) { |
| 1389 | /* |
| 1390 | * If the FDT blob comes from the FIT image and the |
| 1391 | * FIT image address is omitted in the command line |
| 1392 | * argument, try to use ramdisk or os FIT image |
| 1393 | * address or default load address. |
| 1394 | */ |
| 1395 | if (images->fit_uname_rd) |
| 1396 | default_addr = (ulong)images->fit_hdr_rd; |
| 1397 | else if (images->fit_uname_os) |
| 1398 | default_addr = (ulong)images->fit_hdr_os; |
| 1399 | else |
| 1400 | default_addr = load_addr; |
| 1401 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1402 | if (fit_parse_conf(argv[3], default_addr, |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1403 | &fdt_addr, &fit_uname_config)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1404 | debug("* fdt: config '%s' from image at " |
| 1405 | "0x%08lx\n", |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1406 | fit_uname_config, fdt_addr); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1407 | } else if (fit_parse_subimage(argv[3], default_addr, |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1408 | &fdt_addr, &fit_uname_fdt)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1409 | debug("* fdt: subimage '%s' from image at " |
| 1410 | "0x%08lx\n", |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1411 | fit_uname_fdt, fdt_addr); |
| 1412 | } else |
| 1413 | #endif |
| 1414 | { |
| 1415 | fdt_addr = simple_strtoul(argv[3], NULL, 16); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1416 | debug("* fdt: cmdline image address = " |
| 1417 | "0x%08lx\n", |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1418 | fdt_addr); |
| 1419 | } |
| 1420 | #if defined(CONFIG_FIT) |
| 1421 | } else { |
| 1422 | /* use FIT configuration provided in first bootm |
| 1423 | * command argument |
| 1424 | */ |
| 1425 | fdt_addr = (ulong)images->fit_hdr_os; |
| 1426 | fit_uname_config = images->fit_uname_cfg; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1427 | debug("* fdt: using config '%s' from image " |
| 1428 | "at 0x%08lx\n", |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1429 | fit_uname_config, fdt_addr); |
| 1430 | |
| 1431 | /* |
| 1432 | * Check whether configuration has FDT blob defined, |
| 1433 | * if not quit silently. |
| 1434 | */ |
| 1435 | fit_hdr = (void *)fdt_addr; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1436 | cfg_noffset = fit_conf_get_node(fit_hdr, |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1437 | fit_uname_config); |
| 1438 | if (cfg_noffset < 0) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1439 | debug("* fdt: no such config\n"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1440 | return 0; |
| 1441 | } |
| 1442 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1443 | fdt_noffset = fit_conf_get_fdt_node(fit_hdr, |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1444 | cfg_noffset); |
| 1445 | if (fdt_noffset < 0) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1446 | debug("* fdt: no fdt in config\n"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1447 | return 0; |
| 1448 | } |
| 1449 | } |
| 1450 | #endif |
| 1451 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1452 | debug("## Checking for 'FDT'/'FDT Image' at %08lx\n", |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1453 | fdt_addr); |
| 1454 | |
| 1455 | /* copy from dataflash if needed */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1456 | fdt_addr = genimg_get_image(fdt_addr); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1457 | |
| 1458 | /* |
| 1459 | * Check if there is an FDT image at the |
| 1460 | * address provided in the second bootm argument |
| 1461 | * check image type, for FIT images get a FIT node. |
| 1462 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1463 | switch (genimg_get_format((void *)fdt_addr)) { |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1464 | case IMAGE_FORMAT_LEGACY: |
| 1465 | /* verify fdt_addr points to a valid image header */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1466 | printf("## Flattened Device Tree from Legacy Image " |
| 1467 | "at %08lx\n", |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1468 | fdt_addr); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1469 | fdt_hdr = image_get_fdt(fdt_addr); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1470 | if (!fdt_hdr) |
| 1471 | goto error; |
| 1472 | |
| 1473 | /* |
| 1474 | * move image data to the load address, |
| 1475 | * make sure we don't overwrite initial image |
| 1476 | */ |
| 1477 | image_start = (ulong)fdt_hdr; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1478 | image_end = image_get_image_end(fdt_hdr); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1479 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1480 | load_start = image_get_load(fdt_hdr); |
| 1481 | load_end = load_start + image_get_data_size(fdt_hdr); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1482 | |
| 1483 | if ((load_start < image_end) && (load_end > image_start)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1484 | fdt_error("fdt overwritten"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1485 | goto error; |
| 1486 | } |
| 1487 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1488 | debug(" Loading FDT from 0x%08lx to 0x%08lx\n", |
| 1489 | image_get_data(fdt_hdr), load_start); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1490 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1491 | memmove((void *)load_start, |
| 1492 | (void *)image_get_data(fdt_hdr), |
| 1493 | image_get_data_size(fdt_hdr)); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1494 | |
| 1495 | fdt_blob = (char *)load_start; |
| 1496 | break; |
| 1497 | case IMAGE_FORMAT_FIT: |
| 1498 | /* |
| 1499 | * This case will catch both: new uImage format |
| 1500 | * (libfdt based) and raw FDT blob (also libfdt |
| 1501 | * based). |
| 1502 | */ |
| 1503 | #if defined(CONFIG_FIT) |
| 1504 | /* check FDT blob vs FIT blob */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1505 | if (fit_check_format((const void *)fdt_addr)) { |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1506 | /* |
| 1507 | * FIT image |
| 1508 | */ |
| 1509 | fit_hdr = (void *)fdt_addr; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1510 | printf("## Flattened Device Tree from FIT " |
| 1511 | "Image at %08lx\n", |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1512 | fdt_addr); |
| 1513 | |
| 1514 | if (!fit_uname_fdt) { |
| 1515 | /* |
| 1516 | * no FDT blob image node unit name, |
| 1517 | * try to get config node first. If |
| 1518 | * config unit node name is NULL |
| 1519 | * fit_conf_get_node() will try to |
| 1520 | * find default config node |
| 1521 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1522 | cfg_noffset = fit_conf_get_node(fit_hdr, |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1523 | fit_uname_config); |
| 1524 | |
| 1525 | if (cfg_noffset < 0) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1526 | fdt_error("Could not find " |
| 1527 | "configuration " |
| 1528 | "node\n"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1529 | goto error; |
| 1530 | } |
| 1531 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1532 | fit_uname_config = fdt_get_name(fit_hdr, |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1533 | cfg_noffset, NULL); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1534 | printf(" Using '%s' configuration\n", |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1535 | fit_uname_config); |
| 1536 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1537 | fdt_noffset = fit_conf_get_fdt_node( |
| 1538 | fit_hdr, |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1539 | cfg_noffset); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1540 | fit_uname_fdt = fit_get_name(fit_hdr, |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1541 | fdt_noffset, NULL); |
| 1542 | } else { |
| 1543 | /* get FDT component image node offset */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1544 | fdt_noffset = fit_image_get_node( |
| 1545 | fit_hdr, |
| 1546 | fit_uname_fdt); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1547 | } |
| 1548 | if (fdt_noffset < 0) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1549 | fdt_error("Could not find subimage " |
| 1550 | "node\n"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1551 | goto error; |
| 1552 | } |
| 1553 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1554 | printf(" Trying '%s' FDT blob subimage\n", |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1555 | fit_uname_fdt); |
| 1556 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1557 | if (!fit_check_fdt(fit_hdr, fdt_noffset, |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1558 | images->verify)) |
| 1559 | goto error; |
| 1560 | |
| 1561 | /* get ramdisk image data address and length */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1562 | if (fit_image_get_data(fit_hdr, fdt_noffset, |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1563 | &data, &size)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1564 | fdt_error("Could not find FDT " |
| 1565 | "subimage data"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1566 | goto error; |
| 1567 | } |
| 1568 | |
| 1569 | /* verift that image data is a proper FDT blob */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1570 | if (fdt_check_header((char *)data) != 0) { |
| 1571 | fdt_error("Subimage data is not a FTD"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1572 | goto error; |
| 1573 | } |
| 1574 | |
| 1575 | /* |
| 1576 | * move image data to the load address, |
| 1577 | * make sure we don't overwrite initial image |
| 1578 | */ |
| 1579 | image_start = (ulong)fit_hdr; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1580 | image_end = fit_get_end(fit_hdr); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1581 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1582 | if (fit_image_get_load(fit_hdr, fdt_noffset, |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1583 | &load_start) == 0) { |
| 1584 | load_end = load_start + size; |
| 1585 | |
| 1586 | if ((load_start < image_end) && |
| 1587 | (load_end > image_start)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1588 | fdt_error("FDT overwritten"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1589 | goto error; |
| 1590 | } |
| 1591 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1592 | printf(" Loading FDT from 0x%08lx " |
| 1593 | "to 0x%08lx\n", |
| 1594 | (ulong)data, |
| 1595 | load_start); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1596 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1597 | memmove((void *)load_start, |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1598 | (void *)data, size); |
| 1599 | |
| 1600 | fdt_blob = (char *)load_start; |
| 1601 | } else { |
| 1602 | fdt_blob = (char *)data; |
| 1603 | } |
| 1604 | |
| 1605 | images->fit_hdr_fdt = fit_hdr; |
| 1606 | images->fit_uname_fdt = fit_uname_fdt; |
| 1607 | images->fit_noffset_fdt = fdt_noffset; |
| 1608 | break; |
| 1609 | } else |
| 1610 | #endif |
| 1611 | { |
| 1612 | /* |
| 1613 | * FDT blob |
| 1614 | */ |
| 1615 | fdt_blob = (char *)fdt_addr; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1616 | debug("* fdt: raw FDT blob\n"); |
| 1617 | printf("## Flattened Device Tree blob at " |
| 1618 | "%08lx\n", (long)fdt_blob); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1619 | } |
| 1620 | break; |
| 1621 | default: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1622 | puts("ERROR: Did not find a cmdline Flattened Device " |
| 1623 | "Tree\n"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1624 | goto error; |
| 1625 | } |
| 1626 | |
Simon Glass | 0ec2ce4 | 2011-09-23 06:22:04 +0000 | [diff] [blame] | 1627 | printf(" Booting using the fdt blob at 0x%p\n", fdt_blob); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1628 | |
| 1629 | } else if (images->legacy_hdr_valid && |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1630 | image_check_type(&images->legacy_hdr_os_copy, |
| 1631 | IH_TYPE_MULTI)) { |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1632 | |
| 1633 | ulong fdt_data, fdt_len; |
| 1634 | |
| 1635 | /* |
| 1636 | * Now check if we have a legacy multi-component image, |
| 1637 | * get second entry data start address and len. |
| 1638 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1639 | printf("## Flattened Device Tree from multi " |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1640 | "component Image at %08lX\n", |
| 1641 | (ulong)images->legacy_hdr_os); |
| 1642 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1643 | image_multi_getimg(images->legacy_hdr_os, 2, &fdt_data, |
| 1644 | &fdt_len); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1645 | if (fdt_len) { |
| 1646 | |
| 1647 | fdt_blob = (char *)fdt_data; |
Simon Glass | 0ec2ce4 | 2011-09-23 06:22:04 +0000 | [diff] [blame] | 1648 | printf(" Booting using the fdt at 0x%p\n", fdt_blob); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1649 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1650 | if (fdt_check_header(fdt_blob) != 0) { |
| 1651 | fdt_error("image is not a fdt"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1652 | goto error; |
| 1653 | } |
| 1654 | |
John Rigby | d1263fc | 2010-10-13 13:57:32 -0600 | [diff] [blame] | 1655 | if (fdt_totalsize(fdt_blob) != fdt_len) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1656 | fdt_error("fdt size != image size"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1657 | goto error; |
| 1658 | } |
| 1659 | } else { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1660 | debug("## No Flattened Device Tree\n"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1661 | return 0; |
| 1662 | } |
| 1663 | } else { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1664 | debug("## No Flattened Device Tree\n"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1665 | return 0; |
| 1666 | } |
| 1667 | |
| 1668 | *of_flat_tree = fdt_blob; |
John Rigby | d1263fc | 2010-10-13 13:57:32 -0600 | [diff] [blame] | 1669 | *of_size = fdt_totalsize(fdt_blob); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1670 | debug(" of_flat_tree at 0x%08lx size 0x%08lx\n", |
Andrew Klossner | 5251469 | 2008-08-21 07:12:26 -0700 | [diff] [blame] | 1671 | (ulong)*of_flat_tree, *of_size); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 1672 | |
| 1673 | return 0; |
| 1674 | |
| 1675 | error: |
| 1676 | *of_flat_tree = 0; |
| 1677 | *of_size = 0; |
| 1678 | return 1; |
| 1679 | } |
| 1680 | #endif /* CONFIG_OF_LIBFDT */ |
| 1681 | |
John Rigby | fca43cc | 2010-10-13 13:57:35 -0600 | [diff] [blame] | 1682 | #ifdef CONFIG_SYS_BOOT_GET_CMDLINE |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1683 | /** |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1684 | * boot_get_cmdline - allocate and initialize kernel cmdline |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1685 | * @lmb: pointer to lmb handle, will be used for memory mgmt |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1686 | * @cmd_start: pointer to a ulong variable, will hold cmdline start |
| 1687 | * @cmd_end: pointer to a ulong variable, will hold cmdline end |
| 1688 | * |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1689 | * boot_get_cmdline() allocates space for kernel command line below |
Grant Likely | 590d3ca | 2011-03-28 09:58:34 +0000 | [diff] [blame] | 1690 | * BOOTMAPSZ + getenv_bootm_low() address. If "bootargs" U-boot environemnt |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1691 | * variable is present its contents is copied to allocated kernel |
| 1692 | * command line. |
| 1693 | * |
| 1694 | * returns: |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1695 | * 0 - success |
| 1696 | * -1 - failure |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1697 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1698 | int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end) |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1699 | { |
| 1700 | char *cmdline; |
| 1701 | char *s; |
| 1702 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1703 | cmdline = (char *)(ulong)lmb_alloc_base(lmb, CONFIG_SYS_BARGSIZE, 0xf, |
Grant Likely | c3624e6 | 2011-03-28 09:58:43 +0000 | [diff] [blame] | 1704 | getenv_bootm_mapsize() + getenv_bootm_low()); |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1705 | |
| 1706 | if (cmdline == NULL) |
| 1707 | return -1; |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1708 | |
| 1709 | if ((s = getenv("bootargs")) == NULL) |
| 1710 | s = ""; |
| 1711 | |
| 1712 | strcpy(cmdline, s); |
| 1713 | |
| 1714 | *cmd_start = (ulong) & cmdline[0]; |
| 1715 | *cmd_end = *cmd_start + strlen(cmdline); |
| 1716 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1717 | debug("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end); |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1718 | |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1719 | return 0; |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1720 | } |
John Rigby | fca43cc | 2010-10-13 13:57:35 -0600 | [diff] [blame] | 1721 | #endif /* CONFIG_SYS_BOOT_GET_CMDLINE */ |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1722 | |
John Rigby | fca43cc | 2010-10-13 13:57:35 -0600 | [diff] [blame] | 1723 | #ifdef CONFIG_SYS_BOOT_GET_KBD |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1724 | /** |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1725 | * boot_get_kbd - allocate and initialize kernel copy of board info |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1726 | * @lmb: pointer to lmb handle, will be used for memory mgmt |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1727 | * @kbd: double pointer to board info data |
| 1728 | * |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1729 | * boot_get_kbd() allocates space for kernel copy of board info data below |
Grant Likely | 590d3ca | 2011-03-28 09:58:34 +0000 | [diff] [blame] | 1730 | * BOOTMAPSZ + getenv_bootm_low() address and kernel board info is initialized |
| 1731 | * with the current u-boot board info data. |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1732 | * |
| 1733 | * returns: |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1734 | * 0 - success |
| 1735 | * -1 - failure |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1736 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1737 | int boot_get_kbd(struct lmb *lmb, bd_t **kbd) |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1738 | { |
Becky Bruce | 391fd93 | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 1739 | *kbd = (bd_t *)(ulong)lmb_alloc_base(lmb, sizeof(bd_t), 0xf, |
Grant Likely | c3624e6 | 2011-03-28 09:58:43 +0000 | [diff] [blame] | 1740 | getenv_bootm_mapsize() + getenv_bootm_low()); |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1741 | if (*kbd == NULL) |
| 1742 | return -1; |
| 1743 | |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1744 | **kbd = *(gd->bd); |
| 1745 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1746 | debug("## kernel board info at 0x%08lx\n", (ulong)*kbd); |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1747 | |
| 1748 | #if defined(DEBUG) && defined(CONFIG_CMD_BDI) |
| 1749 | do_bdinfo(NULL, 0, 0, NULL); |
| 1750 | #endif |
| 1751 | |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1752 | return 0; |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1753 | } |
John Rigby | fca43cc | 2010-10-13 13:57:35 -0600 | [diff] [blame] | 1754 | #endif /* CONFIG_SYS_BOOT_GET_KBD */ |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1755 | #endif /* !USE_HOSTCC */ |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 1756 | |
Marian Balakowicz | f50433d | 2008-02-21 17:20:20 +0100 | [diff] [blame] | 1757 | #if defined(CONFIG_FIT) |
| 1758 | /*****************************************************************************/ |
| 1759 | /* New uImage format routines */ |
| 1760 | /*****************************************************************************/ |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1761 | #ifndef USE_HOSTCC |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1762 | static int fit_parse_spec(const char *spec, char sepc, ulong addr_curr, |
Marian Balakowicz | f50433d | 2008-02-21 17:20:20 +0100 | [diff] [blame] | 1763 | ulong *addr, const char **name) |
| 1764 | { |
| 1765 | const char *sep; |
| 1766 | |
| 1767 | *addr = addr_curr; |
| 1768 | *name = NULL; |
| 1769 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1770 | sep = strchr(spec, sepc); |
Marian Balakowicz | f50433d | 2008-02-21 17:20:20 +0100 | [diff] [blame] | 1771 | if (sep) { |
| 1772 | if (sep - spec > 0) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1773 | *addr = simple_strtoul(spec, NULL, 16); |
Marian Balakowicz | f50433d | 2008-02-21 17:20:20 +0100 | [diff] [blame] | 1774 | |
| 1775 | *name = sep + 1; |
| 1776 | return 1; |
| 1777 | } |
| 1778 | |
| 1779 | return 0; |
| 1780 | } |
| 1781 | |
| 1782 | /** |
| 1783 | * fit_parse_conf - parse FIT configuration spec |
| 1784 | * @spec: input string, containing configuration spec |
| 1785 | * @add_curr: current image address (to be used as a possible default) |
| 1786 | * @addr: pointer to a ulong variable, will hold FIT image address of a given |
| 1787 | * configuration |
| 1788 | * @conf_name double pointer to a char, will hold pointer to a configuration |
| 1789 | * unit name |
| 1790 | * |
| 1791 | * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>, |
| 1792 | * where <addr> is a FIT image address that contains configuration |
| 1793 | * with a <conf> unit name. |
| 1794 | * |
| 1795 | * Address part is optional, and if omitted default add_curr will |
| 1796 | * be used instead. |
| 1797 | * |
| 1798 | * returns: |
| 1799 | * 1 if spec is a valid configuration string, |
| 1800 | * addr and conf_name are set accordingly |
| 1801 | * 0 otherwise |
| 1802 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1803 | inline int fit_parse_conf(const char *spec, ulong addr_curr, |
Marian Balakowicz | f50433d | 2008-02-21 17:20:20 +0100 | [diff] [blame] | 1804 | ulong *addr, const char **conf_name) |
| 1805 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1806 | return fit_parse_spec(spec, '#', addr_curr, addr, conf_name); |
Marian Balakowicz | f50433d | 2008-02-21 17:20:20 +0100 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | /** |
| 1810 | * fit_parse_subimage - parse FIT subimage spec |
| 1811 | * @spec: input string, containing subimage spec |
| 1812 | * @add_curr: current image address (to be used as a possible default) |
| 1813 | * @addr: pointer to a ulong variable, will hold FIT image address of a given |
| 1814 | * subimage |
| 1815 | * @image_name: double pointer to a char, will hold pointer to a subimage name |
| 1816 | * |
| 1817 | * fit_parse_subimage() expects subimage spec in the for of |
| 1818 | * [<addr>]:<subimage>, where <addr> is a FIT image address that contains |
| 1819 | * subimage with a <subimg> unit name. |
| 1820 | * |
| 1821 | * Address part is optional, and if omitted default add_curr will |
| 1822 | * be used instead. |
| 1823 | * |
| 1824 | * returns: |
| 1825 | * 1 if spec is a valid subimage string, |
| 1826 | * addr and image_name are set accordingly |
| 1827 | * 0 otherwise |
| 1828 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1829 | inline int fit_parse_subimage(const char *spec, ulong addr_curr, |
Marian Balakowicz | f50433d | 2008-02-21 17:20:20 +0100 | [diff] [blame] | 1830 | ulong *addr, const char **image_name) |
| 1831 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1832 | return fit_parse_spec(spec, ':', addr_curr, addr, image_name); |
Marian Balakowicz | f50433d | 2008-02-21 17:20:20 +0100 | [diff] [blame] | 1833 | } |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 1834 | #endif /* !USE_HOSTCC */ |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1835 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1836 | static void fit_get_debug(const void *fit, int noffset, |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1837 | char *prop_name, int err) |
| 1838 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1839 | debug("Can't get '%s' property from FIT 0x%08lx, " |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1840 | "node: offset %d, name %s (%s)\n", |
| 1841 | prop_name, (ulong)fit, noffset, |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1842 | fit_get_name(fit, noffset, NULL), |
| 1843 | fdt_strerror(err)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | /** |
Bartlomiej Sieka | edbed24 | 2008-04-18 12:39:23 +0200 | [diff] [blame] | 1847 | * fit_print_contents - prints out the contents of the FIT format image |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1848 | * @fit: pointer to the FIT format image header |
| 1849 | * @p: pointer to prefix string |
| 1850 | * |
Bartlomiej Sieka | edbed24 | 2008-04-18 12:39:23 +0200 | [diff] [blame] | 1851 | * fit_print_contents() formats a multi line FIT image contents description. |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1852 | * The routine prints out FIT image properties (root node level) follwed by |
| 1853 | * the details of each component image. |
| 1854 | * |
| 1855 | * returns: |
| 1856 | * no returned results |
| 1857 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1858 | void fit_print_contents(const void *fit) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1859 | { |
| 1860 | char *desc; |
| 1861 | char *uname; |
| 1862 | int images_noffset; |
| 1863 | int confs_noffset; |
| 1864 | int noffset; |
| 1865 | int ndepth; |
| 1866 | int count = 0; |
| 1867 | int ret; |
Bartlomiej Sieka | edbed24 | 2008-04-18 12:39:23 +0200 | [diff] [blame] | 1868 | const char *p; |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1869 | #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) |
| 1870 | time_t timestamp; |
| 1871 | #endif |
| 1872 | |
Bartlomiej Sieka | edbed24 | 2008-04-18 12:39:23 +0200 | [diff] [blame] | 1873 | #ifdef USE_HOSTCC |
| 1874 | p = ""; |
| 1875 | #else |
| 1876 | p = " "; |
| 1877 | #endif |
| 1878 | |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1879 | /* Root node properties */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1880 | ret = fit_get_desc(fit, 0, &desc); |
| 1881 | printf("%sFIT description: ", p); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1882 | if (ret) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1883 | printf("unavailable\n"); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1884 | else |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1885 | printf("%s\n", desc); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1886 | |
| 1887 | #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1888 | ret = fit_get_timestamp(fit, 0, ×tamp); |
| 1889 | printf("%sCreated: ", p); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1890 | if (ret) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1891 | printf("unavailable\n"); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1892 | else |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1893 | genimg_print_time(timestamp); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1894 | #endif |
| 1895 | |
| 1896 | /* Find images parent node offset */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1897 | images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1898 | if (images_noffset < 0) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1899 | printf("Can't find images parent node '%s' (%s)\n", |
| 1900 | FIT_IMAGES_PATH, fdt_strerror(images_noffset)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1901 | return; |
| 1902 | } |
| 1903 | |
| 1904 | /* Process its subnodes, print out component images details */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1905 | for (ndepth = 0, count = 0, |
| 1906 | noffset = fdt_next_node(fit, images_noffset, &ndepth); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1907 | (noffset >= 0) && (ndepth > 0); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1908 | noffset = fdt_next_node(fit, noffset, &ndepth)) { |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1909 | if (ndepth == 1) { |
| 1910 | /* |
| 1911 | * Direct child node of the images parent node, |
| 1912 | * i.e. component image node. |
| 1913 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1914 | printf("%s Image %u (%s)\n", p, count++, |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1915 | fit_get_name(fit, noffset, NULL)); |
| 1916 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1917 | fit_image_print(fit, noffset, p); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1918 | } |
| 1919 | } |
| 1920 | |
| 1921 | /* Find configurations parent node offset */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1922 | confs_noffset = fdt_path_offset(fit, FIT_CONFS_PATH); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1923 | if (confs_noffset < 0) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1924 | debug("Can't get configurations parent node '%s' (%s)\n", |
| 1925 | FIT_CONFS_PATH, fdt_strerror(confs_noffset)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1926 | return; |
| 1927 | } |
| 1928 | |
| 1929 | /* get default configuration unit name from default property */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1930 | uname = (char *)fdt_getprop(fit, noffset, FIT_DEFAULT_PROP, NULL); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1931 | if (uname) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1932 | printf("%s Default Configuration: '%s'\n", p, uname); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1933 | |
| 1934 | /* Process its subnodes, print out configurations details */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1935 | for (ndepth = 0, count = 0, |
| 1936 | noffset = fdt_next_node(fit, confs_noffset, &ndepth); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1937 | (noffset >= 0) && (ndepth > 0); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1938 | noffset = fdt_next_node(fit, noffset, &ndepth)) { |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1939 | if (ndepth == 1) { |
| 1940 | /* |
| 1941 | * Direct child node of the configurations parent node, |
| 1942 | * i.e. configuration node. |
| 1943 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1944 | printf("%s Configuration %u (%s)\n", p, count++, |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1945 | fit_get_name(fit, noffset, NULL)); |
| 1946 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1947 | fit_conf_print(fit, noffset, p); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1948 | } |
| 1949 | } |
| 1950 | } |
| 1951 | |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1952 | /** |
| 1953 | * fit_image_print - prints out the FIT component image details |
| 1954 | * @fit: pointer to the FIT format image header |
| 1955 | * @image_noffset: offset of the component image node |
| 1956 | * @p: pointer to prefix string |
| 1957 | * |
| 1958 | * fit_image_print() lists all mandatory properies for the processed component |
Bartlomiej Sieka | fbc87dc | 2008-10-01 15:26:32 +0200 | [diff] [blame] | 1959 | * image. If present, hash nodes are printed out as well. Load |
| 1960 | * address for images of type firmware is also printed out. Since the load |
| 1961 | * address is not mandatory for firmware images, it will be output as |
| 1962 | * "unavailable" when not present. |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1963 | * |
| 1964 | * returns: |
| 1965 | * no returned results |
| 1966 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1967 | void fit_image_print(const void *fit, int image_noffset, const char *p) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1968 | { |
| 1969 | char *desc; |
| 1970 | uint8_t type, arch, os, comp; |
| 1971 | size_t size; |
| 1972 | ulong load, entry; |
| 1973 | const void *data; |
| 1974 | int noffset; |
| 1975 | int ndepth; |
| 1976 | int ret; |
| 1977 | |
| 1978 | /* Mandatory properties */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1979 | ret = fit_get_desc(fit, image_noffset, &desc); |
| 1980 | printf("%s Description: ", p); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1981 | if (ret) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1982 | printf("unavailable\n"); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1983 | else |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1984 | printf("%s\n", desc); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1985 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1986 | fit_image_get_type(fit, image_noffset, &type); |
| 1987 | printf("%s Type: %s\n", p, genimg_get_type_name(type)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1988 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1989 | fit_image_get_comp(fit, image_noffset, &comp); |
| 1990 | printf("%s Compression: %s\n", p, genimg_get_comp_name(comp)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1991 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1992 | ret = fit_image_get_data(fit, image_noffset, &data, &size); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1993 | |
| 1994 | #ifndef USE_HOSTCC |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1995 | printf("%s Data Start: ", p); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1996 | if (ret) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1997 | printf("unavailable\n"); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1998 | else |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1999 | printf("0x%08lx\n", (ulong)data); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2000 | #endif |
| 2001 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2002 | printf("%s Data Size: ", p); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2003 | if (ret) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2004 | printf("unavailable\n"); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2005 | else |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2006 | genimg_print_size(size); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2007 | |
| 2008 | /* Remaining, type dependent properties */ |
| 2009 | if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) || |
| 2010 | (type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) || |
| 2011 | (type == IH_TYPE_FLATDT)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2012 | fit_image_get_arch(fit, image_noffset, &arch); |
| 2013 | printf("%s Architecture: %s\n", p, genimg_get_arch_name(arch)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | if (type == IH_TYPE_KERNEL) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2017 | fit_image_get_os(fit, image_noffset, &os); |
| 2018 | printf("%s OS: %s\n", p, genimg_get_os_name(os)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2019 | } |
| 2020 | |
Bartlomiej Sieka | fbc87dc | 2008-10-01 15:26:32 +0200 | [diff] [blame] | 2021 | if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) || |
| 2022 | (type == IH_TYPE_FIRMWARE)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2023 | ret = fit_image_get_load(fit, image_noffset, &load); |
| 2024 | printf("%s Load Address: ", p); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2025 | if (ret) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2026 | printf("unavailable\n"); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2027 | else |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2028 | printf("0x%08lx\n", load); |
Bartlomiej Sieka | fbc87dc | 2008-10-01 15:26:32 +0200 | [diff] [blame] | 2029 | } |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2030 | |
Bartlomiej Sieka | fbc87dc | 2008-10-01 15:26:32 +0200 | [diff] [blame] | 2031 | if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2032 | fit_image_get_entry(fit, image_noffset, &entry); |
| 2033 | printf("%s Entry Point: ", p); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2034 | if (ret) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2035 | printf("unavailable\n"); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2036 | else |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2037 | printf("0x%08lx\n", entry); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | /* Process all hash subnodes of the component image node */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2041 | for (ndepth = 0, noffset = fdt_next_node(fit, image_noffset, &ndepth); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2042 | (noffset >= 0) && (ndepth > 0); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2043 | noffset = fdt_next_node(fit, noffset, &ndepth)) { |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2044 | if (ndepth == 1) { |
| 2045 | /* Direct child node of the component image node */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2046 | fit_image_print_hash(fit, noffset, p); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2047 | } |
| 2048 | } |
| 2049 | } |
| 2050 | |
| 2051 | /** |
| 2052 | * fit_image_print_hash - prints out the hash node details |
| 2053 | * @fit: pointer to the FIT format image header |
| 2054 | * @noffset: offset of the hash node |
| 2055 | * @p: pointer to prefix string |
| 2056 | * |
| 2057 | * fit_image_print_hash() lists properies for the processed hash node |
| 2058 | * |
| 2059 | * returns: |
| 2060 | * no returned results |
| 2061 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2062 | void fit_image_print_hash(const void *fit, int noffset, const char *p) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2063 | { |
| 2064 | char *algo; |
| 2065 | uint8_t *value; |
| 2066 | int value_len; |
| 2067 | int i, ret; |
| 2068 | |
| 2069 | /* |
| 2070 | * Check subnode name, must be equal to "hash". |
| 2071 | * Multiple hash nodes require unique unit node |
| 2072 | * names, e.g. hash@1, hash@2, etc. |
| 2073 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2074 | if (strncmp(fit_get_name(fit, noffset, NULL), |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2075 | FIT_HASH_NODENAME, |
| 2076 | strlen(FIT_HASH_NODENAME)) != 0) |
| 2077 | return; |
| 2078 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2079 | debug("%s Hash node: '%s'\n", p, |
| 2080 | fit_get_name(fit, noffset, NULL)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2081 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2082 | printf("%s Hash algo: ", p); |
| 2083 | if (fit_image_hash_get_algo(fit, noffset, &algo)) { |
| 2084 | printf("invalid/unsupported\n"); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2085 | return; |
| 2086 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2087 | printf("%s\n", algo); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2088 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2089 | ret = fit_image_hash_get_value(fit, noffset, &value, |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2090 | &value_len); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2091 | printf("%s Hash value: ", p); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2092 | if (ret) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2093 | printf("unavailable\n"); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2094 | } else { |
| 2095 | for (i = 0; i < value_len; i++) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2096 | printf("%02x", value[i]); |
| 2097 | printf("\n"); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2098 | } |
| 2099 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2100 | debug("%s Hash len: %d\n", p, value_len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | /** |
| 2104 | * fit_get_desc - get node description property |
| 2105 | * @fit: pointer to the FIT format image header |
| 2106 | * @noffset: node offset |
| 2107 | * @desc: double pointer to the char, will hold pointer to the descrption |
| 2108 | * |
| 2109 | * fit_get_desc() reads description property from a given node, if |
| 2110 | * description is found pointer to it is returened in third call argument. |
| 2111 | * |
| 2112 | * returns: |
| 2113 | * 0, on success |
| 2114 | * -1, on failure |
| 2115 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2116 | int fit_get_desc(const void *fit, int noffset, char **desc) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2117 | { |
| 2118 | int len; |
| 2119 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2120 | *desc = (char *)fdt_getprop(fit, noffset, FIT_DESC_PROP, &len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2121 | if (*desc == NULL) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2122 | fit_get_debug(fit, noffset, FIT_DESC_PROP, len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2123 | return -1; |
| 2124 | } |
| 2125 | |
| 2126 | return 0; |
| 2127 | } |
| 2128 | |
| 2129 | /** |
| 2130 | * fit_get_timestamp - get node timestamp property |
| 2131 | * @fit: pointer to the FIT format image header |
| 2132 | * @noffset: node offset |
| 2133 | * @timestamp: pointer to the time_t, will hold read timestamp |
| 2134 | * |
| 2135 | * fit_get_timestamp() reads timestamp poperty from given node, if timestamp |
| 2136 | * is found and has a correct size its value is retured in third call |
| 2137 | * argument. |
| 2138 | * |
| 2139 | * returns: |
| 2140 | * 0, on success |
| 2141 | * -1, on property read failure |
| 2142 | * -2, on wrong timestamp size |
| 2143 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2144 | int fit_get_timestamp(const void *fit, int noffset, time_t *timestamp) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2145 | { |
| 2146 | int len; |
| 2147 | const void *data; |
| 2148 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2149 | data = fdt_getprop(fit, noffset, FIT_TIMESTAMP_PROP, &len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2150 | if (data == NULL) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2151 | fit_get_debug(fit, noffset, FIT_TIMESTAMP_PROP, len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2152 | return -1; |
| 2153 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2154 | if (len != sizeof(uint32_t)) { |
| 2155 | debug("FIT timestamp with incorrect size of (%u)\n", len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2156 | return -2; |
| 2157 | } |
| 2158 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2159 | *timestamp = uimage_to_cpu(*((uint32_t *)data)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2160 | return 0; |
| 2161 | } |
| 2162 | |
| 2163 | /** |
| 2164 | * fit_image_get_node - get node offset for component image of a given unit name |
| 2165 | * @fit: pointer to the FIT format image header |
| 2166 | * @image_uname: component image node unit name |
| 2167 | * |
| 2168 | * fit_image_get_node() finds a component image (withing the '/images' |
| 2169 | * node) of a provided unit name. If image is found its node offset is |
| 2170 | * returned to the caller. |
| 2171 | * |
| 2172 | * returns: |
| 2173 | * image node offset when found (>=0) |
| 2174 | * negative number on failure (FDT_ERR_* code) |
| 2175 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2176 | int fit_image_get_node(const void *fit, const char *image_uname) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2177 | { |
| 2178 | int noffset, images_noffset; |
| 2179 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2180 | images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2181 | if (images_noffset < 0) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2182 | debug("Can't find images parent node '%s' (%s)\n", |
| 2183 | FIT_IMAGES_PATH, fdt_strerror(images_noffset)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2184 | return images_noffset; |
| 2185 | } |
| 2186 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2187 | noffset = fdt_subnode_offset(fit, images_noffset, image_uname); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2188 | if (noffset < 0) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2189 | debug("Can't get node offset for image unit name: '%s' (%s)\n", |
| 2190 | image_uname, fdt_strerror(noffset)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2191 | } |
| 2192 | |
| 2193 | return noffset; |
| 2194 | } |
| 2195 | |
| 2196 | /** |
| 2197 | * fit_image_get_os - get os id for a given component image node |
| 2198 | * @fit: pointer to the FIT format image header |
| 2199 | * @noffset: component image node offset |
| 2200 | * @os: pointer to the uint8_t, will hold os numeric id |
| 2201 | * |
| 2202 | * fit_image_get_os() finds os property in a given component image node. |
| 2203 | * If the property is found, its (string) value is translated to the numeric |
| 2204 | * id which is returned to the caller. |
| 2205 | * |
| 2206 | * returns: |
| 2207 | * 0, on success |
| 2208 | * -1, on failure |
| 2209 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2210 | int fit_image_get_os(const void *fit, int noffset, uint8_t *os) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2211 | { |
| 2212 | int len; |
| 2213 | const void *data; |
| 2214 | |
| 2215 | /* Get OS name from property data */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2216 | data = fdt_getprop(fit, noffset, FIT_OS_PROP, &len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2217 | if (data == NULL) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2218 | fit_get_debug(fit, noffset, FIT_OS_PROP, len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2219 | *os = -1; |
| 2220 | return -1; |
| 2221 | } |
| 2222 | |
| 2223 | /* Translate OS name to id */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2224 | *os = genimg_get_os_id(data); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2225 | return 0; |
| 2226 | } |
| 2227 | |
| 2228 | /** |
| 2229 | * fit_image_get_arch - get arch id for a given component image node |
| 2230 | * @fit: pointer to the FIT format image header |
| 2231 | * @noffset: component image node offset |
| 2232 | * @arch: pointer to the uint8_t, will hold arch numeric id |
| 2233 | * |
| 2234 | * fit_image_get_arch() finds arch property in a given component image node. |
| 2235 | * If the property is found, its (string) value is translated to the numeric |
| 2236 | * id which is returned to the caller. |
| 2237 | * |
| 2238 | * returns: |
| 2239 | * 0, on success |
| 2240 | * -1, on failure |
| 2241 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2242 | int fit_image_get_arch(const void *fit, int noffset, uint8_t *arch) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2243 | { |
| 2244 | int len; |
| 2245 | const void *data; |
| 2246 | |
| 2247 | /* Get architecture name from property data */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2248 | data = fdt_getprop(fit, noffset, FIT_ARCH_PROP, &len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2249 | if (data == NULL) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2250 | fit_get_debug(fit, noffset, FIT_ARCH_PROP, len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2251 | *arch = -1; |
| 2252 | return -1; |
| 2253 | } |
| 2254 | |
| 2255 | /* Translate architecture name to id */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2256 | *arch = genimg_get_arch_id(data); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2257 | return 0; |
| 2258 | } |
| 2259 | |
| 2260 | /** |
| 2261 | * fit_image_get_type - get type id for a given component image node |
| 2262 | * @fit: pointer to the FIT format image header |
| 2263 | * @noffset: component image node offset |
| 2264 | * @type: pointer to the uint8_t, will hold type numeric id |
| 2265 | * |
| 2266 | * fit_image_get_type() finds type property in a given component image node. |
| 2267 | * If the property is found, its (string) value is translated to the numeric |
| 2268 | * id which is returned to the caller. |
| 2269 | * |
| 2270 | * returns: |
| 2271 | * 0, on success |
| 2272 | * -1, on failure |
| 2273 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2274 | int fit_image_get_type(const void *fit, int noffset, uint8_t *type) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2275 | { |
| 2276 | int len; |
| 2277 | const void *data; |
| 2278 | |
| 2279 | /* Get image type name from property data */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2280 | data = fdt_getprop(fit, noffset, FIT_TYPE_PROP, &len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2281 | if (data == NULL) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2282 | fit_get_debug(fit, noffset, FIT_TYPE_PROP, len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2283 | *type = -1; |
| 2284 | return -1; |
| 2285 | } |
| 2286 | |
| 2287 | /* Translate image type name to id */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2288 | *type = genimg_get_type_id(data); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2289 | return 0; |
| 2290 | } |
| 2291 | |
| 2292 | /** |
| 2293 | * fit_image_get_comp - get comp id for a given component image node |
| 2294 | * @fit: pointer to the FIT format image header |
| 2295 | * @noffset: component image node offset |
| 2296 | * @comp: pointer to the uint8_t, will hold comp numeric id |
| 2297 | * |
| 2298 | * fit_image_get_comp() finds comp property in a given component image node. |
| 2299 | * If the property is found, its (string) value is translated to the numeric |
| 2300 | * id which is returned to the caller. |
| 2301 | * |
| 2302 | * returns: |
| 2303 | * 0, on success |
| 2304 | * -1, on failure |
| 2305 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2306 | int fit_image_get_comp(const void *fit, int noffset, uint8_t *comp) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2307 | { |
| 2308 | int len; |
| 2309 | const void *data; |
| 2310 | |
| 2311 | /* Get compression name from property data */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2312 | data = fdt_getprop(fit, noffset, FIT_COMP_PROP, &len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2313 | if (data == NULL) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2314 | fit_get_debug(fit, noffset, FIT_COMP_PROP, len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2315 | *comp = -1; |
| 2316 | return -1; |
| 2317 | } |
| 2318 | |
| 2319 | /* Translate compression name to id */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2320 | *comp = genimg_get_comp_id(data); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2321 | return 0; |
| 2322 | } |
| 2323 | |
| 2324 | /** |
| 2325 | * fit_image_get_load - get load address property for a given component image node |
| 2326 | * @fit: pointer to the FIT format image header |
| 2327 | * @noffset: component image node offset |
| 2328 | * @load: pointer to the uint32_t, will hold load address |
| 2329 | * |
| 2330 | * fit_image_get_load() finds load address property in a given component image node. |
| 2331 | * If the property is found, its value is returned to the caller. |
| 2332 | * |
| 2333 | * returns: |
| 2334 | * 0, on success |
| 2335 | * -1, on failure |
| 2336 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2337 | int fit_image_get_load(const void *fit, int noffset, ulong *load) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2338 | { |
| 2339 | int len; |
| 2340 | const uint32_t *data; |
| 2341 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2342 | data = fdt_getprop(fit, noffset, FIT_LOAD_PROP, &len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2343 | if (data == NULL) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2344 | fit_get_debug(fit, noffset, FIT_LOAD_PROP, len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2345 | return -1; |
| 2346 | } |
| 2347 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2348 | *load = uimage_to_cpu(*data); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2349 | return 0; |
| 2350 | } |
| 2351 | |
| 2352 | /** |
| 2353 | * fit_image_get_entry - get entry point address property for a given component image node |
| 2354 | * @fit: pointer to the FIT format image header |
| 2355 | * @noffset: component image node offset |
| 2356 | * @entry: pointer to the uint32_t, will hold entry point address |
| 2357 | * |
| 2358 | * fit_image_get_entry() finds entry point address property in a given component image node. |
| 2359 | * If the property is found, its value is returned to the caller. |
| 2360 | * |
| 2361 | * returns: |
| 2362 | * 0, on success |
| 2363 | * -1, on failure |
| 2364 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2365 | int fit_image_get_entry(const void *fit, int noffset, ulong *entry) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2366 | { |
| 2367 | int len; |
| 2368 | const uint32_t *data; |
| 2369 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2370 | data = fdt_getprop(fit, noffset, FIT_ENTRY_PROP, &len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2371 | if (data == NULL) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2372 | fit_get_debug(fit, noffset, FIT_ENTRY_PROP, len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2373 | return -1; |
| 2374 | } |
| 2375 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2376 | *entry = uimage_to_cpu(*data); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2377 | return 0; |
| 2378 | } |
| 2379 | |
| 2380 | /** |
| 2381 | * fit_image_get_data - get data property and its size for a given component image node |
| 2382 | * @fit: pointer to the FIT format image header |
| 2383 | * @noffset: component image node offset |
| 2384 | * @data: double pointer to void, will hold data property's data address |
| 2385 | * @size: pointer to size_t, will hold data property's data size |
| 2386 | * |
| 2387 | * fit_image_get_data() finds data property in a given component image node. |
| 2388 | * If the property is found its data start address and size are returned to |
| 2389 | * the caller. |
| 2390 | * |
| 2391 | * returns: |
| 2392 | * 0, on success |
| 2393 | * -1, on failure |
| 2394 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2395 | int fit_image_get_data(const void *fit, int noffset, |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2396 | const void **data, size_t *size) |
| 2397 | { |
| 2398 | int len; |
| 2399 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2400 | *data = fdt_getprop(fit, noffset, FIT_DATA_PROP, &len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2401 | if (*data == NULL) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2402 | fit_get_debug(fit, noffset, FIT_DATA_PROP, len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2403 | *size = 0; |
| 2404 | return -1; |
| 2405 | } |
| 2406 | |
| 2407 | *size = len; |
| 2408 | return 0; |
| 2409 | } |
| 2410 | |
| 2411 | /** |
| 2412 | * fit_image_hash_get_algo - get hash algorithm name |
| 2413 | * @fit: pointer to the FIT format image header |
| 2414 | * @noffset: hash node offset |
| 2415 | * @algo: double pointer to char, will hold pointer to the algorithm name |
| 2416 | * |
| 2417 | * fit_image_hash_get_algo() finds hash algorithm property in a given hash node. |
| 2418 | * If the property is found its data start address is returned to the caller. |
| 2419 | * |
| 2420 | * returns: |
| 2421 | * 0, on success |
| 2422 | * -1, on failure |
| 2423 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2424 | int fit_image_hash_get_algo(const void *fit, int noffset, char **algo) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2425 | { |
| 2426 | int len; |
| 2427 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2428 | *algo = (char *)fdt_getprop(fit, noffset, FIT_ALGO_PROP, &len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2429 | if (*algo == NULL) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2430 | fit_get_debug(fit, noffset, FIT_ALGO_PROP, len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2431 | return -1; |
| 2432 | } |
| 2433 | |
| 2434 | return 0; |
| 2435 | } |
| 2436 | |
| 2437 | /** |
| 2438 | * fit_image_hash_get_value - get hash value and length |
| 2439 | * @fit: pointer to the FIT format image header |
| 2440 | * @noffset: hash node offset |
| 2441 | * @value: double pointer to uint8_t, will hold address of a hash value data |
| 2442 | * @value_len: pointer to an int, will hold hash data length |
| 2443 | * |
| 2444 | * fit_image_hash_get_value() finds hash value property in a given hash node. |
| 2445 | * If the property is found its data start address and size are returned to |
| 2446 | * the caller. |
| 2447 | * |
| 2448 | * returns: |
| 2449 | * 0, on success |
| 2450 | * -1, on failure |
| 2451 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2452 | int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value, |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2453 | int *value_len) |
| 2454 | { |
| 2455 | int len; |
| 2456 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2457 | *value = (uint8_t *)fdt_getprop(fit, noffset, FIT_VALUE_PROP, &len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2458 | if (*value == NULL) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2459 | fit_get_debug(fit, noffset, FIT_VALUE_PROP, len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2460 | *value_len = 0; |
| 2461 | return -1; |
| 2462 | } |
| 2463 | |
| 2464 | *value_len = len; |
| 2465 | return 0; |
| 2466 | } |
| 2467 | |
| 2468 | /** |
| 2469 | * fit_set_timestamp - set node timestamp property |
| 2470 | * @fit: pointer to the FIT format image header |
| 2471 | * @noffset: node offset |
| 2472 | * @timestamp: timestamp value to be set |
| 2473 | * |
| 2474 | * fit_set_timestamp() attempts to set timestamp property in the requested |
| 2475 | * node and returns operation status to the caller. |
| 2476 | * |
| 2477 | * returns: |
| 2478 | * 0, on success |
| 2479 | * -1, on property read failure |
| 2480 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2481 | int fit_set_timestamp(void *fit, int noffset, time_t timestamp) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2482 | { |
| 2483 | uint32_t t; |
| 2484 | int ret; |
| 2485 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2486 | t = cpu_to_uimage(timestamp); |
| 2487 | ret = fdt_setprop(fit, noffset, FIT_TIMESTAMP_PROP, &t, |
| 2488 | sizeof(uint32_t)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2489 | if (ret) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2490 | printf("Can't set '%s' property for '%s' node (%s)\n", |
| 2491 | FIT_TIMESTAMP_PROP, fit_get_name(fit, noffset, NULL), |
| 2492 | fdt_strerror(ret)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2493 | return -1; |
| 2494 | } |
| 2495 | |
| 2496 | return 0; |
| 2497 | } |
| 2498 | |
| 2499 | /** |
| 2500 | * calculate_hash - calculate and return hash for provided input data |
| 2501 | * @data: pointer to the input data |
| 2502 | * @data_len: data length |
| 2503 | * @algo: requested hash algorithm |
| 2504 | * @value: pointer to the char, will hold hash value data (caller must |
| 2505 | * allocate enough free space) |
| 2506 | * value_len: length of the calculated hash |
| 2507 | * |
| 2508 | * calculate_hash() computes input data hash according to the requested algorithm. |
| 2509 | * Resulting hash value is placed in caller provided 'value' buffer, length |
| 2510 | * of the calculated hash is returned via value_len pointer argument. |
| 2511 | * |
| 2512 | * returns: |
| 2513 | * 0, on success |
| 2514 | * -1, when algo is unsupported |
| 2515 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2516 | static int calculate_hash(const void *data, int data_len, const char *algo, |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2517 | uint8_t *value, int *value_len) |
| 2518 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2519 | if (strcmp(algo, "crc32") == 0) { |
| 2520 | *((uint32_t *)value) = crc32_wd(0, data, data_len, |
Bartlomiej Sieka | 7590378 | 2008-04-25 13:54:02 +0200 | [diff] [blame] | 2521 | CHUNKSZ_CRC32); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2522 | *((uint32_t *)value) = cpu_to_uimage(*((uint32_t *)value)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2523 | *value_len = 4; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2524 | } else if (strcmp(algo, "sha1") == 0) { |
| 2525 | sha1_csum_wd((unsigned char *) data, data_len, |
Bartlomiej Sieka | 7590378 | 2008-04-25 13:54:02 +0200 | [diff] [blame] | 2526 | (unsigned char *) value, CHUNKSZ_SHA1); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2527 | *value_len = 20; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2528 | } else if (strcmp(algo, "md5") == 0) { |
| 2529 | md5_wd((unsigned char *)data, data_len, value, CHUNKSZ_MD5); |
Bartlomiej Sieka | 766529f | 2008-03-14 16:22:34 +0100 | [diff] [blame] | 2530 | *value_len = 16; |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2531 | } else { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2532 | debug("Unsupported hash alogrithm\n"); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2533 | return -1; |
| 2534 | } |
| 2535 | return 0; |
| 2536 | } |
| 2537 | |
| 2538 | #ifdef USE_HOSTCC |
| 2539 | /** |
| 2540 | * fit_set_hashes - process FIT component image nodes and calculate hashes |
| 2541 | * @fit: pointer to the FIT format image header |
| 2542 | * |
| 2543 | * fit_set_hashes() adds hash values for all component images in the FIT blob. |
| 2544 | * Hashes are calculated for all component images which have hash subnodes |
| 2545 | * with algorithm property set to one of the supported hash algorithms. |
| 2546 | * |
| 2547 | * returns |
| 2548 | * 0, on success |
| 2549 | * libfdt error code, on failure |
| 2550 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2551 | int fit_set_hashes(void *fit) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2552 | { |
| 2553 | int images_noffset; |
| 2554 | int noffset; |
| 2555 | int ndepth; |
| 2556 | int ret; |
| 2557 | |
| 2558 | /* Find images parent node offset */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2559 | images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2560 | if (images_noffset < 0) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2561 | printf("Can't find images parent node '%s' (%s)\n", |
| 2562 | FIT_IMAGES_PATH, fdt_strerror(images_noffset)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2563 | return images_noffset; |
| 2564 | } |
| 2565 | |
| 2566 | /* Process its subnodes, print out component images details */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2567 | for (ndepth = 0, noffset = fdt_next_node(fit, images_noffset, &ndepth); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2568 | (noffset >= 0) && (ndepth > 0); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2569 | noffset = fdt_next_node(fit, noffset, &ndepth)) { |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2570 | if (ndepth == 1) { |
| 2571 | /* |
| 2572 | * Direct child node of the images parent node, |
| 2573 | * i.e. component image node. |
| 2574 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2575 | ret = fit_image_set_hashes(fit, noffset); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2576 | if (ret) |
| 2577 | return ret; |
| 2578 | } |
| 2579 | } |
| 2580 | |
| 2581 | return 0; |
| 2582 | } |
| 2583 | |
| 2584 | /** |
| 2585 | * fit_image_set_hashes - calculate/set hashes for given component image node |
| 2586 | * @fit: pointer to the FIT format image header |
| 2587 | * @image_noffset: requested component image node |
| 2588 | * |
| 2589 | * fit_image_set_hashes() adds hash values for an component image node. All |
| 2590 | * existing hash subnodes are checked, if algorithm property is set to one of |
| 2591 | * the supported hash algorithms, hash value is computed and corresponding |
| 2592 | * hash node property is set, for example: |
| 2593 | * |
| 2594 | * Input component image node structure: |
| 2595 | * |
| 2596 | * o image@1 (at image_noffset) |
| 2597 | * | - data = [binary data] |
| 2598 | * o hash@1 |
| 2599 | * |- algo = "sha1" |
| 2600 | * |
| 2601 | * Output component image node structure: |
| 2602 | * |
| 2603 | * o image@1 (at image_noffset) |
| 2604 | * | - data = [binary data] |
| 2605 | * o hash@1 |
| 2606 | * |- algo = "sha1" |
| 2607 | * |- value = sha1(data) |
| 2608 | * |
| 2609 | * returns: |
| 2610 | * 0 on sucess |
| 2611 | * <0 on failure |
| 2612 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2613 | int fit_image_set_hashes(void *fit, int image_noffset) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2614 | { |
| 2615 | const void *data; |
| 2616 | size_t size; |
| 2617 | char *algo; |
| 2618 | uint8_t value[FIT_MAX_HASH_LEN]; |
| 2619 | int value_len; |
| 2620 | int noffset; |
| 2621 | int ndepth; |
| 2622 | |
| 2623 | /* Get image data and data length */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2624 | if (fit_image_get_data(fit, image_noffset, &data, &size)) { |
| 2625 | printf("Can't get image data/size\n"); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2626 | return -1; |
| 2627 | } |
| 2628 | |
| 2629 | /* Process all hash subnodes of the component image node */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2630 | for (ndepth = 0, noffset = fdt_next_node(fit, image_noffset, &ndepth); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2631 | (noffset >= 0) && (ndepth > 0); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2632 | noffset = fdt_next_node(fit, noffset, &ndepth)) { |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2633 | if (ndepth == 1) { |
| 2634 | /* Direct child node of the component image node */ |
| 2635 | |
| 2636 | /* |
| 2637 | * Check subnode name, must be equal to "hash". |
| 2638 | * Multiple hash nodes require unique unit node |
| 2639 | * names, e.g. hash@1, hash@2, etc. |
| 2640 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2641 | if (strncmp(fit_get_name(fit, noffset, NULL), |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2642 | FIT_HASH_NODENAME, |
| 2643 | strlen(FIT_HASH_NODENAME)) != 0) { |
| 2644 | /* Not a hash subnode, skip it */ |
| 2645 | continue; |
| 2646 | } |
| 2647 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2648 | if (fit_image_hash_get_algo(fit, noffset, &algo)) { |
| 2649 | printf("Can't get hash algo property for " |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2650 | "'%s' hash node in '%s' image node\n", |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2651 | fit_get_name(fit, noffset, NULL), |
| 2652 | fit_get_name(fit, image_noffset, NULL)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2653 | return -1; |
| 2654 | } |
| 2655 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2656 | if (calculate_hash(data, size, algo, value, |
| 2657 | &value_len)) { |
| 2658 | printf("Unsupported hash algorithm (%s) for " |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2659 | "'%s' hash node in '%s' image node\n", |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2660 | algo, fit_get_name(fit, noffset, NULL), |
| 2661 | fit_get_name(fit, image_noffset, |
| 2662 | NULL)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2663 | return -1; |
| 2664 | } |
| 2665 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2666 | if (fit_image_hash_set_value(fit, noffset, value, |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2667 | value_len)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2668 | printf("Can't set hash value for " |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2669 | "'%s' hash node in '%s' image node\n", |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2670 | fit_get_name(fit, noffset, NULL), |
| 2671 | fit_get_name(fit, image_noffset, NULL)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2672 | return -1; |
| 2673 | } |
| 2674 | } |
| 2675 | } |
| 2676 | |
| 2677 | return 0; |
| 2678 | } |
| 2679 | |
| 2680 | /** |
| 2681 | * fit_image_hash_set_value - set hash value in requested has node |
| 2682 | * @fit: pointer to the FIT format image header |
| 2683 | * @noffset: hash node offset |
| 2684 | * @value: hash value to be set |
| 2685 | * @value_len: hash value length |
| 2686 | * |
| 2687 | * fit_image_hash_set_value() attempts to set hash value in a node at offset |
| 2688 | * given and returns operation status to the caller. |
| 2689 | * |
| 2690 | * returns |
| 2691 | * 0, on success |
| 2692 | * -1, on failure |
| 2693 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2694 | int fit_image_hash_set_value(void *fit, int noffset, uint8_t *value, |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2695 | int value_len) |
| 2696 | { |
| 2697 | int ret; |
| 2698 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2699 | ret = fdt_setprop(fit, noffset, FIT_VALUE_PROP, value, value_len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2700 | if (ret) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2701 | printf("Can't set hash '%s' property for '%s' node(%s)\n", |
| 2702 | FIT_VALUE_PROP, fit_get_name(fit, noffset, NULL), |
| 2703 | fdt_strerror(ret)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2704 | return -1; |
| 2705 | } |
| 2706 | |
| 2707 | return 0; |
| 2708 | } |
| 2709 | #endif /* USE_HOSTCC */ |
| 2710 | |
| 2711 | /** |
| 2712 | * fit_image_check_hashes - verify data intergity |
| 2713 | * @fit: pointer to the FIT format image header |
| 2714 | * @image_noffset: component image node offset |
| 2715 | * |
| 2716 | * fit_image_check_hashes() goes over component image hash nodes, |
| 2717 | * re-calculates each data hash and compares with the value stored in hash |
| 2718 | * node. |
| 2719 | * |
| 2720 | * returns: |
| 2721 | * 1, if all hashes are valid |
| 2722 | * 0, otherwise (or on error) |
| 2723 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2724 | int fit_image_check_hashes(const void *fit, int image_noffset) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2725 | { |
| 2726 | const void *data; |
| 2727 | size_t size; |
| 2728 | char *algo; |
| 2729 | uint8_t *fit_value; |
| 2730 | int fit_value_len; |
| 2731 | uint8_t value[FIT_MAX_HASH_LEN]; |
| 2732 | int value_len; |
| 2733 | int noffset; |
| 2734 | int ndepth; |
| 2735 | char *err_msg = ""; |
| 2736 | |
| 2737 | /* Get image data and data length */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2738 | if (fit_image_get_data(fit, image_noffset, &data, &size)) { |
| 2739 | printf("Can't get image data/size\n"); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2740 | return 0; |
| 2741 | } |
| 2742 | |
| 2743 | /* Process all hash subnodes of the component image node */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2744 | for (ndepth = 0, noffset = fdt_next_node(fit, image_noffset, &ndepth); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2745 | (noffset >= 0) && (ndepth > 0); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2746 | noffset = fdt_next_node(fit, noffset, &ndepth)) { |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2747 | if (ndepth == 1) { |
| 2748 | /* Direct child node of the component image node */ |
| 2749 | |
| 2750 | /* |
| 2751 | * Check subnode name, must be equal to "hash". |
| 2752 | * Multiple hash nodes require unique unit node |
| 2753 | * names, e.g. hash@1, hash@2, etc. |
| 2754 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2755 | if (strncmp(fit_get_name(fit, noffset, NULL), |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2756 | FIT_HASH_NODENAME, |
| 2757 | strlen(FIT_HASH_NODENAME)) != 0) |
| 2758 | continue; |
| 2759 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2760 | if (fit_image_hash_get_algo(fit, noffset, &algo)) { |
Bartlomiej Sieka | 919f550 | 2008-09-09 12:58:15 +0200 | [diff] [blame] | 2761 | err_msg = " error!\nCan't get hash algo " |
| 2762 | "property"; |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2763 | goto error; |
| 2764 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2765 | printf("%s", algo); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2766 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2767 | if (fit_image_hash_get_value(fit, noffset, &fit_value, |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2768 | &fit_value_len)) { |
Bartlomiej Sieka | 919f550 | 2008-09-09 12:58:15 +0200 | [diff] [blame] | 2769 | err_msg = " error!\nCan't get hash value " |
| 2770 | "property"; |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2771 | goto error; |
| 2772 | } |
| 2773 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2774 | if (calculate_hash(data, size, algo, value, |
| 2775 | &value_len)) { |
| 2776 | err_msg = " error!\n" |
| 2777 | "Unsupported hash algorithm"; |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2778 | goto error; |
| 2779 | } |
| 2780 | |
| 2781 | if (value_len != fit_value_len) { |
Bartlomiej Sieka | 919f550 | 2008-09-09 12:58:15 +0200 | [diff] [blame] | 2782 | err_msg = " error !\nBad hash value len"; |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2783 | goto error; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2784 | } else if (memcmp(value, fit_value, value_len) != 0) { |
Bartlomiej Sieka | 919f550 | 2008-09-09 12:58:15 +0200 | [diff] [blame] | 2785 | err_msg = " error!\nBad hash value"; |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2786 | goto error; |
| 2787 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2788 | printf("+ "); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2789 | } |
| 2790 | } |
| 2791 | |
| 2792 | return 1; |
| 2793 | |
| 2794 | error: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2795 | printf("%s for '%s' hash node in '%s' image node\n", |
| 2796 | err_msg, fit_get_name(fit, noffset, NULL), |
| 2797 | fit_get_name(fit, image_noffset, NULL)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2798 | return 0; |
| 2799 | } |
| 2800 | |
| 2801 | /** |
Bartlomiej Sieka | 919f550 | 2008-09-09 12:58:15 +0200 | [diff] [blame] | 2802 | * fit_all_image_check_hashes - verify data intergity for all images |
| 2803 | * @fit: pointer to the FIT format image header |
| 2804 | * |
| 2805 | * fit_all_image_check_hashes() goes over all images in the FIT and |
| 2806 | * for every images checks if all it's hashes are valid. |
| 2807 | * |
| 2808 | * returns: |
| 2809 | * 1, if all hashes of all images are valid |
| 2810 | * 0, otherwise (or on error) |
| 2811 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2812 | int fit_all_image_check_hashes(const void *fit) |
Bartlomiej Sieka | 919f550 | 2008-09-09 12:58:15 +0200 | [diff] [blame] | 2813 | { |
| 2814 | int images_noffset; |
| 2815 | int noffset; |
| 2816 | int ndepth; |
| 2817 | int count; |
| 2818 | |
| 2819 | /* Find images parent node offset */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2820 | images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); |
Bartlomiej Sieka | 919f550 | 2008-09-09 12:58:15 +0200 | [diff] [blame] | 2821 | if (images_noffset < 0) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2822 | printf("Can't find images parent node '%s' (%s)\n", |
| 2823 | FIT_IMAGES_PATH, fdt_strerror(images_noffset)); |
Bartlomiej Sieka | 919f550 | 2008-09-09 12:58:15 +0200 | [diff] [blame] | 2824 | return 0; |
| 2825 | } |
| 2826 | |
| 2827 | /* Process all image subnodes, check hashes for each */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2828 | printf("## Checking hash(es) for FIT Image at %08lx ...\n", |
Bartlomiej Sieka | 919f550 | 2008-09-09 12:58:15 +0200 | [diff] [blame] | 2829 | (ulong)fit); |
| 2830 | for (ndepth = 0, count = 0, |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2831 | noffset = fdt_next_node(fit, images_noffset, &ndepth); |
Bartlomiej Sieka | 919f550 | 2008-09-09 12:58:15 +0200 | [diff] [blame] | 2832 | (noffset >= 0) && (ndepth > 0); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2833 | noffset = fdt_next_node(fit, noffset, &ndepth)) { |
Bartlomiej Sieka | 919f550 | 2008-09-09 12:58:15 +0200 | [diff] [blame] | 2834 | if (ndepth == 1) { |
| 2835 | /* |
| 2836 | * Direct child node of the images parent node, |
| 2837 | * i.e. component image node. |
| 2838 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2839 | printf(" Hash(es) for Image %u (%s): ", count++, |
| 2840 | fit_get_name(fit, noffset, NULL)); |
Bartlomiej Sieka | 919f550 | 2008-09-09 12:58:15 +0200 | [diff] [blame] | 2841 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2842 | if (!fit_image_check_hashes(fit, noffset)) |
Bartlomiej Sieka | 919f550 | 2008-09-09 12:58:15 +0200 | [diff] [blame] | 2843 | return 0; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2844 | printf("\n"); |
Bartlomiej Sieka | 919f550 | 2008-09-09 12:58:15 +0200 | [diff] [blame] | 2845 | } |
| 2846 | } |
| 2847 | return 1; |
| 2848 | } |
| 2849 | |
| 2850 | /** |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2851 | * fit_image_check_os - check whether image node is of a given os type |
| 2852 | * @fit: pointer to the FIT format image header |
| 2853 | * @noffset: component image node offset |
| 2854 | * @os: requested image os |
| 2855 | * |
| 2856 | * fit_image_check_os() reads image os property and compares its numeric |
| 2857 | * id with the requested os. Comparison result is returned to the caller. |
| 2858 | * |
| 2859 | * returns: |
| 2860 | * 1 if image is of given os type |
| 2861 | * 0 otherwise (or on error) |
| 2862 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2863 | int fit_image_check_os(const void *fit, int noffset, uint8_t os) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2864 | { |
| 2865 | uint8_t image_os; |
| 2866 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2867 | if (fit_image_get_os(fit, noffset, &image_os)) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2868 | return 0; |
| 2869 | return (os == image_os); |
| 2870 | } |
| 2871 | |
| 2872 | /** |
| 2873 | * fit_image_check_arch - check whether image node is of a given arch |
| 2874 | * @fit: pointer to the FIT format image header |
| 2875 | * @noffset: component image node offset |
| 2876 | * @arch: requested imagearch |
| 2877 | * |
| 2878 | * fit_image_check_arch() reads image arch property and compares its numeric |
| 2879 | * id with the requested arch. Comparison result is returned to the caller. |
| 2880 | * |
| 2881 | * returns: |
| 2882 | * 1 if image is of given arch |
| 2883 | * 0 otherwise (or on error) |
| 2884 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2885 | int fit_image_check_arch(const void *fit, int noffset, uint8_t arch) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2886 | { |
| 2887 | uint8_t image_arch; |
| 2888 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2889 | if (fit_image_get_arch(fit, noffset, &image_arch)) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2890 | return 0; |
| 2891 | return (arch == image_arch); |
| 2892 | } |
| 2893 | |
| 2894 | /** |
| 2895 | * fit_image_check_type - check whether image node is of a given type |
| 2896 | * @fit: pointer to the FIT format image header |
| 2897 | * @noffset: component image node offset |
| 2898 | * @type: requested image type |
| 2899 | * |
| 2900 | * fit_image_check_type() reads image type property and compares its numeric |
| 2901 | * id with the requested type. Comparison result is returned to the caller. |
| 2902 | * |
| 2903 | * returns: |
| 2904 | * 1 if image is of given type |
| 2905 | * 0 otherwise (or on error) |
| 2906 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2907 | int fit_image_check_type(const void *fit, int noffset, uint8_t type) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2908 | { |
| 2909 | uint8_t image_type; |
| 2910 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2911 | if (fit_image_get_type(fit, noffset, &image_type)) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2912 | return 0; |
| 2913 | return (type == image_type); |
| 2914 | } |
| 2915 | |
| 2916 | /** |
| 2917 | * fit_image_check_comp - check whether image node uses given compression |
| 2918 | * @fit: pointer to the FIT format image header |
| 2919 | * @noffset: component image node offset |
| 2920 | * @comp: requested image compression type |
| 2921 | * |
| 2922 | * fit_image_check_comp() reads image compression property and compares its |
| 2923 | * numeric id with the requested compression type. Comparison result is |
| 2924 | * returned to the caller. |
| 2925 | * |
| 2926 | * returns: |
| 2927 | * 1 if image uses requested compression |
| 2928 | * 0 otherwise (or on error) |
| 2929 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2930 | int fit_image_check_comp(const void *fit, int noffset, uint8_t comp) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2931 | { |
| 2932 | uint8_t image_comp; |
| 2933 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2934 | if (fit_image_get_comp(fit, noffset, &image_comp)) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2935 | return 0; |
| 2936 | return (comp == image_comp); |
| 2937 | } |
| 2938 | |
| 2939 | /** |
| 2940 | * fit_check_format - sanity check FIT image format |
| 2941 | * @fit: pointer to the FIT format image header |
| 2942 | * |
| 2943 | * fit_check_format() runs a basic sanity FIT image verification. |
| 2944 | * Routine checks for mandatory properties, nodes, etc. |
| 2945 | * |
| 2946 | * returns: |
| 2947 | * 1, on success |
| 2948 | * 0, on failure |
| 2949 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2950 | int fit_check_format(const void *fit) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2951 | { |
| 2952 | /* mandatory / node 'description' property */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2953 | if (fdt_getprop(fit, 0, FIT_DESC_PROP, NULL) == NULL) { |
| 2954 | debug("Wrong FIT format: no description\n"); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2955 | return 0; |
| 2956 | } |
| 2957 | |
| 2958 | #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) |
| 2959 | /* mandatory / node 'timestamp' property */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2960 | if (fdt_getprop(fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) { |
| 2961 | debug("Wrong FIT format: no timestamp\n"); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2962 | return 0; |
| 2963 | } |
| 2964 | #endif |
| 2965 | |
| 2966 | /* mandatory subimages parent '/images' node */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2967 | if (fdt_path_offset(fit, FIT_IMAGES_PATH) < 0) { |
| 2968 | debug("Wrong FIT format: no images parent node\n"); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2969 | return 0; |
| 2970 | } |
| 2971 | |
| 2972 | return 1; |
| 2973 | } |
| 2974 | |
| 2975 | /** |
| 2976 | * fit_conf_get_node - get node offset for configuration of a given unit name |
| 2977 | * @fit: pointer to the FIT format image header |
| 2978 | * @conf_uname: configuration node unit name |
| 2979 | * |
| 2980 | * fit_conf_get_node() finds a configuration (withing the '/configurations' |
| 2981 | * parant node) of a provided unit name. If configuration is found its node offset |
| 2982 | * is returned to the caller. |
| 2983 | * |
| 2984 | * When NULL is provided in second argument fit_conf_get_node() will search |
| 2985 | * for a default configuration node instead. Default configuration node unit name |
| 2986 | * is retrived from FIT_DEFAULT_PROP property of the '/configurations' node. |
| 2987 | * |
| 2988 | * returns: |
| 2989 | * configuration node offset when found (>=0) |
| 2990 | * negative number on failure (FDT_ERR_* code) |
| 2991 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2992 | int fit_conf_get_node(const void *fit, const char *conf_uname) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2993 | { |
| 2994 | int noffset, confs_noffset; |
| 2995 | int len; |
| 2996 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2997 | confs_noffset = fdt_path_offset(fit, FIT_CONFS_PATH); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2998 | if (confs_noffset < 0) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 2999 | debug("Can't find configurations parent node '%s' (%s)\n", |
| 3000 | FIT_CONFS_PATH, fdt_strerror(confs_noffset)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3001 | return confs_noffset; |
| 3002 | } |
| 3003 | |
| 3004 | if (conf_uname == NULL) { |
| 3005 | /* get configuration unit name from the default property */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3006 | debug("No configuration specified, trying default...\n"); |
| 3007 | conf_uname = (char *)fdt_getprop(fit, confs_noffset, |
| 3008 | FIT_DEFAULT_PROP, &len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3009 | if (conf_uname == NULL) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3010 | fit_get_debug(fit, confs_noffset, FIT_DEFAULT_PROP, |
| 3011 | len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3012 | return len; |
| 3013 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3014 | debug("Found default configuration: '%s'\n", conf_uname); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3015 | } |
| 3016 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3017 | noffset = fdt_subnode_offset(fit, confs_noffset, conf_uname); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3018 | if (noffset < 0) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3019 | debug("Can't get node offset for configuration unit name: " |
| 3020 | "'%s' (%s)\n", |
| 3021 | conf_uname, fdt_strerror(noffset)); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3022 | } |
| 3023 | |
| 3024 | return noffset; |
| 3025 | } |
| 3026 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3027 | static int __fit_conf_get_prop_node(const void *fit, int noffset, |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3028 | const char *prop_name) |
| 3029 | { |
| 3030 | char *uname; |
| 3031 | int len; |
| 3032 | |
| 3033 | /* get kernel image unit name from configuration kernel property */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3034 | uname = (char *)fdt_getprop(fit, noffset, prop_name, &len); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3035 | if (uname == NULL) |
| 3036 | return len; |
| 3037 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3038 | return fit_image_get_node(fit, uname); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3039 | } |
| 3040 | |
| 3041 | /** |
| 3042 | * fit_conf_get_kernel_node - get kernel image node offset that corresponds to |
| 3043 | * a given configuration |
| 3044 | * @fit: pointer to the FIT format image header |
| 3045 | * @noffset: configuration node offset |
| 3046 | * |
| 3047 | * fit_conf_get_kernel_node() retrives kernel image node unit name from |
| 3048 | * configuration FIT_KERNEL_PROP property and translates it to the node |
| 3049 | * offset. |
| 3050 | * |
| 3051 | * returns: |
| 3052 | * image node offset when found (>=0) |
| 3053 | * negative number on failure (FDT_ERR_* code) |
| 3054 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3055 | int fit_conf_get_kernel_node(const void *fit, int noffset) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3056 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3057 | return __fit_conf_get_prop_node(fit, noffset, FIT_KERNEL_PROP); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | /** |
| 3061 | * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to |
| 3062 | * a given configuration |
| 3063 | * @fit: pointer to the FIT format image header |
| 3064 | * @noffset: configuration node offset |
| 3065 | * |
| 3066 | * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from |
| 3067 | * configuration FIT_KERNEL_PROP property and translates it to the node |
| 3068 | * offset. |
| 3069 | * |
| 3070 | * returns: |
| 3071 | * image node offset when found (>=0) |
| 3072 | * negative number on failure (FDT_ERR_* code) |
| 3073 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3074 | int fit_conf_get_ramdisk_node(const void *fit, int noffset) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3075 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3076 | return __fit_conf_get_prop_node(fit, noffset, FIT_RAMDISK_PROP); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3077 | } |
| 3078 | |
| 3079 | /** |
| 3080 | * fit_conf_get_fdt_node - get fdt image node offset that corresponds to |
| 3081 | * a given configuration |
| 3082 | * @fit: pointer to the FIT format image header |
| 3083 | * @noffset: configuration node offset |
| 3084 | * |
| 3085 | * fit_conf_get_fdt_node() retrives fdt image node unit name from |
| 3086 | * configuration FIT_KERNEL_PROP property and translates it to the node |
| 3087 | * offset. |
| 3088 | * |
| 3089 | * returns: |
| 3090 | * image node offset when found (>=0) |
| 3091 | * negative number on failure (FDT_ERR_* code) |
| 3092 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3093 | int fit_conf_get_fdt_node(const void *fit, int noffset) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3094 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3095 | return __fit_conf_get_prop_node(fit, noffset, FIT_FDT_PROP); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3096 | } |
| 3097 | |
| 3098 | /** |
| 3099 | * fit_conf_print - prints out the FIT configuration details |
| 3100 | * @fit: pointer to the FIT format image header |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 3101 | * @noffset: offset of the configuration node |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3102 | * @p: pointer to prefix string |
| 3103 | * |
| 3104 | * fit_conf_print() lists all mandatory properies for the processed |
| 3105 | * configuration node. |
| 3106 | * |
| 3107 | * returns: |
| 3108 | * no returned results |
| 3109 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3110 | void fit_conf_print(const void *fit, int noffset, const char *p) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3111 | { |
| 3112 | char *desc; |
| 3113 | char *uname; |
| 3114 | int ret; |
| 3115 | |
| 3116 | /* Mandatory properties */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3117 | ret = fit_get_desc(fit, noffset, &desc); |
| 3118 | printf("%s Description: ", p); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3119 | if (ret) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3120 | printf("unavailable\n"); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3121 | else |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3122 | printf("%s\n", desc); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3123 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3124 | uname = (char *)fdt_getprop(fit, noffset, FIT_KERNEL_PROP, NULL); |
| 3125 | printf("%s Kernel: ", p); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3126 | if (uname == NULL) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3127 | printf("unavailable\n"); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3128 | else |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3129 | printf("%s\n", uname); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3130 | |
| 3131 | /* Optional properties */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3132 | uname = (char *)fdt_getprop(fit, noffset, FIT_RAMDISK_PROP, NULL); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3133 | if (uname) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3134 | printf("%s Init Ramdisk: %s\n", p, uname); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3135 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3136 | uname = (char *)fdt_getprop(fit, noffset, FIT_FDT_PROP, NULL); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3137 | if (uname) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3138 | printf("%s FDT: %s\n", p, uname); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3139 | } |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 3140 | |
| 3141 | /** |
| 3142 | * fit_check_ramdisk - verify FIT format ramdisk subimage |
| 3143 | * @fit_hdr: pointer to the FIT ramdisk header |
| 3144 | * @rd_noffset: ramdisk subimage node offset within FIT image |
| 3145 | * @arch: requested ramdisk image architecture type |
| 3146 | * @verify: data CRC verification flag |
| 3147 | * |
| 3148 | * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from |
| 3149 | * specified FIT image. |
| 3150 | * |
| 3151 | * returns: |
| 3152 | * 1, on success |
| 3153 | * 0, on failure |
| 3154 | */ |
| 3155 | #ifndef USE_HOSTCC |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3156 | static int fit_check_ramdisk(const void *fit, int rd_noffset, uint8_t arch, |
| 3157 | int verify) |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 3158 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3159 | fit_image_print(fit, rd_noffset, " "); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 3160 | |
| 3161 | if (verify) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3162 | puts(" Verifying Hash Integrity ... "); |
| 3163 | if (!fit_image_check_hashes(fit, rd_noffset)) { |
| 3164 | puts("Bad Data Hash\n"); |
| 3165 | show_boot_progress(-125); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 3166 | return 0; |
| 3167 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3168 | puts("OK\n"); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 3169 | } |
| 3170 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3171 | show_boot_progress(126); |
| 3172 | if (!fit_image_check_os(fit, rd_noffset, IH_OS_LINUX) || |
| 3173 | !fit_image_check_arch(fit, rd_noffset, arch) || |
| 3174 | !fit_image_check_type(fit, rd_noffset, IH_TYPE_RAMDISK)) { |
| 3175 | printf("No Linux %s Ramdisk Image\n", |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 3176 | genimg_get_arch_name(arch)); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3177 | show_boot_progress(-126); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 3178 | return 0; |
| 3179 | } |
| 3180 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 3181 | show_boot_progress(127); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 3182 | return 1; |
| 3183 | } |
| 3184 | #endif /* USE_HOSTCC */ |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 3185 | #endif /* CONFIG_FIT */ |