diff --git a/tools/keytools/Makefile b/tools/keytools/Makefile index 8493a20e..b5a70785 100644 --- a/tools/keytools/Makefile +++ b/tools/keytools/Makefile @@ -7,11 +7,16 @@ ifeq ($(V),0) Q=@ endif +ifeq ($(WOLFBOOT_SECTOR_SIZE),) + WOLFBOOT_SECTOR_SIZE=2048 +endif + CC = gcc WOLFBOOTDIR = ../.. WOLFDIR = $(WOLFBOOTDIR)/lib/wolfssl/ CFLAGS = -Wall -Wextra -Werror CFLAGS += -I. -DWOLFSSL_USER_SETTINGS -I$(WOLFDIR) -I$(WOLFBOOTDIR)/include +CFLAGS += -DWOLFBOOT_SECTOR_SIZE=$(WOLFBOOT_SECTOR_SIZE) # option variables DEBUG_FLAGS = -g -DDEBUG -DDEBUG_SIGNTOOL -DDEBUG_WOLFSSL -DDEBUG_WOLFSSL_VERBOSE diff --git a/tools/keytools/sign.c b/tools/keytools/sign.c index 07dd281f..f781ad53 100755 --- a/tools/keytools/sign.c +++ b/tools/keytools/sign.c @@ -39,8 +39,6 @@ #include #include #include - -#include "target.h" #include "delta.h" #define MAX_SRC_SIZE (1 << 24) @@ -448,8 +446,9 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz, cons if (read_sz > 32) read_sz = 32; io_sz = fread(buf, 1, read_sz, f); - if (io_sz != (int)read_sz) { - ret = -1; break; + if ((io_sz < 0) && !feof(f)) { + ret = -1; + break; } ret = wc_Sha256Update(&sha, buf, read_sz); pos += read_sz; @@ -493,8 +492,9 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz, cons if (read_sz > 128) read_sz = 128; io_sz = fread(buf, 1, read_sz, f); - if (io_sz != (int)read_sz) { - ret = -1; break; + if ((io_sz < 0) && !feof(f)) { + ret = -1; + break; } ret = wc_Sha3_384_Update(&sha, buf, read_sz); pos += read_sz; @@ -866,8 +866,8 @@ static int base_diff(const char *f_base, uint8_t *pubkey, uint32_t pubkey_sz) patch_inv_sz += r; len3 += r; } while (r > 0); - io_sz = ftruncate(fd3, len3); - if (io_sz != len3) { + ret = ftruncate(fd3, len3); + if (ret != 0) { goto cleanup; } close(fd3);