soc/amd/common/block/apob_cache: Add support for RECOVERY_MRC_CACHE

If a mainboard has RECOVERY_MRC_CACHE and the recovery mode is enabled,
then use APOB data from that section and make any updates to that
section. Otherwise continue to use DEFAULT_MRC_CACHE section.

BUG=b:270569389
TEST=Build and boot to OS in Skyrim.

When in normal mode, DEFAULT_MRC_CACHE is used.
Normal Mode Boot1:
------------------
[DEBUG]  FMAP: area RW_MRC_CACHE found @ 0 (122880 bytes)
[INFO ]  APOB RAM hash differs from flash
[SPEW ]  Copy APOB from RAM 0x02001000/0x1db18 to flash 0x0/0x1e000
[DEBUG]  FMAP: area RW_MRC_CACHE found @ 0 (122880 bytes)
[DEBUG]  SF: Successfully erased 122880 bytes @ 0x0
[INFO ]  Updated APOB in flash
Normal Mode Boot2:
-----------------
[DEBUG]  FMAP: area RW_MRC_CACHE found @ 0 (122880 bytes)
[DEBUG]  APOB hash matches flash

When the device is in recovery mode, RECOVERY_MRC_CACHE is used.
Recovery Mode Boot1:
--------------------
[DEBUG]  FMAP: area RECOVERY_MRC_CACHE found @ 650000 (122880 bytes)
[INFO ]  APOB RAM hash differs from flash
[SPEW ]  Copy APOB from RAM 0x02001000/0x1db18 to flash 0x650000/0x1e000
[DEBUG]  FMAP: area RECOVERY_MRC_CACHE found @ 650000 (122880 bytes)
[DEBUG]  SF: Successfully erased 122880 bytes @ 0x650000
[INFO ]  Updated APOB in flash
Recovery Mode Boot2:
--------------------
[DEBUG]  FMAP: area RECOVERY_MRC_CACHE found @ 650000 (122880 bytes)
[DEBUG]  APOB hash matches flash

Switch from Recovery Mode to Normal Mode:
-----------------------------------------
[DEBUG]  FMAP: area RW_MRC_CACHE found @ 0 (122880 bytes)
[DEBUG]  APOB hash matches flash

Switch from Normal Mode to Recovery Mode:
-----------------------------------------
[DEBUG]  FMAP: area RECOVERY_MRC_CACHE found @ 650000 (122880 bytes)
[DEBUG]  APOB hash matches flash

Change-Id: I93f357e407c98b6e5fca495f4f779fad54a3430f
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/73168
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Fred Reitberger <reitbergerfred@gmail.com>
Reviewed-by: Raul Rangel <rrangel@chromium.org>
Reviewed-by: Matt DeVillier <matt.devillier@amd.corp-partner.google.com>
This commit is contained in:
Karthikeyan Ramasubramanian 2023-02-23 17:18:24 -07:00 committed by Felix Held
parent 7c5ad88887
commit 674b07247e
1 changed files with 26 additions and 4 deletions

View File

@ -10,6 +10,7 @@
#include <console/console.h>
#include <fmap.h>
#include <fmap_config.h>
#include <security/vboot/vboot_common.h>
#include <spi_flash.h>
#include <stdint.h>
#include <string.h>
@ -20,6 +21,14 @@
#define DEFAULT_MRC_CACHE "RW_MRC_CACHE"
#define DEFAULT_MRC_CACHE_SIZE FMAP_SECTION_RW_MRC_CACHE_SIZE
#if CONFIG(HAS_RECOVERY_MRC_CACHE)
#define RECOVERY_MRC_CACHE "RECOVERY_MRC_CACHE"
#define RECOVERY_MRC_CACHE_SIZE FMAP_SECTION_RECOVERY_MRC_CACHE_SIZE
#else
#define RECOVERY_MRC_CACHE DEFAULT_MRC_CACHE
#define RECOVERY_MRC_CACHE_SIZE DEFAULT_MRC_CACHE_SIZE
#endif
#if CONFIG(SOC_AMD_COMMON_BLOCK_APOB_HASH)
#define MRC_HASH_SIZE ((uint32_t)sizeof(uint64_t))
#else
@ -35,6 +44,9 @@
_Static_assert(CONFIG_PSP_APOB_DRAM_SIZE == DEFAULT_MRC_CACHE_SIZE,
"APOB DRAM reserved space != to MRC CACHE size - check your config");
_Static_assert(CONFIG_PSP_APOB_DRAM_SIZE == RECOVERY_MRC_CACHE_SIZE,
"APOB DRAM reserved space != to RECOVERY MRC CACHE size - check your config");
#define APOB_SIGNATURE 0x424F5041 /* 'APOB' */
/* APOB_BASE_HEADER from AGESA */
@ -80,7 +92,19 @@ static void *get_apob_dram_address(void)
static int get_nv_rdev(struct region_device *r)
{
if (fmap_locate_area_as_rdev(DEFAULT_MRC_CACHE, r) < 0) {
if (fmap_locate_area_as_rdev(vboot_recovery_mode_enabled() ?
RECOVERY_MRC_CACHE : DEFAULT_MRC_CACHE, r) < 0) {
printk(BIOS_ERR, "No APOB NV region is found in flash\n");
return -1;
}
return 0;
}
static int get_nv_rdev_rw(struct region_device *r)
{
if (fmap_locate_area_as_rdev_rw(vboot_recovery_mode_enabled() ?
RECOVERY_MRC_CACHE : DEFAULT_MRC_CACHE, r) < 0) {
printk(BIOS_ERR, "No APOB NV region is found in flash\n");
return -1;
}
@ -227,10 +251,8 @@ static void soc_update_apob_cache(void *unused)
apob_src_ram, apob_src_ram->size,
region_device_offset(&read_rdev), region_device_sz(&read_rdev));
if (fmap_locate_area_as_rdev_rw(DEFAULT_MRC_CACHE, &write_rdev) < 0) {
printk(BIOS_ERR, "No RW APOB NV region is found in flash\n");
if (get_nv_rdev_rw(&write_rdev) != 0)
return;
}
timestamp_add_now(TS_AMD_APOB_ERASE_START);