]> git.proxmox.com Git - mirror_edk2.git/commitdiff
QuarkPlatformPkg/PlatformBootManager: Add capsule/recovery handling.
authorJiewen Yao <jiewen.yao@intel.com>
Wed, 21 Sep 2016 03:37:27 +0000 (11:37 +0800)
committerJiewen Yao <jiewen.yao@intel.com>
Tue, 8 Nov 2016 14:46:03 +0000 (22:46 +0800)
1) Add capsule and recovery boot path handling in platform BDS.
2) Add check if the platform is using default test key for capsule.
Produce PcdTestKeyUsed to indicate if there is any
test key used in current BIOS, such as recovery key,
or capsule update key.
Then the generic UI may consume this PCD to show warning information.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Kelly Steele <kelly.steele@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Chao Zhang <chao.b.zhang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Michael Kinney <michael.d.kinney@intel.com>
Tested-by: Michael Kinney <michael.d.kinney@intel.com>
QuarkPlatformPkg/Library/PlatformBootManagerLib/PlatformBootManager.c
QuarkPlatformPkg/Library/PlatformBootManagerLib/PlatformBootManager.h
QuarkPlatformPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf

index 19ff3d0f5c504620d79217618b7a61e71567f849..7cb96285679bbcc74f4c328bec788f95c2d52ce2 100644 (file)
@@ -2,7 +2,7 @@
 This file include all platform action which can be customized\r
 by IBV/OEM.\r
 \r
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\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
@@ -205,6 +205,8 @@ PlatformBootManagerBeforeConsole (
   EFI_INPUT_KEY                 Enter;\r
   EFI_INPUT_KEY                 F2;\r
   EFI_BOOT_MANAGER_LOAD_OPTION  BootOption;\r
+  ESRT_MANAGEMENT_PROTOCOL      *EsrtManagement;\r
+  EFI_BOOT_MODE                 BootMode;\r
   EFI_ACPI_S3_SAVE_PROTOCOL     *AcpiS3Save;\r
   EFI_HANDLE                    Handle;\r
   EFI_EVENT                     EndOfDxeEvent;\r
@@ -246,6 +248,40 @@ PlatformBootManagerBeforeConsole (
   //\r
   PlatformRegisterFvBootOption (&mUefiShellFileGuid, L"UEFI Shell", LOAD_OPTION_ACTIVE);\r
 \r
+  Status = gBS->LocateProtocol(&gEsrtManagementProtocolGuid, NULL, (VOID **)&EsrtManagement);\r
+  if (EFI_ERROR(Status)) {\r
+    EsrtManagement = NULL;\r
+  }\r
+\r
+  BootMode = GetBootModeHob();\r
+  switch (BootMode) {\r
+  case BOOT_ON_FLASH_UPDATE:\r
+    DEBUG((DEBUG_INFO, "ProcessCapsules Before EndOfDxe ......\n"));\r
+    Status = ProcessCapsules ();\r
+    DEBUG((DEBUG_INFO, "ProcessCapsules %r\n", Status));\r
+    break;\r
+  case BOOT_IN_RECOVERY_MODE:\r
+    break;\r
+  case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:\r
+  case BOOT_WITH_MINIMAL_CONFIGURATION:\r
+  case BOOT_ON_S4_RESUME:\r
+    if (EsrtManagement != NULL) {\r
+      //\r
+      // Lock ESRT cache repository before EndofDxe if ESRT sync is not needed\r
+      //\r
+      EsrtManagement->LockEsrtRepository();\r
+    }\r
+    break;\r
+  default:\r
+    //\r
+    // Require to sync ESRT from FMP in a new boot\r
+    //\r
+    if (EsrtManagement != NULL) {\r
+      EsrtManagement->SyncEsrtFmp();\r
+    }\r
+    break;\r
+  }\r
+\r
   //\r
   // Prepare for S3\r
   //\r
@@ -303,7 +339,64 @@ PlatformBootManagerAfterConsole (
   VOID\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
+  EFI_STATUS                     Status;\r
+  EFI_BOOT_MODE                  BootMode;\r
+  ESRT_MANAGEMENT_PROTOCOL       *EsrtManagement;\r
+  VOID                           *Buffer;\r
+  UINTN                          Size;\r
+\r
+  Status = gBS->LocateProtocol(&gEsrtManagementProtocolGuid, NULL, (VOID **)&EsrtManagement);\r
+  if (EFI_ERROR(Status)) {\r
+    EsrtManagement = NULL;\r
+  }\r
+\r
+  BootMode = GetBootModeHob();\r
+  switch (BootMode) {\r
+  case BOOT_ON_FLASH_UPDATE:\r
+    DEBUG((DEBUG_INFO, "Capsule Mode detected\n"));\r
+    if (FeaturePcdGet(PcdSupportUpdateCapsuleReset)) {\r
+      EfiBootManagerConnectAll ();\r
+      EfiBootManagerRefreshAllBootOption ();\r
+\r
+      //\r
+      // Always sync ESRT Cache from FMP Instances after connect all and before capsule process\r
+      //\r
+      if (EsrtManagement != NULL) {\r
+        EsrtManagement->SyncEsrtFmp();\r
+      }\r
+\r
+      DEBUG((DEBUG_INFO, "ProcessCapsules After ConnectAll ......\n"));\r
+      Status = ProcessCapsules();\r
+      DEBUG((DEBUG_INFO, "ProcessCapsules %r\n", Status));\r
+    }\r
+    break;\r
+\r
+  case BOOT_IN_RECOVERY_MODE:\r
+    DEBUG((DEBUG_INFO, "Recovery Mode detected\n"));\r
+    // Passthrough\r
+\r
+  case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:\r
+  case BOOT_WITH_MINIMAL_CONFIGURATION:\r
+  case BOOT_WITH_FULL_CONFIGURATION:\r
+  case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:\r
+  case BOOT_WITH_DEFAULT_SETTINGS:\r
+  default:\r
+    EfiBootManagerConnectAll ();\r
+    EfiBootManagerRefreshAllBootOption ();\r
+\r
+    //\r
+    // Sync ESRT Cache from FMP Instance on demand after Connect All\r
+    //\r
+    if ((BootMode != BOOT_ASSUMING_NO_CONFIGURATION_CHANGES) &&\r
+        (BootMode != BOOT_WITH_MINIMAL_CONFIGURATION) &&\r
+        (BootMode != BOOT_ON_S4_RESUME)) {\r
+      if (EsrtManagement != NULL) {\r
+        EsrtManagement->SyncEsrtFmp();\r
+      }\r
+    }\r
+\r
+    break;\r
+  }\r
 \r
   Print (\r
     L"\n"\r
@@ -312,6 +405,40 @@ PlatformBootManagerAfterConsole (
     L"\n"\r
     );\r
 \r
+  //\r
+  // Check if the platform is using test key.\r
+  //\r
+  Status = GetSectionFromAnyFv(\r
+             PcdGetPtr(PcdEdkiiRsa2048Sha256TestPublicKeyFileGuid),\r
+             EFI_SECTION_RAW,\r
+             0,\r
+             &Buffer,\r
+             &Size\r
+             );\r
+  if (!EFI_ERROR(Status)) {\r
+    if ((Size == PcdGetSize(PcdRsa2048Sha256PublicKeyBuffer)) &&\r
+        (CompareMem(Buffer, PcdGetPtr(PcdRsa2048Sha256PublicKeyBuffer), Size) == 0)) {\r
+      Print(L"WARNING: Recovery Test Key is used.\n");\r
+      PcdSetBoolS(PcdTestKeyUsed, TRUE);\r
+    }\r
+    FreePool(Buffer);\r
+  }\r
+  Status = GetSectionFromAnyFv(\r
+             PcdGetPtr(PcdEdkiiPkcs7TestPublicKeyFileGuid),\r
+             EFI_SECTION_RAW,\r
+             0,\r
+             &Buffer,\r
+             &Size\r
+             );\r
+  if (!EFI_ERROR(Status)) {\r
+    if ((Size == PcdGetSize(PcdPkcs7CertBuffer)) &&\r
+        (CompareMem(Buffer, PcdGetPtr(PcdPkcs7CertBuffer), Size) == 0)) {\r
+      Print(L"WARNING: Capsule Test Key is used.\n");\r
+      PcdSetBoolS(PcdTestKeyUsed, TRUE);\r
+    }\r
+    FreePool(Buffer);\r
+  }\r
+\r
   //\r
   // Use a DynamicHii type pcd to save the boot status, which is used to\r
   // control configuration mode, such as FULL/MINIMAL/NO_CHANGES configuration.\r
index 74138839cef8bde113eb10172f1421ad1b9f6edf..395f78b320b6fd4a713fe999aa6b56b3f8ceafc2 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Head file for BDS Platform specific code\r
 \r
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\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
@@ -21,6 +21,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Protocol/FirmwareVolume2.h>\r
 #include <Protocol/AcpiS3Save.h>\r
 #include <Protocol/DxeSmmReadyToLock.h>\r
+#include <Protocol/EsrtManagement.h>\r
 #include <Guid/DebugAgentGuid.h>\r
 #include <Guid/EventGroup.h>\r
 #include <Guid/PcAnsi.h>\r
@@ -32,9 +33,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/DevicePathLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
 #include <Library/UefiLib.h>\r
 #include <Library/UefiBootManagerLib.h>\r
-\r
+#include <Library/PrintLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/CapsuleLib.h>\r
+#include <Library/DxeServicesLib.h>\r
 \r
 typedef struct {\r
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
index d59f14ab3af6b2a07d5f567163f0a81ee1132c98..af399e529a9286f978fab575aa5bd38d588bdbfa 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 #  Include all platform action which can be customized by IBV/OEM.\r
 #\r
-#  Copyright (c) 2012 - 2015, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.<BR>\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
@@ -38,6 +38,9 @@
   IntelFrameworkPkg/IntelFrameworkPkg.dec\r
   IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec\r
   SourceLevelDebugPkg/SourceLevelDebugPkg.dec\r
+  QuarkPlatformPkg/QuarkPlatformPkg.dec\r
+  SecurityPkg/SecurityPkg.dec\r
+  SignedCapsulePkg/SignedCapsulePkg.dec\r
 \r
 [LibraryClasses]\r
   BaseLib\r
   UefiBootServicesTableLib\r
   UefiLib\r
   UefiBootManagerLib\r
+  PrintLib\r
+  HobLib\r
+  CapsuleLib\r
+  DxeServicesLib\r
 \r
 [Protocols]\r
   gEfiFirmwareVolume2ProtocolGuid\r
   gEfiAcpiS3SaveProtocolGuid\r
   gEfiDxeSmmReadyToLockProtocolGuid\r
+  gEsrtManagementProtocolGuid\r
 \r
 [Guids]\r
   gEfiPcAnsiGuid\r
   gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits\r
   gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType\r
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdBootState\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSupportUpdateCapsuleReset\r
+  gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiRsa2048Sha256TestPublicKeyFileGuid\r
+  gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiPkcs7TestPublicKeyFileGuid\r
+  gEfiSecurityPkgTokenSpaceGuid.PcdRsa2048Sha256PublicKeyBuffer\r
+  gEfiSecurityPkgTokenSpaceGuid.PcdPkcs7CertBuffer\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed\r
+\r