NvRAM & BIOS

What is NvRam?

NvRam: Acronym ----  Non-Volatile Random Access Memory.

What are the properties about NvRam?

NvRam Chip always retains its data, even when power to the chip is turn off.

Of course, NvRam is a type of RAM that also called read/write memory, can be used to store data that change.

NvRam in BIOS

We can define a variable in NvRam that keep value after power loss.For example: BIOS Setup Data.

How to use the variable in NvRam?

The Run time service support some functions to Read/Write NvRam data that named Variable Services: GetVariable and SetVariable.

ps:The Run Time service defined in UEFI SPEC.

About GetVariable

typedef

EFI_STATUS

(EFIAPI *EFI_GET_VARIABLE)(

  IN     CHAR16                      *VariableName,

  IN     EFI_GUID                    *VendorGuid,

  OUT    UINT32                      *Attributes,    OPTIONAL

  IN OUT UINTN                       *DataSize,

  OUT    VOID                        *Data           OPTIONAL

  );

This function will get a set of Structural data.

 

About  SetVariable

typedef
EFI_STATUS
(EFIAPI *EFI_SET_VARIABLE)(
  IN  CHAR16                       *VariableName,
  IN  EFI_GUID                     *VendorGuid,
  IN  UINT32                       Attributes,
  IN  UINTN                        DataSize,
  IN  VOID                         *Data
  );

This function will Set a set of Structural data.

 

Let’s examine each component of the function in more detail.

*VariableName    : The structure name you want to access

*VendorGuid        : The GUID for this structure

Attributes             :  Attributes of variable

Attributes  Enumeration:

EFI_VARIABLE_NON_VOLATILE  			//Store in NvRam
EFI_VARIABLE_BOOTSERVICE_ACCESS  	//Just be valid in boot service
EFI_VARIABLE_RUNTIME_ACCESS 			//It’s vaild in RT Service
EFI_VARIABLE_HARDWARE_ERROR_RECORD
EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
EFI_VARIABLE_APPEND_WRITE

DataSize : The Data Size of the structure

*Data     : The pointer to the structure

 

How to use it?

First:

You should have a structure and GUID.

#define JUST_FOR_TEST_GUID \
    {0xc1439232, 0xbfac, 0x412b, 0x97, 0x9a, 0xc, 0xbd, 0x12, 0xb6, 0x1f, 0xf7}

#pragma pack(1)

typedef struct _JUST_FOR_TEST_DATA
{
    UINT8   JUSTFORDATA;
} JUST_FOR_TEST_DATA;

#pragma pack()

Second:

    JUST_FOR_TEST_DATA   JustForTestData;
EFI_GUID    gJustForTestDataGuid = JUST_FOR_TEST_GUID;

Last:Modify variable and setvariable:

JustForTestData.JUSTFORDATA = 0;
            VarSize = sizeof(JUST_FOR_TEST_DATA);
                Status = gRT->SetVariable (
                              L" JustForTestData ",
                              &gAdvHidePolicyVariableGuid,
                              EFI_VARIABLE_NON_VOLATILE,
                              VarSize,
                              & JustForTestData);

Note: You can access Setup Data by GetVariable and SetVariable anytime.

You must first use SetVariable if the variable defined by self.

你可能感兴趣的:(BIOS,解析UEFI中的秘密)