diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.c index 714b5d8..2918d58 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.c +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.c @@ -39,7 +39,10 @@ FtwGetMaxBlockSize ( { EFI_FTW_DEVICE *FtwDevice; + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); + if (!FeaturePcdGet(PcdFullFtwServiceEnable)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 1\n", __FUNCTION__)); return EFI_UNSUPPORTED; } @@ -47,6 +50,8 @@ FtwGetMaxBlockSize ( *BlockSize = FtwDevice->SpareAreaLength; + DEBUG ((DEBUG_VERBOSE, "%a: exit 2, BlockSize=0x%Lx\n", __FUNCTION__, + (UINT64) *BlockSize)); return EFI_SUCCESS; } @@ -86,10 +91,15 @@ FtwAllocate ( EFI_FTW_DEVICE *FtwDevice; EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader; + DEBUG ((DEBUG_VERBOSE, "%a: enter, CallerId=%g, PrivateDataSize=0x%Lx, " + "NumberOfWrites=0x%Lx\n", __FUNCTION__, CallerId, (UINT64)PrivateDataSize, + (UINT64)NumberOfWrites)); + FtwDevice = FTW_CONTEXT_FROM_THIS (This); Status = WorkSpaceRefresh (FtwDevice); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 1: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } // @@ -97,6 +107,7 @@ FtwAllocate ( // if (FTW_WRITE_TOTAL_SIZE (NumberOfWrites, PrivateDataSize) > FtwDevice->FtwWorkSpaceHeader->WriteQueueSize) { DEBUG ((EFI_D_ERROR, "Ftw: Allocate() request exceed Workspace, Caller: %g\n", CallerId)); + DEBUG ((DEBUG_VERBOSE, "%a: exit 2\n", __FUNCTION__)); return EFI_BUFFER_TOO_SMALL; } // @@ -109,6 +120,7 @@ FtwAllocate ( // Previous write has not completed, access denied. // if ((FtwHeader->HeaderAllocated == FTW_VALID_STATE) || (FtwHeader->WritesAllocated == FTW_VALID_STATE)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 3\n", __FUNCTION__)); return EFI_ACCESS_DENIED; } // @@ -118,6 +130,7 @@ FtwAllocate ( if (Offset + FTW_WRITE_TOTAL_SIZE (NumberOfWrites, PrivateDataSize) > FtwDevice->FtwWorkSpaceSize) { Status = FtwReclaimWorkSpace (FtwDevice, TRUE); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 4: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } @@ -143,6 +156,7 @@ FtwAllocate ( (UINT8 *) FtwHeader ); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 5: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } // @@ -155,6 +169,7 @@ FtwAllocate ( WRITES_ALLOCATED ); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 6: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } @@ -165,6 +180,7 @@ FtwAllocate ( NumberOfWrites) ); + DEBUG ((DEBUG_VERBOSE, "%a: exit 7\n", __FUNCTION__)); return EFI_SUCCESS; } @@ -195,6 +211,8 @@ FtwWriteRecord ( UINTN Offset; EFI_LBA WorkSpaceLbaOffset; + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); + FtwDevice = FTW_CONTEXT_FROM_THIS (This); WorkSpaceLbaOffset = FtwDevice->FtwWorkSpaceLba - FtwDevice->FtwWorkBlockLba; @@ -223,6 +241,7 @@ FtwWriteRecord ( SPARE_COMPLETED ); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 1: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } @@ -240,6 +259,7 @@ FtwWriteRecord ( } if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 2: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } // @@ -253,6 +273,7 @@ FtwWriteRecord ( DEST_COMPLETED ); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 3: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } @@ -272,10 +293,12 @@ FtwWriteRecord ( ); Header->Complete = FTW_VALID_STATE; if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 4: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } } + DEBUG ((DEBUG_VERBOSE, "%a: exit 5\n", __FUNCTION__)); return EFI_SUCCESS; } @@ -331,10 +354,15 @@ FtwWrite ( UINT8 *Ptr; EFI_PHYSICAL_ADDRESS FvbPhysicalAddress; + DEBUG ((DEBUG_VERBOSE, "%a: enter, Lba=0x%Lx Offset=0x%Lx Length=0x%Lx " + "PrivateData=%p FvBlockHandle=%p Buffer=%p\n", __FUNCTION__, (UINT64)Lba, + (UINT64)Offset, (UINT64)Length, PrivateData, FvBlockHandle, Buffer)); + FtwDevice = FTW_CONTEXT_FROM_THIS (This); Status = WorkSpaceRefresh (FtwDevice); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 1: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } @@ -349,6 +377,7 @@ FtwWrite ( // Status = FtwAllocate (This, &gEfiCallerIdGuid, 0, 1); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 2: %r\n", __FUNCTION__, Status)); return Status; } } else { @@ -358,6 +387,7 @@ FtwWrite ( // DEBUG ((EFI_D_ERROR, "Ftw: no allocates space for write record!\n")); DEBUG ((EFI_D_ERROR, "Ftw: Allocate service should be called before Write service!\n")); + DEBUG ((DEBUG_VERBOSE, "%a: exit 3\n", __FUNCTION__)); return EFI_NOT_READY; } } @@ -366,6 +396,7 @@ FtwWrite ( // If Record is out of the range of Header, return access denied. // if (((UINTN)((UINT8 *) Record - (UINT8 *) Header)) > FTW_WRITE_TOTAL_SIZE (Header->NumberOfWrites - 1, Header->PrivateDataSize)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 4\n", __FUNCTION__)); return EFI_ACCESS_DENIED; } @@ -373,20 +404,24 @@ FtwWrite ( // Check the COMPLETE flag of last write header // if (Header->Complete == FTW_VALID_STATE) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 5\n", __FUNCTION__)); return EFI_ACCESS_DENIED; } if (Record->DestinationComplete == FTW_VALID_STATE) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 6\n", __FUNCTION__)); return EFI_ACCESS_DENIED; } if ((Record->SpareComplete == FTW_VALID_STATE) && (Record->DestinationComplete != FTW_VALID_STATE)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 7\n", __FUNCTION__)); return EFI_NOT_READY; } // // Check if the input data can fit within the target block // if ((Offset + Length) > FtwDevice->SpareAreaLength) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 8\n", __FUNCTION__)); return EFI_BAD_BUFFER_SIZE; } // @@ -394,12 +429,14 @@ FtwWrite ( // Status = FtwGetFvbByHandle (FvBlockHandle, &Fvb); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 9: %r\n", __FUNCTION__, Status)); return EFI_NOT_FOUND; } Status = Fvb->GetPhysicalAddress (Fvb, &FvbPhysicalAddress); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "FtwLite: Get FVB physical address - %r\n", Status)); + DEBUG ((DEBUG_VERBOSE, "%a: exit 10: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } @@ -431,6 +468,7 @@ FtwWrite ( (UINT8 *) Record ); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 11: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } // @@ -442,6 +480,7 @@ FtwWrite ( MyBufferSize = FtwDevice->SpareAreaLength; MyBuffer = AllocatePool (MyBufferSize); if (MyBuffer == NULL) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 12\n", __FUNCTION__)); return EFI_OUT_OF_RESOURCES; } // @@ -453,6 +492,7 @@ FtwWrite ( Status = Fvb->Read (Fvb, Lba + Index, 0, &MyLength, Ptr); if (EFI_ERROR (Status)) { FreePool (MyBuffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 13: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } @@ -472,6 +512,7 @@ FtwWrite ( SpareBuffer = AllocatePool (SpareBufferSize); if (SpareBuffer == NULL) { FreePool (MyBuffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 14\n", __FUNCTION__)); return EFI_OUT_OF_RESOURCES; } @@ -488,6 +529,7 @@ FtwWrite ( if (EFI_ERROR (Status)) { FreePool (MyBuffer); FreePool (SpareBuffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 15: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } @@ -510,6 +552,7 @@ FtwWrite ( if (EFI_ERROR (Status)) { FreePool (MyBuffer); FreePool (SpareBuffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 16: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } @@ -532,6 +575,7 @@ FtwWrite ( ); if (EFI_ERROR (Status)) { FreePool (SpareBuffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 17: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } @@ -544,6 +588,7 @@ FtwWrite ( Status = FtwWriteRecord (This, Fvb); if (EFI_ERROR (Status)) { FreePool (SpareBuffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 18: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } // @@ -562,6 +607,7 @@ FtwWrite ( ); if (EFI_ERROR (Status)) { FreePool (SpareBuffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 19: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } @@ -580,6 +626,7 @@ FtwWrite ( Length) ); + DEBUG ((DEBUG_VERBOSE, "%a: exit 20\n", __FUNCTION__)); return EFI_SUCCESS; } @@ -610,10 +657,14 @@ FtwRestart ( EFI_FAULT_TOLERANT_WRITE_RECORD *Record; EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb; + DEBUG ((DEBUG_VERBOSE, "%a: enter, FvBlockHandle=%p\n", __FUNCTION__, + FvBlockHandle)); + FtwDevice = FTW_CONTEXT_FROM_THIS (This); Status = WorkSpaceRefresh (FtwDevice); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 1: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } @@ -626,6 +677,7 @@ FtwRestart ( // Status = FtwGetFvbByHandle (FvBlockHandle, &Fvb); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 2: %r\n", __FUNCTION__, Status)); return EFI_NOT_FOUND; } @@ -633,6 +685,7 @@ FtwRestart ( // Check the COMPLETE flag of last write header // if (Header->Complete == FTW_VALID_STATE) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 3\n", __FUNCTION__)); return EFI_ACCESS_DENIED; } @@ -640,10 +693,12 @@ FtwRestart ( // Check the flags of last write record // if (Record->DestinationComplete == FTW_VALID_STATE) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 4\n", __FUNCTION__)); return EFI_ACCESS_DENIED; } if ((Record->SpareComplete != FTW_VALID_STATE)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 5\n", __FUNCTION__)); return EFI_ABORTED; } @@ -653,6 +708,7 @@ FtwRestart ( // Status = FtwWriteRecord (This, Fvb); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 6: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } @@ -663,6 +719,7 @@ FtwRestart ( FtwEraseSpareBlock (FtwDevice); DEBUG ((EFI_D_ERROR, "Ftw: Restart() success \n")); + DEBUG ((DEBUG_VERBOSE, "%a: exit 7\n", __FUNCTION__)); return EFI_SUCCESS; } @@ -686,18 +743,23 @@ FtwAbort ( UINTN Offset; EFI_FTW_DEVICE *FtwDevice; + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); + FtwDevice = FTW_CONTEXT_FROM_THIS (This); Status = WorkSpaceRefresh (FtwDevice); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 1: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } if (FtwDevice->FtwLastWriteHeader->HeaderAllocated != FTW_VALID_STATE) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 2\n", __FUNCTION__)); return EFI_NOT_FOUND; } if (FtwDevice->FtwLastWriteHeader->Complete == FTW_VALID_STATE) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 3\n", __FUNCTION__)); return EFI_NOT_FOUND; } // @@ -711,12 +773,14 @@ FtwAbort ( WRITES_COMPLETED ); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 4: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } FtwDevice->FtwLastWriteHeader->Complete = FTW_VALID_STATE; DEBUG ((EFI_D_ERROR, "Ftw: Abort() success \n")); + DEBUG ((DEBUG_VERBOSE, "%a: exit 5\n", __FUNCTION__)); return EFI_SUCCESS; } @@ -761,7 +825,11 @@ FtwGetLastWrite ( EFI_FAULT_TOLERANT_WRITE_HEADER *Header; EFI_FAULT_TOLERANT_WRITE_RECORD *Record; + DEBUG ((DEBUG_VERBOSE, "%a: enter, PrivateDataSize=0x%Lx\n", __FUNCTION__, + (UINT64)*PrivateDataSize)); + if (!FeaturePcdGet(PcdFullFtwServiceEnable)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 1\n", __FUNCTION__)); return EFI_UNSUPPORTED; } @@ -769,6 +837,7 @@ FtwGetLastWrite ( Status = WorkSpaceRefresh (FtwDevice); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 2: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } @@ -786,6 +855,7 @@ FtwGetLastWrite ( Status = FtwAbort (This); *Complete = TRUE; + DEBUG ((DEBUG_VERBOSE, "%a: exit 3\n", __FUNCTION__)); return EFI_NOT_FOUND; } // @@ -793,6 +863,7 @@ FtwGetLastWrite ( // if (Header->HeaderAllocated != FTW_VALID_STATE) { *Complete = TRUE; + DEBUG ((DEBUG_VERBOSE, "%a: exit 4\n", __FUNCTION__)); return EFI_NOT_FOUND; } // @@ -803,6 +874,7 @@ FtwGetLastWrite ( if (EFI_ERROR (Status)) { FtwAbort (This); *Complete = TRUE; + DEBUG ((DEBUG_VERBOSE, "%a: exit 5: %r\n", __FUNCTION__, Status)); return EFI_NOT_FOUND; } ASSERT (Record != NULL); @@ -829,6 +901,11 @@ FtwGetLastWrite ( DEBUG ((EFI_D_ERROR, "Ftw: GetLasetWrite() success\n")); + DEBUG ((DEBUG_VERBOSE, "%a: exit 6, CallerId=%g Lba=0x%Lx Offset=0x%Lx " + "Length=0x%Lx PrivateDataSize=0x%Lx PrivateData=%p Complete=%d\n", + __FUNCTION__, CallerId, (UINT64)*Lba, (UINT64)*Offset, (UINT64)*Length, + (UINT64)*PrivateDataSize, PrivateData, *Complete)); + return Status; } diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c index 1235bd8..caece56 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c @@ -73,14 +73,19 @@ FtwGetFvbByHandle ( OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock ) { + EFI_STATUS Status; + + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); // // To get the FVB protocol interface on the handle // - return gBS->HandleProtocol ( + Status = gBS->HandleProtocol ( FvBlockHandle, &gEfiFirmwareVolumeBlockProtocolGuid, (VOID **) FvBlock ); + DEBUG ((DEBUG_VERBOSE, "%a: exit: %r\n", __FUNCTION__, Status)); + return Status; } /** @@ -100,6 +105,7 @@ FtwGetSarProtocol ( { EFI_STATUS Status; + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); // // Locate Swap Address Range protocol // @@ -108,6 +114,7 @@ FtwGetSarProtocol ( NULL, SarProtocol ); + DEBUG ((DEBUG_VERBOSE, "%a: exit: %r\n", __FUNCTION__, Status)); return Status; } @@ -134,6 +141,7 @@ GetFvbCountAndBuffer ( { EFI_STATUS Status; + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); // // Locate all handles of Fvb protocol // @@ -144,6 +152,7 @@ GetFvbCountAndBuffer ( NumberHandles, Buffer ); + DEBUG ((DEBUG_VERBOSE, "%a: exit: %r\n", __FUNCTION__, Status)); return Status; } @@ -166,6 +175,9 @@ FvbNotificationEvent ( EFI_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol; EFI_FTW_DEVICE *FtwDevice; + DEBUG ((DEBUG_VERBOSE, "%a: enter, Event=%p Context=%p\n", __FUNCTION__, + Event, Context)); + // // Just return to avoid installing FaultTolerantWriteProtocol again // if Fault Tolerant Write protocol has been installed. @@ -176,6 +188,7 @@ FvbNotificationEvent ( (VOID **) &FtwProtocol ); if (!EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 1: %r\n", __FUNCTION__, Status)); return ; } @@ -185,6 +198,7 @@ FvbNotificationEvent ( FtwDevice = (EFI_FTW_DEVICE *)Context; Status = InitFtwProtocol (FtwDevice); if (EFI_ERROR(Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 2: %r\n", __FUNCTION__, Status)); return ; } @@ -202,6 +216,7 @@ FvbNotificationEvent ( Status = gBS->CloseEvent (Event); ASSERT_EFI_ERROR (Status); + DEBUG ((DEBUG_VERBOSE, "%a: exit 3: %r\n", __FUNCTION__, Status)); return; } @@ -227,11 +242,14 @@ FaultTolerantWriteInitialize ( EFI_STATUS Status; EFI_FTW_DEVICE *FtwDevice; + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); + // // Allocate private data structure for FTW protocol and do some initialization // Status = InitFtwDevice (&FtwDevice); if (EFI_ERROR(Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 1: %r\n", __FUNCTION__, Status)); return Status; } @@ -246,5 +264,6 @@ FaultTolerantWriteInitialize ( &mFvbRegistration ); + DEBUG ((DEBUG_VERBOSE, "%a: exit 2\n", __FUNCTION__)); return EFI_SUCCESS; } diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c index b3352bb..436de4c 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c @@ -35,6 +35,9 @@ IsErasedFlashBuffer ( UINT8 *Ptr; UINTN Index; + DEBUG ((DEBUG_VERBOSE, "%a: enter, Buffer=%p BufferSize=0x%Lx\n", + __FUNCTION__, Buffer, (UINT64)BufferSize)); + Ptr = Buffer; IsEmpty = TRUE; for (Index = 0; Index < BufferSize; Index += 1) { @@ -44,6 +47,7 @@ IsErasedFlashBuffer ( } } + DEBUG ((DEBUG_VERBOSE, "%a: exit, IsEmpty=%d\n", __FUNCTION__, IsEmpty)); return IsEmpty; } @@ -66,12 +70,17 @@ FtwEraseBlock ( EFI_LBA Lba ) { - return FvBlock->EraseBlocks ( + EFI_STATUS Status; + + DEBUG ((DEBUG_VERBOSE, "%a: enter, Lba=0x%Lx\n", __FUNCTION__, (UINT64)Lba)); + Status = FvBlock->EraseBlocks ( FvBlock, Lba, FtwDevice->NumberOfSpareBlock, EFI_LBA_LIST_TERMINATOR ); + DEBUG ((DEBUG_VERBOSE, "%a: exit: %r\n", __FUNCTION__, Status)); + return Status; } /** @@ -96,12 +105,17 @@ FtwEraseSpareBlock ( IN EFI_FTW_DEVICE *FtwDevice ) { - return FtwDevice->FtwBackupFvb->EraseBlocks ( + EFI_STATUS Status; + + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); + Status = FtwDevice->FtwBackupFvb->EraseBlocks ( FtwDevice->FtwBackupFvb, FtwDevice->FtwSpareLba, FtwDevice->NumberOfSpareBlock, EFI_LBA_LIST_TERMINATOR ); + DEBUG ((DEBUG_VERBOSE, "%a: exit: %r\n", __FUNCTION__, Status)); + return Status; } /** @@ -122,17 +136,22 @@ IsWorkingBlock ( EFI_LBA Lba ) { + BOOLEAN Ret; + + DEBUG ((DEBUG_VERBOSE, "%a: enter, Lba=0x%Lx\n", __FUNCTION__, (UINT64)Lba)); // // If matching the following condition, the target block is in working block. // 1. Target block is on the FV of working block (Using the same FVB protocol instance). // 2. Lba falls into the range of working block. // - return (BOOLEAN) + Ret = (BOOLEAN) ( (FvBlock == FtwDevice->FtwFvBlock) && (Lba >= FtwDevice->FtwWorkBlockLba) && (Lba <= FtwDevice->FtwWorkSpaceLba) ); + DEBUG ((DEBUG_VERBOSE, "%a: exit: %d\n", __FUNCTION__, Ret)); + return Ret; } /** @@ -162,6 +181,9 @@ GetFvbByAddress ( EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; EFI_HANDLE FvbHandle; + DEBUG ((DEBUG_VERBOSE, "%a: enter, Address=0x%Lx\n", __FUNCTION__, + (UINT64)Address)); + *FvBlock = NULL; FvbHandle = NULL; // @@ -169,6 +191,7 @@ GetFvbByAddress ( // Status = GetFvbCountAndBuffer (&HandleCount, &HandleBuffer); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 1: %r\n", __FUNCTION__, Status)); return NULL; } // @@ -196,6 +219,7 @@ GetFvbByAddress ( } FreePool (HandleBuffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 2\n", __FUNCTION__)); return FvbHandle; } @@ -227,12 +251,16 @@ IsBootBlock ( BOOLEAN IsSwapped; EFI_HANDLE FvbHandle; + DEBUG ((DEBUG_VERBOSE, "%a: enter, Lba=0x%Lx\n", __FUNCTION__, (UINT64)Lba)); + if (!FeaturePcdGet(PcdFullFtwServiceEnable)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 1\n", __FUNCTION__)); return FALSE; } Status = FtwGetSarProtocol ((VOID **) &SarProtocol); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 2: %r\n", __FUNCTION__, Status)); return FALSE; } // @@ -246,11 +274,13 @@ IsBootBlock ( &BackupBlockSize ); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 3: %r\n", __FUNCTION__, Status)); return FALSE; } Status = SarProtocol->GetSwapState (SarProtocol, &IsSwapped); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 4: %r\n", __FUNCTION__, Status)); return FALSE; } // @@ -263,11 +293,14 @@ IsBootBlock ( } if (FvbHandle == NULL) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 5\n", __FUNCTION__)); return FALSE; } // // Compare the Fvb // + DEBUG ((DEBUG_VERBOSE, "%a: exit 6: %d\n", __FUNCTION__, + FvBlock == BootFvb)); return (BOOLEAN) (FvBlock == BootFvb); } @@ -313,7 +346,10 @@ FlushSpareBlockToBootBlock ( EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *BootFvb; EFI_LBA BootLba; + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); + if (!FeaturePcdGet(PcdFullFtwServiceEnable)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 1\n", __FUNCTION__)); return EFI_UNSUPPORTED; } @@ -322,6 +358,7 @@ FlushSpareBlockToBootBlock ( // Status = FtwGetSarProtocol ((VOID **) &SarProtocol); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 2: %r\n", __FUNCTION__, Status)); return Status; } // @@ -330,6 +367,7 @@ FlushSpareBlockToBootBlock ( Length = FtwDevice->SpareAreaLength; Buffer = AllocatePool (Length); if (Buffer == NULL) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 3\n", __FUNCTION__)); return EFI_OUT_OF_RESOURCES; } // @@ -339,6 +377,7 @@ FlushSpareBlockToBootBlock ( if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "Ftw: Get Top Swapped status - %r\n", Status)); FreePool (Buffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 4: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } @@ -348,6 +387,7 @@ FlushSpareBlockToBootBlock ( // if (GetFvbByAddress (FtwDevice->SpareAreaAddress + FtwDevice->SpareAreaLength, &BootFvb) == NULL) { FreePool (Buffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 5\n", __FUNCTION__)); return EFI_ABORTED; } // @@ -366,6 +406,7 @@ FlushSpareBlockToBootBlock ( ); if (EFI_ERROR (Status)) { FreePool (Buffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 6: %r\n", __FUNCTION__, Status)); return Status; } @@ -387,6 +428,7 @@ FlushSpareBlockToBootBlock ( ); if (EFI_ERROR (Status)) { FreePool (Buffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 7: %r\n", __FUNCTION__, Status)); return Status; } @@ -398,6 +440,7 @@ FlushSpareBlockToBootBlock ( Status = SarProtocol->SetSwapState (SarProtocol, TRUE); if (EFI_ERROR (Status)) { FreePool (Buffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 8: %r\n", __FUNCTION__, Status)); return Status; } } @@ -408,6 +451,7 @@ FlushSpareBlockToBootBlock ( Status = FtwEraseSpareBlock (FtwDevice); if (EFI_ERROR (Status)) { FreePool (Buffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 9: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } // @@ -426,6 +470,7 @@ FlushSpareBlockToBootBlock ( if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "Ftw: FVB Write boot block - %r\n", Status)); FreePool (Buffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 10: %r\n", __FUNCTION__, Status)); return Status; } @@ -439,6 +484,7 @@ FlushSpareBlockToBootBlock ( // Status = SarProtocol->SetSwapState (SarProtocol, FALSE); + DEBUG ((DEBUG_VERBOSE, "%a: exit 11: %r\n", __FUNCTION__, Status)); return Status; } @@ -472,7 +518,10 @@ FlushSpareBlockToTargetBlock ( UINT8 *Ptr; UINTN Index; + DEBUG ((DEBUG_VERBOSE, "%a: enter, Lba=0x%Lx\n", __FUNCTION__, (UINT64)Lba)); + if ((FtwDevice == NULL) || (FvBlock == NULL)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 1\n", __FUNCTION__)); return EFI_INVALID_PARAMETER; } // @@ -481,6 +530,7 @@ FlushSpareBlockToTargetBlock ( Length = FtwDevice->SpareAreaLength; Buffer = AllocatePool (Length); if (Buffer == NULL) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 2\n", __FUNCTION__)); return EFI_OUT_OF_RESOURCES; } // @@ -498,6 +548,7 @@ FlushSpareBlockToTargetBlock ( ); if (EFI_ERROR (Status)) { FreePool (Buffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 3: %r\n", __FUNCTION__, Status)); return Status; } @@ -509,6 +560,7 @@ FlushSpareBlockToTargetBlock ( Status = FtwEraseBlock (FtwDevice, FvBlock, Lba); if (EFI_ERROR (Status)) { FreePool (Buffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 4: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } // @@ -521,6 +573,7 @@ FlushSpareBlockToTargetBlock ( if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "Ftw: FVB Write block - %r\n", Status)); FreePool (Buffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 5: %r\n", __FUNCTION__, Status)); return Status; } @@ -529,6 +582,7 @@ FlushSpareBlockToTargetBlock ( FreePool (Buffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 6: %r\n", __FUNCTION__, Status)); return Status; } @@ -564,12 +618,17 @@ FlushSpareBlockToWorkingBlock ( UINTN Index; EFI_LBA WorkSpaceLbaOffset; + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); + Status = EFI_SUCCESS; + // // Allocate a memory buffer // Length = FtwDevice->SpareAreaLength; Buffer = AllocatePool (Length); if (Buffer == NULL) { + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_OUT_OF_RESOURCES; } @@ -603,6 +662,8 @@ FlushSpareBlockToWorkingBlock ( ); if (EFI_ERROR (Status)) { FreePool (Buffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return Status; } @@ -634,6 +695,8 @@ FlushSpareBlockToWorkingBlock ( ); if (EFI_ERROR (Status)) { FreePool (Buffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_ABORTED; } @@ -645,6 +708,8 @@ FlushSpareBlockToWorkingBlock ( Status = FtwEraseBlock (FtwDevice, FtwDevice->FtwFvBlock, FtwDevice->FtwWorkBlockLba); if (EFI_ERROR (Status)) { FreePool (Buffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_ABORTED; } // @@ -663,6 +728,8 @@ FlushSpareBlockToWorkingBlock ( if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "Ftw: FVB Write block - %r\n", Status)); FreePool (Buffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return Status; } @@ -686,12 +753,16 @@ FlushSpareBlockToWorkingBlock ( WORKING_BLOCK_VALID ); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_ABORTED; } FtwDevice->FtwWorkSpaceHeader->WorkingBlockInvalid = FTW_INVALID_STATE; FtwDevice->FtwWorkSpaceHeader->WorkingBlockValid = FTW_VALID_STATE; + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_SUCCESS; } @@ -725,12 +796,17 @@ FtwUpdateFvState ( UINT8 State; UINTN Length; + DEBUG ((DEBUG_VERBOSE, "%a: enter, Lba=0x%Lx Offset=0x%Lx NewBit=%d\n", + __FUNCTION__, (UINT64)Lba, (UINT64)Offset, NewBit)); + // // Read state from device, assume State is only one byte. // Length = sizeof (UINT8); Status = FvBlock->Read (FvBlock, Lba, Offset, &Length, &State); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_ABORTED; } @@ -744,6 +820,8 @@ FtwUpdateFvState ( Length = sizeof (UINT8); Status = FvBlock->Write (FvBlock, Lba, Offset, &Length, &State); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return Status; } @@ -770,6 +848,11 @@ FtwGetLastWriteHeader ( { UINTN Offset; EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader; + EFI_STATUS Status; + + DEBUG ((DEBUG_VERBOSE, "%a: enter, FtwWorkSpaceSize=0x%Lx\n", __FUNCTION__, + (UINT64)FtwWorkSpaceSize)); + Status = EFI_SUCCESS; *FtwWriteHeader = NULL; FtwHeader = (EFI_FAULT_TOLERANT_WRITE_HEADER *) (FtwWorkSpaceHeader + 1); @@ -782,6 +865,8 @@ FtwGetLastWriteHeader ( // if (Offset >= FtwWorkSpaceSize) { *FtwWriteHeader = FtwHeader; + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_ABORTED; } @@ -792,6 +877,8 @@ FtwGetLastWriteHeader ( // *FtwWriteHeader = FtwHeader; + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_SUCCESS; } @@ -816,6 +903,10 @@ FtwGetLastWriteRecord ( { UINTN Index; EFI_FAULT_TOLERANT_WRITE_RECORD *FtwRecord; + EFI_STATUS Status; + + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); + Status = EFI_SUCCESS; *FtwWriteRecord = NULL; FtwRecord = (EFI_FAULT_TOLERANT_WRITE_RECORD *) (FtwWriteHeader + 1); @@ -829,6 +920,8 @@ FtwGetLastWriteRecord ( // The last write record is found // *FtwWriteRecord = FtwRecord; + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_SUCCESS; } @@ -846,9 +939,13 @@ FtwGetLastWriteRecord ( // if (Index == FtwWriteHeader->NumberOfWrites) { *FtwWriteRecord = (EFI_FAULT_TOLERANT_WRITE_RECORD *) ((UINTN) FtwRecord - FTW_RECORD_SIZE (FtwWriteHeader->PrivateDataSize)); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_SUCCESS; } + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_ABORTED; } @@ -899,10 +996,13 @@ IsLastRecordOfWrites ( UINT8 *Head; UINT8 *Ptr; + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); + Head = (UINT8 *) FtwHeader; Ptr = (UINT8 *) FtwRecord; Head += FTW_WRITE_TOTAL_SIZE (FtwHeader->NumberOfWrites - 1, FtwHeader->PrivateDataSize); + DEBUG ((DEBUG_VERBOSE, "%a: exit: %d\n", __FUNCTION__, Head == Ptr)); return (BOOLEAN) (Head == Ptr); } @@ -923,15 +1023,22 @@ GetPreviousRecordOfWrites ( ) { UINT8 *Ptr; + EFI_STATUS Status = EFI_SUCCESS; + + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); if (IsFirstRecordOfWrites (FtwHeader, *FtwRecord)) { *FtwRecord = NULL; + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_ACCESS_DENIED; } Ptr = (UINT8 *) (*FtwRecord); Ptr -= FTW_RECORD_SIZE (FtwHeader->PrivateDataSize); *FtwRecord = (EFI_FAULT_TOLERANT_WRITE_RECORD *) Ptr; + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_SUCCESS; } @@ -951,13 +1058,18 @@ InitFtwDevice ( ) { EFI_FTW_DEVICE *FtwDevice; - + EFI_STATUS Status = EFI_SUCCESS; + + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); + // // Allocate private data of this driver, // Including the FtwWorkSpace[FTW_WORK_SPACE_SIZE]. // FtwDevice = AllocateZeroPool (sizeof (EFI_FTW_DEVICE) + PcdGet32 (PcdFlashNvStorageFtwWorkingSize)); if (FtwDevice == NULL) { + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_OUT_OF_RESOURCES; } @@ -969,6 +1081,8 @@ InitFtwDevice ( if ((FtwDevice->WorkSpaceLength == 0) || (FtwDevice->SpareAreaLength == 0)) { DEBUG ((EFI_D_ERROR, "Ftw: Workspace or Spare block does not exist!\n")); FreePool (FtwDevice); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_INVALID_PARAMETER; } @@ -989,6 +1103,8 @@ InitFtwDevice ( } *FtwData = FtwDevice; + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_SUCCESS; } @@ -1019,11 +1135,15 @@ FindFvbForFtw ( EFI_FV_BLOCK_MAP_ENTRY *FvbMapEntry; UINT32 LbaIndex; + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); + // // Get all FVB handle. // Status = GetFvbCountAndBuffer (&HandleCount, &HandleBuffer); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_NOT_FOUND; } @@ -1135,9 +1255,13 @@ FindFvbForFtw ( if ((FtwDevice->FtwBackupFvb == NULL) || (FtwDevice->FtwFvBlock == NULL) || (FtwDevice->FtwWorkSpaceLba == (EFI_LBA) (-1)) || (FtwDevice->FtwSpareLba == (EFI_LBA) (-1))) { + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_ABORTED; } + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_SUCCESS; } @@ -1164,11 +1288,15 @@ InitFtwProtocol ( EFI_HANDLE FvbHandle; EFI_LBA WorkSpaceLbaOffset; + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); + // // Find the right SMM Fvb protocol instance for FTW. // Status = FindFvbForFtw (FtwDevice); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_NOT_FOUND; } @@ -1317,6 +1445,8 @@ InitFtwProtocol ( FtwDevice->FtwInstance.Abort = FtwAbort; FtwDevice->FtwInstance.GetLastWrite = FtwGetLastWrite; + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_SUCCESS; } diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c index a5fa12b..85a3a2d 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c @@ -31,6 +31,7 @@ InitializeLocalWorkSpaceHeader ( { EFI_STATUS Status; + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); // // Check signature with gEdkiiWorkingBlockSignatureGuid. // @@ -38,6 +39,7 @@ InitializeLocalWorkSpaceHeader ( // // The local work space header has been initialized. // + DEBUG ((DEBUG_VERBOSE, "%a: exit 1\n", __FUNCTION__)); return; } @@ -73,6 +75,8 @@ InitializeLocalWorkSpaceHeader ( mWorkingBlockHeader.WorkingBlockValid = FTW_VALID_STATE; mWorkingBlockHeader.WorkingBlockInvalid = FTW_INVALID_STATE; + + DEBUG ((DEBUG_VERBOSE, "%a: exit 2\n", __FUNCTION__)); } /** @@ -90,15 +94,20 @@ IsValidWorkSpace ( IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingHeader ) { + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); + if (WorkingHeader == NULL) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 1\n", __FUNCTION__)); return FALSE; } if (CompareMem (WorkingHeader, &mWorkingBlockHeader, sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER)) == 0) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 2\n", __FUNCTION__)); return TRUE; } DEBUG ((EFI_D_ERROR, "Ftw: Work block header check error\n")); + DEBUG ((DEBUG_VERBOSE, "%a: exit 3\n", __FUNCTION__)); return FALSE; } @@ -116,12 +125,15 @@ InitWorkSpaceHeader ( IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingHeader ) { + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); if (WorkingHeader == NULL) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 1\n", __FUNCTION__)); return EFI_INVALID_PARAMETER; } CopyMem (WorkingHeader, &mWorkingBlockHeader, sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER)); + DEBUG ((DEBUG_VERBOSE, "%a: exit 2\n", __FUNCTION__)); return EFI_SUCCESS; } @@ -143,6 +155,7 @@ WorkSpaceRefresh ( UINTN Length; UINTN RemainingSpaceSize; + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); // // Initialize WorkSpace as FTW_ERASED_BYTE // @@ -164,6 +177,7 @@ WorkSpaceRefresh ( FtwDevice->FtwWorkSpace ); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 1: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } // @@ -189,6 +203,7 @@ WorkSpaceRefresh ( Status = FtwReclaimWorkSpace (FtwDevice, TRUE); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "Ftw: Reclaim workspace - %r\n", Status)); + DEBUG ((DEBUG_VERBOSE, "%a: exit 2: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } // @@ -203,6 +218,7 @@ WorkSpaceRefresh ( FtwDevice->FtwWorkSpace ); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 3: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } @@ -212,6 +228,7 @@ WorkSpaceRefresh ( &FtwDevice->FtwLastWriteHeader ); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 4: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } } @@ -223,9 +240,11 @@ WorkSpaceRefresh ( &FtwDevice->FtwLastWriteRecord ); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 5: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } + DEBUG ((DEBUG_VERBOSE, "%a: exit 6\n", __FUNCTION__)); return EFI_SUCCESS; } @@ -258,6 +277,8 @@ FtwReclaimWorkSpace ( UINT8 *Ptr; EFI_LBA WorkSpaceLbaOffset; + DEBUG ((DEBUG_VERBOSE, "%a: enter, PreserveRecord=%d\n", __FUNCTION__, + PreserveRecord)); DEBUG ((EFI_D_INFO, "Ftw: start to reclaim work space\n")); WorkSpaceLbaOffset = FtwDevice->FtwWorkSpaceLba - FtwDevice->FtwWorkBlockLba; @@ -268,6 +289,7 @@ FtwReclaimWorkSpace ( TempBufferSize = FtwDevice->SpareAreaLength; TempBuffer = AllocateZeroPool (TempBufferSize); if (TempBuffer == NULL) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 1\n", __FUNCTION__)); return EFI_OUT_OF_RESOURCES; } @@ -283,6 +305,7 @@ FtwReclaimWorkSpace ( ); if (EFI_ERROR (Status)) { FreePool (TempBuffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 2: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } @@ -361,6 +384,7 @@ FtwReclaimWorkSpace ( SpareBuffer = AllocatePool (SpareBufferSize); if (SpareBuffer == NULL) { FreePool (TempBuffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 3\n", __FUNCTION__)); return EFI_OUT_OF_RESOURCES; } @@ -377,6 +401,7 @@ FtwReclaimWorkSpace ( if (EFI_ERROR (Status)) { FreePool (TempBuffer); FreePool (SpareBuffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 4: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } @@ -399,6 +424,7 @@ FtwReclaimWorkSpace ( if (EFI_ERROR (Status)) { FreePool (TempBuffer); FreePool (SpareBuffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 5: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } @@ -420,6 +446,7 @@ FtwReclaimWorkSpace ( ); if (EFI_ERROR (Status)) { FreePool (SpareBuffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 6: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } // @@ -436,6 +463,7 @@ FtwReclaimWorkSpace ( ); if (EFI_ERROR (Status)) { FreePool (SpareBuffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 7: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } @@ -447,6 +475,7 @@ FtwReclaimWorkSpace ( Status = FlushSpareBlockToWorkingBlock (FtwDevice); if (EFI_ERROR (Status)) { FreePool (SpareBuffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 8: %r\n", __FUNCTION__, Status)); return Status; } // @@ -465,6 +494,7 @@ FtwReclaimWorkSpace ( ); if (EFI_ERROR (Status)) { FreePool (SpareBuffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit 9: %r\n", __FUNCTION__, Status)); return EFI_ABORTED; } @@ -475,5 +505,6 @@ FtwReclaimWorkSpace ( DEBUG ((EFI_D_INFO, "Ftw: reclaim work space successfully\n")); + DEBUG ((DEBUG_VERBOSE, "%a: exit 10\n", __FUNCTION__)); return EFI_SUCCESS; } diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbInfo.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbInfo.c index 72845f9..e9f4254 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbInfo.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbInfo.c @@ -112,6 +112,10 @@ GetFvbInfo ( { STATIC BOOLEAN Checksummed = FALSE; UINTN Index; + EFI_STATUS Status = EFI_SUCCESS; + + DEBUG ((DEBUG_VERBOSE, "%a: enter, FvLength=0x%Lx\n", __FUNCTION__, + FvLength)); if (!Checksummed) { for (Index = 0; Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB_MEDIA_INFO); Index += 1) { @@ -129,9 +133,13 @@ GetFvbInfo ( for (Index = 0; Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB_MEDIA_INFO); Index += 1) { if (mPlatformFvbMediaInfo[Index].FvLength == FvLength) { *FvbInfo = &mPlatformFvbMediaInfo[Index].FvbInfo; + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_SUCCESS; } } + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_NOT_FOUND; } diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c index 7d26c41..56d1b73 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c @@ -147,6 +147,8 @@ Returns: EFI_FW_VOL_INSTANCE *FwhInstance; UINTN Index; + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); + EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal->FvInstance[FVB_VIRTUAL]); // @@ -167,6 +169,8 @@ Returns: EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal->FvbScratchSpace[FVB_VIRTUAL]); EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal); QemuFlashConvertPointers (); + + DEBUG ((DEBUG_VERBOSE, "%a: exit\n", __FUNCTION__)); } EFI_STATUS @@ -196,8 +200,14 @@ Returns: --*/ { EFI_FW_VOL_INSTANCE *FwhRecord; + EFI_STATUS Status = EFI_SUCCESS; + + DEBUG ((DEBUG_VERBOSE, "%a: enter, Instance=0x%Lx, Global=%p, Virtual=%d\n", + __FUNCTION__, (UINT64)Instance, Global, Virtual)); if (Instance >= Global->NumFv) { + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_INVALID_PARAMETER; } // @@ -215,6 +225,8 @@ Returns: *FwhInstance = FwhRecord; + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_SUCCESS; } @@ -249,6 +261,9 @@ Returns: EFI_FW_VOL_INSTANCE *FwhInstance; EFI_STATUS Status; + DEBUG ((DEBUG_VERBOSE, "%a: enter, Instance=0x%Lx, Global=%p, Virtual=%d\n", + __FUNCTION__, (UINT64)Instance, Global, Virtual)); + // // Find the right instance of the FVB private data // @@ -256,6 +271,8 @@ Returns: ASSERT_EFI_ERROR (Status); *Address = FwhInstance->FvBase[Virtual]; + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r, Address=0x%Lx\n", + __FUNCTION__, __LINE__, Status, (UINT64)*Address)); return EFI_SUCCESS; } @@ -289,6 +306,9 @@ Returns: EFI_FW_VOL_INSTANCE *FwhInstance; EFI_STATUS Status; + DEBUG ((DEBUG_VERBOSE, "%a: enter, Instance=0x%Lx, Global=%p, Virtual=%d\n", + __FUNCTION__, (UINT64)Instance, Global, Virtual)); + // // Find the right instance of the FVB private data // @@ -296,6 +316,8 @@ Returns: ASSERT_EFI_ERROR (Status); *Attributes = FwhInstance->VolumeHeader.Attributes; + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r, Attributes=0x%Lx\n", + __FUNCTION__, __LINE__, Status, (UINT64)*Attributes)); return EFI_SUCCESS; } @@ -343,6 +365,10 @@ Returns: EFI_FV_BLOCK_MAP_ENTRY *BlockMap; EFI_STATUS Status; + DEBUG ((DEBUG_VERBOSE, "%a: enter, Instance=0x%Lx, Global=%p, Virtual=%d, " + "Lba=0x%Lx\n", __FUNCTION__, (UINT64)Instance, Global, Virtual, + (UINT64)Lba)); + // // Find the right instance of the FVB private data // @@ -361,6 +387,8 @@ Returns: BlockLength = BlockMap->Length; if (NumBlocks == 0 || BlockLength == 0) { + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_INVALID_PARAMETER; } @@ -373,16 +401,24 @@ Returns: Offset = Offset + (UINTN) MultU64x32 ((Lba - StartLba), BlockLength); if (LbaAddress != NULL) { *LbaAddress = FwhInstance->FvBase[Virtual] + Offset; + DEBUG ((DEBUG_VERBOSE, "%a: LbaAddress=0x%Lx\n", __FUNCTION__, + (UINT64)*LbaAddress)); } if (LbaLength != NULL) { *LbaLength = BlockLength; + DEBUG ((DEBUG_VERBOSE, "%a: LbaLength=0x%Lx\n", __FUNCTION__, + (UINT64)*LbaLength)); } if (NumOfBlocks != NULL) { *NumOfBlocks = (UINTN) (NextLba - Lba); + DEBUG ((DEBUG_VERBOSE, "%a: NumOfBlocks=0x%Lx\n", __FUNCTION__, + (UINT64)*NumOfBlocks)); } + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_SUCCESS; } @@ -434,6 +470,10 @@ Returns: EFI_STATUS Status; EFI_FVB_ATTRIBUTES_2 UnchangedAttributes; + DEBUG ((DEBUG_VERBOSE, "%a: enter, Instance=0x%Lx, Global=%p, Virtual=%d, " + "Attributes=0x%Lx\n", __FUNCTION__, (UINT64)Instance, Global, Virtual, + (UINTN)*Attributes)); + // // Find the right instance of the FVB private data // @@ -467,6 +507,8 @@ Returns: // Some attributes of FV is read only can *not* be set // if ((OldAttributes & UnchangedAttributes) ^ (*Attributes & UnchangedAttributes)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_INVALID_PARAMETER; } // @@ -474,6 +516,8 @@ Returns: // if (OldAttributes & EFI_FVB2_LOCK_STATUS) { if (OldStatus ^ NewStatus) { + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_ACCESS_DENIED; } } @@ -482,6 +526,8 @@ Returns: // if ((Capabilities & EFI_FVB2_READ_DISABLED_CAP) == 0) { if ((NewStatus & EFI_FVB2_READ_STATUS) == 0) { + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_INVALID_PARAMETER; } } @@ -490,6 +536,8 @@ Returns: // if ((Capabilities & EFI_FVB2_READ_ENABLED_CAP) == 0) { if (NewStatus & EFI_FVB2_READ_STATUS) { + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_INVALID_PARAMETER; } } @@ -498,6 +546,8 @@ Returns: // if ((Capabilities & EFI_FVB2_WRITE_DISABLED_CAP) == 0) { if ((NewStatus & EFI_FVB2_WRITE_STATUS) == 0) { + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_INVALID_PARAMETER; } } @@ -506,6 +556,8 @@ Returns: // if ((Capabilities & EFI_FVB2_WRITE_ENABLED_CAP) == 0) { if (NewStatus & EFI_FVB2_WRITE_STATUS) { + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_INVALID_PARAMETER; } } @@ -514,6 +566,8 @@ Returns: // if ((Capabilities & EFI_FVB2_LOCK_CAP) == 0) { if (NewStatus & EFI_FVB2_LOCK_STATUS) { + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_INVALID_PARAMETER; } } @@ -522,6 +576,8 @@ Returns: *AttribPtr = (*AttribPtr) | NewStatus; *Attributes = *AttribPtr; + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r, Attributes=0x%Lx\n", + __FUNCTION__, __LINE__, Status, (UINTN)*Attributes)); return EFI_SUCCESS; } @@ -553,10 +609,16 @@ Returns: --*/ { EFI_FW_VOL_BLOCK_DEVICE *FvbDevice; + EFI_STATUS Status; + + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); FvbDevice = FVB_DEVICE_FROM_THIS (This); - return FvbGetPhysicalAddress (FvbDevice->Instance, Address, mFvbModuleGlobal, EfiGoneVirtual ()); + Status = FvbGetPhysicalAddress (FvbDevice->Instance, Address, mFvbModuleGlobal, EfiGoneVirtual ()); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); + return Status; } EFI_STATUS @@ -589,10 +651,13 @@ Returns: --*/ { EFI_FW_VOL_BLOCK_DEVICE *FvbDevice; + EFI_STATUS Status; + + DEBUG ((DEBUG_VERBOSE, "%a: enter, Lba=0x%Lx\n", __FUNCTION__, (UINT64)Lba)); FvbDevice = FVB_DEVICE_FROM_THIS (This); - return FvbGetLbaAddress ( + Status = FvbGetLbaAddress ( FvbDevice->Instance, Lba, NULL, @@ -601,6 +666,10 @@ Returns: mFvbModuleGlobal, EfiGoneVirtual () ); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r BlockSize=0x%Lx " + "NumOfBlocks=0x%Lx\n", __FUNCTION__, __LINE__, Status, (UINT64)*BlockSize, + (UINT64)*NumOfBlocks)); + return Status; } EFI_STATUS @@ -624,10 +693,16 @@ Returns: --*/ { EFI_FW_VOL_BLOCK_DEVICE *FvbDevice; + EFI_STATUS Status; + + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); FvbDevice = FVB_DEVICE_FROM_THIS (This); - return FvbGetVolumeAttributes (FvbDevice->Instance, Attributes, mFvbModuleGlobal, EfiGoneVirtual ()); + Status = FvbGetVolumeAttributes (FvbDevice->Instance, Attributes, mFvbModuleGlobal, EfiGoneVirtual ()); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); + return Status; } EFI_STATUS @@ -651,10 +726,16 @@ Returns: --*/ { EFI_FW_VOL_BLOCK_DEVICE *FvbDevice; + EFI_STATUS Status; + + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); FvbDevice = FVB_DEVICE_FROM_THIS (This); - return FvbSetVolumeAttributes (FvbDevice->Instance, Attributes, mFvbModuleGlobal, EfiGoneVirtual ()); + Status = FvbSetVolumeAttributes (FvbDevice->Instance, Attributes, mFvbModuleGlobal, EfiGoneVirtual ()); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r, Attributes=0x%Lx\n", + __FUNCTION__, __LINE__, Status, (UINT64)*Attributes)); + return Status; } EFI_STATUS @@ -696,6 +777,8 @@ Returns: UINTN NumOfLba; EFI_STATUS Status; + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); + FvbDevice = FVB_DEVICE_FROM_THIS (This); Status = GetFvbInstance (FvbDevice->Instance, mFvbModuleGlobal, &FwhInstance, EfiGoneVirtual ()); @@ -718,6 +801,8 @@ Returns: // if ((NumOfLba == 0) || ((StartingLba + NumOfLba) > NumOfBlocks)) { VA_END (args); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_INVALID_PARAMETER; } } while (1); @@ -737,6 +822,8 @@ Returns: Status = QemuFlashEraseBlock (StartingLba); if (EFI_ERROR (Status)) { VA_END (args); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return Status; } @@ -748,6 +835,8 @@ Returns: VA_END (args); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_SUCCESS; } @@ -791,7 +880,16 @@ Returns: --*/ { - return QemuFlashWrite ((EFI_LBA)Lba, (UINTN)Offset, NumBytes, (UINT8 *)Buffer); + EFI_STATUS Status; + + DEBUG ((DEBUG_VERBOSE, "%a: enter, Lba=0x%Lx Offset=0x%Lx NumBytes=0x%Lx " + "Buffer=%p\n", __FUNCTION__, (UINT64)Lba, (UINT64)Offset, + (UINT64)*NumBytes, Buffer)); + + Status = QemuFlashWrite ((EFI_LBA)Lba, (UINTN)Offset, NumBytes, (UINT8 *)Buffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r, NumBytes=0x%Lx\n", + __FUNCTION__, __LINE__, Status, (UINT64)*NumBytes)); + return Status; } EFI_STATUS @@ -835,7 +933,16 @@ Returns: --*/ { - return QemuFlashRead ((EFI_LBA)Lba, (UINTN)Offset, NumBytes, (UINT8 *)Buffer); + EFI_STATUS Status; + + DEBUG ((DEBUG_VERBOSE, "%a: enter, Lba=0x%Lx Offset=0x%Lx NumBytes=0x%Lx " + "Buffer=%p\n", __FUNCTION__, (UINT64)Lba, (UINT64)Offset, + (UINT64)*NumBytes, Buffer)); + + Status = QemuFlashRead ((EFI_LBA)Lba, (UINTN)Offset, NumBytes, (UINT8 *)Buffer); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r, NumBytes=0x%Lx\n", + __FUNCTION__, __LINE__, Status, (UINT64)*NumBytes)); + return Status; } EFI_STATUS @@ -857,6 +964,9 @@ Returns: --*/ { UINT16 Checksum; + EFI_STATUS Status = EFI_SUCCESS; + + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); // // Verify the header revision, header signature, length @@ -868,6 +978,8 @@ Returns: (FwVolHeader->FvLength == ((UINTN) -1)) || ((FwVolHeader->HeaderLength & 0x01) != 0) ) { + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_NOT_FOUND; } @@ -883,9 +995,13 @@ Returns: DEBUG ((EFI_D_INFO, "FV@%p Checksum is 0x%x, expected 0x%x\n", FwVolHeader, FwVolHeader->Checksum, Expected)); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_NOT_FOUND; } + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_SUCCESS; } @@ -898,6 +1014,9 @@ MarkMemoryRangeForRuntimeAccess ( { EFI_STATUS Status; + DEBUG ((DEBUG_VERBOSE, "%a: enter, BaseAddress=0x%Lx Length=0x%Lx\n", + __FUNCTION__, (UINT64)BaseAddress, Length)); + // // Mark flash region as runtime memory // @@ -922,6 +1041,8 @@ MarkMemoryRangeForRuntimeAccess ( ); ASSERT_EFI_ERROR (Status); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return Status; } @@ -938,6 +1059,8 @@ InitializeVariableFvHeader ( UINTN WriteLength; UINTN BlockSize; + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); + FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) PcdGet32 (PcdOvmfFlashNvStorageVariableBase); @@ -994,6 +1117,8 @@ InitializeVariableFvHeader ( ASSERT (WriteLength == GoodFwVolHeader->HeaderLength); } + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return Status; } @@ -1028,11 +1153,15 @@ Returns: UINTN NumOfBlocks; EFI_EVENT VirtualAddressChangeEvent; - if (EFI_ERROR (QemuFlashInitialize ())) { + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); + + if (EFI_ERROR ((Status = QemuFlashInitialize ()))) { // // Return an error so image will be unloaded // DEBUG ((EFI_D_INFO, "QEMU flash was not detected. Writable FVB is not being installed.\n")); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_WRITE_PROTECTED; } @@ -1049,6 +1178,8 @@ Returns: Status = InitializeVariableFvHeader (); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_INFO, "QEMU Flash: Unable to initialize variable FV header\n")); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_WRITE_PROTECTED; } @@ -1061,6 +1192,8 @@ Returns: Status = GetFvbInfo (Length, &FwVolHeader); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_INFO, "EFI_ERROR (GetFvbInfo (Length, &FwVolHeader))\n")); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_WRITE_PROTECTED; } } @@ -1223,5 +1356,7 @@ Returns: ASSERT_EFI_ERROR (Status); PcdSetBool (PcdOvmfFlashVariablesEnable, TRUE); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_SUCCESS; } diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c index a3fe7d8..32e07e3 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c @@ -43,7 +43,9 @@ QemuFlashConvertPointers ( VOID ) { + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); EfiConvertPointer (0x0, (VOID **) &mFlashBase); + DEBUG ((DEBUG_VERBOSE, "%a: exit\n", __FUNCTION__)); } @@ -54,7 +56,13 @@ QemuFlashPtr ( IN UINTN Offset ) { - return mFlashBase + (Lba * mFdBlockSize) + Offset; + UINT8 *Ret; + + DEBUG ((DEBUG_VERBOSE, "%a: enter, Lba=0x%Lx Offset=0x%Lx\n", __FUNCTION__, + (UINT64)Lba, (UINT64)Offset)); + Ret = mFlashBase + (Lba * mFdBlockSize) + Offset; + DEBUG ((DEBUG_VERBOSE, "%a: exit, Ret=%p\n", __FUNCTION__, Ret)); + return Ret; } @@ -78,6 +86,8 @@ QemuFlashDetected ( UINT8 OriginalUint8; UINT8 ProbeUint8; + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); + FlashDetected = FALSE; Ptr = QemuFlashPtr (0, 0); @@ -93,6 +103,7 @@ QemuFlashDetected ( if (Offset >= mFdBlockSize) { DEBUG ((EFI_D_INFO, "QEMU Flash: Failed to find probe location\n")); + DEBUG ((DEBUG_VERBOSE, "%a: exit 1\n", __FUNCTION__)); return FALSE; } @@ -122,6 +133,7 @@ QemuFlashDetected ( DEBUG ((EFI_D_INFO, "QemuFlashDetected => %a\n", FlashDetected ? "Yes" : "No")); + DEBUG ((DEBUG_VERBOSE, "%a: exit 2\n", __FUNCTION__)); return FlashDetected; } @@ -146,11 +158,16 @@ QemuFlashRead ( { UINT8 *Ptr; + DEBUG ((DEBUG_VERBOSE, "%a: enter, Lba=0x%Lx Offset=0x%Lx NumBytes=0x%Lx " + "Buffer=%p\n", __FUNCTION__, (UINT64)Lba, (UINT64)Offset, + (UINT64)*NumBytes, Buffer)); + // // Only write to the first 64k. We don't bother saving the FTW Spare // block into the flash memory. // if (Lba >= mFdBlockCount) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 1\n", __FUNCTION__)); return EFI_INVALID_PARAMETER; } @@ -161,6 +178,7 @@ QemuFlashRead ( CopyMem (Buffer, Ptr, *NumBytes); + DEBUG ((DEBUG_VERBOSE, "%a: exit 2\n", __FUNCTION__)); return EFI_SUCCESS; } @@ -186,11 +204,16 @@ QemuFlashWrite ( volatile UINT8 *Ptr; UINTN Loop; + DEBUG ((DEBUG_VERBOSE, "%a: enter, Lba=0x%Lx Offset=0x%Lx NumBytes=0x%Lx " + "Buffer=%p\n", __FUNCTION__, (UINT64)Lba, (UINT64)Offset, + (UINT64)*NumBytes, Buffer)); + // // Only write to the first 64k. We don't bother saving the FTW Spare // block into the flash memory. // if (Lba >= mFdBlockCount) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 1\n", __FUNCTION__)); return EFI_INVALID_PARAMETER; } @@ -211,6 +234,7 @@ QemuFlashWrite ( *Ptr = READ_ARRAY_CMD; } + DEBUG ((DEBUG_VERBOSE, "%a: exit 2\n", __FUNCTION__)); return EFI_SUCCESS; } @@ -228,13 +252,17 @@ QemuFlashEraseBlock ( { volatile UINT8 *Ptr; + DEBUG ((DEBUG_VERBOSE, "%a: enter, Lba=0x%Lx\n", __FUNCTION__, (UINT64)Lba)); + if (Lba >= mFdBlockCount) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 1\n", __FUNCTION__)); return EFI_INVALID_PARAMETER; } Ptr = QemuFlashPtr (Lba, 0); *Ptr = BLOCK_ERASE_CMD; *Ptr = BLOCK_ERASE_CONFIRM_CMD; + DEBUG ((DEBUG_VERBOSE, "%a: exit 2\n", __FUNCTION__)); return EFI_SUCCESS; } @@ -251,15 +279,19 @@ QemuFlashInitialize ( VOID ) { + DEBUG ((DEBUG_VERBOSE, "%a: enter\n", __FUNCTION__)); + mFlashBase = (UINT8*)(UINTN) PcdGet32 (PcdOvmfFdBaseAddress); mFdBlockSize = PcdGet32 (PcdOvmfFirmwareBlockSize); ASSERT(PcdGet32 (PcdOvmfFirmwareFdSize) % mFdBlockSize == 0); mFdBlockCount = PcdGet32 (PcdOvmfFirmwareFdSize) / mFdBlockSize; if (!QemuFlashDetected ()) { + DEBUG ((DEBUG_VERBOSE, "%a: exit 1\n", __FUNCTION__)); return EFI_WRITE_PROTECTED; } + DEBUG ((DEBUG_VERBOSE, "%a: exit 2\n", __FUNCTION__)); return EFI_SUCCESS; } diff --git a/SecurityPkg/VariableAuthenticated/RuntimeDxe/Reclaim.c b/SecurityPkg/VariableAuthenticated/RuntimeDxe/Reclaim.c index b20facd..fc85b18 100644 --- a/SecurityPkg/VariableAuthenticated/RuntimeDxe/Reclaim.c +++ b/SecurityPkg/VariableAuthenticated/RuntimeDxe/Reclaim.c @@ -118,11 +118,14 @@ FtwVariableSpace ( UINTN FtwBufferSize; EFI_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol; + DEBUG ((DEBUG_VERBOSE, "%a:%a: enter\n", __FUNCTION__, __FILE__)); // // Locate fault tolerant write protocol. // Status = GetFtwProtocol((VOID **) &FtwProtocol); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_NOT_FOUND; } // @@ -130,6 +133,8 @@ FtwVariableSpace ( // Status = GetFvbInfoByAddress (VariableBase, &FvbHandle, NULL); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return Status; } // @@ -137,6 +142,8 @@ FtwVariableSpace ( // Status = GetLbaAndOffsetByAddress (VariableBase, &VarLba, &VarOffset); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_ABORTED; } @@ -156,5 +163,7 @@ FtwVariableSpace ( (VOID *) VariableBuffer // write buffer ); + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return Status; } diff --git a/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c b/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c index 28d026a..369e7bb 100644 --- a/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c +++ b/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c @@ -776,6 +776,12 @@ Reclaim ( VARIABLE_HEADER *UpdatingVariable; VARIABLE_HEADER *UpdatingInDeletedTransition; + DEBUG ((DEBUG_VERBOSE, "%a: enter, VariableBase=0x%Lx, IsVolatile=%d, " + "NewVariableSize=0x%Lx, ReclaimPubKeyStore=%d\n", __FUNCTION__, + (UINT64)VariableBase, IsVolatile, (UINTN)NewVariableSize, + ReclaimPubKeyStore)); + Status = EFI_SUCCESS; + UpdatingVariable = NULL; UpdatingInDeletedTransition = NULL; if (UpdatingPtrTrack != NULL) { @@ -826,6 +832,8 @@ Reclaim ( MaximumBufferSize += 1; ValidBuffer = AllocatePool (MaximumBufferSize); if (ValidBuffer == NULL) { + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return EFI_OUT_OF_RESOURCES; } } else { @@ -1067,6 +1075,8 @@ Done: } } + DEBUG ((DEBUG_VERBOSE, "%a: exit @ %d, Status=%r\n", + __FUNCTION__, __LINE__, Status)); return Status; }