From bd9370d775ccc982ba54424f272deaef997f80bc Mon Sep 17 00:00:00 2001 From: Sergii Dmytruk Date: Mon, 6 May 2024 15:02:50 +0300 Subject: drivers/efi/uefi_capsules.c: coalesce and store UEFI capsules How it approximately works: (During a normal system run): 1. OS puts a capsule into RAM and calls UpdateCapsule() function of EFI runtime 2. If applying the update requires a reboot, EFI implementation creates a new CapsuleUpdateData* EFI variable pointing at the beginning of capsules description (not data, but description of the data) and does a warm reboot leaving capsule data and its description in RAM to be picked by firmware on the next boot process (After DEV_INIT:) 3. Capsules are discovered by checking for CapsuleUpdateData* variables 4. Capsule description in memory and capsule data is validated for sanity 5. Capsule data is coalesced into a continuous piece of memory (On BS_WRITE_TABLES via dasharo_add_capsules_to_bootmem() hook:) 6. Buffer with coalesced capsules is marked as reserved (On BS_WRITE_TABLES via lb_uefi_capsules() hook:) 7. coreboot table entry is added for each of the discovered capsules (In UEFI payload:) 8. CapsuleUpdateData* get removed 9. coreboot table is checked for any update capsules which are then applied Change-Id: I162d678ae5c504906084b59c1a8d8c26dadb9433 Signed-off-by: Sergii Dmytruk Reviewed-on: https://review.coreboot.org/c/coreboot/+/83422 Tested-by: build bot (Jenkins) Reviewed-by: Krystian Hebel --- src/lib/bootmem.c | 3 +++ src/lib/coreboot_table.c | 4 ++++ 2 files changed, 7 insertions(+) (limited to 'src/lib') diff --git a/src/lib/bootmem.c b/src/lib/bootmem.c index 578ddac19f..ab15e85d08 100644 --- a/src/lib/bootmem.c +++ b/src/lib/bootmem.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -80,6 +81,8 @@ static void bootmem_init(void) /* Add memory used by CBMEM. */ cbmem_add_bootmem(); + efi_add_capsules_to_bootmem(); + bootmem_add_range((uintptr_t)_stack, REGION_SIZE(stack), BM_MEM_RAMSTAGE); bootmem_add_range((uintptr_t)_program, REGION_SIZE(program), diff --git a/src/lib/coreboot_table.c b/src/lib/coreboot_table.c index 913588feb6..e954edb822 100644 --- a/src/lib/coreboot_table.c +++ b/src/lib/coreboot_table.c @@ -543,6 +543,10 @@ static uintptr_t write_coreboot_table(uintptr_t rom_table_end) /* Add board-specific table entries, if any. */ lb_board(head); + /* Possibly add UEFI capsules. */ + if (CONFIG(DRIVERS_EFI_UPDATE_CAPSULES)) + lb_efi_capsules(head); + if (CONFIG(CHROMEOS_RAMOOPS)) lb_ramoops(head); -- cgit v1.2.3