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 | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 26 | |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 27 | #ifndef USE_HOSTCC |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 28 | #include <common.h> |
| 29 | #include <watchdog.h> |
| 30 | |
| 31 | #ifdef CONFIG_SHOW_BOOT_PROGRESS |
| 32 | #include <status_led.h> |
| 33 | #endif |
| 34 | |
| 35 | #ifdef CONFIG_HAS_DATAFLASH |
| 36 | #include <dataflash.h> |
| 37 | #endif |
| 38 | |
Marian Balakowicz | 1b5605c | 2008-05-07 13:10:04 +0200 | [diff] [blame^] | 39 | #ifdef CONFIG_LOGBUFFER |
| 40 | #include <logbuff.h> |
| 41 | #endif |
| 42 | |
Marian Balakowicz | 2242f53 | 2008-02-21 17:27:41 +0100 | [diff] [blame] | 43 | #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) |
| 44 | #include <rtc.h> |
| 45 | #endif |
| 46 | |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 47 | #include <image.h> |
| 48 | |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [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 <fdt.h> |
| 51 | #include <libfdt.h> |
| 52 | #include <fdt_support.h> |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 53 | #endif |
| 54 | |
| 55 | #if defined(CONFIG_FIT) |
Andy Fleming | 20a14a4 | 2008-04-02 16:19:07 -0500 | [diff] [blame] | 56 | #include <u-boot/md5.h> |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 57 | #include <sha1.h> |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 58 | |
| 59 | static int fit_check_ramdisk (const void *fit, int os_noffset, |
| 60 | uint8_t arch, int verify); |
Marian Balakowicz | fff888a1 | 2008-02-21 17:20:19 +0100 | [diff] [blame] | 61 | #endif |
| 62 | |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 63 | #ifdef CONFIG_CMD_BDI |
| 64 | extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
| 65 | #endif |
| 66 | |
| 67 | DECLARE_GLOBAL_DATA_PTR; |
Marian Balakowicz | 8a5ea3e | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 68 | |
Marian Balakowicz | d985c84 | 2008-03-12 10:14:38 +0100 | [diff] [blame] | 69 | static image_header_t* image_get_ramdisk (ulong rd_addr, uint8_t arch, |
| 70 | int verify); |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 71 | #else |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 72 | #include "mkimage.h" |
Andy Fleming | 20a14a4 | 2008-04-02 16:19:07 -0500 | [diff] [blame] | 73 | #include <u-boot/md5.h> |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 74 | #include <time.h> |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 75 | #include <image.h> |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 76 | #endif /* !USE_HOSTCC*/ |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 77 | |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 78 | typedef struct table_entry { |
| 79 | int id; /* as defined in image.h */ |
| 80 | char *sname; /* short (input) name */ |
| 81 | char *lname; /* long (output) name */ |
| 82 | } table_entry_t; |
| 83 | |
| 84 | static table_entry_t uimage_arch[] = { |
| 85 | { IH_ARCH_INVALID, NULL, "Invalid ARCH", }, |
| 86 | { IH_ARCH_ALPHA, "alpha", "Alpha", }, |
| 87 | { IH_ARCH_ARM, "arm", "ARM", }, |
| 88 | { IH_ARCH_I386, "x86", "Intel x86", }, |
| 89 | { IH_ARCH_IA64, "ia64", "IA64", }, |
| 90 | { IH_ARCH_M68K, "m68k", "M68K", }, |
| 91 | { IH_ARCH_MICROBLAZE, "microblaze", "MicroBlaze", }, |
| 92 | { IH_ARCH_MIPS, "mips", "MIPS", }, |
| 93 | { IH_ARCH_MIPS64, "mips64", "MIPS 64 Bit", }, |
| 94 | { IH_ARCH_NIOS, "nios", "NIOS", }, |
| 95 | { IH_ARCH_NIOS2, "nios2", "NIOS II", }, |
Grant Erickson | e419e12 | 2008-05-04 16:45:01 -0700 | [diff] [blame] | 96 | { IH_ARCH_PPC, "powerpc", "PowerPC", }, |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 97 | { IH_ARCH_PPC, "ppc", "PowerPC", }, |
| 98 | { IH_ARCH_S390, "s390", "IBM S390", }, |
| 99 | { IH_ARCH_SH, "sh", "SuperH", }, |
| 100 | { IH_ARCH_SPARC, "sparc", "SPARC", }, |
| 101 | { IH_ARCH_SPARC64, "sparc64", "SPARC 64 Bit", }, |
| 102 | { IH_ARCH_BLACKFIN, "blackfin", "Blackfin", }, |
| 103 | { IH_ARCH_AVR32, "avr32", "AVR32", }, |
| 104 | { -1, "", "", }, |
| 105 | }; |
| 106 | |
| 107 | static table_entry_t uimage_os[] = { |
| 108 | { IH_OS_INVALID, NULL, "Invalid OS", }, |
| 109 | #if defined(CONFIG_ARTOS) || defined(USE_HOSTCC) |
| 110 | { IH_OS_ARTOS, "artos", "ARTOS", }, |
| 111 | #endif |
| 112 | { IH_OS_LINUX, "linux", "Linux", }, |
| 113 | #if defined(CONFIG_LYNXKDI) || defined(USE_HOSTCC) |
| 114 | { IH_OS_LYNXOS, "lynxos", "LynxOS", }, |
| 115 | #endif |
| 116 | { IH_OS_NETBSD, "netbsd", "NetBSD", }, |
| 117 | { IH_OS_RTEMS, "rtems", "RTEMS", }, |
| 118 | { IH_OS_U_BOOT, "u-boot", "U-Boot", }, |
| 119 | #if defined(CONFIG_CMD_ELF) || defined(USE_HOSTCC) |
| 120 | { IH_OS_QNX, "qnx", "QNX", }, |
| 121 | { IH_OS_VXWORKS, "vxworks", "VxWorks", }, |
| 122 | #endif |
| 123 | #ifdef USE_HOSTCC |
| 124 | { IH_OS_4_4BSD, "4_4bsd", "4_4BSD", }, |
| 125 | { IH_OS_DELL, "dell", "Dell", }, |
| 126 | { IH_OS_ESIX, "esix", "Esix", }, |
| 127 | { IH_OS_FREEBSD, "freebsd", "FreeBSD", }, |
| 128 | { IH_OS_IRIX, "irix", "Irix", }, |
| 129 | { IH_OS_NCR, "ncr", "NCR", }, |
| 130 | { IH_OS_OPENBSD, "openbsd", "OpenBSD", }, |
| 131 | { IH_OS_PSOS, "psos", "pSOS", }, |
| 132 | { IH_OS_SCO, "sco", "SCO", }, |
| 133 | { IH_OS_SOLARIS, "solaris", "Solaris", }, |
| 134 | { IH_OS_SVR4, "svr4", "SVR4", }, |
| 135 | #endif |
| 136 | { -1, "", "", }, |
| 137 | }; |
| 138 | |
| 139 | static table_entry_t uimage_type[] = { |
| 140 | { IH_TYPE_INVALID, NULL, "Invalid Image", }, |
| 141 | { IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image", }, |
| 142 | { IH_TYPE_FIRMWARE, "firmware", "Firmware", }, |
| 143 | { IH_TYPE_KERNEL, "kernel", "Kernel Image", }, |
| 144 | { IH_TYPE_MULTI, "multi", "Multi-File Image", }, |
| 145 | { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", }, |
| 146 | { IH_TYPE_SCRIPT, "script", "Script", }, |
| 147 | { IH_TYPE_STANDALONE, "standalone", "Standalone Program", }, |
| 148 | { IH_TYPE_FLATDT, "flat_dt", "Flat Device Tree", }, |
| 149 | { -1, "", "", }, |
| 150 | }; |
| 151 | |
| 152 | static table_entry_t uimage_comp[] = { |
| 153 | { IH_COMP_NONE, "none", "uncompressed", }, |
| 154 | { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", }, |
| 155 | { IH_COMP_GZIP, "gzip", "gzip compressed", }, |
| 156 | { -1, "", "", }, |
| 157 | }; |
| 158 | |
Mike Frysinger | 89cdab7 | 2008-03-31 11:02:01 -0400 | [diff] [blame] | 159 | uint32_t crc32 (uint32_t, const unsigned char *, uint); |
Bartlomiej Sieka | 7590378 | 2008-04-25 13:54:02 +0200 | [diff] [blame] | 160 | uint32_t crc32_wd (uint32_t, const unsigned char *, uint, uint); |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 161 | static void genimg_print_size (uint32_t size); |
| 162 | #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) |
| 163 | static void genimg_print_time (time_t timestamp); |
| 164 | #endif |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 165 | |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 166 | /*****************************************************************************/ |
| 167 | /* Legacy format routines */ |
| 168 | /*****************************************************************************/ |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 169 | int image_check_hcrc (image_header_t *hdr) |
| 170 | { |
| 171 | ulong hcrc; |
| 172 | ulong len = image_get_header_size (); |
| 173 | image_header_t header; |
| 174 | |
| 175 | /* Copy header so we can blank CRC field for re-calculation */ |
| 176 | memmove (&header, (char *)hdr, image_get_header_size ()); |
| 177 | image_set_hcrc (&header, 0); |
| 178 | |
| 179 | hcrc = crc32 (0, (unsigned char *)&header, len); |
| 180 | |
| 181 | return (hcrc == image_get_hcrc (hdr)); |
| 182 | } |
| 183 | |
| 184 | int image_check_dcrc (image_header_t *hdr) |
| 185 | { |
| 186 | ulong data = image_get_data (hdr); |
| 187 | ulong len = image_get_data_size (hdr); |
Bartlomiej Sieka | 7590378 | 2008-04-25 13:54:02 +0200 | [diff] [blame] | 188 | ulong dcrc = crc32_wd (0, (unsigned char *)data, len, CHUNKSZ_CRC32); |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 189 | |
| 190 | return (dcrc == image_get_dcrc (hdr)); |
| 191 | } |
| 192 | |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 193 | |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 194 | /** |
| 195 | * image_multi_count - get component (sub-image) count |
| 196 | * @hdr: pointer to the header of the multi component image |
| 197 | * |
| 198 | * image_multi_count() returns number of components in a multi |
| 199 | * component image. |
| 200 | * |
| 201 | * Note: no checking of the image type is done, caller must pass |
| 202 | * a valid multi component image. |
| 203 | * |
| 204 | * returns: |
| 205 | * number of components |
| 206 | */ |
| 207 | ulong image_multi_count (image_header_t *hdr) |
| 208 | { |
| 209 | ulong i, count = 0; |
Marian Balakowicz | df6f1b8 | 2008-02-29 16:00:06 +0100 | [diff] [blame] | 210 | uint32_t *size; |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 211 | |
| 212 | /* get start of the image payload, which in case of multi |
| 213 | * component images that points to a table of component sizes */ |
Marian Balakowicz | df6f1b8 | 2008-02-29 16:00:06 +0100 | [diff] [blame] | 214 | size = (uint32_t *)image_get_data (hdr); |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 215 | |
| 216 | /* count non empty slots */ |
| 217 | for (i = 0; size[i]; ++i) |
| 218 | count++; |
| 219 | |
| 220 | return count; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * image_multi_getimg - get component data address and size |
| 225 | * @hdr: pointer to the header of the multi component image |
| 226 | * @idx: index of the requested component |
| 227 | * @data: pointer to a ulong variable, will hold component data address |
| 228 | * @len: pointer to a ulong variable, will hold component size |
| 229 | * |
| 230 | * image_multi_getimg() returns size and data address for the requested |
| 231 | * component in a multi component image. |
| 232 | * |
| 233 | * Note: no checking of the image type is done, caller must pass |
| 234 | * a valid multi component image. |
| 235 | * |
| 236 | * returns: |
| 237 | * data address and size of the component, if idx is valid |
| 238 | * 0 in data and len, if idx is out of range |
| 239 | */ |
| 240 | void image_multi_getimg (image_header_t *hdr, ulong idx, |
| 241 | ulong *data, ulong *len) |
| 242 | { |
| 243 | int i; |
Marian Balakowicz | df6f1b8 | 2008-02-29 16:00:06 +0100 | [diff] [blame] | 244 | uint32_t *size; |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 245 | ulong offset, tail, count, img_data; |
| 246 | |
| 247 | /* get number of component */ |
| 248 | count = image_multi_count (hdr); |
| 249 | |
| 250 | /* get start of the image payload, which in case of multi |
| 251 | * component images that points to a table of component sizes */ |
Marian Balakowicz | df6f1b8 | 2008-02-29 16:00:06 +0100 | [diff] [blame] | 252 | size = (uint32_t *)image_get_data (hdr); |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 253 | |
| 254 | /* get address of the proper component data start, which means |
| 255 | * skipping sizes table (add 1 for last, null entry) */ |
Marian Balakowicz | df6f1b8 | 2008-02-29 16:00:06 +0100 | [diff] [blame] | 256 | img_data = image_get_data (hdr) + (count + 1) * sizeof (uint32_t); |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 257 | |
| 258 | if (idx < count) { |
Marian Balakowicz | df6f1b8 | 2008-02-29 16:00:06 +0100 | [diff] [blame] | 259 | *len = uimage_to_cpu (size[idx]); |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 260 | offset = 0; |
| 261 | tail = 0; |
| 262 | |
| 263 | /* go over all indices preceding requested component idx */ |
| 264 | for (i = 0; i < idx; i++) { |
| 265 | /* add up i-th component size */ |
Marian Balakowicz | df6f1b8 | 2008-02-29 16:00:06 +0100 | [diff] [blame] | 266 | offset += uimage_to_cpu (size[i]); |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 267 | |
| 268 | /* add up alignment for i-th component */ |
Marian Balakowicz | df6f1b8 | 2008-02-29 16:00:06 +0100 | [diff] [blame] | 269 | tail += (4 - uimage_to_cpu (size[i]) % 4); |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | /* calculate idx-th component data address */ |
| 273 | *data = img_data + offset + tail; |
| 274 | } else { |
| 275 | *len = 0; |
| 276 | *data = 0; |
| 277 | } |
| 278 | } |
Marian Balakowicz | 42b73e8 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 279 | |
Marian Balakowicz | 2242f53 | 2008-02-21 17:27:41 +0100 | [diff] [blame] | 280 | static void image_print_type (image_header_t *hdr) |
| 281 | { |
| 282 | const char *os, *arch, *type, *comp; |
| 283 | |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 284 | os = genimg_get_os_name (image_get_os (hdr)); |
| 285 | arch = genimg_get_arch_name (image_get_arch (hdr)); |
| 286 | type = genimg_get_type_name (image_get_type (hdr)); |
| 287 | comp = genimg_get_comp_name (image_get_comp (hdr)); |
Marian Balakowicz | 2242f53 | 2008-02-21 17:27:41 +0100 | [diff] [blame] | 288 | |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 289 | printf ("%s %s %s (%s)\n", arch, os, type, comp); |
Marian Balakowicz | 2242f53 | 2008-02-21 17:27:41 +0100 | [diff] [blame] | 290 | } |
| 291 | |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 292 | /** |
Bartlomiej Sieka | edbed24 | 2008-04-18 12:39:23 +0200 | [diff] [blame] | 293 | * image_print_contents - prints out the contents of the legacy format image |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 294 | * @hdr: pointer to the legacy format image header |
| 295 | * @p: pointer to prefix string |
| 296 | * |
Bartlomiej Sieka | edbed24 | 2008-04-18 12:39:23 +0200 | [diff] [blame] | 297 | * image_print_contents() formats a multi line legacy image contents description. |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 298 | * The routine prints out all header fields followed by the size/offset data |
| 299 | * for MULTI/SCRIPT images. |
| 300 | * |
| 301 | * returns: |
| 302 | * no returned results |
| 303 | */ |
Bartlomiej Sieka | edbed24 | 2008-04-18 12:39:23 +0200 | [diff] [blame] | 304 | void image_print_contents (image_header_t *hdr) |
Marian Balakowicz | 2242f53 | 2008-02-21 17:27:41 +0100 | [diff] [blame] | 305 | { |
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 | |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 314 | printf ("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name (hdr)); |
| 315 | #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) |
| 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 |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 319 | printf ("%sImage Type: ", p); |
Marian Balakowicz | 2242f53 | 2008-02-21 17:27:41 +0100 | [diff] [blame] | 320 | image_print_type (hdr); |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 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 | |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [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; |
| 330 | ulong count = image_multi_count (hdr); |
| 331 | |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [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++) { |
| 334 | image_multi_getimg (hdr, i, &data, &len); |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 335 | |
| 336 | printf ("%s Image %d: ", p, i); |
| 337 | genimg_print_size (len); |
| 338 | |
| 339 | if (image_check_type (hdr, IH_TYPE_SCRIPT) && i > 0) { |
| 340 | /* |
| 341 | * the user may need to know offsets |
| 342 | * if planning to do something with |
| 343 | * multiple files |
| 344 | */ |
| 345 | printf ("%s Offset = 0x%08lx\n", p, data); |
| 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 | */ |
Marian Balakowicz | d985c84 | 2008-03-12 10:14:38 +0100 | [diff] [blame] | 371 | static image_header_t* image_get_ramdisk (ulong rd_addr, uint8_t arch, |
| 372 | int verify) |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 373 | { |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 374 | image_header_t *rd_hdr = (image_header_t *)rd_addr; |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 375 | |
| 376 | if (!image_check_magic (rd_hdr)) { |
| 377 | puts ("Bad Magic Number\n"); |
| 378 | show_boot_progress (-10); |
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 | |
| 382 | if (!image_check_hcrc (rd_hdr)) { |
| 383 | puts ("Bad Header Checksum\n"); |
| 384 | show_boot_progress (-11); |
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 | |
| 388 | show_boot_progress (10); |
Marian Balakowicz | 2242f53 | 2008-02-21 17:27:41 +0100 | [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 ... "); |
Bartlomiej Sieka | 7590378 | 2008-04-25 13:54:02 +0200 | [diff] [blame] | 393 | if (!image_check_dcrc (rd_hdr)) { |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 394 | puts ("Bad Data CRC\n"); |
| 395 | show_boot_progress (-12); |
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 | |
| 401 | show_boot_progress (11); |
| 402 | |
| 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)); |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 408 | show_boot_progress (-13); |
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 |
Bartlomiej Sieka | edbed24 | 2008-04-18 12:39:23 +0200 | [diff] [blame] | 420 | int getenv_yesno (char *var) |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 421 | { |
Bartlomiej Sieka | edbed24 | 2008-04-18 12:39:23 +0200 | [diff] [blame] | 422 | char *s = getenv (var); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 423 | return (s && (*s == 'n')) ? 0 : 1; |
| 424 | } |
| 425 | |
| 426 | ulong getenv_bootm_low(void) |
| 427 | { |
| 428 | char *s = getenv ("bootm_low"); |
| 429 | if (s) { |
| 430 | ulong tmp = simple_strtoul (s, NULL, 16); |
| 431 | return tmp; |
| 432 | } |
| 433 | |
Marian Balakowicz | afe45c8 | 2008-03-12 12:14:15 +0100 | [diff] [blame] | 434 | #if defined(CFG_SDRAM_BASE) |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 435 | return CFG_SDRAM_BASE; |
Marian Balakowicz | afe45c8 | 2008-03-12 12:14:15 +0100 | [diff] [blame] | 436 | #elif defined(CONFIG_ARM) |
| 437 | return gd->bd->bi_dram[0].start; |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 438 | #else |
| 439 | return 0; |
| 440 | #endif |
| 441 | } |
| 442 | |
| 443 | ulong getenv_bootm_size(void) |
| 444 | { |
| 445 | char *s = getenv ("bootm_size"); |
| 446 | if (s) { |
| 447 | ulong tmp = simple_strtoul (s, NULL, 16); |
| 448 | return tmp; |
| 449 | } |
| 450 | |
Marian Balakowicz | afe45c8 | 2008-03-12 12:14:15 +0100 | [diff] [blame] | 451 | #if defined(CONFIG_ARM) |
| 452 | return gd->bd->bi_dram[0].size; |
| 453 | #else |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 454 | return gd->bd->bi_memsize; |
Marian Balakowicz | afe45c8 | 2008-03-12 12:14:15 +0100 | [diff] [blame] | 455 | #endif |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | void memmove_wd (void *to, void *from, size_t len, ulong chunksz) |
| 459 | { |
| 460 | #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) |
| 461 | while (len > 0) { |
| 462 | size_t tail = (len > chunksz) ? chunksz : len; |
| 463 | WATCHDOG_RESET (); |
| 464 | memmove (to, from, tail); |
| 465 | to += tail; |
| 466 | from += tail; |
| 467 | len -= tail; |
| 468 | } |
| 469 | #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */ |
| 470 | memmove (to, from, len); |
| 471 | #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */ |
| 472 | } |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 473 | #endif /* !USE_HOSTCC */ |
| 474 | |
| 475 | static void genimg_print_size (uint32_t size) |
| 476 | { |
| 477 | #ifndef USE_HOSTCC |
| 478 | printf ("%d Bytes = ", size); |
| 479 | print_size (size, "\n"); |
| 480 | #else |
| 481 | printf ("%d Bytes = %.2f kB = %.2f MB\n", |
| 482 | size, (double)size / 1.024e3, |
| 483 | (double)size / 1.048576e6); |
| 484 | #endif |
| 485 | } |
| 486 | |
| 487 | #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) |
| 488 | static void genimg_print_time (time_t timestamp) |
| 489 | { |
| 490 | #ifndef USE_HOSTCC |
| 491 | struct rtc_time tm; |
| 492 | |
| 493 | to_tm (timestamp, &tm); |
| 494 | printf ("%4d-%02d-%02d %2d:%02d:%02d UTC\n", |
| 495 | tm.tm_year, tm.tm_mon, tm.tm_mday, |
| 496 | tm.tm_hour, tm.tm_min, tm.tm_sec); |
| 497 | #else |
| 498 | printf ("%s", ctime(×tamp)); |
| 499 | #endif |
| 500 | } |
| 501 | #endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */ |
| 502 | |
| 503 | /** |
| 504 | * get_table_entry_name - translate entry id to long name |
| 505 | * @table: pointer to a translation table for entries of a specific type |
| 506 | * @msg: message to be returned when translation fails |
| 507 | * @id: entry id to be translated |
| 508 | * |
| 509 | * get_table_entry_name() will go over translation table trying to find |
| 510 | * entry that matches given id. If matching entry is found, its long |
| 511 | * name is returned to the caller. |
| 512 | * |
| 513 | * returns: |
| 514 | * long entry name if translation succeeds |
| 515 | * msg otherwise |
| 516 | */ |
| 517 | static char *get_table_entry_name (table_entry_t *table, char *msg, int id) |
| 518 | { |
| 519 | for (; table->id >= 0; ++table) { |
| 520 | if (table->id == id) |
| 521 | return (table->lname); |
| 522 | } |
| 523 | return (msg); |
| 524 | } |
| 525 | |
| 526 | const char *genimg_get_os_name (uint8_t os) |
| 527 | { |
| 528 | return (get_table_entry_name (uimage_os, "Unknown OS", os)); |
| 529 | } |
| 530 | |
| 531 | const char *genimg_get_arch_name (uint8_t arch) |
| 532 | { |
| 533 | return (get_table_entry_name (uimage_arch, "Unknown Architecture", arch)); |
| 534 | } |
| 535 | |
| 536 | const char *genimg_get_type_name (uint8_t type) |
| 537 | { |
| 538 | return (get_table_entry_name (uimage_type, "Unknown Image", type)); |
| 539 | } |
| 540 | |
| 541 | const char *genimg_get_comp_name (uint8_t comp) |
| 542 | { |
| 543 | return (get_table_entry_name (uimage_comp, "Unknown Compression", comp)); |
| 544 | } |
| 545 | |
| 546 | /** |
| 547 | * get_table_entry_id - translate short entry name to id |
| 548 | * @table: pointer to a translation table for entries of a specific type |
| 549 | * @table_name: to be used in case of error |
| 550 | * @name: entry short name to be translated |
| 551 | * |
| 552 | * get_table_entry_id() will go over translation table trying to find |
| 553 | * entry that matches given short name. If matching entry is found, |
| 554 | * its id returned to the caller. |
| 555 | * |
| 556 | * returns: |
| 557 | * entry id if translation succeeds |
| 558 | * -1 otherwise |
| 559 | */ |
| 560 | static int get_table_entry_id (table_entry_t *table, |
| 561 | const char *table_name, const char *name) |
| 562 | { |
| 563 | table_entry_t *t; |
| 564 | #ifdef USE_HOSTCC |
| 565 | int first = 1; |
| 566 | |
| 567 | for (t = table; t->id >= 0; ++t) { |
| 568 | if (t->sname && strcasecmp(t->sname, name) == 0) |
| 569 | return (t->id); |
| 570 | } |
| 571 | |
| 572 | fprintf (stderr, "\nInvalid %s Type - valid names are", table_name); |
| 573 | for (t = table; t->id >= 0; ++t) { |
| 574 | if (t->sname == NULL) |
| 575 | continue; |
| 576 | fprintf (stderr, "%c %s", (first) ? ':' : ',', t->sname); |
| 577 | first = 0; |
| 578 | } |
| 579 | fprintf (stderr, "\n"); |
| 580 | #else |
| 581 | for (t = table; t->id >= 0; ++t) { |
| 582 | if (t->sname && strcmp(t->sname, name) == 0) |
| 583 | return (t->id); |
| 584 | } |
| 585 | debug ("Invalid %s Type: %s\n", table_name, name); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 586 | #endif /* USE_HOSTCC */ |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 587 | return (-1); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 588 | } |
| 589 | |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 590 | int genimg_get_os_id (const char *name) |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 591 | { |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 592 | return (get_table_entry_id (uimage_os, "OS", name)); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 593 | } |
| 594 | |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 595 | int genimg_get_arch_id (const char *name) |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 596 | { |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 597 | return (get_table_entry_id (uimage_arch, "CPU", name)); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 598 | } |
| 599 | |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 600 | int genimg_get_type_id (const char *name) |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 601 | { |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 602 | return (get_table_entry_id (uimage_type, "Image", name)); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 603 | } |
| 604 | |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 605 | int genimg_get_comp_id (const char *name) |
| 606 | { |
| 607 | return (get_table_entry_id (uimage_comp, "Compression", name)); |
| 608 | } |
| 609 | |
| 610 | #ifndef USE_HOSTCC |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 611 | /** |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 612 | * genimg_get_format - get image format type |
| 613 | * @img_addr: image start address |
| 614 | * |
| 615 | * genimg_get_format() checks whether provided address points to a valid |
| 616 | * legacy or FIT image. |
| 617 | * |
| 618 | * New uImage format and FDT blob are based on a libfdt. FDT blob |
| 619 | * may be passed directly or embedded in a FIT image. In both situations |
| 620 | * genimg_get_format() must be able to dectect libfdt header. |
| 621 | * |
| 622 | * returns: |
| 623 | * image format type or IMAGE_FORMAT_INVALID if no image is present |
| 624 | */ |
| 625 | int genimg_get_format (void *img_addr) |
| 626 | { |
| 627 | ulong format = IMAGE_FORMAT_INVALID; |
| 628 | image_header_t *hdr; |
| 629 | #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT) |
| 630 | char *fit_hdr; |
| 631 | #endif |
| 632 | |
| 633 | hdr = (image_header_t *)img_addr; |
| 634 | if (image_check_magic(hdr)) |
| 635 | format = IMAGE_FORMAT_LEGACY; |
| 636 | #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT) |
| 637 | else { |
| 638 | fit_hdr = (char *)img_addr; |
| 639 | if (fdt_check_header (fit_hdr) == 0) |
| 640 | format = IMAGE_FORMAT_FIT; |
| 641 | } |
| 642 | #endif |
| 643 | |
| 644 | return format; |
| 645 | } |
| 646 | |
| 647 | /** |
| 648 | * genimg_get_image - get image from special storage (if necessary) |
| 649 | * @img_addr: image start address |
| 650 | * |
| 651 | * genimg_get_image() checks if provided image start adddress is located |
| 652 | * in a dataflash storage. If so, image is moved to a system RAM memory. |
| 653 | * |
| 654 | * returns: |
| 655 | * image start address after possible relocation from special storage |
| 656 | */ |
| 657 | ulong genimg_get_image (ulong img_addr) |
| 658 | { |
| 659 | ulong ram_addr = img_addr; |
| 660 | |
| 661 | #ifdef CONFIG_HAS_DATAFLASH |
| 662 | ulong h_size, d_size; |
| 663 | |
| 664 | if (addr_dataflash (img_addr)){ |
| 665 | /* ger RAM address */ |
| 666 | ram_addr = CFG_LOAD_ADDR; |
| 667 | |
| 668 | /* get header size */ |
| 669 | h_size = image_get_header_size (); |
| 670 | #if defined(CONFIG_FIT) |
| 671 | if (sizeof(struct fdt_header) > h_size) |
| 672 | h_size = sizeof(struct fdt_header); |
| 673 | #endif |
| 674 | |
| 675 | /* read in header */ |
| 676 | debug (" Reading image header from dataflash address " |
| 677 | "%08lx to RAM address %08lx\n", img_addr, ram_addr); |
| 678 | |
| 679 | read_dataflash (img_addr, h_size, (char *)ram_addr); |
| 680 | |
| 681 | /* get data size */ |
| 682 | switch (genimg_get_format ((void *)ram_addr)) { |
| 683 | case IMAGE_FORMAT_LEGACY: |
| 684 | d_size = image_get_data_size ((image_header_t *)ram_addr); |
| 685 | debug (" Legacy format image found at 0x%08lx, size 0x%08lx\n", |
| 686 | ram_addr, d_size); |
| 687 | break; |
| 688 | #if defined(CONFIG_FIT) |
| 689 | case IMAGE_FORMAT_FIT: |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 690 | d_size = fit_get_size ((const void *)ram_addr) - h_size; |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 691 | debug (" FIT/FDT format image found at 0x%08lx, size 0x%08lx\n", |
| 692 | ram_addr, d_size); |
| 693 | break; |
| 694 | #endif |
| 695 | default: |
| 696 | printf (" No valid image found at 0x%08lx\n", img_addr); |
| 697 | return ram_addr; |
| 698 | } |
| 699 | |
| 700 | /* read in image data */ |
| 701 | debug (" Reading image remaining data from dataflash address " |
| 702 | "%08lx to RAM address %08lx\n", img_addr + h_size, |
| 703 | ram_addr + h_size); |
| 704 | |
| 705 | read_dataflash (img_addr + h_size, d_size, |
| 706 | (char *)(ram_addr + h_size)); |
| 707 | |
| 708 | } |
| 709 | #endif /* CONFIG_HAS_DATAFLASH */ |
| 710 | |
| 711 | return ram_addr; |
| 712 | } |
| 713 | |
| 714 | /** |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 715 | * fit_has_config - check if there is a valid FIT configuration |
| 716 | * @images: pointer to the bootm command headers structure |
| 717 | * |
| 718 | * fit_has_config() checks if there is a FIT configuration in use |
| 719 | * (if FTI support is present). |
| 720 | * |
| 721 | * returns: |
| 722 | * 0, no FIT support or no configuration found |
| 723 | * 1, configuration found |
| 724 | */ |
| 725 | int genimg_has_config (bootm_headers_t *images) |
| 726 | { |
| 727 | #if defined(CONFIG_FIT) |
| 728 | if (images->fit_uname_cfg) |
| 729 | return 1; |
| 730 | #endif |
| 731 | return 0; |
| 732 | } |
| 733 | |
| 734 | /** |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 735 | * boot_get_ramdisk - main ramdisk handling routine |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 736 | * @argc: command argument count |
| 737 | * @argv: command argument list |
Marian Balakowicz | 8a5ea3e | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 738 | * @images: pointer to the bootm images structure |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 739 | * @arch: expected ramdisk architecture |
| 740 | * @rd_start: pointer to a ulong variable, will hold ramdisk start address |
| 741 | * @rd_end: pointer to a ulong variable, will hold ramdisk end |
| 742 | * |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 743 | * boot_get_ramdisk() is responsible for finding a valid ramdisk image. |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 744 | * Curently supported are the following ramdisk sources: |
| 745 | * - multicomponent kernel/ramdisk image, |
| 746 | * - commandline provided address of decicated ramdisk image. |
| 747 | * |
| 748 | * returns: |
Marian Balakowicz | d985c84 | 2008-03-12 10:14:38 +0100 | [diff] [blame] | 749 | * 0, if ramdisk image was found and valid, or skiped |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 750 | * rd_start and rd_end are set to ramdisk start/end addresses if |
| 751 | * ramdisk image is found and valid |
Marian Balakowicz | d985c84 | 2008-03-12 10:14:38 +0100 | [diff] [blame] | 752 | * |
| 753 | * 1, if ramdisk image is found but corrupted |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 754 | * 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] | 755 | */ |
Marian Balakowicz | d985c84 | 2008-03-12 10:14:38 +0100 | [diff] [blame] | 756 | int boot_get_ramdisk (int argc, char *argv[], bootm_headers_t *images, |
| 757 | uint8_t arch, ulong *rd_start, ulong *rd_end) |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 758 | { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 759 | ulong rd_addr, rd_load; |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 760 | ulong rd_data, rd_len; |
| 761 | image_header_t *rd_hdr; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 762 | #if defined(CONFIG_FIT) |
| 763 | void *fit_hdr; |
| 764 | const char *fit_uname_config = NULL; |
| 765 | const char *fit_uname_ramdisk = NULL; |
| 766 | ulong default_addr; |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 767 | int rd_noffset; |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 768 | int cfg_noffset; |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 769 | const void *data; |
| 770 | size_t size; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 771 | #endif |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 772 | |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 773 | *rd_start = 0; |
| 774 | *rd_end = 0; |
| 775 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 776 | /* |
| 777 | * Look for a '-' which indicates to ignore the |
| 778 | * ramdisk argument |
| 779 | */ |
| 780 | if ((argc >= 3) && (strcmp(argv[2], "-") == 0)) { |
| 781 | debug ("## Skipping init Ramdisk\n"); |
| 782 | rd_len = rd_data = 0; |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 783 | } else if (argc >= 3 || genimg_has_config (images)) { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 784 | #if defined(CONFIG_FIT) |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 785 | if (argc >= 3) { |
| 786 | /* |
| 787 | * If the init ramdisk comes from the FIT image and |
| 788 | * the FIT image address is omitted in the command |
| 789 | * line argument, try to use os FIT image address or |
| 790 | * default load address. |
| 791 | */ |
| 792 | if (images->fit_uname_os) |
| 793 | default_addr = (ulong)images->fit_hdr_os; |
| 794 | else |
| 795 | default_addr = load_addr; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 796 | |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 797 | if (fit_parse_conf (argv[2], default_addr, |
| 798 | &rd_addr, &fit_uname_config)) { |
| 799 | debug ("* ramdisk: config '%s' from image at 0x%08lx\n", |
| 800 | fit_uname_config, rd_addr); |
| 801 | } else if (fit_parse_subimage (argv[2], default_addr, |
| 802 | &rd_addr, &fit_uname_ramdisk)) { |
| 803 | debug ("* ramdisk: subimage '%s' from image at 0x%08lx\n", |
| 804 | fit_uname_ramdisk, rd_addr); |
| 805 | } else |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 806 | #endif |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 807 | { |
| 808 | rd_addr = simple_strtoul(argv[2], NULL, 16); |
| 809 | debug ("* ramdisk: cmdline image address = 0x%08lx\n", |
| 810 | rd_addr); |
| 811 | } |
| 812 | #if defined(CONFIG_FIT) |
| 813 | } else { |
| 814 | /* use FIT configuration provided in first bootm |
| 815 | * command argument |
| 816 | */ |
| 817 | rd_addr = (ulong)images->fit_hdr_os; |
| 818 | fit_uname_config = images->fit_uname_cfg; |
| 819 | debug ("* ramdisk: using config '%s' from image at 0x%08lx\n", |
| 820 | fit_uname_config, rd_addr); |
| 821 | |
| 822 | /* |
| 823 | * Check whether configuration has ramdisk defined, |
| 824 | * if not, don't try to use it, quit silently. |
| 825 | */ |
| 826 | fit_hdr = (void *)rd_addr; |
| 827 | cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config); |
| 828 | if (cfg_noffset < 0) { |
| 829 | debug ("* ramdisk: no such config\n"); |
| 830 | return 0; |
| 831 | } |
| 832 | |
| 833 | rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset); |
| 834 | if (rd_noffset < 0) { |
| 835 | debug ("* ramdisk: no ramdisk in config\n"); |
| 836 | return 0; |
| 837 | } |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 838 | } |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 839 | #endif |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 840 | |
| 841 | /* copy from dataflash if needed */ |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 842 | rd_addr = genimg_get_image (rd_addr); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 843 | |
| 844 | /* |
| 845 | * Check if there is an initrd image at the |
| 846 | * address provided in the second bootm argument |
| 847 | * check image type, for FIT images get FIT node. |
| 848 | */ |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 849 | switch (genimg_get_format ((void *)rd_addr)) { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 850 | case IMAGE_FORMAT_LEGACY: |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 851 | printf ("## Loading init Ramdisk from Legacy " |
| 852 | "Image at %08lx ...\n", rd_addr); |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 853 | |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 854 | show_boot_progress (9); |
Marian Balakowicz | d985c84 | 2008-03-12 10:14:38 +0100 | [diff] [blame] | 855 | rd_hdr = image_get_ramdisk (rd_addr, arch, |
| 856 | images->verify); |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 857 | |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 858 | if (rd_hdr == NULL) |
Kumar Gala | 274cea2 | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 859 | return 1; |
Kumar Gala | 274cea2 | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 860 | |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 861 | rd_data = image_get_data (rd_hdr); |
| 862 | rd_len = image_get_data_size (rd_hdr); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 863 | rd_load = image_get_load (rd_hdr); |
| 864 | break; |
| 865 | #if defined(CONFIG_FIT) |
| 866 | case IMAGE_FORMAT_FIT: |
| 867 | fit_hdr = (void *)rd_addr; |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 868 | printf ("## Loading init Ramdisk from FIT " |
| 869 | "Image at %08lx ...\n", rd_addr); |
| 870 | |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 871 | show_boot_progress (120); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 872 | if (!fit_check_format (fit_hdr)) { |
| 873 | puts ("Bad FIT ramdisk image format!\n"); |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 874 | show_boot_progress (-120); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 875 | return 0; |
| 876 | } |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 877 | show_boot_progress (121); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 878 | |
| 879 | if (!fit_uname_ramdisk) { |
| 880 | /* |
| 881 | * no ramdisk image node unit name, try to get config |
| 882 | * node first. If config unit node name is NULL |
| 883 | * fit_conf_get_node() will try to find default config node |
| 884 | */ |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 885 | show_boot_progress (122); |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 886 | cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config); |
| 887 | if (cfg_noffset < 0) { |
| 888 | puts ("Could not find configuration node\n"); |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 889 | show_boot_progress (-122); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 890 | return 0; |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 891 | } |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 892 | fit_uname_config = fdt_get_name (fit_hdr, cfg_noffset, NULL); |
| 893 | printf (" Using '%s' configuration\n", fit_uname_config); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 894 | |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 895 | rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 896 | fit_uname_ramdisk = fit_get_name (fit_hdr, rd_noffset, NULL); |
| 897 | } else { |
| 898 | /* get ramdisk component image node offset */ |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 899 | show_boot_progress (123); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 900 | rd_noffset = fit_image_get_node (fit_hdr, fit_uname_ramdisk); |
| 901 | } |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 902 | if (rd_noffset < 0) { |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 903 | puts ("Could not find subimage node\n"); |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 904 | show_boot_progress (-124); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 905 | return 0; |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 906 | } |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 907 | |
| 908 | printf (" Trying '%s' ramdisk subimage\n", fit_uname_ramdisk); |
| 909 | |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 910 | show_boot_progress (125); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 911 | if (!fit_check_ramdisk (fit_hdr, rd_noffset, arch, images->verify)) |
| 912 | return 0; |
| 913 | |
| 914 | /* get ramdisk image data address and length */ |
| 915 | if (fit_image_get_data (fit_hdr, rd_noffset, &data, &size)) { |
| 916 | puts ("Could not find ramdisk subimage data!\n"); |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 917 | show_boot_progress (-127); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 918 | return 0; |
| 919 | } |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 920 | show_boot_progress (128); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 921 | |
| 922 | rd_data = (ulong)data; |
| 923 | rd_len = size; |
| 924 | |
| 925 | if (fit_image_get_load (fit_hdr, rd_noffset, &rd_load)) { |
| 926 | puts ("Can't get ramdisk subimage load address!\n"); |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 927 | show_boot_progress (-129); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 928 | return 0; |
| 929 | } |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 930 | show_boot_progress (129); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 931 | |
| 932 | images->fit_hdr_rd = fit_hdr; |
| 933 | images->fit_uname_rd = fit_uname_ramdisk; |
Marian Balakowicz | 3dfe110 | 2008-03-12 10:32:59 +0100 | [diff] [blame] | 934 | images->fit_noffset_rd = rd_noffset; |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 935 | break; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 936 | #endif |
| 937 | default: |
Marian Balakowicz | d985c84 | 2008-03-12 10:14:38 +0100 | [diff] [blame] | 938 | puts ("Wrong Ramdisk Image Format\n"); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 939 | rd_data = rd_len = rd_load = 0; |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 940 | } |
| 941 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 942 | #if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || defined(CONFIG_ARMADILLO) |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 943 | /* |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 944 | * We need to copy the ramdisk to SRAM to let Linux boot |
| 945 | */ |
| 946 | if (rd_data) { |
| 947 | memmove ((void *)rd_load, (uchar *)rd_data, rd_len); |
| 948 | rd_data = rd_load; |
| 949 | } |
| 950 | #endif /* CONFIG_B2 || CONFIG_EVB4510 || CONFIG_ARMADILLO */ |
| 951 | |
| 952 | } else if (images->legacy_hdr_valid && |
Marian Balakowicz | cb1c489 | 2008-04-11 11:07:49 +0200 | [diff] [blame] | 953 | image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 954 | /* |
| 955 | * Now check if we have a legacy mult-component image, |
| 956 | * get second entry data start address and len. |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 957 | */ |
| 958 | show_boot_progress (13); |
| 959 | printf ("## Loading init Ramdisk from multi component " |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 960 | "Legacy Image at %08lx ...\n", |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 961 | (ulong)images->legacy_hdr_os); |
| 962 | |
| 963 | image_multi_getimg (images->legacy_hdr_os, 1, &rd_data, &rd_len); |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 964 | } else { |
| 965 | /* |
| 966 | * no initrd image |
| 967 | */ |
| 968 | show_boot_progress (14); |
| 969 | rd_len = rd_data = 0; |
| 970 | } |
| 971 | |
| 972 | if (!rd_data) { |
| 973 | debug ("## No init Ramdisk\n"); |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 974 | } else { |
| 975 | *rd_start = rd_data; |
| 976 | *rd_end = rd_data + rd_len; |
| 977 | } |
| 978 | debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n", |
| 979 | *rd_start, *rd_end); |
Kumar Gala | 274cea2 | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 980 | |
| 981 | return 0; |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 982 | } |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 983 | |
Daniel Hellstrom | bf3d8b3 | 2008-03-28 08:29:26 +0100 | [diff] [blame] | 984 | #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC) |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 985 | /** |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 986 | * boot_ramdisk_high - relocate init ramdisk |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 987 | * @lmb: pointer to lmb handle, will be used for memory mgmt |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 988 | * @rd_data: ramdisk data start address |
| 989 | * @rd_len: ramdisk data length |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 990 | * @initrd_start: pointer to a ulong variable, will hold final init ramdisk |
| 991 | * start address (after possible relocation) |
| 992 | * @initrd_end: pointer to a ulong variable, will hold final init ramdisk |
| 993 | * end address (after possible relocation) |
| 994 | * |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 995 | * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 996 | * variable and if requested ramdisk data is moved to a specified location. |
| 997 | * |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 998 | * Initrd_start and initrd_end are set to final (after relocation) ramdisk |
| 999 | * start/end addresses if ramdisk image start and len were provided, |
| 1000 | * otherwise set initrd_start and initrd_end set to zeros. |
| 1001 | * |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1002 | * returns: |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1003 | * 0 - success |
| 1004 | * -1 - failure |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1005 | */ |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1006 | 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] | 1007 | ulong *initrd_start, ulong *initrd_end) |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1008 | { |
| 1009 | char *s; |
| 1010 | ulong initrd_high; |
| 1011 | int initrd_copy_to_ram = 1; |
| 1012 | |
| 1013 | if ((s = getenv ("initrd_high")) != NULL) { |
| 1014 | /* a value of "no" or a similar string will act like 0, |
| 1015 | * turning the "load high" feature off. This is intentional. |
| 1016 | */ |
| 1017 | initrd_high = simple_strtoul (s, NULL, 16); |
| 1018 | if (initrd_high == ~0) |
| 1019 | initrd_copy_to_ram = 0; |
| 1020 | } else { |
| 1021 | /* not set, no restrictions to load high */ |
| 1022 | initrd_high = ~0; |
| 1023 | } |
| 1024 | |
Marian Balakowicz | 1b5605c | 2008-05-07 13:10:04 +0200 | [diff] [blame^] | 1025 | /* Prevent initrd from overwriting logbuffer */ |
| 1026 | lmb_reserve(lmb, logbuffer_base() - LOGBUFF_OVERHEAD, LOGBUFF_RESERVE); |
| 1027 | |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1028 | debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n", |
| 1029 | initrd_high, initrd_copy_to_ram); |
| 1030 | |
| 1031 | if (rd_data) { |
| 1032 | if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */ |
| 1033 | debug (" in-place initrd\n"); |
| 1034 | *initrd_start = rd_data; |
| 1035 | *initrd_end = rd_data + rd_len; |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1036 | lmb_reserve(lmb, rd_data, rd_len); |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1037 | } else { |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1038 | if (initrd_high) |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1039 | *initrd_start = lmb_alloc_base (lmb, rd_len, 0x1000, initrd_high); |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1040 | else |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1041 | *initrd_start = lmb_alloc (lmb, rd_len, 0x1000); |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1042 | |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1043 | if (*initrd_start == 0) { |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1044 | puts ("ramdisk - allocation error\n"); |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1045 | goto error; |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1046 | } |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1047 | show_boot_progress (12); |
| 1048 | |
| 1049 | *initrd_end = *initrd_start + rd_len; |
| 1050 | printf (" Loading Ramdisk to %08lx, end %08lx ... ", |
| 1051 | *initrd_start, *initrd_end); |
| 1052 | |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1053 | memmove_wd ((void *)*initrd_start, |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1054 | (void *)rd_data, rd_len, CHUNKSZ); |
| 1055 | |
| 1056 | puts ("OK\n"); |
| 1057 | } |
| 1058 | } else { |
| 1059 | *initrd_start = 0; |
| 1060 | *initrd_end = 0; |
| 1061 | } |
| 1062 | debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n", |
| 1063 | *initrd_start, *initrd_end); |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1064 | |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1065 | return 0; |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1066 | |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1067 | error: |
| 1068 | return -1; |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | /** |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1072 | * boot_get_cmdline - allocate and initialize kernel cmdline |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1073 | * @lmb: pointer to lmb handle, will be used for memory mgmt |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1074 | * @cmd_start: pointer to a ulong variable, will hold cmdline start |
| 1075 | * @cmd_end: pointer to a ulong variable, will hold cmdline end |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1076 | * @bootmap_base: ulong variable, holds offset in physical memory to |
| 1077 | * base of bootmap |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1078 | * |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1079 | * boot_get_cmdline() allocates space for kernel command line below |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1080 | * BOOTMAPSZ + bootmap_base address. If "bootargs" U-boot environemnt |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1081 | * variable is present its contents is copied to allocated kernel |
| 1082 | * command line. |
| 1083 | * |
| 1084 | * returns: |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1085 | * 0 - success |
| 1086 | * -1 - failure |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1087 | */ |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1088 | int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end, |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1089 | ulong bootmap_base) |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1090 | { |
| 1091 | char *cmdline; |
| 1092 | char *s; |
| 1093 | |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1094 | cmdline = (char *)lmb_alloc_base(lmb, CFG_BARGSIZE, 0xf, |
| 1095 | CFG_BOOTMAPSZ + bootmap_base); |
| 1096 | |
| 1097 | if (cmdline == NULL) |
| 1098 | return -1; |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1099 | |
| 1100 | if ((s = getenv("bootargs")) == NULL) |
| 1101 | s = ""; |
| 1102 | |
| 1103 | strcpy(cmdline, s); |
| 1104 | |
| 1105 | *cmd_start = (ulong) & cmdline[0]; |
| 1106 | *cmd_end = *cmd_start + strlen(cmdline); |
| 1107 | |
| 1108 | debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end); |
| 1109 | |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1110 | return 0; |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | /** |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1114 | * boot_get_kbd - allocate and initialize kernel copy of board info |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1115 | * @lmb: pointer to lmb handle, will be used for memory mgmt |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1116 | * @kbd: double pointer to board info data |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1117 | * @bootmap_base: ulong variable, holds offset in physical memory to |
| 1118 | * base of bootmap |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1119 | * |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1120 | * boot_get_kbd() allocates space for kernel copy of board info data below |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1121 | * BOOTMAPSZ + bootmap_base address and kernel board info is initialized with |
| 1122 | * the current u-boot board info data. |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1123 | * |
| 1124 | * returns: |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1125 | * 0 - success |
| 1126 | * -1 - failure |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1127 | */ |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1128 | int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base) |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1129 | { |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1130 | *kbd = (bd_t *)lmb_alloc_base(lmb, sizeof(bd_t), 0xf, |
| 1131 | CFG_BOOTMAPSZ + bootmap_base); |
| 1132 | if (*kbd == NULL) |
| 1133 | return -1; |
| 1134 | |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 1135 | **kbd = *(gd->bd); |
| 1136 | |
| 1137 | debug ("## kernel board info at 0x%08lx\n", (ulong)*kbd); |
| 1138 | |
| 1139 | #if defined(DEBUG) && defined(CONFIG_CMD_BDI) |
| 1140 | do_bdinfo(NULL, 0, 0, NULL); |
| 1141 | #endif |
| 1142 | |
Kumar Gala | e822d7f | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 1143 | return 0; |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 1144 | } |
| 1145 | #endif /* CONFIG_PPC || CONFIG_M68K */ |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1146 | #endif /* !USE_HOSTCC */ |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 1147 | |
Marian Balakowicz | f50433d | 2008-02-21 17:20:20 +0100 | [diff] [blame] | 1148 | #if defined(CONFIG_FIT) |
| 1149 | /*****************************************************************************/ |
| 1150 | /* New uImage format routines */ |
| 1151 | /*****************************************************************************/ |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1152 | #ifndef USE_HOSTCC |
Marian Balakowicz | f50433d | 2008-02-21 17:20:20 +0100 | [diff] [blame] | 1153 | static int fit_parse_spec (const char *spec, char sepc, ulong addr_curr, |
| 1154 | ulong *addr, const char **name) |
| 1155 | { |
| 1156 | const char *sep; |
| 1157 | |
| 1158 | *addr = addr_curr; |
| 1159 | *name = NULL; |
| 1160 | |
| 1161 | sep = strchr (spec, sepc); |
| 1162 | if (sep) { |
| 1163 | if (sep - spec > 0) |
| 1164 | *addr = simple_strtoul (spec, NULL, 16); |
| 1165 | |
| 1166 | *name = sep + 1; |
| 1167 | return 1; |
| 1168 | } |
| 1169 | |
| 1170 | return 0; |
| 1171 | } |
| 1172 | |
| 1173 | /** |
| 1174 | * fit_parse_conf - parse FIT configuration spec |
| 1175 | * @spec: input string, containing configuration spec |
| 1176 | * @add_curr: current image address (to be used as a possible default) |
| 1177 | * @addr: pointer to a ulong variable, will hold FIT image address of a given |
| 1178 | * configuration |
| 1179 | * @conf_name double pointer to a char, will hold pointer to a configuration |
| 1180 | * unit name |
| 1181 | * |
| 1182 | * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>, |
| 1183 | * where <addr> is a FIT image address that contains configuration |
| 1184 | * with a <conf> unit name. |
| 1185 | * |
| 1186 | * Address part is optional, and if omitted default add_curr will |
| 1187 | * be used instead. |
| 1188 | * |
| 1189 | * returns: |
| 1190 | * 1 if spec is a valid configuration string, |
| 1191 | * addr and conf_name are set accordingly |
| 1192 | * 0 otherwise |
| 1193 | */ |
| 1194 | inline int fit_parse_conf (const char *spec, ulong addr_curr, |
| 1195 | ulong *addr, const char **conf_name) |
| 1196 | { |
| 1197 | return fit_parse_spec (spec, '#', addr_curr, addr, conf_name); |
| 1198 | } |
| 1199 | |
| 1200 | /** |
| 1201 | * fit_parse_subimage - parse FIT subimage spec |
| 1202 | * @spec: input string, containing subimage spec |
| 1203 | * @add_curr: current image address (to be used as a possible default) |
| 1204 | * @addr: pointer to a ulong variable, will hold FIT image address of a given |
| 1205 | * subimage |
| 1206 | * @image_name: double pointer to a char, will hold pointer to a subimage name |
| 1207 | * |
| 1208 | * fit_parse_subimage() expects subimage spec in the for of |
| 1209 | * [<addr>]:<subimage>, where <addr> is a FIT image address that contains |
| 1210 | * subimage with a <subimg> unit name. |
| 1211 | * |
| 1212 | * Address part is optional, and if omitted default add_curr will |
| 1213 | * be used instead. |
| 1214 | * |
| 1215 | * returns: |
| 1216 | * 1 if spec is a valid subimage string, |
| 1217 | * addr and image_name are set accordingly |
| 1218 | * 0 otherwise |
| 1219 | */ |
| 1220 | inline int fit_parse_subimage (const char *spec, ulong addr_curr, |
| 1221 | ulong *addr, const char **image_name) |
| 1222 | { |
| 1223 | return fit_parse_spec (spec, ':', addr_curr, addr, image_name); |
| 1224 | } |
Marian Balakowicz | 570abb0 | 2008-02-29 15:59:59 +0100 | [diff] [blame] | 1225 | #endif /* !USE_HOSTCC */ |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1226 | |
| 1227 | static void fit_get_debug (const void *fit, int noffset, |
| 1228 | char *prop_name, int err) |
| 1229 | { |
| 1230 | debug ("Can't get '%s' property from FIT 0x%08lx, " |
| 1231 | "node: offset %d, name %s (%s)\n", |
| 1232 | prop_name, (ulong)fit, noffset, |
| 1233 | fit_get_name (fit, noffset, NULL), |
| 1234 | fdt_strerror (err)); |
| 1235 | } |
| 1236 | |
| 1237 | /** |
Bartlomiej Sieka | edbed24 | 2008-04-18 12:39:23 +0200 | [diff] [blame] | 1238 | * fit_print_contents - prints out the contents of the FIT format image |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1239 | * @fit: pointer to the FIT format image header |
| 1240 | * @p: pointer to prefix string |
| 1241 | * |
Bartlomiej Sieka | edbed24 | 2008-04-18 12:39:23 +0200 | [diff] [blame] | 1242 | * fit_print_contents() formats a multi line FIT image contents description. |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1243 | * The routine prints out FIT image properties (root node level) follwed by |
| 1244 | * the details of each component image. |
| 1245 | * |
| 1246 | * returns: |
| 1247 | * no returned results |
| 1248 | */ |
Bartlomiej Sieka | edbed24 | 2008-04-18 12:39:23 +0200 | [diff] [blame] | 1249 | void fit_print_contents (const void *fit) |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1250 | { |
| 1251 | char *desc; |
| 1252 | char *uname; |
| 1253 | int images_noffset; |
| 1254 | int confs_noffset; |
| 1255 | int noffset; |
| 1256 | int ndepth; |
| 1257 | int count = 0; |
| 1258 | int ret; |
Bartlomiej Sieka | edbed24 | 2008-04-18 12:39:23 +0200 | [diff] [blame] | 1259 | const char *p; |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1260 | #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) |
| 1261 | time_t timestamp; |
| 1262 | #endif |
| 1263 | |
Bartlomiej Sieka | edbed24 | 2008-04-18 12:39:23 +0200 | [diff] [blame] | 1264 | #ifdef USE_HOSTCC |
| 1265 | p = ""; |
| 1266 | #else |
| 1267 | p = " "; |
| 1268 | #endif |
| 1269 | |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1270 | /* Root node properties */ |
| 1271 | ret = fit_get_desc (fit, 0, &desc); |
| 1272 | printf ("%sFIT description: ", p); |
| 1273 | if (ret) |
| 1274 | printf ("unavailable\n"); |
| 1275 | else |
| 1276 | printf ("%s\n", desc); |
| 1277 | |
| 1278 | #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) |
| 1279 | ret = fit_get_timestamp (fit, 0, ×tamp); |
| 1280 | printf ("%sCreated: ", p); |
| 1281 | if (ret) |
| 1282 | printf ("unavailable\n"); |
| 1283 | else |
| 1284 | genimg_print_time (timestamp); |
| 1285 | #endif |
| 1286 | |
| 1287 | /* Find images parent node offset */ |
| 1288 | images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH); |
| 1289 | if (images_noffset < 0) { |
| 1290 | printf ("Can't find images parent node '%s' (%s)\n", |
| 1291 | FIT_IMAGES_PATH, fdt_strerror (images_noffset)); |
| 1292 | return; |
| 1293 | } |
| 1294 | |
| 1295 | /* Process its subnodes, print out component images details */ |
| 1296 | for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth); |
| 1297 | (noffset >= 0) && (ndepth > 0); |
| 1298 | noffset = fdt_next_node (fit, noffset, &ndepth)) { |
| 1299 | if (ndepth == 1) { |
| 1300 | /* |
| 1301 | * Direct child node of the images parent node, |
| 1302 | * i.e. component image node. |
| 1303 | */ |
| 1304 | printf ("%s Image %u (%s)\n", p, count++, |
| 1305 | fit_get_name(fit, noffset, NULL)); |
| 1306 | |
| 1307 | fit_image_print (fit, noffset, p); |
| 1308 | } |
| 1309 | } |
| 1310 | |
| 1311 | /* Find configurations parent node offset */ |
| 1312 | confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH); |
| 1313 | if (confs_noffset < 0) { |
| 1314 | debug ("Can't get configurations parent node '%s' (%s)\n", |
| 1315 | FIT_CONFS_PATH, fdt_strerror (confs_noffset)); |
| 1316 | return; |
| 1317 | } |
| 1318 | |
| 1319 | /* get default configuration unit name from default property */ |
| 1320 | uname = (char *)fdt_getprop (fit, noffset, FIT_DEFAULT_PROP, NULL); |
| 1321 | if (uname) |
| 1322 | printf ("%s Default Configuration: '%s'\n", p, uname); |
| 1323 | |
| 1324 | /* Process its subnodes, print out configurations details */ |
| 1325 | for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, confs_noffset, &ndepth); |
| 1326 | (noffset >= 0) && (ndepth > 0); |
| 1327 | noffset = fdt_next_node (fit, noffset, &ndepth)) { |
| 1328 | if (ndepth == 1) { |
| 1329 | /* |
| 1330 | * Direct child node of the configurations parent node, |
| 1331 | * i.e. configuration node. |
| 1332 | */ |
| 1333 | printf ("%s Configuration %u (%s)\n", p, count++, |
| 1334 | fit_get_name(fit, noffset, NULL)); |
| 1335 | |
| 1336 | fit_conf_print (fit, noffset, p); |
| 1337 | } |
| 1338 | } |
| 1339 | } |
| 1340 | |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1341 | /** |
| 1342 | * fit_image_print - prints out the FIT component image details |
| 1343 | * @fit: pointer to the FIT format image header |
| 1344 | * @image_noffset: offset of the component image node |
| 1345 | * @p: pointer to prefix string |
| 1346 | * |
| 1347 | * fit_image_print() lists all mandatory properies for the processed component |
| 1348 | * image. If present, hash nodes are printed out as well. |
| 1349 | * |
| 1350 | * returns: |
| 1351 | * no returned results |
| 1352 | */ |
| 1353 | void fit_image_print (const void *fit, int image_noffset, const char *p) |
| 1354 | { |
| 1355 | char *desc; |
| 1356 | uint8_t type, arch, os, comp; |
| 1357 | size_t size; |
| 1358 | ulong load, entry; |
| 1359 | const void *data; |
| 1360 | int noffset; |
| 1361 | int ndepth; |
| 1362 | int ret; |
| 1363 | |
| 1364 | /* Mandatory properties */ |
| 1365 | ret = fit_get_desc (fit, image_noffset, &desc); |
| 1366 | printf ("%s Description: ", p); |
| 1367 | if (ret) |
| 1368 | printf ("unavailable\n"); |
| 1369 | else |
| 1370 | printf ("%s\n", desc); |
| 1371 | |
| 1372 | fit_image_get_type (fit, image_noffset, &type); |
| 1373 | printf ("%s Type: %s\n", p, genimg_get_type_name (type)); |
| 1374 | |
| 1375 | fit_image_get_comp (fit, image_noffset, &comp); |
| 1376 | printf ("%s Compression: %s\n", p, genimg_get_comp_name (comp)); |
| 1377 | |
| 1378 | ret = fit_image_get_data (fit, image_noffset, &data, &size); |
| 1379 | |
| 1380 | #ifndef USE_HOSTCC |
| 1381 | printf ("%s Data Start: ", p); |
| 1382 | if (ret) |
| 1383 | printf ("unavailable\n"); |
| 1384 | else |
| 1385 | printf ("0x%08lx\n", (ulong)data); |
| 1386 | #endif |
| 1387 | |
| 1388 | printf ("%s Data Size: ", p); |
| 1389 | if (ret) |
| 1390 | printf ("unavailable\n"); |
| 1391 | else |
| 1392 | genimg_print_size (size); |
| 1393 | |
| 1394 | /* Remaining, type dependent properties */ |
| 1395 | if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) || |
| 1396 | (type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) || |
| 1397 | (type == IH_TYPE_FLATDT)) { |
| 1398 | fit_image_get_arch (fit, image_noffset, &arch); |
| 1399 | printf ("%s Architecture: %s\n", p, genimg_get_arch_name (arch)); |
| 1400 | } |
| 1401 | |
| 1402 | if (type == IH_TYPE_KERNEL) { |
| 1403 | fit_image_get_os (fit, image_noffset, &os); |
| 1404 | printf ("%s OS: %s\n", p, genimg_get_os_name (os)); |
| 1405 | } |
| 1406 | |
| 1407 | if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE)) { |
| 1408 | ret = fit_image_get_load (fit, image_noffset, &load); |
| 1409 | printf ("%s Load Address: ", p); |
| 1410 | if (ret) |
| 1411 | printf ("unavailable\n"); |
| 1412 | else |
| 1413 | printf ("0x%08lx\n", load); |
| 1414 | |
| 1415 | fit_image_get_entry (fit, image_noffset, &entry); |
| 1416 | printf ("%s Entry Point: ", p); |
| 1417 | if (ret) |
| 1418 | printf ("unavailable\n"); |
| 1419 | else |
| 1420 | printf ("0x%08lx\n", entry); |
| 1421 | } |
| 1422 | |
| 1423 | /* Process all hash subnodes of the component image node */ |
| 1424 | for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth); |
| 1425 | (noffset >= 0) && (ndepth > 0); |
| 1426 | noffset = fdt_next_node (fit, noffset, &ndepth)) { |
| 1427 | if (ndepth == 1) { |
| 1428 | /* Direct child node of the component image node */ |
| 1429 | fit_image_print_hash (fit, noffset, p); |
| 1430 | } |
| 1431 | } |
| 1432 | } |
| 1433 | |
| 1434 | /** |
| 1435 | * fit_image_print_hash - prints out the hash node details |
| 1436 | * @fit: pointer to the FIT format image header |
| 1437 | * @noffset: offset of the hash node |
| 1438 | * @p: pointer to prefix string |
| 1439 | * |
| 1440 | * fit_image_print_hash() lists properies for the processed hash node |
| 1441 | * |
| 1442 | * returns: |
| 1443 | * no returned results |
| 1444 | */ |
| 1445 | void fit_image_print_hash (const void *fit, int noffset, const char *p) |
| 1446 | { |
| 1447 | char *algo; |
| 1448 | uint8_t *value; |
| 1449 | int value_len; |
| 1450 | int i, ret; |
| 1451 | |
| 1452 | /* |
| 1453 | * Check subnode name, must be equal to "hash". |
| 1454 | * Multiple hash nodes require unique unit node |
| 1455 | * names, e.g. hash@1, hash@2, etc. |
| 1456 | */ |
| 1457 | if (strncmp (fit_get_name(fit, noffset, NULL), |
| 1458 | FIT_HASH_NODENAME, |
| 1459 | strlen(FIT_HASH_NODENAME)) != 0) |
| 1460 | return; |
| 1461 | |
| 1462 | debug ("%s Hash node: '%s'\n", p, |
| 1463 | fit_get_name (fit, noffset, NULL)); |
| 1464 | |
| 1465 | printf ("%s Hash algo: ", p); |
| 1466 | if (fit_image_hash_get_algo (fit, noffset, &algo)) { |
| 1467 | printf ("invalid/unsupported\n"); |
| 1468 | return; |
| 1469 | } |
| 1470 | printf ("%s\n", algo); |
| 1471 | |
| 1472 | ret = fit_image_hash_get_value (fit, noffset, &value, |
| 1473 | &value_len); |
| 1474 | printf ("%s Hash value: ", p); |
| 1475 | if (ret) { |
| 1476 | printf ("unavailable\n"); |
| 1477 | } else { |
| 1478 | for (i = 0; i < value_len; i++) |
| 1479 | printf ("%02x", value[i]); |
| 1480 | printf ("\n"); |
| 1481 | } |
| 1482 | |
| 1483 | debug ("%s Hash len: %d\n", p, value_len); |
| 1484 | } |
| 1485 | |
| 1486 | /** |
| 1487 | * fit_get_desc - get node description property |
| 1488 | * @fit: pointer to the FIT format image header |
| 1489 | * @noffset: node offset |
| 1490 | * @desc: double pointer to the char, will hold pointer to the descrption |
| 1491 | * |
| 1492 | * fit_get_desc() reads description property from a given node, if |
| 1493 | * description is found pointer to it is returened in third call argument. |
| 1494 | * |
| 1495 | * returns: |
| 1496 | * 0, on success |
| 1497 | * -1, on failure |
| 1498 | */ |
| 1499 | int fit_get_desc (const void *fit, int noffset, char **desc) |
| 1500 | { |
| 1501 | int len; |
| 1502 | |
| 1503 | *desc = (char *)fdt_getprop (fit, noffset, FIT_DESC_PROP, &len); |
| 1504 | if (*desc == NULL) { |
| 1505 | fit_get_debug (fit, noffset, FIT_DESC_PROP, len); |
| 1506 | return -1; |
| 1507 | } |
| 1508 | |
| 1509 | return 0; |
| 1510 | } |
| 1511 | |
| 1512 | /** |
| 1513 | * fit_get_timestamp - get node timestamp property |
| 1514 | * @fit: pointer to the FIT format image header |
| 1515 | * @noffset: node offset |
| 1516 | * @timestamp: pointer to the time_t, will hold read timestamp |
| 1517 | * |
| 1518 | * fit_get_timestamp() reads timestamp poperty from given node, if timestamp |
| 1519 | * is found and has a correct size its value is retured in third call |
| 1520 | * argument. |
| 1521 | * |
| 1522 | * returns: |
| 1523 | * 0, on success |
| 1524 | * -1, on property read failure |
| 1525 | * -2, on wrong timestamp size |
| 1526 | */ |
| 1527 | int fit_get_timestamp (const void *fit, int noffset, time_t *timestamp) |
| 1528 | { |
| 1529 | int len; |
| 1530 | const void *data; |
| 1531 | |
| 1532 | data = fdt_getprop (fit, noffset, FIT_TIMESTAMP_PROP, &len); |
| 1533 | if (data == NULL) { |
| 1534 | fit_get_debug (fit, noffset, FIT_TIMESTAMP_PROP, len); |
| 1535 | return -1; |
| 1536 | } |
| 1537 | if (len != sizeof (uint32_t)) { |
| 1538 | debug ("FIT timestamp with incorrect size of (%u)\n", len); |
| 1539 | return -2; |
| 1540 | } |
| 1541 | |
| 1542 | *timestamp = uimage_to_cpu (*((uint32_t *)data)); |
| 1543 | return 0; |
| 1544 | } |
| 1545 | |
| 1546 | /** |
| 1547 | * fit_image_get_node - get node offset for component image of a given unit name |
| 1548 | * @fit: pointer to the FIT format image header |
| 1549 | * @image_uname: component image node unit name |
| 1550 | * |
| 1551 | * fit_image_get_node() finds a component image (withing the '/images' |
| 1552 | * node) of a provided unit name. If image is found its node offset is |
| 1553 | * returned to the caller. |
| 1554 | * |
| 1555 | * returns: |
| 1556 | * image node offset when found (>=0) |
| 1557 | * negative number on failure (FDT_ERR_* code) |
| 1558 | */ |
| 1559 | int fit_image_get_node (const void *fit, const char *image_uname) |
| 1560 | { |
| 1561 | int noffset, images_noffset; |
| 1562 | |
| 1563 | images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH); |
| 1564 | if (images_noffset < 0) { |
| 1565 | debug ("Can't find images parent node '%s' (%s)\n", |
| 1566 | FIT_IMAGES_PATH, fdt_strerror (images_noffset)); |
| 1567 | return images_noffset; |
| 1568 | } |
| 1569 | |
| 1570 | noffset = fdt_subnode_offset (fit, images_noffset, image_uname); |
| 1571 | if (noffset < 0) { |
| 1572 | debug ("Can't get node offset for image unit name: '%s' (%s)\n", |
| 1573 | image_uname, fdt_strerror (noffset)); |
| 1574 | } |
| 1575 | |
| 1576 | return noffset; |
| 1577 | } |
| 1578 | |
| 1579 | /** |
| 1580 | * fit_image_get_os - get os id for a given component image node |
| 1581 | * @fit: pointer to the FIT format image header |
| 1582 | * @noffset: component image node offset |
| 1583 | * @os: pointer to the uint8_t, will hold os numeric id |
| 1584 | * |
| 1585 | * fit_image_get_os() finds os property in a given component image node. |
| 1586 | * If the property is found, its (string) value is translated to the numeric |
| 1587 | * id which is returned to the caller. |
| 1588 | * |
| 1589 | * returns: |
| 1590 | * 0, on success |
| 1591 | * -1, on failure |
| 1592 | */ |
| 1593 | int fit_image_get_os (const void *fit, int noffset, uint8_t *os) |
| 1594 | { |
| 1595 | int len; |
| 1596 | const void *data; |
| 1597 | |
| 1598 | /* Get OS name from property data */ |
| 1599 | data = fdt_getprop (fit, noffset, FIT_OS_PROP, &len); |
| 1600 | if (data == NULL) { |
| 1601 | fit_get_debug (fit, noffset, FIT_OS_PROP, len); |
| 1602 | *os = -1; |
| 1603 | return -1; |
| 1604 | } |
| 1605 | |
| 1606 | /* Translate OS name to id */ |
| 1607 | *os = genimg_get_os_id (data); |
| 1608 | return 0; |
| 1609 | } |
| 1610 | |
| 1611 | /** |
| 1612 | * fit_image_get_arch - get arch id for a given component image node |
| 1613 | * @fit: pointer to the FIT format image header |
| 1614 | * @noffset: component image node offset |
| 1615 | * @arch: pointer to the uint8_t, will hold arch numeric id |
| 1616 | * |
| 1617 | * fit_image_get_arch() finds arch property in a given component image node. |
| 1618 | * If the property is found, its (string) value is translated to the numeric |
| 1619 | * id which is returned to the caller. |
| 1620 | * |
| 1621 | * returns: |
| 1622 | * 0, on success |
| 1623 | * -1, on failure |
| 1624 | */ |
| 1625 | int fit_image_get_arch (const void *fit, int noffset, uint8_t *arch) |
| 1626 | { |
| 1627 | int len; |
| 1628 | const void *data; |
| 1629 | |
| 1630 | /* Get architecture name from property data */ |
| 1631 | data = fdt_getprop (fit, noffset, FIT_ARCH_PROP, &len); |
| 1632 | if (data == NULL) { |
| 1633 | fit_get_debug (fit, noffset, FIT_ARCH_PROP, len); |
| 1634 | *arch = -1; |
| 1635 | return -1; |
| 1636 | } |
| 1637 | |
| 1638 | /* Translate architecture name to id */ |
| 1639 | *arch = genimg_get_arch_id (data); |
| 1640 | return 0; |
| 1641 | } |
| 1642 | |
| 1643 | /** |
| 1644 | * fit_image_get_type - get type id for a given component image node |
| 1645 | * @fit: pointer to the FIT format image header |
| 1646 | * @noffset: component image node offset |
| 1647 | * @type: pointer to the uint8_t, will hold type numeric id |
| 1648 | * |
| 1649 | * fit_image_get_type() finds type property in a given component image node. |
| 1650 | * If the property is found, its (string) value is translated to the numeric |
| 1651 | * id which is returned to the caller. |
| 1652 | * |
| 1653 | * returns: |
| 1654 | * 0, on success |
| 1655 | * -1, on failure |
| 1656 | */ |
| 1657 | int fit_image_get_type (const void *fit, int noffset, uint8_t *type) |
| 1658 | { |
| 1659 | int len; |
| 1660 | const void *data; |
| 1661 | |
| 1662 | /* Get image type name from property data */ |
| 1663 | data = fdt_getprop (fit, noffset, FIT_TYPE_PROP, &len); |
| 1664 | if (data == NULL) { |
| 1665 | fit_get_debug (fit, noffset, FIT_TYPE_PROP, len); |
| 1666 | *type = -1; |
| 1667 | return -1; |
| 1668 | } |
| 1669 | |
| 1670 | /* Translate image type name to id */ |
| 1671 | *type = genimg_get_type_id (data); |
| 1672 | return 0; |
| 1673 | } |
| 1674 | |
| 1675 | /** |
| 1676 | * fit_image_get_comp - get comp id for a given component image node |
| 1677 | * @fit: pointer to the FIT format image header |
| 1678 | * @noffset: component image node offset |
| 1679 | * @comp: pointer to the uint8_t, will hold comp numeric id |
| 1680 | * |
| 1681 | * fit_image_get_comp() finds comp property in a given component image node. |
| 1682 | * If the property is found, its (string) value is translated to the numeric |
| 1683 | * id which is returned to the caller. |
| 1684 | * |
| 1685 | * returns: |
| 1686 | * 0, on success |
| 1687 | * -1, on failure |
| 1688 | */ |
| 1689 | int fit_image_get_comp (const void *fit, int noffset, uint8_t *comp) |
| 1690 | { |
| 1691 | int len; |
| 1692 | const void *data; |
| 1693 | |
| 1694 | /* Get compression name from property data */ |
| 1695 | data = fdt_getprop (fit, noffset, FIT_COMP_PROP, &len); |
| 1696 | if (data == NULL) { |
| 1697 | fit_get_debug (fit, noffset, FIT_COMP_PROP, len); |
| 1698 | *comp = -1; |
| 1699 | return -1; |
| 1700 | } |
| 1701 | |
| 1702 | /* Translate compression name to id */ |
| 1703 | *comp = genimg_get_comp_id (data); |
| 1704 | return 0; |
| 1705 | } |
| 1706 | |
| 1707 | /** |
| 1708 | * fit_image_get_load - get load address property for a given component image node |
| 1709 | * @fit: pointer to the FIT format image header |
| 1710 | * @noffset: component image node offset |
| 1711 | * @load: pointer to the uint32_t, will hold load address |
| 1712 | * |
| 1713 | * fit_image_get_load() finds load address property in a given component image node. |
| 1714 | * If the property is found, its value is returned to the caller. |
| 1715 | * |
| 1716 | * returns: |
| 1717 | * 0, on success |
| 1718 | * -1, on failure |
| 1719 | */ |
| 1720 | int fit_image_get_load (const void *fit, int noffset, ulong *load) |
| 1721 | { |
| 1722 | int len; |
| 1723 | const uint32_t *data; |
| 1724 | |
| 1725 | data = fdt_getprop (fit, noffset, FIT_LOAD_PROP, &len); |
| 1726 | if (data == NULL) { |
| 1727 | fit_get_debug (fit, noffset, FIT_LOAD_PROP, len); |
| 1728 | return -1; |
| 1729 | } |
| 1730 | |
| 1731 | *load = uimage_to_cpu (*data); |
| 1732 | return 0; |
| 1733 | } |
| 1734 | |
| 1735 | /** |
| 1736 | * fit_image_get_entry - get entry point address property for a given component image node |
| 1737 | * @fit: pointer to the FIT format image header |
| 1738 | * @noffset: component image node offset |
| 1739 | * @entry: pointer to the uint32_t, will hold entry point address |
| 1740 | * |
| 1741 | * fit_image_get_entry() finds entry point address property in a given component image node. |
| 1742 | * If the property is found, its value is returned to the caller. |
| 1743 | * |
| 1744 | * returns: |
| 1745 | * 0, on success |
| 1746 | * -1, on failure |
| 1747 | */ |
| 1748 | int fit_image_get_entry (const void *fit, int noffset, ulong *entry) |
| 1749 | { |
| 1750 | int len; |
| 1751 | const uint32_t *data; |
| 1752 | |
| 1753 | data = fdt_getprop (fit, noffset, FIT_ENTRY_PROP, &len); |
| 1754 | if (data == NULL) { |
| 1755 | fit_get_debug (fit, noffset, FIT_ENTRY_PROP, len); |
| 1756 | return -1; |
| 1757 | } |
| 1758 | |
| 1759 | *entry = uimage_to_cpu (*data); |
| 1760 | return 0; |
| 1761 | } |
| 1762 | |
| 1763 | /** |
| 1764 | * fit_image_get_data - get data property and its size for a given component image node |
| 1765 | * @fit: pointer to the FIT format image header |
| 1766 | * @noffset: component image node offset |
| 1767 | * @data: double pointer to void, will hold data property's data address |
| 1768 | * @size: pointer to size_t, will hold data property's data size |
| 1769 | * |
| 1770 | * fit_image_get_data() finds data property in a given component image node. |
| 1771 | * If the property is found its data start address and size are returned to |
| 1772 | * the caller. |
| 1773 | * |
| 1774 | * returns: |
| 1775 | * 0, on success |
| 1776 | * -1, on failure |
| 1777 | */ |
| 1778 | int fit_image_get_data (const void *fit, int noffset, |
| 1779 | const void **data, size_t *size) |
| 1780 | { |
| 1781 | int len; |
| 1782 | |
| 1783 | *data = fdt_getprop (fit, noffset, FIT_DATA_PROP, &len); |
| 1784 | if (*data == NULL) { |
| 1785 | fit_get_debug (fit, noffset, FIT_DATA_PROP, len); |
| 1786 | *size = 0; |
| 1787 | return -1; |
| 1788 | } |
| 1789 | |
| 1790 | *size = len; |
| 1791 | return 0; |
| 1792 | } |
| 1793 | |
| 1794 | /** |
| 1795 | * fit_image_hash_get_algo - get hash algorithm name |
| 1796 | * @fit: pointer to the FIT format image header |
| 1797 | * @noffset: hash node offset |
| 1798 | * @algo: double pointer to char, will hold pointer to the algorithm name |
| 1799 | * |
| 1800 | * fit_image_hash_get_algo() finds hash algorithm property in a given hash node. |
| 1801 | * If the property is found its data start address is returned to the caller. |
| 1802 | * |
| 1803 | * returns: |
| 1804 | * 0, on success |
| 1805 | * -1, on failure |
| 1806 | */ |
| 1807 | int fit_image_hash_get_algo (const void *fit, int noffset, char **algo) |
| 1808 | { |
| 1809 | int len; |
| 1810 | |
| 1811 | *algo = (char *)fdt_getprop (fit, noffset, FIT_ALGO_PROP, &len); |
| 1812 | if (*algo == NULL) { |
| 1813 | fit_get_debug (fit, noffset, FIT_ALGO_PROP, len); |
| 1814 | return -1; |
| 1815 | } |
| 1816 | |
| 1817 | return 0; |
| 1818 | } |
| 1819 | |
| 1820 | /** |
| 1821 | * fit_image_hash_get_value - get hash value and length |
| 1822 | * @fit: pointer to the FIT format image header |
| 1823 | * @noffset: hash node offset |
| 1824 | * @value: double pointer to uint8_t, will hold address of a hash value data |
| 1825 | * @value_len: pointer to an int, will hold hash data length |
| 1826 | * |
| 1827 | * fit_image_hash_get_value() finds hash value property in a given hash node. |
| 1828 | * If the property is found its data start address and size are returned to |
| 1829 | * the caller. |
| 1830 | * |
| 1831 | * returns: |
| 1832 | * 0, on success |
| 1833 | * -1, on failure |
| 1834 | */ |
| 1835 | int fit_image_hash_get_value (const void *fit, int noffset, uint8_t **value, |
| 1836 | int *value_len) |
| 1837 | { |
| 1838 | int len; |
| 1839 | |
| 1840 | *value = (uint8_t *)fdt_getprop (fit, noffset, FIT_VALUE_PROP, &len); |
| 1841 | if (*value == NULL) { |
| 1842 | fit_get_debug (fit, noffset, FIT_VALUE_PROP, len); |
| 1843 | *value_len = 0; |
| 1844 | return -1; |
| 1845 | } |
| 1846 | |
| 1847 | *value_len = len; |
| 1848 | return 0; |
| 1849 | } |
| 1850 | |
| 1851 | /** |
| 1852 | * fit_set_timestamp - set node timestamp property |
| 1853 | * @fit: pointer to the FIT format image header |
| 1854 | * @noffset: node offset |
| 1855 | * @timestamp: timestamp value to be set |
| 1856 | * |
| 1857 | * fit_set_timestamp() attempts to set timestamp property in the requested |
| 1858 | * node and returns operation status to the caller. |
| 1859 | * |
| 1860 | * returns: |
| 1861 | * 0, on success |
| 1862 | * -1, on property read failure |
| 1863 | */ |
| 1864 | int fit_set_timestamp (void *fit, int noffset, time_t timestamp) |
| 1865 | { |
| 1866 | uint32_t t; |
| 1867 | int ret; |
| 1868 | |
| 1869 | t = cpu_to_uimage (timestamp); |
| 1870 | ret = fdt_setprop (fit, noffset, FIT_TIMESTAMP_PROP, &t, |
| 1871 | sizeof (uint32_t)); |
| 1872 | if (ret) { |
| 1873 | printf ("Can't set '%s' property for '%s' node (%s)\n", |
| 1874 | FIT_TIMESTAMP_PROP, fit_get_name (fit, noffset, NULL), |
| 1875 | fdt_strerror (ret)); |
| 1876 | return -1; |
| 1877 | } |
| 1878 | |
| 1879 | return 0; |
| 1880 | } |
| 1881 | |
| 1882 | /** |
| 1883 | * calculate_hash - calculate and return hash for provided input data |
| 1884 | * @data: pointer to the input data |
| 1885 | * @data_len: data length |
| 1886 | * @algo: requested hash algorithm |
| 1887 | * @value: pointer to the char, will hold hash value data (caller must |
| 1888 | * allocate enough free space) |
| 1889 | * value_len: length of the calculated hash |
| 1890 | * |
| 1891 | * calculate_hash() computes input data hash according to the requested algorithm. |
| 1892 | * Resulting hash value is placed in caller provided 'value' buffer, length |
| 1893 | * of the calculated hash is returned via value_len pointer argument. |
| 1894 | * |
| 1895 | * returns: |
| 1896 | * 0, on success |
| 1897 | * -1, when algo is unsupported |
| 1898 | */ |
| 1899 | static int calculate_hash (const void *data, int data_len, const char *algo, |
| 1900 | uint8_t *value, int *value_len) |
| 1901 | { |
| 1902 | if (strcmp (algo, "crc32") == 0 ) { |
Bartlomiej Sieka | 7590378 | 2008-04-25 13:54:02 +0200 | [diff] [blame] | 1903 | *((uint32_t *)value) = crc32_wd (0, data, data_len, |
| 1904 | CHUNKSZ_CRC32); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1905 | *((uint32_t *)value) = cpu_to_uimage (*((uint32_t *)value)); |
| 1906 | *value_len = 4; |
| 1907 | } else if (strcmp (algo, "sha1") == 0 ) { |
Bartlomiej Sieka | 7590378 | 2008-04-25 13:54:02 +0200 | [diff] [blame] | 1908 | sha1_csum_wd ((unsigned char *) data, data_len, |
| 1909 | (unsigned char *) value, CHUNKSZ_SHA1); |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1910 | *value_len = 20; |
| 1911 | } else if (strcmp (algo, "md5") == 0 ) { |
Bartlomiej Sieka | 7590378 | 2008-04-25 13:54:02 +0200 | [diff] [blame] | 1912 | md5_wd ((unsigned char *)data, data_len, value, CHUNKSZ_MD5); |
Bartlomiej Sieka | 766529f | 2008-03-14 16:22:34 +0100 | [diff] [blame] | 1913 | *value_len = 16; |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 1914 | } else { |
| 1915 | debug ("Unsupported hash alogrithm\n"); |
| 1916 | return -1; |
| 1917 | } |
| 1918 | return 0; |
| 1919 | } |
| 1920 | |
| 1921 | #ifdef USE_HOSTCC |
| 1922 | /** |
| 1923 | * fit_set_hashes - process FIT component image nodes and calculate hashes |
| 1924 | * @fit: pointer to the FIT format image header |
| 1925 | * |
| 1926 | * fit_set_hashes() adds hash values for all component images in the FIT blob. |
| 1927 | * Hashes are calculated for all component images which have hash subnodes |
| 1928 | * with algorithm property set to one of the supported hash algorithms. |
| 1929 | * |
| 1930 | * returns |
| 1931 | * 0, on success |
| 1932 | * libfdt error code, on failure |
| 1933 | */ |
| 1934 | int fit_set_hashes (void *fit) |
| 1935 | { |
| 1936 | int images_noffset; |
| 1937 | int noffset; |
| 1938 | int ndepth; |
| 1939 | int ret; |
| 1940 | |
| 1941 | /* Find images parent node offset */ |
| 1942 | images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH); |
| 1943 | if (images_noffset < 0) { |
| 1944 | printf ("Can't find images parent node '%s' (%s)\n", |
| 1945 | FIT_IMAGES_PATH, fdt_strerror (images_noffset)); |
| 1946 | return images_noffset; |
| 1947 | } |
| 1948 | |
| 1949 | /* Process its subnodes, print out component images details */ |
| 1950 | for (ndepth = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth); |
| 1951 | (noffset >= 0) && (ndepth > 0); |
| 1952 | noffset = fdt_next_node (fit, noffset, &ndepth)) { |
| 1953 | if (ndepth == 1) { |
| 1954 | /* |
| 1955 | * Direct child node of the images parent node, |
| 1956 | * i.e. component image node. |
| 1957 | */ |
| 1958 | ret = fit_image_set_hashes (fit, noffset); |
| 1959 | if (ret) |
| 1960 | return ret; |
| 1961 | } |
| 1962 | } |
| 1963 | |
| 1964 | return 0; |
| 1965 | } |
| 1966 | |
| 1967 | /** |
| 1968 | * fit_image_set_hashes - calculate/set hashes for given component image node |
| 1969 | * @fit: pointer to the FIT format image header |
| 1970 | * @image_noffset: requested component image node |
| 1971 | * |
| 1972 | * fit_image_set_hashes() adds hash values for an component image node. All |
| 1973 | * existing hash subnodes are checked, if algorithm property is set to one of |
| 1974 | * the supported hash algorithms, hash value is computed and corresponding |
| 1975 | * hash node property is set, for example: |
| 1976 | * |
| 1977 | * Input component image node structure: |
| 1978 | * |
| 1979 | * o image@1 (at image_noffset) |
| 1980 | * | - data = [binary data] |
| 1981 | * o hash@1 |
| 1982 | * |- algo = "sha1" |
| 1983 | * |
| 1984 | * Output component image node structure: |
| 1985 | * |
| 1986 | * o image@1 (at image_noffset) |
| 1987 | * | - data = [binary data] |
| 1988 | * o hash@1 |
| 1989 | * |- algo = "sha1" |
| 1990 | * |- value = sha1(data) |
| 1991 | * |
| 1992 | * returns: |
| 1993 | * 0 on sucess |
| 1994 | * <0 on failure |
| 1995 | */ |
| 1996 | int fit_image_set_hashes (void *fit, int image_noffset) |
| 1997 | { |
| 1998 | const void *data; |
| 1999 | size_t size; |
| 2000 | char *algo; |
| 2001 | uint8_t value[FIT_MAX_HASH_LEN]; |
| 2002 | int value_len; |
| 2003 | int noffset; |
| 2004 | int ndepth; |
| 2005 | |
| 2006 | /* Get image data and data length */ |
| 2007 | if (fit_image_get_data (fit, image_noffset, &data, &size)) { |
| 2008 | printf ("Can't get image data/size\n"); |
| 2009 | return -1; |
| 2010 | } |
| 2011 | |
| 2012 | /* Process all hash subnodes of the component image node */ |
| 2013 | for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth); |
| 2014 | (noffset >= 0) && (ndepth > 0); |
| 2015 | noffset = fdt_next_node (fit, noffset, &ndepth)) { |
| 2016 | if (ndepth == 1) { |
| 2017 | /* Direct child node of the component image node */ |
| 2018 | |
| 2019 | /* |
| 2020 | * Check subnode name, must be equal to "hash". |
| 2021 | * Multiple hash nodes require unique unit node |
| 2022 | * names, e.g. hash@1, hash@2, etc. |
| 2023 | */ |
| 2024 | if (strncmp (fit_get_name(fit, noffset, NULL), |
| 2025 | FIT_HASH_NODENAME, |
| 2026 | strlen(FIT_HASH_NODENAME)) != 0) { |
| 2027 | /* Not a hash subnode, skip it */ |
| 2028 | continue; |
| 2029 | } |
| 2030 | |
| 2031 | if (fit_image_hash_get_algo (fit, noffset, &algo)) { |
| 2032 | printf ("Can't get hash algo property for " |
| 2033 | "'%s' hash node in '%s' image node\n", |
| 2034 | fit_get_name (fit, noffset, NULL), |
| 2035 | fit_get_name (fit, image_noffset, NULL)); |
| 2036 | return -1; |
| 2037 | } |
| 2038 | |
| 2039 | if (calculate_hash (data, size, algo, value, &value_len)) { |
| 2040 | printf ("Unsupported hash algorithm (%s) for " |
| 2041 | "'%s' hash node in '%s' image node\n", |
| 2042 | algo, fit_get_name (fit, noffset, NULL), |
| 2043 | fit_get_name (fit, image_noffset, NULL)); |
| 2044 | return -1; |
| 2045 | } |
| 2046 | |
| 2047 | if (fit_image_hash_set_value (fit, noffset, value, |
| 2048 | value_len)) { |
| 2049 | printf ("Can't set hash value for " |
| 2050 | "'%s' hash node in '%s' image node\n", |
| 2051 | fit_get_name (fit, noffset, NULL), |
| 2052 | fit_get_name (fit, image_noffset, NULL)); |
| 2053 | return -1; |
| 2054 | } |
| 2055 | } |
| 2056 | } |
| 2057 | |
| 2058 | return 0; |
| 2059 | } |
| 2060 | |
| 2061 | /** |
| 2062 | * fit_image_hash_set_value - set hash value in requested has node |
| 2063 | * @fit: pointer to the FIT format image header |
| 2064 | * @noffset: hash node offset |
| 2065 | * @value: hash value to be set |
| 2066 | * @value_len: hash value length |
| 2067 | * |
| 2068 | * fit_image_hash_set_value() attempts to set hash value in a node at offset |
| 2069 | * given and returns operation status to the caller. |
| 2070 | * |
| 2071 | * returns |
| 2072 | * 0, on success |
| 2073 | * -1, on failure |
| 2074 | */ |
| 2075 | int fit_image_hash_set_value (void *fit, int noffset, uint8_t *value, |
| 2076 | int value_len) |
| 2077 | { |
| 2078 | int ret; |
| 2079 | |
| 2080 | ret = fdt_setprop (fit, noffset, FIT_VALUE_PROP, value, value_len); |
| 2081 | if (ret) { |
| 2082 | printf ("Can't set hash '%s' property for '%s' node (%s)\n", |
| 2083 | FIT_VALUE_PROP, fit_get_name (fit, noffset, NULL), |
| 2084 | fdt_strerror (ret)); |
| 2085 | return -1; |
| 2086 | } |
| 2087 | |
| 2088 | return 0; |
| 2089 | } |
| 2090 | #endif /* USE_HOSTCC */ |
| 2091 | |
| 2092 | /** |
| 2093 | * fit_image_check_hashes - verify data intergity |
| 2094 | * @fit: pointer to the FIT format image header |
| 2095 | * @image_noffset: component image node offset |
| 2096 | * |
| 2097 | * fit_image_check_hashes() goes over component image hash nodes, |
| 2098 | * re-calculates each data hash and compares with the value stored in hash |
| 2099 | * node. |
| 2100 | * |
| 2101 | * returns: |
| 2102 | * 1, if all hashes are valid |
| 2103 | * 0, otherwise (or on error) |
| 2104 | */ |
| 2105 | int fit_image_check_hashes (const void *fit, int image_noffset) |
| 2106 | { |
| 2107 | const void *data; |
| 2108 | size_t size; |
| 2109 | char *algo; |
| 2110 | uint8_t *fit_value; |
| 2111 | int fit_value_len; |
| 2112 | uint8_t value[FIT_MAX_HASH_LEN]; |
| 2113 | int value_len; |
| 2114 | int noffset; |
| 2115 | int ndepth; |
| 2116 | char *err_msg = ""; |
| 2117 | |
| 2118 | /* Get image data and data length */ |
| 2119 | if (fit_image_get_data (fit, image_noffset, &data, &size)) { |
| 2120 | printf ("Can't get image data/size\n"); |
| 2121 | return 0; |
| 2122 | } |
| 2123 | |
| 2124 | /* Process all hash subnodes of the component image node */ |
| 2125 | for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth); |
| 2126 | (noffset >= 0) && (ndepth > 0); |
| 2127 | noffset = fdt_next_node (fit, noffset, &ndepth)) { |
| 2128 | if (ndepth == 1) { |
| 2129 | /* Direct child node of the component image node */ |
| 2130 | |
| 2131 | /* |
| 2132 | * Check subnode name, must be equal to "hash". |
| 2133 | * Multiple hash nodes require unique unit node |
| 2134 | * names, e.g. hash@1, hash@2, etc. |
| 2135 | */ |
| 2136 | if (strncmp (fit_get_name(fit, noffset, NULL), |
| 2137 | FIT_HASH_NODENAME, |
| 2138 | strlen(FIT_HASH_NODENAME)) != 0) |
| 2139 | continue; |
| 2140 | |
| 2141 | if (fit_image_hash_get_algo (fit, noffset, &algo)) { |
| 2142 | err_msg = "Can't get hash algo property"; |
| 2143 | goto error; |
| 2144 | } |
| 2145 | printf ("%s", algo); |
| 2146 | |
| 2147 | if (fit_image_hash_get_value (fit, noffset, &fit_value, |
| 2148 | &fit_value_len)) { |
| 2149 | err_msg = "Can't get hash value property"; |
| 2150 | goto error; |
| 2151 | } |
| 2152 | |
| 2153 | if (calculate_hash (data, size, algo, value, &value_len)) { |
| 2154 | err_msg = "Unsupported hash algorithm"; |
| 2155 | goto error; |
| 2156 | } |
| 2157 | |
| 2158 | if (value_len != fit_value_len) { |
| 2159 | err_msg = "Bad hash value len"; |
| 2160 | goto error; |
| 2161 | } else if (memcmp (value, fit_value, value_len) != 0) { |
| 2162 | err_msg = "Bad hash value"; |
| 2163 | goto error; |
| 2164 | } |
| 2165 | printf ("+ "); |
| 2166 | } |
| 2167 | } |
| 2168 | |
| 2169 | return 1; |
| 2170 | |
| 2171 | error: |
| 2172 | printf ("%s for '%s' hash node in '%s' image node\n", |
| 2173 | err_msg, fit_get_name (fit, noffset, NULL), |
| 2174 | fit_get_name (fit, image_noffset, NULL)); |
| 2175 | return 0; |
| 2176 | } |
| 2177 | |
| 2178 | /** |
| 2179 | * fit_image_check_os - check whether image node is of a given os type |
| 2180 | * @fit: pointer to the FIT format image header |
| 2181 | * @noffset: component image node offset |
| 2182 | * @os: requested image os |
| 2183 | * |
| 2184 | * fit_image_check_os() reads image os property and compares its numeric |
| 2185 | * id with the requested os. Comparison result is returned to the caller. |
| 2186 | * |
| 2187 | * returns: |
| 2188 | * 1 if image is of given os type |
| 2189 | * 0 otherwise (or on error) |
| 2190 | */ |
| 2191 | int fit_image_check_os (const void *fit, int noffset, uint8_t os) |
| 2192 | { |
| 2193 | uint8_t image_os; |
| 2194 | |
| 2195 | if (fit_image_get_os (fit, noffset, &image_os)) |
| 2196 | return 0; |
| 2197 | return (os == image_os); |
| 2198 | } |
| 2199 | |
| 2200 | /** |
| 2201 | * fit_image_check_arch - check whether image node is of a given arch |
| 2202 | * @fit: pointer to the FIT format image header |
| 2203 | * @noffset: component image node offset |
| 2204 | * @arch: requested imagearch |
| 2205 | * |
| 2206 | * fit_image_check_arch() reads image arch property and compares its numeric |
| 2207 | * id with the requested arch. Comparison result is returned to the caller. |
| 2208 | * |
| 2209 | * returns: |
| 2210 | * 1 if image is of given arch |
| 2211 | * 0 otherwise (or on error) |
| 2212 | */ |
| 2213 | int fit_image_check_arch (const void *fit, int noffset, uint8_t arch) |
| 2214 | { |
| 2215 | uint8_t image_arch; |
| 2216 | |
| 2217 | if (fit_image_get_arch (fit, noffset, &image_arch)) |
| 2218 | return 0; |
| 2219 | return (arch == image_arch); |
| 2220 | } |
| 2221 | |
| 2222 | /** |
| 2223 | * fit_image_check_type - check whether image node is of a given type |
| 2224 | * @fit: pointer to the FIT format image header |
| 2225 | * @noffset: component image node offset |
| 2226 | * @type: requested image type |
| 2227 | * |
| 2228 | * fit_image_check_type() reads image type property and compares its numeric |
| 2229 | * id with the requested type. Comparison result is returned to the caller. |
| 2230 | * |
| 2231 | * returns: |
| 2232 | * 1 if image is of given type |
| 2233 | * 0 otherwise (or on error) |
| 2234 | */ |
| 2235 | int fit_image_check_type (const void *fit, int noffset, uint8_t type) |
| 2236 | { |
| 2237 | uint8_t image_type; |
| 2238 | |
| 2239 | if (fit_image_get_type (fit, noffset, &image_type)) |
| 2240 | return 0; |
| 2241 | return (type == image_type); |
| 2242 | } |
| 2243 | |
| 2244 | /** |
| 2245 | * fit_image_check_comp - check whether image node uses given compression |
| 2246 | * @fit: pointer to the FIT format image header |
| 2247 | * @noffset: component image node offset |
| 2248 | * @comp: requested image compression type |
| 2249 | * |
| 2250 | * fit_image_check_comp() reads image compression property and compares its |
| 2251 | * numeric id with the requested compression type. Comparison result is |
| 2252 | * returned to the caller. |
| 2253 | * |
| 2254 | * returns: |
| 2255 | * 1 if image uses requested compression |
| 2256 | * 0 otherwise (or on error) |
| 2257 | */ |
| 2258 | int fit_image_check_comp (const void *fit, int noffset, uint8_t comp) |
| 2259 | { |
| 2260 | uint8_t image_comp; |
| 2261 | |
| 2262 | if (fit_image_get_comp (fit, noffset, &image_comp)) |
| 2263 | return 0; |
| 2264 | return (comp == image_comp); |
| 2265 | } |
| 2266 | |
| 2267 | /** |
| 2268 | * fit_check_format - sanity check FIT image format |
| 2269 | * @fit: pointer to the FIT format image header |
| 2270 | * |
| 2271 | * fit_check_format() runs a basic sanity FIT image verification. |
| 2272 | * Routine checks for mandatory properties, nodes, etc. |
| 2273 | * |
| 2274 | * returns: |
| 2275 | * 1, on success |
| 2276 | * 0, on failure |
| 2277 | */ |
| 2278 | int fit_check_format (const void *fit) |
| 2279 | { |
| 2280 | /* mandatory / node 'description' property */ |
| 2281 | if (fdt_getprop (fit, 0, FIT_DESC_PROP, NULL) == NULL) { |
| 2282 | debug ("Wrong FIT format: no description\n"); |
| 2283 | return 0; |
| 2284 | } |
| 2285 | |
| 2286 | #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) |
| 2287 | /* mandatory / node 'timestamp' property */ |
| 2288 | if (fdt_getprop (fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) { |
| 2289 | debug ("Wrong FIT format: no description\n"); |
| 2290 | return 0; |
| 2291 | } |
| 2292 | #endif |
| 2293 | |
| 2294 | /* mandatory subimages parent '/images' node */ |
| 2295 | if (fdt_path_offset (fit, FIT_IMAGES_PATH) < 0) { |
| 2296 | debug ("Wrong FIT format: no images parent node\n"); |
| 2297 | return 0; |
| 2298 | } |
| 2299 | |
| 2300 | return 1; |
| 2301 | } |
| 2302 | |
| 2303 | /** |
| 2304 | * fit_conf_get_node - get node offset for configuration of a given unit name |
| 2305 | * @fit: pointer to the FIT format image header |
| 2306 | * @conf_uname: configuration node unit name |
| 2307 | * |
| 2308 | * fit_conf_get_node() finds a configuration (withing the '/configurations' |
| 2309 | * parant node) of a provided unit name. If configuration is found its node offset |
| 2310 | * is returned to the caller. |
| 2311 | * |
| 2312 | * When NULL is provided in second argument fit_conf_get_node() will search |
| 2313 | * for a default configuration node instead. Default configuration node unit name |
| 2314 | * is retrived from FIT_DEFAULT_PROP property of the '/configurations' node. |
| 2315 | * |
| 2316 | * returns: |
| 2317 | * configuration node offset when found (>=0) |
| 2318 | * negative number on failure (FDT_ERR_* code) |
| 2319 | */ |
| 2320 | int fit_conf_get_node (const void *fit, const char *conf_uname) |
| 2321 | { |
| 2322 | int noffset, confs_noffset; |
| 2323 | int len; |
| 2324 | |
| 2325 | confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH); |
| 2326 | if (confs_noffset < 0) { |
| 2327 | debug ("Can't find configurations parent node '%s' (%s)\n", |
| 2328 | FIT_CONFS_PATH, fdt_strerror (confs_noffset)); |
| 2329 | return confs_noffset; |
| 2330 | } |
| 2331 | |
| 2332 | if (conf_uname == NULL) { |
| 2333 | /* get configuration unit name from the default property */ |
| 2334 | debug ("No configuration specified, trying default...\n"); |
| 2335 | conf_uname = (char *)fdt_getprop (fit, confs_noffset, FIT_DEFAULT_PROP, &len); |
| 2336 | if (conf_uname == NULL) { |
| 2337 | fit_get_debug (fit, confs_noffset, FIT_DEFAULT_PROP, len); |
| 2338 | return len; |
| 2339 | } |
| 2340 | debug ("Found default configuration: '%s'\n", conf_uname); |
| 2341 | } |
| 2342 | |
| 2343 | noffset = fdt_subnode_offset (fit, confs_noffset, conf_uname); |
| 2344 | if (noffset < 0) { |
| 2345 | debug ("Can't get node offset for configuration unit name: '%s' (%s)\n", |
| 2346 | conf_uname, fdt_strerror (noffset)); |
| 2347 | } |
| 2348 | |
| 2349 | return noffset; |
| 2350 | } |
| 2351 | |
| 2352 | static int __fit_conf_get_prop_node (const void *fit, int noffset, |
| 2353 | const char *prop_name) |
| 2354 | { |
| 2355 | char *uname; |
| 2356 | int len; |
| 2357 | |
| 2358 | /* get kernel image unit name from configuration kernel property */ |
| 2359 | uname = (char *)fdt_getprop (fit, noffset, prop_name, &len); |
| 2360 | if (uname == NULL) |
| 2361 | return len; |
| 2362 | |
| 2363 | return fit_image_get_node (fit, uname); |
| 2364 | } |
| 2365 | |
| 2366 | /** |
| 2367 | * fit_conf_get_kernel_node - get kernel image node offset that corresponds to |
| 2368 | * a given configuration |
| 2369 | * @fit: pointer to the FIT format image header |
| 2370 | * @noffset: configuration node offset |
| 2371 | * |
| 2372 | * fit_conf_get_kernel_node() retrives kernel image node unit name from |
| 2373 | * configuration FIT_KERNEL_PROP property and translates it to the node |
| 2374 | * offset. |
| 2375 | * |
| 2376 | * returns: |
| 2377 | * image node offset when found (>=0) |
| 2378 | * negative number on failure (FDT_ERR_* code) |
| 2379 | */ |
| 2380 | int fit_conf_get_kernel_node (const void *fit, int noffset) |
| 2381 | { |
| 2382 | return __fit_conf_get_prop_node (fit, noffset, FIT_KERNEL_PROP); |
| 2383 | } |
| 2384 | |
| 2385 | /** |
| 2386 | * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to |
| 2387 | * a given configuration |
| 2388 | * @fit: pointer to the FIT format image header |
| 2389 | * @noffset: configuration node offset |
| 2390 | * |
| 2391 | * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from |
| 2392 | * configuration FIT_KERNEL_PROP property and translates it to the node |
| 2393 | * offset. |
| 2394 | * |
| 2395 | * returns: |
| 2396 | * image node offset when found (>=0) |
| 2397 | * negative number on failure (FDT_ERR_* code) |
| 2398 | */ |
| 2399 | int fit_conf_get_ramdisk_node (const void *fit, int noffset) |
| 2400 | { |
| 2401 | return __fit_conf_get_prop_node (fit, noffset, FIT_RAMDISK_PROP); |
| 2402 | } |
| 2403 | |
| 2404 | /** |
| 2405 | * fit_conf_get_fdt_node - get fdt image node offset that corresponds to |
| 2406 | * a given configuration |
| 2407 | * @fit: pointer to the FIT format image header |
| 2408 | * @noffset: configuration node offset |
| 2409 | * |
| 2410 | * fit_conf_get_fdt_node() retrives fdt image node unit name from |
| 2411 | * configuration FIT_KERNEL_PROP property and translates it to the node |
| 2412 | * offset. |
| 2413 | * |
| 2414 | * returns: |
| 2415 | * image node offset when found (>=0) |
| 2416 | * negative number on failure (FDT_ERR_* code) |
| 2417 | */ |
| 2418 | int fit_conf_get_fdt_node (const void *fit, int noffset) |
| 2419 | { |
| 2420 | return __fit_conf_get_prop_node (fit, noffset, FIT_FDT_PROP); |
| 2421 | } |
| 2422 | |
| 2423 | /** |
| 2424 | * fit_conf_print - prints out the FIT configuration details |
| 2425 | * @fit: pointer to the FIT format image header |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 2426 | * @noffset: offset of the configuration node |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2427 | * @p: pointer to prefix string |
| 2428 | * |
| 2429 | * fit_conf_print() lists all mandatory properies for the processed |
| 2430 | * configuration node. |
| 2431 | * |
| 2432 | * returns: |
| 2433 | * no returned results |
| 2434 | */ |
| 2435 | void fit_conf_print (const void *fit, int noffset, const char *p) |
| 2436 | { |
| 2437 | char *desc; |
| 2438 | char *uname; |
| 2439 | int ret; |
| 2440 | |
| 2441 | /* Mandatory properties */ |
| 2442 | ret = fit_get_desc (fit, noffset, &desc); |
| 2443 | printf ("%s Description: ", p); |
| 2444 | if (ret) |
| 2445 | printf ("unavailable\n"); |
| 2446 | else |
| 2447 | printf ("%s\n", desc); |
| 2448 | |
| 2449 | uname = (char *)fdt_getprop (fit, noffset, FIT_KERNEL_PROP, NULL); |
| 2450 | printf ("%s Kernel: ", p); |
| 2451 | if (uname == NULL) |
| 2452 | printf ("unavailable\n"); |
| 2453 | else |
| 2454 | printf ("%s\n", uname); |
| 2455 | |
| 2456 | /* Optional properties */ |
| 2457 | uname = (char *)fdt_getprop (fit, noffset, FIT_RAMDISK_PROP, NULL); |
| 2458 | if (uname) |
| 2459 | printf ("%s Init Ramdisk: %s\n", p, uname); |
| 2460 | |
| 2461 | uname = (char *)fdt_getprop (fit, noffset, FIT_FDT_PROP, NULL); |
| 2462 | if (uname) |
| 2463 | printf ("%s FDT: %s\n", p, uname); |
| 2464 | } |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 2465 | |
| 2466 | /** |
| 2467 | * fit_check_ramdisk - verify FIT format ramdisk subimage |
| 2468 | * @fit_hdr: pointer to the FIT ramdisk header |
| 2469 | * @rd_noffset: ramdisk subimage node offset within FIT image |
| 2470 | * @arch: requested ramdisk image architecture type |
| 2471 | * @verify: data CRC verification flag |
| 2472 | * |
| 2473 | * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from |
| 2474 | * specified FIT image. |
| 2475 | * |
| 2476 | * returns: |
| 2477 | * 1, on success |
| 2478 | * 0, on failure |
| 2479 | */ |
| 2480 | #ifndef USE_HOSTCC |
| 2481 | static int fit_check_ramdisk (const void *fit, int rd_noffset, uint8_t arch, int verify) |
| 2482 | { |
| 2483 | fit_image_print (fit, rd_noffset, " "); |
| 2484 | |
| 2485 | if (verify) { |
| 2486 | puts (" Verifying Hash Integrity ... "); |
| 2487 | if (!fit_image_check_hashes (fit, rd_noffset)) { |
| 2488 | puts ("Bad Data Hash\n"); |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 2489 | show_boot_progress (-125); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 2490 | return 0; |
| 2491 | } |
| 2492 | puts ("OK\n"); |
| 2493 | } |
| 2494 | |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 2495 | show_boot_progress (126); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 2496 | if (!fit_image_check_os (fit, rd_noffset, IH_OS_LINUX) || |
| 2497 | !fit_image_check_arch (fit, rd_noffset, arch) || |
| 2498 | !fit_image_check_type (fit, rd_noffset, IH_TYPE_RAMDISK)) { |
| 2499 | printf ("No Linux %s Ramdisk Image\n", |
| 2500 | genimg_get_arch_name(arch)); |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 2501 | show_boot_progress (-126); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 2502 | return 0; |
| 2503 | } |
| 2504 | |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 2505 | show_boot_progress (127); |
Marian Balakowicz | c877964 | 2008-03-12 10:12:37 +0100 | [diff] [blame] | 2506 | return 1; |
| 2507 | } |
| 2508 | #endif /* USE_HOSTCC */ |
Marian Balakowicz | 5dfb521 | 2008-02-29 21:24:06 +0100 | [diff] [blame] | 2509 | #endif /* CONFIG_FIT */ |