From abbc67eedf37a240fe6cdd1ce46eedd12cd3a13f Mon Sep 17 00:00:00 2001 From: Charles Manning Date: Wed, 14 May 2014 14:45:00 +1200 Subject: mkimage : Split out and clean pbl_crc32 for use by other image types The crc32 used by pblimgae is NOT the same as zlib crc32. The pbl_crc32 is useful for other purposes in mkimage so split it out. While we are about it, clean up redundant and confusing code. Signed-off-by: Charles Manning --- tools/Makefile | 1 + tools/pbl_crc32.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/pbl_crc32.h | 13 +++++++++++++ tools/pblimage.c | 47 +--------------------------------------------- 4 files changed, 71 insertions(+), 46 deletions(-) create mode 100644 tools/pbl_crc32.c create mode 100644 tools/pbl_crc32.h (limited to 'tools') diff --git a/tools/Makefile b/tools/Makefile index 7610557..cbf00d5 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -91,6 +91,7 @@ dumpimage-mkimage-objs := aisimage.o \ omapimage.o \ os_support.o \ pblimage.o \ + pbl_crc32.o \ sha1.o \ sha256.o \ ublimage.o \ 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 +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 #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; -- cgit v1.1 From 25308f45e11527cbfc7ff6d9dced7800e4b976e4 Mon Sep 17 00:00:00 2001 From: Charles Manning Date: Wed, 14 May 2014 14:45:01 +1200 Subject: tools: Refactor mxsimage to use pbl_crc32 Both pblimage and mxsimage use the same crc algorithm, so refactor. Signed-off-by: Charles Manning --- tools/mxsimage.c | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) (limited to 'tools') 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 @@ -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; -- cgit v1.1 From 64375014c499528d9df5ee37f78844823a9d21f2 Mon Sep 17 00:00:00 2001 From: Michael van der Westhuizen Date: Tue, 20 May 2014 15:58:58 +0200 Subject: Prevent a stack overflow in fit_check_sign It is trivial to crash fit_check_sign by invoking with an absolute path in a deeply nested directory. This is exposed by vboot_test.sh. Signed-off-by: Michael van der Westhuizen Acked-by: Simon Glass --- tools/fit_check_sign.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/fit_check_sign.c b/tools/fit_check_sign.c index d6d9340..817773d 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': -- cgit v1.1 From 97cb4e5450074ec82adeed98af68aede4a30a590 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 5 Jun 2014 16:41:49 +0900 Subject: tools: refactor HOSTLOADLIBES_* options The tools mkimage, dumpimage, fit_info, fit_check_sign always have the common libraries to be linked, so HOSTLOADLIBES_* can be consolidated a little bit. Signed-off-by: Masahiro Yamada Acked-by: Simon Glass --- tools/Makefile | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'tools') diff --git a/tools/Makefile b/tools/Makefile index cbf00d5..40890cf 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -105,28 +105,27 @@ fit_check_sign$(SFX)-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 +# MXSImage needs LibSSL +ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_FIT_SIGNATURE),) +HOSTLOADLIBES_mkimage$(SFX) += -lssl -lcrypto +endif + +HOSTLOADLIBES_dumpimage$(SFX) := $(HOSTLOADLIBES_mkimage$(SFX)) +HOSTLOADLIBES_fit_info$(SFX) := $(HOSTLOADLIBES_mkimage$(SFX)) +HOSTLOADLIBES_fit_check_sign$(SFX) := $(HOSTLOADLIBES_mkimage$(SFX)) + hostprogs-$(CONFIG_EXYNOS5250) += mkexynosspl$(SFX) hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl$(SFX) HOSTCFLAGS_mkexynosspl$(SFX).o := -pedantic -- cgit v1.1 From 18b06652cdd58364fe1493fd9996dce2333ed5ba Mon Sep 17 00:00:00 2001 From: Jeroen Hofstee Date: Fri, 30 May 2014 15:45:28 +0200 Subject: tools: include u-boot version of sha256.h When building tools the u-boot specific sha256.h is required, but the host version of sha256.h is used when present. This leads to build errors on FreeBSD which does have a system sha256.h include. Like libfdt_env.h explicitly include u-boot's sha256.h. cc: Simon Glass Signed-off-by: Jeroen Hofstee Acked-by: Simon Glass --- tools/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'tools') diff --git a/tools/Makefile b/tools/Makefile index 40890cf..762f7dc 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -190,6 +190,7 @@ endif # !LOGO_BMP # Define _GNU_SOURCE to obtain the getline prototype from stdio.h # HOST_EXTRACFLAGS += -include $(srctree)/include/libfdt_env.h \ + -include $(srctree)/include/sha256.h \ $(patsubst -I%,-idirafter%, $(UBOOTINCLUDE)) \ -I$(srctree)/lib/libfdt \ -I$(srctree)/tools \ -- cgit v1.1 From ef0af64b1c45b8ee28db12c16c4ee881ee328e44 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 2 Jun 2014 22:04:52 -0600 Subject: Improve error handling in fit_common Make the error handling common, and make sure the file is always closed on error. Rename the parameter to be more description and add comments. Signed-off-by: Simon Glass --- tools/fit_check_sign.c | 4 ++-- tools/fit_common.c | 28 ++++++++++++++-------------- tools/fit_common.h | 14 ++++++++++++-- tools/fit_info.c | 2 +- 4 files changed, 29 insertions(+), 19 deletions(-) (limited to 'tools') diff --git a/tools/fit_check_sign.c b/tools/fit_check_sign.c index 817773d..357650d 100644 --- a/tools/fit_check_sign.c +++ b/tools/fit_check_sign.c @@ -62,10 +62,10 @@ int main(int argc, char **argv) break; } - ffd = mmap_fdt(cmdname, fdtfile, &fit_blob, &fsbuf, 0); + ffd = mmap_fdt(cmdname, fdtfile, &fit_blob, &fsbuf, false); if (ffd < 0) return EXIT_FAILURE; - kfd = mmap_fdt(cmdname, keyfile, &key_blob, &ksbuf, 0); + kfd = mmap_fdt(cmdname, keyfile, &key_blob, &ksbuf, false); if (ffd < 0) return EXIT_FAILURE; diff --git a/tools/fit_common.c b/tools/fit_common.c index ee1767b..286f357 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, void **blobp, + struct stat *sbuf, bool delete_on_error) { void *ptr; int fd; @@ -50,17 +50,13 @@ 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; } errno = 0; @@ -68,19 +64,23 @@ 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; } *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..adcee6d 100644 --- a/tools/fit_common.h +++ b/tools/fit_common.h @@ -16,7 +16,17 @@ 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 + * @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, void **blobp, + struct stat *sbuf, bool delete_on_error); #endif /* _FIT_COMMON_H_ */ diff --git a/tools/fit_info.c b/tools/fit_info.c index 50f3c8e..9442ff1 100644 --- a/tools/fit_info.c +++ b/tools/fit_info.c @@ -68,7 +68,7 @@ int main(int argc, char **argv) break; } - ffd = mmap_fdt(cmdname, fdtfile, &fit_blob, &fsbuf, 0); + ffd = mmap_fdt(cmdname, fdtfile, &fit_blob, &fsbuf, false); if (ffd < 0) { printf("Could not open %s\n", fdtfile); -- cgit v1.1 From a9468115699de562f08796bf2eabd832435bedec Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 2 Jun 2014 22:04:53 -0600 Subject: mkimage: Automatically make space in FDT when full When adding hashes or signatures, the target FDT may be full. Detect this and automatically try again after making 1KB of space. Signed-off-by: Simon Glass --- tools/fit_check_sign.c | 4 +- tools/fit_common.c | 25 ++++++++++- tools/fit_common.h | 5 ++- tools/fit_image.c | 112 ++++++++++++++++++++++++++++++------------------- tools/fit_info.c | 2 +- tools/image-host.c | 26 ++++++++---- 6 files changed, 114 insertions(+), 60 deletions(-) (limited to 'tools') diff --git a/tools/fit_check_sign.c b/tools/fit_check_sign.c index 357650d..af257cc 100644 --- a/tools/fit_check_sign.c +++ b/tools/fit_check_sign.c @@ -62,10 +62,10 @@ int main(int argc, char **argv) break; } - ffd = mmap_fdt(cmdname, fdtfile, &fit_blob, &fsbuf, false); + ffd = mmap_fdt(cmdname, fdtfile, 0, &fit_blob, &fsbuf, false); if (ffd < 0) return EXIT_FAILURE; - kfd = mmap_fdt(cmdname, keyfile, &key_blob, &ksbuf, false); + kfd = mmap_fdt(cmdname, keyfile, 0, &key_blob, &ksbuf, false); if (ffd < 0) return EXIT_FAILURE; diff --git a/tools/fit_common.c b/tools/fit_common.c index 286f357..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(const char *cmdname, const char *fname, void **blobp, - struct stat *sbuf, bool delete_on_error) +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; @@ -59,6 +59,15 @@ int mmap_fdt(const char *cmdname, const char *fname, void **blobp, 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; ptr = mmap(0, sbuf->st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); if ((ptr == MAP_FAILED) || (errno != 0)) { @@ -73,6 +82,18 @@ int mmap_fdt(const char *cmdname, const char *fname, void **blobp, 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; diff --git a/tools/fit_common.h b/tools/fit_common.h index adcee6d..b8d8438 100644 --- a/tools/fit_common.h +++ b/tools/fit_common.h @@ -21,12 +21,13 @@ int fit_check_image_types(uint8_t type); * * @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, void **blobp, - struct stat *sbuf, bool delete_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 9442ff1..afbed7b 100644 --- a/tools/fit_info.c +++ b/tools/fit_info.c @@ -68,7 +68,7 @@ int main(int argc, char **argv) break; } - ffd = mmap_fdt(cmdname, fdtfile, &fit_blob, &fsbuf, false); + 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-host.c b/tools/image-host.c index 651f1c2..2be5e80 100644 --- a/tools/image-host.c +++ b/tools/image-host.c @@ -224,7 +224,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 +591,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 +607,13 @@ 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) { + printf("Failed to add verification data for '%s' signature node in '%s' image node\n", + node_name, conf_name); + return ret == FDT_ERR_NOSPACE ? -ENOSPC : -EIO; + } } return 0; -- cgit v1.1 From ad80c4a3220b5348f904f909ed572c364d50f867 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 6 Jun 2014 14:04:32 +0900 Subject: kbuild, tools: generate wrapper C sources automatically by Makefile There are many source files shared between U-boot image and tools. Instead of adding a lot of dummy wrapper files that just include the corresponding file in lib/ or common/ directory, Makefile should automatically generate them. The original inspiration for this came from scripts/Makefile.asm-generic of Linux Kernel. Signed-off-by: Masahiro Yamada Acked-by: Simon Glass Tested-by: Simon Glass --- tools/.gitignore | 3 +++ tools/Makefile | 36 +++++++++++++++++++++++------------- tools/crc32.c | 1 - tools/env_embedded.c | 1 - tools/fdt.c | 1 - tools/fdt_ro.c | 1 - tools/fdt_rw.c | 1 - tools/fdt_strerror.c | 1 - tools/fdt_wip.c | 1 - tools/fdtdec.c | 1 - tools/image-fit.c | 1 - tools/image-sig.c | 1 - tools/image.c | 1 - tools/md5.c | 1 - tools/rsa-checksum.c | 1 - tools/rsa-sign.c | 1 - tools/rsa-verify.c | 1 - tools/sha1.c | 1 - tools/sha256.c | 1 - 19 files changed, 26 insertions(+), 30 deletions(-) delete mode 100644 tools/crc32.c delete mode 100644 tools/env_embedded.c delete mode 100644 tools/fdt.c delete mode 100644 tools/fdt_ro.c delete mode 100644 tools/fdt_rw.c delete mode 100644 tools/fdt_strerror.c delete mode 100644 tools/fdt_wip.c delete mode 100644 tools/fdtdec.c delete mode 100644 tools/image-fit.c delete mode 100644 tools/image-sig.c delete mode 100644 tools/image.c delete mode 100644 tools/md5.c delete mode 100644 tools/rsa-checksum.c delete mode 100644 tools/rsa-sign.c delete mode 100644 tools/rsa-verify.c delete mode 100644 tools/sha1.c delete mode 100644 tools/sha256.c (limited to 'tools') diff --git a/tools/.gitignore b/tools/.gitignore index 725db90..0eb9068 100644 --- a/tools/.gitignore +++ b/tools/.gitignore @@ -21,3 +21,6 @@ /easylogo/easylogo /gdb/gdbcont /gdb/gdbsend + +/lib/ +/common/ diff --git a/tools/Makefile b/tools/Makefile index 762f7dc..06a95bb 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -47,7 +47,7 @@ hostprogs-$(CONFIG_VIDEO_LOGO) += bmp_logo$(SFX) HOSTCFLAGS_bmp_logo$(SFX).o := -pedantic hostprogs-$(CONFIG_BUILD_ENVCRC) += envcrc$(SFX) -envcrc$(SFX)-objs := crc32.o env_embedded.o envcrc.o sha1.o +envcrc$(SFX)-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 @@ -59,41 +59,43 @@ hostprogs-$(CONFIG_XWAY_SWAP_BYTES) += xway-swap-bytes$(SFX) HOSTCFLAGS_xway-swap-bytes$(SFX).o := -pedantic hostprogs-y += mkenvimage$(SFX) -mkenvimage$(SFX)-objs := crc32.o mkenvimage.o os_support.o +mkenvimage$(SFX)-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) -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 \ + lib/crc32.o \ default_image.o \ - fdtdec.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 \ pbl_crc32.o \ - sha1.o \ - sha256.o \ + lib/sha1.o \ + lib/sha256.o \ ublimage.o \ $(LIBFDT_OBJS) \ $(RSA_OBJS-y) @@ -139,7 +141,7 @@ hostprogs-$(CONFIG_SUNXI) += mksunxiboot$(SFX) hostprogs-$(CONFIG_NETCONSOLE) += ncb$(SFX) hostprogs-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1$(SFX) -ubsha1$(SFX)-objs := os_support.o sha1.o ubsha1.o +ubsha1$(SFX)-objs := os_support.o ubsha1.o lib/sha1.o HOSTCFLAGS_ubsha1.o := -pedantic @@ -159,6 +161,14 @@ HOSTCFLAGS_sha256.o := -pedantic #hostprogs-$(CONFIG_PPC) += mpc86x_clk$(SFX) #HOSTCFLAGS_mpc86x_clk$(SFX).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) # Generated LCD/video logo 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/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/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-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/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/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" -- cgit v1.1 From 96b09a97f5eda5132d059ce3c72dafb53654380f Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 6 Jun 2014 20:46:44 +0900 Subject: kbuild: remove unnecessary adjustment for Cygwin "SFX = .exe" was originally added for Cygwin environment. It is true that GCC on Cygwin spits executables with .exe extention. For example, gcc -o foo foo.c will generate "foo.exe", not "foo". But GNU make is also nicely adjusted for Cygwin. For example, foo: foo.c gcc -o $@ $< will compare the timestamp between "foo.exe" and "foo.c". You do not have to tweak Makefiles like this: foo$(SFX): foo.c gcc -o $@ $< And "make clean" works as well without adjustment for Cygwin because the command "rm foo" on Cygwin will delete both "foo" and "foo.exe". In conclusion, makefiles do not need special care for Cygwin. Signed-off-by: Masahiro Yamada --- tools/Makefile | 89 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 40 insertions(+), 49 deletions(-) (limited to 'tools') diff --git a/tools/Makefile b/tools/Makefile index 06a95bb..0088c1a 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,31 +29,31 @@ 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 := envcrc.o lib/crc32.o common/env_embedded.o lib/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 := mkenvimage.o os_support.o lib/crc32.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) := common/image-sig.o # Flattened device tree objects @@ -100,10 +91,10 @@ dumpimage-mkimage-objs := aisimage.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? @@ -121,33 +112,33 @@ endif # MXSImage needs LibSSL ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_FIT_SIGNATURE),) -HOSTLOADLIBES_mkimage$(SFX) += -lssl -lcrypto +HOSTLOADLIBES_mkimage += -lssl -lcrypto endif -HOSTLOADLIBES_dumpimage$(SFX) := $(HOSTLOADLIBES_mkimage$(SFX)) -HOSTLOADLIBES_fit_info$(SFX) := $(HOSTLOADLIBES_mkimage$(SFX)) -HOSTLOADLIBES_fit_check_sign$(SFX) := $(HOSTLOADLIBES_mkimage$(SFX)) +HOSTLOADLIBES_dumpimage := $(HOSTLOADLIBES_mkimage) +HOSTLOADLIBES_fit_info := $(HOSTLOADLIBES_mkimage) +HOSTLOADLIBES_fit_check_sign := $(HOSTLOADLIBES_mkimage) -hostprogs-$(CONFIG_EXYNOS5250) += mkexynosspl$(SFX) -hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl$(SFX) -HOSTCFLAGS_mkexynosspl$(SFX).o := -pedantic +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 ubsha1.o lib/sha1.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 @@ -158,8 +149,8 @@ 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)/%,%,$@)>" >$@ -- cgit v1.1 From 7050f0de7e566862ed72ac4d86ddf21d929651c8 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 6 Jun 2014 20:46:45 +0900 Subject: .gitignore: move *.exe pattern to the top gitignore for Cygwin GCC on Cygwin generates executables with .exe extension, for example: scripts/basic/fixdep.exe scripts/docproc.exe To ignore them, *.exe pattern should be moved from tools/.gitignore to ./.gitignore Signed-off-by: Masahiro Yamada --- tools/.gitignore | 1 - 1 file changed, 1 deletion(-) (limited to 'tools') diff --git a/tools/.gitignore b/tools/.gitignore index 0eb9068..cefe923 100644 --- a/tools/.gitignore +++ b/tools/.gitignore @@ -17,7 +17,6 @@ /relocate-rela /ubsha1 /xway-swap-bytes -/*.exe /easylogo/easylogo /gdb/gdbcont /gdb/gdbsend -- cgit v1.1 From 597a8b2c68574970dc38c55abe07712b6045776a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 12 Jun 2014 07:24:42 -0600 Subject: mkimage: Automatically expand FDT in more cases The original code did not cover every case and there was a missing negative sign in one case. Expand the coverage and fix the bug. Signed-off-by: Simon Glass --- tools/image-host.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/image-host.c b/tools/image-host.c index 2be5e80..faeef66 100644 --- a/tools/image-host.c +++ b/tools/image-host.c @@ -609,11 +609,13 @@ static int fit_config_process_sig(const char *keydir, void *keydest, /* Write the public key into the supplied FDT file */ 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 == FDT_ERR_NOSPACE ? -ENOSPC : -EIO; } + return ret; } return 0; -- cgit v1.1 From ba923cab0006838eb726e40207501ddf16eabd80 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 12 Jun 2014 07:24:44 -0600 Subject: tools: Check arguments in fit_check_sign/fit_info These tools crash if no arguments are provided. Add checks to avoid this. Signed-off-by: Simon Glass Acked-by: Heiko Schocher --- tools/fit_check_sign.c | 9 +++++++++ tools/fit_info.c | 12 ++++++++++++ 2 files changed, 21 insertions(+) (limited to 'tools') diff --git a/tools/fit_check_sign.c b/tools/fit_check_sign.c index af257cc..e1198bc 100644 --- a/tools/fit_check_sign.c +++ b/tools/fit_check_sign.c @@ -62,6 +62,15 @@ int main(int argc, char **argv) break; } + 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; diff --git a/tools/fit_info.c b/tools/fit_info.c index afbed7b..481ac6d 100644 --- a/tools/fit_info.c +++ b/tools/fit_info.c @@ -68,6 +68,18 @@ int main(int argc, char **argv) break; } + 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) { -- cgit v1.1 From 12df2abe3e159d622701611766c085b860329f78 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 12 Jun 2014 07:24:45 -0600 Subject: Reverse the meaning of the fit_config_verify() return code It is more common to have 0 mean OK, and -ve mean error. Change this function to work the same way to avoid confusion. Signed-off-by: Simon Glass --- tools/fit_check_sign.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/fit_check_sign.c b/tools/fit_check_sign.c index e1198bc..768be2f 100644 --- a/tools/fit_check_sign.c +++ b/tools/fit_check_sign.c @@ -80,8 +80,7 @@ int main(int argc, char **argv) image_set_host_blob(key_blob); ret = fit_check_sign(fit_blob, key_blob); - - if (ret) + if (!ret) ret = EXIT_SUCCESS; else ret = EXIT_FAILURE; -- cgit v1.1 From ea51a6282316f383fa04defa30ea15feb36d5d69 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 12 Jun 2014 07:24:51 -0600 Subject: Allow compiling common/bootm.c on with HOSTCC We want to use some of the functionality in this file, so make it build on the host. Signed-off-by: Simon Glass --- tools/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'tools') diff --git a/tools/Makefile b/tools/Makefile index 0088c1a..949b6c6 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -66,6 +66,7 @@ RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := $(addprefix lib/rsa/, \ dumpimage-mkimage-objs := aisimage.o \ atmelimage.o \ $(FIT_SIG_OBJS-y) \ + common/bootm.o \ lib/crc32.o \ default_image.o \ lib/fdtdec.o \ -- cgit v1.1 From ce1400f6949bbfec01fe381a844b14844cb3be12 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 12 Jun 2014 07:24:53 -0600 Subject: Enhance fit_check_sign to check all images At present this tool only checks the configuration signing. Have it also look at each of the images in the configuration and confirm that they verify. Signed-off-by: Simon Glass Acked-by: Heiko Schocher (v1) --- tools/fit_check_sign.c | 7 +++++-- tools/image-host.c | 12 +++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'tools') diff --git a/tools/fit_check_sign.c b/tools/fit_check_sign.c index 768be2f..69e99c0 100644 --- a/tools/fit_check_sign.c +++ b/tools/fit_check_sign.c @@ -80,10 +80,13 @@ int main(int argc, char **argv) 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/image-host.c b/tools/image-host.c index faeef66..0eff720 100644 --- a/tools/image-host.c +++ b/tools/image-host.c @@ -10,6 +10,7 @@ */ #include "mkimage.h" +#include #include #include @@ -707,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 -- cgit v1.1 From 2b9912e6a7df7b1f60beb7942bd0e6fa5f9d0167 Mon Sep 17 00:00:00 2001 From: Jeroen Hofstee Date: Thu, 12 Jun 2014 22:27:12 +0200 Subject: includes: move openssl headers to include/u-boot commit 18b06652cd "tools: include u-boot version of sha256.h" unconditionally forced the sha256.h from u-boot to be used for tools instead of the host version. This is fragile though as it will also include the host version. Therefore move it to include/u-boot to join u-boot/md5.h etc which were renamed for the same reason. cc: Simon Glass Signed-off-by: Jeroen Hofstee --- tools/Makefile | 1 - tools/dumpimage.h | 2 +- tools/imagetool.h | 2 +- tools/mkimage.h | 2 +- tools/ubsha1.c | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) (limited to 'tools') diff --git a/tools/Makefile b/tools/Makefile index 949b6c6..3a1180f 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -192,7 +192,6 @@ endif # !LOGO_BMP # Define _GNU_SOURCE to obtain the getline prototype from stdio.h # HOST_EXTRACFLAGS += -include $(srctree)/include/libfdt_env.h \ - -include $(srctree)/include/sha256.h \ $(patsubst -I%,-idirafter%, $(UBOOTINCLUDE)) \ -I$(srctree)/lib/libfdt \ -I$(srctree)/tools \ 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 #include #include -#include +#include #include "fdt_host.h" #include "imagetool.h" 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 #include #include -#include +#include #include "fdt_host.h" #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 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 #include #include -#include +#include #include "fdt_host.h" #include "imagetool.h" 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 #include #include -#include "sha1.h" +#include int main (int argc, char **argv) { -- cgit v1.1 From b047d671dbf60beab9822349f794a0152b97ac31 Mon Sep 17 00:00:00 2001 From: Heiko Schocher Date: Sun, 22 Jun 2014 06:33:29 +0200 Subject: lib, fdt: move fdtdec_get_int() out of lib/fdtdec.c move fdtdec_get_int() out of lib/fdtdec.c into lib/fdtdec_common.c as this function is also used, if CONFIG_OF_CONTROL is not used. Poped up on the ids8313 board using signed FIT images, and activating CONFIG_SYS_GENERIC_BOARD. Without this patch it shows on boot: No valid FDT found - please append one to U-Boot binary, use u-boot-dtb.bin or define CONFIG_OF_EMBED. For sandbox, use -d With this patch, it boots again with CONFIG_SYS_GENERIC_BOARD enabled. Signed-off-by: Heiko Schocher Acked-by: Simon Glass Cc: Tom Rini --- tools/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'tools') diff --git a/tools/Makefile b/tools/Makefile index 3a1180f..61b2048 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -69,6 +69,7 @@ dumpimage-mkimage-objs := aisimage.o \ common/bootm.o \ lib/crc32.o \ default_image.o \ + lib/fdtdec_common.o \ lib/fdtdec.o \ fit_common.o \ fit_image.o \ -- cgit v1.1