]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/CapsuleApp: Enhance Capsule-On-Disk related functions.
authorxuwei6 <wei6.xu@intel.com>
Fri, 24 May 2019 08:52:35 +0000 (16:52 +0800)
committerZhang, Chao B <chao.b.zhang@intel.com>
Thu, 20 Jun 2019 08:50:40 +0000 (16:50 +0800)
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1840

1. Add missing '\n' in usage.
2. Fix the dead loop of CapsuleApp -L.
3. Fix the bug that CapsuleApp -OD cannot perform capsules in sub-
folder.
4. Optimize the handling for option -NR and -OD to support both
'CapsuleApp <Capsule> -OD -NR' and 'CapsuleApp <Capsule> -NR -OD'.
5. Check if Capsule-On-Disk is supported by "OsIndicationsSupported"
variable firstly before processing capsules. If not supported, prompt
an error message and quit the process.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Chao B Zhang <chao.b.zhang@intel.com>
Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
Reviewed-by: Chao B Zhang <chao.b.zhang@intel.com>
Acked-by: Hao A Wu <hao.a.wu@intel.com>
MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c

index e3c591dbf3c822c8127d8e09a28f4f5dcbc5ac01..0b5f7c86841808a18d7805ddb5375b5d507a739e 100644 (file)
@@ -849,7 +849,7 @@ PrintUsage (
   Print(L"Parameter:\n");\r
   Print(L"  -NR: No reset will be triggered for the capsule\n");\r
   Print(L"       with CAPSULE_FLAGS_PERSIST_ACROSS_RESET and without CAPSULE_FLAGS_INITIATE_RESET.\n");\r
-  Print(L"  -OD: Delivery of Capsules via file on Mass Storage device.");\r
+  Print(L"  -OD: Delivery of Capsules via file on Mass Storage device.\n");\r
   Print(L"  -S:  Dump capsule report variable (EFI_CAPSULE_REPORT_GUID),\n");\r
   Print(L"       which is defined in UEFI specification.\n");\r
   Print(L"  -C:  Clear capsule report variable (EFI_CAPSULE_REPORT_GUID),\n");\r
@@ -1020,40 +1020,39 @@ UefiMain (
     }\r
   }\r
 \r
-  if (ParaOdIndex != 0) {\r
-    if (ParaOdIndex == Argc - 1) {\r
+  if (ParaOdIndex > ParaNrIndex) {\r
+    if (ParaNrIndex != 0) {\r
+      CapsuleLastIndex = ParaNrIndex - 1;\r
+    } else {\r
+      CapsuleLastIndex = ParaOdIndex - 1;\r
+    }\r
+\r
+    if (ParaOdIndex == Argc -1) {\r
       MapFsStr = NULL;\r
     } else if (ParaOdIndex == Argc - 2) {\r
       MapFsStr = Argv[Argc-1];\r
     } else {\r
-      Print (L"CapsuleApp: Invalid Position for -OD Options\n");\r
+      Print (L"CapsuleApp: Cannot specify more than one FS mapping!\n");\r
       Status = EFI_INVALID_PARAMETER;\r
       goto Done;\r
     }\r
-\r
-    if (ParaNrIndex != 0) {\r
-      if (ParaNrIndex + 1 == ParaOdIndex) {\r
-        CapsuleLastIndex = ParaNrIndex - 1;\r
-      } else {\r
-        Print (L"CapsuleApp: Invalid Position for -NR Options\n");\r
-        Status = EFI_INVALID_PARAMETER;\r
-        goto Done;\r
-      }\r
-    } else {\r
+  } else if (ParaOdIndex < ParaNrIndex) {\r
+    if (ParaOdIndex != 0) {\r
       CapsuleLastIndex = ParaOdIndex - 1;\r
-    }\r
-  } else {\r
-    if (ParaNrIndex != 0) {\r
-      if (ParaNrIndex == Argc -1) {\r
-        CapsuleLastIndex = ParaNrIndex - 1;\r
+      if (ParaOdIndex == ParaNrIndex - 1) {\r
+        MapFsStr = NULL;\r
+      } else if (ParaOdIndex == ParaNrIndex - 2) {\r
+        MapFsStr = Argv[ParaOdIndex + 1];\r
       } else {\r
-        Print (L"CapsuleApp: Invalid Position for -NR Options\n");\r
+        Print (L"CapsuleApp: Cannot specify more than one FS mapping!\n");\r
         Status = EFI_INVALID_PARAMETER;\r
         goto Done;\r
       }\r
     } else {\r
-      CapsuleLastIndex = Argc - 1;\r
+      CapsuleLastIndex = ParaNrIndex - 1;\r
     }\r
+  } else {\r
+    CapsuleLastIndex = Argc - 1;\r
   }\r
 \r
   CapsuleNum = CapsuleLastIndex - CapsuleFirstIndex + 1;\r
index b81c5b7b3afe05549608c7bc7522ba93f0a5da50..0e0c566702dc901d603ad5330a9603a759da0da0 100644 (file)
@@ -812,8 +812,8 @@ DumpCapsuleFromDisk (
   //\r
   // Get file count first\r
   //\r
+  Status = FileHandleFindFirstFile (DirHandle, &FileInfo);\r
   do {\r
-    Status = FileHandleFindFirstFile (DirHandle, &FileInfo);\r
     if (EFI_ERROR (Status) || FileInfo == NULL) {\r
       Print (L"Get File Info Fail. Status = %r\n", Status);\r
       goto Done;\r
@@ -846,8 +846,8 @@ DumpCapsuleFromDisk (
   //\r
   // Get all file info\r
   //\r
+  Status = FileHandleFindFirstFile (DirHandle, &FileInfo);\r
   do {\r
-    Status = FileHandleFindFirstFile (DirHandle, &FileInfo);\r
     if (EFI_ERROR (Status) || FileInfo == NULL) {\r
       Print (L"Get File Info Fail. Status = %r\n", Status);\r
       goto Done;\r
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