summaryrefslogtreecommitdiffstats
path: root/EmbeddedPkg/Library
diff options
context:
space:
mode:
authorArd Biesheuvel <ard.biesheuvel@linaro.org>2017-03-14 08:01:04 +0000
committerArd Biesheuvel <ard.biesheuvel@linaro.org>2017-03-14 20:08:31 +0000
commit6ac97ad31edbd9c8cdea778f452273974c589bf1 (patch)
tree1c744104ac2c848afe6d5312e06dd3e56a32e727 /EmbeddedPkg/Library
parentc03f5b2c42911c6af436beb7bbc4f63dd054fc83 (diff)
downloadedk2-6ac97ad31edbd9c8cdea778f452273974c589bf1.tar.gz
edk2-6ac97ad31edbd9c8cdea778f452273974c589bf1.tar.bz2
edk2-6ac97ad31edbd9c8cdea778f452273974c589bf1.zip
EmbeddedPkg/PrePiLib: allocate code pages for DxeCore
The recently introduced memory protection features inadvertently broke the boot on all PrePi platforms, because the changes to explicitly use EfiBootServicesCode for loading the DxeCore PE/COFF image need to be applied in a different way for PrePi. So add a simple helper function that sets the type of an allocation to EfiBootServicesCode, and invoke it to allocate the space for DxeCore. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Tested-by: Michael Zimmermann <sigmaepsilon92@gmail.com> Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Diffstat (limited to 'EmbeddedPkg/Library')
-rw-r--r--EmbeddedPkg/Library/PrePiLib/PrePi.h1
-rw-r--r--EmbeddedPkg/Library/PrePiLib/PrePiLib.c33
2 files changed, 33 insertions, 1 deletions
diff --git a/EmbeddedPkg/Library/PrePiLib/PrePi.h b/EmbeddedPkg/Library/PrePiLib/PrePi.h
index 607561cd24..b39c3b4346 100644
--- a/EmbeddedPkg/Library/PrePiLib/PrePi.h
+++ b/EmbeddedPkg/Library/PrePiLib/PrePi.h
@@ -26,6 +26,7 @@
#include <Library/UefiDecompressLib.h>
#include <Library/PeCoffLib.h>
#include <Library/CacheMaintenanceLib.h>
+#include <Library/MemoryAllocationLib.h>
#include <Library/TimerLib.h>
#include <Library/PerformanceLib.h>
diff --git a/EmbeddedPkg/Library/PrePiLib/PrePiLib.c b/EmbeddedPkg/Library/PrePiLib/PrePiLib.c
index 9a1ef344df..d119cf33a5 100644
--- a/EmbeddedPkg/Library/PrePiLib/PrePiLib.c
+++ b/EmbeddedPkg/Library/PrePiLib/PrePiLib.c
@@ -28,6 +28,37 @@ SecWinNtPeiLoadFile (
IN EFI_PHYSICAL_ADDRESS *EntryPoint
);
+STATIC
+VOID*
+EFIAPI
+AllocateCodePages (
+ IN UINTN Pages
+ )
+{
+ VOID *Alloc;
+ EFI_PEI_HOB_POINTERS Hob;
+
+ Alloc = AllocatePages (Pages);
+ if (Alloc == NULL) {
+ return NULL;
+ }
+
+ // find the HOB we just created, and change the type to EfiBootServicesCode
+ Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);
+ while (Hob.Raw != NULL) {
+ if (Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress == (UINTN)Alloc) {
+ Hob.MemoryAllocation->AllocDescriptor.MemoryType = EfiBootServicesCode;
+ return Alloc;
+ }
+ Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, GET_NEXT_HOB (Hob));
+ }
+
+ ASSERT (FALSE);
+
+ FreePages (Alloc, Pages);
+ return NULL;
+}
+
EFI_STATUS
EFIAPI
@@ -54,7 +85,7 @@ LoadPeCoffImage (
//
// Allocate Memory for the image
//
- Buffer = AllocatePages (EFI_SIZE_TO_PAGES((UINT32)ImageContext.ImageSize));
+ Buffer = AllocateCodePages (EFI_SIZE_TO_PAGES((UINT32)ImageContext.ImageSize));
ASSERT (Buffer != 0);