/**@file\r
\r
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
+ Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
-Module Name:\r
+ Module Name:\r
\r
- FWBlockService.c\r
+ FWBlockService.c\r
\r
-Abstract:\r
+ Abstract:\r
\r
-Revision History\r
+ Revision History\r
\r
**/\r
\r
-//\r
-// The package level header files this module uses\r
-//\r
-#include <PiDxe.h>\r
-\r
//\r
// The protocols, PPI and GUID defintions for this module\r
//\r
-#include <Guid/EventGroup.h>\r
-#include <Protocol/FirmwareVolumeBlock.h>\r
#include <Protocol/DevicePath.h>\r
+#include <Protocol/FirmwareVolumeBlock.h>\r
\r
//\r
// The Library classes this module consumes\r
//\r
-#include <Library/UefiLib.h>\r
-#include <Library/UefiDriverEntryPoint.h>\r
#include <Library/BaseLib.h>\r
-#include <Library/DxeServicesTableLib.h>\r
-#include <Library/UefiRuntimeLib.h>\r
-#include <Library/DebugLib.h>\r
#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/DxeServicesTableLib.h>\r
#include <Library/MemoryAllocationLib.h>\r
#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/DevicePathLib.h>\r
\r
#include "FwBlockService.h"\r
#include "QemuFlash.h"\r
\r
-#define EFI_FVB2_STATUS (EFI_FVB2_READ_STATUS | EFI_FVB2_WRITE_STATUS | EFI_FVB2_LOCK_STATUS)\r
+#define EFI_FVB2_STATUS \\r
+ (EFI_FVB2_READ_STATUS | EFI_FVB2_WRITE_STATUS | EFI_FVB2_LOCK_STATUS)\r
\r
ESAL_FWB_GLOBAL *mFvbModuleGlobal;\r
\r
};\r
\r
\r
-\r
-VOID\r
-EFIAPI\r
-FvbVirtualddressChangeEvent (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Fixup internal data so that EFI and SAL can be call in virtual mode.\r
- Call the passed in Child Notify event and convert the mFvbModuleGlobal\r
- date items to there virtual address.\r
-\r
- mFvbModuleGlobal->FvInstance[FVB_PHYSICAL] - Physical copy of instance data\r
- mFvbModuleGlobal->FvInstance[FVB_VIRTUAL] - Virtual pointer to common\r
- instance data.\r
-\r
-Arguments:\r
-\r
- (Standard EFI notify event - EFI_EVENT_NOTIFY)\r
-\r
-Returns:\r
-\r
- None\r
-\r
---*/\r
-{\r
- EFI_FW_VOL_INSTANCE *FwhInstance;\r
- UINTN Index;\r
-\r
- EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal->FvInstance[FVB_VIRTUAL]);\r
-\r
- //\r
- // Convert the base address of all the instances\r
- //\r
- Index = 0;\r
- FwhInstance = mFvbModuleGlobal->FvInstance[FVB_PHYSICAL];\r
- while (Index < mFvbModuleGlobal->NumFv) {\r
- EfiConvertPointer (0x0, (VOID **) &FwhInstance->FvBase[FVB_VIRTUAL]);\r
- FwhInstance = (EFI_FW_VOL_INSTANCE *)\r
- (\r
- (UINTN) ((UINT8 *) FwhInstance) + FwhInstance->VolumeHeader.HeaderLength +\r
- (sizeof (EFI_FW_VOL_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER))\r
- );\r
- Index++;\r
- }\r
-\r
- EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal->FvbScratchSpace[FVB_VIRTUAL]);\r
- EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal);\r
- QemuFlashConvertPointers ();\r
-}\r
-\r
EFI_STATUS\r
GetFvbInstance (\r
IN UINTN Instance,\r
IN ESAL_FWB_GLOBAL *Global,\r
- OUT EFI_FW_VOL_INSTANCE **FwhInstance,\r
- IN BOOLEAN Virtual\r
+ OUT EFI_FW_VOL_INSTANCE **FwhInstance\r
)\r
/*++\r
\r
-Routine Description:\r
- Retrieves the physical address of a memory mapped FV\r
+ Routine Description:\r
+ Retrieves the physical address of a memory mapped FV\r
\r
-Arguments:\r
- Instance - The FV instance whose base address is going to be\r
- returned\r
- Global - Pointer to ESAL_FWB_GLOBAL that contains all\r
- instance data\r
- FwhInstance - The EFI_FW_VOL_INSTANCE fimrware instance structure\r
- Virtual - Whether CPU is in virtual or physical mode\r
+ Arguments:\r
+ Instance - The FV instance whose base address is going to be\r
+ returned\r
+ Global - Pointer to ESAL_FWB_GLOBAL that contains all\r
+ instance data\r
+ FwhInstance - The EFI_FW_VOL_INSTANCE fimrware instance structure\r
\r
-Returns:\r
- EFI_SUCCESS - Successfully returns\r
- EFI_INVALID_PARAMETER - Instance not found\r
+ Returns:\r
+ EFI_SUCCESS - Successfully returns\r
+ EFI_INVALID_PARAMETER - Instance not found\r
\r
--*/\r
{\r
//\r
// Find the right instance of the FVB private data\r
//\r
- FwhRecord = Global->FvInstance[Virtual];\r
+ FwhRecord = Global->FvInstance;\r
while (Instance > 0) {\r
FwhRecord = (EFI_FW_VOL_INSTANCE *)\r
(\r
FvbGetPhysicalAddress (\r
IN UINTN Instance,\r
OUT EFI_PHYSICAL_ADDRESS *Address,\r
- IN ESAL_FWB_GLOBAL *Global,\r
- IN BOOLEAN Virtual\r
+ IN ESAL_FWB_GLOBAL *Global\r
)\r
/*++\r
\r
-Routine Description:\r
- Retrieves the physical address of a memory mapped FV\r
+ Routine Description:\r
+ Retrieves the physical address of a memory mapped FV\r
\r
-Arguments:\r
- Instance - The FV instance whose base address is going to be\r
- returned\r
- Address - Pointer to a caller allocated EFI_PHYSICAL_ADDRESS\r
- that on successful return, contains the base address\r
- of the firmware volume.\r
- Global - Pointer to ESAL_FWB_GLOBAL that contains all\r
- instance data\r
- Virtual - Whether CPU is in virtual or physical mode\r
+ Arguments:\r
+ Instance - The FV instance whose base address is going to be\r
+ returned\r
+ Address - Pointer to a caller allocated EFI_PHYSICAL_ADDRESS\r
+ that on successful return, contains the base\r
+ address of the firmware volume.\r
+ Global - Pointer to ESAL_FWB_GLOBAL that contains all\r
+ instance data\r
\r
-Returns:\r
- EFI_SUCCESS - Successfully returns\r
- EFI_INVALID_PARAMETER - Instance not found\r
+ Returns:\r
+ EFI_SUCCESS - Successfully returns\r
+ EFI_INVALID_PARAMETER - Instance not found\r
\r
--*/\r
{\r
//\r
// Find the right instance of the FVB private data\r
//\r
- Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);\r
+ Status = GetFvbInstance (Instance, Global, &FwhInstance);\r
ASSERT_EFI_ERROR (Status);\r
- *Address = FwhInstance->FvBase[Virtual];\r
+ *Address = FwhInstance->FvBase;\r
\r
return EFI_SUCCESS;\r
}\r
FvbGetVolumeAttributes (\r
IN UINTN Instance,\r
OUT EFI_FVB_ATTRIBUTES_2 *Attributes,\r
- IN ESAL_FWB_GLOBAL *Global,\r
- IN BOOLEAN Virtual\r
+ IN ESAL_FWB_GLOBAL *Global\r
)\r
/*++\r
\r
-Routine Description:\r
- Retrieves attributes, insures positive polarity of attribute bits, returns\r
- resulting attributes in output parameter\r
+ Routine Description:\r
+ Retrieves attributes, insures positive polarity of attribute bits, returns\r
+ resulting attributes in output parameter\r
\r
-Arguments:\r
- Instance - The FV instance whose attributes is going to be\r
- returned\r
- Attributes - Output buffer which contains attributes\r
- Global - Pointer to ESAL_FWB_GLOBAL that contains all\r
- instance data\r
- Virtual - Whether CPU is in virtual or physical mode\r
+ Arguments:\r
+ Instance - The FV instance whose attributes is going to be\r
+ returned\r
+ Attributes - Output buffer which contains attributes\r
+ Global - Pointer to ESAL_FWB_GLOBAL that contains all\r
+ instance data\r
\r
-Returns:\r
- EFI_SUCCESS - Successfully returns\r
- EFI_INVALID_PARAMETER - Instance not found\r
+ Returns:\r
+ EFI_SUCCESS - Successfully returns\r
+ EFI_INVALID_PARAMETER - Instance not found\r
\r
--*/\r
{\r
//\r
// Find the right instance of the FVB private data\r
//\r
- Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);\r
+ Status = GetFvbInstance (Instance, Global, &FwhInstance);\r
ASSERT_EFI_ERROR (Status);\r
*Attributes = FwhInstance->VolumeHeader.Attributes;\r
\r
OUT UINTN *LbaAddress,\r
OUT UINTN *LbaLength,\r
OUT UINTN *NumOfBlocks,\r
- IN ESAL_FWB_GLOBAL *Global,\r
- IN BOOLEAN Virtual\r
+ IN ESAL_FWB_GLOBAL *Global\r
)\r
/*++\r
\r
-Routine Description:\r
- Retrieves the starting address of an LBA in an FV\r
-\r
-Arguments:\r
- Instance - The FV instance which the Lba belongs to\r
- Lba - The logical block address\r
- LbaAddress - On output, contains the physical starting address\r
- of the Lba\r
- LbaLength - On output, contains the length of the block\r
- NumOfBlocks - A pointer to a caller allocated UINTN in which the\r
- number of consecutive blocks starting with Lba is\r
- returned. All blocks in this range have a size of\r
- BlockSize\r
- Global - Pointer to ESAL_FWB_GLOBAL that contains all\r
- instance data\r
- Virtual - Whether CPU is in virtual or physical mode\r
-\r
-Returns:\r
- EFI_SUCCESS - Successfully returns\r
- EFI_INVALID_PARAMETER - Instance not found\r
+ Routine Description:\r
+ Retrieves the starting address of an LBA in an FV\r
+\r
+ Arguments:\r
+ Instance - The FV instance which the Lba belongs to\r
+ Lba - The logical block address\r
+ LbaAddress - On output, contains the physical starting address\r
+ of the Lba\r
+ LbaLength - On output, contains the length of the block\r
+ NumOfBlocks - A pointer to a caller allocated UINTN in which the\r
+ number of consecutive blocks starting with Lba is\r
+ returned. All blocks in this range have a size of\r
+ BlockSize\r
+ Global - Pointer to ESAL_FWB_GLOBAL that contains all\r
+ instance data\r
+\r
+ Returns:\r
+ EFI_SUCCESS - Successfully returns\r
+ EFI_INVALID_PARAMETER - Instance not found\r
\r
--*/\r
{\r
//\r
// Find the right instance of the FVB private data\r
//\r
- Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);\r
+ Status = GetFvbInstance (Instance, Global, &FwhInstance);\r
ASSERT_EFI_ERROR (Status);\r
\r
StartLba = 0;\r
if (Lba >= StartLba && Lba < NextLba) {\r
Offset = Offset + (UINTN) MultU64x32 ((Lba - StartLba), BlockLength);\r
if (LbaAddress != NULL) {\r
- *LbaAddress = FwhInstance->FvBase[Virtual] + Offset;\r
+ *LbaAddress = FwhInstance->FvBase + Offset;\r
}\r
\r
if (LbaLength != NULL) {\r
FvbSetVolumeAttributes (\r
IN UINTN Instance,\r
IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes,\r
- IN ESAL_FWB_GLOBAL *Global,\r
- IN BOOLEAN Virtual\r
+ IN ESAL_FWB_GLOBAL *Global\r
)\r
/*++\r
\r
-Routine Description:\r
- Modifies the current settings of the firmware volume according to the\r
- input parameter, and returns the new setting of the volume\r
-\r
-Arguments:\r
- Instance - The FV instance whose attributes is going to be\r
- modified\r
- Attributes - On input, it is a pointer to EFI_FVB_ATTRIBUTES_2\r
- containing the desired firmware volume settings.\r
- On successful return, it contains the new settings\r
- of the firmware volume\r
- Global - Pointer to ESAL_FWB_GLOBAL that contains all\r
- instance data\r
- Virtual - Whether CPU is in virtual or physical mode\r
-\r
-Returns:\r
- EFI_SUCCESS - Successfully returns\r
- EFI_ACCESS_DENIED - The volume setting is locked and cannot be modified\r
- EFI_INVALID_PARAMETER - Instance not found, or The attributes requested are\r
- in conflict with the capabilities as declared in the\r
- firmware volume header\r
+ Routine Description:\r
+ Modifies the current settings of the firmware volume according to the\r
+ input parameter, and returns the new setting of the volume\r
+\r
+ Arguments:\r
+ Instance - The FV instance whose attributes is going to be\r
+ modified\r
+ Attributes - On input, it is a pointer to EFI_FVB_ATTRIBUTES_2\r
+ containing the desired firmware volume settings.\r
+ On successful return, it contains the new settings\r
+ of the firmware volume\r
+ Global - Pointer to ESAL_FWB_GLOBAL that contains all\r
+ instance data\r
+\r
+ Returns:\r
+ EFI_SUCCESS - Successfully returns\r
+ EFI_ACCESS_DENIED - The volume setting is locked and cannot be modified\r
+ EFI_INVALID_PARAMETER - Instance not found, or The attributes requested are\r
+ in conflict with the capabilities as declared in\r
+ the firmware volume header\r
\r
--*/\r
{\r
//\r
// Find the right instance of the FVB private data\r
//\r
- Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);\r
+ Status = GetFvbInstance (Instance, Global, &FwhInstance);\r
ASSERT_EFI_ERROR (Status);\r
\r
- AttribPtr = (EFI_FVB_ATTRIBUTES_2 *) &(FwhInstance->VolumeHeader.Attributes);\r
+ AttribPtr =\r
+ (EFI_FVB_ATTRIBUTES_2 *) &(FwhInstance->VolumeHeader.Attributes);\r
OldAttributes = *AttribPtr;\r
Capabilities = OldAttributes & (EFI_FVB2_READ_DISABLED_CAP | \\r
EFI_FVB2_READ_ENABLED_CAP | \\r
//\r
// Some attributes of FV is read only can *not* be set\r
//\r
- if ((OldAttributes & UnchangedAttributes) ^ (*Attributes & UnchangedAttributes)) {\r
+ if ((OldAttributes & UnchangedAttributes) ^\r
+ (*Attributes & UnchangedAttributes)) {\r
return EFI_INVALID_PARAMETER;\r
}\r
//\r
)\r
/*++\r
\r
-Routine Description:\r
-\r
- Retrieves the physical address of the device.\r
+ Routine Description:\r
\r
-Arguments:\r
+ Retrieves the physical address of the device.\r
\r
- This - Calling context\r
- Address - Output buffer containing the address.\r
+ Arguments:\r
\r
-Returns:\r
+ This - Calling context\r
+ Address - Output buffer containing the address.\r
\r
-Returns:\r
- EFI_SUCCESS - Successfully returns\r
+ Returns:\r
+ EFI_SUCCESS - Successfully returns\r
\r
--*/\r
{\r
\r
FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
\r
- return FvbGetPhysicalAddress (FvbDevice->Instance, Address, mFvbModuleGlobal, EfiGoneVirtual ());\r
+ return FvbGetPhysicalAddress (FvbDevice->Instance, Address,\r
+ mFvbModuleGlobal);\r
}\r
\r
EFI_STATUS\r
)\r
/*++\r
\r
-Routine Description:\r
- Retrieve the size of a logical block\r
+ Routine Description:\r
+ Retrieve the size of a logical block\r
\r
-Arguments:\r
- This - Calling context\r
- Lba - Indicates which block to return the size for.\r
- BlockSize - A pointer to a caller allocated UINTN in which\r
- the size of the block is returned\r
- NumOfBlocks - a pointer to a caller allocated UINTN in which the\r
- number of consecutive blocks starting with Lba is\r
- returned. All blocks in this range have a size of\r
- BlockSize\r
+ Arguments:\r
+ This - Calling context\r
+ Lba - Indicates which block to return the size for.\r
+ BlockSize - A pointer to a caller allocated UINTN in which\r
+ the size of the block is returned\r
+ NumOfBlocks - a pointer to a caller allocated UINTN in which the\r
+ number of consecutive blocks starting with Lba is\r
+ returned. All blocks in this range have a size of\r
+ BlockSize\r
\r
-Returns:\r
- EFI_SUCCESS - The firmware volume was read successfully and\r
- contents are in Buffer\r
+ Returns:\r
+ EFI_SUCCESS - The firmware volume was read successfully and\r
+ contents are in Buffer\r
\r
--*/\r
{\r
NULL,\r
BlockSize,\r
NumOfBlocks,\r
- mFvbModuleGlobal,\r
- EfiGoneVirtual ()\r
+ mFvbModuleGlobal\r
);\r
}\r
\r
)\r
/*++\r
\r
-Routine Description:\r
- Retrieves Volume attributes. No polarity translations are done.\r
+ Routine Description:\r
+ Retrieves Volume attributes. No polarity translations are done.\r
\r
-Arguments:\r
- This - Calling context\r
- Attributes - output buffer which contains attributes\r
+ Arguments:\r
+ This - Calling context\r
+ Attributes - output buffer which contains attributes\r
\r
-Returns:\r
- EFI_SUCCESS - Successfully returns\r
+ Returns:\r
+ EFI_SUCCESS - Successfully returns\r
\r
--*/\r
{\r
\r
FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
\r
- return FvbGetVolumeAttributes (FvbDevice->Instance, Attributes, mFvbModuleGlobal, EfiGoneVirtual ());\r
+ return FvbGetVolumeAttributes (FvbDevice->Instance, Attributes,\r
+ mFvbModuleGlobal);\r
}\r
\r
EFI_STATUS\r
)\r
/*++\r
\r
-Routine Description:\r
- Sets Volume attributes. No polarity translations are done.\r
+ Routine Description:\r
+ Sets Volume attributes. No polarity translations are done.\r
\r
-Arguments:\r
- This - Calling context\r
- Attributes - output buffer which contains attributes\r
+ Arguments:\r
+ This - Calling context\r
+ Attributes - output buffer which contains attributes\r
\r
-Returns:\r
- EFI_SUCCESS - Successfully returns\r
+ Returns:\r
+ EFI_SUCCESS - Successfully returns\r
\r
--*/\r
{\r
\r
FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
\r
- return FvbSetVolumeAttributes (FvbDevice->Instance, Attributes, mFvbModuleGlobal, EfiGoneVirtual ());\r
+ return FvbSetVolumeAttributes (FvbDevice->Instance, Attributes,\r
+ mFvbModuleGlobal);\r
}\r
\r
EFI_STATUS\r
)\r
/*++\r
\r
-Routine Description:\r
+ Routine Description:\r
\r
- The EraseBlock() function erases one or more blocks as denoted by the\r
- variable argument list. The entire parameter list of blocks must be verified\r
- prior to erasing any blocks. If a block is requested that does not exist\r
- within the associated firmware volume (it has a larger index than the last\r
- block of the firmware volume), the EraseBlock() function must return\r
- EFI_INVALID_PARAMETER without modifying the contents of the firmware volume.\r
+ The EraseBlock() function erases one or more blocks as denoted by the\r
+ variable argument list. The entire parameter list of blocks must be\r
+ verified prior to erasing any blocks. If a block is requested that does\r
+ not exist within the associated firmware volume (it has a larger index than\r
+ the last block of the firmware volume), the EraseBlock() function must\r
+ return EFI_INVALID_PARAMETER without modifying the contents of the firmware\r
+ volume.\r
\r
-Arguments:\r
- This - Calling context\r
- ... - Starting LBA followed by Number of Lba to erase.\r
- a -1 to terminate the list.\r
+ Arguments:\r
+ This - Calling context\r
+ ... - Starting LBA followed by Number of Lba to erase.\r
+ a -1 to terminate the list.\r
\r
-Returns:\r
- EFI_SUCCESS - The erase request was successfully completed\r
- EFI_ACCESS_DENIED - The firmware volume is in the WriteDisabled state\r
- EFI_DEVICE_ERROR - The block device is not functioning correctly and\r
- could not be written. Firmware device may have been\r
- partially erased\r
+ Returns:\r
+ EFI_SUCCESS - The erase request was successfully completed\r
+ EFI_ACCESS_DENIED - The firmware volume is in the WriteDisabled state\r
+ EFI_DEVICE_ERROR - The block device is not functioning correctly and\r
+ could not be written. Firmware device may have been\r
+ partially erased\r
\r
--*/\r
{\r
\r
FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
\r
- Status = GetFvbInstance (FvbDevice->Instance, mFvbModuleGlobal, &FwhInstance, EfiGoneVirtual ());\r
+ Status = GetFvbInstance (FvbDevice->Instance, mFvbModuleGlobal,\r
+ &FwhInstance);\r
ASSERT_EFI_ERROR (Status);\r
\r
NumOfBlocks = FwhInstance->NumOfBlocks;\r
break;\r
}\r
\r
- NumOfLba = VA_ARG (args, UINT32);\r
+ NumOfLba = VA_ARG (args, UINTN);\r
\r
//\r
// Check input parameters\r
break;\r
}\r
\r
- NumOfLba = VA_ARG (args, UINT32);\r
+ NumOfLba = VA_ARG (args, UINTN);\r
\r
while (NumOfLba > 0) {\r
Status = QemuFlashEraseBlock (StartingLba);\r
)\r
/*++\r
\r
-Routine Description:\r
-\r
- Writes data beginning at Lba:Offset from FV. The write terminates either\r
- when *NumBytes of data have been written, or when a block boundary is\r
- reached. *NumBytes is updated to reflect the actual number of bytes\r
- written. The write opertion does not include erase. This routine will\r
- attempt to write only the specified bytes. If the writes do not stick,\r
- it will return an error.\r
-\r
-Arguments:\r
- This - Calling context\r
- Lba - Block in which to begin write\r
- Offset - Offset in the block at which to begin write\r
- NumBytes - On input, indicates the requested write size. On\r
- output, indicates the actual number of bytes written\r
- Buffer - Buffer containing source data for the write.\r
-\r
-Returns:\r
- EFI_SUCCESS - The firmware volume was written successfully\r
- EFI_BAD_BUFFER_SIZE - Write attempted across a LBA boundary. On output,\r
- NumBytes contains the total number of bytes\r
- actually written\r
- EFI_ACCESS_DENIED - The firmware volume is in the WriteDisabled state\r
- EFI_DEVICE_ERROR - The block device is not functioning correctly and\r
- could not be written\r
- EFI_INVALID_PARAMETER - NumBytes or Buffer are NULL\r
+ Routine Description:\r
+\r
+ Writes data beginning at Lba:Offset from FV. The write terminates either\r
+ when *NumBytes of data have been written, or when a block boundary is\r
+ reached. *NumBytes is updated to reflect the actual number of bytes\r
+ written. The write opertion does not include erase. This routine will\r
+ attempt to write only the specified bytes. If the writes do not stick,\r
+ it will return an error.\r
+\r
+ Arguments:\r
+ This - Calling context\r
+ Lba - Block in which to begin write\r
+ Offset - Offset in the block at which to begin write\r
+ NumBytes - On input, indicates the requested write size. On\r
+ output, indicates the actual number of bytes\r
+ written\r
+ Buffer - Buffer containing source data for the write.\r
+\r
+ Returns:\r
+ EFI_SUCCESS - The firmware volume was written successfully\r
+ EFI_BAD_BUFFER_SIZE - Write attempted across a LBA boundary. On output,\r
+ NumBytes contains the total number of bytes\r
+ actually written\r
+ EFI_ACCESS_DENIED - The firmware volume is in the WriteDisabled state\r
+ EFI_DEVICE_ERROR - The block device is not functioning correctly and\r
+ could not be written\r
+ EFI_INVALID_PARAMETER - NumBytes or Buffer are NULL\r
\r
--*/\r
{\r
- return QemuFlashWrite ((EFI_LBA)Lba, (UINTN)Offset, NumBytes, (UINT8 *)Buffer);\r
+ return QemuFlashWrite ((EFI_LBA)Lba, (UINTN)Offset, NumBytes,\r
+ (UINT8 *)Buffer);\r
}\r
\r
EFI_STATUS\r
)\r
/*++\r
\r
-Routine Description:\r
-\r
- Reads data beginning at Lba:Offset from FV. The Read terminates either\r
- when *NumBytes of data have been read, or when a block boundary is\r
- reached. *NumBytes is updated to reflect the actual number of bytes\r
- written. The write opertion does not include erase. This routine will\r
- attempt to write only the specified bytes. If the writes do not stick,\r
- it will return an error.\r
-\r
-Arguments:\r
- This - Calling context\r
- Lba - Block in which to begin Read\r
- Offset - Offset in the block at which to begin Read\r
- NumBytes - On input, indicates the requested write size. On\r
- output, indicates the actual number of bytes Read\r
- Buffer - Buffer containing source data for the Read.\r
-\r
-Returns:\r
- EFI_SUCCESS - The firmware volume was read successfully and\r
- contents are in Buffer\r
- EFI_BAD_BUFFER_SIZE - Read attempted across a LBA boundary. On output,\r
- NumBytes contains the total number of bytes returned\r
- in Buffer\r
- EFI_ACCESS_DENIED - The firmware volume is in the ReadDisabled state\r
- EFI_DEVICE_ERROR - The block device is not functioning correctly and\r
- could not be read\r
- EFI_INVALID_PARAMETER - NumBytes or Buffer are NULL\r
+ Routine Description:\r
+\r
+ Reads data beginning at Lba:Offset from FV. The Read terminates either\r
+ when *NumBytes of data have been read, or when a block boundary is\r
+ reached. *NumBytes is updated to reflect the actual number of bytes\r
+ written. The write opertion does not include erase. This routine will\r
+ attempt to write only the specified bytes. If the writes do not stick,\r
+ it will return an error.\r
+\r
+ Arguments:\r
+ This - Calling context\r
+ Lba - Block in which to begin Read\r
+ Offset - Offset in the block at which to begin Read\r
+ NumBytes - On input, indicates the requested write size. On\r
+ output, indicates the actual number of bytes Read\r
+ Buffer - Buffer containing source data for the Read.\r
+\r
+ Returns:\r
+ EFI_SUCCESS - The firmware volume was read successfully and\r
+ contents are in Buffer\r
+ EFI_BAD_BUFFER_SIZE - Read attempted across a LBA boundary. On output,\r
+ NumBytes contains the total number of bytes\r
+ returned in Buffer\r
+ EFI_ACCESS_DENIED - The firmware volume is in the ReadDisabled state\r
+ EFI_DEVICE_ERROR - The block device is not functioning correctly and\r
+ could not be read\r
+ EFI_INVALID_PARAMETER - NumBytes or Buffer are NULL\r
\r
--*/\r
{\r
- return QemuFlashRead ((EFI_LBA)Lba, (UINTN)Offset, NumBytes, (UINT8 *)Buffer);\r
+ return QemuFlashRead ((EFI_LBA)Lba, (UINTN)Offset, NumBytes,\r
+ (UINT8 *)Buffer);\r
}\r
\r
EFI_STATUS\r
)\r
/*++\r
\r
-Routine Description:\r
- Check the integrity of firmware volume header\r
+ Routine Description:\r
+ Check the integrity of firmware volume header\r
\r
-Arguments:\r
- FwVolHeader - A pointer to a firmware volume header\r
+ Arguments:\r
+ FwVolHeader - A pointer to a firmware volume header\r
\r
-Returns:\r
- EFI_SUCCESS - The firmware volume is consistent\r
- EFI_NOT_FOUND - The firmware volume has corrupted. So it is not an FV\r
+ Returns:\r
+ EFI_SUCCESS - The firmware volume is consistent\r
+ EFI_NOT_FOUND - The firmware volume has corrupted. So it is not an\r
+ FV\r
\r
--*/\r
{\r
// Verify the header checksum\r
//\r
\r
- Checksum = CalculateSum16 ((UINT16 *) FwVolHeader, FwVolHeader->HeaderLength);\r
+ Checksum = CalculateSum16 ((UINT16 *) FwVolHeader,\r
+ FwVolHeader->HeaderLength);\r
if (Checksum != 0) {\r
UINT16 Expected;\r
\r
return EFI_SUCCESS;\r
}\r
\r
-STATIC\r
-EFI_STATUS\r
-MarkMemoryRangeForRuntimeAccess (\r
- EFI_PHYSICAL_ADDRESS BaseAddress,\r
- UINTN Length\r
- )\r
-{\r
- EFI_STATUS Status;\r
-\r
- //\r
- // Mark flash region as runtime memory\r
- //\r
- Status = gDS->RemoveMemorySpace (\r
- BaseAddress,\r
- Length\r
- );\r
-\r
- Status = gDS->AddMemorySpace (\r
- EfiGcdMemoryTypeSystemMemory,\r
- BaseAddress,\r
- Length,\r
- EFI_MEMORY_UC | EFI_MEMORY_RUNTIME\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- Status = gBS->AllocatePages (\r
- AllocateAddress,\r
- EfiRuntimeServicesData,\r
- EFI_SIZE_TO_PAGES (Length),\r
- &BaseAddress\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- return Status;\r
-}\r
-\r
STATIC\r
EFI_STATUS\r
InitializeVariableFvHeader (\r
UINTN Offset;\r
UINTN Start;\r
\r
- DEBUG ((EFI_D_INFO, "Variable FV header is not valid. It will be reinitialized.\n"));\r
+ DEBUG ((EFI_D_INFO,\r
+ "Variable FV header is not valid. It will be reinitialized.\n"));\r
\r
//\r
// Get FvbInfo to provide in FwhInstance.\r
)\r
/*++\r
\r
-Routine Description:\r
- This function does common initialization for FVB services\r
+ Routine Description:\r
+ This function does common initialization for FVB services\r
\r
-Arguments:\r
+ Arguments:\r
\r
-Returns:\r
+ Returns:\r
\r
--*/\r
{\r
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
UINT32 BufferSize;\r
EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;\r
- EFI_HANDLE FwbHandle;\r
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
- EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *OldFwbInterface;\r
UINT32 MaxLbaSize;\r
EFI_PHYSICAL_ADDRESS BaseAddress;\r
UINTN Length;\r
UINTN NumOfBlocks;\r
- EFI_EVENT VirtualAddressChangeEvent;\r
+ RETURN_STATUS PcdStatus;\r
\r
if (EFI_ERROR (QemuFlashInitialize ())) {\r
//\r
// Return an error so image will be unloaded\r
//\r
- DEBUG ((EFI_D_INFO, "QEMU flash was not detected. Writable FVB is not being installed.\n"));\r
+ DEBUG ((EFI_D_INFO,\r
+ "QEMU flash was not detected. Writable FVB is not being installed.\n"));\r
return EFI_WRITE_PROTECTED;\r
}\r
\r
\r
Status = InitializeVariableFvHeader ();\r
if (EFI_ERROR (Status)) {\r
- DEBUG ((EFI_D_INFO, "QEMU Flash: Unable to initialize variable FV header\n"));\r
+ DEBUG ((EFI_D_INFO,\r
+ "QEMU Flash: Unable to initialize variable FV header\n"));\r
return EFI_WRITE_PROTECTED;\r
}\r
\r
}\r
}\r
\r
- BufferSize = (sizeof (EFI_FW_VOL_INSTANCE) + FwVolHeader->HeaderLength - sizeof (EFI_FIRMWARE_VOLUME_HEADER));\r
+ BufferSize = (sizeof (EFI_FW_VOL_INSTANCE) +\r
+ FwVolHeader->HeaderLength -\r
+ sizeof (EFI_FIRMWARE_VOLUME_HEADER)\r
+ );\r
+ mFvbModuleGlobal->FvInstance = AllocateRuntimePool (BufferSize);\r
+ ASSERT (mFvbModuleGlobal->FvInstance != NULL);\r
\r
- //\r
- // Only need to allocate once. There is only one copy of physical memory for\r
- // the private data of each FV instance. But in virtual mode or in physical\r
- // mode, the address of the the physical memory may be different.\r
- //\r
- mFvbModuleGlobal->FvInstance[FVB_PHYSICAL] = AllocateRuntimePool (BufferSize);\r
- ASSERT (mFvbModuleGlobal->FvInstance[FVB_PHYSICAL] != NULL);\r
-\r
- //\r
- // Make a virtual copy of the FvInstance pointer.\r
- //\r
- FwhInstance = mFvbModuleGlobal->FvInstance[FVB_PHYSICAL];\r
- mFvbModuleGlobal->FvInstance[FVB_VIRTUAL] = FwhInstance;\r
+ FwhInstance = mFvbModuleGlobal->FvInstance;\r
\r
mFvbModuleGlobal->NumFv = 0;\r
MaxLbaSize = 0;\r
(EFI_FIRMWARE_VOLUME_HEADER *) (UINTN)\r
PcdGet32 (PcdOvmfFlashNvStorageVariableBase);\r
\r
- FwhInstance->FvBase[FVB_PHYSICAL] = (UINTN) BaseAddress;\r
- FwhInstance->FvBase[FVB_VIRTUAL] = (UINTN) BaseAddress;\r
+ FwhInstance->FvBase = (UINTN) BaseAddress;\r
\r
- CopyMem ((UINTN *) &(FwhInstance->VolumeHeader), (UINTN *) FwVolHeader, FwVolHeader->HeaderLength);\r
+ CopyMem ((UINTN *) &(FwhInstance->VolumeHeader), (UINTN *) FwVolHeader,\r
+ FwVolHeader->HeaderLength);\r
FwVolHeader = &(FwhInstance->VolumeHeader);\r
- EfiInitializeLock (&(FwhInstance->FvbDevLock), TPL_HIGH_LEVEL);\r
\r
NumOfBlocks = 0;\r
\r
- for (PtrBlockMapEntry = FwVolHeader->BlockMap; PtrBlockMapEntry->NumBlocks != 0; PtrBlockMapEntry++) {\r
+ for (PtrBlockMapEntry = FwVolHeader->BlockMap;\r
+ PtrBlockMapEntry->NumBlocks != 0;\r
+ PtrBlockMapEntry++) {\r
//\r
// Get the maximum size of a block.\r
//\r
// Set up the devicepath\r
//\r
if (FwVolHeader->ExtHeaderOffset == 0) {\r
+ FV_MEMMAP_DEVICE_PATH *FvMemmapDevicePath;\r
+\r
//\r
// FV does not contains extension header, then produce MEMMAP_DEVICE_PATH\r
//\r
- FvbDevice->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateCopyPool (sizeof (FV_MEMMAP_DEVICE_PATH), &mFvMemmapDevicePathTemplate);\r
- ((FV_MEMMAP_DEVICE_PATH *) FvbDevice->DevicePath)->MemMapDevPath.StartingAddress = BaseAddress;\r
- ((FV_MEMMAP_DEVICE_PATH *) FvbDevice->DevicePath)->MemMapDevPath.EndingAddress = BaseAddress + FwVolHeader->FvLength - 1;\r
+ FvMemmapDevicePath = AllocateCopyPool (sizeof (FV_MEMMAP_DEVICE_PATH),\r
+ &mFvMemmapDevicePathTemplate);\r
+ FvMemmapDevicePath->MemMapDevPath.StartingAddress = BaseAddress;\r
+ FvMemmapDevicePath->MemMapDevPath.EndingAddress =\r
+ BaseAddress + FwVolHeader->FvLength - 1;\r
+ FvbDevice->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)FvMemmapDevicePath;\r
} else {\r
- FvbDevice->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateCopyPool (sizeof (FV_PIWG_DEVICE_PATH), &mFvPIWGDevicePathTemplate);\r
+ FV_PIWG_DEVICE_PATH *FvPiwgDevicePath;\r
+\r
+ FvPiwgDevicePath = AllocateCopyPool (sizeof (FV_PIWG_DEVICE_PATH),\r
+ &mFvPIWGDevicePathTemplate);\r
CopyGuid (\r
- &((FV_PIWG_DEVICE_PATH *)FvbDevice->DevicePath)->FvDevPath.FvName,\r
+ &FvPiwgDevicePath->FvDevPath.FvName,\r
(GUID *)(UINTN)(BaseAddress + FwVolHeader->ExtHeaderOffset)\r
);\r
+ FvbDevice->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)FvPiwgDevicePath;\r
}\r
\r
//\r
- // Find a handle with a matching device path that has supports FW Block protocol\r
+ // Module type specific hook.\r
//\r
- Status = gBS->LocateDevicePath (&gEfiFirmwareVolumeBlockProtocolGuid, &FvbDevice->DevicePath, &FwbHandle);\r
- if (EFI_ERROR (Status)) {\r
- //\r
- // LocateDevicePath fails so install a new interface and device path\r
- //\r
- FwbHandle = NULL;\r
- DEBUG ((EFI_D_INFO, "Installing QEMU flash FVB\n"));\r
- Status = gBS->InstallMultipleProtocolInterfaces (\r
- &FwbHandle,\r
- &gEfiFirmwareVolumeBlockProtocolGuid,\r
- &FvbDevice->FwVolBlockInstance,\r
- &gEfiDevicePathProtocolGuid,\r
- FvbDevice->DevicePath,\r
- NULL\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
- } else if (IsDevicePathEnd (FvbDevice->DevicePath)) {\r
- //\r
- // Device already exists, so reinstall the FVB protocol\r
- //\r
- Status = gBS->HandleProtocol (\r
- FwbHandle,\r
- &gEfiFirmwareVolumeBlockProtocolGuid,\r
- (VOID**)&OldFwbInterface\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
+ InstallProtocolInterfaces (FvbDevice);\r
\r
- DEBUG ((EFI_D_INFO, "Reinstalling FVB for QEMU flash region\n"));\r
- Status = gBS->ReinstallProtocolInterface (\r
- FwbHandle,\r
- &gEfiFirmwareVolumeBlockProtocolGuid,\r
- OldFwbInterface,\r
- &FvbDevice->FwVolBlockInstance\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
- } else {\r
- //\r
- // There was a FVB protocol on an End Device Path node\r
- //\r
- ASSERT (FALSE);\r
- }\r
-\r
- MarkMemoryRangeForRuntimeAccess (BaseAddress, Length);\r
+ MarkIoMemoryRangeForRuntimeAccess (BaseAddress, Length);\r
\r
//\r
// Set several PCD values to point to flash\r
//\r
- PcdSet64 (\r
+ PcdStatus = PcdSet64S (\r
PcdFlashNvStorageVariableBase64,\r
(UINTN) PcdGet32 (PcdOvmfFlashNvStorageVariableBase)\r
);\r
- PcdSet32 (\r
+ ASSERT_RETURN_ERROR (PcdStatus);\r
+ PcdStatus = PcdSet32S (\r
PcdFlashNvStorageFtwWorkingBase,\r
PcdGet32 (PcdOvmfFlashNvStorageFtwWorkingBase)\r
);\r
- PcdSet32 (\r
+ ASSERT_RETURN_ERROR (PcdStatus);\r
+ PcdStatus = PcdSet32S (\r
PcdFlashNvStorageFtwSpareBase,\r
PcdGet32 (PcdOvmfFlashNvStorageFtwSpareBase)\r
);\r
+ ASSERT_RETURN_ERROR (PcdStatus);\r
\r
FwhInstance = (EFI_FW_VOL_INSTANCE *)\r
(\r
(sizeof (EFI_FW_VOL_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER))\r
);\r
\r
- VirtualAddressChangeEvent = NULL;\r
- Status = gBS->CreateEventEx (\r
- EVT_NOTIFY_SIGNAL,\r
- TPL_NOTIFY,\r
- FvbVirtualddressChangeEvent,\r
- NULL,\r
- &gEfiEventVirtualAddressChangeGuid,\r
- &VirtualAddressChangeEvent\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
+ //\r
+ // Module type specific hook.\r
+ //\r
+ InstallVirtualAddressChangeHandler ();\r
\r
- PcdSetBool (PcdOvmfFlashVariablesEnable, TRUE);\r
+ PcdStatus = PcdSetBoolS (PcdOvmfFlashVariablesEnable, TRUE);\r
+ ASSERT_RETURN_ERROR (PcdStatus);\r
return EFI_SUCCESS;\r
}\r