File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -581,3 +581,36 @@ 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+ uint64_t ms ;
597+ uint32_t val ;
598+ uint32_t elapsed_ticks ;
599+
600+ /* Stable read: retry until ms matches before and after reading VAL.
601+ * Avoids a 1ms jump if the SysTick IRQ fires mid-read and makes the
602+ * timer non-monotonic (would break udelay() comparisons). */
603+ do {
604+ ms = HAL_time_ms ;
605+ val = SysTick -> VAL ;
606+ } while (ms != HAL_time_ms );
607+
608+ /* VAL counts LOAD..0 over LOAD+1 ticks, so elapsed = (LOAD+1) - VAL. */
609+ elapsed_ticks = (load + 1U ) - val ;
610+ if (elapsed_ticks > load )
611+ elapsed_ticks = load + 1U ;
612+
613+ return (ms * 1000ULL ) +
614+ ((uint64_t )elapsed_ticks * 1000000ULL / SystemCoreClock );
615+ }
616+ #endif
Original file line number Diff line number Diff 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,21 @@ 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+ if (bootRet >= 0 )
1490+ BENCHMARK_END ("done" );
1491+ }
1492+ if (bootRet >= 0 ) {
1493+ wolfBoot_printf ("Verifying signature..." );
1494+ BENCHMARK_START ();
1495+ bootRet = wolfBoot_verify_authenticity (& boot );
1496+ if (bootRet >= 0 )
1497+ BENCHMARK_END ("done" );
1498+ }
1499+ if (bootRet < 0 ) {
14881500 wolfBoot_printf ("Boot failed: Hdr %d, Hash %d, Sig %d\n" ,
14891501 boot .hdr_ok , boot .sha_ok , boot .signature_ok );
14901502#ifndef WOLFBOOT_SELF_UPDATE_MONOLITHIC
You can’t perform that action at this time.
0 commit comments