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 || !fit_check_format(ptr))
35 int fit_check_image_types(uint8_t type)
37 if (type == IH_TYPE_FLATDT)
43 int mmap_fdt(const char *cmdname, const char *fname, size_t size_inc,
44 void **blobp, struct stat *sbuf, bool delete_on_error,
50 /* Load FIT blob into memory (we need to write hashes/signatures) */
51 fd = open(fname, (read_only ? O_RDONLY : O_RDWR) | O_BINARY);
54 fprintf(stderr, "%s: Can't open %s: %s\n",
55 cmdname, fname, strerror(errno));
59 if (fstat(fd, sbuf) < 0) {
60 fprintf(stderr, "%s: Can't stat %s: %s\n",
61 cmdname, fname, strerror(errno));
66 sbuf->st_size += size_inc;
67 if (ftruncate(fd, sbuf->st_size)) {
68 fprintf(stderr, "%s: Can't expand %s: %s\n",
69 cmdname, fname, strerror(errno));
75 ptr = mmap(0, sbuf->st_size,
76 (read_only ? PROT_READ : PROT_READ | PROT_WRITE), MAP_SHARED,
78 if ((ptr == MAP_FAILED) || (errno != 0)) {
79 fprintf(stderr, "%s: Can't read %s: %s\n",
80 cmdname, fname, strerror(errno));
84 /* check if ptr has a valid blob */
85 if (fdt_check_header(ptr)) {
86 fprintf(stderr, "%s: Invalid FIT blob\n", cmdname);
90 /* expand if needed */
94 ret = fdt_open_into(ptr, ptr, sbuf->st_size);
96 fprintf(stderr, "%s: Cannot expand FDT: %s\n",
97 cmdname, fdt_strerror(ret));