From faebb6211541d55008d54469ba1ed336650caffa Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Tue, 14 Apr 2026 16:24:03 +0200 Subject: [PATCH] Fixed test regressions --- .gitignore | 5 ++++- src/tpm.c | 5 +++-- src/update_flash.c | 16 ++++++++++++++-- tools/unit-tests/Makefile | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index eccdcaee..71dcbc5c 100644 --- a/.gitignore +++ b/.gitignore @@ -114,6 +114,7 @@ include/target.h .wolfboot-offset .wolfboot-partition-size .bootloader-partition-size +NVChip MPLabX/wolfBoot-SAME51.X/.generated_files/ test-dummy-ca/** @@ -183,6 +184,9 @@ tools/unit-tests/unit-update-flash-delta tools/unit-tests/unit-update-flash-self-update tools/unit-tests/unit-loader-tpm-init tools/unit-tests/unit-update-ram-nofixed +tools/unit-tests/unit-max-space +tools/unit-tests/unit-sdhci-disk-unaligned + @@ -376,4 +380,3 @@ system-default.dtb test_output/ sdcard.img - diff --git a/src/tpm.c b/src/tpm.c index d5d6f813..a5777337 100644 --- a/src/tpm.c +++ b/src/tpm.c @@ -355,13 +355,14 @@ int wolfBoot_tpm2_extend(uint8_t pcrIndex, uint8_t* hash, int line) TPM2_GetHashDigestSize(WOLFBOOT_TPM_PCR_ALG)); #ifdef WOLFBOOT_DEBUG_TPM if (rc == 0) { + int read_rc; wolfBoot_printf("Measured boot: Index %d, Line %d\n", pcrIndex, line); - rc = wolfTPM2_ReadPCR(&wolftpm_dev, pcrIndex, WOLFBOOT_TPM_PCR_ALG, + read_rc = wolfTPM2_ReadPCR(&wolftpm_dev, pcrIndex, WOLFBOOT_TPM_PCR_ALG, digest, &digestSz); wolfBoot_printf("PCR %d: Res %d, Digest Sz %d\n", - pcrIndex, rc, digestSz); + pcrIndex, read_rc, digestSz); wolfBoot_print_bin(digest, digestSz); } else { diff --git a/src/update_flash.c b/src/update_flash.c index fd60efae..8aafbd24 100644 --- a/src/update_flash.c +++ b/src/update_flash.c @@ -567,6 +567,18 @@ static int RAMFUNCTION wolfBoot_swap_and_final_erase(int resume) # define DELTA_BLOCK_SIZE 1024 #endif +static inline uint32_t wb_im2n32(uint32_t val) +{ +#ifdef BIG_ENDIAN_ORDER + return val; +#else + return (((val & 0x000000FFU) << 24) | + ((val & 0x0000FF00U) << 8) | + ((val & 0x00FF0000U) >> 8) | + ((val & 0xFF000000U) >> 24)); +#endif +} + static int wolfBoot_delta_update(struct wolfBoot_image *boot, struct wolfBoot_image *update, struct wolfBoot_image *swap, int inverse, int resume) @@ -619,9 +631,9 @@ static int wolfBoot_delta_update(struct wolfBoot_image *boot, &delta_base_hash, &delta_base_hash_sz) < 0) { return -1; } - delta_img_size = im2n(*img_size); + delta_img_size = wb_im2n32(*img_size); if (inverse) - delta_img_offset = im2n(*img_offset); + delta_img_offset = wb_im2n32(*img_offset); cur_v = wolfBoot_current_firmware_version(); upd_v = wolfBoot_update_firmware_version(); delta_base_v = wolfBoot_get_diffbase_version(PART_UPDATE); diff --git a/tools/unit-tests/Makefile b/tools/unit-tests/Makefile index 23f2fcaf..0875ad64 100644 --- a/tools/unit-tests/Makefile +++ b/tools/unit-tests/Makefile @@ -240,7 +240,7 @@ unit-boot-x86-fsp: ../../include/target.h unit-boot-x86_fsp.c -Wl,--gc-sections unit-loader-tpm-init: ../../include/target.h unit-loader-tpm-init.c - gcc -o $@ $^ $(CFLAGS) -DWOLFBOOT_LOADER_MAIN -DWOLFBOOT_TPM \ + gcc -o $@ $^ $(CFLAGS) -I$(WOLFBOOT_LIB_WOLFTPM) -DWOLFBOOT_LOADER_MAIN -DWOLFBOOT_TPM \ -DWOLFBOOT_HOOK_PANIC -DWOLFBOOT_SIGN_ECC256 \ -DWOLFBOOT_HASH_SHA256 -ffunction-sections -fdata-sections \ $(LDFLAGS) -Wl,--gc-sections