18#define KVMTOOL_NOR_BLOCK_SIZE SIZE_64KB
22#define MAX_FLASH_DEVICES 4
26#define LABEL_UEFI_VAR_STORE "System-firmware"
30STATIC INT32 mUefiVarStoreNode = MAX_INT32;
45 DEBUG ((DEBUG_INFO,
"NorFlashPlatformInitialization\n"));
47 if ((mNorFlashDeviceCount > 0) && (mUefiVarStoreNode != MAX_INT32)) {
63 Status = mFdtClient->SetNodeProperty (
70 if (EFI_ERROR (Status)) {
71 DEBUG ((DEBUG_WARN,
"Failed to set cfi-flash status to 'disabled'\n"));
74 Status = EFI_NOT_FOUND;
75 DEBUG ((DEBUG_ERROR,
"Flash device for UEFI variable storage not found\n"));
96 UINTN FlashNvStorageVariableBase;
97 UINTN FlashNvStorageFtwWorkingBase;
98 UINTN FlashNvStorageFtwSpareBase;
99 UINTN FlashNvStorageVariableSize;
100 UINTN FlashNvStorageFtwWorkingSize;
101 UINTN FlashNvStorageFtwSpareSize;
103 FlashNvStorageVariableSize =
PcdGet32 (PcdFlashNvStorageVariableSize);
104 FlashNvStorageFtwWorkingSize =
PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
105 FlashNvStorageFtwSpareSize =
PcdGet32 (PcdFlashNvStorageFtwSpareSize);
107 if ((FlashNvStorageVariableSize == 0) ||
108 (FlashNvStorageFtwWorkingSize == 0) ||
109 (FlashNvStorageFtwSpareSize == 0))
111 DEBUG ((DEBUG_ERROR,
"FlashNvStorage size not defined\n"));
112 return EFI_INVALID_PARAMETER;
116 FlashRegion = FlashDevice->DeviceBaseAddress;
118 FlashNvStorageVariableBase = FlashRegion;
119 FlashRegion +=
PcdGet32 (PcdFlashNvStorageVariableSize);
121 FlashNvStorageFtwWorkingBase = FlashRegion;
122 FlashRegion +=
PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
124 FlashNvStorageFtwSpareBase = FlashRegion;
125 FlashRegion +=
PcdGet32 (PcdFlashNvStorageFtwSpareSize);
127 if (FlashRegion > (FlashDevice->DeviceBaseAddress + FlashDevice->Size)) {
128 DEBUG ((DEBUG_ERROR,
"Insufficient flash storage size\n"));
129 return EFI_OUT_OF_RESOURCES;
133 PcdFlashNvStorageVariableBase,
134 FlashNvStorageVariableBase
138 PcdFlashNvStorageFtwWorkingBase,
139 FlashNvStorageFtwWorkingBase
143 PcdFlashNvStorageFtwSpareBase,
144 FlashNvStorageFtwSpareBase
149 "PcdFlashNvStorageVariableBase = 0x%x\n",
150 FlashNvStorageVariableBase
154 "PcdFlashNvStorageVariableSize = 0x%x\n",
155 FlashNvStorageVariableSize
159 "PcdFlashNvStorageFtwWorkingBase = 0x%x\n",
160 FlashNvStorageFtwWorkingBase
164 "PcdFlashNvStorageFtwWorkingSize = 0x%x\n",
165 FlashNvStorageFtwWorkingSize
169 "PcdFlashNvStorageFtwSpareBase = 0x%x\n",
170 FlashNvStorageFtwSpareBase
174 "PcdFlashNvStorageFtwSpareSize = 0x%x\n",
175 FlashNvStorageFtwSpareSize
195 if (mNorFlashDeviceCount > 0) {
196 *NorFlashDescriptions = mNorFlashDevices;
197 *Count = mNorFlashDeviceCount;
201 return EFI_NOT_FOUND;
227 UINTN UefiVarStoreIndex;
231 if ((mNorFlashDeviceCount != 0) ||
PcdGetBool (PcdEmuVariableNvModeEnable)) {
235 Status =
gBS->LocateProtocol (
236 &gFdtClientProtocolGuid,
242 UefiVarStoreIndex = MAX_UINTN;
243 for (FindNodeStatus = mFdtClient->FindCompatibleNode (
248 !EFI_ERROR (FindNodeStatus) &&
250 FindNodeStatus = mFdtClient->FindNextCompatibleNode (
257 Status = mFdtClient->GetNodeProperty (
261 (
CONST VOID **)&Label,
264 if (EFI_ERROR (Status)) {
267 "%a: GetNodeProperty ('label') failed (Status == %r)\n",
272 UefiVarStoreIndex = mNorFlashDeviceCount;
273 mUefiVarStoreNode = Node;
276 Status = mFdtClient->GetNodeProperty (
283 if (EFI_ERROR (Status)) {
286 "%a: GetNodeProperty () failed (Status == %r)\n",
293 ASSERT ((PropSize % (4 *
sizeof (UINT32))) == 0);
295 while ((PropSize >= (4 *
sizeof (UINT32))) &&
302 PropSize -= 4 *
sizeof (UINT32);
309 ((Base + Size) >
PcdGet64 (PcdFvBaseAddress)))
316 "NOR%d : Base = 0x%lx, Size = 0x%lx\n",
317 mNorFlashDeviceCount,
322 mNorFlashDevices[mNorFlashDeviceCount].DeviceBaseAddress = (
UINTN)Base;
323 mNorFlashDevices[mNorFlashDeviceCount].RegionBaseAddress = (
UINTN)Base;
324 mNorFlashDevices[mNorFlashDeviceCount].Size = (
UINTN)Size;
326 mNorFlashDeviceCount++;
331 if (mNorFlashDeviceCount > 0) {
332 if (UefiVarStoreIndex == MAX_UINTN) {
335 UefiVarStoreIndex = mNorFlashDeviceCount - 1;
336 mUefiVarStoreNode = Node;
339 if (mNorFlashDevices[UefiVarStoreIndex].DeviceBaseAddress != 0) {
341 if (EFI_ERROR (Status)) {
344 "ERROR: Failed to setup variable store, Status = %r\n",
352 "ERROR: Invalid Flash device Base address\n"
355 Status = EFI_NOT_FOUND;
361 "INFO: No Flash device found fallback to Runtime Variable Emulation.\n"
364 if (EFI_ERROR (Status)) {
367 "ERROR: Failed to set PcdEmuVariableNvModeEnable, Status = %r\n",
UINT64 EFIAPI ReadUnaligned64(IN CONST UINT64 *Buffer)
INTN EFIAPI AsciiStrCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString)
UINT64 EFIAPI SwapBytes64(IN UINT64 Value)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
#define PcdGet64(TokenName)
#define PcdSetBoolS(TokenName, Value)
#define PcdGet32(TokenName)
#define PcdGetBool(TokenName)
#define PcdSet32S(TokenName, Value)