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