UEFI筆記 --- PeiReadOnlyVariable2->GetVariable()


問:在PEI階段,PeiReadOnlyVariable2->GetVariable()可以從Pei Hob或NV RAM中獲取UEFI變量,例如Setup默認值。若平台首次燒錄BIOS並開機,在Hob尚未建立,而且還沒有將Setup默認值set到NVRAM中之前,第一次是如何讀取到Setup默認值的?


先來看一下 EFI_PEI_READ_ONLY_VARIABLE2_PPI,

//
// This PPI provides a lightweight, read-only variant of the full EFI 
// variable services. 
//
struct _EFI_PEI_READ_ONLY_VARIABLE2_PPI {
    EFI_PEI_GET_VARIABLE2           GetVariable;
    EFI_PEI_GET_NEXT_VARIABLE_NAME2 NextVariableName;
};

在PEI階段,該PPI允許以read-only的方式獲取UEFI variable store。

//
// This service retrieves a variable's value using its name and GUID.
//
// Read the specified variable from the UEFI variable store. If the Data 
// buffer is too small to hold the contents of the variable, 
// the error EFI_BUFFER_TOO_SMALL is returned and DataSize is set to the
// required buffer size to obtain the data.
//
typedef
EFI_STATUS
(EFIAPI *EFI_PEI_GET_VARIABLE2)(
    IN CONST  EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,
    IN CONST  CHAR16                          *VariableName,
    IN CONST  EFI_GUID                        *VariableGuid,
    OUT       UINT32                          *Attributes,
    IN OUT    UINTN                           *DataSize,
    OUT       VOID                            *Data
);

EFI_PEI_GET_VARIABLE2 interface的作用是從PEI Hob或NVRAM中獲取variable storages。

對於上面所提問題,一開始認為GetVariable()可以直接從SPI Flash中的Bios binary中讀取到Variable storages。實際上不然,GetVariable()只能根據VariableName和VariableGuid從PEI Hob或NVRAM中讀取相應的variable,若Hob list與NVRAM中都不存在相應的varible header,則返回EFI_NOT_FOUND。因此,對於第一次BIOS開機,第一次執行GetVariable()是不可能得到想要的setup默認值的。

Setup默認值是通過FCE工具打到Bios binary中的,並且以PEIM FFS文件的形式存在於PEI FV中。BIOS首次開機時,會根據GUID檢索Flash BIOS中的Setup FFS文件,讀取到內存中,並建立相應的Variable Hob,Boot OS之前再將Setup默認值寫入到NVRAM中。下次開機,就可以直接從NVRAM中讀取了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM