X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FC%2FGenFv%2FGenFvInternalLib.c;h=2b80e7919ba250c3ce1d4de6a5f13ad790787855;hb=9425b34925d0cf1b96aaf2c316d3299df9780252;hp=bf6b40c4c47050bc3d101d8818257de2556364ed;hpb=6db97871107cba3d92ec2f3b7eb350f1fff47a11;p=mirror_edk2.git diff --git a/BaseTools/Source/C/GenFv/GenFvInternalLib.c b/BaseTools/Source/C/GenFv/GenFvInternalLib.c index bf6b40c4c4..2b80e7919b 100644 --- a/BaseTools/Source/C/GenFv/GenFvInternalLib.c +++ b/BaseTools/Source/C/GenFv/GenFvInternalLib.c @@ -1,7 +1,7 @@ /** @file This file contains the internal functions required to generate a Firmware Volume. -Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.
Portions Copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.
Portions Copyright (c) 2016 HP Development Company, L.P.
This program and the accompanying materials @@ -44,6 +44,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. BOOLEAN mArm = FALSE; STATIC UINT32 MaxFfsAlignment = 0; +BOOLEAN VtfFileFlag = FALSE; EFI_GUID mEfiFirmwareVolumeTopFileGuid = EFI_FFS_VOLUME_TOP_FILE_GUID; EFI_GUID mFileGuidArray [MAX_NUMBER_OF_FILES_IN_FV]; @@ -464,57 +465,97 @@ Returns: case 0: // // 1 byte alignment + //if bit 1 have set, 128K byte alignmnet // - *Alignment = 0; + if (FfsFile->Attributes & FFS_ATTRIB_DATA_ALIGNMENT2) { + *Alignment = 17; + } else { + *Alignment = 0; + } break; case 1: // // 16 byte alignment + //if bit 1 have set, 256K byte alignment // - *Alignment = 4; + if (FfsFile->Attributes & FFS_ATTRIB_DATA_ALIGNMENT2) { + *Alignment = 18; + } else { + *Alignment = 4; + } break; case 2: // // 128 byte alignment + //if bit 1 have set, 512K byte alignment // - *Alignment = 7; + if (FfsFile->Attributes & FFS_ATTRIB_DATA_ALIGNMENT2) { + *Alignment = 19; + } else { + *Alignment = 7; + } break; case 3: // // 512 byte alignment + //if bit 1 have set, 1M byte alignment // - *Alignment = 9; + if (FfsFile->Attributes & FFS_ATTRIB_DATA_ALIGNMENT2) { + *Alignment = 20; + } else { + *Alignment = 9; + } break; case 4: // // 1K byte alignment + //if bit 1 have set, 2M byte alignment // - *Alignment = 10; + if (FfsFile->Attributes & FFS_ATTRIB_DATA_ALIGNMENT2) { + *Alignment = 21; + } else { + *Alignment = 10; + } break; case 5: // // 4K byte alignment + //if bit 1 have set, 4M byte alignment // - *Alignment = 12; + if (FfsFile->Attributes & FFS_ATTRIB_DATA_ALIGNMENT2) { + *Alignment = 22; + } else { + *Alignment = 12; + } break; case 6: // // 32K byte alignment + //if bit 1 have set , 8M byte alignment // - *Alignment = 15; + if (FfsFile->Attributes & FFS_ATTRIB_DATA_ALIGNMENT2) { + *Alignment = 23; + } else { + *Alignment = 15; + } break; case 7: // // 64K byte alignment + //if bit 1 have set, 16M alignment // - *Alignment = 16; + if (FfsFile->Attributes & FFS_ATTRIB_DATA_ALIGNMENT2) { + *Alignment = 24; + } else { + *Alignment = 16; + } break; default: @@ -560,7 +601,9 @@ Returns: UINTN PadFileSize; UINT32 NextFfsHeaderSize; UINT32 CurFfsHeaderSize; + UINT32 Index; + Index = 0; CurFfsHeaderSize = sizeof (EFI_FFS_FILE_HEADER); // // Verify input parameters. @@ -665,6 +708,19 @@ Returns: // // Copy Fv Extension Header and Set Fv Extension header offset // + if (ExtHeader->ExtHeaderSize > sizeof (EFI_FIRMWARE_VOLUME_EXT_HEADER)) { + for (Index = sizeof (EFI_FIRMWARE_VOLUME_EXT_HEADER); Index < ExtHeader->ExtHeaderSize;) { + if (((EFI_FIRMWARE_VOLUME_EXT_ENTRY *)((UINT8 *)ExtHeader + Index))-> ExtEntryType == EFI_FV_EXT_TYPE_USED_SIZE_TYPE) { + if (VtfFileFlag) { + ((EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE *)((UINT8 *)ExtHeader + Index))->UsedSize = mFvTotalSize; + } else { + ((EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE *)((UINT8 *)ExtHeader + Index))->UsedSize = mFvTakenSize; + } + break; + } + Index += ((EFI_FIRMWARE_VOLUME_EXT_ENTRY *)((UINT8 *)ExtHeader + Index))-> ExtEntrySize; + } + } memcpy ((UINT8 *)PadFile + CurFfsHeaderSize, ExtHeader, ExtHeader->ExtHeaderSize); ((EFI_FIRMWARE_VOLUME_HEADER *) FvImage->FileImage)->ExtHeaderOffset = (UINT16) ((UINTN) ((UINT8 *)PadFile + CurFfsHeaderSize) - (UINTN) FvImage->FileImage); // @@ -1060,7 +1116,7 @@ Returns: // Clear the alignment bits: these have become meaningless now that we have // adjusted the padding section. // - FfsFile->Attributes &= ~FFS_ATTRIB_DATA_ALIGNMENT; + FfsFile->Attributes &= ~(FFS_ATTRIB_DATA_ALIGNMENT | FFS_ATTRIB_DATA_ALIGNMENT2); // // Recalculate the FFS header checksum. Instead of setting Header and State @@ -1161,6 +1217,7 @@ Returns: // FileBuffer = malloc (FileSize); if (FileBuffer == NULL) { + fclose (NewFile); Error (NULL, 0, 4001, "Resouce", "memory cannot be allocated!"); return EFI_OUT_OF_RESOURCES; } @@ -3018,12 +3075,10 @@ Returns: UINT32 FfsAlignment; UINT32 FfsHeaderSize; EFI_FFS_FILE_HEADER FfsHeader; - BOOLEAN VtfFileFlag; UINTN VtfFileSize; FvExtendHeaderSize = 0; VtfFileSize = 0; - VtfFileFlag = FALSE; fpin = NULL; Index = 0; @@ -3506,6 +3561,7 @@ Returns: PeFileSize = _filelength (fileno (PeFile)); PeFileBuffer = (UINT8 *) malloc (PeFileSize); if (PeFileBuffer == NULL) { + fclose (PeFile); Error (NULL, 0, 4001, "Resource", "memory cannot be allocated on rebase of %s", FileName); return EFI_OUT_OF_RESOURCES; } @@ -3761,6 +3817,7 @@ Returns: PeFileSize = _filelength (fileno (PeFile)); PeFileBuffer = (UINT8 *) malloc (PeFileSize); if (PeFileBuffer == NULL) { + fclose (PeFile); Error (NULL, 0, 4001, "Resource", "memory cannot be allocated on rebase of %s", FileName); return EFI_OUT_OF_RESOURCES; }