]> git.proxmox.com Git - mirror_edk2.git/commitdiff
EmbeddedPkg/PrePiLib: allocate code pages for DxeCore
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 14 Mar 2017 08:01:04 +0000 (08:01 +0000)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 14 Mar 2017 20:08:31 +0000 (20:08 +0000)
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>
EmbeddedPkg/Library/PrePiLib/PrePi.h
EmbeddedPkg/Library/PrePiLib/PrePiLib.c

index 607561cd2496e6a2b7d9e7e9e3ebe0bd5a9b81c2..b39c3b43464e993ace83b04acd9cb104eb2c2363 100644 (file)
@@ -26,6 +26,7 @@
 #include <Library/UefiDecompressLib.h>\r
 #include <Library/PeCoffLib.h>\r
 #include <Library/CacheMaintenanceLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
 #include <Library/TimerLib.h>\r
 #include <Library/PerformanceLib.h>\r
 \r
index 9a1ef344df6e4c5f027fb6db050c8ddb500dd0a8..d119cf33a5d36772bbe38437921ff6ead07a9cdb 100644 (file)
@@ -28,6 +28,37 @@ SecWinNtPeiLoadFile (
   IN  EFI_PHYSICAL_ADDRESS    *EntryPoint\r
   );\r
 \r
+STATIC\r
+VOID*\r
+EFIAPI\r
+AllocateCodePages (\r
+  IN  UINTN     Pages\r
+  )\r
+{\r
+  VOID                    *Alloc;\r
+  EFI_PEI_HOB_POINTERS    Hob;\r
+\r
+  Alloc = AllocatePages (Pages);\r
+  if (Alloc == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  // find the HOB we just created, and change the type to EfiBootServicesCode\r
+  Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);\r
+  while (Hob.Raw != NULL) {\r
+    if (Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress == (UINTN)Alloc) {\r
+      Hob.MemoryAllocation->AllocDescriptor.MemoryType = EfiBootServicesCode;\r
+      return Alloc;\r
+    }\r
+    Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, GET_NEXT_HOB (Hob));\r
+  }\r
+\r
+  ASSERT (FALSE);\r
+\r
+  FreePages (Alloc, Pages);\r
+  return NULL;\r
+}\r
+\r
 \r
 EFI_STATUS\r
 EFIAPI\r
@@ -54,7 +85,7 @@ LoadPeCoffImage (
   //\r
   // Allocate Memory for the image\r
   //\r
-  Buffer = AllocatePages (EFI_SIZE_TO_PAGES((UINT32)ImageContext.ImageSize));\r
+  Buffer = AllocateCodePages (EFI_SIZE_TO_PAGES((UINT32)ImageContext.ImageSize));\r
   ASSERT (Buffer != 0);\r
 \r
 \r