summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/.gitignore4
-rw-r--r--tools/Makefile133
-rw-r--r--tools/crc32.c1
-rw-r--r--tools/dumpimage.h2
-rw-r--r--tools/env_embedded.c1
-rw-r--r--tools/fdt.c1
-rw-r--r--tools/fdt_ro.c1
-rw-r--r--tools/fdt_rw.c1
-rw-r--r--tools/fdt_strerror.c1
-rw-r--r--tools/fdt_wip.c1
-rw-r--r--tools/fdtdec.c1
-rw-r--r--tools/fit_check_sign.c26
-rw-r--r--tools/fit_common.c49
-rw-r--r--tools/fit_common.h15
-rw-r--r--tools/fit_image.c112
-rw-r--r--tools/fit_info.c14
-rw-r--r--tools/image-fit.c1
-rw-r--r--tools/image-host.c40
-rw-r--r--tools/image-sig.c1
-rw-r--r--tools/image.c1
-rw-r--r--tools/imagetool.h2
-rw-r--r--tools/md5.c1
-rw-r--r--tools/mkimage.h2
-rw-r--r--tools/mxsimage.c32
-rw-r--r--tools/pbl_crc32.c56
-rw-r--r--tools/pbl_crc32.h13
-rw-r--r--tools/pblimage.c47
-rw-r--r--tools/rsa-checksum.c1
-rw-r--r--tools/rsa-sign.c1
-rw-r--r--tools/rsa-verify.c1
-rw-r--r--tools/sha1.c1
-rw-r--r--tools/sha256.c1
-rw-r--r--tools/ubsha1.c2
33 files changed, 328 insertions, 238 deletions
diff --git a/tools/.gitignore b/tools/.gitignore
index 725db90..cefe923 100644
--- a/tools/.gitignore
+++ b/tools/.gitignore
@@ -17,7 +17,9 @@
/relocate-rela
/ubsha1
/xway-swap-bytes
-/*.exe
/easylogo/easylogo
/gdb/gdbcont
/gdb/gdbsend
+
+/lib/
+/common/
diff --git a/tools/Makefile b/tools/Makefile
index 7610557..61b2048 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -5,15 +5,6 @@
# SPDX-License-Identifier: GPL-2.0+
#
-#
-# toolchains targeting win32 generate .exe files
-#
-ifneq (,$(findstring WIN32 ,$(shell $(HOSTCC) -E -dM -xc /dev/null)))
-SFX = .exe
-else
-SFX =
-endif
-
# Enable all the config-independent tools
ifneq ($(HOST_TOOLS_ALL),)
CONFIG_LCD_LOGO = y
@@ -38,114 +29,118 @@ ENVCRC-$(CONFIG_ENV_IS_IN_NVRAM) = y
ENVCRC-$(CONFIG_ENV_IS_IN_SPI_FLASH) = y
CONFIG_BUILD_ENVCRC ?= $(ENVCRC-y)
-hostprogs-$(CONFIG_SPL_GENERATE_ATMEL_PMECC_HEADER) += atmel_pmecc_params$(SFX)
+hostprogs-$(CONFIG_SPL_GENERATE_ATMEL_PMECC_HEADER) += atmel_pmecc_params
# TODO: CONFIG_CMD_LICENSE does not work
-hostprogs-$(CONFIG_CMD_LICENSE) += bin2header$(SFX)
-hostprogs-$(CONFIG_LCD_LOGO) += bmp_logo$(SFX)
-hostprogs-$(CONFIG_VIDEO_LOGO) += bmp_logo$(SFX)
-HOSTCFLAGS_bmp_logo$(SFX).o := -pedantic
+hostprogs-$(CONFIG_CMD_LICENSE) += bin2header
+hostprogs-$(CONFIG_LCD_LOGO) += bmp_logo
+hostprogs-$(CONFIG_VIDEO_LOGO) += bmp_logo
+HOSTCFLAGS_bmp_logo.o := -pedantic
-hostprogs-$(CONFIG_BUILD_ENVCRC) += envcrc$(SFX)
-envcrc$(SFX)-objs := crc32.o env_embedded.o envcrc.o sha1.o
+hostprogs-$(CONFIG_BUILD_ENVCRC) += envcrc
+envcrc-objs := envcrc.o lib/crc32.o common/env_embedded.o lib/sha1.o
-hostprogs-$(CONFIG_CMD_NET) += gen_eth_addr$(SFX)
-HOSTCFLAGS_gen_eth_addr$(SFX).o := -pedantic
+hostprogs-$(CONFIG_CMD_NET) += gen_eth_addr
+HOSTCFLAGS_gen_eth_addr.o := -pedantic
-hostprogs-$(CONFIG_CMD_LOADS) += img2srec$(SFX)
-HOSTCFLAGS_img2srec$(SFX).o := -pedantic
+hostprogs-$(CONFIG_CMD_LOADS) += img2srec
+HOSTCFLAGS_img2srec.o := -pedantic
-hostprogs-$(CONFIG_XWAY_SWAP_BYTES) += xway-swap-bytes$(SFX)
-HOSTCFLAGS_xway-swap-bytes$(SFX).o := -pedantic
+hostprogs-$(CONFIG_XWAY_SWAP_BYTES) += xway-swap-bytes
+HOSTCFLAGS_xway-swap-bytes.o := -pedantic
-hostprogs-y += mkenvimage$(SFX)
-mkenvimage$(SFX)-objs := crc32.o mkenvimage.o os_support.o
+hostprogs-y += mkenvimage
+mkenvimage-objs := mkenvimage.o os_support.o lib/crc32.o
-hostprogs-y += dumpimage$(SFX) mkimage$(SFX)
-hostprogs-$(CONFIG_FIT_SIGNATURE) += fit_info$(SFX) fit_check_sign$(SFX)
+hostprogs-y += dumpimage mkimage
+hostprogs-$(CONFIG_FIT_SIGNATURE) += fit_info fit_check_sign
-FIT_SIG_OBJS-$(CONFIG_FIT_SIGNATURE) := image-sig.o
+FIT_SIG_OBJS-$(CONFIG_FIT_SIGNATURE) := common/image-sig.o
# Flattened device tree objects
-LIBFDT_OBJS := fdt.o fdt_ro.o fdt_rw.o fdt_strerror.o fdt_wip.o
-RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := rsa-sign.o rsa-verify.o rsa-checksum.o
+LIBFDT_OBJS := $(addprefix lib/libfdt/, \
+ fdt.o fdt_ro.o fdt_rw.o fdt_strerror.o fdt_wip.o)
+RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := $(addprefix lib/rsa/, \
+ rsa-sign.o rsa-verify.o rsa-checksum.o)
# common objs for dumpimage and mkimage
dumpimage-mkimage-objs := aisimage.o \
atmelimage.o \
$(FIT_SIG_OBJS-y) \
- crc32.o \
+ common/bootm.o \
+ lib/crc32.o \
default_image.o \
- fdtdec.o \
+ lib/fdtdec_common.o \
+ lib/fdtdec.o \
fit_common.o \
fit_image.o \
gpimage.o \
gpimage-common.o \
- image-fit.o \
+ common/image-fit.o \
image-host.o \
- image.o \
+ common/image.o \
imagetool.o \
imximage.o \
kwbimage.o \
- md5.o \
+ lib/md5.o \
mxsimage.o \
omapimage.o \
os_support.o \
pblimage.o \
- sha1.o \
- sha256.o \
+ pbl_crc32.o \
+ lib/sha1.o \
+ lib/sha256.o \
ublimage.o \
$(LIBFDT_OBJS) \
$(RSA_OBJS-y)
-dumpimage$(SFX)-objs := $(dumpimage-mkimage-objs) dumpimage.o
-mkimage$(SFX)-objs := $(dumpimage-mkimage-objs) mkimage.o
-fit_info$(SFX)-objs := $(dumpimage-mkimage-objs) fit_info.o
-fit_check_sign$(SFX)-objs := $(dumpimage-mkimage-objs) fit_check_sign.o
+dumpimage-objs := $(dumpimage-mkimage-objs) dumpimage.o
+mkimage-objs := $(dumpimage-mkimage-objs) mkimage.o
+fit_info-objs := $(dumpimage-mkimage-objs) fit_info.o
+fit_check_sign-objs := $(dumpimage-mkimage-objs) fit_check_sign.o
# TODO(sjg@chromium.org): Is this correct on Mac OS?
-# MXSImage needs LibSSL
ifneq ($(CONFIG_MX23)$(CONFIG_MX28),)
-HOSTLOADLIBES_dumpimage$(SFX) := -lssl -lcrypto
-HOSTLOADLIBES_mkimage$(SFX) := -lssl -lcrypto
-HOSTLOADLIBES_fit_info$(SFX) := -lssl -lcrypto
-HOSTLOADLIBES_fit_check_sign$(SFX) := -lssl -lcrypto
# Add CONFIG_MXS into host CFLAGS, so we can check whether or not register
# the mxsimage support within tools/mxsimage.c .
HOSTCFLAGS_mxsimage.o += -DCONFIG_MXS
endif
ifdef CONFIG_FIT_SIGNATURE
-HOSTLOADLIBES_dumpimage$(SFX) := -lssl -lcrypto
-HOSTLOADLIBES_mkimage$(SFX) := -lssl -lcrypto
-HOSTLOADLIBES_fit_info$(SFX) := -lssl -lcrypto
-HOSTLOADLIBES_fit_check_sign$(SFX) := -lssl -lcrypto
-
# This affects include/image.h, but including the board config file
# is tricky, so manually define this options here.
HOST_EXTRACFLAGS += -DCONFIG_FIT_SIGNATURE
endif
-hostprogs-$(CONFIG_EXYNOS5250) += mkexynosspl$(SFX)
-hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl$(SFX)
-HOSTCFLAGS_mkexynosspl$(SFX).o := -pedantic
+# MXSImage needs LibSSL
+ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_FIT_SIGNATURE),)
+HOSTLOADLIBES_mkimage += -lssl -lcrypto
+endif
+
+HOSTLOADLIBES_dumpimage := $(HOSTLOADLIBES_mkimage)
+HOSTLOADLIBES_fit_info := $(HOSTLOADLIBES_mkimage)
+HOSTLOADLIBES_fit_check_sign := $(HOSTLOADLIBES_mkimage)
+
+hostprogs-$(CONFIG_EXYNOS5250) += mkexynosspl
+hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl
+HOSTCFLAGS_mkexynosspl.o := -pedantic
-hostprogs-$(CONFIG_MX23) += mxsboot$(SFX)
-hostprogs-$(CONFIG_MX28) += mxsboot$(SFX)
-HOSTCFLAGS_mxsboot$(SFX).o := -pedantic
+hostprogs-$(CONFIG_MX23) += mxsboot
+hostprogs-$(CONFIG_MX28) += mxsboot
+HOSTCFLAGS_mxsboot.o := -pedantic
-hostprogs-$(CONFIG_SUNXI) += mksunxiboot$(SFX)
+hostprogs-$(CONFIG_SUNXI) += mksunxiboot
-hostprogs-$(CONFIG_NETCONSOLE) += ncb$(SFX)
-hostprogs-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1$(SFX)
+hostprogs-$(CONFIG_NETCONSOLE) += ncb
+hostprogs-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1
-ubsha1$(SFX)-objs := os_support.o sha1.o ubsha1.o
+ubsha1-objs := os_support.o ubsha1.o lib/sha1.o
HOSTCFLAGS_ubsha1.o := -pedantic
-hostprogs-$(CONFIG_KIRKWOOD) += kwboot$(SFX)
-hostprogs-y += proftool$(SFX)
-hostprogs-$(CONFIG_STATIC_RELA) += relocate-rela$(SFX)
+hostprogs-$(CONFIG_KIRKWOOD) += kwboot
+hostprogs-y += proftool
+hostprogs-$(CONFIG_STATIC_RELA) += relocate-rela
# We build some files with extra pedantic flags to try to minimize things
# that won't build on some weird host compiler -- though there are lots of
@@ -156,8 +151,16 @@ HOSTCFLAGS_sha1.o := -pedantic
HOSTCFLAGS_sha256.o := -pedantic
# Don't build by default
-#hostprogs-$(CONFIG_PPC) += mpc86x_clk$(SFX)
-#HOSTCFLAGS_mpc86x_clk$(SFX).o := -pedantic
+#hostprogs-$(CONFIG_PPC) += mpc86x_clk
+#HOSTCFLAGS_mpc86x_clk.o := -pedantic
+
+quiet_cmd_wrap = WRAP $@
+cmd_wrap = echo "\#include <$(srctree)/$(patsubst $(obj)/%,%,$@)>" >$@
+
+$(obj)/lib/%.c $(obj)/common/%.c:
+ $(call cmd,wrap)
+
+clean-dirs := lib common
always := $(hostprogs-y)
diff --git a/tools/crc32.c b/tools/crc32.c
deleted file mode 100644
index aed7112..0000000
--- a/tools/crc32.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/crc32.c"
diff --git a/tools/dumpimage.h b/tools/dumpimage.h
index d78523d..e415f14 100644
--- a/tools/dumpimage.h
+++ b/tools/dumpimage.h
@@ -18,7 +18,7 @@
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
-#include <sha1.h>
+#include <u-boot/sha1.h>
#include "fdt_host.h"
#include "imagetool.h"
diff --git a/tools/env_embedded.c b/tools/env_embedded.c
deleted file mode 100644
index 59a6357..0000000
--- a/tools/env_embedded.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../common/env_embedded.c"
diff --git a/tools/fdt.c b/tools/fdt.c
deleted file mode 100644
index 1eafc56..0000000
--- a/tools/fdt.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/libfdt/fdt.c"
diff --git a/tools/fdt_ro.c b/tools/fdt_ro.c
deleted file mode 100644
index 9005fe3..0000000
--- a/tools/fdt_ro.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/libfdt/fdt_ro.c"
diff --git a/tools/fdt_rw.c b/tools/fdt_rw.c
deleted file mode 100644
index adc3fdf..0000000
--- a/tools/fdt_rw.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/libfdt/fdt_rw.c"
diff --git a/tools/fdt_strerror.c b/tools/fdt_strerror.c
deleted file mode 100644
index d0b5822..0000000
--- a/tools/fdt_strerror.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/libfdt/fdt_strerror.c"
diff --git a/tools/fdt_wip.c b/tools/fdt_wip.c
deleted file mode 100644
index 7810f07..0000000
--- a/tools/fdt_wip.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/libfdt/fdt_wip.c"
diff --git a/tools/fdtdec.c b/tools/fdtdec.c
deleted file mode 100644
index f1c2256..0000000
--- a/tools/fdtdec.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/fdtdec.c"
diff --git a/tools/fit_check_sign.c b/tools/fit_check_sign.c
index d6d9340..69e99c0 100644
--- a/tools/fit_check_sign.c
+++ b/tools/fit_check_sign.c
@@ -42,12 +42,13 @@ int main(int argc, char **argv)
void *fit_blob;
char *fdtfile = NULL;
char *keyfile = NULL;
- char cmdname[50];
+ char cmdname[256];
int ret;
void *key_blob;
int c;
- strcpy(cmdname, *argv);
+ strncpy(cmdname, *argv, sizeof(cmdname) - 1);
+ cmdname[sizeof(cmdname) - 1] = '\0';
while ((c = getopt(argc, argv, "f:k:")) != -1)
switch (c) {
case 'f':
@@ -61,20 +62,31 @@ int main(int argc, char **argv)
break;
}
- ffd = mmap_fdt(cmdname, fdtfile, &fit_blob, &fsbuf, 0);
+ if (!fdtfile) {
+ fprintf(stderr, "%s: Missing fdt file\n", *argv);
+ usage(*argv);
+ }
+ if (!keyfile) {
+ fprintf(stderr, "%s: Missing key file\n", *argv);
+ usage(*argv);
+ }
+
+ ffd = mmap_fdt(cmdname, fdtfile, 0, &fit_blob, &fsbuf, false);
if (ffd < 0)
return EXIT_FAILURE;
- kfd = mmap_fdt(cmdname, keyfile, &key_blob, &ksbuf, 0);
+ kfd = mmap_fdt(cmdname, keyfile, 0, &key_blob, &ksbuf, false);
if (ffd < 0)
return EXIT_FAILURE;
image_set_host_blob(key_blob);
ret = fit_check_sign(fit_blob, key_blob);
-
- if (ret)
+ if (!ret) {
ret = EXIT_SUCCESS;
- else
+ fprintf(stderr, "Signature check OK\n");
+ } else {
ret = EXIT_FAILURE;
+ fprintf(stderr, "Signature check Bad (error %d)\n", ret);
+ }
(void) munmap((void *)fit_blob, fsbuf.st_size);
(void) munmap((void *)key_blob, ksbuf.st_size);
diff --git a/tools/fit_common.c b/tools/fit_common.c
index ee1767b..81ba698 100644
--- a/tools/fit_common.c
+++ b/tools/fit_common.c
@@ -38,8 +38,8 @@ int fit_check_image_types(uint8_t type)
return EXIT_FAILURE;
}
-int mmap_fdt(char *cmdname, const char *fname, void **blobp,
- struct stat *sbuf, int useunlink)
+int mmap_fdt(const char *cmdname, const char *fname, size_t size_inc,
+ void **blobp, struct stat *sbuf, bool delete_on_error)
{
void *ptr;
int fd;
@@ -50,17 +50,22 @@ int mmap_fdt(char *cmdname, const char *fname, void **blobp,
if (fd < 0) {
fprintf(stderr, "%s: Can't open %s: %s\n",
cmdname, fname, strerror(errno));
- if (useunlink)
- unlink(fname);
- return -1;
+ goto err;
}
if (fstat(fd, sbuf) < 0) {
fprintf(stderr, "%s: Can't stat %s: %s\n",
cmdname, fname, strerror(errno));
- if (useunlink)
- unlink(fname);
- return -1;
+ goto err;
+ }
+
+ if (size_inc) {
+ sbuf->st_size += size_inc;
+ if (ftruncate(fd, sbuf->st_size)) {
+ fprintf(stderr, "%s: Can't expand %s: %s\n",
+ cmdname, fname, strerror(errno));
+ goto err;
+ }
}
errno = 0;
@@ -68,19 +73,35 @@ int mmap_fdt(char *cmdname, const char *fname, void **blobp,
if ((ptr == MAP_FAILED) || (errno != 0)) {
fprintf(stderr, "%s: Can't read %s: %s\n",
cmdname, fname, strerror(errno));
- if (useunlink)
- unlink(fname);
- return -1;
+ goto err;
}
/* check if ptr has a valid blob */
if (fdt_check_header(ptr)) {
fprintf(stderr, "%s: Invalid FIT blob\n", cmdname);
- if (useunlink)
- unlink(fname);
- return -1;
+ goto err;
+ }
+
+ /* expand if needed */
+ if (size_inc) {
+ int ret;
+
+ ret = fdt_open_into(ptr, ptr, sbuf->st_size);
+ if (ret) {
+ fprintf(stderr, "%s: Cannot expand FDT: %s\n",
+ cmdname, fdt_strerror(ret));
+ goto err;
+ }
}
*blobp = ptr;
return fd;
+
+err:
+ if (fd >= 0)
+ close(fd);
+ if (delete_on_error)
+ unlink(fname);
+
+ return -1;
}
diff --git a/tools/fit_common.h b/tools/fit_common.h
index adf4404..b8d8438 100644
--- a/tools/fit_common.h
+++ b/tools/fit_common.h
@@ -16,7 +16,18 @@ int fit_verify_header(unsigned char *ptr, int image_size,
int fit_check_image_types(uint8_t type);
-int mmap_fdt(char *cmdname, const char *fname, void **blobp,
- struct stat *sbuf, int useunlink);
+/**
+ * Map an FDT into memory, optionally increasing its size
+ *
+ * @cmdname: Tool name (for displaying with error messages)
+ * @fname: Filename containing FDT
+ * @size_inc: Amount to increase size by (0 = leave it alone)
+ * @blobp: Returns pointer to FDT blob
+ * @sbuf: File status information is stored here
+ * @delete_on_error: true to delete the file if we get an error
+ * @return 0 if OK, -1 on error.
+ */
+int mmap_fdt(const char *cmdname, const char *fname, size_t size_inc,
+ void **blobp, struct stat *sbuf, bool delete_on_error);
#endif /* _FIT_COMMON_H_ */
diff --git a/tools/fit_image.c b/tools/fit_image.c
index eeee484..3ececf9 100644
--- a/tools/fit_image.c
+++ b/tools/fit_image.c
@@ -22,6 +22,54 @@
static image_header_t header;
+static int fit_add_file_data(struct image_tool_params *params, size_t size_inc,
+ const char *tmpfile)
+{
+ int tfd, destfd = 0;
+ void *dest_blob = NULL;
+ off_t destfd_size = 0;
+ struct stat sbuf;
+ void *ptr;
+ int ret = 0;
+
+ tfd = mmap_fdt(params->cmdname, tmpfile, size_inc, &ptr, &sbuf, true);
+ if (tfd < 0)
+ return -EIO;
+
+ if (params->keydest) {
+ struct stat dest_sbuf;
+
+ destfd = mmap_fdt(params->cmdname, params->keydest, size_inc,
+ &dest_blob, &dest_sbuf, false);
+ if (destfd < 0) {
+ ret = -EIO;
+ goto err_keydest;
+ }
+ destfd_size = dest_sbuf.st_size;
+ }
+
+ /* for first image creation, add a timestamp at offset 0 i.e., root */
+ if (params->datafile)
+ ret = fit_set_timestamp(ptr, 0, sbuf.st_mtime);
+
+ if (!ret) {
+ ret = fit_add_verification_data(params->keydir, dest_blob, ptr,
+ params->comment,
+ params->require_keys);
+ }
+
+ if (dest_blob) {
+ munmap(dest_blob, destfd_size);
+ close(destfd);
+ }
+
+err_keydest:
+ munmap(ptr, sbuf.st_size);
+ close(tfd);
+
+ return ret;
+}
+
/**
* fit_handle_file - main FIT file processing function
*
@@ -38,11 +86,8 @@ static int fit_handle_file(struct image_tool_params *params)
{
char tmpfile[MKIMAGE_MAX_TMPFILE_LEN];
char cmd[MKIMAGE_MAX_DTC_CMDLINE_LEN];
- int tfd, destfd = 0;
- void *dest_blob = NULL;
- struct stat sbuf;
- void *ptr;
- off_t destfd_size = 0;
+ size_t size_inc;
+ int ret;
/* Flattened Image Tree (FIT) format handling */
debug ("FIT format handling\n");
@@ -73,40 +118,26 @@ static int fit_handle_file(struct image_tool_params *params)
goto err_system;
}
- if (params->keydest) {
- destfd = mmap_fdt(params->cmdname, params->keydest,
- &dest_blob, &sbuf, 1);
- if (destfd < 0)
- goto err_keydest;
- destfd_size = sbuf.st_size;
+ /*
+ * Set hashes for images in the blob. Unfortunately we may need more
+ * space in either FDT, so keep trying until we succeed.
+ *
+ * Note: this is pretty inefficient for signing, since we must
+ * calculate the signature every time. It would be better to calculate
+ * all the data and then store it in a separate step. However, this
+ * would be considerably more complex to implement. Generally a few
+ * steps of this loop is enough to sign with several keys.
+ */
+ for (size_inc = 0; size_inc < 64 * 1024; size_inc += 1024) {
+ ret = fit_add_file_data(params, size_inc, tmpfile);
+ if (!ret || ret != -ENOSPC)
+ break;
}
- tfd = mmap_fdt(params->cmdname, tmpfile, &ptr, &sbuf, 1);
- if (tfd < 0)
- goto err_mmap;
-
- /* set hashes for images in the blob */
- if (fit_add_verification_data(params->keydir,
- dest_blob, ptr, params->comment,
- params->require_keys)) {
+ if (ret) {
fprintf(stderr, "%s Can't add hashes to FIT blob\n",
params->cmdname);
- goto err_add_hashes;
- }
-
- /* for first image creation, add a timestamp at offset 0 i.e., root */
- if (params->datafile && fit_set_timestamp(ptr, 0, sbuf.st_mtime)) {
- fprintf (stderr, "%s: Can't add image timestamp\n",
- params->cmdname);
- goto err_add_timestamp;
- }
- debug ("Added timestamp successfully\n");
-
- munmap ((void *)ptr, sbuf.st_size);
- close (tfd);
- if (dest_blob) {
- munmap(dest_blob, destfd_size);
- close(destfd);
+ goto err_system;
}
if (rename (tmpfile, params->imagefile) == -1) {
@@ -115,17 +146,10 @@ static int fit_handle_file(struct image_tool_params *params)
strerror (errno));
unlink (tmpfile);
unlink (params->imagefile);
- return (EXIT_FAILURE);
+ return EXIT_FAILURE;
}
- return (EXIT_SUCCESS);
+ return EXIT_SUCCESS;
-err_add_timestamp:
-err_add_hashes:
- munmap(ptr, sbuf.st_size);
-err_mmap:
- if (dest_blob)
- munmap(dest_blob, destfd_size);
-err_keydest:
err_system:
unlink(tmpfile);
return -1;
diff --git a/tools/fit_info.c b/tools/fit_info.c
index 50f3c8e..481ac6d 100644
--- a/tools/fit_info.c
+++ b/tools/fit_info.c
@@ -68,7 +68,19 @@ int main(int argc, char **argv)
break;
}
- ffd = mmap_fdt(cmdname, fdtfile, &fit_blob, &fsbuf, 0);
+ if (!fdtfile) {
+ fprintf(stderr, "%s: Missing fdt file\n", *argv);
+ usage(*argv);
+ }
+ if (!nodename) {
+ fprintf(stderr, "%s: Missing node name\n", *argv);
+ usage(*argv);
+ }
+ if (!propertyname) {
+ fprintf(stderr, "%s: Missing property name\n", *argv);
+ usage(*argv);
+ }
+ ffd = mmap_fdt(cmdname, fdtfile, 0, &fit_blob, &fsbuf, false);
if (ffd < 0) {
printf("Could not open %s\n", fdtfile);
diff --git a/tools/image-fit.c b/tools/image-fit.c
deleted file mode 100644
index 037e5cc..0000000
--- a/tools/image-fit.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../common/image-fit.c"
diff --git a/tools/image-host.c b/tools/image-host.c
index 651f1c2..0eff720 100644
--- a/tools/image-host.c
+++ b/tools/image-host.c
@@ -10,6 +10,7 @@
*/
#include "mkimage.h"
+#include <bootm.h>
#include <image.h>
#include <version.h>
@@ -224,7 +225,9 @@ static int fit_image_process_sig(const char *keydir, void *keydest,
ret = fit_image_write_sig(fit, noffset, value, value_len, comment,
NULL, 0);
if (ret) {
- printf("Can't write signature for '%s' signature node in '%s' image node: %s\n",
+ if (ret == -FDT_ERR_NOSPACE)
+ return -ENOSPC;
+ printf("Can't write signature for '%s' signature node in '%s' conf node: %s\n",
node_name, image_name, fdt_strerror(ret));
return -1;
}
@@ -589,10 +592,13 @@ static int fit_config_process_sig(const char *keydir, void *keydest,
return -1;
}
- if (fit_image_write_sig(fit, noffset, value, value_len, comment,
- region_prop, region_proplen)) {
- printf("Can't write signature for '%s' signature node in '%s' conf node\n",
- node_name, conf_name);
+ ret = fit_image_write_sig(fit, noffset, value, value_len, comment,
+ region_prop, region_proplen);
+ if (ret) {
+ if (ret == -FDT_ERR_NOSPACE)
+ return -ENOSPC;
+ printf("Can't write signature for '%s' signature node in '%s' conf node: %s\n",
+ node_name, conf_name, fdt_strerror(ret));
return -1;
}
free(value);
@@ -602,10 +608,15 @@ static int fit_config_process_sig(const char *keydir, void *keydest,
info.keyname = fdt_getprop(fit, noffset, "key-name-hint", NULL);
/* Write the public key into the supplied FDT file */
- if (keydest && info.algo->add_verify_data(&info, keydest)) {
- printf("Failed to add verification data for '%s' signature node in '%s' image node\n",
- node_name, conf_name);
- return -1;
+ if (keydest) {
+ ret = info.algo->add_verify_data(&info, keydest);
+ if (ret == -ENOSPC)
+ return -ENOSPC;
+ if (ret) {
+ printf("Failed to add verification data for '%s' signature node in '%s' image node\n",
+ node_name, conf_name);
+ }
+ return ret;
}
return 0;
@@ -697,16 +708,21 @@ int fit_add_verification_data(const char *keydir, void *keydest, void *fit,
}
#ifdef CONFIG_FIT_SIGNATURE
-int fit_check_sign(const void *working_fdt, const void *key)
+int fit_check_sign(const void *fit, const void *key)
{
int cfg_noffset;
int ret;
- cfg_noffset = fit_conf_get_node(working_fdt, NULL);
+ cfg_noffset = fit_conf_get_node(fit, NULL);
if (!cfg_noffset)
return -1;
- ret = fit_config_verify(working_fdt, cfg_noffset);
+ printf("Verifying Hash Integrity ... ");
+ ret = fit_config_verify(fit, cfg_noffset);
+ if (ret)
+ return ret;
+ ret = bootm_host_load_images(fit, cfg_noffset);
+
return ret;
}
#endif
diff --git a/tools/image-sig.c b/tools/image-sig.c
deleted file mode 100644
index e45419f..0000000
--- a/tools/image-sig.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../common/image-sig.c"
diff --git a/tools/image.c b/tools/image.c
deleted file mode 100644
index 0f9bacc..0000000
--- a/tools/image.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../common/image.c"
diff --git a/tools/imagetool.h b/tools/imagetool.h
index c480687..c8af0e8 100644
--- a/tools/imagetool.h
+++ b/tools/imagetool.h
@@ -18,7 +18,7 @@
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
-#include <sha1.h>
+#include <u-boot/sha1.h>
#include "fdt_host.h"
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
diff --git a/tools/md5.c b/tools/md5.c
deleted file mode 100644
index befaa32..0000000
--- a/tools/md5.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/md5.c"
diff --git a/tools/mkimage.h b/tools/mkimage.h
index d5491b6..3f369b7 100644
--- a/tools/mkimage.h
+++ b/tools/mkimage.h
@@ -18,7 +18,7 @@
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
-#include <sha1.h>
+#include <u-boot/sha1.h>
#include "fdt_host.h"
#include "imagetool.h"
diff --git a/tools/mxsimage.c b/tools/mxsimage.c
index 045b35a..81c7f2d 100644
--- a/tools/mxsimage.c
+++ b/tools/mxsimage.c
@@ -19,6 +19,7 @@
#include "imagetool.h"
#include "mxsimage.h"
+#include "pbl_crc32.h"
#include <image.h>
@@ -231,29 +232,6 @@ static int sb_aes_reinit(struct sb_image_ctx *ictx, int enc)
}
/*
- * CRC32
- */
-static uint32_t crc32(uint8_t *data, uint32_t len)
-{
- const uint32_t poly = 0x04c11db7;
- uint32_t crc32 = 0xffffffff;
- unsigned int byte, bit;
-
- for (byte = 0; byte < len; byte++) {
- crc32 ^= data[byte] << 24;
-
- for (bit = 8; bit > 0; bit--) {
- if (crc32 & (1UL << 31))
- crc32 = (crc32 << 1) ^ poly;
- else
- crc32 = (crc32 << 1);
- }
- }
-
- return crc32;
-}
-
-/*
* Debug
*/
static void soprintf(struct sb_image_ctx *ictx, const char *fmt, ...)
@@ -998,7 +976,9 @@ static int sb_build_command_load(struct sb_image_ctx *ictx,
ccmd->load.address = dest;
ccmd->load.count = cctx->length;
- ccmd->load.crc32 = crc32(cctx->data, cctx->length);
+ ccmd->load.crc32 = pbl_crc32(0,
+ (const char *)cctx->data,
+ cctx->length);
cctx->size = sizeof(*ccmd) + cctx->length;
@@ -1834,7 +1814,9 @@ static int sb_verify_command(struct sb_image_ctx *ictx,
EVP_DigestUpdate(&ictx->md_ctx, cctx->data, asize);
sb_aes_crypt(ictx, cctx->data, cctx->data, asize);
- if (ccmd->load.crc32 != crc32(cctx->data, asize)) {
+ if (ccmd->load.crc32 != pbl_crc32(0,
+ (const char *)cctx->data,
+ asize)) {
fprintf(stderr,
"ERR: SB LOAD command payload CRC32 invalid!\n");
return -EINVAL;
diff --git a/tools/pbl_crc32.c b/tools/pbl_crc32.c
new file mode 100644
index 0000000..6e6735a
--- /dev/null
+++ b/tools/pbl_crc32.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2012 Freescale Semiconductor, Inc.
+ *
+ * Cleaned up and refactored by Charles Manning.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+#include "pblimage.h"
+
+static uint32_t crc_table[256];
+static int crc_table_valid;
+
+static void make_crc_table(void)
+{
+ uint32_t mask;
+ int i, j;
+ uint32_t poly; /* polynomial exclusive-or pattern */
+
+ if (crc_table_valid)
+ return;
+
+ /*
+ * the polynomial used by PBL is 1 + x1 + x2 + x4 + x5 + x7 + x8 + x10
+ * + x11 + x12 + x16 + x22 + x23 + x26 + x32.
+ */
+ poly = 0x04c11db7;
+
+ for (i = 0; i < 256; i++) {
+ mask = i << 24;
+ for (j = 0; j < 8; j++) {
+ if (mask & 0x80000000)
+ mask = (mask << 1) ^ poly;
+ else
+ mask <<= 1;
+ }
+ crc_table[i] = mask;
+ }
+
+ crc_table_valid = 1;
+}
+
+uint32_t pbl_crc32(uint32_t in_crc, const char *buf, uint32_t len)
+{
+ uint32_t crc32_val;
+ int i;
+
+ make_crc_table();
+
+ crc32_val = ~in_crc;
+
+ for (i = 0; i < len; i++)
+ crc32_val = (crc32_val << 8) ^
+ crc_table[(crc32_val >> 24) ^ (*buf++ & 0xff)];
+
+ return crc32_val;
+}
diff --git a/tools/pbl_crc32.h b/tools/pbl_crc32.h
new file mode 100644
index 0000000..4ab55ee
--- /dev/null
+++ b/tools/pbl_crc32.h
@@ -0,0 +1,13 @@
+/*
+ * Copyright 2012 Freescale Semiconductor, Inc.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef PBLCRC32_H
+#define PBLCRC32_H
+
+#include <stdint.h>
+uint32_t pbl_crc32(uint32_t in_crc, const char *buf, uint32_t len);
+
+#endif
diff --git a/tools/pblimage.c b/tools/pblimage.c
index ef3d7f6..6e6e801 100644
--- a/tools/pblimage.c
+++ b/tools/pblimage.c
@@ -6,6 +6,7 @@
#include "imagetool.h"
#include <image.h>
#include "pblimage.h"
+#include "pbl_crc32.h"
/*
* Initialize to an invalid value.
@@ -137,52 +138,6 @@ static void pbl_parser(char *name)
fclose(fd);
}
-static uint32_t crc_table[256];
-
-static void make_crc_table(void)
-{
- uint32_t mask;
- int i, j;
- uint32_t poly; /* polynomial exclusive-or pattern */
-
- /*
- * the polynomial used by PBL is 1 + x1 + x2 + x4 + x5 + x7 + x8 + x10
- * + x11 + x12 + x16 + x22 + x23 + x26 + x32.
- */
- poly = 0x04c11db7;
-
- for (i = 0; i < 256; i++) {
- mask = i << 24;
- for (j = 0; j < 8; j++) {
- if (mask & 0x80000000)
- mask = (mask << 1) ^ poly;
- else
- mask <<= 1;
- }
- crc_table[i] = mask;
- }
-}
-
-unsigned long pbl_crc32(unsigned long crc, const char *buf, uint32_t len)
-{
- uint32_t crc32_val = 0xffffffff;
- uint32_t xor = 0x0;
- int i;
-
- make_crc_table();
-
- for (i = 0; i < len; i++)
- crc32_val = (crc32_val << 8) ^
- crc_table[(crc32_val >> 24) ^ (*buf++ & 0xff)];
-
- crc32_val = crc32_val ^ xor;
- if (crc32_val < 0) {
- crc32_val += 0xffffffff;
- crc32_val += 1;
- }
- return crc32_val;
-}
-
static uint32_t reverse_byte(uint32_t val)
{
uint32_t temp;
diff --git a/tools/rsa-checksum.c b/tools/rsa-checksum.c
deleted file mode 100644
index 09033e6..0000000
--- a/tools/rsa-checksum.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/rsa/rsa-checksum.c"
diff --git a/tools/rsa-sign.c b/tools/rsa-sign.c
deleted file mode 100644
index 150bbe1..0000000
--- a/tools/rsa-sign.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/rsa/rsa-sign.c"
diff --git a/tools/rsa-verify.c b/tools/rsa-verify.c
deleted file mode 100644
index bb662a1..0000000
--- a/tools/rsa-verify.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/rsa/rsa-verify.c"
diff --git a/tools/sha1.c b/tools/sha1.c
deleted file mode 100644
index 0d717df..0000000
--- a/tools/sha1.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/sha1.c"
diff --git a/tools/sha256.c b/tools/sha256.c
deleted file mode 100644
index 8ca931f..0000000
--- a/tools/sha256.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/sha256.c"
diff --git a/tools/ubsha1.c b/tools/ubsha1.c
index 1041588..4a17246 100644
--- a/tools/ubsha1.c
+++ b/tools/ubsha1.c
@@ -13,7 +13,7 @@
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
-#include "sha1.h"
+#include <u-boot/sha1.h>
int main (int argc, char **argv)
{