問:在PEI階段,PeiReadOnlyVariable2->GetVariable()能夠從Pei Hob或NV RAM中獲取UEFI變量,例如Setup默認值。若平臺首次燒錄BIOS並開機,在Hob還沒有創建,並且尚未將Setup默認值set到NVRAM中以前,第一次是如何讀取到Setup默認值的?ios
先來看一下 EFI_PEI_READ_ONLY_VARIABLE2_PPI,ide
// // 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。ui
對於上面所提問題,一開始認爲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默認值的。code
Setup默認值是經過FCE工具打到Bios binary中的,而且以PEIM FFS文件的形式存在於PEI FV中。BIOS首次開機時,會根據GUID檢索Flash BIOS中的Setup FFS文件,讀取到內存中,並創建相應的Variable Hob,Boot OS以前再將Setup默認值寫入到NVRAM中。下次開機,就能夠直接從NVRAM中讀取了。內存