From bf330f2dd0d961db4de087fe6b773b44b0fe12dd Mon Sep 17 00:00:00 2001 From: Wonkyu Kim Date: Fri, 16 May 2025 01:39:36 -0700 Subject: [PATCH] security/vboot: Back up CMOS data later boot phase Introduce POSTPONE_SPI_ACCESS to save CMOS data in a later boot phase to avoid flash access delay by other boot controllers. Intel has pre-CPU boot controllers (e.g. CSE) which load non-CPU firmwares. Boot-critical firmwares are loaded before CPU reset and non-boot-critical firmwares are loaded during CPU boot. If another controller accesses SPI to load firmwares, reading SPI by CPU is ok, but writing to SPI for saving CMOS data can take ~30ms sometimes. Saving CMOS data usually takes less than 1ms. Before this change, sometimes it delays like below: BS: callback (0x7386f908) @ src/security/vboot/vbnv_cmos.c:122 (32 ms) After this change, the delay is less than 1 ms: BS: callback (0x7386f908) @ src/security/vboot/vbnv_cmos.c:122 (0 ms) TEST 1. Enable DEBUG_BOOT_STATE 2. Check time BS: callback (0x7386f908) @ src/security/vboot/vbnv_cmos.c:120 (0 ms) Signed-off-by: Wonkyu Kim Change-Id: I8836c14601beb56c614605b9840c8506d6d8536c Reviewed-on: https://review.coreboot.org/c/coreboot/+/87738 Reviewed-by: Subrata Banik Tested-by: build bot (Jenkins) --- src/Kconfig | 9 +++++++++ src/security/vboot/vbnv_cmos.c | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/src/Kconfig b/src/Kconfig index 58c2e07ea9..1a49a8ba55 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -1563,3 +1563,12 @@ config HAVE_RAMSTAGE config SEPARATE_ROMSTAGE default y + +config POSTPONE_SPI_ACCESS + bool + help + Enable this option to postpone SPI access to later boot phase + (BS_PAYLOAD_BOOT) to prevent flash write access delays caused by + simultaneous accesses from other SPI masters like CSE. This symptom + was found in Intel SoCs (Panther Lake and Wildcat Lake) but it can be + used other SOCs. diff --git a/src/security/vboot/vbnv_cmos.c b/src/security/vboot/vbnv_cmos.c index 5073509fc9..916e1ca03e 100644 --- a/src/security/vboot/vbnv_cmos.c +++ b/src/security/vboot/vbnv_cmos.c @@ -115,5 +115,10 @@ static void back_up_vbnv_cmos(void *unused) /* Save to flash, will only be saved if different. */ save_vbnv_flash(vbnv_cmos); } + +#if CONFIG(POSTPONE_SPI_ACCESS) +BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, back_up_vbnv_cmos, NULL); +#else BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT, back_up_vbnv_cmos, NULL); #endif +#endif