diff --git a/config/examples/vorago_va416x0.config b/config/examples/vorago_va416x0.config index 6452ddf596..ba223fb2ab 100644 --- a/config/examples/vorago_va416x0.config +++ b/config/examples/vorago_va416x0.config @@ -82,6 +82,10 @@ WOLFBOOT_RESTORE_CLOCK?=1 #CFLAGS_EXTRA+=-DDEBUG_EXT_FLASH #CFLAGS_EXTRA+=-DTEST_EXT_FLASH +# Optional: Boot benchmarking (timing of integrity check, signature verify) +# Requires DEBUG_UART=1 for output +#BOOT_BENCHMARK?=1 + # Optional: Enable wolfCrypt test and benchmark in test-app # Uncomment to enable # Note: Requires ~80-160KB additional flash and ~10-20KB RAM diff --git a/hal/va416x0.c b/hal/va416x0.c index 914d7f7534..e5c73eab6d 100644 --- a/hal/va416x0.c +++ b/hal/va416x0.c @@ -581,3 +581,22 @@ void hal_prepare_boot(void) /* Disable system config IRQs */ VOR_SYSCONFIG->IRQ_ENB = 0; } + +#if defined(WOLFBOOT_UPDATE_DISK) || defined(BOOT_BENCHMARK) +/* Microsecond timer for boot benchmarking. + * Uses SysTick counter (counts down each ms tick) combined with + * HAL_time_ms (incremented by SysTick_Handler every 1ms). + * SysTick->LOAD = (SystemCoreClock / 1000) - 1 (configured by HAL_Init). + * SysTick->VAL counts down from LOAD to 0. + */ +uint64_t hal_get_timer_us(void) +{ + extern volatile uint64_t HAL_time_ms; + uint32_t load = SysTick->LOAD; + uint32_t val = SysTick->VAL; + uint32_t elapsed_ticks = load - val; + + return (HAL_time_ms * 1000ULL) + + ((uint64_t)elapsed_ticks * 1000000ULL / SystemCoreClock); +} +#endif diff --git a/src/update_flash.c b/src/update_flash.c index 92f6496f56..fa2660b554 100644 --- a/src/update_flash.c +++ b/src/update_flash.c @@ -1401,6 +1401,7 @@ void RAMFUNCTION wolfBoot_start(void) uint8_t updateState; #endif /* !WOLFBOOT_SELF_UPDATE_MONOLITHIC */ struct wolfBoot_image boot; + BENCHMARK_DECLARE(); #if defined(ARCH_SIM) && defined(WOLFBOOT_TPM) && defined(WOLFBOOT_TPM_SEAL) wolfBoot_unlock_disk(); @@ -1481,10 +1482,19 @@ void RAMFUNCTION wolfBoot_start(void) wolfBoot_get_blob_version(boot.hdr)); #ifndef WOLFBOOT_SKIP_BOOT_VERIFY - if (bootRet < 0 - || (wolfBoot_verify_integrity(&boot) < 0) - || (wolfBoot_verify_authenticity(&boot) < 0) - ) { + if (bootRet >= 0) { + wolfBoot_printf("Checking integrity..."); + BENCHMARK_START(); + bootRet = wolfBoot_verify_integrity(&boot); + BENCHMARK_END("done"); + } + if (bootRet >= 0) { + wolfBoot_printf("Verifying signature..."); + BENCHMARK_START(); + bootRet = wolfBoot_verify_authenticity(&boot); + BENCHMARK_END("done"); + } + if (bootRet < 0) { wolfBoot_printf("Boot failed: Hdr %d, Hash %d, Sig %d\n", boot.hdr_ok, boot.sha_ok, boot.signature_ok); #ifndef WOLFBOOT_SELF_UPDATE_MONOLITHIC