From 50bb682c5cc52769e7cbd835a00dbcbc75a4f0e7 Mon Sep 17 00:00:00 2001 From: Harald Seiler Date: Thu, 28 May 2020 17:54:45 +0200 Subject: tools: fw_env: Fix warning when reading too little When using CONFIG_ENV_IS_IN_FAT and the config-file specifies a size larger than what U-Boot wrote into the env-file, a confusing error message is shown: $ fw_printenv Read error on /boot/uboot.env: Success Fix this by showing a different error message when read returns too little data. Signed-off-by: Harald Seiler --- tools/env/fw_env.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 8734663cd4c..c6378ecf34f 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -946,11 +946,17 @@ static int flash_read_buf(int dev, int fd, void *buf, size_t count, lseek(fd, blockstart + block_seek, SEEK_SET); rc = read(fd, buf + processed, readlen); - if (rc != readlen) { + if (rc == -1) { fprintf(stderr, "Read error on %s: %s\n", DEVNAME(dev), strerror(errno)); return -1; } + if (rc != readlen) { + fprintf(stderr, "Read error on %s: " + "Attempted to read %d bytes but got %d\n", + DEVNAME(dev), readlen, rc); + return -1; + } #ifdef DEBUG fprintf(stderr, "Read 0x%x bytes at 0x%llx on %s\n", rc, (unsigned long long)blockstart + block_seek, -- cgit v1.3.1 From 317291167701480da6c235a17b0a7e89dafcff78 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 27 May 2020 07:24:55 -0600 Subject: mkimage: Default to adding a crc32 hash with '-f auto' This option currently does not add any sort of hash to the images in the FIT. Add a hash node requesting a crc32 checksum, which at least provides some protection. The crc32 value is easily ignored (e.g. in SPL) if not needed. and takes up only about 48 bytes per image, including overhead. Suggested-by: Wolfgang Denk Signed-off-by: Simon Glass Reviewed-by: Wolfgang Denk --- tools/fit_image.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/fit_image.c b/tools/fit_image.c index 88ff093d05b..a082d9386d2 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -111,7 +111,7 @@ static int fit_calc_size(struct image_tool_params *params) if (size < 0) return -1; - /* Add space for properties */ + /* Add space for properties and hash node */ total_size += size + 300; } @@ -192,6 +192,18 @@ static void get_basename(char *str, int size, const char *fname) str[len] = '\0'; } +/** + * add_crc_node() - Add a hash node to request a CRC checksum for an image + * + * @fdt: Device tree to add to (in sequential-write mode) + */ +static void add_crc_node(void *fdt) +{ + fdt_begin_node(fdt, "hash-1"); + fdt_property_string(fdt, FIT_ALGO_PROP, "crc32"); + fdt_end_node(fdt); +} + /** * fit_write_images() - Write out a list of images to the FIT * @@ -230,6 +242,7 @@ static int fit_write_images(struct image_tool_params *params, char *fdt) ret = fdt_property_file(params, fdt, FIT_DATA_PROP, params->datafile); if (ret) return ret; + add_crc_node(fdt); fdt_end_node(fdt); /* Now the device tree files if available */ @@ -252,6 +265,7 @@ static int fit_write_images(struct image_tool_params *params, char *fdt) genimg_get_arch_short_name(params->arch)); fdt_property_string(fdt, FIT_COMP_PROP, genimg_get_comp_short_name(IH_COMP_NONE)); + add_crc_node(fdt); fdt_end_node(fdt); } @@ -269,7 +283,7 @@ static int fit_write_images(struct image_tool_params *params, char *fdt) params->fit_ramdisk); if (ret) return ret; - + add_crc_node(fdt); fdt_end_node(fdt); } -- cgit v1.3.1