mirror of https://github.com/acidanthera/audk.git
MdePkg HobLib: Check FV alignment when building FV HOB
If the FvImage buffer is not at its required alignment, then ASSERT(). Also update the function header description of BuildFv(2)Hob() correspondingly. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=205 Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> Regression-tested-by: Laszlo Ersek <lersek@redhat.com>
This commit is contained in:
parent
619c488963
commit
471d6210a8
|
@ -8,7 +8,7 @@
|
||||||
allows the PEI phase to pass information to the DXE phase. HOBs are position
|
allows the PEI phase to pass information to the DXE phase. HOBs are position
|
||||||
independent and can be relocated easily to different memory memory locations.
|
independent and can be relocated easily to different memory memory locations.
|
||||||
|
|
||||||
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
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
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -304,6 +304,7 @@ BuildGuidDataHob (
|
||||||
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
|
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
|
||||||
|
|
||||||
If there is no additional space for HOB creation, then ASSERT().
|
If there is no additional space for HOB creation, then ASSERT().
|
||||||
|
If the FvImage buffer is not at its required alignment, then ASSERT().
|
||||||
|
|
||||||
@param BaseAddress The base address of the Firmware Volume.
|
@param BaseAddress The base address of the Firmware Volume.
|
||||||
@param Length The size of the Firmware Volume in bytes.
|
@param Length The size of the Firmware Volume in bytes.
|
||||||
|
@ -324,6 +325,7 @@ BuildFvHob (
|
||||||
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
|
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
|
||||||
|
|
||||||
If there is no additional space for HOB creation, then ASSERT().
|
If there is no additional space for HOB creation, then ASSERT().
|
||||||
|
If the FvImage buffer is not at its required alignment, then ASSERT().
|
||||||
|
|
||||||
@param BaseAddress The base address of the Firmware Volume.
|
@param BaseAddress The base address of the Firmware Volume.
|
||||||
@param Length The size of the Firmware Volume in bytes.
|
@param Length The size of the Firmware Volume in bytes.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/** @file
|
/** @file
|
||||||
HOB Library implementation for DxeCore driver.
|
HOB Library implementation for DxeCore driver.
|
||||||
|
|
||||||
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
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
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -385,6 +385,7 @@ BuildGuidDataHob (
|
||||||
for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
|
for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
|
||||||
|
|
||||||
If there is no additional space for HOB creation, then ASSERT().
|
If there is no additional space for HOB creation, then ASSERT().
|
||||||
|
If the FvImage buffer is not at its required alignment, then ASSERT().
|
||||||
|
|
||||||
@param BaseAddress The base address of the Firmware Volume.
|
@param BaseAddress The base address of the Firmware Volume.
|
||||||
@param Length The size of the Firmware Volume in bytes.
|
@param Length The size of the Firmware Volume in bytes.
|
||||||
|
@ -411,6 +412,7 @@ BuildFvHob (
|
||||||
for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
|
for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
|
||||||
|
|
||||||
If there is no additional space for HOB creation, then ASSERT().
|
If there is no additional space for HOB creation, then ASSERT().
|
||||||
|
If the FvImage buffer is not at its required alignment, then ASSERT().
|
||||||
|
|
||||||
@param BaseAddress The base address of the Firmware Volume.
|
@param BaseAddress The base address of the Firmware Volume.
|
||||||
@param Length The size of the Firmware Volume in bytes.
|
@param Length The size of the Firmware Volume in bytes.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/** @file
|
/** @file
|
||||||
HOB Library implemenation for Dxe Phase.
|
HOB Library implemenation for Dxe Phase.
|
||||||
|
|
||||||
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
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
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -418,6 +418,7 @@ BuildGuidDataHob (
|
||||||
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
|
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
|
||||||
|
|
||||||
If there is no additional space for HOB creation, then ASSERT().
|
If there is no additional space for HOB creation, then ASSERT().
|
||||||
|
If the FvImage buffer is not at its required alignment, then ASSERT().
|
||||||
|
|
||||||
@param BaseAddress The base address of the Firmware Volume.
|
@param BaseAddress The base address of the Firmware Volume.
|
||||||
@param Length The size of the Firmware Volume in bytes.
|
@param Length The size of the Firmware Volume in bytes.
|
||||||
|
@ -444,6 +445,7 @@ BuildFvHob (
|
||||||
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
|
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
|
||||||
|
|
||||||
If there is no additional space for HOB creation, then ASSERT().
|
If there is no additional space for HOB creation, then ASSERT().
|
||||||
|
If the FvImage buffer is not at its required alignment, then ASSERT().
|
||||||
|
|
||||||
@param BaseAddress The base address of the Firmware Volume.
|
@param BaseAddress The base address of the Firmware Volume.
|
||||||
@param Length The size of the Firmware Volume in bytes.
|
@param Length The size of the Firmware Volume in bytes.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/** @file
|
/** @file
|
||||||
Provide Hob Library functions for Pei phase.
|
Provide Hob Library functions for Pei phase.
|
||||||
|
|
||||||
Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
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
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -473,6 +473,62 @@ BuildGuidDataHob (
|
||||||
return CopyMem (HobData, Data, DataLength);
|
return CopyMem (HobData, Data, DataLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Check FV alignment.
|
||||||
|
|
||||||
|
@param BaseAddress The base address of the Firmware Volume.
|
||||||
|
@param Length The size of the Firmware Volume in bytes.
|
||||||
|
|
||||||
|
@retval TRUE FvImage buffer is at its required alignment.
|
||||||
|
@retval FALSE FvImage buffer is not at its required alignment.
|
||||||
|
|
||||||
|
**/
|
||||||
|
BOOLEAN
|
||||||
|
InternalCheckFvAlignment (
|
||||||
|
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
||||||
|
IN UINT64 Length
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
|
||||||
|
UINT32 FvAlignment;
|
||||||
|
|
||||||
|
FvAlignment = 0;
|
||||||
|
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress;
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
if ((FwVolHeader->Attributes & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {
|
||||||
|
//
|
||||||
|
// Get FvHeader 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) {
|
||||||
|
//
|
||||||
|
// FvImage buffer is not at its required alignment.
|
||||||
|
//
|
||||||
|
DEBUG ((
|
||||||
|
DEBUG_ERROR,
|
||||||
|
"Unaligned FvImage found at 0x%lx:0x%lx, the required alignment is 0x%x\n",
|
||||||
|
BaseAddress,
|
||||||
|
Length,
|
||||||
|
FvAlignment
|
||||||
|
));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Builds a Firmware Volume HOB.
|
Builds a Firmware Volume HOB.
|
||||||
|
|
||||||
|
@ -481,6 +537,7 @@ BuildGuidDataHob (
|
||||||
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
|
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
|
||||||
|
|
||||||
If there is no additional space for HOB creation, then ASSERT().
|
If there is no additional space for HOB creation, then ASSERT().
|
||||||
|
If the FvImage buffer is not at its required alignment, then ASSERT().
|
||||||
|
|
||||||
@param BaseAddress The base address of the Firmware Volume.
|
@param BaseAddress The base address of the Firmware Volume.
|
||||||
@param Length The size of the Firmware Volume in bytes.
|
@param Length The size of the Firmware Volume in bytes.
|
||||||
|
@ -495,6 +552,11 @@ BuildFvHob (
|
||||||
{
|
{
|
||||||
EFI_HOB_FIRMWARE_VOLUME *Hob;
|
EFI_HOB_FIRMWARE_VOLUME *Hob;
|
||||||
|
|
||||||
|
if (!InternalCheckFvAlignment (BaseAddress, Length)) {
|
||||||
|
ASSERT (FALSE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME));
|
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME));
|
||||||
if (Hob == NULL) {
|
if (Hob == NULL) {
|
||||||
return;
|
return;
|
||||||
|
@ -512,6 +574,7 @@ BuildFvHob (
|
||||||
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
|
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
|
||||||
|
|
||||||
If there is no additional space for HOB creation, then ASSERT().
|
If there is no additional space for HOB creation, then ASSERT().
|
||||||
|
If the FvImage buffer is not at its required alignment, then ASSERT().
|
||||||
|
|
||||||
@param BaseAddress The base address of the Firmware Volume.
|
@param BaseAddress The base address of the Firmware Volume.
|
||||||
@param Length The size of the Firmware Volume in bytes.
|
@param Length The size of the Firmware Volume in bytes.
|
||||||
|
@ -530,6 +593,11 @@ BuildFv2Hob (
|
||||||
{
|
{
|
||||||
EFI_HOB_FIRMWARE_VOLUME2 *Hob;
|
EFI_HOB_FIRMWARE_VOLUME2 *Hob;
|
||||||
|
|
||||||
|
if (!InternalCheckFvAlignment (BaseAddress, Length)) {
|
||||||
|
ASSERT (FALSE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV2, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME2));
|
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV2, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME2));
|
||||||
if (Hob == NULL) {
|
if (Hob == NULL) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue