Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013, Google Inc. |
| 4 | * |
| 5 | * (C) Copyright 2008 Semihalf |
| 6 | * |
| 7 | * (C) Copyright 2000-2006 |
| 8 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Simon Glass | c581970 | 2021-02-15 17:08:09 -0700 | [diff] [blame] | 11 | #define LOG_CATEGORY LOGC_BOOT |
| 12 | |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 13 | #ifdef USE_HOSTCC |
| 14 | #include "mkimage.h" |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 15 | #include <time.h> |
Simon Glass | 4d72caa | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 16 | #include <linux/libfdt.h> |
Simon Glass | 3db7110 | 2019-11-14 12:57:16 -0700 | [diff] [blame] | 17 | #include <u-boot/crc.h> |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 18 | #else |
Andreas Dannenberg | eba3fbd | 2016-07-27 12:12:39 -0500 | [diff] [blame] | 19 | #include <linux/compiler.h> |
Marek Vasut | 4c531d9 | 2021-06-11 04:09:56 +0200 | [diff] [blame] | 20 | #include <linux/sizes.h> |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 21 | #include <common.h> |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 22 | #include <errno.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 23 | #include <log.h> |
Joe Hershberger | 0eb25b6 | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 24 | #include <mapmem.h> |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 25 | #include <asm/io.h> |
Pantelis Antoniou | 169043d | 2017-09-04 23:12:16 +0300 | [diff] [blame] | 26 | #include <malloc.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 27 | #include <asm/global_data.h> |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 28 | DECLARE_GLOBAL_DATA_PTR; |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 29 | #endif /* !USE_HOSTCC*/ |
| 30 | |
Julius Werner | b1307f8 | 2019-07-24 19:37:55 -0700 | [diff] [blame] | 31 | #include <bootm.h> |
Andreas Dannenberg | eba3fbd | 2016-07-27 12:12:39 -0500 | [diff] [blame] | 32 | #include <image.h> |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 33 | #include <bootstage.h> |
Sebastian Reichel | f14e6ee | 2021-01-04 20:48:03 +0100 | [diff] [blame] | 34 | #include <linux/kconfig.h> |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 35 | #include <u-boot/crc.h> |
| 36 | #include <u-boot/md5.h> |
Jeroen Hofstee | 2b9912e | 2014-06-12 22:27:12 +0200 | [diff] [blame] | 37 | #include <u-boot/sha1.h> |
| 38 | #include <u-boot/sha256.h> |
Reuben Dowle | d16b38f | 2020-04-16 17:36:52 +1200 | [diff] [blame] | 39 | #include <u-boot/sha512.h> |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 40 | |
| 41 | /*****************************************************************************/ |
| 42 | /* New uImage format routines */ |
| 43 | /*****************************************************************************/ |
| 44 | #ifndef USE_HOSTCC |
| 45 | static int fit_parse_spec(const char *spec, char sepc, ulong addr_curr, |
| 46 | ulong *addr, const char **name) |
| 47 | { |
| 48 | const char *sep; |
| 49 | |
| 50 | *addr = addr_curr; |
| 51 | *name = NULL; |
| 52 | |
| 53 | sep = strchr(spec, sepc); |
| 54 | if (sep) { |
| 55 | if (sep - spec > 0) |
Simon Glass | 7e5f460 | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 56 | *addr = hextoul(spec, NULL); |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 57 | |
| 58 | *name = sep + 1; |
| 59 | return 1; |
| 60 | } |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * fit_parse_conf - parse FIT configuration spec |
| 67 | * @spec: input string, containing configuration spec |
| 68 | * @add_curr: current image address (to be used as a possible default) |
| 69 | * @addr: pointer to a ulong variable, will hold FIT image address of a given |
| 70 | * configuration |
| 71 | * @conf_name double pointer to a char, will hold pointer to a configuration |
| 72 | * unit name |
| 73 | * |
Masahiro Yamada | 069d594 | 2013-09-18 09:36:38 +0900 | [diff] [blame] | 74 | * fit_parse_conf() expects configuration spec in the form of [<addr>]#<conf>, |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 75 | * where <addr> is a FIT image address that contains configuration |
| 76 | * with a <conf> unit name. |
| 77 | * |
| 78 | * Address part is optional, and if omitted default add_curr will |
| 79 | * be used instead. |
| 80 | * |
| 81 | * returns: |
| 82 | * 1 if spec is a valid configuration string, |
| 83 | * addr and conf_name are set accordingly |
| 84 | * 0 otherwise |
| 85 | */ |
| 86 | int fit_parse_conf(const char *spec, ulong addr_curr, |
| 87 | ulong *addr, const char **conf_name) |
| 88 | { |
| 89 | return fit_parse_spec(spec, '#', addr_curr, addr, conf_name); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * fit_parse_subimage - parse FIT subimage spec |
| 94 | * @spec: input string, containing subimage spec |
| 95 | * @add_curr: current image address (to be used as a possible default) |
| 96 | * @addr: pointer to a ulong variable, will hold FIT image address of a given |
| 97 | * subimage |
| 98 | * @image_name: double pointer to a char, will hold pointer to a subimage name |
| 99 | * |
Masahiro Yamada | 069d594 | 2013-09-18 09:36:38 +0900 | [diff] [blame] | 100 | * fit_parse_subimage() expects subimage spec in the form of |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 101 | * [<addr>]:<subimage>, where <addr> is a FIT image address that contains |
| 102 | * subimage with a <subimg> unit name. |
| 103 | * |
| 104 | * Address part is optional, and if omitted default add_curr will |
| 105 | * be used instead. |
| 106 | * |
| 107 | * returns: |
| 108 | * 1 if spec is a valid subimage string, |
| 109 | * addr and image_name are set accordingly |
| 110 | * 0 otherwise |
| 111 | */ |
| 112 | int fit_parse_subimage(const char *spec, ulong addr_curr, |
| 113 | ulong *addr, const char **image_name) |
| 114 | { |
| 115 | return fit_parse_spec(spec, ':', addr_curr, addr, image_name); |
| 116 | } |
| 117 | #endif /* !USE_HOSTCC */ |
| 118 | |
Joel Stanley | 93af80f | 2020-12-08 14:42:14 +1030 | [diff] [blame] | 119 | #ifdef USE_HOSTCC |
| 120 | /* Host tools use these implementations for Cipher and Signature support */ |
| 121 | static void *host_blob; |
| 122 | |
| 123 | void image_set_host_blob(void *blob) |
| 124 | { |
| 125 | host_blob = blob; |
| 126 | } |
| 127 | |
| 128 | void *image_get_host_blob(void) |
| 129 | { |
| 130 | return host_blob; |
| 131 | } |
| 132 | #endif /* USE_HOSTCC */ |
| 133 | |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 134 | static void fit_get_debug(const void *fit, int noffset, |
| 135 | char *prop_name, int err) |
| 136 | { |
| 137 | debug("Can't get '%s' property from FIT 0x%08lx, node: offset %d, name %s (%s)\n", |
| 138 | prop_name, (ulong)fit, noffset, fit_get_name(fit, noffset, NULL), |
| 139 | fdt_strerror(err)); |
| 140 | } |
| 141 | |
Guilherme Maciel Ferreira | 39931f9 | 2015-01-15 02:54:42 -0200 | [diff] [blame] | 142 | /** |
| 143 | * fit_get_subimage_count - get component (sub-image) count |
| 144 | * @fit: pointer to the FIT format image header |
| 145 | * @images_noffset: offset of images node |
| 146 | * |
| 147 | * returns: |
| 148 | * number of image components |
| 149 | */ |
| 150 | int fit_get_subimage_count(const void *fit, int images_noffset) |
| 151 | { |
| 152 | int noffset; |
| 153 | int ndepth; |
| 154 | int count = 0; |
| 155 | |
| 156 | /* Process its subnodes, print out component images details */ |
| 157 | for (ndepth = 0, count = 0, |
| 158 | noffset = fdt_next_node(fit, images_noffset, &ndepth); |
| 159 | (noffset >= 0) && (ndepth > 0); |
| 160 | noffset = fdt_next_node(fit, noffset, &ndepth)) { |
| 161 | if (ndepth == 1) { |
| 162 | count++; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | return count; |
| 167 | } |
| 168 | |
Ravik Hasija | 7a01882 | 2021-01-27 14:01:48 -0800 | [diff] [blame] | 169 | #if CONFIG_IS_ENABLED(FIT_PRINT) || CONFIG_IS_ENABLED(SPL_FIT_PRINT) |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 170 | /** |
Tom Rini | 16c4b16 | 2018-05-08 14:34:05 -0400 | [diff] [blame] | 171 | * fit_image_print_data() - prints out the hash node details |
| 172 | * @fit: pointer to the FIT format image header |
| 173 | * @noffset: offset of the hash node |
| 174 | * @p: pointer to prefix string |
| 175 | * @type: Type of information to print ("hash" or "sign") |
| 176 | * |
| 177 | * fit_image_print_data() lists properties for the processed hash node |
| 178 | * |
| 179 | * This function avoid using puts() since it prints a newline on the host |
| 180 | * but does not in U-Boot. |
| 181 | * |
| 182 | * returns: |
| 183 | * no returned results |
| 184 | */ |
| 185 | static void fit_image_print_data(const void *fit, int noffset, const char *p, |
| 186 | const char *type) |
| 187 | { |
| 188 | const char *keyname; |
| 189 | uint8_t *value; |
| 190 | int value_len; |
| 191 | char *algo; |
Philippe Reynes | 2003156 | 2018-11-14 13:51:00 +0100 | [diff] [blame] | 192 | const char *padding; |
Simon Glass | 72188f5 | 2020-03-18 11:44:06 -0600 | [diff] [blame] | 193 | bool required; |
Tom Rini | 16c4b16 | 2018-05-08 14:34:05 -0400 | [diff] [blame] | 194 | int ret, i; |
| 195 | |
| 196 | debug("%s %s node: '%s'\n", p, type, |
| 197 | fit_get_name(fit, noffset, NULL)); |
| 198 | printf("%s %s algo: ", p, type); |
| 199 | if (fit_image_hash_get_algo(fit, noffset, &algo)) { |
| 200 | printf("invalid/unsupported\n"); |
| 201 | return; |
| 202 | } |
| 203 | printf("%s", algo); |
Simon Glass | 72188f5 | 2020-03-18 11:44:06 -0600 | [diff] [blame] | 204 | keyname = fdt_getprop(fit, noffset, FIT_KEY_HINT, NULL); |
| 205 | required = fdt_getprop(fit, noffset, FIT_KEY_REQUIRED, NULL) != NULL; |
Tom Rini | 16c4b16 | 2018-05-08 14:34:05 -0400 | [diff] [blame] | 206 | if (keyname) |
| 207 | printf(":%s", keyname); |
| 208 | if (required) |
| 209 | printf(" (required)"); |
| 210 | printf("\n"); |
| 211 | |
Philippe Reynes | 2003156 | 2018-11-14 13:51:00 +0100 | [diff] [blame] | 212 | padding = fdt_getprop(fit, noffset, "padding", NULL); |
| 213 | if (padding) |
| 214 | printf("%s %s padding: %s\n", p, type, padding); |
| 215 | |
Tom Rini | 16c4b16 | 2018-05-08 14:34:05 -0400 | [diff] [blame] | 216 | ret = fit_image_hash_get_value(fit, noffset, &value, |
| 217 | &value_len); |
| 218 | printf("%s %s value: ", p, type); |
| 219 | if (ret) { |
| 220 | printf("unavailable\n"); |
| 221 | } else { |
| 222 | for (i = 0; i < value_len; i++) |
| 223 | printf("%02x", value[i]); |
| 224 | printf("\n"); |
| 225 | } |
| 226 | |
| 227 | debug("%s %s len: %d\n", p, type, value_len); |
| 228 | |
| 229 | /* Signatures have a time stamp */ |
| 230 | if (IMAGE_ENABLE_TIMESTAMP && keyname) { |
| 231 | time_t timestamp; |
| 232 | |
| 233 | printf("%s Timestamp: ", p); |
| 234 | if (fit_get_timestamp(fit, noffset, ×tamp)) |
| 235 | printf("unavailable\n"); |
| 236 | else |
| 237 | genimg_print_time(timestamp); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * fit_image_print_verification_data() - prints out the hash/signature details |
| 243 | * @fit: pointer to the FIT format image header |
| 244 | * @noffset: offset of the hash or signature node |
| 245 | * @p: pointer to prefix string |
| 246 | * |
| 247 | * This lists properties for the processed hash node |
| 248 | * |
| 249 | * returns: |
| 250 | * no returned results |
| 251 | */ |
| 252 | static void fit_image_print_verification_data(const void *fit, int noffset, |
| 253 | const char *p) |
| 254 | { |
| 255 | const char *name; |
| 256 | |
| 257 | /* |
| 258 | * Check subnode name, must be equal to "hash" or "signature". |
| 259 | * Multiple hash/signature nodes require unique unit node |
| 260 | * names, e.g. hash-1, hash-2, signature-1, signature-2, etc. |
| 261 | */ |
| 262 | name = fit_get_name(fit, noffset, NULL); |
| 263 | if (!strncmp(name, FIT_HASH_NODENAME, strlen(FIT_HASH_NODENAME))) { |
| 264 | fit_image_print_data(fit, noffset, p, "Hash"); |
| 265 | } else if (!strncmp(name, FIT_SIG_NODENAME, |
| 266 | strlen(FIT_SIG_NODENAME))) { |
| 267 | fit_image_print_data(fit, noffset, p, "Sign"); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * fit_conf_print - prints out the FIT configuration details |
| 273 | * @fit: pointer to the FIT format image header |
| 274 | * @noffset: offset of the configuration node |
| 275 | * @p: pointer to prefix string |
| 276 | * |
| 277 | * fit_conf_print() lists all mandatory properties for the processed |
| 278 | * configuration node. |
| 279 | * |
| 280 | * returns: |
| 281 | * no returned results |
| 282 | */ |
| 283 | static void fit_conf_print(const void *fit, int noffset, const char *p) |
| 284 | { |
| 285 | char *desc; |
| 286 | const char *uname; |
| 287 | int ret; |
| 288 | int fdt_index, loadables_index; |
| 289 | int ndepth; |
| 290 | |
| 291 | /* Mandatory properties */ |
| 292 | ret = fit_get_desc(fit, noffset, &desc); |
| 293 | printf("%s Description: ", p); |
| 294 | if (ret) |
| 295 | printf("unavailable\n"); |
| 296 | else |
| 297 | printf("%s\n", desc); |
| 298 | |
| 299 | uname = fdt_getprop(fit, noffset, FIT_KERNEL_PROP, NULL); |
| 300 | printf("%s Kernel: ", p); |
| 301 | if (!uname) |
| 302 | printf("unavailable\n"); |
| 303 | else |
| 304 | printf("%s\n", uname); |
| 305 | |
| 306 | /* Optional properties */ |
| 307 | uname = fdt_getprop(fit, noffset, FIT_RAMDISK_PROP, NULL); |
| 308 | if (uname) |
| 309 | printf("%s Init Ramdisk: %s\n", p, uname); |
| 310 | |
| 311 | uname = fdt_getprop(fit, noffset, FIT_FIRMWARE_PROP, NULL); |
| 312 | if (uname) |
| 313 | printf("%s Firmware: %s\n", p, uname); |
| 314 | |
| 315 | for (fdt_index = 0; |
| 316 | uname = fdt_stringlist_get(fit, noffset, FIT_FDT_PROP, |
| 317 | fdt_index, NULL), uname; |
| 318 | fdt_index++) { |
| 319 | if (fdt_index == 0) |
| 320 | printf("%s FDT: ", p); |
| 321 | else |
| 322 | printf("%s ", p); |
| 323 | printf("%s\n", uname); |
| 324 | } |
| 325 | |
| 326 | uname = fdt_getprop(fit, noffset, FIT_FPGA_PROP, NULL); |
| 327 | if (uname) |
| 328 | printf("%s FPGA: %s\n", p, uname); |
| 329 | |
| 330 | /* Print out all of the specified loadables */ |
| 331 | for (loadables_index = 0; |
| 332 | uname = fdt_stringlist_get(fit, noffset, FIT_LOADABLE_PROP, |
| 333 | loadables_index, NULL), uname; |
| 334 | loadables_index++) { |
| 335 | if (loadables_index == 0) { |
| 336 | printf("%s Loadables: ", p); |
| 337 | } else { |
| 338 | printf("%s ", p); |
| 339 | } |
| 340 | printf("%s\n", uname); |
| 341 | } |
| 342 | |
| 343 | /* Process all hash subnodes of the component configuration node */ |
| 344 | for (ndepth = 0, noffset = fdt_next_node(fit, noffset, &ndepth); |
| 345 | (noffset >= 0) && (ndepth > 0); |
| 346 | noffset = fdt_next_node(fit, noffset, &ndepth)) { |
| 347 | if (ndepth == 1) { |
| 348 | /* Direct child node of the component configuration node */ |
| 349 | fit_image_print_verification_data(fit, noffset, p); |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | /** |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 355 | * fit_print_contents - prints out the contents of the FIT format image |
| 356 | * @fit: pointer to the FIT format image header |
| 357 | * @p: pointer to prefix string |
| 358 | * |
| 359 | * fit_print_contents() formats a multi line FIT image contents description. |
Andreas Dannenberg | e17adbb | 2016-06-15 17:00:19 -0500 | [diff] [blame] | 360 | * The routine prints out FIT image properties (root node level) followed by |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 361 | * the details of each component image. |
| 362 | * |
| 363 | * returns: |
| 364 | * no returned results |
| 365 | */ |
| 366 | void fit_print_contents(const void *fit) |
| 367 | { |
| 368 | char *desc; |
| 369 | char *uname; |
| 370 | int images_noffset; |
| 371 | int confs_noffset; |
| 372 | int noffset; |
| 373 | int ndepth; |
| 374 | int count = 0; |
| 375 | int ret; |
| 376 | const char *p; |
| 377 | time_t timestamp; |
| 378 | |
Simon Glass | 1fe7d93 | 2013-05-08 08:05:58 +0000 | [diff] [blame] | 379 | /* Indent string is defined in header image.h */ |
| 380 | p = IMAGE_INDENT_STRING; |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 381 | |
| 382 | /* Root node properties */ |
| 383 | ret = fit_get_desc(fit, 0, &desc); |
| 384 | printf("%sFIT description: ", p); |
| 385 | if (ret) |
| 386 | printf("unavailable\n"); |
| 387 | else |
| 388 | printf("%s\n", desc); |
| 389 | |
| 390 | if (IMAGE_ENABLE_TIMESTAMP) { |
| 391 | ret = fit_get_timestamp(fit, 0, ×tamp); |
| 392 | printf("%sCreated: ", p); |
| 393 | if (ret) |
| 394 | printf("unavailable\n"); |
| 395 | else |
| 396 | genimg_print_time(timestamp); |
| 397 | } |
| 398 | |
| 399 | /* Find images parent node offset */ |
| 400 | images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); |
| 401 | if (images_noffset < 0) { |
| 402 | printf("Can't find images parent node '%s' (%s)\n", |
| 403 | FIT_IMAGES_PATH, fdt_strerror(images_noffset)); |
| 404 | return; |
| 405 | } |
| 406 | |
| 407 | /* Process its subnodes, print out component images details */ |
| 408 | for (ndepth = 0, count = 0, |
| 409 | noffset = fdt_next_node(fit, images_noffset, &ndepth); |
| 410 | (noffset >= 0) && (ndepth > 0); |
| 411 | noffset = fdt_next_node(fit, noffset, &ndepth)) { |
| 412 | if (ndepth == 1) { |
| 413 | /* |
| 414 | * Direct child node of the images parent node, |
| 415 | * i.e. component image node. |
| 416 | */ |
| 417 | printf("%s Image %u (%s)\n", p, count++, |
| 418 | fit_get_name(fit, noffset, NULL)); |
| 419 | |
| 420 | fit_image_print(fit, noffset, p); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | /* Find configurations parent node offset */ |
| 425 | confs_noffset = fdt_path_offset(fit, FIT_CONFS_PATH); |
| 426 | if (confs_noffset < 0) { |
| 427 | debug("Can't get configurations parent node '%s' (%s)\n", |
| 428 | FIT_CONFS_PATH, fdt_strerror(confs_noffset)); |
| 429 | return; |
| 430 | } |
| 431 | |
| 432 | /* get default configuration unit name from default property */ |
| 433 | uname = (char *)fdt_getprop(fit, noffset, FIT_DEFAULT_PROP, NULL); |
| 434 | if (uname) |
| 435 | printf("%s Default Configuration: '%s'\n", p, uname); |
| 436 | |
| 437 | /* Process its subnodes, print out configurations details */ |
| 438 | for (ndepth = 0, count = 0, |
| 439 | noffset = fdt_next_node(fit, confs_noffset, &ndepth); |
| 440 | (noffset >= 0) && (ndepth > 0); |
| 441 | noffset = fdt_next_node(fit, noffset, &ndepth)) { |
| 442 | if (ndepth == 1) { |
| 443 | /* |
| 444 | * Direct child node of the configurations parent node, |
| 445 | * i.e. configuration node. |
| 446 | */ |
| 447 | printf("%s Configuration %u (%s)\n", p, count++, |
| 448 | fit_get_name(fit, noffset, NULL)); |
| 449 | |
| 450 | fit_conf_print(fit, noffset, p); |
| 451 | } |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | /** |
| 456 | * fit_image_print - prints out the FIT component image details |
| 457 | * @fit: pointer to the FIT format image header |
| 458 | * @image_noffset: offset of the component image node |
| 459 | * @p: pointer to prefix string |
| 460 | * |
Andreas Dannenberg | e17adbb | 2016-06-15 17:00:19 -0500 | [diff] [blame] | 461 | * fit_image_print() lists all mandatory properties for the processed component |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 462 | * image. If present, hash nodes are printed out as well. Load |
| 463 | * address for images of type firmware is also printed out. Since the load |
| 464 | * address is not mandatory for firmware images, it will be output as |
| 465 | * "unavailable" when not present. |
| 466 | * |
| 467 | * returns: |
| 468 | * no returned results |
| 469 | */ |
| 470 | void fit_image_print(const void *fit, int image_noffset, const char *p) |
| 471 | { |
| 472 | char *desc; |
| 473 | uint8_t type, arch, os, comp; |
| 474 | size_t size; |
| 475 | ulong load, entry; |
| 476 | const void *data; |
| 477 | int noffset; |
| 478 | int ndepth; |
| 479 | int ret; |
| 480 | |
| 481 | /* Mandatory properties */ |
| 482 | ret = fit_get_desc(fit, image_noffset, &desc); |
| 483 | printf("%s Description: ", p); |
| 484 | if (ret) |
| 485 | printf("unavailable\n"); |
| 486 | else |
| 487 | printf("%s\n", desc); |
| 488 | |
Simon Glass | 1fd1e2f | 2013-07-16 20:10:01 -0700 | [diff] [blame] | 489 | if (IMAGE_ENABLE_TIMESTAMP) { |
| 490 | time_t timestamp; |
| 491 | |
| 492 | ret = fit_get_timestamp(fit, 0, ×tamp); |
| 493 | printf("%s Created: ", p); |
| 494 | if (ret) |
| 495 | printf("unavailable\n"); |
| 496 | else |
| 497 | genimg_print_time(timestamp); |
| 498 | } |
| 499 | |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 500 | fit_image_get_type(fit, image_noffset, &type); |
| 501 | printf("%s Type: %s\n", p, genimg_get_type_name(type)); |
| 502 | |
| 503 | fit_image_get_comp(fit, image_noffset, &comp); |
| 504 | printf("%s Compression: %s\n", p, genimg_get_comp_name(comp)); |
| 505 | |
Kelvin Cheung | c3c8638 | 2018-05-19 18:21:37 +0800 | [diff] [blame] | 506 | ret = fit_image_get_data_and_size(fit, image_noffset, &data, &size); |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 507 | |
Sebastian Reichel | f14e6ee | 2021-01-04 20:48:03 +0100 | [diff] [blame] | 508 | if (!host_build()) { |
| 509 | printf("%s Data Start: ", p); |
| 510 | if (ret) { |
| 511 | printf("unavailable\n"); |
| 512 | } else { |
| 513 | void *vdata = (void *)data; |
Simon Glass | c6ac13b | 2013-05-16 13:53:26 +0000 | [diff] [blame] | 514 | |
Sebastian Reichel | f14e6ee | 2021-01-04 20:48:03 +0100 | [diff] [blame] | 515 | printf("0x%08lx\n", (ulong)map_to_sysmem(vdata)); |
| 516 | } |
Simon Glass | c6ac13b | 2013-05-16 13:53:26 +0000 | [diff] [blame] | 517 | } |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 518 | |
| 519 | printf("%s Data Size: ", p); |
| 520 | if (ret) |
| 521 | printf("unavailable\n"); |
| 522 | else |
| 523 | genimg_print_size(size); |
| 524 | |
| 525 | /* Remaining, type dependent properties */ |
| 526 | if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) || |
| 527 | (type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) || |
| 528 | (type == IH_TYPE_FLATDT)) { |
| 529 | fit_image_get_arch(fit, image_noffset, &arch); |
| 530 | printf("%s Architecture: %s\n", p, genimg_get_arch_name(arch)); |
| 531 | } |
| 532 | |
Michal Simek | 6faf462 | 2018-03-26 16:31:27 +0200 | [diff] [blame] | 533 | if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_RAMDISK) || |
| 534 | (type == IH_TYPE_FIRMWARE)) { |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 535 | fit_image_get_os(fit, image_noffset, &os); |
| 536 | printf("%s OS: %s\n", p, genimg_get_os_name(os)); |
| 537 | } |
| 538 | |
| 539 | if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) || |
Michal Simek | 62afc60 | 2016-05-17 14:03:50 +0200 | [diff] [blame] | 540 | (type == IH_TYPE_FIRMWARE) || (type == IH_TYPE_RAMDISK) || |
| 541 | (type == IH_TYPE_FPGA)) { |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 542 | ret = fit_image_get_load(fit, image_noffset, &load); |
| 543 | printf("%s Load Address: ", p); |
| 544 | if (ret) |
| 545 | printf("unavailable\n"); |
| 546 | else |
| 547 | printf("0x%08lx\n", load); |
| 548 | } |
| 549 | |
Pantelis Antoniou | 169043d | 2017-09-04 23:12:16 +0300 | [diff] [blame] | 550 | /* optional load address for FDT */ |
| 551 | if (type == IH_TYPE_FLATDT && !fit_image_get_load(fit, image_noffset, &load)) |
| 552 | printf("%s Load Address: 0x%08lx\n", p, load); |
| 553 | |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 554 | if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) || |
| 555 | (type == IH_TYPE_RAMDISK)) { |
York Sun | 6004765 | 2016-02-29 15:48:40 -0800 | [diff] [blame] | 556 | ret = fit_image_get_entry(fit, image_noffset, &entry); |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 557 | printf("%s Entry Point: ", p); |
| 558 | if (ret) |
| 559 | printf("unavailable\n"); |
| 560 | else |
| 561 | printf("0x%08lx\n", entry); |
| 562 | } |
| 563 | |
| 564 | /* Process all hash subnodes of the component image node */ |
| 565 | for (ndepth = 0, noffset = fdt_next_node(fit, image_noffset, &ndepth); |
| 566 | (noffset >= 0) && (ndepth > 0); |
| 567 | noffset = fdt_next_node(fit, noffset, &ndepth)) { |
| 568 | if (ndepth == 1) { |
| 569 | /* Direct child node of the component image node */ |
Simon Glass | d8b7536 | 2013-05-07 06:12:02 +0000 | [diff] [blame] | 570 | fit_image_print_verification_data(fit, noffset, p); |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 571 | } |
| 572 | } |
| 573 | } |
Marek Vasut | a3c43b1 | 2018-05-13 00:22:53 +0200 | [diff] [blame] | 574 | #else |
| 575 | void fit_print_contents(const void *fit) { } |
| 576 | void fit_image_print(const void *fit, int image_noffset, const char *p) { } |
Ravik Hasija | 7a01882 | 2021-01-27 14:01:48 -0800 | [diff] [blame] | 577 | #endif /* CONFIG_IS_ENABLED(FIR_PRINT) || CONFIG_IS_ENABLED(SPL_FIT_PRINT) */ |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 578 | |
| 579 | /** |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 580 | * fit_get_desc - get node description property |
| 581 | * @fit: pointer to the FIT format image header |
| 582 | * @noffset: node offset |
Andreas Dannenberg | e17adbb | 2016-06-15 17:00:19 -0500 | [diff] [blame] | 583 | * @desc: double pointer to the char, will hold pointer to the description |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 584 | * |
| 585 | * fit_get_desc() reads description property from a given node, if |
Andreas Dannenberg | e17adbb | 2016-06-15 17:00:19 -0500 | [diff] [blame] | 586 | * description is found pointer to it is returned in third call argument. |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 587 | * |
| 588 | * returns: |
| 589 | * 0, on success |
| 590 | * -1, on failure |
| 591 | */ |
| 592 | int fit_get_desc(const void *fit, int noffset, char **desc) |
| 593 | { |
| 594 | int len; |
| 595 | |
| 596 | *desc = (char *)fdt_getprop(fit, noffset, FIT_DESC_PROP, &len); |
| 597 | if (*desc == NULL) { |
| 598 | fit_get_debug(fit, noffset, FIT_DESC_PROP, len); |
| 599 | return -1; |
| 600 | } |
| 601 | |
| 602 | return 0; |
| 603 | } |
| 604 | |
| 605 | /** |
| 606 | * fit_get_timestamp - get node timestamp property |
| 607 | * @fit: pointer to the FIT format image header |
| 608 | * @noffset: node offset |
| 609 | * @timestamp: pointer to the time_t, will hold read timestamp |
| 610 | * |
Andreas Dannenberg | e17adbb | 2016-06-15 17:00:19 -0500 | [diff] [blame] | 611 | * fit_get_timestamp() reads timestamp property from given node, if timestamp |
| 612 | * is found and has a correct size its value is returned in third call |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 613 | * argument. |
| 614 | * |
| 615 | * returns: |
| 616 | * 0, on success |
| 617 | * -1, on property read failure |
| 618 | * -2, on wrong timestamp size |
| 619 | */ |
| 620 | int fit_get_timestamp(const void *fit, int noffset, time_t *timestamp) |
| 621 | { |
| 622 | int len; |
| 623 | const void *data; |
| 624 | |
| 625 | data = fdt_getprop(fit, noffset, FIT_TIMESTAMP_PROP, &len); |
| 626 | if (data == NULL) { |
| 627 | fit_get_debug(fit, noffset, FIT_TIMESTAMP_PROP, len); |
| 628 | return -1; |
| 629 | } |
| 630 | if (len != sizeof(uint32_t)) { |
| 631 | debug("FIT timestamp with incorrect size of (%u)\n", len); |
| 632 | return -2; |
| 633 | } |
| 634 | |
| 635 | *timestamp = uimage_to_cpu(*((uint32_t *)data)); |
| 636 | return 0; |
| 637 | } |
| 638 | |
| 639 | /** |
| 640 | * fit_image_get_node - get node offset for component image of a given unit name |
| 641 | * @fit: pointer to the FIT format image header |
| 642 | * @image_uname: component image node unit name |
| 643 | * |
Andreas Dannenberg | e17adbb | 2016-06-15 17:00:19 -0500 | [diff] [blame] | 644 | * fit_image_get_node() finds a component image (within the '/images' |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 645 | * node) of a provided unit name. If image is found its node offset is |
| 646 | * returned to the caller. |
| 647 | * |
| 648 | * returns: |
| 649 | * image node offset when found (>=0) |
| 650 | * negative number on failure (FDT_ERR_* code) |
| 651 | */ |
| 652 | int fit_image_get_node(const void *fit, const char *image_uname) |
| 653 | { |
| 654 | int noffset, images_noffset; |
| 655 | |
| 656 | images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); |
| 657 | if (images_noffset < 0) { |
| 658 | debug("Can't find images parent node '%s' (%s)\n", |
| 659 | FIT_IMAGES_PATH, fdt_strerror(images_noffset)); |
| 660 | return images_noffset; |
| 661 | } |
| 662 | |
| 663 | noffset = fdt_subnode_offset(fit, images_noffset, image_uname); |
| 664 | if (noffset < 0) { |
| 665 | debug("Can't get node offset for image unit name: '%s' (%s)\n", |
| 666 | image_uname, fdt_strerror(noffset)); |
| 667 | } |
| 668 | |
| 669 | return noffset; |
| 670 | } |
| 671 | |
| 672 | /** |
| 673 | * fit_image_get_os - get os id for a given component image node |
| 674 | * @fit: pointer to the FIT format image header |
| 675 | * @noffset: component image node offset |
| 676 | * @os: pointer to the uint8_t, will hold os numeric id |
| 677 | * |
| 678 | * fit_image_get_os() finds os property in a given component image node. |
| 679 | * If the property is found, its (string) value is translated to the numeric |
| 680 | * id which is returned to the caller. |
| 681 | * |
| 682 | * returns: |
| 683 | * 0, on success |
| 684 | * -1, on failure |
| 685 | */ |
| 686 | int fit_image_get_os(const void *fit, int noffset, uint8_t *os) |
| 687 | { |
| 688 | int len; |
| 689 | const void *data; |
| 690 | |
| 691 | /* Get OS name from property data */ |
| 692 | data = fdt_getprop(fit, noffset, FIT_OS_PROP, &len); |
| 693 | if (data == NULL) { |
| 694 | fit_get_debug(fit, noffset, FIT_OS_PROP, len); |
| 695 | *os = -1; |
| 696 | return -1; |
| 697 | } |
| 698 | |
| 699 | /* Translate OS name to id */ |
| 700 | *os = genimg_get_os_id(data); |
| 701 | return 0; |
| 702 | } |
| 703 | |
| 704 | /** |
| 705 | * fit_image_get_arch - get arch id for a given component image node |
| 706 | * @fit: pointer to the FIT format image header |
| 707 | * @noffset: component image node offset |
| 708 | * @arch: pointer to the uint8_t, will hold arch numeric id |
| 709 | * |
| 710 | * fit_image_get_arch() finds arch property in a given component image node. |
| 711 | * If the property is found, its (string) value is translated to the numeric |
| 712 | * id which is returned to the caller. |
| 713 | * |
| 714 | * returns: |
| 715 | * 0, on success |
| 716 | * -1, on failure |
| 717 | */ |
| 718 | int fit_image_get_arch(const void *fit, int noffset, uint8_t *arch) |
| 719 | { |
| 720 | int len; |
| 721 | const void *data; |
| 722 | |
| 723 | /* Get architecture name from property data */ |
| 724 | data = fdt_getprop(fit, noffset, FIT_ARCH_PROP, &len); |
| 725 | if (data == NULL) { |
| 726 | fit_get_debug(fit, noffset, FIT_ARCH_PROP, len); |
| 727 | *arch = -1; |
| 728 | return -1; |
| 729 | } |
| 730 | |
| 731 | /* Translate architecture name to id */ |
| 732 | *arch = genimg_get_arch_id(data); |
| 733 | return 0; |
| 734 | } |
| 735 | |
| 736 | /** |
| 737 | * fit_image_get_type - get type id for a given component image node |
| 738 | * @fit: pointer to the FIT format image header |
| 739 | * @noffset: component image node offset |
| 740 | * @type: pointer to the uint8_t, will hold type numeric id |
| 741 | * |
| 742 | * fit_image_get_type() finds type property in a given component image node. |
| 743 | * If the property is found, its (string) value is translated to the numeric |
| 744 | * id which is returned to the caller. |
| 745 | * |
| 746 | * returns: |
| 747 | * 0, on success |
| 748 | * -1, on failure |
| 749 | */ |
| 750 | int fit_image_get_type(const void *fit, int noffset, uint8_t *type) |
| 751 | { |
| 752 | int len; |
| 753 | const void *data; |
| 754 | |
| 755 | /* Get image type name from property data */ |
| 756 | data = fdt_getprop(fit, noffset, FIT_TYPE_PROP, &len); |
| 757 | if (data == NULL) { |
| 758 | fit_get_debug(fit, noffset, FIT_TYPE_PROP, len); |
| 759 | *type = -1; |
| 760 | return -1; |
| 761 | } |
| 762 | |
| 763 | /* Translate image type name to id */ |
| 764 | *type = genimg_get_type_id(data); |
| 765 | return 0; |
| 766 | } |
| 767 | |
| 768 | /** |
| 769 | * fit_image_get_comp - get comp id for a given component image node |
| 770 | * @fit: pointer to the FIT format image header |
| 771 | * @noffset: component image node offset |
| 772 | * @comp: pointer to the uint8_t, will hold comp numeric id |
| 773 | * |
| 774 | * fit_image_get_comp() finds comp property in a given component image node. |
| 775 | * If the property is found, its (string) value is translated to the numeric |
| 776 | * id which is returned to the caller. |
| 777 | * |
| 778 | * returns: |
| 779 | * 0, on success |
| 780 | * -1, on failure |
| 781 | */ |
| 782 | int fit_image_get_comp(const void *fit, int noffset, uint8_t *comp) |
| 783 | { |
| 784 | int len; |
| 785 | const void *data; |
| 786 | |
| 787 | /* Get compression name from property data */ |
| 788 | data = fdt_getprop(fit, noffset, FIT_COMP_PROP, &len); |
| 789 | if (data == NULL) { |
| 790 | fit_get_debug(fit, noffset, FIT_COMP_PROP, len); |
| 791 | *comp = -1; |
| 792 | return -1; |
| 793 | } |
| 794 | |
| 795 | /* Translate compression name to id */ |
| 796 | *comp = genimg_get_comp_id(data); |
| 797 | return 0; |
| 798 | } |
| 799 | |
York Sun | 6004765 | 2016-02-29 15:48:40 -0800 | [diff] [blame] | 800 | static int fit_image_get_address(const void *fit, int noffset, char *name, |
| 801 | ulong *load) |
| 802 | { |
York Sun | c1913cb | 2016-02-29 15:48:41 -0800 | [diff] [blame] | 803 | int len, cell_len; |
| 804 | const fdt32_t *cell; |
| 805 | uint64_t load64 = 0; |
York Sun | 6004765 | 2016-02-29 15:48:40 -0800 | [diff] [blame] | 806 | |
York Sun | c1913cb | 2016-02-29 15:48:41 -0800 | [diff] [blame] | 807 | cell = fdt_getprop(fit, noffset, name, &len); |
| 808 | if (cell == NULL) { |
York Sun | 6004765 | 2016-02-29 15:48:40 -0800 | [diff] [blame] | 809 | fit_get_debug(fit, noffset, name, len); |
| 810 | return -1; |
| 811 | } |
| 812 | |
York Sun | c1913cb | 2016-02-29 15:48:41 -0800 | [diff] [blame] | 813 | cell_len = len >> 2; |
| 814 | /* Use load64 to avoid compiling warning for 32-bit target */ |
| 815 | while (cell_len--) { |
| 816 | load64 = (load64 << 32) | uimage_to_cpu(*cell); |
| 817 | cell++; |
| 818 | } |
Michal Simek | 13d1ca8 | 2020-09-03 12:44:51 +0200 | [diff] [blame] | 819 | |
| 820 | if (len > sizeof(ulong) && (uint32_t)(load64 >> 32)) { |
| 821 | printf("Unsupported %s address size\n", name); |
| 822 | return -1; |
| 823 | } |
| 824 | |
York Sun | c1913cb | 2016-02-29 15:48:41 -0800 | [diff] [blame] | 825 | *load = (ulong)load64; |
York Sun | 6004765 | 2016-02-29 15:48:40 -0800 | [diff] [blame] | 826 | |
| 827 | return 0; |
| 828 | } |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 829 | /** |
| 830 | * fit_image_get_load() - get load addr property for given component image node |
| 831 | * @fit: pointer to the FIT format image header |
| 832 | * @noffset: component image node offset |
| 833 | * @load: pointer to the uint32_t, will hold load address |
| 834 | * |
| 835 | * fit_image_get_load() finds load address property in a given component |
| 836 | * image node. If the property is found, its value is returned to the caller. |
| 837 | * |
| 838 | * returns: |
| 839 | * 0, on success |
| 840 | * -1, on failure |
| 841 | */ |
| 842 | int fit_image_get_load(const void *fit, int noffset, ulong *load) |
| 843 | { |
York Sun | 6004765 | 2016-02-29 15:48:40 -0800 | [diff] [blame] | 844 | return fit_image_get_address(fit, noffset, FIT_LOAD_PROP, load); |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | /** |
| 848 | * fit_image_get_entry() - get entry point address property |
| 849 | * @fit: pointer to the FIT format image header |
| 850 | * @noffset: component image node offset |
| 851 | * @entry: pointer to the uint32_t, will hold entry point address |
| 852 | * |
| 853 | * This gets the entry point address property for a given component image |
| 854 | * node. |
| 855 | * |
| 856 | * fit_image_get_entry() finds entry point address property in a given |
| 857 | * component image node. If the property is found, its value is returned |
| 858 | * to the caller. |
| 859 | * |
| 860 | * returns: |
| 861 | * 0, on success |
| 862 | * -1, on failure |
| 863 | */ |
| 864 | int fit_image_get_entry(const void *fit, int noffset, ulong *entry) |
| 865 | { |
York Sun | 6004765 | 2016-02-29 15:48:40 -0800 | [diff] [blame] | 866 | return fit_image_get_address(fit, noffset, FIT_ENTRY_PROP, entry); |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | /** |
| 870 | * fit_image_get_data - get data property and its size for a given component image node |
| 871 | * @fit: pointer to the FIT format image header |
| 872 | * @noffset: component image node offset |
| 873 | * @data: double pointer to void, will hold data property's data address |
| 874 | * @size: pointer to size_t, will hold data property's data size |
| 875 | * |
| 876 | * fit_image_get_data() finds data property in a given component image node. |
| 877 | * If the property is found its data start address and size are returned to |
| 878 | * the caller. |
| 879 | * |
| 880 | * returns: |
| 881 | * 0, on success |
| 882 | * -1, on failure |
| 883 | */ |
| 884 | int fit_image_get_data(const void *fit, int noffset, |
| 885 | const void **data, size_t *size) |
| 886 | { |
| 887 | int len; |
| 888 | |
| 889 | *data = fdt_getprop(fit, noffset, FIT_DATA_PROP, &len); |
| 890 | if (*data == NULL) { |
| 891 | fit_get_debug(fit, noffset, FIT_DATA_PROP, len); |
| 892 | *size = 0; |
| 893 | return -1; |
| 894 | } |
| 895 | |
| 896 | *size = len; |
| 897 | return 0; |
| 898 | } |
| 899 | |
| 900 | /** |
tomas.melin@vaisala.com | db1b79b | 2017-01-13 13:20:14 +0200 | [diff] [blame] | 901 | * Get 'data-offset' property from a given image node. |
| 902 | * |
| 903 | * @fit: pointer to the FIT image header |
| 904 | * @noffset: component image node offset |
| 905 | * @data_offset: holds the data-offset property |
| 906 | * |
| 907 | * returns: |
| 908 | * 0, on success |
| 909 | * -ENOENT if the property could not be found |
| 910 | */ |
| 911 | int fit_image_get_data_offset(const void *fit, int noffset, int *data_offset) |
| 912 | { |
| 913 | const fdt32_t *val; |
| 914 | |
| 915 | val = fdt_getprop(fit, noffset, FIT_DATA_OFFSET_PROP, NULL); |
| 916 | if (!val) |
| 917 | return -ENOENT; |
| 918 | |
| 919 | *data_offset = fdt32_to_cpu(*val); |
| 920 | |
| 921 | return 0; |
| 922 | } |
| 923 | |
| 924 | /** |
Peng Fan | a1be94b | 2017-12-05 13:20:59 +0800 | [diff] [blame] | 925 | * Get 'data-position' property from a given image node. |
| 926 | * |
| 927 | * @fit: pointer to the FIT image header |
| 928 | * @noffset: component image node offset |
| 929 | * @data_position: holds the data-position property |
| 930 | * |
| 931 | * returns: |
| 932 | * 0, on success |
| 933 | * -ENOENT if the property could not be found |
| 934 | */ |
| 935 | int fit_image_get_data_position(const void *fit, int noffset, |
| 936 | int *data_position) |
| 937 | { |
| 938 | const fdt32_t *val; |
| 939 | |
| 940 | val = fdt_getprop(fit, noffset, FIT_DATA_POSITION_PROP, NULL); |
| 941 | if (!val) |
| 942 | return -ENOENT; |
| 943 | |
| 944 | *data_position = fdt32_to_cpu(*val); |
| 945 | |
| 946 | return 0; |
| 947 | } |
| 948 | |
| 949 | /** |
tomas.melin@vaisala.com | db1b79b | 2017-01-13 13:20:14 +0200 | [diff] [blame] | 950 | * Get 'data-size' property from a given image node. |
| 951 | * |
| 952 | * @fit: pointer to the FIT image header |
| 953 | * @noffset: component image node offset |
| 954 | * @data_size: holds the data-size property |
| 955 | * |
| 956 | * returns: |
| 957 | * 0, on success |
| 958 | * -ENOENT if the property could not be found |
| 959 | */ |
| 960 | int fit_image_get_data_size(const void *fit, int noffset, int *data_size) |
| 961 | { |
| 962 | const fdt32_t *val; |
| 963 | |
| 964 | val = fdt_getprop(fit, noffset, FIT_DATA_SIZE_PROP, NULL); |
| 965 | if (!val) |
| 966 | return -ENOENT; |
| 967 | |
| 968 | *data_size = fdt32_to_cpu(*val); |
| 969 | |
| 970 | return 0; |
| 971 | } |
| 972 | |
| 973 | /** |
Philippe Reynes | 4df3578 | 2019-12-18 18:25:42 +0100 | [diff] [blame] | 974 | * Get 'data-size-unciphered' property from a given image node. |
| 975 | * |
| 976 | * @fit: pointer to the FIT image header |
| 977 | * @noffset: component image node offset |
| 978 | * @data_size: holds the data-size property |
| 979 | * |
| 980 | * returns: |
| 981 | * 0, on success |
| 982 | * -ENOENT if the property could not be found |
| 983 | */ |
| 984 | int fit_image_get_data_size_unciphered(const void *fit, int noffset, |
| 985 | size_t *data_size) |
| 986 | { |
| 987 | const fdt32_t *val; |
| 988 | |
| 989 | val = fdt_getprop(fit, noffset, "data-size-unciphered", NULL); |
| 990 | if (!val) |
| 991 | return -ENOENT; |
| 992 | |
| 993 | *data_size = (size_t)fdt32_to_cpu(*val); |
| 994 | |
| 995 | return 0; |
| 996 | } |
| 997 | |
| 998 | /** |
Kelvin Cheung | c3c8638 | 2018-05-19 18:21:37 +0800 | [diff] [blame] | 999 | * fit_image_get_data_and_size - get data and its size including |
| 1000 | * both embedded and external data |
| 1001 | * @fit: pointer to the FIT format image header |
| 1002 | * @noffset: component image node offset |
| 1003 | * @data: double pointer to void, will hold data property's data address |
| 1004 | * @size: pointer to size_t, will hold data property's data size |
| 1005 | * |
| 1006 | * fit_image_get_data_and_size() finds data and its size including |
| 1007 | * both embedded and external data. If the property is found |
| 1008 | * its data start address and size are returned to the caller. |
| 1009 | * |
| 1010 | * returns: |
| 1011 | * 0, on success |
| 1012 | * otherwise, on failure |
| 1013 | */ |
| 1014 | int fit_image_get_data_and_size(const void *fit, int noffset, |
| 1015 | const void **data, size_t *size) |
| 1016 | { |
| 1017 | bool external_data = false; |
| 1018 | int offset; |
| 1019 | int len; |
| 1020 | int ret; |
| 1021 | |
| 1022 | if (!fit_image_get_data_position(fit, noffset, &offset)) { |
| 1023 | external_data = true; |
| 1024 | } else if (!fit_image_get_data_offset(fit, noffset, &offset)) { |
| 1025 | external_data = true; |
| 1026 | /* |
| 1027 | * For FIT with external data, figure out where |
| 1028 | * the external images start. This is the base |
| 1029 | * for the data-offset properties in each image. |
| 1030 | */ |
| 1031 | offset += ((fdt_totalsize(fit) + 3) & ~3); |
| 1032 | } |
| 1033 | |
| 1034 | if (external_data) { |
| 1035 | debug("External Data\n"); |
| 1036 | ret = fit_image_get_data_size(fit, noffset, &len); |
Heinrich Schuchardt | 1837804 | 2020-03-11 21:51:08 +0100 | [diff] [blame] | 1037 | if (!ret) { |
| 1038 | *data = fit + offset; |
| 1039 | *size = len; |
| 1040 | } |
Kelvin Cheung | c3c8638 | 2018-05-19 18:21:37 +0800 | [diff] [blame] | 1041 | } else { |
| 1042 | ret = fit_image_get_data(fit, noffset, data, size); |
| 1043 | } |
| 1044 | |
| 1045 | return ret; |
| 1046 | } |
| 1047 | |
| 1048 | /** |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1049 | * fit_image_hash_get_algo - get hash algorithm name |
| 1050 | * @fit: pointer to the FIT format image header |
| 1051 | * @noffset: hash node offset |
| 1052 | * @algo: double pointer to char, will hold pointer to the algorithm name |
| 1053 | * |
| 1054 | * fit_image_hash_get_algo() finds hash algorithm property in a given hash node. |
| 1055 | * If the property is found its data start address is returned to the caller. |
| 1056 | * |
| 1057 | * returns: |
| 1058 | * 0, on success |
| 1059 | * -1, on failure |
| 1060 | */ |
| 1061 | int fit_image_hash_get_algo(const void *fit, int noffset, char **algo) |
| 1062 | { |
| 1063 | int len; |
| 1064 | |
| 1065 | *algo = (char *)fdt_getprop(fit, noffset, FIT_ALGO_PROP, &len); |
| 1066 | if (*algo == NULL) { |
| 1067 | fit_get_debug(fit, noffset, FIT_ALGO_PROP, len); |
| 1068 | return -1; |
| 1069 | } |
| 1070 | |
| 1071 | return 0; |
| 1072 | } |
| 1073 | |
| 1074 | /** |
| 1075 | * fit_image_hash_get_value - get hash value and length |
| 1076 | * @fit: pointer to the FIT format image header |
| 1077 | * @noffset: hash node offset |
| 1078 | * @value: double pointer to uint8_t, will hold address of a hash value data |
| 1079 | * @value_len: pointer to an int, will hold hash data length |
| 1080 | * |
| 1081 | * fit_image_hash_get_value() finds hash value property in a given hash node. |
| 1082 | * If the property is found its data start address and size are returned to |
| 1083 | * the caller. |
| 1084 | * |
| 1085 | * returns: |
| 1086 | * 0, on success |
| 1087 | * -1, on failure |
| 1088 | */ |
| 1089 | int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value, |
| 1090 | int *value_len) |
| 1091 | { |
| 1092 | int len; |
| 1093 | |
| 1094 | *value = (uint8_t *)fdt_getprop(fit, noffset, FIT_VALUE_PROP, &len); |
| 1095 | if (*value == NULL) { |
| 1096 | fit_get_debug(fit, noffset, FIT_VALUE_PROP, len); |
| 1097 | *value_len = 0; |
| 1098 | return -1; |
| 1099 | } |
| 1100 | |
| 1101 | *value_len = len; |
| 1102 | return 0; |
| 1103 | } |
| 1104 | |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1105 | /** |
| 1106 | * fit_image_hash_get_ignore - get hash ignore flag |
| 1107 | * @fit: pointer to the FIT format image header |
| 1108 | * @noffset: hash node offset |
| 1109 | * @ignore: pointer to an int, will hold hash ignore flag |
| 1110 | * |
| 1111 | * fit_image_hash_get_ignore() finds hash ignore property in a given hash node. |
| 1112 | * If the property is found and non-zero, the hash algorithm is not verified by |
| 1113 | * u-boot automatically. |
| 1114 | * |
| 1115 | * returns: |
| 1116 | * 0, on ignore not found |
| 1117 | * value, on ignore found |
| 1118 | */ |
Simon Glass | ab9efc6 | 2013-05-07 06:11:58 +0000 | [diff] [blame] | 1119 | static int fit_image_hash_get_ignore(const void *fit, int noffset, int *ignore) |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1120 | { |
| 1121 | int len; |
| 1122 | int *value; |
| 1123 | |
| 1124 | value = (int *)fdt_getprop(fit, noffset, FIT_IGNORE_PROP, &len); |
| 1125 | if (value == NULL || len != sizeof(int)) |
| 1126 | *ignore = 0; |
| 1127 | else |
| 1128 | *ignore = *value; |
| 1129 | |
| 1130 | return 0; |
| 1131 | } |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1132 | |
Philippe Reynes | 7298e42 | 2019-12-18 18:25:41 +0100 | [diff] [blame] | 1133 | /** |
| 1134 | * fit_image_cipher_get_algo - get cipher algorithm name |
| 1135 | * @fit: pointer to the FIT format image header |
| 1136 | * @noffset: cipher node offset |
| 1137 | * @algo: double pointer to char, will hold pointer to the algorithm name |
| 1138 | * |
| 1139 | * fit_image_cipher_get_algo() finds cipher algorithm property in a given |
| 1140 | * cipher node. If the property is found its data start address is returned |
| 1141 | * to the caller. |
| 1142 | * |
| 1143 | * returns: |
| 1144 | * 0, on success |
| 1145 | * -1, on failure |
| 1146 | */ |
| 1147 | int fit_image_cipher_get_algo(const void *fit, int noffset, char **algo) |
| 1148 | { |
| 1149 | int len; |
| 1150 | |
| 1151 | *algo = (char *)fdt_getprop(fit, noffset, FIT_ALGO_PROP, &len); |
| 1152 | if (!*algo) { |
| 1153 | fit_get_debug(fit, noffset, FIT_ALGO_PROP, len); |
| 1154 | return -1; |
| 1155 | } |
| 1156 | |
| 1157 | return 0; |
| 1158 | } |
| 1159 | |
Simon Glass | 7a80de4 | 2016-02-24 09:14:42 -0700 | [diff] [blame] | 1160 | ulong fit_get_end(const void *fit) |
| 1161 | { |
| 1162 | return map_to_sysmem((void *)(fit + fdt_totalsize(fit))); |
| 1163 | } |
| 1164 | |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1165 | /** |
| 1166 | * fit_set_timestamp - set node timestamp property |
| 1167 | * @fit: pointer to the FIT format image header |
| 1168 | * @noffset: node offset |
| 1169 | * @timestamp: timestamp value to be set |
| 1170 | * |
| 1171 | * fit_set_timestamp() attempts to set timestamp property in the requested |
| 1172 | * node and returns operation status to the caller. |
| 1173 | * |
| 1174 | * returns: |
| 1175 | * 0, on success |
Simon Glass | 4f427a4 | 2014-06-02 22:04:51 -0600 | [diff] [blame] | 1176 | * -ENOSPC if no space in device tree, -1 for other error |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1177 | */ |
| 1178 | int fit_set_timestamp(void *fit, int noffset, time_t timestamp) |
| 1179 | { |
| 1180 | uint32_t t; |
| 1181 | int ret; |
| 1182 | |
| 1183 | t = cpu_to_uimage(timestamp); |
| 1184 | ret = fdt_setprop(fit, noffset, FIT_TIMESTAMP_PROP, &t, |
| 1185 | sizeof(uint32_t)); |
| 1186 | if (ret) { |
Simon Glass | 8df81e1 | 2016-05-01 13:55:37 -0600 | [diff] [blame] | 1187 | debug("Can't set '%s' property for '%s' node (%s)\n", |
| 1188 | FIT_TIMESTAMP_PROP, fit_get_name(fit, noffset, NULL), |
| 1189 | fdt_strerror(ret)); |
Simon Glass | 4f427a4 | 2014-06-02 22:04:51 -0600 | [diff] [blame] | 1190 | return ret == -FDT_ERR_NOSPACE ? -ENOSPC : -1; |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | return 0; |
| 1194 | } |
| 1195 | |
Alexandru Gagniuc | 92055e1 | 2021-09-02 19:54:21 -0500 | [diff] [blame^] | 1196 | static void crc32_uimage_fixup(void *value) |
| 1197 | { |
| 1198 | /* TODO: In C, this type punning is undefined behavior: */ |
| 1199 | *((uint32_t *)value) = cpu_to_uimage(*((uint32_t *)value)); |
| 1200 | } |
| 1201 | |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1202 | /** |
| 1203 | * calculate_hash - calculate and return hash for provided input data |
| 1204 | * @data: pointer to the input data |
| 1205 | * @data_len: data length |
| 1206 | * @algo: requested hash algorithm |
| 1207 | * @value: pointer to the char, will hold hash value data (caller must |
| 1208 | * allocate enough free space) |
| 1209 | * value_len: length of the calculated hash |
| 1210 | * |
| 1211 | * calculate_hash() computes input data hash according to the requested |
| 1212 | * algorithm. |
| 1213 | * Resulting hash value is placed in caller provided 'value' buffer, length |
| 1214 | * of the calculated hash is returned via value_len pointer argument. |
| 1215 | * |
| 1216 | * returns: |
| 1217 | * 0, on success |
| 1218 | * -1, when algo is unsupported |
| 1219 | */ |
Alexandru Gagniuc | 92055e1 | 2021-09-02 19:54:21 -0500 | [diff] [blame^] | 1220 | int calculate_hash(const void *data, int data_len, const char *name, |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1221 | uint8_t *value, int *value_len) |
| 1222 | { |
Alexandru Gagniuc | 92055e1 | 2021-09-02 19:54:21 -0500 | [diff] [blame^] | 1223 | struct hash_algo *algo; |
| 1224 | int ret; |
| 1225 | |
| 1226 | ret = hash_lookup_algo(name, &algo); |
| 1227 | if (ret < 0) { |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1228 | debug("Unsupported hash alogrithm\n"); |
| 1229 | return -1; |
| 1230 | } |
Alexandru Gagniuc | 92055e1 | 2021-09-02 19:54:21 -0500 | [diff] [blame^] | 1231 | |
| 1232 | algo->hash_func_ws(data, data_len, value, algo->chunk_size); |
| 1233 | *value_len = algo->digest_size; |
| 1234 | |
| 1235 | if (!strcmp(name, "crc32")) |
| 1236 | crc32_uimage_fixup(value); |
| 1237 | |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1238 | return 0; |
| 1239 | } |
| 1240 | |
Simon Glass | ab9efc6 | 2013-05-07 06:11:58 +0000 | [diff] [blame] | 1241 | static int fit_image_check_hash(const void *fit, int noffset, const void *data, |
| 1242 | size_t size, char **err_msgp) |
| 1243 | { |
| 1244 | uint8_t value[FIT_MAX_HASH_LEN]; |
| 1245 | int value_len; |
| 1246 | char *algo; |
| 1247 | uint8_t *fit_value; |
| 1248 | int fit_value_len; |
| 1249 | int ignore; |
| 1250 | |
| 1251 | *err_msgp = NULL; |
| 1252 | |
| 1253 | if (fit_image_hash_get_algo(fit, noffset, &algo)) { |
Simon Glass | e754da2 | 2013-05-07 06:11:59 +0000 | [diff] [blame] | 1254 | *err_msgp = "Can't get hash algo property"; |
Simon Glass | ab9efc6 | 2013-05-07 06:11:58 +0000 | [diff] [blame] | 1255 | return -1; |
| 1256 | } |
| 1257 | printf("%s", algo); |
| 1258 | |
| 1259 | if (IMAGE_ENABLE_IGNORE) { |
| 1260 | fit_image_hash_get_ignore(fit, noffset, &ignore); |
| 1261 | if (ignore) { |
| 1262 | printf("-skipped "); |
| 1263 | return 0; |
| 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | if (fit_image_hash_get_value(fit, noffset, &fit_value, |
| 1268 | &fit_value_len)) { |
Simon Glass | e754da2 | 2013-05-07 06:11:59 +0000 | [diff] [blame] | 1269 | *err_msgp = "Can't get hash value property"; |
Simon Glass | ab9efc6 | 2013-05-07 06:11:58 +0000 | [diff] [blame] | 1270 | return -1; |
| 1271 | } |
| 1272 | |
| 1273 | if (calculate_hash(data, size, algo, value, &value_len)) { |
Simon Glass | e754da2 | 2013-05-07 06:11:59 +0000 | [diff] [blame] | 1274 | *err_msgp = "Unsupported hash algorithm"; |
Simon Glass | ab9efc6 | 2013-05-07 06:11:58 +0000 | [diff] [blame] | 1275 | return -1; |
| 1276 | } |
| 1277 | |
| 1278 | if (value_len != fit_value_len) { |
Simon Glass | e754da2 | 2013-05-07 06:11:59 +0000 | [diff] [blame] | 1279 | *err_msgp = "Bad hash value len"; |
Simon Glass | ab9efc6 | 2013-05-07 06:11:58 +0000 | [diff] [blame] | 1280 | return -1; |
| 1281 | } else if (memcmp(value, fit_value, value_len) != 0) { |
Simon Glass | e754da2 | 2013-05-07 06:11:59 +0000 | [diff] [blame] | 1282 | *err_msgp = "Bad hash value"; |
Simon Glass | ab9efc6 | 2013-05-07 06:11:58 +0000 | [diff] [blame] | 1283 | return -1; |
| 1284 | } |
| 1285 | |
| 1286 | return 0; |
| 1287 | } |
| 1288 | |
Jun Nie | 5c643db | 2018-02-27 16:55:58 +0800 | [diff] [blame] | 1289 | int fit_image_verify_with_data(const void *fit, int image_noffset, |
| 1290 | const void *data, size_t size) |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1291 | { |
Simon Glass | 56518e7 | 2013-06-13 15:10:01 -0700 | [diff] [blame] | 1292 | int noffset = 0; |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1293 | char *err_msg = ""; |
Simon Glass | 56518e7 | 2013-06-13 15:10:01 -0700 | [diff] [blame] | 1294 | int verify_all = 1; |
| 1295 | int ret; |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1296 | |
Simon Glass | 56518e7 | 2013-06-13 15:10:01 -0700 | [diff] [blame] | 1297 | /* Verify all required signatures */ |
AKASHI Takahiro | b983cc2 | 2020-02-21 15:12:55 +0900 | [diff] [blame] | 1298 | if (FIT_IMAGE_ENABLE_VERIFY && |
Simon Glass | 56518e7 | 2013-06-13 15:10:01 -0700 | [diff] [blame] | 1299 | fit_image_verify_required_sigs(fit, image_noffset, data, size, |
| 1300 | gd_fdt_blob(), &verify_all)) { |
| 1301 | err_msg = "Unable to verify required signature"; |
| 1302 | goto error; |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | /* Process all hash subnodes of the component image node */ |
Simon Glass | df87e6b | 2016-10-02 17:59:29 -0600 | [diff] [blame] | 1306 | fdt_for_each_subnode(noffset, fit, image_noffset) { |
Simon Glass | ab9efc6 | 2013-05-07 06:11:58 +0000 | [diff] [blame] | 1307 | const char *name = fit_get_name(fit, noffset, NULL); |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1308 | |
Simon Glass | ab9efc6 | 2013-05-07 06:11:58 +0000 | [diff] [blame] | 1309 | /* |
| 1310 | * Check subnode name, must be equal to "hash". |
| 1311 | * Multiple hash nodes require unique unit node |
Andre Przywara | b2267e8 | 2017-12-04 02:05:10 +0000 | [diff] [blame] | 1312 | * names, e.g. hash-1, hash-2, etc. |
Simon Glass | ab9efc6 | 2013-05-07 06:11:58 +0000 | [diff] [blame] | 1313 | */ |
| 1314 | if (!strncmp(name, FIT_HASH_NODENAME, |
| 1315 | strlen(FIT_HASH_NODENAME))) { |
| 1316 | if (fit_image_check_hash(fit, noffset, data, size, |
| 1317 | &err_msg)) |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1318 | goto error; |
Simon Glass | ab9efc6 | 2013-05-07 06:11:58 +0000 | [diff] [blame] | 1319 | puts("+ "); |
AKASHI Takahiro | b983cc2 | 2020-02-21 15:12:55 +0900 | [diff] [blame] | 1320 | } else if (FIT_IMAGE_ENABLE_VERIFY && verify_all && |
Simon Glass | 56518e7 | 2013-06-13 15:10:01 -0700 | [diff] [blame] | 1321 | !strncmp(name, FIT_SIG_NODENAME, |
| 1322 | strlen(FIT_SIG_NODENAME))) { |
| 1323 | ret = fit_image_check_sig(fit, noffset, data, |
| 1324 | size, -1, &err_msg); |
Simon Glass | 2e33e76 | 2016-02-24 09:14:43 -0700 | [diff] [blame] | 1325 | |
| 1326 | /* |
| 1327 | * Show an indication on failure, but do not return |
| 1328 | * an error. Only keys marked 'required' can cause |
| 1329 | * an image validation failure. See the call to |
| 1330 | * fit_image_verify_required_sigs() above. |
| 1331 | */ |
| 1332 | if (ret) |
Simon Glass | 56518e7 | 2013-06-13 15:10:01 -0700 | [diff] [blame] | 1333 | puts("- "); |
| 1334 | else |
| 1335 | puts("+ "); |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | if (noffset == -FDT_ERR_TRUNCATED || noffset == -FDT_ERR_BADSTRUCTURE) { |
Simon Glass | e754da2 | 2013-05-07 06:11:59 +0000 | [diff] [blame] | 1340 | err_msg = "Corrupted or truncated tree"; |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1341 | goto error; |
| 1342 | } |
| 1343 | |
| 1344 | return 1; |
| 1345 | |
| 1346 | error: |
Simon Glass | e754da2 | 2013-05-07 06:11:59 +0000 | [diff] [blame] | 1347 | printf(" error!\n%s for '%s' hash node in '%s' image node\n", |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1348 | err_msg, fit_get_name(fit, noffset, NULL), |
| 1349 | fit_get_name(fit, image_noffset, NULL)); |
| 1350 | return 0; |
| 1351 | } |
| 1352 | |
| 1353 | /** |
Jun Nie | 5c643db | 2018-02-27 16:55:58 +0800 | [diff] [blame] | 1354 | * fit_image_verify - verify data integrity |
| 1355 | * @fit: pointer to the FIT format image header |
| 1356 | * @image_noffset: component image node offset |
| 1357 | * |
| 1358 | * fit_image_verify() goes over component image hash nodes, |
| 1359 | * re-calculates each data hash and compares with the value stored in hash |
| 1360 | * node. |
| 1361 | * |
| 1362 | * returns: |
| 1363 | * 1, if all hashes are valid |
| 1364 | * 0, otherwise (or on error) |
| 1365 | */ |
| 1366 | int fit_image_verify(const void *fit, int image_noffset) |
| 1367 | { |
Simon Glass | 79af75f | 2021-02-15 17:08:06 -0700 | [diff] [blame] | 1368 | const char *name = fit_get_name(fit, image_noffset, NULL); |
Jun Nie | 5c643db | 2018-02-27 16:55:58 +0800 | [diff] [blame] | 1369 | const void *data; |
| 1370 | size_t size; |
Jun Nie | 5c643db | 2018-02-27 16:55:58 +0800 | [diff] [blame] | 1371 | char *err_msg = ""; |
| 1372 | |
Simon Glass | 1ac9c4c | 2021-07-05 16:32:56 -0600 | [diff] [blame] | 1373 | if (IS_ENABLED(CONFIG_FIT_SIGNATURE) && strchr(name, '@')) { |
Simon Glass | 79af75f | 2021-02-15 17:08:06 -0700 | [diff] [blame] | 1374 | /* |
| 1375 | * We don't support this since libfdt considers names with the |
| 1376 | * name root but different @ suffix to be equal |
| 1377 | */ |
| 1378 | err_msg = "Node name contains @"; |
| 1379 | goto err; |
| 1380 | } |
Jun Nie | 5c643db | 2018-02-27 16:55:58 +0800 | [diff] [blame] | 1381 | /* Get image data and data length */ |
Kelvin Cheung | c3c8638 | 2018-05-19 18:21:37 +0800 | [diff] [blame] | 1382 | if (fit_image_get_data_and_size(fit, image_noffset, &data, &size)) { |
Jun Nie | 5c643db | 2018-02-27 16:55:58 +0800 | [diff] [blame] | 1383 | err_msg = "Can't get image data/size"; |
Simon Glass | 79af75f | 2021-02-15 17:08:06 -0700 | [diff] [blame] | 1384 | goto err; |
Jun Nie | 5c643db | 2018-02-27 16:55:58 +0800 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | return fit_image_verify_with_data(fit, image_noffset, data, size); |
Simon Glass | 79af75f | 2021-02-15 17:08:06 -0700 | [diff] [blame] | 1388 | |
| 1389 | err: |
| 1390 | printf("error!\n%s in '%s' image node\n", err_msg, |
| 1391 | fit_get_name(fit, image_noffset, NULL)); |
| 1392 | return 0; |
Jun Nie | 5c643db | 2018-02-27 16:55:58 +0800 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | /** |
Andreas Dannenberg | e17adbb | 2016-06-15 17:00:19 -0500 | [diff] [blame] | 1396 | * fit_all_image_verify - verify data integrity for all images |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1397 | * @fit: pointer to the FIT format image header |
| 1398 | * |
Simon Glass | b8da836 | 2013-05-07 06:11:57 +0000 | [diff] [blame] | 1399 | * fit_all_image_verify() goes over all images in the FIT and |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1400 | * for every images checks if all it's hashes are valid. |
| 1401 | * |
| 1402 | * returns: |
| 1403 | * 1, if all hashes of all images are valid |
| 1404 | * 0, otherwise (or on error) |
| 1405 | */ |
Simon Glass | b8da836 | 2013-05-07 06:11:57 +0000 | [diff] [blame] | 1406 | int fit_all_image_verify(const void *fit) |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1407 | { |
| 1408 | int images_noffset; |
| 1409 | int noffset; |
| 1410 | int ndepth; |
| 1411 | int count; |
| 1412 | |
| 1413 | /* Find images parent node offset */ |
| 1414 | images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); |
| 1415 | if (images_noffset < 0) { |
| 1416 | printf("Can't find images parent node '%s' (%s)\n", |
| 1417 | FIT_IMAGES_PATH, fdt_strerror(images_noffset)); |
| 1418 | return 0; |
| 1419 | } |
| 1420 | |
| 1421 | /* Process all image subnodes, check hashes for each */ |
| 1422 | printf("## Checking hash(es) for FIT Image at %08lx ...\n", |
| 1423 | (ulong)fit); |
| 1424 | for (ndepth = 0, count = 0, |
| 1425 | noffset = fdt_next_node(fit, images_noffset, &ndepth); |
| 1426 | (noffset >= 0) && (ndepth > 0); |
| 1427 | noffset = fdt_next_node(fit, noffset, &ndepth)) { |
| 1428 | if (ndepth == 1) { |
| 1429 | /* |
| 1430 | * Direct child node of the images parent node, |
| 1431 | * i.e. component image node. |
| 1432 | */ |
Simon Glass | 73223f0 | 2016-02-22 22:55:43 -0700 | [diff] [blame] | 1433 | printf(" Hash(es) for Image %u (%s): ", count, |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1434 | fit_get_name(fit, noffset, NULL)); |
Simon Glass | 73223f0 | 2016-02-22 22:55:43 -0700 | [diff] [blame] | 1435 | count++; |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1436 | |
Simon Glass | b8da836 | 2013-05-07 06:11:57 +0000 | [diff] [blame] | 1437 | if (!fit_image_verify(fit, noffset)) |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1438 | return 0; |
| 1439 | printf("\n"); |
| 1440 | } |
| 1441 | } |
| 1442 | return 1; |
| 1443 | } |
| 1444 | |
Philippe Reynes | 4df3578 | 2019-12-18 18:25:42 +0100 | [diff] [blame] | 1445 | static int fit_image_uncipher(const void *fit, int image_noffset, |
| 1446 | void **data, size_t *size) |
| 1447 | { |
| 1448 | int cipher_noffset, ret; |
| 1449 | void *dst; |
| 1450 | size_t size_dst; |
| 1451 | |
| 1452 | cipher_noffset = fdt_subnode_offset(fit, image_noffset, |
| 1453 | FIT_CIPHER_NODENAME); |
| 1454 | if (cipher_noffset < 0) |
| 1455 | return 0; |
| 1456 | |
| 1457 | ret = fit_image_decrypt_data(fit, image_noffset, cipher_noffset, |
| 1458 | *data, *size, &dst, &size_dst); |
| 1459 | if (ret) |
| 1460 | goto out; |
| 1461 | |
| 1462 | *data = dst; |
| 1463 | *size = size_dst; |
| 1464 | |
| 1465 | out: |
| 1466 | return ret; |
| 1467 | } |
Philippe Reynes | 4df3578 | 2019-12-18 18:25:42 +0100 | [diff] [blame] | 1468 | |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1469 | /** |
| 1470 | * fit_image_check_os - check whether image node is of a given os type |
| 1471 | * @fit: pointer to the FIT format image header |
| 1472 | * @noffset: component image node offset |
| 1473 | * @os: requested image os |
| 1474 | * |
| 1475 | * fit_image_check_os() reads image os property and compares its numeric |
| 1476 | * id with the requested os. Comparison result is returned to the caller. |
| 1477 | * |
| 1478 | * returns: |
| 1479 | * 1 if image is of given os type |
| 1480 | * 0 otherwise (or on error) |
| 1481 | */ |
| 1482 | int fit_image_check_os(const void *fit, int noffset, uint8_t os) |
| 1483 | { |
| 1484 | uint8_t image_os; |
| 1485 | |
| 1486 | if (fit_image_get_os(fit, noffset, &image_os)) |
| 1487 | return 0; |
| 1488 | return (os == image_os); |
| 1489 | } |
| 1490 | |
| 1491 | /** |
| 1492 | * fit_image_check_arch - check whether image node is of a given arch |
| 1493 | * @fit: pointer to the FIT format image header |
| 1494 | * @noffset: component image node offset |
| 1495 | * @arch: requested imagearch |
| 1496 | * |
| 1497 | * fit_image_check_arch() reads image arch property and compares its numeric |
| 1498 | * id with the requested arch. Comparison result is returned to the caller. |
| 1499 | * |
| 1500 | * returns: |
| 1501 | * 1 if image is of given arch |
| 1502 | * 0 otherwise (or on error) |
| 1503 | */ |
| 1504 | int fit_image_check_arch(const void *fit, int noffset, uint8_t arch) |
| 1505 | { |
| 1506 | uint8_t image_arch; |
Alison Wang | ec6617c | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 1507 | int aarch32_support = 0; |
| 1508 | |
Simon Glass | e2734d6 | 2021-03-15 18:11:12 +1300 | [diff] [blame] | 1509 | /* Let's assume that sandbox can load any architecture */ |
| 1510 | if (IS_ENABLED(CONFIG_SANDBOX)) |
| 1511 | return true; |
| 1512 | |
Sebastian Reichel | f14e6ee | 2021-01-04 20:48:03 +0100 | [diff] [blame] | 1513 | if (IS_ENABLED(CONFIG_ARM64_SUPPORT_AARCH32)) |
| 1514 | aarch32_support = 1; |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1515 | |
| 1516 | if (fit_image_get_arch(fit, noffset, &image_arch)) |
| 1517 | return 0; |
Simon Glass | 5bda35c | 2014-10-10 08:21:57 -0600 | [diff] [blame] | 1518 | return (arch == image_arch) || |
Alison Wang | ec6617c | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 1519 | (arch == IH_ARCH_I386 && image_arch == IH_ARCH_X86_64) || |
| 1520 | (arch == IH_ARCH_ARM64 && image_arch == IH_ARCH_ARM && |
| 1521 | aarch32_support); |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | /** |
| 1525 | * fit_image_check_type - check whether image node is of a given type |
| 1526 | * @fit: pointer to the FIT format image header |
| 1527 | * @noffset: component image node offset |
| 1528 | * @type: requested image type |
| 1529 | * |
| 1530 | * fit_image_check_type() reads image type property and compares its numeric |
| 1531 | * id with the requested type. Comparison result is returned to the caller. |
| 1532 | * |
| 1533 | * returns: |
| 1534 | * 1 if image is of given type |
| 1535 | * 0 otherwise (or on error) |
| 1536 | */ |
| 1537 | int fit_image_check_type(const void *fit, int noffset, uint8_t type) |
| 1538 | { |
| 1539 | uint8_t image_type; |
| 1540 | |
| 1541 | if (fit_image_get_type(fit, noffset, &image_type)) |
| 1542 | return 0; |
| 1543 | return (type == image_type); |
| 1544 | } |
| 1545 | |
| 1546 | /** |
| 1547 | * fit_image_check_comp - check whether image node uses given compression |
| 1548 | * @fit: pointer to the FIT format image header |
| 1549 | * @noffset: component image node offset |
| 1550 | * @comp: requested image compression type |
| 1551 | * |
| 1552 | * fit_image_check_comp() reads image compression property and compares its |
| 1553 | * numeric id with the requested compression type. Comparison result is |
| 1554 | * returned to the caller. |
| 1555 | * |
| 1556 | * returns: |
| 1557 | * 1 if image uses requested compression |
| 1558 | * 0 otherwise (or on error) |
| 1559 | */ |
| 1560 | int fit_image_check_comp(const void *fit, int noffset, uint8_t comp) |
| 1561 | { |
| 1562 | uint8_t image_comp; |
| 1563 | |
| 1564 | if (fit_image_get_comp(fit, noffset, &image_comp)) |
| 1565 | return 0; |
| 1566 | return (comp == image_comp); |
| 1567 | } |
| 1568 | |
Simon Glass | 3f04db8 | 2021-02-15 17:08:12 -0700 | [diff] [blame] | 1569 | /** |
| 1570 | * fdt_check_no_at() - Check for nodes whose names contain '@' |
| 1571 | * |
| 1572 | * This checks the parent node and all subnodes recursively |
| 1573 | * |
| 1574 | * @fit: FIT to check |
| 1575 | * @parent: Parent node to check |
| 1576 | * @return 0 if OK, -EADDRNOTAVAIL is a node has a name containing '@' |
| 1577 | */ |
| 1578 | static int fdt_check_no_at(const void *fit, int parent) |
| 1579 | { |
| 1580 | const char *name; |
| 1581 | int node; |
| 1582 | int ret; |
| 1583 | |
| 1584 | name = fdt_get_name(fit, parent, NULL); |
| 1585 | if (!name || strchr(name, '@')) |
| 1586 | return -EADDRNOTAVAIL; |
| 1587 | |
| 1588 | fdt_for_each_subnode(node, fit, parent) { |
| 1589 | ret = fdt_check_no_at(fit, node); |
| 1590 | if (ret) |
| 1591 | return ret; |
| 1592 | } |
| 1593 | |
| 1594 | return 0; |
| 1595 | } |
| 1596 | |
Simon Glass | c581970 | 2021-02-15 17:08:09 -0700 | [diff] [blame] | 1597 | int fit_check_format(const void *fit, ulong size) |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1598 | { |
Simon Glass | c581970 | 2021-02-15 17:08:09 -0700 | [diff] [blame] | 1599 | int ret; |
| 1600 | |
Heinrich Schuchardt | ea1a9ec | 2021-01-13 02:09:12 +0100 | [diff] [blame] | 1601 | /* A FIT image must be a valid FDT */ |
Simon Glass | c581970 | 2021-02-15 17:08:09 -0700 | [diff] [blame] | 1602 | ret = fdt_check_header(fit); |
| 1603 | if (ret) { |
| 1604 | log_debug("Wrong FIT format: not a flattened device tree (err=%d)\n", |
| 1605 | ret); |
| 1606 | return -ENOEXEC; |
Heinrich Schuchardt | ea1a9ec | 2021-01-13 02:09:12 +0100 | [diff] [blame] | 1607 | } |
| 1608 | |
Simon Glass | 6f3c2d8 | 2021-02-15 17:08:10 -0700 | [diff] [blame] | 1609 | if (CONFIG_IS_ENABLED(FIT_FULL_CHECK)) { |
| 1610 | /* |
| 1611 | * If we are not given the size, make do wtih calculating it. |
| 1612 | * This is not as secure, so we should consider a flag to |
| 1613 | * control this. |
| 1614 | */ |
| 1615 | if (size == IMAGE_SIZE_INVAL) |
| 1616 | size = fdt_totalsize(fit); |
| 1617 | ret = fdt_check_full(fit, size); |
Simon Glass | 3f04db8 | 2021-02-15 17:08:12 -0700 | [diff] [blame] | 1618 | if (ret) |
| 1619 | ret = -EINVAL; |
Simon Glass | 6f3c2d8 | 2021-02-15 17:08:10 -0700 | [diff] [blame] | 1620 | |
Simon Glass | 3f04db8 | 2021-02-15 17:08:12 -0700 | [diff] [blame] | 1621 | /* |
| 1622 | * U-Boot stopped using unit addressed in 2017. Since libfdt |
| 1623 | * can match nodes ignoring any unit address, signature |
| 1624 | * verification can see the wrong node if one is inserted with |
| 1625 | * the same name as a valid node but with a unit address |
| 1626 | * attached. Protect against this by disallowing unit addresses. |
| 1627 | */ |
| 1628 | if (!ret && CONFIG_IS_ENABLED(FIT_SIGNATURE)) { |
| 1629 | ret = fdt_check_no_at(fit, 0); |
| 1630 | |
| 1631 | if (ret) { |
| 1632 | log_debug("FIT check error %d\n", ret); |
| 1633 | return ret; |
| 1634 | } |
| 1635 | } |
Simon Glass | 6f3c2d8 | 2021-02-15 17:08:10 -0700 | [diff] [blame] | 1636 | if (ret) { |
| 1637 | log_debug("FIT check error %d\n", ret); |
Simon Glass | 3f04db8 | 2021-02-15 17:08:12 -0700 | [diff] [blame] | 1638 | return ret; |
Simon Glass | 6f3c2d8 | 2021-02-15 17:08:10 -0700 | [diff] [blame] | 1639 | } |
| 1640 | } |
| 1641 | |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1642 | /* mandatory / node 'description' property */ |
Simon Glass | c581970 | 2021-02-15 17:08:09 -0700 | [diff] [blame] | 1643 | if (!fdt_getprop(fit, 0, FIT_DESC_PROP, NULL)) { |
| 1644 | log_debug("Wrong FIT format: no description\n"); |
| 1645 | return -ENOMSG; |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1646 | } |
| 1647 | |
| 1648 | if (IMAGE_ENABLE_TIMESTAMP) { |
| 1649 | /* mandatory / node 'timestamp' property */ |
Simon Glass | c581970 | 2021-02-15 17:08:09 -0700 | [diff] [blame] | 1650 | if (!fdt_getprop(fit, 0, FIT_TIMESTAMP_PROP, NULL)) { |
| 1651 | log_debug("Wrong FIT format: no timestamp\n"); |
Simon Glass | 29cbc4b | 2021-02-24 08:50:32 -0500 | [diff] [blame] | 1652 | return -EBADMSG; |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1653 | } |
| 1654 | } |
| 1655 | |
| 1656 | /* mandatory subimages parent '/images' node */ |
| 1657 | if (fdt_path_offset(fit, FIT_IMAGES_PATH) < 0) { |
Simon Glass | c581970 | 2021-02-15 17:08:09 -0700 | [diff] [blame] | 1658 | log_debug("Wrong FIT format: no images parent node\n"); |
| 1659 | return -ENOENT; |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1660 | } |
| 1661 | |
Simon Glass | c581970 | 2021-02-15 17:08:09 -0700 | [diff] [blame] | 1662 | return 0; |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1663 | } |
| 1664 | |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1665 | /** |
| 1666 | * fit_conf_find_compat |
| 1667 | * @fit: pointer to the FIT format image header |
| 1668 | * @fdt: pointer to the device tree to compare against |
| 1669 | * |
| 1670 | * fit_conf_find_compat() attempts to find the configuration whose fdt is the |
| 1671 | * most compatible with the passed in device tree. |
| 1672 | * |
| 1673 | * Example: |
| 1674 | * |
| 1675 | * / o image-tree |
| 1676 | * |-o images |
Andre Przywara | b2267e8 | 2017-12-04 02:05:10 +0000 | [diff] [blame] | 1677 | * | |-o fdt-1 |
| 1678 | * | |-o fdt-2 |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1679 | * | |
| 1680 | * |-o configurations |
Andre Przywara | b2267e8 | 2017-12-04 02:05:10 +0000 | [diff] [blame] | 1681 | * |-o config-1 |
| 1682 | * | |-fdt = fdt-1 |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1683 | * | |
Andre Przywara | b2267e8 | 2017-12-04 02:05:10 +0000 | [diff] [blame] | 1684 | * |-o config-2 |
| 1685 | * |-fdt = fdt-2 |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1686 | * |
| 1687 | * / o U-Boot fdt |
| 1688 | * |-compatible = "foo,bar", "bim,bam" |
| 1689 | * |
| 1690 | * / o kernel fdt1 |
| 1691 | * |-compatible = "foo,bar", |
| 1692 | * |
| 1693 | * / o kernel fdt2 |
| 1694 | * |-compatible = "bim,bam", "baz,biz" |
| 1695 | * |
| 1696 | * Configuration 1 would be picked because the first string in U-Boot's |
| 1697 | * compatible list, "foo,bar", matches a compatible string in the root of fdt1. |
| 1698 | * "bim,bam" in fdt2 matches the second string which isn't as good as fdt1. |
| 1699 | * |
Julius Werner | 18cfa61 | 2019-07-24 19:37:56 -0700 | [diff] [blame] | 1700 | * As an optimization, the compatible property from the FDT's root node can be |
| 1701 | * copied into the configuration node in the FIT image. This is required to |
| 1702 | * match configurations with compressed FDTs. |
| 1703 | * |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1704 | * returns: |
| 1705 | * offset to the configuration to use if one was found |
| 1706 | * -1 otherwise |
| 1707 | */ |
| 1708 | int fit_conf_find_compat(const void *fit, const void *fdt) |
| 1709 | { |
| 1710 | int ndepth = 0; |
| 1711 | int noffset, confs_noffset, images_noffset; |
| 1712 | const void *fdt_compat; |
| 1713 | int fdt_compat_len; |
| 1714 | int best_match_offset = 0; |
| 1715 | int best_match_pos = 0; |
| 1716 | |
| 1717 | confs_noffset = fdt_path_offset(fit, FIT_CONFS_PATH); |
| 1718 | images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); |
| 1719 | if (confs_noffset < 0 || images_noffset < 0) { |
| 1720 | debug("Can't find configurations or images nodes.\n"); |
| 1721 | return -1; |
| 1722 | } |
| 1723 | |
| 1724 | fdt_compat = fdt_getprop(fdt, 0, "compatible", &fdt_compat_len); |
| 1725 | if (!fdt_compat) { |
| 1726 | debug("Fdt for comparison has no \"compatible\" property.\n"); |
| 1727 | return -1; |
| 1728 | } |
| 1729 | |
| 1730 | /* |
| 1731 | * Loop over the configurations in the FIT image. |
| 1732 | */ |
| 1733 | for (noffset = fdt_next_node(fit, confs_noffset, &ndepth); |
| 1734 | (noffset >= 0) && (ndepth > 0); |
| 1735 | noffset = fdt_next_node(fit, noffset, &ndepth)) { |
Julius Werner | 18cfa61 | 2019-07-24 19:37:56 -0700 | [diff] [blame] | 1736 | const void *fdt; |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1737 | const char *kfdt_name; |
Julius Werner | 18cfa61 | 2019-07-24 19:37:56 -0700 | [diff] [blame] | 1738 | int kfdt_noffset, compat_noffset; |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1739 | const char *cur_fdt_compat; |
| 1740 | int len; |
Julius Werner | 18cfa61 | 2019-07-24 19:37:56 -0700 | [diff] [blame] | 1741 | size_t sz; |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1742 | int i; |
| 1743 | |
| 1744 | if (ndepth > 1) |
| 1745 | continue; |
| 1746 | |
Julius Werner | 18cfa61 | 2019-07-24 19:37:56 -0700 | [diff] [blame] | 1747 | /* If there's a compat property in the config node, use that. */ |
| 1748 | if (fdt_getprop(fit, noffset, "compatible", NULL)) { |
| 1749 | fdt = fit; /* search in FIT image */ |
| 1750 | compat_noffset = noffset; /* search under config node */ |
| 1751 | } else { /* Otherwise extract it from the kernel FDT. */ |
| 1752 | kfdt_name = fdt_getprop(fit, noffset, "fdt", &len); |
| 1753 | if (!kfdt_name) { |
| 1754 | debug("No fdt property found.\n"); |
| 1755 | continue; |
| 1756 | } |
| 1757 | kfdt_noffset = fdt_subnode_offset(fit, images_noffset, |
| 1758 | kfdt_name); |
| 1759 | if (kfdt_noffset < 0) { |
| 1760 | debug("No image node named \"%s\" found.\n", |
| 1761 | kfdt_name); |
| 1762 | continue; |
| 1763 | } |
Julius Werner | b1307f8 | 2019-07-24 19:37:55 -0700 | [diff] [blame] | 1764 | |
Julius Werner | 18cfa61 | 2019-07-24 19:37:56 -0700 | [diff] [blame] | 1765 | if (!fit_image_check_comp(fit, kfdt_noffset, |
| 1766 | IH_COMP_NONE)) { |
| 1767 | debug("Can't extract compat from \"%s\" " |
| 1768 | "(compressed)\n", kfdt_name); |
| 1769 | continue; |
| 1770 | } |
Julius Werner | b1307f8 | 2019-07-24 19:37:55 -0700 | [diff] [blame] | 1771 | |
Julius Werner | 18cfa61 | 2019-07-24 19:37:56 -0700 | [diff] [blame] | 1772 | /* search in this config's kernel FDT */ |
John Keeping | 650bf00 | 2021-06-25 17:58:04 +0100 | [diff] [blame] | 1773 | if (fit_image_get_data_and_size(fit, kfdt_noffset, |
| 1774 | &fdt, &sz)) { |
Julius Werner | 18cfa61 | 2019-07-24 19:37:56 -0700 | [diff] [blame] | 1775 | debug("Failed to get fdt \"%s\".\n", kfdt_name); |
| 1776 | continue; |
| 1777 | } |
| 1778 | |
| 1779 | compat_noffset = 0; /* search kFDT under root node */ |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | len = fdt_compat_len; |
| 1783 | cur_fdt_compat = fdt_compat; |
| 1784 | /* |
| 1785 | * Look for a match for each U-Boot compatibility string in |
Julius Werner | 18cfa61 | 2019-07-24 19:37:56 -0700 | [diff] [blame] | 1786 | * turn in the compat string property. |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1787 | */ |
| 1788 | for (i = 0; len > 0 && |
| 1789 | (!best_match_offset || best_match_pos > i); i++) { |
| 1790 | int cur_len = strlen(cur_fdt_compat) + 1; |
| 1791 | |
Julius Werner | 18cfa61 | 2019-07-24 19:37:56 -0700 | [diff] [blame] | 1792 | if (!fdt_node_check_compatible(fdt, compat_noffset, |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1793 | cur_fdt_compat)) { |
| 1794 | best_match_offset = noffset; |
| 1795 | best_match_pos = i; |
| 1796 | break; |
| 1797 | } |
| 1798 | len -= cur_len; |
| 1799 | cur_fdt_compat += cur_len; |
| 1800 | } |
| 1801 | } |
| 1802 | if (!best_match_offset) { |
| 1803 | debug("No match found.\n"); |
| 1804 | return -1; |
| 1805 | } |
| 1806 | |
| 1807 | return best_match_offset; |
| 1808 | } |
| 1809 | |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1810 | int fit_conf_get_node(const void *fit, const char *conf_uname) |
| 1811 | { |
| 1812 | int noffset, confs_noffset; |
| 1813 | int len; |
Pantelis Antoniou | 169043d | 2017-09-04 23:12:16 +0300 | [diff] [blame] | 1814 | const char *s; |
| 1815 | char *conf_uname_copy = NULL; |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1816 | |
| 1817 | confs_noffset = fdt_path_offset(fit, FIT_CONFS_PATH); |
| 1818 | if (confs_noffset < 0) { |
| 1819 | debug("Can't find configurations parent node '%s' (%s)\n", |
| 1820 | FIT_CONFS_PATH, fdt_strerror(confs_noffset)); |
| 1821 | return confs_noffset; |
| 1822 | } |
| 1823 | |
| 1824 | if (conf_uname == NULL) { |
| 1825 | /* get configuration unit name from the default property */ |
| 1826 | debug("No configuration specified, trying default...\n"); |
Sebastian Reichel | d8ab0fe | 2021-01-04 20:48:04 +0100 | [diff] [blame] | 1827 | if (!host_build() && IS_ENABLED(CONFIG_MULTI_DTB_FIT)) { |
| 1828 | noffset = fit_find_config_node(fit); |
| 1829 | if (noffset < 0) |
| 1830 | return noffset; |
| 1831 | conf_uname = fdt_get_name(fit, noffset, NULL); |
| 1832 | } else { |
| 1833 | conf_uname = (char *)fdt_getprop(fit, confs_noffset, |
| 1834 | FIT_DEFAULT_PROP, &len); |
| 1835 | if (conf_uname == NULL) { |
| 1836 | fit_get_debug(fit, confs_noffset, FIT_DEFAULT_PROP, |
| 1837 | len); |
| 1838 | return len; |
| 1839 | } |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1840 | } |
| 1841 | debug("Found default configuration: '%s'\n", conf_uname); |
| 1842 | } |
| 1843 | |
Pantelis Antoniou | 169043d | 2017-09-04 23:12:16 +0300 | [diff] [blame] | 1844 | s = strchr(conf_uname, '#'); |
| 1845 | if (s) { |
| 1846 | len = s - conf_uname; |
| 1847 | conf_uname_copy = malloc(len + 1); |
| 1848 | if (!conf_uname_copy) { |
| 1849 | debug("Can't allocate uname copy: '%s'\n", |
| 1850 | conf_uname); |
| 1851 | return -ENOMEM; |
| 1852 | } |
| 1853 | memcpy(conf_uname_copy, conf_uname, len); |
| 1854 | conf_uname_copy[len] = '\0'; |
| 1855 | conf_uname = conf_uname_copy; |
| 1856 | } |
| 1857 | |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1858 | noffset = fdt_subnode_offset(fit, confs_noffset, conf_uname); |
| 1859 | if (noffset < 0) { |
| 1860 | debug("Can't get node offset for configuration unit name: '%s' (%s)\n", |
| 1861 | conf_uname, fdt_strerror(noffset)); |
| 1862 | } |
| 1863 | |
Pantelis Antoniou | 169043d | 2017-09-04 23:12:16 +0300 | [diff] [blame] | 1864 | if (conf_uname_copy) |
| 1865 | free(conf_uname_copy); |
| 1866 | |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1867 | return noffset; |
| 1868 | } |
| 1869 | |
Pantelis Antoniou | ad026ad | 2017-09-04 23:12:14 +0300 | [diff] [blame] | 1870 | int fit_conf_get_prop_node_count(const void *fit, int noffset, |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1871 | const char *prop_name) |
| 1872 | { |
Pantelis Antoniou | ad026ad | 2017-09-04 23:12:14 +0300 | [diff] [blame] | 1873 | return fdt_stringlist_count(fit, noffset, prop_name); |
| 1874 | } |
| 1875 | |
| 1876 | int fit_conf_get_prop_node_index(const void *fit, int noffset, |
| 1877 | const char *prop_name, int index) |
| 1878 | { |
| 1879 | const char *uname; |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1880 | int len; |
| 1881 | |
| 1882 | /* get kernel image unit name from configuration kernel property */ |
Pantelis Antoniou | ad026ad | 2017-09-04 23:12:14 +0300 | [diff] [blame] | 1883 | uname = fdt_stringlist_get(fit, noffset, prop_name, index, &len); |
Simon Glass | 53fbb7e | 2013-05-07 06:11:53 +0000 | [diff] [blame] | 1884 | if (uname == NULL) |
| 1885 | return len; |
| 1886 | |
| 1887 | return fit_image_get_node(fit, uname); |
| 1888 | } |
| 1889 | |
Pantelis Antoniou | ad026ad | 2017-09-04 23:12:14 +0300 | [diff] [blame] | 1890 | int fit_conf_get_prop_node(const void *fit, int noffset, |
| 1891 | const char *prop_name) |
| 1892 | { |
| 1893 | return fit_conf_get_prop_node_index(fit, noffset, prop_name, 0); |
| 1894 | } |
| 1895 | |
Jeroen Hofstee | 718feca | 2014-10-08 22:57:38 +0200 | [diff] [blame] | 1896 | static int fit_image_select(const void *fit, int rd_noffset, int verify) |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 1897 | { |
| 1898 | fit_image_print(fit, rd_noffset, " "); |
| 1899 | |
| 1900 | if (verify) { |
| 1901 | puts(" Verifying Hash Integrity ... "); |
| 1902 | if (!fit_image_verify(fit, rd_noffset)) { |
| 1903 | puts("Bad Data Hash\n"); |
| 1904 | return -EACCES; |
| 1905 | } |
| 1906 | puts("OK\n"); |
| 1907 | } |
| 1908 | |
| 1909 | return 0; |
| 1910 | } |
| 1911 | |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 1912 | int fit_get_node_from_config(bootm_headers_t *images, const char *prop_name, |
| 1913 | ulong addr) |
| 1914 | { |
| 1915 | int cfg_noffset; |
| 1916 | void *fit_hdr; |
| 1917 | int noffset; |
| 1918 | |
| 1919 | debug("* %s: using config '%s' from image at 0x%08lx\n", |
| 1920 | prop_name, images->fit_uname_cfg, addr); |
| 1921 | |
| 1922 | /* Check whether configuration has this property defined */ |
| 1923 | fit_hdr = map_sysmem(addr, 0); |
| 1924 | cfg_noffset = fit_conf_get_node(fit_hdr, images->fit_uname_cfg); |
| 1925 | if (cfg_noffset < 0) { |
| 1926 | debug("* %s: no such config\n", prop_name); |
Paul Burton | bd86ef1 | 2016-09-20 18:17:12 +0100 | [diff] [blame] | 1927 | return -EINVAL; |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | noffset = fit_conf_get_prop_node(fit_hdr, cfg_noffset, prop_name); |
| 1931 | if (noffset < 0) { |
| 1932 | debug("* %s: no '%s' in config\n", prop_name, prop_name); |
Jonathan Gray | bac17b7 | 2016-09-03 08:30:14 +1000 | [diff] [blame] | 1933 | return -ENOENT; |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | return noffset; |
| 1937 | } |
| 1938 | |
Simon Glass | 126cc86 | 2014-06-12 07:24:47 -0600 | [diff] [blame] | 1939 | /** |
| 1940 | * fit_get_image_type_property() - get property name for IH_TYPE_... |
| 1941 | * |
| 1942 | * @return the properly name where we expect to find the image in the |
| 1943 | * config node |
| 1944 | */ |
| 1945 | static const char *fit_get_image_type_property(int type) |
| 1946 | { |
| 1947 | /* |
| 1948 | * This is sort-of available in the uimage_type[] table in image.c |
Andreas Dannenberg | e17adbb | 2016-06-15 17:00:19 -0500 | [diff] [blame] | 1949 | * but we don't have access to the short name, and "fdt" is different |
Simon Glass | 126cc86 | 2014-06-12 07:24:47 -0600 | [diff] [blame] | 1950 | * anyway. So let's just keep it here. |
| 1951 | */ |
| 1952 | switch (type) { |
| 1953 | case IH_TYPE_FLATDT: |
| 1954 | return FIT_FDT_PROP; |
| 1955 | case IH_TYPE_KERNEL: |
| 1956 | return FIT_KERNEL_PROP; |
Alexandru Gagniuc | 47b6f7f | 2021-04-01 13:25:30 -0500 | [diff] [blame] | 1957 | case IH_TYPE_FIRMWARE: |
| 1958 | return FIT_FIRMWARE_PROP; |
Simon Glass | 126cc86 | 2014-06-12 07:24:47 -0600 | [diff] [blame] | 1959 | case IH_TYPE_RAMDISK: |
| 1960 | return FIT_RAMDISK_PROP; |
Simon Glass | 90268b8 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 1961 | case IH_TYPE_X86_SETUP: |
| 1962 | return FIT_SETUP_PROP; |
Karl Apsite | 84a07db | 2015-05-21 09:52:48 -0400 | [diff] [blame] | 1963 | case IH_TYPE_LOADABLE: |
| 1964 | return FIT_LOADABLE_PROP; |
Michal Simek | 62afc60 | 2016-05-17 14:03:50 +0200 | [diff] [blame] | 1965 | case IH_TYPE_FPGA: |
| 1966 | return FIT_FPGA_PROP; |
Marek Vasut | 0298d20 | 2018-05-13 00:22:54 +0200 | [diff] [blame] | 1967 | case IH_TYPE_STANDALONE: |
| 1968 | return FIT_STANDALONE_PROP; |
Simon Glass | 126cc86 | 2014-06-12 07:24:47 -0600 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | return "unknown"; |
| 1972 | } |
| 1973 | |
| 1974 | int fit_image_load(bootm_headers_t *images, ulong addr, |
Simon Glass | f320a4d | 2013-07-10 23:08:10 -0700 | [diff] [blame] | 1975 | const char **fit_unamep, const char **fit_uname_configp, |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 1976 | int arch, int image_type, int bootstage_id, |
| 1977 | enum fit_load_op load_op, ulong *datap, ulong *lenp) |
| 1978 | { |
| 1979 | int cfg_noffset, noffset; |
| 1980 | const char *fit_uname; |
Simon Glass | f320a4d | 2013-07-10 23:08:10 -0700 | [diff] [blame] | 1981 | const char *fit_uname_config; |
Pantelis Antoniou | 7c3dc77 | 2017-09-04 23:12:15 +0300 | [diff] [blame] | 1982 | const char *fit_base_uname_config; |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 1983 | const void *fit; |
Julius Werner | b1307f8 | 2019-07-24 19:37:55 -0700 | [diff] [blame] | 1984 | void *buf; |
| 1985 | void *loadbuf; |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 1986 | size_t size; |
| 1987 | int type_ok, os_ok; |
Julius Werner | b1307f8 | 2019-07-24 19:37:55 -0700 | [diff] [blame] | 1988 | ulong load, load_end, data, len; |
| 1989 | uint8_t os, comp; |
Alison Wang | ec6617c | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 1990 | #ifndef USE_HOSTCC |
| 1991 | uint8_t os_arch; |
| 1992 | #endif |
Simon Glass | 126cc86 | 2014-06-12 07:24:47 -0600 | [diff] [blame] | 1993 | const char *prop_name; |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 1994 | int ret; |
| 1995 | |
| 1996 | fit = map_sysmem(addr, 0); |
| 1997 | fit_uname = fit_unamep ? *fit_unamep : NULL; |
Simon Glass | f320a4d | 2013-07-10 23:08:10 -0700 | [diff] [blame] | 1998 | fit_uname_config = fit_uname_configp ? *fit_uname_configp : NULL; |
Pantelis Antoniou | 7c3dc77 | 2017-09-04 23:12:15 +0300 | [diff] [blame] | 1999 | fit_base_uname_config = NULL; |
Simon Glass | 126cc86 | 2014-06-12 07:24:47 -0600 | [diff] [blame] | 2000 | prop_name = fit_get_image_type_property(image_type); |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2001 | printf("## Loading %s from FIT Image at %08lx ...\n", prop_name, addr); |
| 2002 | |
| 2003 | bootstage_mark(bootstage_id + BOOTSTAGE_SUB_FORMAT); |
Simon Glass | 3f04db8 | 2021-02-15 17:08:12 -0700 | [diff] [blame] | 2004 | ret = fit_check_format(fit, IMAGE_SIZE_INVAL); |
| 2005 | if (ret) { |
| 2006 | printf("Bad FIT %s image format! (err=%d)\n", prop_name, ret); |
| 2007 | if (CONFIG_IS_ENABLED(FIT_SIGNATURE) && ret == -EADDRNOTAVAIL) |
| 2008 | printf("Signature checking prevents use of unit addresses (@) in nodes\n"); |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2009 | bootstage_error(bootstage_id + BOOTSTAGE_SUB_FORMAT); |
Simon Glass | 3f04db8 | 2021-02-15 17:08:12 -0700 | [diff] [blame] | 2010 | return ret; |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2011 | } |
| 2012 | bootstage_mark(bootstage_id + BOOTSTAGE_SUB_FORMAT_OK); |
| 2013 | if (fit_uname) { |
Masahiro Yamada | f150c83 | 2014-02-18 15:39:21 +0900 | [diff] [blame] | 2014 | /* get FIT component image node offset */ |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2015 | bootstage_mark(bootstage_id + BOOTSTAGE_SUB_UNIT_NAME); |
| 2016 | noffset = fit_image_get_node(fit, fit_uname); |
| 2017 | } else { |
| 2018 | /* |
| 2019 | * no image node unit name, try to get config |
| 2020 | * node first. If config unit node name is NULL |
| 2021 | * fit_conf_get_node() will try to find default config node |
| 2022 | */ |
| 2023 | bootstage_mark(bootstage_id + BOOTSTAGE_SUB_NO_UNIT_NAME); |
Simon Glass | 70c1c89 | 2021-07-14 17:05:36 -0500 | [diff] [blame] | 2024 | if (IS_ENABLED(CONFIG_FIT_BEST_MATCH) && !fit_uname_config) { |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2025 | cfg_noffset = fit_conf_find_compat(fit, gd_fdt_blob()); |
| 2026 | } else { |
| 2027 | cfg_noffset = fit_conf_get_node(fit, |
| 2028 | fit_uname_config); |
| 2029 | } |
| 2030 | if (cfg_noffset < 0) { |
| 2031 | puts("Could not find configuration node\n"); |
| 2032 | bootstage_error(bootstage_id + |
| 2033 | BOOTSTAGE_SUB_NO_UNIT_NAME); |
| 2034 | return -ENOENT; |
| 2035 | } |
Marek Vasut | 078e558 | 2018-05-31 17:59:07 +0200 | [diff] [blame] | 2036 | |
Pantelis Antoniou | 7c3dc77 | 2017-09-04 23:12:15 +0300 | [diff] [blame] | 2037 | fit_base_uname_config = fdt_get_name(fit, cfg_noffset, NULL); |
| 2038 | printf(" Using '%s' configuration\n", fit_base_uname_config); |
Marek Vasut | 078e558 | 2018-05-31 17:59:07 +0200 | [diff] [blame] | 2039 | /* Remember this config */ |
| 2040 | if (image_type == IH_TYPE_KERNEL) |
Pantelis Antoniou | 7c3dc77 | 2017-09-04 23:12:15 +0300 | [diff] [blame] | 2041 | images->fit_uname_cfg = fit_base_uname_config; |
Marek Vasut | 078e558 | 2018-05-31 17:59:07 +0200 | [diff] [blame] | 2042 | |
AKASHI Takahiro | b983cc2 | 2020-02-21 15:12:55 +0900 | [diff] [blame] | 2043 | if (FIT_IMAGE_ENABLE_VERIFY && images->verify) { |
Marek Vasut | 078e558 | 2018-05-31 17:59:07 +0200 | [diff] [blame] | 2044 | puts(" Verifying Hash Integrity ... "); |
| 2045 | if (fit_config_verify(fit, cfg_noffset)) { |
| 2046 | puts("Bad Data Hash\n"); |
| 2047 | bootstage_error(bootstage_id + |
| 2048 | BOOTSTAGE_SUB_HASH); |
| 2049 | return -EACCES; |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2050 | } |
Marek Vasut | 078e558 | 2018-05-31 17:59:07 +0200 | [diff] [blame] | 2051 | puts("OK\n"); |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2052 | } |
| 2053 | |
Marek Vasut | 078e558 | 2018-05-31 17:59:07 +0200 | [diff] [blame] | 2054 | bootstage_mark(BOOTSTAGE_ID_FIT_CONFIG); |
| 2055 | |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2056 | noffset = fit_conf_get_prop_node(fit, cfg_noffset, |
| 2057 | prop_name); |
| 2058 | fit_uname = fit_get_name(fit, noffset, NULL); |
| 2059 | } |
| 2060 | if (noffset < 0) { |
Simon Glass | 382cf62 | 2020-03-18 11:43:56 -0600 | [diff] [blame] | 2061 | printf("Could not find subimage node type '%s'\n", prop_name); |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2062 | bootstage_error(bootstage_id + BOOTSTAGE_SUB_SUBNODE); |
| 2063 | return -ENOENT; |
| 2064 | } |
| 2065 | |
| 2066 | printf(" Trying '%s' %s subimage\n", fit_uname, prop_name); |
| 2067 | |
| 2068 | ret = fit_image_select(fit, noffset, images->verify); |
| 2069 | if (ret) { |
| 2070 | bootstage_error(bootstage_id + BOOTSTAGE_SUB_HASH); |
| 2071 | return ret; |
| 2072 | } |
| 2073 | |
| 2074 | bootstage_mark(bootstage_id + BOOTSTAGE_SUB_CHECK_ARCH); |
Sebastian Reichel | f14e6ee | 2021-01-04 20:48:03 +0100 | [diff] [blame] | 2075 | if (!host_build() && IS_ENABLED(CONFIG_SANDBOX)) { |
| 2076 | if (!fit_image_check_target_arch(fit, noffset)) { |
| 2077 | puts("Unsupported Architecture\n"); |
| 2078 | bootstage_error(bootstage_id + BOOTSTAGE_SUB_CHECK_ARCH); |
| 2079 | return -ENOEXEC; |
| 2080 | } |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2081 | } |
Alison Wang | ec6617c | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 2082 | |
| 2083 | #ifndef USE_HOSTCC |
| 2084 | fit_image_get_arch(fit, noffset, &os_arch); |
| 2085 | images->os.arch = os_arch; |
| 2086 | #endif |
| 2087 | |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2088 | bootstage_mark(bootstage_id + BOOTSTAGE_SUB_CHECK_ALL); |
| 2089 | type_ok = fit_image_check_type(fit, noffset, image_type) || |
mario.six@gdsys.cc | e8fb435 | 2016-07-20 08:32:50 +0200 | [diff] [blame] | 2090 | fit_image_check_type(fit, noffset, IH_TYPE_FIRMWARE) || |
Alexandru Gagniuc | 033ac4e | 2021-04-01 13:25:31 -0500 | [diff] [blame] | 2091 | fit_image_check_type(fit, noffset, IH_TYPE_TEE) || |
mario.six@gdsys.cc | e8fb435 | 2016-07-20 08:32:50 +0200 | [diff] [blame] | 2092 | (image_type == IH_TYPE_KERNEL && |
| 2093 | fit_image_check_type(fit, noffset, IH_TYPE_KERNEL_NOLOAD)); |
Marek Vasut | 3811723 | 2014-12-16 14:07:22 +0100 | [diff] [blame] | 2094 | |
Andreas Bießmann | 950fe26 | 2016-08-14 20:31:24 +0200 | [diff] [blame] | 2095 | os_ok = image_type == IH_TYPE_FLATDT || |
| 2096 | image_type == IH_TYPE_FPGA || |
Marek Vasut | 3811723 | 2014-12-16 14:07:22 +0100 | [diff] [blame] | 2097 | fit_image_check_os(fit, noffset, IH_OS_LINUX) || |
mario.six@gdsys.cc | e8fb435 | 2016-07-20 08:32:50 +0200 | [diff] [blame] | 2098 | fit_image_check_os(fit, noffset, IH_OS_U_BOOT) || |
Alexandru Gagniuc | 033ac4e | 2021-04-01 13:25:31 -0500 | [diff] [blame] | 2099 | fit_image_check_os(fit, noffset, IH_OS_TEE) || |
Cristian Ciocaltea | a031b03 | 2019-12-24 18:05:38 +0200 | [diff] [blame] | 2100 | fit_image_check_os(fit, noffset, IH_OS_OPENRTOS) || |
Lihua Zhao | 0df27d6 | 2020-03-18 07:32:07 -0700 | [diff] [blame] | 2101 | fit_image_check_os(fit, noffset, IH_OS_EFI) || |
| 2102 | fit_image_check_os(fit, noffset, IH_OS_VXWORKS); |
Karl Apsite | 84a07db | 2015-05-21 09:52:48 -0400 | [diff] [blame] | 2103 | |
| 2104 | /* |
| 2105 | * If either of the checks fail, we should report an error, but |
| 2106 | * if the image type is coming from the "loadables" field, we |
| 2107 | * don't care what it is |
| 2108 | */ |
| 2109 | if ((!type_ok || !os_ok) && image_type != IH_TYPE_LOADABLE) { |
Marek Vasut | 3811723 | 2014-12-16 14:07:22 +0100 | [diff] [blame] | 2110 | fit_image_get_os(fit, noffset, &os); |
| 2111 | printf("No %s %s %s Image\n", |
| 2112 | genimg_get_os_name(os), |
| 2113 | genimg_get_arch_name(arch), |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2114 | genimg_get_type_name(image_type)); |
| 2115 | bootstage_error(bootstage_id + BOOTSTAGE_SUB_CHECK_ALL); |
| 2116 | return -EIO; |
| 2117 | } |
| 2118 | |
| 2119 | bootstage_mark(bootstage_id + BOOTSTAGE_SUB_CHECK_ALL_OK); |
| 2120 | |
| 2121 | /* get image data address and length */ |
Julius Werner | b1307f8 | 2019-07-24 19:37:55 -0700 | [diff] [blame] | 2122 | if (fit_image_get_data_and_size(fit, noffset, |
| 2123 | (const void **)&buf, &size)) { |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2124 | printf("Could not find %s subimage data!\n", prop_name); |
| 2125 | bootstage_error(bootstage_id + BOOTSTAGE_SUB_GET_DATA); |
Simon Glass | 2f99807 | 2013-06-16 07:46:49 -0700 | [diff] [blame] | 2126 | return -ENOENT; |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2127 | } |
Andrew F. Davis | 44402fe | 2016-11-21 14:37:09 -0600 | [diff] [blame] | 2128 | |
Philippe Reynes | 4df3578 | 2019-12-18 18:25:42 +0100 | [diff] [blame] | 2129 | /* Decrypt data before uncompress/move */ |
Sebastian Reichel | f14e6ee | 2021-01-04 20:48:03 +0100 | [diff] [blame] | 2130 | if (IS_ENABLED(CONFIG_FIT_CIPHER) && IMAGE_ENABLE_DECRYPT) { |
Philippe Reynes | 4df3578 | 2019-12-18 18:25:42 +0100 | [diff] [blame] | 2131 | puts(" Decrypting Data ... "); |
| 2132 | if (fit_image_uncipher(fit, noffset, &buf, &size)) { |
| 2133 | puts("Error\n"); |
| 2134 | return -EACCES; |
| 2135 | } |
| 2136 | puts("OK\n"); |
| 2137 | } |
Philippe Reynes | 4df3578 | 2019-12-18 18:25:42 +0100 | [diff] [blame] | 2138 | |
Andrew F. Davis | 44402fe | 2016-11-21 14:37:09 -0600 | [diff] [blame] | 2139 | /* perform any post-processing on the image data */ |
Sebastian Reichel | f14e6ee | 2021-01-04 20:48:03 +0100 | [diff] [blame] | 2140 | if (!host_build() && IS_ENABLED(CONFIG_FIT_IMAGE_POST_PROCESS)) |
Lokesh Vutla | 481d394 | 2021-06-11 11:45:05 +0300 | [diff] [blame] | 2141 | board_fit_image_post_process(fit, noffset, &buf, &size); |
Andrew F. Davis | 44402fe | 2016-11-21 14:37:09 -0600 | [diff] [blame] | 2142 | |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2143 | len = (ulong)size; |
| 2144 | |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2145 | bootstage_mark(bootstage_id + BOOTSTAGE_SUB_GET_DATA_OK); |
| 2146 | |
Julius Werner | b1307f8 | 2019-07-24 19:37:55 -0700 | [diff] [blame] | 2147 | data = map_to_sysmem(buf); |
| 2148 | load = data; |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2149 | if (load_op == FIT_LOAD_IGNORED) { |
| 2150 | /* Don't load */ |
| 2151 | } else if (fit_image_get_load(fit, noffset, &load)) { |
| 2152 | if (load_op == FIT_LOAD_REQUIRED) { |
| 2153 | printf("Can't get %s subimage load address!\n", |
| 2154 | prop_name); |
| 2155 | bootstage_error(bootstage_id + BOOTSTAGE_SUB_LOAD); |
| 2156 | return -EBADF; |
| 2157 | } |
Simon Glass | fe20a81 | 2014-08-22 14:26:43 -0600 | [diff] [blame] | 2158 | } else if (load_op != FIT_LOAD_OPTIONAL_NON_ZERO || load) { |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2159 | ulong image_start, image_end; |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2160 | |
| 2161 | /* |
| 2162 | * move image data to the load address, |
| 2163 | * make sure we don't overwrite initial image |
| 2164 | */ |
| 2165 | image_start = addr; |
| 2166 | image_end = addr + fit_get_size(fit); |
| 2167 | |
| 2168 | load_end = load + len; |
| 2169 | if (image_type != IH_TYPE_KERNEL && |
| 2170 | load < image_end && load_end > image_start) { |
| 2171 | printf("Error: %s overwritten\n", prop_name); |
| 2172 | return -EXDEV; |
| 2173 | } |
| 2174 | |
| 2175 | printf(" Loading %s from 0x%08lx to 0x%08lx\n", |
| 2176 | prop_name, data, load); |
Julius Werner | b1307f8 | 2019-07-24 19:37:55 -0700 | [diff] [blame] | 2177 | } else { |
| 2178 | load = data; /* No load address specified */ |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2179 | } |
Julius Werner | b1307f8 | 2019-07-24 19:37:55 -0700 | [diff] [blame] | 2180 | |
| 2181 | comp = IH_COMP_NONE; |
| 2182 | loadbuf = buf; |
| 2183 | /* Kernel images get decompressed later in bootm_load_os(). */ |
Julius Werner | bddd985 | 2019-08-02 15:52:28 -0700 | [diff] [blame] | 2184 | if (!fit_image_get_comp(fit, noffset, &comp) && |
| 2185 | comp != IH_COMP_NONE && |
| 2186 | !(image_type == IH_TYPE_KERNEL || |
| 2187 | image_type == IH_TYPE_KERNEL_NOLOAD || |
| 2188 | image_type == IH_TYPE_RAMDISK)) { |
Julius Werner | b1307f8 | 2019-07-24 19:37:55 -0700 | [diff] [blame] | 2189 | ulong max_decomp_len = len * 20; |
| 2190 | if (load == data) { |
| 2191 | loadbuf = malloc(max_decomp_len); |
| 2192 | load = map_to_sysmem(loadbuf); |
| 2193 | } else { |
| 2194 | loadbuf = map_sysmem(load, max_decomp_len); |
| 2195 | } |
| 2196 | if (image_decomp(comp, load, data, image_type, |
| 2197 | loadbuf, buf, len, max_decomp_len, &load_end)) { |
| 2198 | printf("Error decompressing %s\n", prop_name); |
| 2199 | |
| 2200 | return -ENOEXEC; |
| 2201 | } |
| 2202 | len = load_end - load; |
| 2203 | } else if (load != data) { |
| 2204 | loadbuf = map_sysmem(load, len); |
| 2205 | memcpy(loadbuf, buf, len); |
| 2206 | } |
| 2207 | |
Julius Werner | bddd985 | 2019-08-02 15:52:28 -0700 | [diff] [blame] | 2208 | if (image_type == IH_TYPE_RAMDISK && comp != IH_COMP_NONE) |
| 2209 | puts("WARNING: 'compression' nodes for ramdisks are deprecated," |
| 2210 | " please fix your .its file!\n"); |
| 2211 | |
Julius Werner | b1307f8 | 2019-07-24 19:37:55 -0700 | [diff] [blame] | 2212 | /* verify that image data is a proper FDT blob */ |
| 2213 | if (image_type == IH_TYPE_FLATDT && fdt_check_header(loadbuf)) { |
| 2214 | puts("Subimage data is not a FDT"); |
| 2215 | return -ENOEXEC; |
| 2216 | } |
| 2217 | |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2218 | bootstage_mark(bootstage_id + BOOTSTAGE_SUB_LOAD); |
| 2219 | |
Julius Werner | b1307f8 | 2019-07-24 19:37:55 -0700 | [diff] [blame] | 2220 | *datap = load; |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2221 | *lenp = len; |
| 2222 | if (fit_unamep) |
| 2223 | *fit_unamep = (char *)fit_uname; |
Simon Glass | f320a4d | 2013-07-10 23:08:10 -0700 | [diff] [blame] | 2224 | if (fit_uname_configp) |
Pantelis Antoniou | 7c3dc77 | 2017-09-04 23:12:15 +0300 | [diff] [blame] | 2225 | *fit_uname_configp = (char *)(fit_uname_config ? : |
| 2226 | fit_base_uname_config); |
Simon Glass | 782cfbb | 2013-05-16 13:53:21 +0000 | [diff] [blame] | 2227 | |
| 2228 | return noffset; |
| 2229 | } |
Simon Glass | 90268b8 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 2230 | |
| 2231 | int boot_get_setup_fit(bootm_headers_t *images, uint8_t arch, |
| 2232 | ulong *setup_start, ulong *setup_len) |
| 2233 | { |
| 2234 | int noffset; |
| 2235 | ulong addr; |
| 2236 | ulong len; |
| 2237 | int ret; |
| 2238 | |
| 2239 | addr = map_to_sysmem(images->fit_hdr_os); |
| 2240 | noffset = fit_get_node_from_config(images, FIT_SETUP_PROP, addr); |
| 2241 | if (noffset < 0) |
| 2242 | return noffset; |
| 2243 | |
| 2244 | ret = fit_image_load(images, addr, NULL, NULL, arch, |
| 2245 | IH_TYPE_X86_SETUP, BOOTSTAGE_ID_FIT_SETUP_START, |
| 2246 | FIT_LOAD_REQUIRED, setup_start, &len); |
| 2247 | |
| 2248 | return ret; |
| 2249 | } |
Pantelis Antoniou | 169043d | 2017-09-04 23:12:16 +0300 | [diff] [blame] | 2250 | |
| 2251 | #ifndef USE_HOSTCC |
| 2252 | int boot_get_fdt_fit(bootm_headers_t *images, ulong addr, |
| 2253 | const char **fit_unamep, const char **fit_uname_configp, |
| 2254 | int arch, ulong *datap, ulong *lenp) |
| 2255 | { |
| 2256 | int fdt_noffset, cfg_noffset, count; |
| 2257 | const void *fit; |
| 2258 | const char *fit_uname = NULL; |
| 2259 | const char *fit_uname_config = NULL; |
| 2260 | char *fit_uname_config_copy = NULL; |
| 2261 | char *next_config = NULL; |
| 2262 | ulong load, len; |
| 2263 | #ifdef CONFIG_OF_LIBFDT_OVERLAY |
| 2264 | ulong image_start, image_end; |
Marek Vasut | 4c531d9 | 2021-06-11 04:09:56 +0200 | [diff] [blame] | 2265 | ulong ovload, ovlen, ovcopylen; |
Pantelis Antoniou | 169043d | 2017-09-04 23:12:16 +0300 | [diff] [blame] | 2266 | const char *uconfig; |
| 2267 | const char *uname; |
Marek Vasut | 4c531d9 | 2021-06-11 04:09:56 +0200 | [diff] [blame] | 2268 | void *base, *ov, *ovcopy = NULL; |
Pantelis Antoniou | 169043d | 2017-09-04 23:12:16 +0300 | [diff] [blame] | 2269 | int i, err, noffset, ov_noffset; |
| 2270 | #endif |
| 2271 | |
| 2272 | fit_uname = fit_unamep ? *fit_unamep : NULL; |
| 2273 | |
| 2274 | if (fit_uname_configp && *fit_uname_configp) { |
| 2275 | fit_uname_config_copy = strdup(*fit_uname_configp); |
| 2276 | if (!fit_uname_config_copy) |
| 2277 | return -ENOMEM; |
| 2278 | |
| 2279 | next_config = strchr(fit_uname_config_copy, '#'); |
| 2280 | if (next_config) |
| 2281 | *next_config++ = '\0'; |
| 2282 | if (next_config - 1 > fit_uname_config_copy) |
| 2283 | fit_uname_config = fit_uname_config_copy; |
| 2284 | } |
| 2285 | |
| 2286 | fdt_noffset = fit_image_load(images, |
| 2287 | addr, &fit_uname, &fit_uname_config, |
| 2288 | arch, IH_TYPE_FLATDT, |
| 2289 | BOOTSTAGE_ID_FIT_FDT_START, |
| 2290 | FIT_LOAD_OPTIONAL, &load, &len); |
| 2291 | |
| 2292 | if (fdt_noffset < 0) |
| 2293 | goto out; |
| 2294 | |
| 2295 | debug("fit_uname=%s, fit_uname_config=%s\n", |
| 2296 | fit_uname ? fit_uname : "<NULL>", |
| 2297 | fit_uname_config ? fit_uname_config : "<NULL>"); |
| 2298 | |
| 2299 | fit = map_sysmem(addr, 0); |
| 2300 | |
| 2301 | cfg_noffset = fit_conf_get_node(fit, fit_uname_config); |
| 2302 | |
| 2303 | /* single blob, or error just return as well */ |
| 2304 | count = fit_conf_get_prop_node_count(fit, cfg_noffset, FIT_FDT_PROP); |
| 2305 | if (count <= 1 && !next_config) |
| 2306 | goto out; |
| 2307 | |
| 2308 | /* we need to apply overlays */ |
| 2309 | |
| 2310 | #ifdef CONFIG_OF_LIBFDT_OVERLAY |
| 2311 | image_start = addr; |
| 2312 | image_end = addr + fit_get_size(fit); |
| 2313 | /* verify that relocation took place by load address not being in fit */ |
| 2314 | if (load >= image_start && load < image_end) { |
| 2315 | /* check is simplified; fit load checks for overlaps */ |
| 2316 | printf("Overlayed FDT requires relocation\n"); |
| 2317 | fdt_noffset = -EBADF; |
| 2318 | goto out; |
| 2319 | } |
| 2320 | |
| 2321 | base = map_sysmem(load, len); |
| 2322 | |
| 2323 | /* apply extra configs in FIT first, followed by args */ |
| 2324 | for (i = 1; ; i++) { |
| 2325 | if (i < count) { |
| 2326 | noffset = fit_conf_get_prop_node_index(fit, cfg_noffset, |
| 2327 | FIT_FDT_PROP, i); |
| 2328 | uname = fit_get_name(fit, noffset, NULL); |
| 2329 | uconfig = NULL; |
| 2330 | } else { |
| 2331 | if (!next_config) |
| 2332 | break; |
| 2333 | uconfig = next_config; |
| 2334 | next_config = strchr(next_config, '#'); |
| 2335 | if (next_config) |
| 2336 | *next_config++ = '\0'; |
| 2337 | uname = NULL; |
Peter Ujfalusi | 35c7527 | 2019-03-06 15:52:27 +0200 | [diff] [blame] | 2338 | |
| 2339 | /* |
| 2340 | * fit_image_load() would load the first FDT from the |
| 2341 | * extra config only when uconfig is specified. |
| 2342 | * Check if the extra config contains multiple FDTs and |
| 2343 | * if so, load them. |
| 2344 | */ |
| 2345 | cfg_noffset = fit_conf_get_node(fit, uconfig); |
| 2346 | |
| 2347 | i = 0; |
| 2348 | count = fit_conf_get_prop_node_count(fit, cfg_noffset, |
| 2349 | FIT_FDT_PROP); |
Pantelis Antoniou | 169043d | 2017-09-04 23:12:16 +0300 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | debug("%d: using uname=%s uconfig=%s\n", i, uname, uconfig); |
| 2353 | |
| 2354 | ov_noffset = fit_image_load(images, |
| 2355 | addr, &uname, &uconfig, |
| 2356 | arch, IH_TYPE_FLATDT, |
| 2357 | BOOTSTAGE_ID_FIT_FDT_START, |
Marek Vasut | 4c531d9 | 2021-06-11 04:09:56 +0200 | [diff] [blame] | 2358 | FIT_LOAD_IGNORED, &ovload, &ovlen); |
Pantelis Antoniou | 169043d | 2017-09-04 23:12:16 +0300 | [diff] [blame] | 2359 | if (ov_noffset < 0) { |
| 2360 | printf("load of %s failed\n", uname); |
| 2361 | continue; |
| 2362 | } |
| 2363 | debug("%s loaded at 0x%08lx len=0x%08lx\n", |
| 2364 | uname, ovload, ovlen); |
| 2365 | ov = map_sysmem(ovload, ovlen); |
| 2366 | |
Marek Vasut | 4c531d9 | 2021-06-11 04:09:56 +0200 | [diff] [blame] | 2367 | ovcopylen = ALIGN(fdt_totalsize(ov), SZ_4K); |
| 2368 | ovcopy = malloc(ovcopylen); |
| 2369 | if (!ovcopy) { |
| 2370 | printf("failed to duplicate DTO before application\n"); |
| 2371 | fdt_noffset = -ENOMEM; |
| 2372 | goto out; |
| 2373 | } |
| 2374 | |
| 2375 | err = fdt_open_into(ov, ovcopy, ovcopylen); |
| 2376 | if (err < 0) { |
| 2377 | printf("failed on fdt_open_into for DTO\n"); |
| 2378 | fdt_noffset = err; |
| 2379 | goto out; |
| 2380 | } |
| 2381 | |
Pantelis Antoniou | 169043d | 2017-09-04 23:12:16 +0300 | [diff] [blame] | 2382 | base = map_sysmem(load, len + ovlen); |
| 2383 | err = fdt_open_into(base, base, len + ovlen); |
| 2384 | if (err < 0) { |
| 2385 | printf("failed on fdt_open_into\n"); |
| 2386 | fdt_noffset = err; |
| 2387 | goto out; |
| 2388 | } |
Marek Vasut | 4c531d9 | 2021-06-11 04:09:56 +0200 | [diff] [blame] | 2389 | |
Pantelis Antoniou | 169043d | 2017-09-04 23:12:16 +0300 | [diff] [blame] | 2390 | /* the verbose method prints out messages on error */ |
Marek Vasut | 4c531d9 | 2021-06-11 04:09:56 +0200 | [diff] [blame] | 2391 | err = fdt_overlay_apply_verbose(base, ovcopy); |
Pantelis Antoniou | 169043d | 2017-09-04 23:12:16 +0300 | [diff] [blame] | 2392 | if (err < 0) { |
| 2393 | fdt_noffset = err; |
| 2394 | goto out; |
| 2395 | } |
| 2396 | fdt_pack(base); |
| 2397 | len = fdt_totalsize(base); |
Marek Vasut | 4c531d9 | 2021-06-11 04:09:56 +0200 | [diff] [blame] | 2398 | |
| 2399 | free(ovcopy); |
| 2400 | ovcopy = NULL; |
Pantelis Antoniou | 169043d | 2017-09-04 23:12:16 +0300 | [diff] [blame] | 2401 | } |
| 2402 | #else |
| 2403 | printf("config with overlays but CONFIG_OF_LIBFDT_OVERLAY not set\n"); |
| 2404 | fdt_noffset = -EBADF; |
| 2405 | #endif |
| 2406 | |
| 2407 | out: |
| 2408 | if (datap) |
| 2409 | *datap = load; |
| 2410 | if (lenp) |
| 2411 | *lenp = len; |
| 2412 | if (fit_unamep) |
| 2413 | *fit_unamep = fit_uname; |
| 2414 | if (fit_uname_configp) |
| 2415 | *fit_uname_configp = fit_uname_config; |
| 2416 | |
Marek Vasut | 4c531d9 | 2021-06-11 04:09:56 +0200 | [diff] [blame] | 2417 | #ifdef CONFIG_OF_LIBFDT_OVERLAY |
| 2418 | if (ovcopy) |
| 2419 | free(ovcopy); |
| 2420 | #endif |
Pantelis Antoniou | 169043d | 2017-09-04 23:12:16 +0300 | [diff] [blame] | 2421 | if (fit_uname_config_copy) |
| 2422 | free(fit_uname_config_copy); |
| 2423 | return fdt_noffset; |
| 2424 | } |
| 2425 | #endif |