From: Star Zeng <star.zeng@intel.com>
To: edk2-devel@lists.01.org
Cc: Star Zeng <star.zeng@intel.com>, Liming Gao <liming.gao@intel.com>
Subject: [PATCH V2 3/4] MdeModulePkg DxeCore: Check FvImage alignment
Date: Wed, 29 Nov 2017 18:14:56 +0800 [thread overview]
Message-ID: <1511950497-9088-4-git-send-email-star.zeng@intel.com> (raw)
In-Reply-To: <1511950497-9088-1-git-send-email-star.zeng@intel.com>
No need to allocate aligned buffer if FvImage has been
at required alignment.
Then the code logic will be aligned with ProcessFvFile() in
MdeModulePkg/Core/Pei/FwVol/FwVol.c.
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
---
MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c | 32 ++++++++++++++++-----------
1 file changed, 19 insertions(+), 13 deletions(-)
diff --git a/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c b/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c
index 5eee71bb2cd3..c7b9224c0e33 100644
--- a/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c
+++ b/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c
@@ -1023,32 +1023,38 @@ CoreProcessFvImageFile (
// 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 ((FvHeader->Attributes & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {
+ if ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {
//
// Get FvHeader alignment
//
- FvAlignment = 1 << ((FvHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);
+ FvAlignment = 1 << ((ReadUnaligned32 (&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.
+ // Check FvImage alignment.
//
- AlignedBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), (UINTN) FvAlignment);
- if (AlignedBuffer == NULL) {
- FreePool (Buffer);
- return EFI_OUT_OF_RESOURCES;
- } else {
+ if ((UINTN) FvHeader % FvAlignment != 0) {
//
- // Move FvImage into the aligned buffer and release the original buffer.
+ // Allocate the aligned buffer for the FvImage.
//
- CopyMem (AlignedBuffer, Buffer, BufferSize);
- FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) AlignedBuffer;
- CoreFreePool (Buffer);
- Buffer = NULL;
+ 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;
+ }
}
}
//
--
2.7.0.windows.1
next prev parent reply other threads:[~2017-11-29 10:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-29 10:14 [PATCH 0/4] Add USED_SIZE FV_EXT_TYPE support Star Zeng
2017-11-29 10:14 ` [PATCH V2 1/4] MdePkg PiFirmwareVolume.h: Add USED_SIZE FV_EXT_TYPE definitions Star Zeng
2017-11-29 10:14 ` [PATCH V2 2/4] MdeModulePkg PeiCore: Support USED_SIZE FV_EXT_TYPE Star Zeng
2017-11-29 10:14 ` Star Zeng [this message]
2017-11-29 10:14 ` [PATCH V2 4/4] MdeModulePkg DxeCore: " Star Zeng
2017-11-30 11:09 ` [PATCH 0/4] Add USED_SIZE FV_EXT_TYPE support Gao, Liming
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1511950497-9088-4-git-send-email-star.zeng@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox