X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=Nt32Pkg%2FFvbServicesRuntimeDxe%2FFWBlockService.c;h=3400516f0c3ce9e0a66fe0ebe301fc22e952eaad;hb=47e4bf71e3d9b2554f9611aaf5c1941a7a759155;hp=cb5360f82160b6c19b0dc9ebfcaf10b5db2d972b;hpb=efd542830fe0031d00985cfcb9ea333b7b65fa12;p=mirror_edk2.git diff --git a/Nt32Pkg/FvbServicesRuntimeDxe/FWBlockService.c b/Nt32Pkg/FvbServicesRuntimeDxe/FWBlockService.c index cb5360f821..3400516f0c 100644 --- a/Nt32Pkg/FvbServicesRuntimeDxe/FWBlockService.c +++ b/Nt32Pkg/FvbServicesRuntimeDxe/FWBlockService.c @@ -1,7 +1,7 @@ /**@file -Copyright (c) 2006 - 2007, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -29,7 +29,6 @@ Revision History // #include #include -#include #include // // The Library classes this module consumes @@ -52,31 +51,55 @@ Revision History ESAL_FWB_GLOBAL *mFvbModuleGlobal; -EFI_FW_VOL_BLOCK_DEVICE mFvbDeviceTemplate = { - FVB_DEVICE_SIGNATURE, +FV_MEMMAP_DEVICE_PATH mFvMemmapDevicePathTemplate = { { { + HARDWARE_DEVICE_PATH, + HW_MEMMAP_DP, { - HARDWARE_DEVICE_PATH, - HW_MEMMAP_DP, - { - sizeof (MEMMAP_DEVICE_PATH), - 0 - } - }, - EfiMemoryMappedIO, - 0, - 0, + (UINT8)(sizeof (MEMMAP_DEVICE_PATH)), + (UINT8)(sizeof (MEMMAP_DEVICE_PATH) >> 8) + } }, + EfiMemoryMappedIO, + (EFI_PHYSICAL_ADDRESS) 0, + (EFI_PHYSICAL_ADDRESS) 0, + }, + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { + END_DEVICE_PATH_LENGTH, + 0 + } + } +}; + +FV_PIWG_DEVICE_PATH mFvPIWGDevicePathTemplate = { + { { - END_DEVICE_PATH_TYPE, - END_ENTIRE_DEVICE_PATH_SUBTYPE, + MEDIA_DEVICE_PATH, + MEDIA_PIWG_FW_VOL_DP, { - sizeof (EFI_DEVICE_PATH_PROTOCOL), - 0 + (UINT8)(sizeof (MEDIA_FW_VOL_DEVICE_PATH)), + (UINT8)(sizeof (MEDIA_FW_VOL_DEVICE_PATH) >> 8) } - } + }, + { 0 } }, + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { + END_DEVICE_PATH_LENGTH, + 0 + } + } +}; + +EFI_FW_VOL_BLOCK_DEVICE mFvbDeviceTemplate = { + FVB_DEVICE_SIGNATURE, + NULL, 0, { FvbProtocolGetAttributes, @@ -927,14 +950,10 @@ Returns: // // Check input parameters // - if (NumOfLba == 0) { + if ((NumOfLba == 0) || ((StartingLba + NumOfLba) > NumOfBlocks)) { VA_END (args); return EFI_INVALID_PARAMETER; } - - if ((StartingLba + NumOfLba) > NumOfBlocks) { - return EFI_INVALID_PARAMETER; - } } while (1); VA_END (args); @@ -1081,10 +1100,6 @@ Returns: --*/ { - UINT16 *Ptr; - UINT16 HeaderLength; - UINT16 Checksum; - // // Verify the header revision, header signature, length // Length of FvBlock cannot be 2**64-1 @@ -1097,19 +1112,11 @@ Returns: ) { return EFI_NOT_FOUND; } + // // Verify the header checksum // - HeaderLength = (UINT16) (FwVolHeader->HeaderLength / 2); - Ptr = (UINT16 *) FwVolHeader; - Checksum = 0; - while (HeaderLength > 0) { - Checksum = (UINT16)(Checksum + (*Ptr)); - HeaderLength--; - Ptr++; - } - - if (Checksum != 0) { + if (CalculateCheckSum16 ((UINT16 *) FwVolHeader, FwVolHeader->HeaderLength) != 0) { return EFI_NOT_FOUND; } @@ -1143,15 +1150,13 @@ Returns: EFI_HANDLE FwbHandle; EFI_FW_VOL_BLOCK_DEVICE *FvbDevice; EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *OldFwbInterface; - EFI_DEVICE_PATH_PROTOCOL *TempFwbDevicePath; - FV_DEVICE_PATH TempFvbDevicePathData; UINT32 MaxLbaSize; EFI_PHYSICAL_ADDRESS BaseAddress; UINT64 Length; UINTN NumOfBlocks; EFI_PEI_HOB_POINTERS FvHob; - // + // // Get the DXE services table // DxeServices = gDS; @@ -1262,7 +1267,7 @@ Returns: FwVolHeader->HeaderLength ); } - + FwhInstance->FvBase[FVB_PHYSICAL] = (UINTN) BaseAddress; FwhInstance->FvBase[FVB_VIRTUAL] = (UINTN) BaseAddress; @@ -1274,9 +1279,7 @@ Returns: for (PtrBlockMapEntry = FwVolHeader->BlockMap; PtrBlockMapEntry->NumBlocks != 0; PtrBlockMapEntry++) { // - // Get the maximum size of a block. The size will be used to allocate - // buffer for Scratch space, the intermediate buffer for FVB extension - // protocol + // Get the maximum size of a block. // if (MaxLbaSize < PtrBlockMapEntry->Length) { MaxLbaSize = PtrBlockMapEntry->Length; @@ -1299,19 +1302,29 @@ Returns: FvbDevice->Instance = mFvbModuleGlobal->NumFv; mFvbModuleGlobal->NumFv++; - + + // // Set up the devicepath // - FvbDevice->DevicePath.MemMapDevPath.StartingAddress = BaseAddress; - FvbDevice->DevicePath.MemMapDevPath.EndingAddress = BaseAddress + (FwVolHeader->FvLength - 1); - + if (FwVolHeader->ExtHeaderOffset == 0) { + // + // FV does not contains extension header, then produce MEMMAP_DEVICE_PATH + // + FvbDevice->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateCopyPool (sizeof (FV_MEMMAP_DEVICE_PATH), &mFvMemmapDevicePathTemplate); + ((FV_MEMMAP_DEVICE_PATH *) FvbDevice->DevicePath)->MemMapDevPath.StartingAddress = BaseAddress; + ((FV_MEMMAP_DEVICE_PATH *) FvbDevice->DevicePath)->MemMapDevPath.EndingAddress = BaseAddress + FwVolHeader->FvLength - 1; + } else { + FvbDevice->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateCopyPool (sizeof (FV_PIWG_DEVICE_PATH), &mFvPIWGDevicePathTemplate); + CopyGuid ( + &((FV_PIWG_DEVICE_PATH *)FvbDevice->DevicePath)->FvDevPath.FvName, + (GUID *)(UINTN)(BaseAddress + FwVolHeader->ExtHeaderOffset) + ); + } // // Find a handle with a matching device path that has supports FW Block protocol // - TempFwbDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) &TempFvbDevicePathData; - CopyMem (TempFwbDevicePath, &FvbDevice->DevicePath, sizeof (FV_DEVICE_PATH)); - Status = gBS->LocateDevicePath (&gEfiFirmwareVolumeBlockProtocolGuid, &TempFwbDevicePath, &FwbHandle); + Status = gBS->LocateDevicePath (&gEfiFirmwareVolumeBlockProtocolGuid, &FvbDevice->DevicePath, &FwbHandle); if (EFI_ERROR (Status)) { // // LocateDevicePath fails so install a new interface and device path @@ -1322,11 +1335,11 @@ Returns: &gEfiFirmwareVolumeBlockProtocolGuid, &FvbDevice->FwVolBlockInstance, &gEfiDevicePathProtocolGuid, - &FvbDevice->DevicePath, + FvbDevice->DevicePath, NULL ); ASSERT_EFI_ERROR (Status); - } else if (IsDevicePathEnd (TempFwbDevicePath)) { + } else if (IsDevicePathEnd (FvbDevice->DevicePath)) { // // Device allready exists, so reinstall the FVB protocol // @@ -1352,15 +1365,6 @@ Returns: ASSERT (FALSE); } - Status = gBS->InstallMultipleProtocolInterfaces ( - &FwbHandle, - &gEfiAlternateFvBlockGuid, - NULL, - NULL - ); - - ASSERT_EFI_ERROR (Status); - FwhInstance = (EFI_FW_VOL_INSTANCE *) ( (UINTN) ((UINT8 *) FwhInstance) + FwVolHeader->HeaderLength +