* [PATCH 1/6] MdeModulePkg CapsuleApp: Check Arg count for -P GET option
2018-07-13 9:08 [PATCH 0/6] CapsuleApp: Some enhancements Star Zeng
@ 2018-07-13 9:08 ` Star Zeng
2018-07-13 9:08 ` [PATCH 2/6] MdeModulePkg CapsuleApp: Fix memory leak in DumpFmpImage() Star Zeng
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Star Zeng @ 2018-07-13 9:08 UTC (permalink / raw)
To: edk2-devel; +Cc: Star Zeng, Michael D Kinney, Jiewen Yao, Yonghong Zhu
Also add help info for CapsuleApp -P GET option.
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 | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
index e9be39fd71be..80b66bc6f371 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
@@ -740,7 +740,8 @@ PrintUsage (
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.\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" -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");
@@ -820,7 +821,15 @@ UefiMain (
DumpFmpData();
}
if (Argc >= 3) {
- if (StrCmp(Argv[2], L"GET") == 0) {
+ if (StrCmp(Argv[2], L"GET") != 0) {
+ Print(L"CapsuleApp: Unrecognized option(%s).\n", Argv[2]);
+ return EFI_UNSUPPORTED;
+ } else {
+ if (Argc != 7) {
+ Print(L"CapsuleApp: Incorrect parameter count.\n");
+ return EFI_UNSUPPORTED;
+ }
+
EFI_GUID ImageTypeId;
UINTN ImageIndex;
//
@@ -832,9 +841,11 @@ UefiMain (
return EFI_INVALID_PARAMETER;
}
ImageIndex = StrDecimalToUintn(Argv[4]);
- if (StrCmp(Argv[5], L"-O") == 0) {
- DumpFmpImage(&ImageTypeId, ImageIndex, Argv[6]);
+ if (StrCmp(Argv[5], L"-O") != 0) {
+ Print(L"CapsuleApp: NO output file name.\n");
+ return EFI_UNSUPPORTED;
}
+ DumpFmpImage(&ImageTypeId, ImageIndex, Argv[6]);
}
}
return EFI_SUCCESS;
--
2.7.0.windows.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/6] MdeModulePkg CapsuleApp: Fix memory leak in DumpFmpImage()
2018-07-13 9:08 [PATCH 0/6] CapsuleApp: Some enhancements Star Zeng
2018-07-13 9:08 ` [PATCH 1/6] MdeModulePkg CapsuleApp: Check Arg count for -P GET option Star Zeng
@ 2018-07-13 9:08 ` Star Zeng
2018-07-13 9:08 ` [PATCH 3/6] MdeModulePkg CapsuleApp: Do not parse bits in CapsuleFlags of ESRT Star Zeng
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Star Zeng @ 2018-07-13 9:08 UTC (permalink / raw)
To: edk2-devel; +Cc: Star Zeng, Michael D Kinney, Jiewen Yao, Yonghong Zhu
Image buffer should be freed after using.
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, 2 insertions(+)
diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
index 6c1320942bf4..c0197dd640e4 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
@@ -953,5 +953,7 @@ DumpFmpImage (
Status = WriteFileFromBuffer(ImageName, ImageSize, Image);
Print(L"CapsuleApp: Dump %g ImageIndex (0x%x) to %s %r\n", ImageTypeId, ImageIndex, ImageName, Status);
+ FreePool (Image);
+
return ;
}
--
2.7.0.windows.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/6] MdeModulePkg CapsuleApp: Do not parse bits in CapsuleFlags of ESRT
2018-07-13 9:08 [PATCH 0/6] CapsuleApp: Some enhancements Star Zeng
2018-07-13 9:08 ` [PATCH 1/6] MdeModulePkg CapsuleApp: Check Arg count for -P GET option Star Zeng
2018-07-13 9:08 ` [PATCH 2/6] MdeModulePkg CapsuleApp: Fix memory leak in DumpFmpImage() Star Zeng
@ 2018-07-13 9:08 ` Star Zeng
2018-07-13 9:08 ` [PATCH 4/6] MdeModulePkg CapsuleApp: Show clear message when option is unrecognized Star Zeng
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Star Zeng @ 2018-07-13 9:08 UTC (permalink / raw)
To: edk2-devel; +Cc: Star Zeng, Michael D Kinney, Jiewen Yao, Yonghong Zhu
According to UEFI spec, only bits 0-15 of CapsuleFlags are
meaningful and CapsuleGuid specific, CAPSULE_FLAGS_PERSIST_ACROSS_RESET
CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE/CAPSULE_FLAGS_INITIATE_RESET
defined in UEFI spec are in bits 16-31, they should not be parsed in
CapsuleFlags of ESRT.
CapsuleFlags
The capsule flags field contains the CapsuleGuid flags (bits 0-15)
as defined in the EFI_CAPSULE_HEADER that will be set in the capsule
header.
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 | 3 ---
1 file changed, 3 deletions(-)
diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
index c0197dd640e4..97f1893ef433 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
@@ -454,9 +454,6 @@ DumpEsrtEntry (
Print(L" FwVersion - 0x%x\n", EsrtEntry->FwVersion);
Print(L" LowestSupportedFwVersion - 0x%x\n", EsrtEntry->LowestSupportedFwVersion);
Print(L" CapsuleFlags - 0x%x\n", EsrtEntry->CapsuleFlags);
- Print(L" PERSIST_ACROSS_RESET - 0x%x\n", EsrtEntry->CapsuleFlags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET);
- Print(L" POPULATE_SYSTEM_TABLE - 0x%x\n", EsrtEntry->CapsuleFlags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE);
- Print(L" INITIATE_RESET - 0x%x\n", EsrtEntry->CapsuleFlags & CAPSULE_FLAGS_INITIATE_RESET);
Print(L" LastAttemptVersion - 0x%x\n", EsrtEntry->LastAttemptVersion);
Print(L" LastAttemptStatus - 0x%x (%a)\n", EsrtEntry->LastAttemptStatus, LastAttemptStatusToString(EsrtEntry->LastAttemptStatus));
}
--
2.7.0.windows.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/6] MdeModulePkg CapsuleApp: Show clear message when option is unrecognized
2018-07-13 9:08 [PATCH 0/6] CapsuleApp: Some enhancements Star Zeng
` (2 preceding siblings ...)
2018-07-13 9:08 ` [PATCH 3/6] MdeModulePkg CapsuleApp: Do not parse bits in CapsuleFlags of ESRT Star Zeng
@ 2018-07-13 9:08 ` Star Zeng
2018-07-13 9:08 ` [PATCH 5/6] MdeModulePkg CapsuleApp: Check capsule header before using its Flags Star Zeng
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Star Zeng @ 2018-07-13 9:08 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 | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
index 80b66bc6f371..a83ebf3d101b 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
@@ -850,10 +850,17 @@ UefiMain (
}
return EFI_SUCCESS;
}
+
if (StrCmp(Argv[1], L"-E") == 0) {
DumpEsrtData();
return EFI_SUCCESS;
}
+
+ if (Argv[1][0] == L'-') {
+ Print(L"CapsuleApp: Unrecognized option(%s).\n", Argv[1]);
+ return EFI_UNSUPPORTED;
+ }
+
CapsuleFirstIndex = 1;
NoReset = FALSE;
if ((Argc > 1) && (StrCmp(Argv[Argc - 1], L"-NR") == 0)) {
--
2.7.0.windows.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5/6] MdeModulePkg CapsuleApp: Check capsule header before using its Flags
2018-07-13 9:08 [PATCH 0/6] CapsuleApp: Some enhancements Star Zeng
` (3 preceding siblings ...)
2018-07-13 9:08 ` [PATCH 4/6] MdeModulePkg CapsuleApp: Show clear message when option is unrecognized Star Zeng
@ 2018-07-13 9:08 ` Star Zeng
2018-07-13 9:08 ` [PATCH 6/6] MdeModulePkg CapsuleApp: Use EFI_UNSUPPORTED for incorrect Argc case Star Zeng
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Star Zeng @ 2018-07-13 9:08 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 | 38 ++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
index a83ebf3d101b..dbcffddea9ce 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
@@ -716,6 +716,40 @@ 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
@@ -891,6 +925,10 @@ UefiMain (
Print(L"CapsuleApp: capsule image (%s) is not found.\n", CapsuleName);
goto Done;
}
+ if (!IsValidCapsuleHeader (CapsuleBuffer[Index], FileSize[Index])) {
+ Print(L"CapsuleApp: Capsule image (%s) is not a valid capsule.\n", CapsuleName);
+ return EFI_INVALID_PARAMETER;
+ }
}
//
--
2.7.0.windows.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 6/6] MdeModulePkg CapsuleApp: Use EFI_UNSUPPORTED for incorrect Argc case
2018-07-13 9:08 [PATCH 0/6] CapsuleApp: Some enhancements Star Zeng
` (4 preceding siblings ...)
2018-07-13 9:08 ` [PATCH 5/6] MdeModulePkg CapsuleApp: Check capsule header before using its Flags Star Zeng
@ 2018-07-13 9:08 ` Star Zeng
2018-07-23 0:59 ` [PATCH 0/6] CapsuleApp: Some enhancements Yao, Jiewen
2018-07-27 1:33 ` Yao, Jiewen
7 siblings, 0 replies; 9+ messages in thread
From: Star Zeng @ 2018-07-13 9:08 UTC (permalink / raw)
To: edk2-devel; +Cc: Star Zeng, Michael D Kinney, Jiewen Yao, Yonghong Zhu
Align code to use EFI_UNSUPPORTED for all incorrect Argc cases.
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 | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
index dbcffddea9ce..df5de91ef524 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
@@ -193,7 +193,7 @@ CreateBmpFmp (
// VerticalResolution >= BMP_IMAGE_HEADER.PixelHeight
if (Argc != 5) {
- Print(L"CapsuleApp: Invalid Parameter.\n");
+ Print(L"CapsuleApp: Incorrect parameter count.\n");
return EFI_UNSUPPORTED;
}
@@ -387,7 +387,7 @@ CreateNestedFmp (
EFI_STATUS Status;
if (Argc != 5) {
- Print(L"CapsuleApp: Invalid Parameter.\n");
+ Print(L"CapsuleApp: Incorrect parameter count.\n");
return EFI_UNSUPPORTED;
}
@@ -793,7 +793,8 @@ PrintUsage (
@param[in] SystemTable The system table.
@retval EFI_SUCCESS Command completed successfully.
- @retval EFI_INVALID_PARAMETER Command usage error.
+ @retval EFI_UNSUPPORTED Command usage unsupported.
+ @retval EFI_INVALID_PARAMETER Command usage invalid.
@retval EFI_NOT_FOUND The input file can't be found.
**/
EFI_STATUS
@@ -824,12 +825,12 @@ UefiMain (
}
if (Argc < 2) {
PrintUsage();
- return EFI_INVALID_PARAMETER;
+ return EFI_UNSUPPORTED;
}
if (StrCmp(Argv[1], L"-D") == 0) {
- if (Argc < 3) {
- Print(L"CapsuleApp: NO input capsule name.\n");
- return EFI_INVALID_PARAMETER;
+ if (Argc != 3) {
+ Print(L"CapsuleApp: Incorrect parameter count.\n");
+ return EFI_UNSUPPORTED;
}
Status = DumpCapsule(Argv[2]);
return Status;
--
2.7.0.windows.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 0/6] CapsuleApp: Some enhancements
2018-07-13 9:08 [PATCH 0/6] CapsuleApp: Some enhancements Star Zeng
` (5 preceding siblings ...)
2018-07-13 9:08 ` [PATCH 6/6] MdeModulePkg CapsuleApp: Use EFI_UNSUPPORTED for incorrect Argc case Star Zeng
@ 2018-07-23 0:59 ` Yao, Jiewen
2018-07-27 1:33 ` Yao, Jiewen
7 siblings, 0 replies; 9+ messages in thread
From: Yao, Jiewen @ 2018-07-23 0:59 UTC (permalink / raw)
To: Zeng, Star, edk2-devel@lists.01.org; +Cc: Kinney, Michael D, Zeng, Star
Reviewed-by: Jiewen.yao@intel.com
> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Star
> Zeng
> Sent: Friday, July 13, 2018 5:09 PM
> To: edk2-devel@lists.01.org
> Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Yao, Jiewen
> <jiewen.yao@intel.com>; Zeng, Star <star.zeng@intel.com>
> Subject: [edk2] [PATCH 0/6] CapsuleApp: Some enhancements
>
> 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: Check Arg count for -P GET option
> MdeModulePkg CapsuleApp: Fix memory leak in DumpFmpImage()
> MdeModulePkg CapsuleApp: Do not parse bits in CapsuleFlags of ESRT
> MdeModulePkg CapsuleApp: Show clear message when option is
> unrecognized
> MdeModulePkg CapsuleApp: Check capsule header before using its Flags
> MdeModulePkg CapsuleApp: Use EFI_UNSUPPORTED for incorrect Argc case
>
> MdeModulePkg/Application/CapsuleApp/CapsuleApp.c | 79
> +++++++++++++++++++----
> MdeModulePkg/Application/CapsuleApp/CapsuleDump.c | 5 +-
> 2 files changed, 70 insertions(+), 14 deletions(-)
>
> --
> 2.7.0.windows.1
>
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/6] CapsuleApp: Some enhancements
2018-07-13 9:08 [PATCH 0/6] CapsuleApp: Some enhancements Star Zeng
` (6 preceding siblings ...)
2018-07-23 0:59 ` [PATCH 0/6] CapsuleApp: Some enhancements Yao, Jiewen
@ 2018-07-27 1:33 ` Yao, Jiewen
7 siblings, 0 replies; 9+ messages in thread
From: Yao, Jiewen @ 2018-07-27 1:33 UTC (permalink / raw)
To: Zeng, Star, edk2-devel@lists.01.org; +Cc: Kinney, Michael D, Zeng, Star
Reviewed-by: jiewen.yao@intel.com
> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Star
> Zeng
> Sent: Friday, July 13, 2018 5:09 PM
> To: edk2-devel@lists.01.org
> Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Yao, Jiewen
> <jiewen.yao@intel.com>; Zeng, Star <star.zeng@intel.com>
> Subject: [edk2] [PATCH 0/6] CapsuleApp: Some enhancements
>
> 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: Check Arg count for -P GET option
> MdeModulePkg CapsuleApp: Fix memory leak in DumpFmpImage()
> MdeModulePkg CapsuleApp: Do not parse bits in CapsuleFlags of ESRT
> MdeModulePkg CapsuleApp: Show clear message when option is
> unrecognized
> MdeModulePkg CapsuleApp: Check capsule header before using its Flags
> MdeModulePkg CapsuleApp: Use EFI_UNSUPPORTED for incorrect Argc case
>
> MdeModulePkg/Application/CapsuleApp/CapsuleApp.c | 79
> +++++++++++++++++++----
> MdeModulePkg/Application/CapsuleApp/CapsuleDump.c | 5 +-
> 2 files changed, 70 insertions(+), 14 deletions(-)
>
> --
> 2.7.0.windows.1
>
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
^ permalink raw reply [flat|nested] 9+ messages in thread