]> git.proxmox.com Git - mirror_edk2.git/blobdiff - QuarkPlatformPkg/Library/PlatformBootManagerLib/PlatformBootManager.c
QuarkPlatformPkg/PlatformBootManager: Add capsule/recovery handling.
[mirror_edk2.git] / QuarkPlatformPkg / Library / PlatformBootManagerLib / PlatformBootManager.c
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