Revision: 14671
http://sourceforge.net/p/edk2/code/14671
Author: lzeng14
Date: 2013-09-16 01:50:44 +0000 (Mon, 16 Sep 2013)
Log Message:
-----------
MdeModulePkg: Add support for weakly aligned FVs.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <[email protected]>
Reviewed-by: Liming Gao <[email protected]>
Modified Paths:
--------------
trunk/edk2/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c
trunk/edk2/MdeModulePkg/Core/Dxe/FwVolBlock/FwVolBlock.c
trunk/edk2/MdeModulePkg/Core/Pei/FwVol/FwVol.c
trunk/edk2/MdePkg/Include/Pi/PiFirmwareVolume.h
Modified: trunk/edk2/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c
===================================================================
--- trunk/edk2/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c 2013-09-16
01:48:08 UTC (rev 14670)
+++ trunk/edk2/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c 2013-09-16
01:50:44 UTC (rev 14671)
@@ -1036,39 +1036,48 @@
//
FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) Buffer;
//
- // Get FvHeader alignment
+ // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first
byte of the volume
+ // can be aligned on any power-of-two boundary. A weakly aligned volume
can not be moved from
+ // its initial linked location and maintain its alignment.
//
- FvAlignment = 1 << ((FvHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);
- //
- // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS
alignment value.
- //
- if (FvAlignment < 8) {
- FvAlignment = 8;
- }
- //
- // Allocate the aligned buffer for the FvImage.
- //
- AlignedBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize),
(UINTN) FvAlignment);
- if (AlignedBuffer == NULL) {
- Status = EFI_OUT_OF_RESOURCES;
- } else {
+ if ((FvHeader->Attributes & EFI_FVB2_WEAK_ALIGNMENT) !=
EFI_FVB2_WEAK_ALIGNMENT) {
//
- // Move FvImage into the aligned buffer and release the original buffer.
+ // Get FvHeader alignment
//
- CopyMem (AlignedBuffer, Buffer, BufferSize);
- CoreFreePool (Buffer);
- Buffer = NULL;
+ FvAlignment = 1 << ((FvHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);
//
- // Produce a FVB protocol for the file
+ // FvAlignment must be greater than or equal to 8 bytes of the minimum
FFS alignment value.
//
- Status = ProduceFVBProtocolOnBuffer (
- (EFI_PHYSICAL_ADDRESS) (UINTN) AlignedBuffer,
- (UINT64)BufferSize,
- FvHandle,
- AuthenticationStatus,
- NULL
- );
+ if (FvAlignment < 8) {
+ FvAlignment = 8;
+ }
+ //
+ // Allocate the aligned buffer for the FvImage.
+ //
+ AlignedBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize),
(UINTN) FvAlignment);
+ if (AlignedBuffer == NULL) {
+ FreePool (Buffer);
+ return EFI_OUT_OF_RESOURCES;
+ } else {
+ //
+ // Move FvImage into the aligned buffer and release the original
buffer.
+ //
+ CopyMem (AlignedBuffer, Buffer, BufferSize);
+ FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) AlignedBuffer;
+ CoreFreePool (Buffer);
+ Buffer = NULL;
+ }
}
+ //
+ // Produce a FVB protocol for the file
+ //
+ Status = ProduceFVBProtocolOnBuffer (
+ (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,
+ (UINT64)BufferSize,
+ FvHandle,
+ AuthenticationStatus,
+ NULL
+ );
}
if (EFI_ERROR (Status)) {
Modified: trunk/edk2/MdeModulePkg/Core/Dxe/FwVolBlock/FwVolBlock.c
===================================================================
--- trunk/edk2/MdeModulePkg/Core/Dxe/FwVolBlock/FwVolBlock.c 2013-09-16
01:48:08 UTC (rev 14670)
+++ trunk/edk2/MdeModulePkg/Core/Dxe/FwVolBlock/FwVolBlock.c 2013-09-16
01:50:44 UTC (rev 14671)
@@ -474,22 +474,31 @@
if (FwVolHeader->Signature != EFI_FVH_SIGNATURE) {
return EFI_VOLUME_CORRUPTED;
}
+
//
- // Get FvHeader alignment
+ // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first
byte of the volume
+ // can be aligned on any power-of-two boundary. A weakly aligned volume can
not be moved from
+ // its initial linked location and maintain its alignment.
//
- FvAlignment = 1 << ((FwVolHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);
- //
- // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS
alignment value.
- //
- if (FvAlignment < 8) {
- FvAlignment = 8;
- }
- if ((UINTN)BaseAddress % FvAlignment != 0) {
+ if ((FwVolHeader->Attributes & EFI_FVB2_WEAK_ALIGNMENT) !=
EFI_FVB2_WEAK_ALIGNMENT) {
//
- // FvImage buffer is not at its required alignment.
+ // Get FvHeader alignment
//
- return EFI_VOLUME_CORRUPTED;
+ FvAlignment = 1 << ((FwVolHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);
+ //
+ // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS
alignment value.
+ //
+ if (FvAlignment < 8) {
+ FvAlignment = 8;
+ }
+ if ((UINTN)BaseAddress % FvAlignment != 0) {
+ //
+ // FvImage buffer is not at its required alignment.
+ //
+ return EFI_VOLUME_CORRUPTED;
+ }
}
+
//
// Allocate EFI_FW_VOL_BLOCK_DEVICE
//
Modified: trunk/edk2/MdeModulePkg/Core/Pei/FwVol/FwVol.c
===================================================================
--- trunk/edk2/MdeModulePkg/Core/Pei/FwVol/FwVol.c 2013-09-16 01:48:08 UTC
(rev 14670)
+++ trunk/edk2/MdeModulePkg/Core/Pei/FwVol/FwVol.c 2013-09-16 01:50:44 UTC
(rev 14671)
@@ -1,7 +1,7 @@
/** @file
Pei Core Firmware File System service routines.
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
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
@@ -226,7 +226,7 @@
IN CONST EFI_GUID *FileName, OPTIONAL
IN EFI_FV_FILETYPE SearchType,
IN OUT EFI_PEI_FILE_HANDLE *FileHandle,
- IN OUT EFI_PEI_FV_HANDLE *AprioriFile OPTIONAL
+ IN OUT EFI_PEI_FILE_HANDLE *AprioriFile OPTIONAL
)
{
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
@@ -1112,26 +1112,33 @@
}
//
- // FvAlignment must be more than 8 bytes required by FvHeader structure.
+ // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first
byte of the volume
+ // can be aligned on any power-of-two boundary. A weakly aligned volume can
not be moved from
+ // its initial linked location and maintain its alignment.
//
- FvAlignment = 1 << ((ReadUnaligned32 (&FvHeader->Attributes) &
EFI_FVB2_ALIGNMENT) >> 16);
- if (FvAlignment < 8) {
- FvAlignment = 8;
- }
-
- //
- // Check FvImage
- //
- if ((UINTN) FvHeader % FvAlignment != 0) {
- FvLength = ReadUnaligned64 (&FvHeader->FvLength);
- NewFvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvLength),
FvAlignment);
- if (NewFvBuffer == NULL) {
- return EFI_OUT_OF_RESOURCES;
+ if ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_WEAK_ALIGNMENT) !=
EFI_FVB2_WEAK_ALIGNMENT) {
+ //
+ // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS
alignment value.
+ //
+ FvAlignment = 1 << ((ReadUnaligned32 (&FvHeader->Attributes) &
EFI_FVB2_ALIGNMENT) >> 16);
+ if (FvAlignment < 8) {
+ FvAlignment = 8;
}
- CopyMem (NewFvBuffer, FvHeader, (UINTN) FvLength);
- FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) NewFvBuffer;
+
+ //
+ // Check FvImage
+ //
+ if ((UINTN) FvHeader % FvAlignment != 0) {
+ FvLength = ReadUnaligned64 (&FvHeader->FvLength);
+ NewFvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32)
FvLength), FvAlignment);
+ if (NewFvBuffer == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+ CopyMem (NewFvBuffer, FvHeader, (UINTN) FvLength);
+ FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) NewFvBuffer;
+ }
}
-
+
Status = ParentFvPpi->GetVolumeInfo (ParentFvPpi, ParentFvHandle,
&ParentFvImageInfo);
ASSERT_EFI_ERROR (Status);
Modified: trunk/edk2/MdePkg/Include/Pi/PiFirmwareVolume.h
===================================================================
--- trunk/edk2/MdePkg/Include/Pi/PiFirmwareVolume.h 2013-09-16 01:48:08 UTC
(rev 14670)
+++ trunk/edk2/MdePkg/Include/Pi/PiFirmwareVolume.h 2013-09-16 01:50:44 UTC
(rev 14671)
@@ -1,7 +1,7 @@
/** @file
The firmware volume related definitions in PI.
- Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
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
@@ -11,7 +11,7 @@
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
IMPLIED.
@par Revision Reference:
- PI Version 1.2C
+ PI Version 1.3
**/
@@ -86,8 +86,8 @@
#define EFI_FVB2_ALIGNMENT_512M 0x001D0000
#define EFI_FVB2_ALIGNMENT_1G 0x001E0000
#define EFI_FVB2_ALIGNMENT_2G 0x001F0000
+#define EFI_FVB2_WEAK_ALIGNMENT 0x80000000
-
typedef struct {
///
/// The number of sequential blocks which are of the same size.
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13.
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits