Skip to content

Commit c7bf17c

Browse files
filiplepleSergiiDmytruk
authored andcommitted
drivers/efi/capsules.c: auto-set attempt_slot_b on capsule detection
When coreboot detects that a capsule has been loaded, it automatically sets the attempt_slot_b flag on redundancy-enabled platforms. This ensures that after an update the new firmware (Slot A) is booted. Placed the capsule-gated topswap bit toggle in the former enable_capsule_smi(), and renamed the function to more comprehensive enable_capsule_update_path(). Upstream-Status: Pending Change-Id: I21359cbae9fa1f424cce2039c5690b87e819ce92 Signed-off-by: Filip Lewiński <filip.lewinski@3mdeb.com> Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
1 parent 1d07968 commit c7bf17c

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

src/drivers/efi/capsules.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#include <Guid/FmpCapsule.h>
2424
#include <IndustryStandard/WindowsUxCapsule.h>
2525

26+
/* Weak default - platforms can override to prepare redundant slots */
27+
__weak void efi_capsule_update_prepare_redundant_slot(void) { }
28+
2629
/*
2730
* Overview
2831
*
@@ -801,7 +804,7 @@ BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT, parse_capsules, NULL);
801804

802805
#endif
803806

804-
static void enable_capsule_smi(void *unused)
807+
static void enable_capsule_update_path(void *unused)
805808
{
806809
uint32_t ret;
807810

@@ -824,6 +827,10 @@ static void enable_capsule_smi(void *unused)
824827

825828
printk(BIOS_INFO, "%sabled capsule update SMI handler\n",
826829
ret == SMMSTORE_RET_SUCCESS ? "En" : "Dis");
830+
831+
/* For redundancy-enabled platforms, ensure booting from Slot B */
832+
if (full_flash_access)
833+
efi_capsule_update_prepare_redundant_slot();
827834
}
828835

829-
BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_ENTRY, enable_capsule_smi, NULL);
836+
BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_ENTRY, enable_capsule_update_path, NULL);

src/drivers/efi/capsules.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,12 @@ static inline void efi_add_capsules_to_bootmem(void) { }
2424

2525
#endif
2626

27+
/*
28+
* Called when UEFI update capsules are detected.
29+
*
30+
* Platform-specific code can override this to prepare for capsule updates,
31+
* e.g., to switch to a redundant firmware slot for safe updates.
32+
*/
33+
void efi_capsule_update_prepare_redundant_slot(void);
34+
2735
#endif /* _EDK2_CAPSULES_H_ */

src/soc/intel/common/block/rtc/rtc.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* SPDX-License-Identifier: GPL-2.0-only */
22

3+
#include <console/console.h>
4+
#include <drivers/efi/capsules.h>
35
#include <fmap.h>
46
#include <intelblocks/pcr.h>
57
#include <intelblocks/rtc.h>
@@ -44,6 +46,19 @@ void rtc_conf_set_bios_interface_lockdown(void)
4446
}
4547

4648
#if CONFIG(INTEL_HAS_TOP_SWAP)
49+
50+
/*
51+
* When UEFI update capsules are detected, enable the attempt_slot_b CMOS option
52+
* so that the next boot will use the Top Swap (slot B) region for safe updates.
53+
*/
54+
void efi_capsule_update_prepare_redundant_slot(void)
55+
{
56+
if (CONFIG(INTEL_TOP_SWAP_OPTION_CONTROL)) {
57+
printk(BIOS_INFO, "Top Swap: enabling slot B for capsule update\n");
58+
set_uint_option(TOP_SWAP_ENABLE_CMOS_OPTION, 1);
59+
}
60+
}
61+
4762
void configure_rtc_buc_top_swap(enum ts_config ts_state)
4863
{
4964
pcr_rmw32(PID_RTC, PCR_RTC_BUC, ~PCR_RTC_BUC_TOP_SWAP, ts_state);

0 commit comments

Comments
 (0)