This adds support for FVB in order to support a platform independent and non-volatile variable store on UefiPayloadPkg. It is required for non-volatile variable support, TPM support, Secureboot support and more. Since commit bc744f5893fc4d53275ed26dd8d968011c6a09c1 coreboot supports the SMMSTORE v2 feature. It implements a SMI handler that is able to write, read and erase pages in the boot media (SPI flash). The communication is done using a fixed communication buffer that is allocated in CBMEM. The existence of this optional feature is advertised by a coreboot table. When the SMMSTORE feature is not available the variable emulation is used by setting PcdEmuVariableNvModeEnable to TRUE. Add a library for SMMStore to be used in DXE. The DXE component provides runtime services and takes care of virtual to physical mapping the communication buffers between SMM and OS. Make use of the APRIORI DXE to initialize an empty store on the first boot and set the PCDs to sane values before the variable driver is loaded. Tests on Intel(R) Xeon(R) E-2288G CPU @ 3.70G showed that the SMI isn't triggered with a probability of 1:40 of all cases when called in a tight loop. The CPU continues running and the SMI is triggeres asynchronously a few clock cycles later. coreboot only handels synchronous APM request and does nothing on asynchronous APM triggers. As there's no livesign from SMM it's impossible to tell if the handler has run. Just wait a bit and try again to trigger a synchronous SMI. Tests confirmed that out of 5 million tries the SMI is now always handled. Tested on Linux and Windows 10 on real hardware. Currently this cannot be tested on coreboot and qemu as it doesn't support the SMMSTORE on qemu. Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
119 lines
3.0 KiB
C
119 lines
3.0 KiB
C
/** @file BlSMMStoreDxe.h
|
|
|
|
Copyright (c) 2020, 9elements Agency GmbH<BR>
|
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
|
|
|
**/
|
|
|
|
#ifndef __COREBOOT_SMM_STORE_DXE_H__
|
|
#define __COREBOOT_SMM_STORE_DXE_H__
|
|
|
|
|
|
#include <Base.h>
|
|
#include <PiDxe.h>
|
|
|
|
#include <Guid/EventGroup.h>
|
|
|
|
#include <Protocol/BlockIo.h>
|
|
#include <Protocol/DiskIo.h>
|
|
#include <Protocol/FirmwareVolumeBlock.h>
|
|
|
|
#include <Library/DebugLib.h>
|
|
#include <Library/IoLib.h>
|
|
#include <Library/UefiLib.h>
|
|
#include <Library/UefiRuntimeLib.h>
|
|
|
|
#define SMMSTORE_SIGNATURE SIGNATURE_32('S', 'M', 'M', 'S')
|
|
#define INSTANCE_FROM_FVB_THIS(a) CR(a, SMMSTORE_INSTANCE, FvbProtocol, SMMSTORE_SIGNATURE)
|
|
|
|
typedef struct _SMMSTORE_INSTANCE SMMSTORE_INSTANCE;
|
|
|
|
#pragma pack (1)
|
|
typedef struct {
|
|
VENDOR_DEVICE_PATH Vendor;
|
|
UINT8 Index;
|
|
EFI_DEVICE_PATH_PROTOCOL End;
|
|
} NOR_FLASH_DEVICE_PATH;
|
|
#pragma pack ()
|
|
|
|
struct _SMMSTORE_INSTANCE {
|
|
UINT32 Signature;
|
|
EFI_HANDLE Handle;
|
|
EFI_BLOCK_IO_MEDIA Media;
|
|
|
|
EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL FvbProtocol;
|
|
|
|
NOR_FLASH_DEVICE_PATH DevicePath;
|
|
};
|
|
|
|
//
|
|
// BlSMMStoreFvbDxe.c
|
|
//
|
|
|
|
EFI_STATUS
|
|
EFIAPI
|
|
SMMStoreFvbInitialize (
|
|
IN SMMSTORE_INSTANCE* Instance
|
|
);
|
|
|
|
EFI_STATUS
|
|
EFIAPI
|
|
FvbGetAttributes(
|
|
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
|
OUT EFI_FVB_ATTRIBUTES_2 *Attributes
|
|
);
|
|
|
|
EFI_STATUS
|
|
EFIAPI
|
|
FvbSetAttributes(
|
|
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
|
IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes
|
|
);
|
|
|
|
EFI_STATUS
|
|
EFIAPI
|
|
FvbGetPhysicalAddress(
|
|
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
|
OUT EFI_PHYSICAL_ADDRESS *Address
|
|
);
|
|
|
|
EFI_STATUS
|
|
EFIAPI
|
|
FvbGetBlockSize(
|
|
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
|
IN EFI_LBA Lba,
|
|
OUT UINTN *BlockSize,
|
|
OUT UINTN *NumberOfBlocks
|
|
);
|
|
|
|
EFI_STATUS
|
|
EFIAPI
|
|
FvbRead(
|
|
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
|
IN EFI_LBA Lba,
|
|
IN UINTN Offset,
|
|
IN OUT UINTN *NumBytes,
|
|
IN OUT UINT8 *Buffer
|
|
);
|
|
|
|
EFI_STATUS
|
|
EFIAPI
|
|
FvbWrite(
|
|
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
|
IN EFI_LBA Lba,
|
|
IN UINTN Offset,
|
|
IN OUT UINTN *NumBytes,
|
|
IN UINT8 *Buffer
|
|
);
|
|
|
|
EFI_STATUS
|
|
EFIAPI
|
|
FvbEraseBlocks(
|
|
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
|
...
|
|
);
|
|
|
|
|
|
#endif /* __COREBOOT_SMM_STORE_DXE_H__ */
|