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