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