Subrata Banik has submitted this change. ( https://review.coreboot.org/c/coreboot/+/86452?usp=email )
Change subject: drivers/intel/fsp2_0: Add early low-battery shutdown during memory init ......................................................................
drivers/intel/fsp2_0: Add early low-battery shutdown during memory init
This commit introduces an early low-battery shutdown mechanism during FSP memory initialization. This is particularly important during firmware updates, where memory training can consume significant power and lead to abrupt shutdowns, potentially corrupting the firmware.
The changes include:
- Adding platform_display_early_shutdown_notification() to notify the user of the impending shutdown. - Checking platform_is_low_battery_shutdown_needed() to determine if a shutdown is necessary. - Implementing a shutdown sequence if low battery is detected during memory init, especially when no MRC cache is found (i.e. firmware update). - Deferring shutdown on systems without MAINBOARD_HAS_EARLY_LIBGFXINIT so that FSP-M (uGOP) can display a message.
This prevents firmware update corruption due to low battery.
BUG=b:339673254 TEST=Verified low battery boot event logging and controlled shutdown.
Change-Id: Ia135b238d1e16722c2ca8d3b461e83b4ce513adf Signed-off-by: Subrata Banik subratabanik@google.com Reviewed-on: https://review.coreboot.org/c/coreboot/+/86452 Reviewed-by: Jayvik Desai jayvik@google.com Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Kapil Porwal kapilporwal@google.com --- M src/drivers/intel/fsp2_0/include/fsp/api.h M src/drivers/intel/fsp2_0/memory_init.c 2 files changed, 56 insertions(+), 0 deletions(-)
Approvals: Jayvik Desai: Looks good to me, approved build bot (Jenkins): Verified Kapil Porwal: Looks good to me, approved
diff --git a/src/drivers/intel/fsp2_0/include/fsp/api.h b/src/drivers/intel/fsp2_0/include/fsp/api.h index 28b24ce..d159b71 100644 --- a/src/drivers/intel/fsp2_0/include/fsp/api.h +++ b/src/drivers/intel/fsp2_0/include/fsp/api.h @@ -63,6 +63,26 @@ #else static inline bool platform_is_low_battery_shutdown_needed(void) { return false; } #endif + +/* + * Displays an early shutdown notification to the user. + * + * This function is responsible to perform the needful operations for informing + * the user that the system is about to shut down prematurely. The implementation + * might be different depending upon the underlying technology that can be used for + * implementing eSOL for user notification. + * + * Argument: NULL for platform with libgfxinit and FSP-M UPD pointer for uGOP. + * + * Note: This function should be called before the actual shutdown process begins, + * allowing the user to potentially save data or take other necessary actions. + */ +#if CONFIG(PLATFORM_HAS_EARLY_LOW_BATTERY_INDICATOR) +void platform_display_early_shutdown_notification(void *arg); +#else +static inline void platform_display_early_shutdown_notification(void *arg) { /* nop */ } +#endif + /* Check if MultiPhase Si Init is enabled */ bool fsp_is_multi_phase_init_enabled(void); /* diff --git a/src/drivers/intel/fsp2_0/memory_init.c b/src/drivers/intel/fsp2_0/memory_init.c index ce0d283..38627c6 100644 --- a/src/drivers/intel/fsp2_0/memory_init.c +++ b/src/drivers/intel/fsp2_0/memory_init.c @@ -19,6 +19,7 @@ #include <security/tpm/tspi.h> #include <security/vboot/antirollback.h> #include <security/vboot/vboot_common.h> +#include <soc/intel/common/reset.h> #include <string.h> #include <symbols.h> #include <timestamp.h> @@ -331,6 +332,31 @@ timestamp_add_now(TS_FSP_MULTI_PHASE_MEM_INIT_END); }
+/** + * Checks for low battery during firmware update and initiates shutdown if necessary. + * + * This function checks if the system is in firmware update mode (indicated by + * a missing MRC cache) and if the battery is critically low. If both conditions + * are met, it initiates a shutdown to prevent interruption of the firmware + * update process. + */ +static void handle_low_battery_during_firmware_update(bool *defer_shutdown, FSPM_UPD *fspm_upd) +{ + if (!CONFIG(PLATFORM_HAS_EARLY_LOW_BATTERY_INDICATOR) || + !platform_is_low_battery_shutdown_needed()) + return; + + if (CONFIG(MAINBOARD_HAS_EARLY_LIBGFXINIT)) { + platform_display_early_shutdown_notification(NULL); + /* User has been notified of low battery; safe to power off. */ + do_low_battery_poweroff(); /* Do not return */ + } + + /* Defer shutdown until FSP-M (uGOP) display text message for user notification */ + platform_display_early_shutdown_notification(fspm_upd); + *defer_shutdown = true; +} + static void do_fsp_memory_init(const struct fspm_context *context, bool s3wake) { efi_return_status_t status; @@ -338,6 +364,7 @@ FSPM_UPD fspm_upd, *upd; FSPM_ARCHx_UPD *arch_upd; uint32_t version; + bool poweroff_after_fsp_execution = false; const struct fsp_header *hdr = &context->header; const struct memranges *memmap = &context->memmap;
@@ -389,6 +416,11 @@ early_ramtop_enable_cache_range(); #endif
+ /* Low battery check during firmware update */ + if (!arch_upd->NvsBufferPtr) + handle_low_battery_during_firmware_update(&poweroff_after_fsp_execution, + &fspm_upd); + /* Give SoC and mainboard a chance to update the UPD */ platform_fsp_memory_init_params_cb(&fspm_upd, version);
@@ -425,6 +457,10 @@ null_breakpoint_init(); stack_canary_breakpoint_init();
+ /* User has been notified of low battery; safe to power off. */ + if (poweroff_after_fsp_execution) + do_low_battery_poweroff(); + post_code(POSTCODE_FSP_MEMORY_EXIT); timestamp_add_now(TS_FSP_MEMORY_INIT_END);