ArmPlatformPkg: enable use of authenticated variables in NorFlashDxe
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Thu, 7 May 2015 15:18:14 +0000 (15:18 +0000)
committeroliviermartin <oliviermartin@Edk2>
Thu, 7 May 2015 15:18:14 +0000 (15:18 +0000)
The NorFlashDxe uses an explicit 'BEFORE xxx' Depex declaration to
ensure that it is dispatched before VariableRuntimeDxe, and uses the
file GUID of the latter as 'xxx' explicitly to accomplish that.

However, when enabling UEFI Secure Boot, this breaks down since the
authenticated VariableRuntimeDxe is a completely separate driver, with
a different GUID. Also, the hardcoded dependency on gEfiVariableGuid,
which is not used under UEFI Secure Boot, needs to be factored out in
order to allow this driver to be used.

So clone NorFlashDxe.inf into NorFlashAuthenticatedDxe.inf, and fix
up the dependencies so they refer to gEfiAuthenticatedVariableGuid and
SecurityPkg/VariableAuthenticated/RuntimeDxe/VariableRuntimeDxe.inf
instead.

Contributed-under: TianoCore Contribution Agreement 1.0
Reviewed-by: Olivier Martin <olivier.martin@arm.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17355 6f19259b-4bc3-4df7-8a09-765794883524

ArmPlatformPkg/ArmPlatformPkg.dec
ArmPlatformPkg/ArmVExpressPkg/ArmVExpressPkg.dec
ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashAuthenticatedDxe.inf [new file with mode: 0644]
ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashAuthenticatedVariableDep.c [new file with mode: 0644]
ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h
ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf
ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c
ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashVariableDep.c [new file with mode: 0644]

index 9364bb92c5f022dc90435e465671690638448b95..58328345bd06295ae98c464d419d1c426ce9b909 100644 (file)
   # Following Guid must match FILE_GUID in MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf\r
   #\r
   gVariableRuntimeDxeFileGuid = { 0xcbd2e4d5, 0x7068, 0x4ff5, { 0xb4, 0x62, 0x98, 0x22, 0xb4, 0xad, 0x8d, 0x60 } }\r
+  #\r
+  # Following Guid must match FILE_GUID in SecurityPkg/VariableAuthenticated/RuntimeDxe/VariableRuntimeDxe.inf\r
+  #\r
+  gVariableAuthenticatedRuntimeDxeFileGuid = { 0x2226f30f, 0x3d5b, 0x402d,  {0x99, 0x36, 0xa9, 0x71, 0x84, 0xEB, 0x45, 0x16 } }\r
 \r
   ## Include/Guid/ArmGlobalVariableHob.h\r
   gArmGlobalVariableGuid      = { 0xc3253c90, 0xa24f, 0x4599, { 0xa6, 0x64, 0x1f, 0x88, 0x13, 0x77, 0x8f, 0xc9} }\r
index e8108bc34b561efae3821fd191c11a436029dddf..fd59375d9baf012a6ab3491c317f7e8670b6699d 100644 (file)
 \r
 [Guids.common]\r
   gArmVExpressTokenSpaceGuid    =  { 0x9c0aaed4, 0x74c5, 0x4043, { 0xb4, 0x17, 0xa3, 0x22, 0x38, 0x14, 0xce, 0x76 } }\r
-  #\r
-  # Following Guid must match FILE_GUID in MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf\r
-  #\r
-  gVariableRuntimeDxeFileGuid = { 0xcbd2e4d5, 0x7068, 0x4ff5, { 0xb4, 0x62, 0x98, 0x22, 0xb4, 0xad, 0x8d, 0x60 } }\r
 \r
 [PcdsFeatureFlag.common]\r
 \r
diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashAuthenticatedDxe.inf b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashAuthenticatedDxe.inf
new file mode 100644 (file)
index 0000000..ff8f048
--- /dev/null
@@ -0,0 +1,76 @@
+#/** @file\r
+#\r
+#  Component description file for NorFlashAuthenticatedDxe module\r
+#\r
+#  Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>\r
+#  Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = NorFlashAuthenticatedDxe\r
+  FILE_GUID                      = 10B86CEA-F2FE-456A-B1C7-4F506CA46005\r
+  MODULE_TYPE                    = DXE_RUNTIME_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = NorFlashInitialise\r
+\r
+[Sources.common]\r
+  NorFlashDxe.c\r
+  NorFlashFvbDxe.c\r
+  NorFlashBlockIoDxe.c\r
+  NorFlashAuthenticatedVariableDep.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+  SecurityPkg/SecurityPkg.dec\r
+\r
+[LibraryClasses]\r
+  IoLib\r
+  BaseLib\r
+  DebugLib\r
+  HobLib\r
+  NorFlashPlatformLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  UefiBootServicesTableLib\r
+  UefiRuntimeLib\r
+  DxeServicesTableLib\r
+\r
+[Guids]\r
+  gEfiSystemNvDataFvGuid\r
+  gEfiAuthenticatedVariableGuid\r
+  gEfiEventVirtualAddressChangeGuid\r
+\r
+[Protocols]\r
+  gEfiBlockIoProtocolGuid\r
+  gEfiDevicePathProtocolGuid\r
+  gEfiFirmwareVolumeBlockProtocolGuid\r
+  gEfiDiskIoProtocolGuid\r
+\r
+[Pcd.common]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize\r
+\r
+  gArmPlatformTokenSpaceGuid.PcdNorFlashCheckBlockLocked\r
+\r
+[Depex]\r
+  #\r
+  # NorFlashAuthenticatedDxe must be loaded before VariableAuthenticatedRuntimeDxe\r
+  # in case empty flash needs populating with default values\r
+  #\r
+  BEFORE gVariableAuthenticatedRuntimeDxeFileGuid\r
diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashAuthenticatedVariableDep.c b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashAuthenticatedVariableDep.c
new file mode 100644 (file)
index 0000000..2ea8ead
--- /dev/null
@@ -0,0 +1,19 @@
+/** @file  NorFlashAuthenticatedVariableDep.c\r
+\r
+  Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Base.h>\r
+\r
+#include <Include/Guid/AuthenticatedVariableFormat.h>\r
+\r
+CONST EFI_GUID* CONST mNorFlashVariableGuid = &gEfiAuthenticatedVariableGuid;\r
index c24680098f629541fe823a7356c778e7819f7907..d0b5c5b12f9e4ef5cc490af855db4a22fd3e6c21 100644 (file)
@@ -152,6 +152,8 @@ struct _NOR_FLASH_INSTANCE {
   NOR_FLASH_DEVICE_PATH               DevicePath;\r
 };\r
 \r
+extern CONST EFI_GUID* CONST          mNorFlashVariableGuid;\r
+\r
 EFI_STATUS\r
 NorFlashReadCfiData (\r
   IN  UINTN                   DeviceBaseAddress,\r
index a161c0399e52036be5f0b297794d4a473cdc4089..563d7573e7a25db20067a752a449fc5d7dbbe6cf 100644 (file)
@@ -26,6 +26,7 @@
   NorFlashDxe.c\r
   NorFlashFvbDxe.c\r
   NorFlashBlockIoDxe.c\r
+  NorFlashVariableDep.c\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
index 4f56bae330229404100ae448f4e1d4a27702e399..3ed3bb945ff681da40b7a5a1fdfd735e9fa0db98 100644 (file)
@@ -111,7 +111,7 @@ InitializeFvAndVariableStoreHeaders (
   // VARIABLE_STORE_HEADER\r
   //\r
   VariableStoreHeader = (VARIABLE_STORE_HEADER*)((UINTN)Headers + FirmwareVolumeHeader->HeaderLength);\r
-  CopyGuid (&VariableStoreHeader->Signature, &gEfiVariableGuid);\r
+  CopyGuid (&VariableStoreHeader->Signature, mNorFlashVariableGuid);\r
   VariableStoreHeader->Size = PcdGet32(PcdFlashNvStorageVariableSize) - FirmwareVolumeHeader->HeaderLength;\r
   VariableStoreHeader->Format            = VARIABLE_STORE_FORMATTED;\r
   VariableStoreHeader->State             = VARIABLE_STORE_HEALTHY;\r
@@ -178,7 +178,7 @@ ValidateFvHeader (
   VariableStoreHeader = (VARIABLE_STORE_HEADER*)((UINTN)FwVolHeader + FwVolHeader->HeaderLength);\r
 \r
   // Check the Variable Store Guid\r
-  if( CompareGuid (&VariableStoreHeader->Signature, &gEfiVariableGuid) == FALSE ) {\r
+  if (!CompareGuid (&VariableStoreHeader->Signature, mNorFlashVariableGuid)) {\r
     DEBUG ((EFI_D_ERROR, "ValidateFvHeader: Variable Store Guid non-compatible\n"));\r
     return EFI_NOT_FOUND;\r
   }\r
diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashVariableDep.c b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashVariableDep.c
new file mode 100644 (file)
index 0000000..4d52296
--- /dev/null
@@ -0,0 +1,19 @@
+/** @file  NorFlashVariableDep.c\r
+\r
+  Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Base.h>\r
+\r
+#include <Include/Guid/VariableFormat.h>\r
+\r
+CONST EFI_GUID* CONST mNorFlashVariableGuid = &gEfiVariableGuid;\r