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