Newer
Older
AMI-Aptio-BIOS-Reversed / AmiNetworkPkg / Redfish / AmiRedFishApi / AmiRedFishApi.md
@Ajax Dong Ajax Dong 2 days ago 6 KB Full restructure

AmiRedFishApi

Function Table

Address Name Description
AmiRedfishReadUnaligned64
AmiRedfishWriteUnaligned64
AmiRedfishDebugPrint
AmiRedfishAssert
AmiRedfishFreePool
AmiRedfishGetDebugLevel
AmiRedfishInitHobList
AmiRedfishGetSecureBootMode
AmiRedfishGetSecureBoot
AmiRedfishSetSecureBootSetup
AmiRedfishSetVariable
AmiRedfishProcessPK
AmiRedfishGetRawImage
AmiRedfishProcessAllVariables
AmiRedfishEntryPoint
GUID definitions
Global data
Protocol handle GUID array used for InstallMultipleProtocolInterfaces.
The value 17039617 (0x01040001) may encode version/attributes info.
STATIC CONST UINT32 mAmiRedfishProtocolVersion = 17039617;
Table of Secure Boot variable names (dbx, dbt, dbr, db).
STATIC CONST CHAR16 *mSecureBootVarNames[] = {
Table of default value variable names (dbxDefault, dbtDefault, ...).
STATIC CONST CHAR16 *mSecureBootDefaultNames[] = {
Table of image GUIDs associated with each Secure Boot variable.
STATIC EFI_GUID *mSecureBootImageGuids[] = {
Default variable GUID for Secure Boot variables.
STATIC EFI_GUID mSecureBootDefaultGuid = AMI_SECUREBOOT_DEFAULT_GUID;
Cached HOB list pointer.
STATIC VOID *mHobList = NULL;
Cached debug/report protocol pointer.
STATIC VOID *mDebugProtocol = NULL;
Internal helper functions
Allocate report status code protocol buffer.
Interface = AllocateZeroPool (0x10);
Locate the protocol via gBS->LocateProtocol.
Status = gBS->LocateProtocol (
reuse as debug protocol GUID
offset to protocol API
Call debug protocol's output function at offset 0.
Call debug protocol assertion handler at offset 8.
Read CMOS index 0x70 to preserve NMI bit, then select index 0x4B.
Index = IoRead8 (0x70);
Retrieve the HOB list from the system table configuration table array.
if (gST->NumberOfTableEntries > 0) {
Walk HOBs to find the gEfiHobMemoryAllocModuleGuid entry.
The specific GUID used here is the AmiRedfishHobGuid which matches
an AMI-specific HOB entry containing Redfish configuration data.
Secure Boot mode detection
First query the variable to determine its current size/attributes.
Status = gRT->GetVariable (
Variable management
Validate parameters.
if **(VarName == NULL VarGuid == NULL) {**
Validate data buffer requirements.
if ((Flags & REDFISH_OP_RUNTIME_ACCESS) != 0) {
Check if the variable already exists (and if we should skip NV write).
BufferSize = 0;
Variable does not exist or exists with a different size.
First attempt to get the variable from the default storage.
if **(Status == EFI_BUFFER_TOO_SMALL Status == EFI_SUCCESS) {**
Variable exists skip unless REDFISH_OP_BOOTSERVICE_ACCESS forces write.
if ((Flags & REDFISH_OP_BOOTSERVICE_ACCESS) == 0) {
Variable not found. Try to read it from the default location
using gRT->GetVariable with the appropriate time-based attributes.
AmiRedfishInitHobList (NULL);
Read the default variable using time-based variable access.
If the default variable is not found, clear the NV flag and retry.
Write the runtime variable.
Write the RT variable with the user-supplied data.
Status = gRT->SetVariable (
RT variable name
Write the non-volatile variable.
if ((Flags & REDFISH_OP_BOOTSERVICE_ACCESS) != 0) {
If the variable was written successfully, re-read its size for logging.
if (Status == EFI_SUCCESS) {
if ((Flags & REDFISH_OP_SIZE_CHECK) != 0) {
Raw image extraction from Firmware Volumes
Get the Loaded Image Protocol for the current image.
Status = gBS->HandleProtocol (
Get the section extraction protocol from the FV handle.
Try searching all handles for a matching FV section.
Status = gBS->LocateHandleBuffer (
Check if this handle's device path matches our FV.
if (LoadedImage->DeviceHandle == FvHandle) {
Try to open the section data by the image GUID.
SectionData = NULL;
Open FV section with the image GUID using the appropriate
section extraction protocol interface.
Iterate over all Secure Boot variables
EFI_GUID *ImageGuid;
UINTN ActualSize;
Default GUID for Secure Boot variables.
DefaultGuid = &mSecureBootDefaultGuid;
Iterate over the 4 Secure Boot variables (dbx, dbt, dbr, db).
for (VarIndex = 0; VarIndex < ARRAY_SIZE (mSecureBootVarNames); VarIndex++) {
Check whether the variable already exists in NVRAM.
If the variable exists and we should not overwrite it, skip.
if (!EFI_ERROR (Status) && (Flags & REDFISH_OP_BOOTSERVICE_ACCESS) == 0) {
Extract raw image data from the FV for this variable.
Write the variable.
Status = AmiRedfishSetVariable (
Free the section data if it was allocated by the extraction routine.
AmiRedfishFreePool (Data);
Entry Point
Cache global pointers from the System Table.
gImageHandle = ImageHandle;
Verify all required global pointers are non-NULL.
ASSERT (gImageHandle != NULL);
Initialize the HOB list for this driver.
AmiRedfishInitHobList (ImageHandle);
Install the AmiRedfishProtocolGuid onto the image handle.
Status = gBS->InstallMultipleProtocolInterfaces (

Generated by HR650X BIOS Decompilation Project