Skip to content

Commit 64f318c

Browse files
committed
Added boot benchmark support to update_flash.c.
1 parent 8b7ce4e commit 64f318c

3 files changed

Lines changed: 37 additions & 4 deletions

File tree

config/examples/vorago_va416x0.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ WOLFBOOT_RESTORE_CLOCK?=1
8282
#CFLAGS_EXTRA+=-DDEBUG_EXT_FLASH
8383
#CFLAGS_EXTRA+=-DTEST_EXT_FLASH
8484

85+
# Optional: Boot benchmarking (timing of integrity check, signature verify)
86+
# Requires DEBUG_UART=1 for output
87+
#BOOT_BENCHMARK?=1
88+
8589
# Optional: Enable wolfCrypt test and benchmark in test-app
8690
# Uncomment to enable
8791
# Note: Requires ~80-160KB additional flash and ~10-20KB RAM

hal/va416x0.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,3 +581,22 @@ void hal_prepare_boot(void)
581581
/* Disable system config IRQs */
582582
VOR_SYSCONFIG->IRQ_ENB = 0;
583583
}
584+
585+
#if defined(WOLFBOOT_UPDATE_DISK) || defined(BOOT_BENCHMARK)
586+
/* Microsecond timer for boot benchmarking.
587+
* Uses SysTick counter (counts down each ms tick) combined with
588+
* HAL_time_ms (incremented by SysTick_Handler every 1ms).
589+
* SysTick->LOAD = (SystemCoreClock / 1000) - 1 (configured by HAL_Init).
590+
* SysTick->VAL counts down from LOAD to 0.
591+
*/
592+
uint64_t hal_get_timer_us(void)
593+
{
594+
extern volatile uint64_t HAL_time_ms;
595+
uint32_t load = SysTick->LOAD;
596+
uint32_t val = SysTick->VAL;
597+
uint32_t elapsed_ticks = load - val;
598+
599+
return (HAL_time_ms * 1000ULL) +
600+
((uint64_t)elapsed_ticks * 1000000ULL / SystemCoreClock);
601+
}
602+
#endif

src/update_flash.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,7 @@ void RAMFUNCTION wolfBoot_start(void)
14011401
uint8_t updateState;
14021402
#endif /* !WOLFBOOT_SELF_UPDATE_MONOLITHIC */
14031403
struct wolfBoot_image boot;
1404+
BENCHMARK_DECLARE();
14041405

14051406
#if defined(ARCH_SIM) && defined(WOLFBOOT_TPM) && defined(WOLFBOOT_TPM_SEAL)
14061407
wolfBoot_unlock_disk();
@@ -1481,10 +1482,19 @@ void RAMFUNCTION wolfBoot_start(void)
14811482
wolfBoot_get_blob_version(boot.hdr));
14821483

14831484
#ifndef WOLFBOOT_SKIP_BOOT_VERIFY
1484-
if (bootRet < 0
1485-
|| (wolfBoot_verify_integrity(&boot) < 0)
1486-
|| (wolfBoot_verify_authenticity(&boot) < 0)
1487-
) {
1485+
if (bootRet >= 0) {
1486+
wolfBoot_printf("Checking integrity...");
1487+
BENCHMARK_START();
1488+
bootRet = wolfBoot_verify_integrity(&boot);
1489+
BENCHMARK_END("done");
1490+
}
1491+
if (bootRet >= 0) {
1492+
wolfBoot_printf("Verifying signature...");
1493+
BENCHMARK_START();
1494+
bootRet = wolfBoot_verify_authenticity(&boot);
1495+
BENCHMARK_END("done");
1496+
}
1497+
if (bootRet < 0) {
14881498
wolfBoot_printf("Boot failed: Hdr %d, Hash %d, Sig %d\n",
14891499
boot.hdr_ok, boot.sha_ok, boot.signature_ok);
14901500
#ifndef WOLFBOOT_SELF_UPDATE_MONOLITHIC

0 commit comments

Comments
 (0)