1 // SPDX-License-Identifier: GPL-2.0+
4 * DENX Software Engineering
7 * (C) Copyright 2008 Semihalf
9 * (C) Copyright 2000-2004
10 * DENX Software Engineering
14 * FIT image specific code abstracted from mkimage.c
15 * some functions added to address abstraction
17 * All rights reserved.
20 #include "imagetool.h"
22 #include "fit_common.h"
24 #include <u-boot/crc.h>
26 int fit_verify_header(unsigned char *ptr, int image_size,
27 struct image_tool_params *params)
29 if (fdt_check_header(ptr) != EXIT_SUCCESS ||
30 fit_check_format(ptr, IMAGE_SIZE_INVAL))
36 int fit_check_image_types(uint8_t type)
38 if (type == IH_TYPE_FLATDT)
44 int mmap_fdt(const char *cmdname, const char *fname, size_t size_inc,
45 void **blobp, struct stat *sbuf, bool delete_on_error,
51 /* Load FIT blob into memory (we need to write hashes/signatures) */
52 fd = open(fname, (read_only ? O_RDONLY : O_RDWR) | O_BINARY);
55 fprintf(stderr, "%s: Can't open %s: %s\n",
56 cmdname, fname, strerror(errno));
60 if (fstat(fd, sbuf) < 0) {
61 fprintf(stderr, "%s: Can't stat %s: %s\n",
62 cmdname, fname, strerror(errno));
67 sbuf->st_size += size_inc;
68 if (ftruncate(fd, sbuf->st_size)) {
69 fprintf(stderr, "%s: Can't expand %s: %s\n",
70 cmdname, fname, strerror(errno));
76 ptr = mmap(0, sbuf->st_size,
77 (read_only ? PROT_READ : PROT_READ | PROT_WRITE), MAP_SHARED,
79 if ((ptr == MAP_FAILED) || (errno != 0)) {
80 fprintf(stderr, "%s: Can't read %s: %s\n",
81 cmdname, fname, strerror(errno));
85 /* check if ptr has a valid blob */
86 if (fdt_check_header(ptr)) {
87 fprintf(stderr, "%s: Invalid FIT blob\n", cmdname);
91 /* expand if needed */
95 ret = fdt_open_into(ptr, ptr, sbuf->st_size);
97 fprintf(stderr, "%s: Cannot expand FDT: %s\n",
98 cmdname, fdt_strerror(ret));