From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-x22e.google.com (mail-wr0-x22e.google.com [IPv6:2a00:1450:400c:c0c::22e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id CC8C5802A5 for ; Tue, 14 Mar 2017 01:01:12 -0700 (PDT) Received: by mail-wr0-x22e.google.com with SMTP id l37so118384909wrc.1 for ; Tue, 14 Mar 2017 01:01:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=BhtiWMd5S96t+Zpnd/sW28vNKUi0deuD2mEFljPpbPo=; b=OQlh7OQo+qCSgMoIqpFEUEX8kcp4DHcPfZb4350yFudvIPBz7ZnO1kzOhd7Wq8c0fJ 6X1/7uu+RF1krKb90myAEC+sT7sijRwGG3yY3p9Bp+b4HwLFFS3fRj+xHSqUV9Uwu2k6 eOXZ95ZkbvxCi23Iu2fukLCAjMyv+qCVRCN1Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=BhtiWMd5S96t+Zpnd/sW28vNKUi0deuD2mEFljPpbPo=; b=saSC+De1cmY7pR8He4Jxf8UaSVQvbVgh67GVkvmDzuxnpwWdWkXk5W6H8NYpQF6dXK sZPVILEmqqO4LxeosYPVXSetB7Akaya1siBrp82H/5ZdNSI4vzRmRdvtuiOgxBXjWOKA 32tbcx7dkbEM+wuQZRefzAoJffON2W+2/Mv0Tysej4lM0hPepRE4NS2+qTHgO/VuWexM Vy9w443FTuIQ3hV1tyNoQ+HqL1ckFmP71u4FRp7c3qxAJcnvXqWz9lY2ZK4XuBsn2cCt 9jX92hebO74ZK+EZIg3FQLNa1RfYpv/HLGOUyCdUVAW44Hw3C9rWEbKYfPMc0jEWj5i6 B95w== X-Gm-Message-State: AMke39n2HUJrD95y9mecU1yxmMBzzbwzATjODZGt9a5qqWoOUsTmwCNvbfdFRdHvw0jAWBN+ X-Received: by 10.223.155.135 with SMTP id d7mr29169323wrc.99.1489478470978; Tue, 14 Mar 2017 01:01:10 -0700 (PDT) Received: from localhost.localdomain ([197.130.229.126]) by smtp.gmail.com with ESMTPSA id p93sm27974450wrc.67.2017.03.14.01.01.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 14 Mar 2017 01:01:10 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org Cc: ryan.harkin@linaro.org, sigmaepsilon92@gmail.com, lersek@redhat.com, Ard Biesheuvel Date: Tue, 14 Mar 2017 08:01:04 +0000 Message-Id: <1489478464-5737-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [PATCH v2] EmbeddedPkg/PrePiLib: allocate code pages for DxeCore X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Mar 2017 08:01:13 -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 Tested-by: Michael Zimmermann --- v2: add missing MemoryAllocationLib.h include add Michael's T/b EmbeddedPkg/Library/PrePiLib/PrePi.h | 1 + EmbeddedPkg/Library/PrePiLib/PrePiLib.c | 34 +++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/EmbeddedPkg/Library/PrePiLib/PrePi.h b/EmbeddedPkg/Library/PrePiLib/PrePi.h index 607561cd2496..84eca23ec8a6 100644 --- a/EmbeddedPkg/Library/PrePiLib/PrePi.h +++ b/EmbeddedPkg/Library/PrePiLib/PrePi.h @@ -28,6 +28,7 @@ #include #include #include +#include #include diff --git a/EmbeddedPkg/Library/PrePiLib/PrePiLib.c b/EmbeddedPkg/Library/PrePiLib/PrePiLib.c index 9a1ef344df6e..bba8e7384edc 100644 --- a/EmbeddedPkg/Library/PrePiLib/PrePiLib.c +++ b/EmbeddedPkg/Library/PrePiLib/PrePiLib.c @@ -28,6 +28,38 @@ 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 = GET_NEXT_HOB (Hob); + Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw); + } + + ASSERT (FALSE); + + FreePages (Alloc, Pages); + return NULL; +} + EFI_STATUS EFIAPI @@ -54,7 +86,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); -- 2.7.4