public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 0/5] CapsuleApp: Some enhancements
@ 2018-07-26 10:16 Star Zeng
  2018-07-26 10:16 ` [PATCH 1/6] MdeModulePkg CapsuleApp: Fix VS2012 build failure caused by 5410502 Star Zeng
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Star Zeng @ 2018-07-26 10:16 UTC (permalink / raw)
  To: edk2-devel; +Cc: Star Zeng, Michael D Kinney, Jiewen Yao, Yonghong Zhu

V2: Last patch is new added.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>

Star Zeng (6):
  MdeModulePkg CapsuleApp: Fix VS2012 build failure caused by 5410502
  MdeModulePkg CapsuleApp: Fix -D failed to dump Nest FMP capsule
  MdeModulePkg CapsuleApp: Refine -N option help information
  MdeModulePkg CapsuleApp: Index need be decimal for -P GET option
  MdeModulePkg CapsuleApp: Prompt info for -C option
  MdeModulePkg CapsuleApp: Check capsule header for -D and -N options

 MdeModulePkg/Application/CapsuleApp/CapsuleApp.c  | 154 ++++++++++++++--------
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c |  27 +++-
 2 files changed, 125 insertions(+), 56 deletions(-)

-- 
2.7.0.windows.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/6] MdeModulePkg CapsuleApp: Fix VS2012 build failure caused by 5410502
  2018-07-26 10:16 [PATCH 0/5] CapsuleApp: Some enhancements Star Zeng
@ 2018-07-26 10:16 ` Star Zeng
  2018-07-27  0:43   ` Bi, Dandan
  2018-07-26 10:16 ` [PATCH 2/6] MdeModulePkg CapsuleApp: Fix -D failed to dump Nest FMP capsule Star Zeng
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 9+ messages in thread
From: Star Zeng @ 2018-07-26 10:16 UTC (permalink / raw)
  To: edk2-devel; +Cc: Star Zeng, Jiewen Yao, Dandan Bi

The build failure is like below.
xxx\CapsuleApp.c(868) : error C2275: 'EFI_GUID' :
  illegal use of this type as an expression
        xxx/UefiBaseType.h(29) : see declaration of 'EFI_GUID'
xxx\CapsuleApp.c(868) : error C2146: syntax error :
  missing ';' before identifier 'ImageTypeId'
xxx\CapsuleApp.c(868) : error C2065: 'ImageTypeId' : undeclared identifier
xxx\CapsuleApp.c(869) : error C2275: 'UINTN' :
  illegal use of this type as an expression
        xxx\ProcessorBind.h(224) : see declaration of 'UINTN'
xxx\CapsuleApp.c(869) : error C2146: syntax error :
  missing ';' before identifier 'ImageIndex'
