OvmfPkg: PlatformPei: take no-exec DXE settings from the QEMU command line

Control them with:

  -fw_cfg name=opt/ovmf/PcdPropertiesTableEnable,file=no.txt \
  -fw_cfg name=opt/ovmf/PcdSetNxForStack,file=yes.txt

where the contents of the text files can be

  [0nN1yY](\n|\r\n)?

The macro trickery is not optimal, but it is caused by PcdSetBool(), which
is itself a macro, and can only take open-coded PCD names (ie. no
variables, like function parameters).

Cc: Jordan Justen <jordan.l.justen@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18471 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Laszlo Ersek 2015-09-15 08:35:14 +00:00 committed by lersek
parent c075d250f6
commit ab081a50e5
2 changed files with 65 additions and 2 deletions

View File

@ -242,6 +242,68 @@ MemMapInitialization (
} }
} }
EFI_STATUS
GetNamedFwCfgBoolean (
IN CHAR8 *FwCfgFileName,
OUT BOOLEAN *Setting
)
{
EFI_STATUS Status;
FIRMWARE_CONFIG_ITEM FwCfgItem;
UINTN FwCfgSize;
UINT8 Value[3];
Status = QemuFwCfgFindFile (FwCfgFileName, &FwCfgItem, &FwCfgSize);
if (EFI_ERROR (Status)) {
return Status;
}
if (FwCfgSize > sizeof Value) {
return EFI_BAD_BUFFER_SIZE;
}
QemuFwCfgSelectItem (FwCfgItem);
QemuFwCfgReadBytes (FwCfgSize, Value);
if ((FwCfgSize == 1) ||
(FwCfgSize == 2 && Value[1] == '\n') ||
(FwCfgSize == 3 && Value[1] == '\r' && Value[2] == '\n')) {
switch (Value[0]) {
case '0':
case 'n':
case 'N':
*Setting = FALSE;
return EFI_SUCCESS;
case '1':
case 'y':
case 'Y':
*Setting = TRUE;
return EFI_SUCCESS;
default:
break;
}
}
return EFI_PROTOCOL_ERROR;
}
#define UPDATE_BOOLEAN_PCD_FROM_FW_CFG(TokenName) \
do { \
BOOLEAN Setting; \
\
if (!EFI_ERROR (GetNamedFwCfgBoolean ( \
"opt/ovmf/" #TokenName, &Setting))) { \
PcdSetBool (TokenName, Setting); \
} \
} while (0)
VOID
NoexecDxeInitialization (
VOID
)
{
UPDATE_BOOLEAN_PCD_FROM_FW_CFG (PcdPropertiesTableEnable);
UPDATE_BOOLEAN_PCD_FROM_FW_CFG (PcdSetNxForStack);
}
VOID VOID
MiscInitialization ( MiscInitialization (
@ -438,10 +500,9 @@ InitializePlatform (
if (mBootMode != BOOT_ON_S3_RESUME) { if (mBootMode != BOOT_ON_S3_RESUME) {
ReserveEmuVariableNvStore (); ReserveEmuVariableNvStore ();
PeiFvInitialization (); PeiFvInitialization ();
MemMapInitialization (); MemMapInitialization ();
NoexecDxeInitialization ();
} }
MiscInitialization (); MiscInitialization ();

View File

@ -83,6 +83,8 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration
gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode
gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable
gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack
gEfiMdeModulePkgTokenSpaceGuid.PcdPropertiesTableEnable
gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddress gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddress
[Ppis] [Ppis]