]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
MdeModulePkg/CapsuleApp: Enhance Capsule-On-Disk related functions.
[mirror_edk2.git] / MdeModulePkg / Application / CapsuleApp / CapsuleOnDisk.c
index a11683d66c77a878c4b27f5eef24e831881e282e..df43a436f2c070a62f043426ec703a4719fb45fd 100644 (file)
@@ -23,6 +23,8 @@
 #include <Guid/GlobalVariable.h>\r
 #include <Guid/Gpt.h>\r
 \r
+#define MAX_CAPSULE_NUM 10\r
+\r
 EFI_GUID mCapsuleOnDiskBootOptionGuid = { 0x4CC29BB7, 0x2413, 0x40A2, { 0xB0, 0x6D, 0x25, 0x3E, 0x37, 0x10, 0xF5, 0x32 } };\r
 \r
 /**\r
@@ -744,6 +746,41 @@ SetCapsuleStatusVariable (
   return Status;\r
 }\r
 \r
+/**\r
+  Check if Capsule On Disk is supported.\r
+\r
+  @retval TRUE              Capsule On Disk is supported.\r
+  @retval FALSE             Capsule On Disk is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+IsCapsuleOnDiskSupported (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  UINT64                        OsIndicationsSupported;\r
+  UINTN                         DataSize;\r
+\r
+  DataSize = sizeof(UINT64);\r
+  Status = gRT->GetVariable (\r
+                  L"OsIndicationsSupported",\r
+                  &gEfiGlobalVariableGuid,\r
+                  NULL,\r
+                  &DataSize,\r
+                  &OsIndicationsSupported\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+\r
+  if (OsIndicationsSupported & EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED) {\r
+    return TRUE;\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
 /**\r
   Process Capsule On Disk.\r
 \r
@@ -770,6 +807,16 @@ ProcessCapsuleOnDisk (
   UINT16                          BootNext;\r
   EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Fs;\r
   BOOLEAN                         UpdateBootNext;\r
+  CHAR16                          *FileName[MAX_CAPSULE_NUM];\r
+  UINTN                           Index;\r
+\r
+  //\r
+  // Check if Capsule On Disk is supported\r
+  //\r
+  if (!IsCapsuleOnDiskSupported ()) {\r
+    Print (L"CapsuleApp: Capsule On Disk is not supported.\n");\r
+    return EFI_UNSUPPORTED;\r
+  }\r
 \r
   //\r
   // Get a valid file system from boot path\r
@@ -782,10 +829,17 @@ ProcessCapsuleOnDisk (
     return Status;\r
   }\r
 \r
+  //\r
+  // Get file name from file path\r
+  //\r
+  for (Index = 0; Index < CapsuleNum; Index ++) {\r
+    FileName[Index] = GetFileNameFromPath (FilePath[Index]);\r
+  }\r
+\r
   //\r
   // Copy capsule image to '\efi\UpdateCapsule\'\r
   //\r
-  Status = WriteUpdateFile (CapsuleBuffer, CapsuleBufferSize, FilePath, CapsuleNum, Fs);\r
+  Status = WriteUpdateFile (CapsuleBuffer, CapsuleBufferSize, FileName, CapsuleNum, Fs);\r
   if (EFI_ERROR (Status)) {\r
     Print (L"CapsuleApp: capsule image could not be copied for update.\n");\r
     return Status;\r