xxx\CapsuleApp.c(869) : error C2065: 'ImageIndex' : undeclared identifier

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
---
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
index df5de91ef524..95aa20760560 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
@@ -809,14 +809,16 @@ UefiMain (
   UINTN                         FileSize[MAX_CAPSULE_NUM];
   VOID                          *CapsuleBuffer[MAX_CAPSULE_NUM];
   EFI_CAPSULE_BLOCK_DESCRIPTOR  *BlockDescriptors;
-  EFI_CAPSULE_HEADER             *CapsuleHeaderArray[MAX_CAPSULE_NUM + 1];
-  UINT64                         MaxCapsuleSize;
-  EFI_RESET_TYPE                 ResetType;
-  BOOLEAN                        NeedReset;
-  BOOLEAN                        NoReset;
-  CHAR16                         *CapsuleName;
-  UINTN                          CapsuleNum;
-  UINTN                          Index;
+  EFI_CAPSULE_HEADER            *CapsuleHeaderArray[MAX_CAPSULE_NUM + 1];
+  UINT64                        MaxCapsuleSize;
+  EFI_RESET_TYPE                ResetType;
+  BOOLEAN                       NeedReset;
+  BOOLEAN                       NoReset;
+  CHAR16                        *CapsuleName;
+  UINTN                         CapsuleNum;
+  UINTN                         Index;
+  EFI_GUID                      ImageTypeId;
+  UINTN                         ImageIndex;
 
   Status = GetArg();
   if (EFI_ERROR(Status)) {
@@ -865,8 +867,6 @@ UefiMain (
           return EFI_UNSUPPORTED;
         }
 
-        EFI_GUID  ImageTypeId;
-        UINTN     ImageIndex;
         //
         // FMP->GetImage()
         //
-- 
2.7.0.windows.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/6] MdeModulePkg CapsuleApp: Fix -D failed to dump Nest FMP capsule
  2018-07-26 10:16 [PATCH 0/5] CapsuleApp: Some enhancements Star Zeng
  2018-07-26 10:16 ` [PATCH 1/6] MdeModulePkg CapsuleApp: Fix VS2012 build failure caused by 5410502 Star Zeng
@ 2018-07-26 10:16 ` Star Zeng
  2018-07-26 10:16 ` [PATCH 3/6] MdeModulePkg CapsuleApp: Refine -N option help information Star Zeng
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Star Zeng @ 2018-07-26 10:16 UTC (permalink / raw)
  To: edk2-devel; +Cc: Star Zeng, Michael D Kinney, Jiewen Yao, Yonghong Zhu

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
---
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
index 97f1893ef433..4c85e8c23dff 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
@@ -214,7 +214,7 @@ IsNestedFmpCapsule (
   // FMP GUID after ESRT one
   //
   NestedCapsuleHeader = (EFI_CAPSULE_HEADER *)((UINT8 *)CapsuleHeader + CapsuleHeader->HeaderSize);
-  NestedCapsuleSize = (UINTN)CapsuleHeader + CapsuleHeader->HeaderSize - (UINTN)NestedCapsuleHeader;
+  NestedCapsuleSize = (UINTN)CapsuleHeader + CapsuleHeader->CapsuleImageSize- (UINTN)NestedCapsuleHeader;
   if (NestedCapsuleSize < sizeof(EFI_CAPSULE_HEADER)) {
     return FALSE;
   }
-- 
2.7.0.windows.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/6] MdeModulePkg CapsuleApp: Refine -N option help information
  2018-07-26 10:16 [PATCH 0/5] CapsuleApp: Some enhancements Star Zeng
  2018-07-26 10:16 ` [PATCH 1/6] MdeModulePkg CapsuleApp: Fix VS2012 build failure caused by 5410502 Star Zeng
  2018-07-26 10:16 ` [PATCH 2/6] MdeModulePkg CapsuleApp: Fix -D failed to dump Nest FMP capsule Star Zeng
@ 2018-07-26 10:16 ` Star Zeng
  2018-07-26 10:16 ` [PATCH 4/6] MdeModulePkg CapsuleApp: Index need be decimal for -P GET option Star Zeng
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Star Zeng @ 2018-07-26 10:16 UTC (permalink / raw)
  To: edk2-devel; +Cc: Star Zeng, Michael D Kinney, Jiewen Yao, Yonghong Zhu

-N option is used to append a Capsule Header to an existing
FMP capsule image with its ImageTypeId supported by the system.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
---
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
index 95aa20760560..3a87439f104e 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
@@ -779,7 +779,8 @@ PrintUsage (
   Print(L"  -E:  Dump UEFI ESRT table info.\n");
   Print(L"  -G:  Convert a BMP file to be an UX capsule,\n");
   Print(L"       according to Windows Firmware Update document\n");
-  Print(L"  -N:  Append a Capsule Header to an existing capsule image,\n");
+  Print(L"  -N:  Append a Capsule Header to an existing FMP capsule image\n");
+  Print(L"       with its ImageTypeId supported by the system,\n");
   Print(L"       according to Windows Firmware Update document\n");
   Print(L"  -O:  Output new Capsule file name\n");
   Print(L"  -D:  Dump Capsule image header information, image payload information if it is an UX capsule\n");
-- 
2.7.0.windows.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/6] MdeModulePkg CapsuleApp: Index need be decimal for -P GET option
  2018-07-26 10:16 [PATCH 0/5] CapsuleApp: Some enhancements Star Zeng
                   ` (2 preceding siblings ...)
  2018-07-26 10:16 ` [PATCH 3/6] MdeModulePkg CapsuleApp: Refine -N option help information Star Zeng
@ 2018-07-26 10:16 ` Star Zeng
  2018-07-26 10:16 ` [PATCH 5/6] MdeModulePkg CapsuleApp: Prompt info for -C option Star Zeng
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Star Zeng @ 2018-07-26 10:16 UTC (permalink / raw)
  To: edk2-devel; +Cc: Star Zeng, Michael D Kinney, Jiewen Yao, Yonghong Zhu

Also adjust the help information to be not too long to be suitable
for different display resolutions.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
---
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
index 3a87439f104e..93bf4252bac6 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
@@ -768,14 +768,16 @@ PrintUsage (
   Print(L"  CapsuleApp -D <Capsule>\n");
   Print(L"  CapsuleApp -P GET <ImageTypeId> <Index> -O <FileName>\n");
   Print(L"Parameter:\n");
-  Print(L"  -NR: No reset will be triggered for the capsule\n");
-  Print(L"       with CAPSULE_FLAGS_PERSIST_ACROSS_RESET and without CAPSULE_FLAGS_INITIATE_RESET.\n");
+  Print(L"  -NR: No reset will be triggered for the capsule with\n");
+  Print(L"       CAPSULE_FLAGS_PERSIST_ACROSS_RESET and without\n");
+  Print(L"       CAPSULE_FLAGS_INITIATE_RESET.\n");
   Print(L"  -S:  Dump capsule report variable (EFI_CAPSULE_REPORT_GUID),\n");
   Print(L"       which is defined in UEFI specification.\n");
   Print(L"  -C:  Clear capsule report variable (EFI_CAPSULE_REPORT_GUID),\n");
   Print(L"       which is defined in UEFI specification.\n");
   Print(L"  -P:  Dump UEFI FMP protocol info, or get image with specified\n");
-  Print(L"       ImageTypeId and index to a file if 'GET' option is used.\n");
+  Print(L"       ImageTypeId and Index (decimal format) to a file if 'GET'\n");
+  Print(L"       option is used.\n");
   Print(L"  -E:  Dump UEFI ESRT table info.\n");
   Print(L"  -G:  Convert a BMP file to be an UX capsule,\n");
   Print(L"       according to Windows Firmware Update document\n");
@@ -783,8 +785,9 @@ PrintUsage (
   Print(L"       with its ImageTypeId supported by the system,\n");
   Print(L"       according to Windows Firmware Update document\n");
   Print(L"  -O:  Output new Capsule file name\n");
-  Print(L"  -D:  Dump Capsule image header information, image payload information if it is an UX capsule\n");
-  Print(L"       and FMP header information if it is a FMP capsule.\n");
+  Print(L"  -D:  Dump Capsule image header information, image payload\n");
+  Print(L"       information if it is an UX capsule and FMP header\n");
+  Print(L"       information if it is a FMP capsule.\n");
 }
 
 /**
-- 
2.7.0.windows.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 5/6] MdeModulePkg CapsuleApp: Prompt info for -C option
  2018-07-26 10:16 [PATCH 0/5] CapsuleApp: Some enhancements Star Zeng
                   ` (3 preceding siblings ...)
  2018-07-26 10:16 ` [PATCH 4/6] MdeModulePkg CapsuleApp: Index need be decimal for -P GET option Star Zeng
@ 2018-07-26 10:16 ` Star Zeng
  2018-07-26 10:16 ` [PATCH 6/6] MdeModulePkg CapsuleApp: Check capsule header for -D and -N options Star Zeng
  2018-07-26 12:50 ` [PATCH 0/5] CapsuleApp: Some enhancements Yao, Jiewen
  6 siblings, 0 replies; 9+ messages in thread
From: Star Zeng @ 2018-07-26 10:16 UTC (permalink / raw)
  To: edk2-devel; +Cc: Star Zeng, Michael D Kinney, Jiewen Yao, Yonghong Zhu

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
---
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.c  | 17 +++++++++++++----
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c |  2 +-
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
index 93bf4252bac6..2967b0d1dd18 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
@@ -70,7 +70,7 @@ DumpCapsule (
   @retval EFI_UNSUPPORTED        Input parameter is not valid.
 **/
 EFI_STATUS
-DmpCapsuleStatusVariable (
+DumpCapsuleStatusVariable (
   VOID
   );
 
@@ -466,11 +466,13 @@ ClearCapsuleStatusVariable (
   UINT32                              Index;
   CHAR16                              CapsuleVarName[20];
   CHAR16                              *TempVarName;
+  BOOLEAN                             Found;
 
   StrCpyS (CapsuleVarName, sizeof(CapsuleVarName)/sizeof(CapsuleVarName[0]), L"Capsule");
   TempVarName = CapsuleVarName + StrLen (CapsuleVarName);
   Index = 0;
 
+  Found = FALSE;
   while (TRUE) {
     UnicodeSPrint (TempVarName, 5 * sizeof(CHAR16), L"%04x", Index);
 
@@ -481,12 +483,15 @@ ClearCapsuleStatusVariable (
                     0,
                     (VOID *)NULL
                     );
-    if (EFI_ERROR(Status)) {
+    if (Status == EFI_NOT_FOUND) {
       //
-      // There is no capsule variables, quit
+      // There is no more capsule variables, quit
       //
       break;
     }
+    Found = TRUE;
+
+    Print (L"Clear %s %r\n", CapsuleVarName, Status);
 
     Index++;
     if (Index > 0xFFFF) {
@@ -494,6 +499,10 @@ ClearCapsuleStatusVariable (
     }
   }
 
+  if (!Found) {
+    Print (L"No any Capsule#### variable found\n");
+  }
+
   return EFI_SUCCESS;
 }
 
@@ -850,7 +859,7 @@ UefiMain (
     return Status;
   }
   if (StrCmp(Argv[1], L"-S") == 0) {
-    Status = DmpCapsuleStatusVariable();
+    Status = DumpCapsuleStatusVariable();
     return EFI_SUCCESS;
   }
   if (StrCmp(Argv[1], L"-C") == 0) {
diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
index 4c85e8c23dff..11bf2e1d4530 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
@@ -283,7 +283,7 @@ Done:
   @retval EFI_UNSUPPORTED        Input parameter is not valid.
 **/
 EFI_STATUS
-DmpCapsuleStatusVariable (
+DumpCapsuleStatusVariable (
   VOID
   )
 {
-- 
2.7.0.windows.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 6/6] MdeModulePkg CapsuleApp: Check capsule header for -D and -N options
  2018-07-26 10:16 [PATCH 0/5] CapsuleApp: Some enhancements Star Zeng
                   ` (4 preceding siblings ...)
  2018-07-26 10:16 ` [PATCH 5/6] MdeModulePkg CapsuleApp: Prompt info for -C option Star Zeng
@ 2018-07-26 10:16 ` Star Zeng
  2018-07-26 12:50 ` [PATCH 0/5] CapsuleApp: Some enhancements Yao, Jiewen
  6 siblings, 0 replies; 9+ messages in thread
From: Star Zeng @ 2018-07-26 10:16 UTC (permalink / raw)
  To: edk2-devel; +Cc: Star Zeng, Michael D Kinney, Jiewen Yao, Yonghong Zhu

Then meaningful error message can be shown when the input image is
unexpected.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
---
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.c  | 101 ++++++++++++++--------
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c |  23 +++++
 2 files changed, 90 insertions(+), 34 deletions(-)

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
index 2967b0d1dd18..894da2f2d9d5 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
@@ -363,6 +363,60 @@ GetEsrtFwType (
 }
 
 /**
+  Validate if it is valid capsule header
+
+  This function assumes the caller provided correct CapsuleHeader pointer
+  and CapsuleSize.
+
+  This function validates the fields in EFI_CAPSULE_HEADER.
+
+  @param[in] CapsuleHeader  Points to a capsule header.
+  @param[in] CapsuleSize    Size of the whole capsule image.
+
+**/
+BOOLEAN
+IsValidCapsuleHeader (
+  IN EFI_CAPSULE_HEADER     *CapsuleHeader,
+  IN UINT64                 CapsuleSize
+  )
+{
+  if (CapsuleSize < sizeof (EFI_CAPSULE_HEADER)) {
+    return FALSE;
+  }
+  if (CapsuleHeader->CapsuleImageSize != CapsuleSize) {
+    return FALSE;
+  }
+  if (CapsuleHeader->HeaderSize > CapsuleHeader->CapsuleImageSize) {
+    return FALSE;
+  }
+  if (CapsuleHeader->HeaderSize < sizeof (EFI_CAPSULE_HEADER)) {
+    return FALSE;
+  }
+
+  return TRUE;
+}
+
+/**
+  Return if this CapsuleGuid is a FMP capsule GUID or not.
+
+  @param[in] CapsuleGuid A pointer to EFI_GUID
+
+  @retval TRUE  It is a FMP capsule GUID.
+  @retval FALSE It is not a FMP capsule GUID.
+**/
+BOOLEAN
+IsFmpCapsuleGuid (
+  IN EFI_GUID  *CapsuleGuid
+  )
+{
+  if (CompareGuid(&gEfiFmpCapsuleGuid, CapsuleGuid)) {
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
+/**
   Append a capsule header on top of current image.
   This function follows Windows UEFI Firmware Update Platform document.
 
@@ -407,15 +461,28 @@ CreateNestedFmp (
     Print(L"CapsuleApp: Capsule image (%s) is not found.\n", CapsuleName);
     goto Done;
   }
+  if (!IsValidCapsuleHeader (CapsuleBuffer, FileSize)) {
+    Print(L"CapsuleApp: Capsule image (%s) is not a valid capsule.\n", CapsuleName);
+    Status = EFI_INVALID_PARAMETER;
+    goto Done;
+  }
+
+  if (!IsFmpCapsuleGuid (&((EFI_CAPSULE_HEADER *) CapsuleBuffer)->CapsuleGuid)) {
+    Print(L"CapsuleApp: Capsule image (%s) is not a FMP capsule.\n", CapsuleName);
+    Status = EFI_INVALID_PARAMETER;
+    goto Done;
+  }
 
   ImageTypeId = GetCapsuleImageTypeId(CapsuleBuffer);
   if (ImageTypeId == NULL) {
     Print(L"CapsuleApp: Capsule ImageTypeId is not found.\n");
+    Status = EFI_INVALID_PARAMETER;
     goto Done;
   }
   FwType = GetEsrtFwType(ImageTypeId);
   if ((FwType != ESRT_FW_TYPE_SYSTEMFIRMWARE) && (FwType != ESRT_FW_TYPE_DEVICEFIRMWARE)) {
     Print(L"CapsuleApp: Capsule FwType is invalid.\n");
+    Status = EFI_INVALID_PARAMETER;
     goto Done;
   }
 
@@ -725,40 +792,6 @@ CleanGatherList (
 }
 
 /**
-  Validate if it is valid capsule header
-
-  This function assumes the caller provided correct CapsuleHeader pointer
-  and CapsuleSize.
-
-  This function validates the fields in EFI_CAPSULE_HEADER.
-
-  @param[in] CapsuleHeader  Points to a capsule header.
-  @param[in] CapsuleSize    Size of the whole capsule image.
-
-**/
-BOOLEAN
-IsValidCapsuleHeader (
-  IN EFI_CAPSULE_HEADER     *CapsuleHeader,
-  IN UINT64                 CapsuleSize
-  )
-{
-  if (CapsuleSize < sizeof (EFI_CAPSULE_HEADER)) {
-    return FALSE;
-  }
-  if (CapsuleHeader->CapsuleImageSize != CapsuleSize) {
-    return FALSE;
-  }
-  if (CapsuleHeader->HeaderSize > CapsuleHeader->CapsuleImageSize) {
-    return FALSE;
-  }
-  if (CapsuleHeader->HeaderSize < sizeof (EFI_CAPSULE_HEADER)) {
-    return FALSE;
-  }
-
-  return TRUE;
-}
-
-/**
   Print APP usage.
 **/
 VOID
diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
index 11bf2e1d4530..45c3ecd050ab 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
@@ -62,6 +62,24 @@ WriteFileFromBuffer (
   );
 
 /**
+  Validate if it is valid capsule header
+
+  This function assumes the caller provided correct CapsuleHeader pointer
+  and CapsuleSize.
+
+  This function validates the fields in EFI_CAPSULE_HEADER.
+
+  @param[in] CapsuleHeader  Points to a capsule header.
+  @param[in] CapsuleSize    Size of the whole capsule image.
+
+**/
+BOOLEAN
+IsValidCapsuleHeader (
+  IN EFI_CAPSULE_HEADER     *CapsuleHeader,
+  IN UINT64                 CapsuleSize
+  );
+
+/**
   Dump UX capsule information.
 
   @param[in] CapsuleHeader      The UX capsule header
@@ -248,6 +266,11 @@ DumpCapsule (
     Print(L"CapsuleApp: Capsule (%s) is not found.\n", CapsuleName);
     goto Done;
   }
+  if (!IsValidCapsuleHeader (Buffer, FileSize)) {
+    Print(L"CapsuleApp: Capsule image (%s) is not a valid capsule.\n", CapsuleName);
+    Status = EFI_INVALID_PARAMETER;
+    goto Done;
+  }
 
   CapsuleHeader = Buffer;
   if (CompareGuid(&CapsuleHeader->CapsuleGuid, &gWindowsUxCapsuleGuid)) {
-- 
2.7.0.windows.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/5] CapsuleApp: Some enhancements
  2018-07-26 10:16 [PATCH 0/5] CapsuleApp: Some enhancements Star Zeng
                   ` (5 preceding siblings ...)
  2018-07-26 10:16 ` [PATCH 6/6] MdeModulePkg CapsuleApp: Check capsule header for -D and -N options Star Zeng
@ 2018-07-26 12:50 ` Yao, Jiewen
  6 siblings, 0 replies; 9+ messages in thread
From: Yao, Jiewen @ 2018-07-26 12:50 UTC (permalink / raw)
  To: Zeng, Star, edk2-devel@lists.01.org; +Cc: Kinney, Michael D, Zhu, Yonghong

Reviewed-by: Jiewen.yao@intel.com

> -----Original Message-----
> From: Zeng, Star
> Sent: Thursday, July 26, 2018 6:17 PM
> To: edk2-devel@lists.01.org
> Cc: Zeng, Star <star.zeng@intel.com>; Kinney, Michael D
> <michael.d.kinney@intel.com>; Yao, Jiewen <jiewen.yao@intel.com>; Zhu,
> Yonghong <yonghong.zhu@intel.com>
> Subject: [PATCH 0/5] CapsuleApp: Some enhancements
> 
> V2: Last patch is new added.
> 
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Yonghong Zhu <yonghong.zhu@intel.com>
> 
> Star Zeng (6):
>   MdeModulePkg CapsuleApp: Fix VS2012 build failure caused by 5410502
>   MdeModulePkg CapsuleApp: Fix -D failed to dump Nest FMP capsule
>   MdeModulePkg CapsuleApp: Refine -N option help information
>   MdeModulePkg CapsuleApp: Index need be decimal for -P GET option
>   MdeModulePkg CapsuleApp: Prompt info for -C option
>   MdeModulePkg CapsuleApp: Check capsule header for -D and -N options
> 
>  MdeModulePkg/Application/CapsuleApp/CapsuleApp.c  | 154
> ++++++++++++++--------
>  MdeModulePkg/Application/CapsuleApp/CapsuleDump.c |  27 +++-
>  2 files changed, 125 insertions(+), 56 deletions(-)
> 
> --
> 2.7.0.windows.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/6] MdeModulePkg CapsuleApp: Fix VS2012 build failure caused by 5410502
  2018-07-26 10:16 ` [PATCH 1/6] MdeModulePkg CapsuleApp: Fix VS2012 build failure caused by 5410502 Star Zeng
@ 2018-07-27  0:43   ` Bi, Dandan
  0 siblings, 0 replies; 9+ messages in thread
From: Bi, Dandan @ 2018-07-27  0:43 UTC (permalink / raw)
  To: Zeng, Star, edk2-devel@lists.01.org; +Cc: Yao, Jiewen

Reviewed-by: Dandan Bi <dandan.bi@intel.com>

Thanks,
Dandan

-----Original Message-----
From: Zeng, Star 
Sent: Thursday, July 26, 2018 6:17 PM
To: edk2-devel@lists.01.org
Cc: Zeng, Star <star.zeng@intel.com>; Yao, Jiewen <jiewen.yao@intel.com>; Bi, Dandan <dandan.bi@intel.com>
Subject: [PATCH 1/6] MdeModulePkg CapsuleApp: Fix VS2012 build failure caused by 5410502

The build failure is like below.
xxx\CapsuleApp.c(868) : error C2275: 'EFI_GUID' :
  illegal use of this type as an expression
        xxx/UefiBaseType.h(29) : see declaration of 'EFI_GUID'
xxx\CapsuleApp.c(868) : error C2146: syntax error :
  missing ';' before identifier 'ImageTypeId'
xxx\CapsuleApp.c(868) : error C2065: 'ImageTypeId' : undeclared identifier
xxx\CapsuleApp.c(869) : error C2275: 'UINTN' :
  illegal use of this type as an expression
        xxx\ProcessorBind.h(224) : see declaration of 'UINTN'
xxx\CapsuleApp.c(869) : error C2146: syntax error :
  missing ';' before identifier 'ImageIndex'
xxx\CapsuleApp.c(869) : error C2065: 'ImageIndex' : undeclared identifier

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
---
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
index df5de91ef524..95aa20760560 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
@@ -809,14 +809,16 @@ UefiMain (
   UINTN                         FileSize[MAX_CAPSULE_NUM];
   VOID                          *CapsuleBuffer[MAX_CAPSULE_NUM];
   EFI_CAPSULE_BLOCK_DESCRIPTOR  *BlockDescriptors;
-  EFI_CAPSULE_HEADER             *CapsuleHeaderArray[MAX_CAPSULE_NUM + 1];
-  UINT64                         MaxCapsuleSize;
-  EFI_RESET_TYPE                 ResetType;
-  BOOLEAN                        NeedReset;
-  BOOLEAN                        NoReset;
-  CHAR16                         *CapsuleName;
-  UINTN                          CapsuleNum;
-  UINTN                          Index;
+  EFI_CAPSULE_HEADER            *CapsuleHeaderArray[MAX_CAPSULE_NUM + 1];
+  UINT64                        MaxCapsuleSize;
+  EFI_RESET_TYPE                ResetType;
+  BOOLEAN                       NeedReset;
+  BOOLEAN                       NoReset;
+  CHAR16                        *CapsuleName;
+  UINTN                         CapsuleNum;
+  UINTN                         Index;
+  EFI_GUID                      ImageTypeId;
+  UINTN                         ImageIndex;
 
   Status = GetArg();
   if (EFI_ERROR(Status)) {
@@ -865,8 +867,6 @@ UefiMain (
           return EFI_UNSUPPORTED;
         }
 
-        EFI_GUID  ImageTypeId;
-        UINTN     ImageIndex;
         //
         // FMP->GetImage()
         //
-- 
2.7.0.windows.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-07-27  0:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-26 10:16 [PATCH 0/5] CapsuleApp: Some enhancements Star Zeng
2018-07-26 10:16 ` [PATCH 1/6] MdeModulePkg CapsuleApp: Fix VS2012 build failure caused by 5410502 Star Zeng
2018-07-27  0:43   ` Bi, Dandan
2018-07-26 10:16 ` [PATCH 2/6] MdeModulePkg CapsuleApp: Fix -D failed to dump Nest FMP capsule Star Zeng
2018-07-26 10:16 ` [PATCH 3/6] MdeModulePkg CapsuleApp: Refine -N option help information Star Zeng
2018-07-26 10:16 ` [PATCH 4/6] MdeModulePkg CapsuleApp: Index need be decimal for -P GET option Star Zeng
2018-07-26 10:16 ` [PATCH 5/6] MdeModulePkg CapsuleApp: Prompt info for -C option Star Zeng
2018-07-26 10:16 ` [PATCH 6/6] MdeModulePkg CapsuleApp: Check capsule header for -D and -N options Star Zeng
2018-07-26 12:50 ` [PATCH 0/5] CapsuleApp: Some enhancements Yao, Jiewen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox