]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/CapsuleApp: Enhance Capsule-On-Disk related functions.
authorWei6 Xu <wei6.xu@intel.com>
Mon, 24 Jun 2019 05:21:35 +0000 (13:21 +0800)
committerZhang, Chao B <chao.b.zhang@intel.com>
Wed, 26 Jun 2019 07:08:18 +0000 (15:08 +0800)
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1840

1. Introduce an internal header file to put definitions in it.
2. Add missing '\n' in usage.
3. Fix the dead loop of CapsuleApp -L.
4. Fix the bug that CapsuleApp -OD cannot perform capsules in sub-
folder.
5. Optimize the handling for option -NR and -OD to support both
'CapsuleApp <Capsule> -OD -NR' and 'CapsuleApp <Capsule> -NR -OD'.
6. 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/AppSupport.c
MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
MdeModulePkg/Application/CapsuleApp/CapsuleApp.h [new file with mode: 0644]
MdeModulePkg/Application/CapsuleApp/CapsuleApp.inf
MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c

index d9ce1b4843f8544b9d269d3f511264b0772fbd25..8fe70dc3b6d8bfb3651245c84702b375962f5ae7 100644 (file)
@@ -1,21 +1,12 @@
 /** @file\r
   A shell application that triggers capsule update process.\r
 \r
-  Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
-#include <Uefi.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Protocol/SimpleFileSystem.h>\r
-#include <Protocol/ShellParameters.h>\r
-#include <Protocol/Shell.h>\r
-#include <Guid/FileInfo.h>\r
+#include "CapsuleApp.h"\r
 \r
 UINTN  Argc;\r
 CHAR16 **Argv;\r
index e3c591dbf3c822c8127d8e09a28f4f5dcbc5ac01..3439ce5febe0e045a9dc202883abbfd171fdbe8b 100644 (file)
@@ -6,36 +6,7 @@
 \r
 **/\r
 \r
-#include <Uefi.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/UefiRuntimeServicesTableLib.h>\r
-#include <Library/UefiLib.h>\r
-#include <Library/PrintLib.h>\r
-#include <Library/BmpSupportLib.h>\r
-#include <Protocol/GraphicsOutput.h>\r
-#include <Guid/GlobalVariable.h>\r
-#include <Guid/CapsuleReport.h>\r
-#include <Guid/SystemResourceTable.h>\r
-#include <Guid/FmpCapsule.h>\r
-#include <IndustryStandard/WindowsUxCapsule.h>\r
-\r
-#define CAPSULE_HEADER_SIZE  0x20\r
-\r
-#define NESTED_CAPSULE_HEADER_SIZE  SIZE_4KB\r
-#define SYSTEM_FIRMWARE_FLAG 0x50000\r
-#define DEVICE_FIRMWARE_FLAG 0x78010\r
-\r
-#define MAJOR_VERSION   1\r
-#define MINOR_VERSION   0\r
-\r
-#define MAX_CAPSULE_NUM 10\r
-\r
-extern UINTN  Argc;\r
-extern CHAR16 **Argv;\r
+#include "CapsuleApp.h"\r
 \r
 //\r
 // Define how many block descriptors we want to test with.\r
@@ -44,149 +15,6 @@ UINTN  NumberOfDescriptors = 1;
 UINTN  CapsuleFirstIndex;\r
 UINTN  CapsuleLastIndex;\r
 \r
-/**\r
-  Dump capsule information\r
-\r
-  @param[in] CapsuleName  The name of the capsule image.\r
-\r
-  @retval EFI_SUCCESS            The capsule information is dumped.\r
-  @retval EFI_UNSUPPORTED        Input parameter is not valid.\r
-**/\r
-EFI_STATUS\r
-DumpCapsule (\r
-  IN CHAR16                                        *CapsuleName\r
-  );\r
-\r
-/**\r
-  Dump capsule status variable.\r
-\r
-  @retval EFI_SUCCESS            The capsule status variable is dumped.\r
-  @retval EFI_UNSUPPORTED        Input parameter is not valid.\r
-**/\r
-EFI_STATUS\r
-DumpCapsuleStatusVariable (\r
-  VOID\r
-  );\r
-\r
-/**\r
-  Dump FMP protocol info.\r
-**/\r
-VOID\r
-DumpFmpData (\r
-  VOID\r
-  );\r
-\r
-/**\r
-  Dump FMP image data.\r
-\r
-  @param[in]  ImageTypeId   The ImageTypeId of the FMP image.\r
-                            It is used to identify the FMP protocol.\r
-  @param[in]  ImageIndex    The ImageIndex of the FMP image.\r
-                            It is the input parameter for FMP->GetImage().\r
-  @param[in]  ImageName     The file name to hold the output FMP image.\r
-**/\r
-VOID\r
-DumpFmpImage (\r
-  IN EFI_GUID  *ImageTypeId,\r
-  IN UINTN     ImageIndex,\r
-  IN CHAR16    *ImageName\r
-  );\r
-\r
-/**\r
-  Dump ESRT info.\r
-**/\r
-VOID\r
-DumpEsrtData (\r
-  VOID\r
-  );\r
-\r
-/**\r
-  Dump Provisioned Capsule.\r
-\r
-  @param[in]  DumpCapsuleInfo  The flag to indicate whether to dump the capsule inforomation.\r
-**/\r
-VOID\r
-DumpProvisionedCapsule (\r
-  IN BOOLEAN                      DumpCapsuleInfo\r
-  );\r
-\r
-/**\r
-  Dump all EFI System Partition.\r
-**/\r
-VOID\r
-DumpAllEfiSysPartition (\r
-  VOID\r
-  );\r
-\r
-/**\r
-  Process Capsule On Disk.\r
-\r
-  @param[in]  CapsuleBuffer       An array of pointer to capsule images\r
-  @param[in]  CapsuleBufferSize   An array of UINTN to capsule images size\r
-  @param[in]  FilePath            An array of capsule images file path\r
-  @param[in]  Map                 File system mapping string\r
-  @param[in]  CapsuleNum          The count of capsule images\r
-\r
-  @retval EFI_SUCCESS       Capsule on disk success.\r
-  @retval others            Capsule on disk fail.\r
-\r
-**/\r
-EFI_STATUS\r
-ProcessCapsuleOnDisk (\r
-  IN VOID                          **CapsuleBuffer,\r
-  IN UINTN                         *CapsuleBufferSize,\r
-  IN CHAR16                        **FilePath,\r
-  IN CHAR16                        *Map,\r
-  IN UINTN                         CapsuleNum\r
-  );\r
-\r
-/**\r
-  Read a file.\r
-\r
-  @param[in]  FileName        The file to be read.\r
-  @param[out] BufferSize      The file buffer size\r
-  @param[out] Buffer          The file buffer\r
-\r
-  @retval EFI_SUCCESS    Read file successfully\r
-  @retval EFI_NOT_FOUND  Shell protocol or file not found\r
-  @retval others         Read file failed\r
-**/\r
-EFI_STATUS\r
-ReadFileToBuffer (\r
-  IN  CHAR16                               *FileName,\r
-  OUT UINTN                                *BufferSize,\r
-  OUT VOID                                 **Buffer\r
-  );\r
-\r
-/**\r
-  Write a file.\r
-\r
-  @param[in] FileName        The file to be written.\r
-  @param[in] BufferSize      The file buffer size\r
-  @param[in] Buffer          The file buffer\r
-\r
-  @retval EFI_SUCCESS    Write file successfully\r
-  @retval EFI_NOT_FOUND  Shell protocol not found\r
-  @retval others         Write file failed\r
-**/\r
-EFI_STATUS\r
-WriteFileFromBuffer (\r
-  IN  CHAR16                               *FileName,\r
-  IN  UINTN                                BufferSize,\r
-  IN  VOID                                 *Buffer\r
-  );\r
-\r
-/**\r
-\r
-  This function parse application ARG.\r
-\r
-  @return Status\r
-**/\r
-EFI_STATUS\r
-GetArg (\r
-  VOID\r
-  );\r
-\r
 /**\r
   Create UX capsule.\r
 \r
@@ -849,7 +677,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 +848,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
diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.h b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.h
new file mode 100644 (file)
index 0000000..270d235
--- /dev/null
@@ -0,0 +1,240 @@
+/** @file\r
+  A shell application that triggers capsule update process.\r
+\r
+  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+\r
+#ifndef _CAPSULE_APP_H_\r
+#define _CAPSULE_APP_H_\r
+\r
+#include <Uefi.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/BmpSupportLib.h>\r
+#include <Library/FileHandleLib.h>\r
+#include <Library/SortLib.h>\r
+#include <Library/UefiBootManagerLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Protocol/GraphicsOutput.h>\r
+#include <Protocol/SimpleFileSystem.h>\r
+#include <Protocol/ShellParameters.h>\r
+#include <Protocol/Shell.h>\r
+#include <Protocol/FirmwareManagement.h>\r
+#include <Guid/GlobalVariable.h>\r
+#include <Guid/CapsuleReport.h>\r
+#include <Guid/SystemResourceTable.h>\r
+#include <Guid/FmpCapsule.h>\r
+#include <Guid/FileInfo.h>\r
+#include <Guid/ImageAuthentication.h>\r
+#include <Guid/CapsuleVendor.h>\r
+#include <Guid/Gpt.h>\r
+#include <IndustryStandard/WindowsUxCapsule.h>\r
+\r
+#define CAPSULE_HEADER_SIZE  0x20\r
+\r
+#define NESTED_CAPSULE_HEADER_SIZE  SIZE_4KB\r
+#define SYSTEM_FIRMWARE_FLAG 0x50000\r
+#define DEVICE_FIRMWARE_FLAG 0x78010\r
+\r
+#define MAJOR_VERSION   1\r
+#define MINOR_VERSION   0\r
+\r
+#define MAX_CAPSULE_NUM 10\r
+\r
+//\r
+// (20 * (6+5+2))+1) unicode characters from EFI FAT spec (doubled for bytes)\r
+//\r
+#define MAX_FILE_NAME_SIZE   522\r
+#define MAX_FILE_NAME_LEN    (MAX_FILE_NAME_SIZE / sizeof(CHAR16))\r
+\r
+extern UINTN  Argc;\r
+extern CHAR16 **Argv;\r
+\r
+/**\r
+\r
+  This function parse application ARG.\r
+\r
+  @return Status\r
+**/\r
+EFI_STATUS\r
+GetArg (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Get shell protocol.\r
+\r
+  @return Pointer to shell protocol.\r
+\r
+**/\r
+EFI_SHELL_PROTOCOL *\r
+GetShellProtocol (\r
+  VOID\r
+  );\r
+\r
+\r
+/**\r
+  Read a file.\r
+\r
+  @param[in]  FileName        The file to be read.\r
+  @param[out] BufferSize      The file buffer size\r
+  @param[out] Buffer          The file buffer\r
+\r
+  @retval EFI_SUCCESS    Read file successfully\r
+  @retval EFI_NOT_FOUND  Shell protocol or file not found\r
+  @retval others         Read file failed\r
+**/\r
+EFI_STATUS\r
+ReadFileToBuffer (\r
+  IN  CHAR16                               *FileName,\r
+  OUT UINTN                                *BufferSize,\r
+  OUT VOID                                 **Buffer\r
+  );\r
+\r
+/**\r
+  Write a file.\r
+\r
+  @param[in] FileName        The file to be written.\r
+  @param[in] BufferSize      The file buffer size\r
+  @param[in] Buffer          The file buffer\r
+\r
+  @retval EFI_SUCCESS    Write file successfully\r
+  @retval EFI_NOT_FOUND  Shell protocol not found\r
+  @retval others         Write file failed\r
+**/\r
+EFI_STATUS\r
+WriteFileFromBuffer (\r
+  IN  CHAR16                               *FileName,\r
+  IN  UINTN                                BufferSize,\r
+  IN  VOID                                 *Buffer\r
+  );\r
+\r
+\r
+/**\r
+  Dump capsule information\r
+\r
+  @param[in] CapsuleName  The name of the capsule image.\r
+\r
+  @retval EFI_SUCCESS            The capsule information is dumped.\r
+  @retval EFI_UNSUPPORTED        Input parameter is not valid.\r
+**/\r
+EFI_STATUS\r
+DumpCapsule (\r
+  IN CHAR16                                        *CapsuleName\r
+  );\r
+\r
+/**\r
+  Dump capsule status variable.\r
+\r
+  @retval EFI_SUCCESS            The capsule status variable is dumped.\r
+  @retval EFI_UNSUPPORTED        Input parameter is not valid.\r
+**/\r
+EFI_STATUS\r
+DumpCapsuleStatusVariable (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Dump FMP protocol info.\r
+**/\r
+VOID\r
+DumpFmpData (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Dump FMP image data.\r
+\r
+  @param[in]  ImageTypeId   The ImageTypeId of the FMP image.\r
+                            It is used to identify the FMP protocol.\r
+  @param[in]  ImageIndex    The ImageIndex of the FMP image.\r
+                            It is the input parameter for FMP->GetImage().\r
+  @param[in]  ImageName     The file name to hold the output FMP image.\r
+**/\r
+VOID\r
+DumpFmpImage (\r
+  IN EFI_GUID  *ImageTypeId,\r
+  IN UINTN     ImageIndex,\r
+  IN CHAR16    *ImageName\r
+  );\r
+\r
+/**\r
+  Dump ESRT info.\r
+**/\r
+VOID\r
+DumpEsrtData (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Dump Provisioned Capsule.\r
+\r
+  @param[in]  DumpCapsuleInfo  The flag to indicate whether to dump the capsule inforomation.\r
+**/\r
+VOID\r
+DumpProvisionedCapsule (\r
+  IN BOOLEAN                      DumpCapsuleInfo\r
+  );\r
+\r
+/**\r
+  Dump all EFI System Partition.\r
+**/\r
+VOID\r
+DumpAllEfiSysPartition (\r
+  VOID\r
+  );\r
+\r
+\r
+/**\r
+  Get SimpleFileSystem from boot option file path.\r
+\r
+  @param[in]  DevicePath     The file path of boot option\r
+  @param[out] FullPath       The full device path of boot device\r
+  @param[out] Fs             The file system within EfiSysPartition\r
+\r
+  @retval EFI_SUCCESS    Get file system successfully\r
+  @retval EFI_NOT_FOUND  No valid file system found\r
+  @retval others         Get file system failed\r
+\r
+**/\r
+EFI_STATUS\r
+GetEfiSysPartitionFromBootOptionFilePath (\r
+  IN  EFI_DEVICE_PATH_PROTOCOL         *DevicePath,\r
+  OUT EFI_DEVICE_PATH_PROTOCOL         **FullPath,\r
+  OUT EFI_SIMPLE_FILE_SYSTEM_PROTOCOL  **Fs\r
+  );\r
+\r
+\r
+/**\r
+  Process Capsule On Disk.\r
+\r
+  @param[in]  CapsuleBuffer       An array of pointer to capsule images\r
+  @param[in]  CapsuleBufferSize   An array of UINTN to capsule images size\r
+  @param[in]  FilePath            An array of capsule images file path\r
+  @param[in]  Map                 File system mapping string\r
+  @param[in]  CapsuleNum          The count of capsule images\r
+\r
+  @retval EFI_SUCCESS       Capsule on disk success.\r
+  @retval others            Capsule on disk fail.\r
+\r
+**/\r
+EFI_STATUS\r
+ProcessCapsuleOnDisk (\r
+  IN VOID                          **CapsuleBuffer,\r
+  IN UINTN                         *CapsuleBufferSize,\r
+  IN CHAR16                        **FilePath,\r
+  IN CHAR16                        *Map,\r
+  IN UINTN                         CapsuleNum\r
+  );\r
+\r
+#endif\r
+\r
index 8ca5e0410485090538b481218e9c9553efbb81c8..6ed0659835b2c2361e2255fde6b1a03c070450bb 100644 (file)
@@ -4,7 +4,7 @@
 # This application can trigger capsule update process. It can also\r
 # generate capsule image, or dump capsule variable information.\r
 #\r
-#  Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>\r
 #  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 ##\r
@@ -26,6 +26,7 @@
 \r
 [Sources]\r
   CapsuleApp.c\r
+  CapsuleApp.h\r
   CapsuleDump.c\r
   CapsuleOnDisk.c\r
   AppSupport.c\r
index b81c5b7b3afe05549608c7bc7522ba93f0a5da50..58a93568d01350d22744572defa943e0c44eaadc 100644 (file)
@@ -6,98 +6,7 @@
 \r
 **/\r
 \r
-#include <PiDxe.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/UefiRuntimeServicesTableLib.h>\r
-#include <Library/UefiLib.h>\r
-#include <Library/PrintLib.h>\r
-#include <Library/FileHandleLib.h>\r
-#include <Library/SortLib.h>\r
-#include <Library/UefiBootManagerLib.h>\r
-#include <Library/DevicePathLib.h>\r
-#include <Protocol/FirmwareManagement.h>\r
-#include <Protocol/SimpleFileSystem.h>\r
-#include <Protocol/Shell.h>\r
-#include <Guid/ImageAuthentication.h>\r
-#include <Guid/CapsuleReport.h>\r
-#include <Guid/SystemResourceTable.h>\r
-#include <Guid/FmpCapsule.h>\r
-#include <Guid/CapsuleVendor.h>\r
-#include <IndustryStandard/WindowsUxCapsule.h>\r
-\r
-//\r
-// (20 * (6+5+2))+1) unicode characters from EFI FAT spec (doubled for bytes)\r
-//\r
-#define MAX_FILE_NAME_SIZE   522\r
-#define MAX_FILE_NAME_LEN    (MAX_FILE_NAME_SIZE / sizeof(CHAR16))\r
-\r
-/**\r
-  Read a file.\r
-\r
-  @param[in]  FileName        The file to be read.\r
-  @param[out] BufferSize      The file buffer size\r
-  @param[out] Buffer          The file buffer\r
-\r
-  @retval EFI_SUCCESS    Read file successfully\r
-  @retval EFI_NOT_FOUND  File not found\r
-**/\r
-EFI_STATUS\r
-ReadFileToBuffer (\r
-  IN  CHAR16                               *FileName,\r
-  OUT UINTN                                *BufferSize,\r
-  OUT VOID                                 **Buffer\r
-  );\r
-\r
-/**\r
-  Write a file.\r
-\r
-  @param[in] FileName        The file to be written.\r
-  @param[in] BufferSize      The file buffer size\r
-  @param[in] Buffer          The file buffer\r
-\r
-  @retval EFI_SUCCESS    Write file successfully\r
-**/\r
-EFI_STATUS\r
-WriteFileFromBuffer (\r
-  IN  CHAR16                               *FileName,\r
-  IN  UINTN                                BufferSize,\r
-  IN  VOID                                 *Buffer\r
-  );\r
-\r
-/**\r
-  Get shell protocol.\r
-\r
-  @return Pointer to shell protocol.\r
-\r
-**/\r
-EFI_SHELL_PROTOCOL *\r
-GetShellProtocol (\r
-  VOID\r
-  );\r
-\r
-/**\r
-  Get SimpleFileSystem from boot option file path.\r
-\r
-  @param[in]  DevicePath     The file path of boot option\r
-  @param[out] FullPath       The full device path of boot device\r
-  @param[out] Fs             The file system within EfiSysPartition\r
-\r
-  @retval EFI_SUCCESS    Get file system successfully\r
-  @retval EFI_NOT_FOUND  No valid file system found\r
-  @retval others         Get file system failed\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-GetEfiSysPartitionFromBootOptionFilePath (\r
-  IN  EFI_DEVICE_PATH_PROTOCOL         *DevicePath,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL         **FullPath,\r
-  OUT EFI_SIMPLE_FILE_SYSTEM_PROTOCOL  **Fs\r
-  );\r
+#include "CapsuleApp.h"\r
 \r
 /**\r
   Validate if it is valid capsule header\r
@@ -709,7 +618,6 @@ SplitFileNameExtension (
 \r
 **/\r
 INTN\r
-EFIAPI\r
 CompareFileNameInAlphabet (\r
   IN VOID                         *Left,\r
   IN VOID                         *Right\r
@@ -812,8 +720,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 +754,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..382efa9aa04f96a8e8dda905c545db7b06a1aac0 100644 (file)
@@ -5,36 +5,10 @@
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
-#include <Uefi.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/UefiRuntimeServicesTableLib.h>\r
-#include <Library/UefiLib.h>\r
-#include <Library/PrintLib.h>\r
-#include <Library/DevicePathLib.h>\r
-#include <Library/FileHandleLib.h>\r
-#include <Library/UefiBootManagerLib.h>\r
-#include <Protocol/SimpleFileSystem.h>\r
-#include <Protocol/Shell.h>\r
-#include <Guid/FileInfo.h>\r
-#include <Guid/GlobalVariable.h>\r
-#include <Guid/Gpt.h>\r
 \r
-EFI_GUID mCapsuleOnDiskBootOptionGuid = { 0x4CC29BB7, 0x2413, 0x40A2, { 0xB0, 0x6D, 0x25, 0x3E, 0x37, 0x10, 0xF5, 0x32 } };\r
-\r
-/**\r
-  Get shell protocol.\r
+#include "CapsuleApp.h"\r
 \r
-  @return Pointer to shell protocol.\r
-\r
-**/\r
-EFI_SHELL_PROTOCOL *\r
-GetShellProtocol (\r
-  VOID\r
-  );\r
+EFI_GUID mCapsuleOnDiskBootOptionGuid = { 0x4CC29BB7, 0x2413, 0x40A2, { 0xB0, 0x6D, 0x25, 0x3E, 0x37, 0x10, 0xF5, 0x32 } };\r
 \r
 /**\r
   Get file name from file path.\r
@@ -330,7 +304,6 @@ GetEfiSysPartitionFromDevPath (
 \r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 GetEfiSysPartitionFromBootOptionFilePath (\r
   IN  EFI_DEVICE_PATH_PROTOCOL         *DevicePath,\r
   OUT EFI_DEVICE_PATH_PROTOCOL         **FullPath,\r
@@ -398,7 +371,6 @@ GetEfiSysPartitionFromBootOptionFilePath (
 \r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 GetUpdateFileSystem (\r
   IN  CHAR16                           *Map,\r
   OUT UINT16                           *BootNext,\r
@@ -744,6 +716,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 +777,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 +799,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