]> git.proxmox.com Git - mirror_edk2.git/commitdiff
IntelFrameworkModulePkg: Add DxeCapsuleLib
authorjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 2 Sep 2011 21:31:02 +0000 (21:31 +0000)
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 2 Sep 2011 21:31:02 +0000 (21:31 +0000)
Signed-off-by: jljusten
Reviewed-by: rsun3
Reviewed-by: lgao4
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12274 6f19259b-4bc3-4df7-8a09-765794883524

IntelFrameworkModulePkg/IntelFrameworkModulePkg.dsc
IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.c [new file with mode: 0644]
IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.inf [new file with mode: 0644]

index 97d922895239e03ced93278eb6c6d59a49ead76e..3fc3bcca69aa6daa82db1604035b801b8693f724 100644 (file)
   IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf\r
   IntelFrameworkModulePkg/Library/PlatformBdsLibNull/PlatformBdsLibNull.inf\r
   IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf\r
+  IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.inf\r
 \r
   IntelFrameworkModulePkg/Bus/Pci/IdeBusDxe/IdeBusDxe.inf\r
   IntelFrameworkModulePkg/Bus/Isa/IsaBusDxe/IsaBusDxe.inf\r
diff --git a/IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.c b/IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.c
new file mode 100644 (file)
index 0000000..12c7272
--- /dev/null
@@ -0,0 +1,141 @@
+/** @file\r
+  Capsule Library instance to update capsule image to flash.\r
+\r
+  Copyright (c) 2007 - 2010, Intel Corporation. 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
+#include <PiDxe.h>\r
+#include <Guid/Capsule.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DxeServicesTableLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/CapsuleLib.h>\r
+\r
+/**\r
+  Those capsules supported by the firmwares.\r
+\r
+  @param  CapsuleHeader    Points to a capsule header.\r
+\r
+  @retval EFI_SUCESS       Input capsule is supported by firmware.\r
+  @retval EFI_UNSUPPORTED  Input capsule is not supported by the firmware.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SupportCapsuleImage (\r
+  IN EFI_CAPSULE_HEADER *CapsuleHeader\r
+  )\r
+{\r
+  if (CompareGuid (&gEfiCapsuleGuid, &CapsuleHeader->CapsuleGuid)) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  The firmware implements to process the capsule image.\r
+\r
+  @param  CapsuleHeader         Points to a capsule header.\r
+\r
+  @retval EFI_SUCESS            Process Capsule Image successfully.\r
+  @retval EFI_UNSUPPORTED       Capsule image is not supported by the firmware.\r
+  @retval EFI_VOLUME_CORRUPTED  FV volume in the capsule is corrupted.\r
+  @retval EFI_OUT_OF_RESOURCES  Not enough memory.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ProcessCapsuleImage (\r
+  IN EFI_CAPSULE_HEADER *CapsuleHeader\r
+  )\r
+{\r
+  UINT32                       Length;\r
+  EFI_FIRMWARE_VOLUME_HEADER   *FvImage;\r
+  EFI_FIRMWARE_VOLUME_HEADER   *ProcessedFvImage;\r
+  EFI_STATUS                   Status;\r
+  EFI_HANDLE                   FvProtocolHandle;\r
+  UINT32                       FvAlignment;\r
+\r
+  FvImage = NULL;\r
+  ProcessedFvImage = NULL;\r
+  Status  = EFI_SUCCESS;\r
+\r
+  if (SupportCapsuleImage (CapsuleHeader) != EFI_SUCCESS) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Skip the capsule header, move to the Firware Volume\r
+  //\r
+  FvImage = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINT8 *) CapsuleHeader + CapsuleHeader->HeaderSize);\r
+  Length  = CapsuleHeader->CapsuleImageSize - CapsuleHeader->HeaderSize;\r
+\r
+  while (Length != 0) {\r
+    //\r
+    // Point to the next firmware volume header, and then\r
+    // call the DXE service to process it.\r
+    //\r
+    if (FvImage->FvLength > (UINTN) Length) {\r
+      //\r
+      // Notes: need to stuff this status somewhere so that the\r
+      // error can be detected at OS runtime\r
+      //\r
+      Status = EFI_VOLUME_CORRUPTED;\r
+      break;\r
+    }\r
+\r
+    FvAlignment = 1 << ((FvImage->Attributes & EFI_FVB2_ALIGNMENT) >> 16);\r
+    //\r
+    // FvAlignment must be more than 8 bytes required by FvHeader structure.\r
+    //\r
+    if (FvAlignment < 8) {\r
+      FvAlignment = 8;\r
+    }\r
+    //\r
+    // Check FvImage Align is required.\r
+    //\r
+    if (((UINTN) FvImage % FvAlignment) == 0) {\r
+      ProcessedFvImage = FvImage;\r
+    } else {\r
+      //\r
+      // Allocate new aligned buffer to store FvImage.\r
+      //\r
+      ProcessedFvImage = (EFI_FIRMWARE_VOLUME_HEADER *) AllocateAlignedPages ((UINTN) EFI_SIZE_TO_PAGES (FvImage->FvLength), (UINTN) FvAlignment);\r
+      if (ProcessedFvImage == NULL) {\r
+        Status = EFI_OUT_OF_RESOURCES;\r
+        break;\r
+      }\r
+      CopyMem (ProcessedFvImage, FvImage, (UINTN) FvImage->FvLength);\r
+    }\r
+\r
+    Status = gDS->ProcessFirmwareVolume (\r
+                  (VOID *) ProcessedFvImage,\r
+                  (UINTN) ProcessedFvImage->FvLength,\r
+                  &FvProtocolHandle\r
+                  );\r
+    if (EFI_ERROR (Status)) {\r
+      break;\r
+    }\r
+    //\r
+    // Call the dispatcher to dispatch any drivers from the produced firmware volume\r
+    //\r
+    gDS->Dispatch ();\r
+    //\r
+    // On to the next FV in the capsule\r
+    //\r
+    Length -= (UINT32) FvImage->FvLength;\r
+    FvImage = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINT8 *) FvImage + FvImage->FvLength);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
diff --git a/IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.inf b/IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.inf
new file mode 100644 (file)
index 0000000..c11d8f7
--- /dev/null
@@ -0,0 +1,47 @@
+## @file\r
+# Capsule library instance for DXE_DRIVER, DXE_RUNTIME_DRIVER\r
+#\r
+# Copyright (c) 2007 - 2011, Intel Corporation. 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                      = DxeCapsuleLib\r
+  FILE_GUID                      = 654950df-1ede-4b04-b144-6b77845736ad\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = CapsuleLib|DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources]\r
+  DxeCapsuleLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseMemoryLib\r
+  DebugLib\r
+  MemoryAllocationLib\r
+  DxeServicesTableLib\r
+\r
+[Guids]\r
+  gEfiCapsuleGuid                         # SOMETIMES_CONSUMED\r
+  
\ No newline at end of file