[edk2] [PATCH] UefiCpuPkg/Microcode.c: Add verification before calculate CheckSum32

2019-03-04 Thread Chen A Chen
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1020

Should make sure the TotalSize of Microcode is aligned with 4 bytes
before calling CalculateSum32 function.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
Cc: Ray Ni 
Cc: Eric Dong 
---
 UefiCpuPkg/Library/MpInitLib/Microcode.c | 31 ---
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c 
b/UefiCpuPkg/Library/MpInitLib/Microcode.c
index 5f9ae22794..643a6f94f4 100644
--- a/UefiCpuPkg/Library/MpInitLib/Microcode.c
+++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c
@@ -166,20 +166,29 @@ MicrocodeDetect (
 //
 CorrectMicrocode = FALSE;
 
-//
-// Save an in-complete CheckSum32 from CheckSum Part1 for common parts.
-//
 if (MicrocodeEntryPoint->DataSize == 0) {
-  InCompleteCheckSum32 = CalculateSum32 (
-   (UINT32 *) MicrocodeEntryPoint,
-   sizeof (CPU_MICROCODE_HEADER) + 2000
-   );
+  TotalSize = sizeof (CPU_MICROCODE_HEADER) + 2000;
 } else {
-  InCompleteCheckSum32 = CalculateSum32 (
-   (UINT32 *) MicrocodeEntryPoint,
-   sizeof (CPU_MICROCODE_HEADER) + 
MicrocodeEntryPoint->DataSize
-   );
+  TotalSize = sizeof (CPU_MICROCODE_HEADER) + 
MicrocodeEntryPoint->DataSize;
 }
+
+///
+/// Check overflow and whether TotalSize is aligned with 4 bytes.
+///
+if ( ((UINTN)MicrocodeEntryPoint + TotalSize) > MicrocodeEnd ||
+ (TotalSize & 0x3) != 0
+   ) {
+  MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) (((UINTN) 
MicrocodeEntryPoint) + SIZE_1KB);
+  continue;
+}
+
+//
+// Save an in-complete CheckSum32 from CheckSum Part1 for common parts.
+//
+InCompleteCheckSum32 = CalculateSum32 (
+ (UINT32 *) MicrocodeEntryPoint,
+ TotalSize
+ );
 InCompleteCheckSum32 -= MicrocodeEntryPoint->ProcessorSignature.Uint32;
 InCompleteCheckSum32 -= MicrocodeEntryPoint->ProcessorFlags;
 InCompleteCheckSum32 -= MicrocodeEntryPoint->Checksum;
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v2] UefiCpuPkg/Microcode: Add verification logic before parsing payload

2019-02-28 Thread Chen A Chen
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1020

The function MicrocodeDetect may receive untrusted input. Add verification
logic to check Microcode Payload Header.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
Cc: Ray Ni 
Cc: Eric Dong 
---
 UefiCpuPkg/Library/MpInitLib/Microcode.c | 187 ---
 1 file changed, 124 insertions(+), 63 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c 
b/UefiCpuPkg/Library/MpInitLib/Microcode.c
index 5f9ae22794..c06e51f5e6 100644
--- a/UefiCpuPkg/Library/MpInitLib/Microcode.c
+++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c
@@ -32,6 +32,66 @@ GetCurrentMicrocodeSignature (
   return BiosSignIdMsr.Bits.MicrocodeUpdateSignature;
 }
 
+/**
+  Verify whether Microcode payload is valid.
+
+  @param[in]  MicrocodeHeader   Point to the Microcode payload buffer.
+
+  @retval TRUE  Valid payload
+  @retval FALSE Invalid payload
+**/
+BOOLEAN
+IsMicrocodeHeaderValid (
+  IN CPU_MICROCODE_HEADER *MicrocodeHeader
+  )
+{
+  UINT32  DataSize;
+
+  ASSERT (MicrocodeHeader != NULL);
+
+  ///
+  /// Verify Version
+  ///
+  if (MicrocodeHeader->HeaderVersion != 0x1) {
+return FALSE;
+  }
+  if (MicrocodeHeader->LoaderRevision != 0x1) {
+return FALSE;
+  }
+
+  ///
+  /// Check whether DataSize is aligned with 4 bytes.
+  ///
+  if (MicrocodeHeader->DataSize != 0 && (MicrocodeHeader->DataSize & 0x3) != 
0) {
+return FALSE;
+  }
+
+  ///
+  /// Check whether TotalSize is aligned with 1KB.
+  ///
+  if ((MicrocodeHeader->TotalSize & (SIZE_1KB - 1)) != 0) {
+return FALSE;
+  }
+
+  ///
+  /// Verify DataSize and TotalSize.
+  ///
+  if (MicrocodeHeader->DataSize == 0) {
+DataSize = 2000;
+  } else {
+DataSize = MicrocodeHeader->DataSize;
+  }
+
+  if ( (MicrocodeHeader->TotalSize <= sizeof (CPU_MICROCODE_HEADER)) ||
+   (MicrocodeHeader->TotalSize <= DataSize) ||
+   (MicrocodeHeader->TotalSize != sizeof (CPU_MICROCODE_HEADER) + DataSize)
+ ) {
+return FALSE;
+  }
+
+  return TRUE;
+}
+
 /**
   Detect whether specified processor can find matching microcode patch and 
load it.
 
@@ -166,6 +226,18 @@ MicrocodeDetect (
 //
 CorrectMicrocode = FALSE;
 
+if (!IsMicrocodeHeaderValid (MicrocodeEntryPoint)) {
+  //
+  // It is the padding data between the microcode patches for microcode 
patches alignment.
+  // Because the microcode patch is the multiple of 1-KByte, the padding 
data should not
+  // exist if the microcode patch alignment value is not larger than 
1-KByte. So, the microcode
+  // alignment value should be larger than 1-KByte. We could skip SIZE_1KB 
padding data to
+  // find the next possible microcode patch header.
+  //
+  MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) (((UINTN) 
MicrocodeEntryPoint) + SIZE_1KB);
+  continue;
+}
+
 //
 // Save an in-complete CheckSum32 from CheckSum Part1 for common parts.
 //
@@ -184,90 +256,79 @@ MicrocodeDetect (
 InCompleteCheckSum32 -= MicrocodeEntryPoint->ProcessorFlags;
 InCompleteCheckSum32 -= MicrocodeEntryPoint->Checksum;
 
-if (MicrocodeEntryPoint->HeaderVersion == 0x1) {
+//
+// It is the microcode header. It is not the padding data between 
microcode patches
+// because the padding data should not include 0x0001 and it should be 
the repeated
+// byte format (like 0xXYXYXYXY).
+//
+if (MicrocodeEntryPoint->ProcessorSignature.Uint32 == Eax.Uint32 &&
+MicrocodeEntryPoint->UpdateRevision > LatestRevision &&
+(MicrocodeEntryPoint->ProcessorFlags & (1 << PlatformId))
+) {
   //
-  // It is the microcode header. It is not the padding data between 
microcode patches
-  // because the padding data should not include 0x0001 and it should 
be the repeated
-  // byte format (like 0xXYXYXYXY).
+  // Calculate CheckSum Part1.
   //
-  if (MicrocodeEntryPoint->ProcessorSignature.Uint32 == Eax.Uint32 &&
-  MicrocodeEntryPoint->UpdateRevision > LatestRevision &&
-  (MicrocodeEntryPoint->ProcessorFlags & (1 << PlatformId))
-  ) {
+  CheckSum32 = InCompleteCheckSum32;
+  CheckSum32 += MicrocodeEntryPoint->ProcessorSignature.Uint32;
+  CheckSum32 += MicrocodeEntryPoint->ProcessorFlags;
+  CheckSum32 += MicrocodeEntryPoint->Checksum;
+  if (CheckSum32 == 0) {
+CorrectMicrocode = TRUE;
+ProcessorFlags = MicrocodeEntryPoint->ProcessorFlags;
+  }
+} else if ((MicrocodeEntryPoint->DataSize != 0) &&
+   (MicrocodeEntryPoint->UpdateRevision > LatestRevision)) {
+  ExtendedTableLength = MicrocodeEntryPoint->TotalSize - 
(MicrocodeEntryPoint->DataSize +
+ 

[edk2] [PATCH 2/2] UefiCpuPkg/Microcode: Add verification logic before parsing payload

2019-02-27 Thread Chen A Chen
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1020

The function MicrocodeDetect may receive untrusted input. Add verification
logic to check Microcode Payload Header.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
Cc: Ray Ni 
Cc: Eric Dong 
---
 UefiCpuPkg/Library/MpInitLib/Microcode.c | 190 +--
 1 file changed, 127 insertions(+), 63 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c 
b/UefiCpuPkg/Library/MpInitLib/Microcode.c
index 5f9ae22794..1d5e964791 100644
--- a/UefiCpuPkg/Library/MpInitLib/Microcode.c
+++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c
@@ -32,6 +32,69 @@ GetCurrentMicrocodeSignature (
   return BiosSignIdMsr.Bits.MicrocodeUpdateSignature;
 }
 
+/**
+  Verify Microcode.
+
+  @param[in]  MicrocodeHeader   Point to the Microcode payload buffer.
+
+  @retval TRUE  Valid payload
+  @retval FALSE Invalid payload
+**/
+BOOLEAN
+VerifyMicrocodeHeader (
+  IN CPU_MICROCODE_HEADER *MicrocodeHeader
+  )
+{
+  UINTN   TotalSize;
+  UINTN   DataSize;
+
+  if (MicrocodeHeader == NULL) {
+return FALSE;
+  }
+
+  ///
+  /// Verify Version
+  ///
+  if (MicrocodeHeader->HeaderVersion != 0x1) {
+return FALSE;
+  }
+  if (MicrocodeHeader->LoaderRevision != 0x1) {
+return FALSE;
+  }
+
+  ///
+  /// Verify TotalSize
+  ///
+  if (MicrocodeHeader->DataSize == 0) {
+TotalSize = 2048;
+  } else {
+TotalSize = MicrocodeHeader->TotalSize;
+  }
+  if (TotalSize <= sizeof (CPU_MICROCODE_HEADER)) {
+return FALSE;
+  }
+  if ((TotalSize & (SIZE_1KB - 1)) != 0) {
+return FALSE;
+  }
+
+  ///
+  /// Verify DataSize
+  ///
+  if (MicrocodeHeader->DataSize == 0) {
+DataSize = 2048 - sizeof (CPU_MICROCODE_HEADER);
+  } else {
+DataSize = MicrocodeHeader->DataSize;
+  }
+  if (DataSize > TotalSize - sizeof (CPU_MICROCODE_HEADER)) {
+return FALSE;
+  }
+  if ((DataSize & 0x3) != 0) {
+return FALSE;
+  }
+
+  return TRUE;
+}
+
 /**
   Detect whether specified processor can find matching microcode patch and 
load it.
 
@@ -166,6 +229,18 @@ MicrocodeDetect (
 //
 CorrectMicrocode = FALSE;
 
+if (!VerifyMicrocodeHeader (MicrocodeEntryPoint)) {
+  //
+  // It is the padding data between the microcode patches for microcode 
patches alignment.
+  // Because the microcode patch is the multiple of 1-KByte, the padding 
data should not
+  // exist if the microcode patch alignment value is not larger than 
1-KByte. So, the microcode
+  // alignment value should be larger than 1-KByte. We could skip SIZE_1KB 
padding data to
+  // find the next possible microcode patch header.
+  //
+  MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) (((UINTN) 
MicrocodeEntryPoint) + SIZE_1KB);
+  continue;
+}
+
 //
 // Save an in-complete CheckSum32 from CheckSum Part1 for common parts.
 //
@@ -184,90 +259,79 @@ MicrocodeDetect (
 InCompleteCheckSum32 -= MicrocodeEntryPoint->ProcessorFlags;
 InCompleteCheckSum32 -= MicrocodeEntryPoint->Checksum;
 
-if (MicrocodeEntryPoint->HeaderVersion == 0x1) {
+//
+// It is the microcode header. It is not the padding data between 
microcode patches
+// because the padding data should not include 0x0001 and it should be 
the repeated
+// byte format (like 0xXYXYXYXY).
+//
+if (MicrocodeEntryPoint->ProcessorSignature.Uint32 == Eax.Uint32 &&
+MicrocodeEntryPoint->UpdateRevision > LatestRevision &&
+(MicrocodeEntryPoint->ProcessorFlags & (1 << PlatformId))
+) {
   //
-  // It is the microcode header. It is not the padding data between 
microcode patches
-  // because the padding data should not include 0x0001 and it should 
be the repeated
-  // byte format (like 0xXYXYXYXY).
+  // Calculate CheckSum Part1.
   //
-  if (MicrocodeEntryPoint->ProcessorSignature.Uint32 == Eax.Uint32 &&
-  MicrocodeEntryPoint->UpdateRevision > LatestRevision &&
-  (MicrocodeEntryPoint->ProcessorFlags & (1 << PlatformId))
-  ) {
+  CheckSum32 = InCompleteCheckSum32;
+  CheckSum32 += MicrocodeEntryPoint->ProcessorSignature.Uint32;
+  CheckSum32 += MicrocodeEntryPoint->ProcessorFlags;
+  CheckSum32 += MicrocodeEntryPoint->Checksum;
+  if (CheckSum32 == 0) {
+CorrectMicrocode = TRUE;
+ProcessorFlags = MicrocodeEntryPoint->ProcessorFlags;
+  }
+} else if ((MicrocodeEntryPoint->DataSize != 0) &&
+   (MicrocodeEntryPoint->UpdateRevision > LatestRevision)) {
+  ExtendedTableLength = MicrocodeEntryPoint->TotalSize - 
(MicrocodeEntryPoint->DataSize +
+  sizeof (CPU_MICROCODE_HEADER));
+  if (ExtendedTableLength != 0

[edk2] [PATCH 1/2] UefiCpuPkg/Microcode: Fix InComplete CheckSum32 issue

2019-02-27 Thread Chen A Chen
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1020

The Microcode region indicated by MicrocodePatchAddress PCD may contain
more than one Microcode entry. We should save InCompleteCheckSum32 value
for each payload. Move the logic for calculate InCompleteCheckSum32 from
the outsize of the do-while loop to the inside.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
Cc: Ray Ni 
Cc: Eric Dong 
---
 UefiCpuPkg/Library/MpInitLib/Microcode.c | 37 
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c 
b/UefiCpuPkg/Library/MpInitLib/Microcode.c
index e1f661d6b1..5f9ae22794 100644
--- a/UefiCpuPkg/Library/MpInitLib/Microcode.c
+++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c
@@ -159,30 +159,31 @@ MicrocodeDetect (
   MicrocodeEnd = (UINTN) (CpuMpData->MicrocodePatchAddress + 
CpuMpData->MicrocodePatchRegionSize);
   MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) (UINTN) 
CpuMpData->MicrocodePatchAddress;
 
-  //
-  // Save an in-complete CheckSum32 from CheckSum Part1 for common parts.
-  //
-  if (MicrocodeEntryPoint->DataSize == 0) {
-InCompleteCheckSum32 = CalculateSum32 (
- (UINT32 *) MicrocodeEntryPoint,
- sizeof (CPU_MICROCODE_HEADER) + 2000
- );
-  } else {
-InCompleteCheckSum32 = CalculateSum32 (
- (UINT32 *) MicrocodeEntryPoint,
- sizeof (CPU_MICROCODE_HEADER) + 
MicrocodeEntryPoint->DataSize
- );
-  }
-  InCompleteCheckSum32 -= MicrocodeEntryPoint->ProcessorSignature.Uint32;
-  InCompleteCheckSum32 -= MicrocodeEntryPoint->ProcessorFlags;
-  InCompleteCheckSum32 -= MicrocodeEntryPoint->Checksum;
-
   do {
 //
 // Check if the microcode is for the Cpu and the version is newer
 // and the update can be processed on the platform
 //
 CorrectMicrocode = FALSE;
+
+//
+// Save an in-complete CheckSum32 from CheckSum Part1 for common parts.
+//
+if (MicrocodeEntryPoint->DataSize == 0) {
+  InCompleteCheckSum32 = CalculateSum32 (
+   (UINT32 *) MicrocodeEntryPoint,
+   sizeof (CPU_MICROCODE_HEADER) + 2000
+   );
+} else {
+  InCompleteCheckSum32 = CalculateSum32 (
+   (UINT32 *) MicrocodeEntryPoint,
+   sizeof (CPU_MICROCODE_HEADER) + 
MicrocodeEntryPoint->DataSize
+   );
+}
+InCompleteCheckSum32 -= MicrocodeEntryPoint->ProcessorSignature.Uint32;
+InCompleteCheckSum32 -= MicrocodeEntryPoint->ProcessorFlags;
+InCompleteCheckSum32 -= MicrocodeEntryPoint->Checksum;
+
 if (MicrocodeEntryPoint->HeaderVersion == 0x1) {
   //
   // It is the microcode header. It is not the padding data between 
microcode patches
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 0/2] Fix Microcode failure issue

2019-02-27 Thread Chen A Chen
The first patch is used to fix InComplete CheckSum32 issue.
Add a verification logic to check Microcode header before parsing payload.

Chen A Chen (2):
  UefiCpuPkg/Microcode: Fix InComplete CheckSum32 issue
  UefiCpuPkg/Microcode: Add verification logic before parsing payload

 UefiCpuPkg/Library/MpInitLib/Microcode.c | 227 ---
 1 file changed, 146 insertions(+), 81 deletions(-)

-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] IntelSiliconPkg/MicrocodeUpdate: Fix incorrect checksum issue

2019-02-21 Thread Chen A Chen
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1020

The same issue has fixed in UefiCpuPkg/Microcode.c file.
Please reference b6f67b4d58b81f12f63f5f8c94cf8af3600297ab
to get more detail information.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
Cc: Ray Ni 
Cc: Rangasai V Chaganty 
---
 .../Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdate.c   | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git 
a/IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdate.c 
b/IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdate.c
index 9b5757da71..e45c7a8def 100644
--- a/IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdate.c
+++ b/IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdate.c
@@ -390,6 +390,7 @@ VerifyMicrocode (
   UINTN   DataSize;
   UINT32  CurrentRevision;
   PROCESSOR_INFO  *ProcessorInfo;
+  UINT32  InCompleteCheckSum32;
   UINT32  CheckSum32;
   UINTN   ExtendedTableLength;
   UINT32  ExtendedTableCount;
@@ -488,6 +489,10 @@ VerifyMicrocode (
 }
 return EFI_VOLUME_CORRUPTED;
   }
+  InCompleteCheckSum32 = CheckSum32;
+  InCompleteCheckSum32 -= MicrocodeEntryPoint->ProcessorSignature.Uint32;
+  InCompleteCheckSum32 -= MicrocodeEntryPoint->ProcessorFlags;
+  InCompleteCheckSum32 -= MicrocodeEntryPoint->Checksum;
 
   //
   // Check ProcessorSignature/ProcessorFlags
@@ -522,7 +527,10 @@ VerifyMicrocode (
   } else {
 ExtendedTable = (CPU_MICROCODE_EXTENDED_TABLE 
*)(ExtendedTableHeader + 1);
 for (Index = 0; Index < ExtendedTableCount; Index++) {
-  CheckSum32 = CalculateSum32((UINT32 *)ExtendedTable, 
sizeof(CPU_MICROCODE_EXTENDED_TABLE));
+  CheckSum32 = InCompleteCheckSum32;
+  CheckSum32 += ExtendedTable->ProcessorSignature.Uint32;
+  CheckSum32 += ExtendedTable->ProcessorFlag;
+  CheckSum32 += ExtendedTable->Checksum;
   if (CheckSum32 != 0) {
 DEBUG((DEBUG_ERROR, "VerifyMicrocode - The checksum for 
ExtendedTable entry with index 0x%x is incorrect\n", Index));
   } else {
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] MdeModulePkg: Rename confusion function name

2019-02-21 Thread Chen A Chen
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1536

To avoid the confusion caused by function name,
rename EfiBootManagerGetNextFullDevicePath to
EfiBootManagerGetNextLoadOptionDevicePath.
As an API function should add EFIAPI prefix for this function.

Cc: Ray Ni 
Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c | 2 +-
 MdeModulePkg/Include/Library/UefiBootManagerLib.h   | 3 ++-
 MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c| 3 ++-
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c 
b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
index f6e46cbdb1..4ff69af1b4 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
@@ -355,7 +355,7 @@ GetEfiSysPartitionFromBootOptionFilePath (
   //
   do {
 PreFullPath = CurFullPath;
-CurFullPath = EfiBootManagerGetNextFullDevicePath (DevicePath, 
CurFullPath);
+CurFullPath = EfiBootManagerGetNextLoadOptionDevicePath (DevicePath, 
CurFullPath);
 
 if (PreFullPath != NULL) {
   FreePool (PreFullPath);
diff --git a/MdeModulePkg/Include/Library/UefiBootManagerLib.h 
b/MdeModulePkg/Include/Library/UefiBootManagerLib.h
index 64347ff160..69678a62ca 100644
--- a/MdeModulePkg/Include/Library/UefiBootManagerLib.h
+++ b/MdeModulePkg/Include/Library/UefiBootManagerLib.h
@@ -460,7 +460,8 @@ EfiBootManagerGetBootManagerMenu (
   Caller is responsible to free the memory.
 **/
 EFI_DEVICE_PATH_PROTOCOL *
-EfiBootManagerGetNextFullDevicePath (
+EFIAPI
+EfiBootManagerGetNextLoadOptionDevicePath (
   IN  EFI_DEVICE_PATH_PROTOCOL  *FilePath,
   IN  EFI_DEVICE_PATH_PROTOCOL  *FullPath
   );
diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c 
b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
index 9be1633b74..d5957db610 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
@@ -2482,7 +2482,8 @@ EfiBootManagerGetBootManagerMenu (
   Caller is responsible to free the memory.
 **/
 EFI_DEVICE_PATH_PROTOCOL *
-EfiBootManagerGetNextFullDevicePath (
+EFIAPI
+EfiBootManagerGetNextLoadOptionDevicePath (
   IN  EFI_DEVICE_PATH_PROTOCOL  *FilePath,
   IN  EFI_DEVICE_PATH_PROTOCOL  *FullPath
   )
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v2] UefiCpuPkg/Microcode: Fix incorrect checksum issue for extended table

2019-02-19 Thread Chen A Chen
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1020

The following Microcode payload format is define in SDM spec.
Payload: |MicrocodeHeader|MicrocodeBinary|ExtendedHeader|ExtendedTable|.
When we verify the CheckSum32 with ExtendedTable, we should use the fields
of ExtendedTable to replace corresponding fields in MicrocodeHeader,
and then calculate the CheckSum32 with MicrocodeHeader+MicrocodeBinary.
This patch already verified on ICL platform.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
Cc: Ray Ni 
Cc: Eric Dong 
Cc: Zhang Chao B 
---
 UefiCpuPkg/Library/MpInitLib/Microcode.c | 82 
 1 file changed, 73 insertions(+), 9 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c 
b/UefiCpuPkg/Library/MpInitLib/Microcode.c
index d84344c6f5..e1f661d6b1 100644
--- a/UefiCpuPkg/Library/MpInitLib/Microcode.c
+++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c
@@ -35,6 +35,42 @@ GetCurrentMicrocodeSignature (
 /**
   Detect whether specified processor can find matching microcode patch and 
load it.
 
+  Microcode Payload as the following format:
+  ++--+
+  |  CPU_MICROCODE_HEADER  |  |
+  ++  CheckSum Part1  |
+  |Microcode Binary|  |
+  ++--+
+  |  CPU_MICROCODE_EXTENDED_TABLE_HEADER   |  |
+  ++  CheckSum Part2  |
+  |  CPU_MICROCODE_EXTENDED_TABLE  |  |
+  |   ...  |  |
+  ++--+
+
+  There may by multiple CPU_MICROCODE_EXTENDED_TABLE in this format.
+  The count of CPU_MICROCODE_EXTENDED_TABLE is indicated by 
ExtendedSignatureCount
+  of CPU_MICROCODE_EXTENDED_TABLE_HEADER structure.
+
+  When we are trying to verify the CheckSum32 with extended table.
+  We should use the fields of exnteded table to replace the corresponding
+  fields in CPU_MICROCODE_HEADER structure, and recalculate the
+  CheckSum32 with CPU_MICROCODE_HEADER + Microcode Binary. We named
+  it as CheckSum Part3.
+
+  The CheckSum Part2 is used to verify the CPU_MICROCODE_EXTENDED_TABLE_HEADER
+  and CPU_MICROCODE_EXTENDED_TABLE parts. We should make sure CheckSum Part2
+  is correct before we are going to verify each CPU_MICROCODE_EXTENDED_TABLE.
+
+  Only ProcessorSignature, ProcessorFlag and CheckSum are different between
+  CheckSum Part1 and CheckSum Part3. To avoid multiple computing CheckSum 
Part3.
+  Save an in-complete CheckSum32 from CheckSum Part1 for common parts.
+  When we are going to calculate CheckSum32, just should use the corresponding 
part
+  of the ProcessorSignature, ProcessorFlag and CheckSum with in-complete 
CheckSum32.
+
+  Notes: CheckSum32 is not a strong verification.
+ It does not guarantee that the data has not been modified.
+ CPU has its own mechanism to verify Microcode Binary part.
+
   @param[in]  CpuMpDataThe pointer to CPU MP Data structure.
   @param[in]  IsBspCallIn  Indicate whether the caller is BSP or not.
 **/
@@ -57,6 +93,7 @@ MicrocodeDetect (
   UINT32  LatestRevision;
   UINTN   TotalSize;
   UINT32  CheckSum32;
+  UINT32  InCompleteCheckSum32;
   BOOLEAN CorrectMicrocode;
   VOID*MicrocodeData;
   MSR_IA32_PLATFORM_ID_REGISTER   PlatformIdMsr;
@@ -121,6 +158,25 @@ MicrocodeDetect (
   MicrocodeData  = NULL;
   MicrocodeEnd = (UINTN) (CpuMpData->MicrocodePatchAddress + 
CpuMpData->MicrocodePatchRegionSize);
   MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) (UINTN) 
CpuMpData->MicrocodePatchAddress;
+
+  //
+  // Save an in-complete CheckSum32 from CheckSum Part1 for common parts.
+  //
+  if (MicrocodeEntryPoint->DataSize == 0) {
+InCompleteCheckSum32 = CalculateSum32 (
+ (UINT32 *) MicrocodeEntryPoint,
+ sizeof (CPU_MICROCODE_HEADER) + 2000
+ );
+  } else {
+InCompleteCheckSum32 = CalculateSum32 (
+ (UINT32 *) MicrocodeEntryPoint,
+ sizeof (CPU_MICROCODE_HEADER) + 
MicrocodeEntryPoint->DataSize
+ );
+  }
+  InCompleteCheckSum32 -= MicrocodeEntryPoint->ProcessorSignature.Uint32;
+  InCompleteCheckSum32 -= MicrocodeEntryPoint->ProcessorFlags;
+  InCompleteCheckSum32 -= MicrocodeEntryPoint->Checksum;
+
   do {
 //
 // Check if the microcode is for the Cpu and the version is newer
@@ -137,14 +193,13 @@ MicrocodeDetect (
   MicrocodeEntryPoint->Upda

[edk2] [PATCH] UefiCpuPkg/Microcode: Fix incorrect checksum issue for extended table

2019-02-18 Thread Chen A Chen
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1020

The following Microcode payload format is define in SDM spec.
Payload: |MicrocodeHeader|MicrocodeBinary|ExtendedHeader|ExtendedTable|.
When we verify the CheckSum32 with ExtendedTable, we should use the fields
of ExtendedTable to replace corresponding fields in MicrocodeHeader,
and then calculate the CheckSum32 with MicrocodeHeader+MicrocodeBinary.
This patch already verified on ICL platform.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
Cc: Ray Ni 
Cc: Eric Dong 
Cc: Zhang Chao B 
---
 UefiCpuPkg/Library/MpInitLib/Microcode.c | 82 
 1 file changed, 73 insertions(+), 9 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c 
b/UefiCpuPkg/Library/MpInitLib/Microcode.c
index d84344c6f5..e1f661d6b1 100644
--- a/UefiCpuPkg/Library/MpInitLib/Microcode.c
+++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c
@@ -35,6 +35,42 @@ GetCurrentMicrocodeSignature (
 /**
   Detect whether specified processor can find matching microcode patch and 
load it.
 
+  Microcode Payload as the following format:
+  ++--+
+  |  CPU_MICROCODE_HEADER  |  |
+  ++  CheckSum Part1  |
+  |Microcode Binary|  |
+  ++--+
+  |  CPU_MICROCODE_EXTENDED_TABLE_HEADER   |  |
+  ++  CheckSum Part2  |
+  |  CPU_MICROCODE_EXTENDED_TABLE  |  |
+  |   ...  |  |
+  ++--+
+
+  There may by multiple CPU_MICROCODE_EXTENDED_TABLE in this format.
+  The count of CPU_MICROCODE_EXTENDED_TABLE is indicated by 
ExtendedSignatureCount
+  of CPU_MICROCODE_EXTENDED_TABLE_HEADER structure.
+
+  When we are trying to verify the CheckSum32 with extended table.
+  We should use the fields of exnteded table to replace the corresponding
+  fields in CPU_MICROCODE_HEADER structure, and recalculate the
+  CheckSum32 with CPU_MICROCODE_HEADER + Microcode Binary. We named
+  it as CheckSum Part3.
+
+  The CheckSum Part2 is used to verify the CPU_MICROCODE_EXTENDED_TABLE_HEADER
+  and CPU_MICROCODE_EXTENDED_TABLE parts. We should make sure CheckSum Part2
+  is correct before we are going to verify each CPU_MICROCODE_EXTENDED_TABLE.
+
+  Only ProcessorSignature, ProcessorFlag and CheckSum are different between
+  CheckSum Part1 and CheckSum Part3. To avoid multiple computing CheckSum 
Part3.
+  Save an in-complete CheckSum32 from CheckSum Part1 for common parts.
+  When we are going to calculate CheckSum32, just should use the corresponding 
part
+  of the ProcessorSignature, ProcessorFlag and CheckSum with in-complete 
CheckSum32.
+
+  Notes: CheckSum32 is not a strong verification.
+ It does not guarantee that the data has not been modified.
+ CPU has its own mechanism to verify Microcode Binary part.
+
   @param[in]  CpuMpDataThe pointer to CPU MP Data structure.
   @param[in]  IsBspCallIn  Indicate whether the caller is BSP or not.
 **/
@@ -57,6 +93,7 @@ MicrocodeDetect (
   UINT32  LatestRevision;
   UINTN   TotalSize;
   UINT32  CheckSum32;
+  UINT32  InCompleteCheckSum32;
   BOOLEAN CorrectMicrocode;
   VOID*MicrocodeData;
   MSR_IA32_PLATFORM_ID_REGISTER   PlatformIdMsr;
@@ -121,6 +158,25 @@ MicrocodeDetect (
   MicrocodeData  = NULL;
   MicrocodeEnd = (UINTN) (CpuMpData->MicrocodePatchAddress + 
CpuMpData->MicrocodePatchRegionSize);
   MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) (UINTN) 
CpuMpData->MicrocodePatchAddress;
+
+  //
+  // Save an in-complete CheckSum32 from CheckSum Part1 for common parts.
+  //
+  if (MicrocodeEntryPoint->DataSize == 0) {
+InCompleteCheckSum32 = CalculateSum32 (
+ (UINT32 *) MicrocodeEntryPoint,
+ sizeof (CPU_MICROCODE_HEADER) + 2000
+ );
+  } else {
+InCompleteCheckSum32 = CalculateSum32 (
+ (UINT32 *) MicrocodeEntryPoint,
+ sizeof (CPU_MICROCODE_HEADER) + 
MicrocodeEntryPoint->DataSize
+ );
+  }
+  InCompleteCheckSum32 -= MicrocodeEntryPoint->ProcessorSignature.Uint32;
+  InCompleteCheckSum32 -= MicrocodeEntryPoint->ProcessorFlags;
+  InCompleteCheckSum32 -= MicrocodeEntryPoint->Checksum;
+
   do {
 //
 // Check if the microcode is for the Cpu and the version is newer
@@ -137,14 +193,13 @@ MicrocodeDetect (
   MicrocodeEntryPoint->Upda

[edk2] [PATCH] UefiCpuPkg/Microcode: Fix incorrect checksum issue for extended table

2019-02-17 Thread Chen A Chen
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1020

The following Microcode payload format is define in SDM spec.
Payload: |MicrocodeHeader|MicrocodeBinary|ExtendedHeader|ExtendedTable|.
When we verify the CheckSum32 with ExtendedTable, we should use the fields
of ExtendedTable to replace corresponding fields in MicrocodeHeader,
and then calculate the CheckSum32 with MicrocodeHeader+MicrocodeBinary.
This patch already verified on ICL platform.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
Cc: Ray Ni 
Cc: Eric Dong 
---
 UefiCpuPkg/Library/MpInitLib/Microcode.c | 38 
 1 file changed, 29 insertions(+), 9 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c 
b/UefiCpuPkg/Library/MpInitLib/Microcode.c
index d84344c6f5..38880cdbec 100644
--- a/UefiCpuPkg/Library/MpInitLib/Microcode.c
+++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c
@@ -57,6 +57,7 @@ MicrocodeDetect (
   UINT32  LatestRevision;
   UINTN   TotalSize;
   UINT32  CheckSum32;
+  UINT32  InCompleteCheckSum32;
   BOOLEAN CorrectMicrocode;
   VOID*MicrocodeData;
   MSR_IA32_PLATFORM_ID_REGISTER   PlatformIdMsr;
@@ -121,6 +122,26 @@ MicrocodeDetect (
   MicrocodeData  = NULL;
   MicrocodeEnd = (UINTN) (CpuMpData->MicrocodePatchAddress + 
CpuMpData->MicrocodePatchRegionSize);
   MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) (UINTN) 
CpuMpData->MicrocodePatchAddress;
+
+  //
+  // To avoid double calculate checksum32 value.
+  // Save the CheckSum32 of the common parts in advance.
+  //
+  if (MicrocodeEntryPoint->DataSize == 0) {
+InCompleteCheckSum32 = CalculateSum32 (
+ (UINT32 *) MicrocodeEntryPoint,
+ sizeof (CPU_MICROCODE_HEADER) + 2000
+ );
+  } else {
+InCompleteCheckSum32 = CalculateSum32 (
+ (UINT32 *) MicrocodeEntryPoint,
+ sizeof (CPU_MICROCODE_HEADER) + 
MicrocodeEntryPoint->DataSize
+ );
+  }
+  InCompleteCheckSum32 -= MicrocodeEntryPoint->ProcessorSignature.Uint32;
+  InCompleteCheckSum32 -= MicrocodeEntryPoint->ProcessorFlags;
+  InCompleteCheckSum32 -= MicrocodeEntryPoint->Checksum;
+
   do {
 //
 // Check if the microcode is for the Cpu and the version is newer
@@ -137,14 +158,10 @@ MicrocodeDetect (
   MicrocodeEntryPoint->UpdateRevision > LatestRevision &&
   (MicrocodeEntryPoint->ProcessorFlags & (1 << PlatformId))
   ) {
-if (MicrocodeEntryPoint->DataSize == 0) {
-  CheckSum32 = CalculateSum32 ((UINT32 *) MicrocodeEntryPoint, 2048);
-} else {
-  CheckSum32 = CalculateSum32 (
- (UINT32 *) MicrocodeEntryPoint,
- MicrocodeEntryPoint->DataSize + sizeof 
(CPU_MICROCODE_HEADER)
- );
-}
+CheckSum32 = InCompleteCheckSum32;
+CheckSum32 += MicrocodeEntryPoint->ProcessorSignature.Uint32;
+CheckSum32 += MicrocodeEntryPoint->ProcessorFlags;
+CheckSum32 += MicrocodeEntryPoint->Checksum;
 if (CheckSum32 == 0) {
   CorrectMicrocode = TRUE;
   ProcessorFlags = MicrocodeEntryPoint->ProcessorFlags;
@@ -171,7 +188,10 @@ MicrocodeDetect (
   ExtendedTableCount = ExtendedTableHeader->ExtendedSignatureCount;
   ExtendedTable  = (CPU_MICROCODE_EXTENDED_TABLE *) 
(ExtendedTableHeader + 1);
   for (Index = 0; Index < ExtendedTableCount; Index ++) {
-CheckSum32 = CalculateSum32 ((UINT32 *) ExtendedTable, 
sizeof(CPU_MICROCODE_EXTENDED_TABLE));
+CheckSum32 = InCompleteCheckSum32;
+CheckSum32 += ExtendedTable->ProcessorSignature.Uint32;
+CheckSum32 += ExtendedTable->ProcessorFlag;
+CheckSum32 += ExtendedTable->Checksum;
 if (CheckSum32 == 0) {
   //
   // Verify Header
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v3] MdeModulePkg/CapsuleApp: Fix memory leak issue.

2019-02-12 Thread Chen A Chen
This issue is caused by FileInfoBuffer variable. This is a pointer array
and each elements also pointer to a memory buffer that is allocated and
returned by AllocateCopyPool function.

Cc: Jian J Wang 
Cc: Hao Wu 
Cc: Zhang Chao B 
Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c | 87 ---
 1 file changed, 60 insertions(+), 27 deletions(-)

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c 
b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
index ba2583accb..9fd4af4e55 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
@@ -806,48 +806,69 @@ DumpCapsuleFromDisk (
   Status = Fs->OpenVolume (Fs, );
   if (EFI_ERROR (Status)) {
 Print (L"Cannot open volume. Status = %r\n", Status);
-return EFI_NOT_FOUND;
+goto Done;
   }
 
   Status = Root->Open (Root, , EFI_CAPSULE_FILE_DIRECTORY, 
EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE , 0);
   if (EFI_ERROR (Status)) {
 Print (L"Cannot open %s. Status = %r\n", EFI_CAPSULE_FILE_DIRECTORY, 
Status);
-return EFI_NOT_FOUND;
+goto Done;
   }
 
   //
   // Get file count first
   //
-  for ( Status = FileHandleFindFirstFile (DirHandle, )
-  ; !EFI_ERROR(Status) && !NoFile
-  ; Status = FileHandleFindNextFile (DirHandle, FileInfo, )
- ){
-if ((FileInfo->Attribute & (EFI_FILE_SYSTEM | EFI_FILE_ARCHIVE)) == 0) {
-  continue;
+  do {
+Status = FileHandleFindFirstFile (DirHandle, );
+if (EFI_ERROR (Status) || FileInfo == NULL) {
+  Print (L"Get File Info Fail. Status = %r\n", Status);
+  goto Done;
 }
-FileCount++;
-  }
+
+if ((FileInfo->Attribute & (EFI_FILE_SYSTEM | EFI_FILE_ARCHIVE)) != 0) {
+  FileCount++;
+}
+
+Status = FileHandleFindNextFile (DirHandle, FileInfo, );
+if (EFI_ERROR (Status)) {
+  Print (L"Get Next File Fail. Status = %r\n", Status);
+  goto Done;
+}
+  } while (!NoFile);
 
   if (FileCount == 0) {
 Print (L"Error: No capsule file found!\n");
-return EFI_NOT_FOUND;
+Status = EFI_NOT_FOUND;
+goto Done;
   }
 
-  FileInfoBuffer = AllocatePool (sizeof(FileInfo) * FileCount);
+  FileInfoBuffer = AllocateZeroPool (sizeof (FileInfo) * FileCount);
+  if (FileInfoBuffer == NULL) {
+Status = EFI_OUT_OF_RESOURCES;
+goto Done;
+  }
   NoFile = FALSE;
 
   //
   // Get all file info
   //
-  for ( Status = FileHandleFindFirstFile (DirHandle, )
-  ; !EFI_ERROR (Status) && !NoFile
-  ; Status = FileHandleFindNextFile (DirHandle, FileInfo, )
- ){
-if ((FileInfo->Attribute & (EFI_FILE_SYSTEM | EFI_FILE_ARCHIVE)) == 0) {
-  continue;
+  do {
+Status = FileHandleFindFirstFile (DirHandle, );
+if (EFI_ERROR (Status) || FileInfo == NULL) {
+  Print (L"Get File Info Fail. Status = %r\n", Status);
+  goto Done;
+}
+
+if ((FileInfo->Attribute & (EFI_FILE_SYSTEM | EFI_FILE_ARCHIVE)) != 0) {
+  FileInfoBuffer[Index++] = AllocateCopyPool ((UINTN)FileInfo->Size, 
FileInfo);
 }
-FileInfoBuffer[Index++] = AllocateCopyPool ((UINTN)FileInfo->Size, 
FileInfo);
-  }
+
+Status = FileHandleFindNextFile (DirHandle, FileInfo, );
+if (EFI_ERROR (Status)) {
+  Print (L"Get Next File Fail. Status = %r\n", Status);
+  goto Done;
+}
+  } while (!NoFile);
 
   //
   // Sort FileInfoBuffer by alphabet order
@@ -866,7 +887,8 @@ DumpCapsuleFromDisk (
   }
 
   if (!DumpCapsuleInfo) {
-return EFI_SUCCESS;
+Status = EFI_SUCCESS;
+goto Done;
   }
 
   Print(L"The infomation of the capsules:\n");
@@ -875,27 +897,28 @@ DumpCapsuleFromDisk (
 FileHandle = NULL;
 Status = DirHandle->Open (DirHandle, , 
FileInfoBuffer[Index]->FileName, EFI_FILE_MODE_READ, 0);
 if (EFI_ERROR (Status)) {
-  break;
+  goto Done;
 }
 
 Status = FileHandleGetSize (FileHandle, (UINT64 *) );
 if (EFI_ERROR (Status)) {
   Print (L"Cannot read file %s. Status = %r\n", 
FileInfoBuffer[Index]->FileName, Status);
   FileHandleClose (FileHandle);
-  return Status;
+  goto Done;
 }
 
 FileBuffer = AllocatePool (FileSize);
 if (FileBuffer == NULL) {
-  return RETURN_OUT_OF_RESOURCES;
+  Status = EFI_OUT_OF_RESOURCES;
+  goto Done;
 }
 
 Status = FileHandleRead (FileHandle, , FileBuffer);
 if (EFI_ERROR (Status)) {
   Print (L"Cannot read file %s. Status = %r\n", 
FileInfoBuffer[Index]->FileName, Status);
-  FreePool (FileBuffer);
   FileHandleClose (FileHandle);
-  return Status;
+  FreePool (FileBuffer);
+  goto Done;
 }
 
 Print (L"**\n");
@@ -906,7 +929,17 @@ DumpCapsuleFromDisk (
 FreePool (FileBuffer);
   }

[edk2] [PATCH v2] MdeModulePkg/CapsuleApp: Fix memory leak issue.

2019-02-11 Thread Chen A Chen
This issue is caused by FileInfoBuffer variable. This is a pointer array
and each elements also pointer to a memory buffer that is allocated and
returned by AllocateCopyPool function.

Cc: Jian J Wang 
Cc: Hao Wu 
Cc: Zhang Chao B 
Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c | 83 ---
 1 file changed, 58 insertions(+), 25 deletions(-)

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c 
b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
index ba2583accb..732472bb9c 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
@@ -806,48 +806,69 @@ DumpCapsuleFromDisk (
   Status = Fs->OpenVolume (Fs, );
   if (EFI_ERROR (Status)) {
 Print (L"Cannot open volume. Status = %r\n", Status);
-return EFI_NOT_FOUND;
+goto Done;
   }
 
   Status = Root->Open (Root, , EFI_CAPSULE_FILE_DIRECTORY, 
EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE , 0);
   if (EFI_ERROR (Status)) {
 Print (L"Cannot open %s. Status = %r\n", EFI_CAPSULE_FILE_DIRECTORY, 
Status);
-return EFI_NOT_FOUND;
+goto Done;
   }
 
   //
   // Get file count first
   //
-  for ( Status = FileHandleFindFirstFile (DirHandle, )
-  ; !EFI_ERROR(Status) && !NoFile
-  ; Status = FileHandleFindNextFile (DirHandle, FileInfo, )
- ){
-if ((FileInfo->Attribute & (EFI_FILE_SYSTEM | EFI_FILE_ARCHIVE)) == 0) {
-  continue;
+  do {
+Status = FileHandleFindFirstFile (DirHandle, );
+if (EFI_ERROR (Status) || FileInfo == NULL) {
+  Print (L"Get File Info Fail. Status = %r\n", Status);
+  goto Done;
 }
-FileCount++;
-  }
+
+if ((FileInfo->Attribute & (EFI_FILE_SYSTEM | EFI_FILE_ARCHIVE)) != 0) {
+  FileCount++;
+}
+
+Status = FileHandleFindNextFile (DirHandle, FileInfo, );
+if (EFI_ERROR (Status)) {
+  Print (L"Get Next File Fail. Status = %r\n", Status);
+  goto Done;
+}
+  } while (!NoFile);
 
   if (FileCount == 0) {
 Print (L"Error: No capsule file found!\n");
-return EFI_NOT_FOUND;
+Status = EFI_NOT_FOUND;
+goto Done;
   }
 
   FileInfoBuffer = AllocatePool (sizeof(FileInfo) * FileCount);
+  if (FileInfoBuffer == NULL) {
+Status = EFI_OUT_OF_RESOURCES;
+goto Done;
+  }
   NoFile = FALSE;
 
   //
   // Get all file info
   //
-  for ( Status = FileHandleFindFirstFile (DirHandle, )
-  ; !EFI_ERROR (Status) && !NoFile
-  ; Status = FileHandleFindNextFile (DirHandle, FileInfo, )
- ){
-if ((FileInfo->Attribute & (EFI_FILE_SYSTEM | EFI_FILE_ARCHIVE)) == 0) {
-  continue;
+  do {
+Status = FileHandleFindFirstFile (DirHandle, );
+if (EFI_ERROR (Status) || FileInfo == NULL) {
+  Print (L"Get File Info Fail. Status = %r\n", Status);
+  goto Done;
+}
+
+if ((FileInfo->Attribute & (EFI_FILE_SYSTEM | EFI_FILE_ARCHIVE)) != 0) {
+  FileInfoBuffer[Index++] = AllocateCopyPool ((UINTN)FileInfo->Size, 
FileInfo);
 }
-FileInfoBuffer[Index++] = AllocateCopyPool ((UINTN)FileInfo->Size, 
FileInfo);
-  }
+
+Status = FileHandleFindNextFile (DirHandle, FileInfo, );
+if (EFI_ERROR (Status)) {
+  Print (L"Get Next File Fail. Status = %r\n", Status);
+  goto Done;
+}
+  } while (!NoFile);
 
   //
   // Sort FileInfoBuffer by alphabet order
@@ -866,7 +887,8 @@ DumpCapsuleFromDisk (
   }
 
   if (!DumpCapsuleInfo) {
-return EFI_SUCCESS;
+Status = EFI_SUCCESS;
+goto Done;
   }
 
   Print(L"The infomation of the capsules:\n");
@@ -875,19 +897,20 @@ DumpCapsuleFromDisk (
 FileHandle = NULL;
 Status = DirHandle->Open (DirHandle, , 
FileInfoBuffer[Index]->FileName, EFI_FILE_MODE_READ, 0);
 if (EFI_ERROR (Status)) {
-  break;
+  goto Done;
 }
 
 Status = FileHandleGetSize (FileHandle, (UINT64 *) );
 if (EFI_ERROR (Status)) {
   Print (L"Cannot read file %s. Status = %r\n", 
FileInfoBuffer[Index]->FileName, Status);
   FileHandleClose (FileHandle);
-  return Status;
+  goto Done;
 }
 
 FileBuffer = AllocatePool (FileSize);
 if (FileBuffer == NULL) {
-  return RETURN_OUT_OF_RESOURCES;
+  Status = EFI_OUT_OF_RESOURCES;
+  goto Done;
 }
 
 Status = FileHandleRead (FileHandle, , FileBuffer);
@@ -895,7 +918,7 @@ DumpCapsuleFromDisk (
   Print (L"Cannot read file %s. Status = %r\n", 
FileInfoBuffer[Index]->FileName, Status);
   FreePool (FileBuffer);
   FileHandleClose (FileHandle);
-  return Status;
+  goto Done;
 }
 
 Print (L"**\n");
@@ -906,7 +929,17 @@ DumpCapsuleFromDisk (
 FreePool (FileBuffer);
   }
 
-  return EFI_SUCCESS;
+Done:
+  if (FileInfoBuffer != NULL) {
+for (Index = 0; Ind

[edk2] [PATCH] MdeModulePkg/CapsuleApp: Fix memory leak issue.

2019-02-10 Thread Chen A Chen
This issue is caused by FileInfoBuffer variable. This is a pointer array
and each elements also pointer to a memory buffer that is allocated and
returned by AllocateCopyPool function.

Cc: Jian J Wang 
Cc: Hao Wu 
Cc: Zhang Chao B 
Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c | 81 ---
 1 file changed, 56 insertions(+), 25 deletions(-)

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c 
b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
index 7bef5a1378..00cf45d66a 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
@@ -806,48 +806,69 @@ DumpCapsuleFromDisk (
   Status = Fs->OpenVolume (Fs, );
   if (EFI_ERROR (Status)) {
 Print (L"Cannot open volume. Status = %r\n", Status);
-return EFI_NOT_FOUND;
+goto Done;
   }
 
   Status = Root->Open (Root, , EFI_CAPSULE_FILE_DIRECTORY, 
EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE , 0);
   if (EFI_ERROR (Status)) {
 Print (L"Cannot open %s. Status = %r\n", EFI_CAPSULE_FILE_DIRECTORY, 
Status);
-return EFI_NOT_FOUND;
+goto Done;
   }
 
   //
   // Get file count first
   //
-  for ( Status = FileHandleFindFirstFile (DirHandle, )
-  ; !EFI_ERROR(Status) && !NoFile
-  ; Status = FileHandleFindNextFile (DirHandle, FileInfo, )
- ){
-if ((FileInfo->Attribute & (EFI_FILE_SYSTEM | EFI_FILE_ARCHIVE)) == 0) {
-  continue;
+  do {
+Status = FileHandleFindFirstFile (DirHandle, );
+if (EFI_ERROR (Status) || FileInfo == NULL) {
+  Print (L"Get File Info Fail. Status = %r\n", Status);
+  goto Done;
 }
-FileCount++;
-  }
+
+if ((FileInfo->Attribute & (EFI_FILE_SYSTEM | EFI_FILE_ARCHIVE)) != 0) {
+  FileCount++;
+}
+
+Status = FileHandleFindNextFile (DirHandle, FileInfo, );
+if (EFI_ERROR (Status)) {
+  Print (L"Get Next File Fail. Status = %r\n", Status);
+  goto Done;
+}
+  } while (!NoFile);
 
   if (FileCount == 0) {
 Print (L"Error: No capsule file found!\n");
-return EFI_NOT_FOUND;
+Status = EFI_NOT_FOUND;
+goto Done;
   }
 
   FileInfoBuffer = AllocatePool (sizeof(FileInfo) * FileCount);
+  if (FileInfoBuffer == NULL) {
+Status = EFI_OUT_OF_RESOURCES;
+goto Done;
+  }
   NoFile = FALSE;
 
   //
   // Get all file info
   //
-  for ( Status = FileHandleFindFirstFile (DirHandle, )
-  ; !EFI_ERROR (Status) && !NoFile
-  ; Status = FileHandleFindNextFile (DirHandle, FileInfo, )
- ){
-if ((FileInfo->Attribute & (EFI_FILE_SYSTEM | EFI_FILE_ARCHIVE)) == 0) {
-  continue;
+  do {
+Status = FileHandleFindFirstFile (DirHandle, );
+if (EFI_ERROR (Status) || FileInfo == NULL) {
+  Print (L"Get File Info Fail. Status = %r\n", Status);
+  goto Done;
 }
-FileInfoBuffer[Index++] = AllocateCopyPool ((UINTN)FileInfo->Size, 
FileInfo);
-  }
+
+if ((FileInfo->Attribute & (EFI_FILE_SYSTEM | EFI_FILE_ARCHIVE)) != 0) {
+  FileInfoBuffer[Index++] = AllocateCopyPool ((UINTN)FileInfo->Size, 
FileInfo);
+}
+
+Status = FileHandleFindNextFile (DirHandle, FileInfo, );
+if (EFI_ERROR (Status)) {
+  Print (L"Get Next File Fail. Status = %r\n", Status);
+  goto Done;
+}
+  } while (!NoFile);
 
   //
   // Sort FileInfoBuffer by alphabet order
@@ -866,7 +887,8 @@ DumpCapsuleFromDisk (
   }
 
   if (!DumpCapsuleInfo) {
-return EFI_SUCCESS;
+Status = EFI_SUCCESS;
+goto Done;
   }
 
   Print(L"The infomation of the capsules:\n");
@@ -875,19 +897,20 @@ DumpCapsuleFromDisk (
 FileHandle = NULL;
 Status = DirHandle->Open (DirHandle, , 
FileInfoBuffer[Index]->FileName, EFI_FILE_MODE_READ, 0);
 if (EFI_ERROR (Status)) {
-  break;
+  goto Done;
 }
 
 Status = FileHandleGetSize (FileHandle, (UINT64 *) );
 if (EFI_ERROR (Status)) {
   Print (L"Cannot read file %s. Status = %r\n", 
FileInfoBuffer[Index]->FileName, Status);
   FileHandleClose (FileHandle);
-  return Status;
+  goto Done;
 }
 
 FileBuffer = AllocatePool (FileSize);
 if (FileBuffer == NULL) {
-  return RETURN_OUT_OF_RESOURCES;
+  Status = EFI_OUT_OF_RESOURCES;
+  goto Done;
 }
 
 Status = FileHandleRead (FileHandle, , FileBuffer);
@@ -895,7 +918,7 @@ DumpCapsuleFromDisk (
   Print (L"Cannot read file %s. Status = %r\n", 
FileInfoBuffer[Index]->FileName, Status);
   FreePool (FileBuffer);
   FileHandleClose (FileHandle);
-  return Status;
+  goto Done;
 }
 
 Print (L"**\n");
@@ -906,7 +929,15 @@ DumpCapsuleFromDisk (
 FreePool (FileBuffer);
   }
 
-  return EFI_SUCCESS;
+Done:
+  if (FileInfoBuffer != NULL) {
+for

[edk2] [PATCH] MdeModulePkg/CapsuleApp: Fix potential NULL pointer dereference issue

2019-02-10 Thread Chen A Chen
To avoid potential NULL pointer dereference issue. Initialize them at
the beginning of the function. This patch is a supplement which was missed
at e98212cb5d59fff8f385d9179ad7f1a3ce9cf215 commit.

Cc: Jian J Wang 
Cc: Hao Wu 
Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c  | 23 +-
 .../Application/CapsuleApp/CapsuleOnDisk.c |  5 -
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c 
b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
index 33d2ecc582..cbbfda1424 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
@@ -1001,12 +1001,15 @@ DumpProvisionedCapsule (
   EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Fs;
   EFI_SHELL_PROTOCOL  *ShellProtocol;
 
-  ShellProtocol = GetShellProtocol ();
-
   Index = 0;
   CapsuleDataPtr64  = NULL;
   BootNext  = NULL;
-  ShellProtocol = NULL;
+
+  ShellProtocol = GetShellProtocol ();
+  if (ShellProtocol == NULL) {
+Print (L"Get Shell Protocol Fail\n");
+return ;
+  }
 
   //
   // Dump capsule provisioned on Memory
@@ -1033,16 +1036,16 @@ DumpProvisionedCapsule (
   (VOID **) ,
   NULL
   );
-if (EFI_ERROR (Status)) {
+if (EFI_ERROR (Status) || CapsuleDataPtr64 == NULL) {
   if (Index == 0) {
 Print (L"No data.\n");
   }
   break;
-} else {
-  Index++;
-  Print (L"Capsule Description at 0x%08x\n", *CapsuleDataPtr64);
-  DumpBlockDescriptors ((EFI_CAPSULE_BLOCK_DESCRIPTOR*) (UINTN) 
*CapsuleDataPtr64, DumpCapsuleInfo);
 }
+
+Index++;
+Print (L"Capsule Description at 0x%08x\n", *CapsuleDataPtr64);
+DumpBlockDescriptors ((EFI_CAPSULE_BLOCK_DESCRIPTOR*) (UINTN) 
*CapsuleDataPtr64, DumpCapsuleInfo);
   }
 
   //
@@ -1057,7 +1060,9 @@ DumpProvisionedCapsule (
  (VOID **) ,
  NULL
 );
-  if (!EFI_ERROR (Status)) {
+  if (EFI_ERROR (Status) || BootNext == NULL) {
+Print (L"Get BootNext Variable Fail. Status = %r\n", Status);
+  } else {
 UnicodeSPrint (BootOptionName, sizeof (BootOptionName), L"Boot%04x", 
*BootNext);
 Status = EfiBootManagerVariableToLoadOption (BootOptionName, 
);
 if (!EFI_ERROR (Status)) {
diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c 
b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
index 4faa863bca..f6e46cbdb1 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
@@ -445,7 +445,10 @@ GetUpdateFileSystem (
(VOID **),
NULL
);
-if (!EFI_ERROR (Status)) {
+if (EFI_ERROR (Status) || BootNextData == NULL) {
+  Print (L"Get Boot Next Data Fail. Status = %r\n", Status);
+  return EFI_NOT_FOUND;
+} else {
   UnicodeSPrint (BootOptionName, sizeof (BootOptionName), L"Boot%04x", 
*BootNextData);
   Status = EfiBootManagerVariableToLoadOption (BootOptionName, 
);
   if (!EFI_ERROR (Status)) {
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] FatPkg/FatPei/Gpt.c: Fix uninitialized variable issue

2019-01-31 Thread Chen A Chen
Uninitialized pointer variable may randomly point to a block of memory.
In This case, FreePool function will free a block of memory that is not
belongs to this function.

Cc: Ruiyu Ni 
Cc: Hao Wu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 FatPkg/FatPei/Gpt.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/FatPkg/FatPei/Gpt.c b/FatPkg/FatPei/Gpt.c
index c3afb668d7..bba33c5bfd 100644
--- a/FatPkg/FatPei/Gpt.c
+++ b/FatPkg/FatPei/Gpt.c
@@ -244,6 +244,9 @@ PartitionCheckGptEntryArray (
   UINTN   Index2;
   EFI_PARTITION_ENTRY *Entry;
 
+  PartitionEntryBuffer = NULL;
+  PartitionEntryStatus = NULL;
+
   ParentBlockDev  = &(PrivateData->BlockDevice[ParentBlockDevNo]);
   Found   = FALSE;
 
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] MdeModulePkg/CapsuleApp: Fix potential NULL pointer dereference issue

2019-01-31 Thread Chen A Chen
To avoid potential NULL pointer dereference issue. Initialize them at
the beginning of the function.

Cc: Jian J Wang 
Cc: Hao Wu 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.c|  5 +++--
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c   | 17 +++--
 MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c | 17 +++--
 3 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c 
b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
index 896acd3304..198a63555d 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
@@ -916,8 +916,9 @@ UefiMain (
   EFI_GUID  ImageTypeId;
   UINTN ImageIndex;
 
-  MapFsStr = NULL;
-  CapsuleNum = 0;
+  BlockDescriptors  = NULL;
+  MapFsStr  = NULL;
+  CapsuleNum= 0;
 
   Status = GetArg();
   if (EFI_ERROR(Status)) {
diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c 
b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
index 5bf617c5f6..7bef5a1378 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
@@ -795,11 +795,13 @@ DumpCapsuleFromDisk (
   UINTN FileCount;
   BOOLEAN   NoFile;
 
-  DirHandle  = NULL;
-  FileHandle = NULL;
-  Index  = 0;
-  FileCount  = 0;
-  NoFile = FALSE;
+  DirHandle   = NULL;
+  FileHandle  = NULL;
+  Index   = 0;
+  FileInfoBuffer  = NULL;
+  FileInfo= NULL;
+  FileCount   = 0;
+  NoFile  = FALSE;
 
   Status = Fs->OpenVolume (Fs, );
   if (EFI_ERROR (Status)) {
@@ -970,7 +972,10 @@ DumpProvisionedCapsule (
 
   ShellProtocol = GetShellProtocol ();
 
-  Index = 0;
+  Index = 0;
+  CapsuleDataPtr64  = NULL;
+  BootNext  = NULL;
+  ShellProtocol = NULL;
 
   //
   // Dump capsule provisioned on Memory
diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c 
b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
index 393b7ae7db..4faa863bca 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
@@ -151,9 +151,14 @@ DumpAllEfiSysPartition (
   UINTN  NumberEfiSystemPartitions;
   EFI_SHELL_PROTOCOL *ShellProtocol;
 
-  ShellProtocol = GetShellProtocol ();
   NumberEfiSystemPartitions = 0;
 
+  ShellProtocol = GetShellProtocol ();
+  if (ShellProtocol == NULL) {
+Print (L"Get Shell Protocol Fail\n");;
+return ;
+  }
+
   Print (L"EFI System Partition list:\n");
 
   gBS->LocateHandleBuffer (
@@ -421,7 +426,13 @@ GetUpdateFileSystem (
   EFI_BOOT_MANAGER_LOAD_OPTIONNewOption;
 
   MappedDevicePath = NULL;
+  BootOptionBuffer = NULL;
+
   ShellProtocol = GetShellProtocol ();
+  if (ShellProtocol == NULL) {
+Print (L"Get Shell Protocol Fail\n");;
+return EFI_NOT_FOUND;
+  }
 
   //
   // 1. If Fs is not assigned and there are capsule provisioned before,
@@ -468,7 +479,9 @@ GetUpdateFileSystem (
   // 2. Get EFI system partition form boot options.
   //
   BootOptionBuffer = EfiBootManagerGetLoadOptions (, 
LoadOptionTypeBoot);
-  if (BootOptionCount == 0 && Map == NULL) {
+  if ( (BootOptionBuffer == NULL) ||
+   (BootOptionCount == 0 && Map == NULL)
+ ) {
 return EFI_NOT_FOUND;
   }
 
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v4 1/4] MdePkg/UefiSpec.h: Add definition to support Capsule-on-Disk feature

2019-01-30 Thread Chen A Chen
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1482

UEFI Spec define this definition to support Capsule-on-Disk.

Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 MdePkg/Include/Uefi/UefiSpec.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/MdePkg/Include/Uefi/UefiSpec.h b/MdePkg/Include/Uefi/UefiSpec.h
index 75af99de50..8e7b96f09a 100644
--- a/MdePkg/Include/Uefi/UefiSpec.h
+++ b/MdePkg/Include/Uefi/UefiSpec.h
@@ -2201,6 +2201,11 @@ typedef struct {
   #error Unknown Processor Type
 #endif
 
+//
+// The directory within the active EFI System Partition defined for delivery 
of capsule to firmware
+//
+#define EFI_CAPSULE_FILE_DIRECTORYL"\\EFI\\UpdateCapsule\\"
+
 #include 
 #include 
 #include 
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v4 0/4] Introduce CapsuleApp patch v4

2019-01-30 Thread Chen A Chen
No functionality change.
Fix ECC and code style issue.
Already pass CR process.
https://git-amr-7.devtools.intel.com/gerrit/#/c/39023/

Chen A Chen (4):
  MdePkg/UefiSpec.h: Add definition to support Capsule-on-Disk feature
  MdeModulePkg/CapsuleApp: Add a function used to get next DevicePath
  MdeModulePkg/CapsuleApp: Add functions to support Capsule-on-Disk
  MdeModulePkg/CapsuleApp: Enhance CapsuleApp to support Capsule-on-Disk

 MdeModulePkg/Application/CapsuleApp/CapsuleApp.c   | 160 +++-
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.inf |   8 +
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c  | 538 +-
 .../Application/CapsuleApp/CapsuleOnDisk.c | 808 +
 MdeModulePkg/Include/Library/UefiBootManagerLib.h  |  21 +-
 MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c   |  24 +-
 MdeModulePkg/MdeModulePkg.dsc  |   1 +
 MdePkg/Include/Uefi/UefiSpec.h |   5 +
 8 files changed, 1546 insertions(+), 19 deletions(-)
 create mode 100644 MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c

-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v4 3/4] MdeModulePkg/CapsuleApp: Add functions to support Capsule-on-Disk

2019-01-30 Thread Chen A Chen
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1482

This file provide some basic function to support Capsule-on-Disk.

Cc: Jian J Wang 
Cc: Hao Wu 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
Reviewed-by: Jian J Wang 
---
 .../Application/CapsuleApp/CapsuleOnDisk.c | 808 +
 1 file changed, 808 insertions(+)
 create mode 100644 MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c 
b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
new file mode 100644
index 00..393b7ae7db
--- /dev/null
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
@@ -0,0 +1,808 @@
+/** @file
+  Process Capsule On Disk.
+
+  Copyright (c) 2019, Intel Corporation. All rights reserved.
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD 
License
+  which accompanies this distribution.  The full text of the license may be 
found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+EFI_GUID mCapsuleOnDiskBootOptionGuid = { 0x4CC29BB7, 0x2413, 0x40A2, { 0xB0, 
0x6D, 0x25, 0x3E, 0x37, 0x10, 0xF5, 0x32 } };
+
+/**
+  Get shell protocol.
+
+  @return Pointer to shell protocol.
+
+**/
+EFI_SHELL_PROTOCOL *
+GetShellProtocol (
+  VOID
+  );
+
+/**
+  Get file name from file path.
+
+  @param  FilePathFile path.
+
+  @return Pointer to file name.
+
+**/
+CHAR16 *
+GetFileNameFromPath (
+  CHAR16*FilePath
+  )
+{
+  EFI_STATUSStatus;
+  EFI_SHELL_PROTOCOL*ShellProtocol;
+  SHELL_FILE_HANDLE Handle;
+  EFI_FILE_INFO *FileInfo;
+
+  ShellProtocol = GetShellProtocol ();
+  if (ShellProtocol == NULL) {
+return NULL;
+  }
+
+  //
+  // Open file by FileName.
+  //
+  Status = ShellProtocol->OpenFileByName (
+FilePath,
+,
+EFI_FILE_MODE_READ
+);
+  if (EFI_ERROR (Status)) {
+return NULL;
+  }
+
+  //
+  // Get file name from EFI_FILE_INFO.
+  //
+  FileInfo = ShellProtocol->GetFileInfo (Handle);
+  ShellProtocol->CloseFile (Handle);
+  if (FileInfo == NULL) {
+return NULL;
+  }
+
+  return FileInfo->FileName;
+}
+
+/**
+  Check if the device path is EFI system Partition.
+
+  @param  DevicePathThe ESP device path.
+
+  @retval TRUEDevicePath is a device path for ESP.
+  @retval FALSE   DevicePath is not a device path for ESP.
+
+**/
+BOOLEAN
+IsEfiSysPartitionDevicePath (
+  EFI_DEVICE_PATH_PROTOCOL   *DevicePath
+  )
+{
+  EFI_STATUS Status;
+  EFI_DEVICE_PATH_PROTOCOL   *TempDevicePath;
+  HARDDRIVE_DEVICE_PATH  *Hd;
+  EFI_HANDLE Handle;
+
+  //
+  // Check if the device path contains GPT node
+  //
+  TempDevicePath = DevicePath;
+
+  while (!IsDevicePathEnd (TempDevicePath)) {
+if ((DevicePathType (TempDevicePath) == MEDIA_DEVICE_PATH) &&
+  (DevicePathSubType (TempDevicePath) == MEDIA_HARDDRIVE_DP)) {
+  Hd = (HARDDRIVE_DEVICE_PATH *)TempDevicePath;
+  if (Hd->MBRType == MBR_TYPE_EFI_PARTITION_TABLE_HEADER) {
+break;
+  }
+}
+TempDevicePath = NextDevicePathNode (TempDevicePath);
+  }
+
+  if (!IsDevicePathEnd (TempDevicePath)) {
+//
+// Search for EFI system partition protocol on full device path in Boot 
Option
+//
+Status = gBS->LocateDevicePath (, , 
);
+return EFI_ERROR (Status) ? FALSE : TRUE;
+  } else {
+return FALSE;
+  }
+}
+
+/**
+  Dump all EFI System Partition.
+
+**/
+VOID
+DumpAllEfiSysPartition (
+  VOID
+  )
+{
+  EFI_HANDLE *SimpleFileSystemHandles;
+  UINTN  NumberSimpleFileSystemHandles;
+  UINTN  Index;
+  EFI_DEVICE_PATH_PROTOCOL   *DevicePath;
+  UINTN  NumberEfiSystemPartitions;
+  EFI_SHELL_PROTOCOL *ShellProtocol;
+
+  ShellProtocol = GetShellProtocol ();
+  NumberEfiSystemPartitions = 0;
+
+  Print (L"EFI System Partition list:\n");
+
+  gBS->LocateHandleBuffer (
+ ByProtocol,
+ ,
+ NULL,
+ ,
+ 
+ );
+
+  for (Index = 0; Index < NumberSimpleFileSystemHandles; Index++) {
+DevicePath = DevicePathFromHandle (SimpleFileSystemHandles[Index]);
+if (IsEfiSysPartitionDevicePath (DevicePath)) {
+  NumberEfiSystemPartitions++;
+  Print(L"%s\n%s\n", ShellProtocol->GetMapFr

[edk2] [PATCH v4 2/4] MdeModulePkg/CapsuleApp: Add a function used to get next DevicePath

2019-01-30 Thread Chen A Chen
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1482

Add a new function to support Capsule-on-Disk feature.
This function is used to get next full DevicePath from a load option.

Cc: Jian J Wang 
Cc: Hao Wu 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
Reviewed-by: Jian J Wang 
---
 MdeModulePkg/Include/Library/UefiBootManagerLib.h | 21 +++-
 MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c  | 24 ++-
 2 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Include/Library/UefiBootManagerLib.h 
b/MdeModulePkg/Include/Library/UefiBootManagerLib.h
index bfc0cb86f8..64347ff160 100644
--- a/MdeModulePkg/Include/Library/UefiBootManagerLib.h
+++ b/MdeModulePkg/Include/Library/UefiBootManagerLib.h
@@ -1,7 +1,7 @@
 /** @file
   Provide Boot Manager related library APIs.
 
-Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2019, Intel Corporation. All rights reserved.
 (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
@@ -445,6 +445,25 @@ EfiBootManagerGetBootManagerMenu (
   EFI_BOOT_MANAGER_LOAD_OPTION *BootOption
   );
 
+/**
+  Get the next possible full path pointing to the load option.
+  The routine doesn't guarantee the returned full path points to an existing
+  file, and it also doesn't guarantee the existing file is a valid load option.
+  BmGetNextLoadOptionBuffer() guarantees.
+
+  @param FilePath  The device path pointing to a load option.
+   It could be a short-form device path.
+  @param FullPath  The full path returned by the routine in last call.
+   Set to NULL in first call.
+
+  @return The next possible full path pointing to the load option.
+  Caller is responsible to free the memory.
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EfiBootManagerGetNextFullDevicePath (
+  IN  EFI_DEVICE_PATH_PROTOCOL  *FilePath,
+  IN  EFI_DEVICE_PATH_PROTOCOL  *FullPath
+  );
 
 /**
   Get the load option by its device path.
diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c 
b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
index 6a23477eb8..684d7b8b1b 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
@@ -1,7 +1,7 @@
 /** @file
   Library functions which relates with booting.
 
-Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2019, Intel Corporation. All rights reserved.
 (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
@@ -2461,3 +2461,25 @@ EfiBootManagerGetBootManagerMenu (
   }
 }
 
+/**
+  Get the next possible full path pointing to the load option.
+  The routine doesn't guarantee the returned full path points to an existing
+  file, and it also doesn't guarantee the existing file is a valid load option.
+  BmGetNextLoadOptionBuffer() guarantees.
+
+  @param FilePath  The device path pointing to a load option.
+   It could be a short-form device path.
+  @param FullPath  The full path returned by the routine in last call.
+   Set to NULL in first call.
+
+  @return The next possible full path pointing to the load option.
+  Caller is responsible to free the memory.
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EfiBootManagerGetNextFullDevicePath (
+  IN  EFI_DEVICE_PATH_PROTOCOL  *FilePath,
+  IN  EFI_DEVICE_PATH_PROTOCOL  *FullPath
+  )
+{
+  return BmGetNextLoadOptionDevicePath(FilePath, FullPath);
+}
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v4 4/4] MdeModulePkg/CapsuleApp: Enhance CapsuleApp to support Capsule-on-Disk

2019-01-30 Thread Chen A Chen
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1482

CapsuleApp is used for trigger capsule update.
Add -OD option in CapsuleApp to support doing capsule update via storage.
Add -F and -L options to support dumping information feature.
Finish unit test for -F and -L options.
Already verify this feature on Denlow platform, success to update capsule
via hard disk with -OD option.

Cc: Jian J Wang 
Cc: Hao Wu 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
Reviewed-by: Jian J Wang 
---
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.c   | 160 +-
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.inf |   8 +
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c  | 538 -
 MdeModulePkg/MdeModulePkg.dsc  |   1 +
 4 files changed, 690 insertions(+), 17 deletions(-)

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c 
b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
index 4d907242f3..896acd3304 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
@@ -1,7 +1,7 @@
 /** @file
   A shell application that triggers capsule update process.
 
-  Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
+  Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -105,6 +106,46 @@ DumpEsrtData (
   VOID
   );
 
+/**
+  Dump Provisioned Capsule.
+
+  @param[in]  DumpCapsuleInfo  The flag to indicate whether to dump the 
capsule inforomation.
+**/
+VOID
+DumpProvisionedCapsule (
+  IN BOOLEAN  DumpCapsuleInfo
+  );
+
+/**
+  Dump all EFI System Partition.
+**/
+VOID
+DumpAllEfiSysPartition (
+  VOID
+  );
+
+/**
+  Process Capsule On Disk.
+
+  @param[in]  CapsuleBuffer   An array of pointer to capsule images
+  @param[in]  CapsuleBufferSize   An array of UINTN to capsule images size
+  @param[in]  FilePathAn array of capsule images file path
+  @param[in]  Map File system mapping string
+  @param[in]  CapsuleNum  The count of capsule images
+
+  @retval EFI_SUCCESS   Capsule on disk success.
+  @retval othersCapsule on disk fail.
+
+**/
+EFI_STATUS
+ProcessCapsuleOnDisk (
+  IN VOID  **CapsuleBuffer,
+  IN UINTN *CapsuleBufferSize,
+  IN CHAR16**FilePath,
+  IN CHAR16*Map,
+  IN UINTN CapsuleNum
+  );
+
 /**
   Read a file.
 
@@ -799,19 +840,22 @@ PrintUsage (
   )
 {
   Print(L"CapsuleApp:  usage\n");
-  Print(L"  CapsuleApp  [-NR]\n");
+  Print(L"  CapsuleApp  [-NR] [-OD [FSx]]\n");
   Print(L"  CapsuleApp -S\n");
   Print(L"  CapsuleApp -C\n");
   Print(L"  CapsuleApp -P\n");
   Print(L"  CapsuleApp -E\n");
+  Print(L"  CapsuleApp -L\n");
+  Print(L"  CapsuleApp -L INFO\n");
+  Print(L"  CapsuleApp -F\n");
   Print(L"  CapsuleApp -G  -O \n");
   Print(L"  CapsuleApp -N  -O \n");
   Print(L"  CapsuleApp -D \n");
   Print(L"  CapsuleApp -P GET   -O \n");
   Print(L"Parameter:\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"  -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"  -OD: Delivery of Capsules via file on Mass Storage device.");
   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");
@@ -820,6 +864,8 @@ PrintUsage (
   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"  -L:  Dump provisioned capsule image information.\n");
+  Print(L"  -F:  Dump all EFI System Partition.\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 FMP capsule image\n");
@@ -851,7 +897,7 @@ UefiMain (
 {
   EFI_S

[edk2] [PATCH v3 4/4] MdeModulePkg/CapsuleApp: Enhance CapsuleApp to support Capsule-on-Disk

2019-01-28 Thread Chen A Chen
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1482

CapsuleApp is used for trigger capsule update.
Add -OD option in CapsuleApp to support doing capsule update via storage.
Add -F and -L options to support dumping information feature.
Finish unit test for -F and -L options.
Already verify this feature on Denlow platform, success to update capsule
via hard disk with -OD option.

Cc: Jian J Wang 
Cc: Hao Wu 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.c   | 155 +-
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.inf |   8 +
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c  | 538 -
 3 files changed, 684 insertions(+), 17 deletions(-)

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c 
b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
index 4d907242f3..258e6995bc 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
@@ -1,7 +1,7 @@
 /** @file
   A shell application that triggers capsule update process.
 
-  Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
+  Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -105,6 +106,44 @@ DumpEsrtData (
   VOID
   );
 
+/**
+  Dump Provisioned Capsule.
+
+  @param[in]  DumpCapsuleInfo  The flag to indicate whether to dump the 
capsule inforomation.
+**/
+VOID
+DumpProvisionedCapsule (
+  IN BOOLEAN  DumpCapsuleInfo
+  );
+
+/**
+  Dump all EFI System Partition.
+**/
+VOID
+DumpAllEfiSysPartition (
+  VOID
+  );
+
+/**
+  Process Capsule On Disk.
+
+  @param[in]  CapsuleBufferAn array of pointer to capsule images
+  @param[in]  FileSize An array of UINTN to capsule images size
+  @param[in]  OrgFileName  An array of orginal capsule images name
+  @param[in]  NewFileName  An array of new capsule images name
+  @param[in]  CapsuleNum   The count of capsule images
+
+  @retval EFI_SUCCESS   Capsule on disk success.
+**/
+EFI_STATUS
+ProcessCapsuleOnDisk (
+  IN VOID  **CapsuleBuffer,
+  IN UINTN *CapsuleBufferSize,
+  IN CHAR16**FilePath,
+  IN CHAR16*Map,
+  IN UINTN CapsuleNum
+  );
+
 /**
   Read a file.
 
@@ -799,19 +838,22 @@ PrintUsage (
   )
 {
   Print(L"CapsuleApp:  usage\n");
-  Print(L"  CapsuleApp  [-NR]\n");
+  Print(L"  CapsuleApp  [-NR] [-OD [FSx]]\n");
   Print(L"  CapsuleApp -S\n");
   Print(L"  CapsuleApp -C\n");
   Print(L"  CapsuleApp -P\n");
   Print(L"  CapsuleApp -E\n");
+  Print(L"  CapsuleApp -L\n");
+  Print(L"  CapsuleApp -L INFO\n");
+  Print(L"  CapsuleApp -F\n");
   Print(L"  CapsuleApp -G  -O \n");
   Print(L"  CapsuleApp -N  -O \n");
   Print(L"  CapsuleApp -D \n");
   Print(L"  CapsuleApp -P GET   -O \n");
   Print(L"Parameter:\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"  -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"  -OD: Delivery of Capsules via file on Mass Storage device.");
   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");
@@ -820,6 +862,8 @@ PrintUsage (
   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"  -L:  Dump provisioned capsule image information.\n");
+  Print(L"  -F:  Dump all EFI System Partition.\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 FMP capsule image\n");
@@ -851,7 +895,7 @@ UefiMain (
 {
   EFI_STATUSStatus;
   RETURN_STATUS RStatus;
-  UINTN FileSize[MAX_CAPSULE_NUM];
+  UINTN

[edk2] [PATCH v3 0/4] Introduce CapsuleApp patch v3

2019-01-28 Thread Chen A Chen
Fix Typo and code style issue, no any function change.
According to package owner's input, Split this patch to smaller granularity.

Chen A Chen (4):
  MdePkg/UefiSpec.h: Add definition to support Capsule-on-Disk feature
  MdeModulePkg/CapsuleApp: Add a function used to get next DevicePath
  MdeModulePkg/CapsuleApp: Add functions to support Capsule-on-Disk
  MdeModulePkg/CapsuleApp: Enhance CapsuleApp to support Capsule-on-Disk

 MdeModulePkg/Application/CapsuleApp/CapsuleApp.c   | 155 +++-
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.inf |   8 +
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c  | 538 +-
 .../Application/CapsuleApp/CapsuleOnDisk.c | 806 +
 MdeModulePkg/Include/Library/UefiBootManagerLib.h  |  21 +-
 MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c   |  24 +-
 MdePkg/Include/Uefi/UefiSpec.h |   5 +
 7 files changed, 1538 insertions(+), 19 deletions(-)
 create mode 100644 MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c

-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v3 3/4] MdeModulePkg/CapsuleApp: Add functions to support Capsule-on-Disk

2019-01-28 Thread Chen A Chen
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1482

This file provide some basic function to support Capsule-on-Disk.

Cc: Jian J Wang 
Cc: Hao Wu 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 .../Application/CapsuleApp/CapsuleOnDisk.c | 806 +
 1 file changed, 806 insertions(+)
 create mode 100644 MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c 
b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
new file mode 100644
index 00..16ce9519b2
--- /dev/null
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
@@ -0,0 +1,806 @@
+/** @file
+  Process Capsule On Disk.
+
+  Copyright (c) 2019, Intel Corporation. All rights reserved.
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD 
License
+  which accompanies this distribution.  The full text of the license may be 
found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+EFI_GUID mCapsuleOnDiskBootOptionGuid = { 0x4CC29BB7, 0x2413, 0x40A2, { 0xB0, 
0x6D, 0x25, 0x3E, 0x37, 0x10, 0xF5, 0x32 } };
+
+/**
+  Get shell protocol.
+
+  @return Pointer to shell protocol.
+
+**/
+EFI_SHELL_PROTOCOL *
+GetShellProtocol (
+  VOID
+  );
+
+/**
+  Get file name from file path.
+
+  @param  FilePathFile path.
+
+  @return Pointer to file name.
+
+**/
+CHAR16 *
+GetFileNameFromPath (
+  CHAR16*FilePath
+  )
+{
+  EFI_STATUSStatus;
+  EFI_SHELL_PROTOCOL*ShellProtocol;
+  SHELL_FILE_HANDLE Handle;
+  EFI_FILE_INFO *FileInfo;
+
+  ShellProtocol = GetShellProtocol ();
+  if (ShellProtocol == NULL) {
+return NULL;
+  }
+
+  //
+  // Open file by FileName.
+  //
+  Status = ShellProtocol->OpenFileByName (
+FilePath,
+,
+EFI_FILE_MODE_READ
+);
+  if (EFI_ERROR (Status)) {
+return NULL;
+  }
+
+  //
+  // Get file name from EFI_FILE_INFO.
+  //
+  FileInfo = ShellProtocol->GetFileInfo (Handle);
+  ShellProtocol->CloseFile (Handle);
+  if (FileInfo == NULL) {
+return NULL;
+  }
+
+  return FileInfo->FileName;
+}
+
+/**
+  Check if the device path is EFI system Partition.
+
+  @param  DevicePathThe ESP device path.
+
+  @retval TRUEDevicePath is a device path for ESP.
+  @retval FALSE   DevicePath is not a device path for ESP.
+
+**/
+BOOLEAN
+IsEfiSysPartitionDevicePath (
+  EFI_DEVICE_PATH_PROTOCOL   *DevicePath
+  )
+{
+  EFI_STATUS Status;
+  EFI_DEVICE_PATH_PROTOCOL   *TempDevicePath;
+  HARDDRIVE_DEVICE_PATH  *Hd;
+  EFI_HANDLE Handle;
+
+  //
+  // Check if the device path contains GPT node
+  //
+  TempDevicePath = DevicePath;
+
+  while (!IsDevicePathEnd (TempDevicePath)) {
+if ((DevicePathType (TempDevicePath) == MEDIA_DEVICE_PATH) &&
+  (DevicePathSubType (TempDevicePath) == MEDIA_HARDDRIVE_DP)) {
+  Hd = (HARDDRIVE_DEVICE_PATH *)TempDevicePath;
+  if (Hd->MBRType == MBR_TYPE_EFI_PARTITION_TABLE_HEADER) {
+break;
+  }
+}
+TempDevicePath = NextDevicePathNode (TempDevicePath);
+  }
+
+  if (!IsDevicePathEnd (TempDevicePath)) {
+//
+// Search for EFI system partition protocol on full device path in Boot 
Option
+//
+Status = gBS->LocateDevicePath (, , 
);
+return EFI_ERROR (Status) ? FALSE : TRUE;
+  } else {
+return FALSE;
+  }
+}
+
+/**
+  Dump all EFI System Partition.
+
+**/
+VOID
+DumpAllEfiSysPartition (
+  VOID
+  )
+{
+  EFI_HANDLE *SimpleFileSystemHandles;
+  UINTN  NumberSimpleFileSystemHandles;
+  UINTN  Index;
+  EFI_DEVICE_PATH_PROTOCOL   *DevicePath;
+  UINTN  NumberEfiSystemPartitions;
+  EFI_SHELL_PROTOCOL *ShellProtocol;
+
+  ShellProtocol = GetShellProtocol ();
+  NumberEfiSystemPartitions = 0;
+
+  Print (L"EFI System Partition list:\n");
+
+  gBS->LocateHandleBuffer (
+ ByProtocol,
+ ,
+ NULL,
+ ,
+ 
+ );
+
+  for (Index = 0; Index < NumberSimpleFileSystemHandles; Index++) {
+DevicePath = DevicePathFromHandle (SimpleFileSystemHandles[Index]);
+if (IsEfiSysPartitionDevicePath (DevicePath)) {
+  NumberEfiSystemPartitions++;
+  Print(L"%s\n%s\n", ShellProtocol->GetMapFr

[edk2] [PATCH v3 1/4] MdePkg/UefiSpec.h: Add definition to support Capsule-on-Disk feature

2019-01-28 Thread Chen A Chen
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1482

UEFI Spec define this definition to support Capsule-on-Disk.

Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 MdePkg/Include/Uefi/UefiSpec.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/MdePkg/Include/Uefi/UefiSpec.h b/MdePkg/Include/Uefi/UefiSpec.h
index 75af99de50..9d3d7a9a63 100644
--- a/MdePkg/Include/Uefi/UefiSpec.h
+++ b/MdePkg/Include/Uefi/UefiSpec.h
@@ -2201,6 +2201,11 @@ typedef struct {
   #error Unknown Processor Type
 #endif
 
+//
+// The directory within the active EFI System Partition defined for delivery 
of capsule to firmware
+//
+#define EFI_CAPSULE_FROM_FILE_DIRL"\\EFI\\UpdateCapsule\\"
+
 #include 
 #include 
 #include 
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v3 2/4] MdeModulePkg/CapsuleApp: Add a function used to get next DevicePath

2019-01-28 Thread Chen A Chen
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1482

Add a new function to support Capsule-on-Disk feature.
This function is used to get next full DevicePath from a load option.

Cc: Jian J Wang 
Cc: Hao Wu 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 MdeModulePkg/Include/Library/UefiBootManagerLib.h | 21 +++-
 MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c  | 24 ++-
 2 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Include/Library/UefiBootManagerLib.h 
b/MdeModulePkg/Include/Library/UefiBootManagerLib.h
index bfc0cb86f8..64347ff160 100644
--- a/MdeModulePkg/Include/Library/UefiBootManagerLib.h
+++ b/MdeModulePkg/Include/Library/UefiBootManagerLib.h
@@ -1,7 +1,7 @@
 /** @file
   Provide Boot Manager related library APIs.
 
-Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2019, Intel Corporation. All rights reserved.
 (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
@@ -445,6 +445,25 @@ EfiBootManagerGetBootManagerMenu (
   EFI_BOOT_MANAGER_LOAD_OPTION *BootOption
   );
 
+/**
+  Get the next possible full path pointing to the load option.
+  The routine doesn't guarantee the returned full path points to an existing
+  file, and it also doesn't guarantee the existing file is a valid load option.
+  BmGetNextLoadOptionBuffer() guarantees.
+
+  @param FilePath  The device path pointing to a load option.
+   It could be a short-form device path.
+  @param FullPath  The full path returned by the routine in last call.
+   Set to NULL in first call.
+
+  @return The next possible full path pointing to the load option.
+  Caller is responsible to free the memory.
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EfiBootManagerGetNextFullDevicePath (
+  IN  EFI_DEVICE_PATH_PROTOCOL  *FilePath,
+  IN  EFI_DEVICE_PATH_PROTOCOL  *FullPath
+  );
 
 /**
   Get the load option by its device path.
diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c 
b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
index 6a23477eb8..684d7b8b1b 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
@@ -1,7 +1,7 @@
 /** @file
   Library functions which relates with booting.
 
-Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2019, Intel Corporation. All rights reserved.
 (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
@@ -2461,3 +2461,25 @@ EfiBootManagerGetBootManagerMenu (
   }
 }
 
+/**
+  Get the next possible full path pointing to the load option.
+  The routine doesn't guarantee the returned full path points to an existing
+  file, and it also doesn't guarantee the existing file is a valid load option.
+  BmGetNextLoadOptionBuffer() guarantees.
+
+  @param FilePath  The device path pointing to a load option.
+   It could be a short-form device path.
+  @param FullPath  The full path returned by the routine in last call.
+   Set to NULL in first call.
+
+  @return The next possible full path pointing to the load option.
+  Caller is responsible to free the memory.
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EfiBootManagerGetNextFullDevicePath (
+  IN  EFI_DEVICE_PATH_PROTOCOL  *FilePath,
+  IN  EFI_DEVICE_PATH_PROTOCOL  *FullPath
+  )
+{
+  return BmGetNextLoadOptionDevicePath(FilePath, FullPath);
+}
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v3 3/3] FatPkg: Add GPT check in FatPei to support Capsule-on-Disk feature.

2019-01-28 Thread Chen A Chen
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1470
This feature is used for finding GPT partition.
Follow the following step to check.
1) Check Protective MBR.
2) Check GPT primary/backup header.
3) Check GPT primary/backup entry array.

Cc: Ruiyu Ni 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
Reviewed-by: Hao Wu 
---
 FatPkg/FatPei/FatLitePeim.h |   3 +-
 FatPkg/FatPei/FatPei.inf|   3 +
 FatPkg/FatPei/Gpt.c | 548 
 FatPkg/FatPei/Part.c|  36 ++-
 4 files changed, 585 insertions(+), 5 deletions(-)
 create mode 100644 FatPkg/FatPei/Gpt.c

diff --git a/FatPkg/FatPei/FatLitePeim.h b/FatPkg/FatPei/FatLitePeim.h
index fbf887da5f..82ab045f2a 100644
--- a/FatPkg/FatPei/FatLitePeim.h
+++ b/FatPkg/FatPei/FatLitePeim.h
@@ -1,7 +1,7 @@
 /** @file
   Data structures for FAT recovery PEIM
 
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
 
 This program and the accompanying materials are licensed and made available
 under the terms and conditions of the BSD License which accompanies this
@@ -27,6 +27,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/FatPkg/FatPei/FatPei.inf b/FatPkg/FatPei/FatPei.inf
index 57312a9047..050bc4e157 100644
--- a/FatPkg/FatPei/FatPei.inf
+++ b/FatPkg/FatPei/FatPei.inf
@@ -31,6 +31,7 @@
 
 [Sources]
   Mbr.c
+  Gpt.c
   Eltorito.c
   Part.c
   FatLiteApi.c
@@ -49,6 +50,7 @@
 [LibraryClasses]
   PcdLib
   BaseMemoryLib
+  MemoryAllocationLib
   PeimEntryPoint
   BaseLib
   DebugLib
@@ -61,6 +63,7 @@
   gRecoveryOnFatIdeDiskGuid   ## SOMETIMES_CONSUMES   ## 
UNDEFINED
   gRecoveryOnFatFloppyDiskGuid## SOMETIMES_CONSUMES   ## 
UNDEFINED
   gRecoveryOnFatNvmeDiskGuid  ## SOMETIMES_CONSUMES   ## 
UNDEFINED
+  gEfiPartTypeUnusedGuid  ## SOMETIMES_CONSUMES   ## 
UNDEFINED
 
 
 [Ppis]
diff --git a/FatPkg/FatPei/Gpt.c b/FatPkg/FatPei/Gpt.c
new file mode 100644
index 00..c3afb668d7
--- /dev/null
+++ b/FatPkg/FatPei/Gpt.c
@@ -0,0 +1,548 @@
+/** @file
+  Routines supporting partition discovery and
+  logical device reading
+
+Copyright (c) 2019 Intel Corporation. All rights reserved.
+
+This program and the accompanying materials are licensed and made available
+under the terms and conditions of the BSD License which accompanies this
+distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include 
+#include 
+#include 
+#include "FatLitePeim.h"
+
+//
+// Assumption: 'a' and 'blocksize' are all UINT32 or UINT64.
+// If 'a' and 'blocksize' are not the same type, should use DivU64xU32 to 
calculate.
+//
+#define EFI_SIZE_TO_BLOCKS(a, blocksize)  (((a) / (blocksize)) + (((a) % 
(blocksize)) ? 1 : 0))
+
+//
+// GPT Partition Entry Status
+//
+typedef struct {
+  BOOLEAN OutOfRange;
+  BOOLEAN Overlap;
+  BOOLEAN OsSpecific;
+} EFI_PARTITION_ENTRY_STATUS;
+
+/**
+  Check if the CRC field in the Partition table header is valid.
+
+  @param[in]  PartHeader  Partition table header structure
+
+  @retval TRUE  the CRC is valid
+  @retval FALSE the CRC is invalid
+
+**/
+BOOLEAN
+PartitionCheckGptHeaderCRC (
+  IN  EFI_PARTITION_TABLE_HEADER  *PartHeader
+  )
+{
+  UINT32  GptHdrCrc;
+  UINT32  Crc;
+
+  GptHdrCrc = PartHeader->Header.CRC32;
+
+  //
+  // Set CRC field to zero when doing calcuation
+  //
+  PartHeader->Header.CRC32 = 0;
+
+  Crc = CalculateCrc32 (PartHeader, PartHeader->Header.HeaderSize);
+
+  //
+  // Restore Header CRC
+  //
+  PartHeader->Header.CRC32 = GptHdrCrc;
+
+  return (GptHdrCrc == Crc);
+}
+
+
+/**
+  Check if the CRC field in the Partition table header is valid
+  for Partition entry array.
+
+  @param[in]  PartHeader  Partition table header structure
+  @param[in]  PartEntry   The partition entry array
+
+  @retval TRUE  the CRC is valid
+  @retval FALSE the CRC is invalid
+
+**/
+BOOLEAN
+PartitionCheckGptEntryArrayCRC (
+  IN  EFI_PARTITION_TABLE_HEADER *PartHeader,
+  IN  EFI_PARTITION_ENTRY*PartEntry
+  )
+{
+  UINT32  Crc;
+  UINTN   Size;
+
+  Size = (UINTN)MultU64x32(PartHeader->NumberOfPartitionEntries, 
PartHeader->SizeOfPartitionEntry);
+  Crc  = CalculateCrc32 (PartEntry, Size);
+
+  return (BOOLEAN) (PartHeader->PartitionEntryArrayCRC32 == Crc);
+}
+
+/**
+  The function is used for valid GPT table. Both for Primary and Backup GPT 
header.
+
+  @param[in]  PrivateData   The global memory map
+  @param[in]  ParentBlockDevNo  The parent block device
+  @param[in]  I

[edk2] [PATCH v2 0/3] FatPkg/GPT: Introduce GPT patch v3

2019-01-28 Thread Chen A Chen
No function change, fix code style issue.

Chen A Chen (3):
  FatPkg: Break down Part.c file.
  MdePkg/UefiGpt.h: Add new definition for enable GPT support
  FatPkg: Add GPT check in FatPei to support Capsule-on-Disk feature.

 FatPkg/FatPei/Eltorito.c  | 239 ++
 FatPkg/FatPei/FatLitePeim.h   |   3 +-
 FatPkg/FatPei/FatPei.inf  |   7 +-
 FatPkg/FatPei/Gpt.c   | 548 ++
 FatPkg/FatPei/Mbr.c   | 181 ++
 FatPkg/FatPei/Part.c  | 434 +++--
 MdePkg/Include/Uefi/UefiGpt.h |   6 +-
 7 files changed, 1020 insertions(+), 398 deletions(-)
 create mode 100644 FatPkg/FatPei/Eltorito.c
 create mode 100644 FatPkg/FatPei/Gpt.c
 create mode 100644 FatPkg/FatPei/Mbr.c

-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v3 2/3] MdePkg/UefiGpt.h: Add new definition for enable GPT support

2019-01-28 Thread Chen A Chen
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1470

This definition comes from UEFI Spec to support GPT in FatPei driver.

Cc: Liming Gao 
Cc: Michael D Kinney 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
Reviewed-by: Liming Gao 
---
 MdePkg/Include/Uefi/UefiGpt.h | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/MdePkg/Include/Uefi/UefiGpt.h b/MdePkg/Include/Uefi/UefiGpt.h
index f635b05390..e4e919beaf 100644
--- a/MdePkg/Include/Uefi/UefiGpt.h
+++ b/MdePkg/Include/Uefi/UefiGpt.h
@@ -1,7 +1,7 @@
 /** @file
   EFI Guid Partition Table Format Definition.
 
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
 This program and the accompanying materials are licensed and made available 
under
 the terms and conditions of the BSD License that accompanies this distribution.
 The full text of the license may be found at
@@ -24,6 +24,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 /// EFI Partition Table Signature: "EFI PART".
 ///
 #define EFI_PTAB_HEADER_ID  SIGNATURE_64 ('E','F','I',' ','P','A','R','T')
+///
+/// Minimum bytes reserve for EFI entry array buffer.
+///
+#define EFI_GPT_PART_ENTRY_MIN_SIZE 16384
 
 #pragma pack(1)
 
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v3 1/3] FatPkg: Break down Part.c file.

2019-01-28 Thread Chen A Chen
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1470
Break down partition parsing logic to 2 parts, Eltorito and MBR.

Cc: Ruiyu Ni 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
Reviewed-by: Hao Wu 
---
 FatPkg/FatPei/Eltorito.c | 239 
 FatPkg/FatPei/FatPei.inf |   4 +-
 FatPkg/FatPei/Mbr.c  | 181 +
 FatPkg/FatPei/Part.c | 402 ++-
 4 files changed, 432 insertions(+), 394 deletions(-)
 create mode 100644 FatPkg/FatPei/Eltorito.c
 create mode 100644 FatPkg/FatPei/Mbr.c

diff --git a/FatPkg/FatPei/Eltorito.c b/FatPkg/FatPei/Eltorito.c
new file mode 100644
index 00..a350237bd3
--- /dev/null
+++ b/FatPkg/FatPei/Eltorito.c
@@ -0,0 +1,239 @@
+/** @file
+  Routines supporting partition discovery and
+  logical device reading
+
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+
+This program and the accompanying materials are licensed and made available
+under the terms and conditions of the BSD License which accompanies this
+distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include 
+#include "FatLitePeim.h"
+
+/**
+  This function finds Eltorito partitions. Main algorithm
+  is ported from DXE partition driver.
+
+  @param[in]  PrivateData   The global memory map
+  @param[in]  ParentBlockDevNo  The parent block device
+
+  @retval TRUE  New partitions are detected and logical block 
devices
+are added to block device array
+  @retval FALSE No new partitions are added
+
+**/
+BOOLEAN
+FatFindEltoritoPartitions (
+  IN  PEI_FAT_PRIVATE_DATA *PrivateData,
+  IN  UINTNParentBlockDevNo
+  )
+{
+  EFI_STATUS  Status;
+  BOOLEAN Found;
+  PEI_FAT_BLOCK_DEVICE*BlockDev;
+  PEI_FAT_BLOCK_DEVICE*ParentBlockDev;
+  UINT32  VolDescriptorLba;
+  UINT32  Lba;
+  CDROM_VOLUME_DESCRIPTOR *VolDescriptor;
+  ELTORITO_CATALOG*Catalog;
+  UINTN   Check;
+  UINTN   Index;
+  UINTN   MaxIndex;
+  UINT16  *CheckBuffer;
+  UINT32  SubBlockSize;
+  UINT32  SectorCount;
+  UINT32  VolSpaceSize;
+
+  if (ParentBlockDevNo > PEI_FAT_MAX_BLOCK_DEVICE - 1) {
+return FALSE;
+  }
+
+  Found   = FALSE;
+  ParentBlockDev  = &(PrivateData->BlockDevice[ParentBlockDevNo]);
+  VolSpaceSize= 0;
+
+  //
+  // CD_ROM has the fixed block size as 2048 bytes
+  //
+  if (ParentBlockDev->BlockSize != 2048) {
+return FALSE;
+  }
+
+  VolDescriptor = (CDROM_VOLUME_DESCRIPTOR *) PrivateData->BlockData;
+  Catalog   = (ELTORITO_CATALOG *) VolDescriptor;
+
+  //
+  // the ISO-9660 volume descriptor starts at 32k on the media
+  // and CD_ROM has the fixed block size as 2048 bytes, so...
+  //
+  VolDescriptorLba = 15;
+  //
+  // ((16*2048) / Media->BlockSize) - 1;
+  //
+  // Loop: handle one volume descriptor per time
+  //
+  while (TRUE) {
+
+VolDescriptorLba += 1;
+if (VolDescriptorLba > ParentBlockDev->LastBlock) {
+  //
+  // We are pointing past the end of the device so exit
+  //
+  break;
+}
+
+Status = FatReadBlock (
+  PrivateData,
+  ParentBlockDevNo,
+  VolDescriptorLba,
+  ParentBlockDev->BlockSize,
+  VolDescriptor
+  );
+if (EFI_ERROR (Status)) {
+  break;
+}
+//
+// Check for valid volume descriptor signature
+//
+if (VolDescriptor->Unknown.Type == CDVOL_TYPE_END ||
+CompareMem (VolDescriptor->Unknown.Id, CDVOL_ID, sizeof 
(VolDescriptor->Unknown.Id)) != 0
+) {
+  //
+  // end of Volume descriptor list
+  //
+  break;
+}
+//
+// Read the Volume Space Size from Primary Volume Descriptor 81-88 byte
+//
+if (VolDescriptor->Unknown.Type == CDVOL_TYPE_CODED) {
+  VolSpaceSize = VolDescriptor->PrimaryVolume.VolSpaceSize[1];
+}
+//
+// Is it an El Torito volume descriptor?
+//
+if (CompareMem (
+  VolDescriptor->BootRecordVolume.SystemId,
+  CDVOL_ELTORITO_ID,
+  sizeof (CDVOL_ELTORITO_ID) - 1
+  ) != 0) {
+  continue;
+}
+//
+// Read in the boot El Torito boot catalog
+//
+Lba = UNPACK_INT32 (VolDescriptor->BootRecordVolume.EltCatalog);
+if (Lba > ParentBlockDev->LastBlock) {
+  continue;
+}
+
+Status = FatReadBlock (
+  PrivateData,
+  ParentBlockDevNo,
+

[edk2] [PATCH v2 0/2] CapsuleApp: Introduce Patch v2

2019-01-27 Thread Chen A Chen
Follow Gao,Liming and Yao,jiewen's comments, the MdeModulePkg should not
depends on ShellPkg. Remove the first patch of v1 that was used to refine
code with ShelLib, so the v2 has only 2 patch file.

Chen A Chen (2):
  MdePkg/UefiSpec.h: Add definition to support Capsule-on-Disk feature.
  MdeModulePkg/CapsuleApp: Enhance CapsuleApp to support
Capsule-on-Disk.

 MdeModulePkg/Application/CapsuleApp/CapsuleApp.c   | 153 +++-
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.inf |   8 +
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c  | 535 +-
 .../Application/CapsuleApp/CapsuleOnDisk.c | 802 +
 MdeModulePkg/Include/Library/UefiBootManagerLib.h  |  19 +
 MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c   |  22 +
 MdePkg/Include/Uefi/UefiSpec.h |   5 +
 7 files changed, 1529 insertions(+), 15 deletions(-)
 create mode 100644 MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c

-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v2 0/3] FatPkg/GPT: Introduce GPT patch v2

2019-01-27 Thread Chen A Chen
*)  For first patch, fix spelling error issue.
*)  For sencond pathc, add EFI_ prefix for GPT_PART_ENTRY_MIN_SIZE definition,
Remove duplicated structure definition.
*)  Fix spelling error issue.
Add calling FatFindGptPartitions logic in FatPei driver.

Chen A Chen (3):
  FatPkg: Break down Part.c file.
  MdePkg/UefiGpt.h: Add new definition for enable GPT support
  FatPkg: Add GPT check in FatPei to support Capsule-on-Disk feature.

 FatPkg/FatPei/Eltorito.c  | 239 ++
 FatPkg/FatPei/FatLitePeim.h   |   1 +
 FatPkg/FatPei/FatPei.inf  |   5 +
 FatPkg/FatPei/Gpt.c   | 552 ++
 FatPkg/FatPei/Mbr.c   | 182 ++
 FatPkg/FatPei/Part.c  | 401 ++
 MdePkg/Include/Uefi/UefiGpt.h |   4 +
 7 files changed, 997 insertions(+), 387 deletions(-)
 create mode 100644 FatPkg/FatPei/Eltorito.c
 create mode 100644 FatPkg/FatPei/Gpt.c
 create mode 100644 FatPkg/FatPei/Mbr.c

-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v2 1/3] FatPkg: Break down Part.c file.

2019-01-27 Thread Chen A Chen
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1470
Break down partition parsing logic to 2 parts, Eltorito and MBR.

Cc: Ruiyu Ni 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 FatPkg/FatPei/Eltorito.c | 239 +
 FatPkg/FatPei/FatPei.inf |   4 +-
 FatPkg/FatPei/Mbr.c  | 182 ++
 FatPkg/FatPei/Part.c | 385 +--
 4 files changed, 425 insertions(+), 385 deletions(-)
 create mode 100644 FatPkg/FatPei/Eltorito.c
 create mode 100644 FatPkg/FatPei/Mbr.c

diff --git a/FatPkg/FatPei/Eltorito.c b/FatPkg/FatPei/Eltorito.c
new file mode 100644
index 00..ffaef51860
--- /dev/null
+++ b/FatPkg/FatPei/Eltorito.c
@@ -0,0 +1,239 @@
+/** @file
+  Routines supporting partition discovery and
+  logical device reading
+
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+
+This program and the accompanying materials are licensed and made available
+under the terms and conditions of the BSD License which accompanies this
+distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include 
+#include "FatLitePeim.h"
+
+/**
+  This function finds Eltorito partitions. Main algorithm
+  is ported from DXE partition driver.
+
+  @param  PrivateData   The global memory map
+  @param  ParentBlockDevNo  The parent block device
+
+  @retval TRUE  New partitions are detected and logical block 
devices
+are  added to block device array
+  @retval FALSE No New partitions are added;
+
+**/
+BOOLEAN
+FatFindEltoritoPartitions (
+  IN  PEI_FAT_PRIVATE_DATA *PrivateData,
+  IN  UINTNParentBlockDevNo
+  )
+{
+  EFI_STATUS  Status;
+  BOOLEAN Found;
+  PEI_FAT_BLOCK_DEVICE*BlockDev;
+  PEI_FAT_BLOCK_DEVICE*ParentBlockDev;
+  UINT32  VolDescriptorLba;
+  UINT32  Lba;
+  CDROM_VOLUME_DESCRIPTOR *VolDescriptor;
+  ELTORITO_CATALOG*Catalog;
+  UINTN   Check;
+  UINTN   Index;
+  UINTN   MaxIndex;
+  UINT16  *CheckBuffer;
+  UINT32  SubBlockSize;
+  UINT32  SectorCount;
+  UINT32  VolSpaceSize;
+
+  if (ParentBlockDevNo > PEI_FAT_MAX_BLOCK_DEVICE - 1) {
+return FALSE;
+  }
+
+  Found   = FALSE;
+  ParentBlockDev  = &(PrivateData->BlockDevice[ParentBlockDevNo]);
+  VolSpaceSize= 0;
+
+  //
+  // CD_ROM has the fixed block size as 2048 bytes
+  //
+  if (ParentBlockDev->BlockSize != 2048) {
+return FALSE;
+  }
+
+  VolDescriptor = (CDROM_VOLUME_DESCRIPTOR *) PrivateData->BlockData;
+  Catalog   = (ELTORITO_CATALOG *) VolDescriptor;
+
+  //
+  // the ISO-9660 volume descriptor starts at 32k on the media
+  // and CD_ROM has the fixed block size as 2048 bytes, so...
+  //
+  VolDescriptorLba = 15;
+  //
+  // ((16*2048) / Media->BlockSize) - 1;
+  //
+  // Loop: handle one volume descriptor per time
+  //
+  while (TRUE) {
+
+VolDescriptorLba += 1;
+if (VolDescriptorLba > ParentBlockDev->LastBlock) {
+  //
+  // We are pointing past the end of the device so exit
+  //
+  break;
+}
+
+Status = FatReadBlock (
+  PrivateData,
+  ParentBlockDevNo,
+  VolDescriptorLba,
+  ParentBlockDev->BlockSize,
+  VolDescriptor
+  );
+if (EFI_ERROR (Status)) {
+  break;
+}
+//
+// Check for valid volume descriptor signature
+//
+if (VolDescriptor->Unknown.Type == CDVOL_TYPE_END ||
+CompareMem (VolDescriptor->Unknown.Id, CDVOL_ID, sizeof 
(VolDescriptor->Unknown.Id)) != 0
+) {
+  //
+  // end of Volume descriptor list
+  //
+  break;
+}
+//
+// Read the Volume Space Size from Primary Volume Descriptor 81-88 byte
+//
+if (VolDescriptor->Unknown.Type == CDVOL_TYPE_CODED) {
+  VolSpaceSize = VolDescriptor->PrimaryVolume.VolSpaceSize[1];
+}
+//
+// Is it an El Torito volume descriptor?
+//
+if (CompareMem (
+  VolDescriptor->BootRecordVolume.SystemId,
+  CDVOL_ELTORITO_ID,
+  sizeof (CDVOL_ELTORITO_ID) - 1
+  ) != 0) {
+  continue;
+}
+//
+// Read in the boot El Torito boot catalog
+//
+Lba = UNPACK_INT32 (VolDescriptor->BootRecordVolume.EltCatalog);
+if (Lba > ParentBlockDev->LastBlock) {
+  continue;
+}
+
+Status = FatReadBlock (
+  PrivateData,
+  ParentBlockDevNo,
+  Lba,
+  ParentBlockDev->

[edk2] [PATCH v2 2/3] MdePkg/UefiGpt.h: Add new definition for enable GPT support

2019-01-27 Thread Chen A Chen
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1470

This definition comes from UEFI Spec and used to support GPT in FatPei driver.

Cc: Liming Gao 
Cc: Michael D Kinney 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 MdePkg/Include/Uefi/UefiGpt.h | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/MdePkg/Include/Uefi/UefiGpt.h b/MdePkg/Include/Uefi/UefiGpt.h
index f635b05390..e4e919beaf 100644
--- a/MdePkg/Include/Uefi/UefiGpt.h
+++ b/MdePkg/Include/Uefi/UefiGpt.h
@@ -1,7 +1,7 @@
 /** @file
   EFI Guid Partition Table Format Definition.
 
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
 This program and the accompanying materials are licensed and made available 
under
 the terms and conditions of the BSD License that accompanies this distribution.
 The full text of the license may be found at
@@ -24,6 +24,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 /// EFI Partition Table Signature: "EFI PART".
 ///
 #define EFI_PTAB_HEADER_ID  SIGNATURE_64 ('E','F','I',' ','P','A','R','T')
+///
+/// Minimum bytes reserve for EFI entry array buffer.
+///
+#define EFI_GPT_PART_ENTRY_MIN_SIZE 16384
 
 #pragma pack(1)
 
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v2 3/3] FatPkg: Add GPT check in FatPei to support Capsule-on-Disk feature.

2019-01-27 Thread Chen A Chen
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1470
This feature is used for finding GPT partition, follow the following step to 
check.
1) Check Protective MBR.
2) Check GPT primary/backup header.
3) Check GPT primary/backup entry array.

Cc: Ruiyu Ni 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 FatPkg/FatPei/FatLitePeim.h |   3 +-
 FatPkg/FatPei/FatPei.inf|   3 +
 FatPkg/FatPei/Gpt.c | 552 
 FatPkg/FatPei/Part.c|  16 +-
 4 files changed, 570 insertions(+), 4 deletions(-)
 create mode 100644 FatPkg/FatPei/Gpt.c

diff --git a/FatPkg/FatPei/FatLitePeim.h b/FatPkg/FatPei/FatLitePeim.h
index fbf887da5f..3a0d8ae123 100644
--- a/FatPkg/FatPei/FatLitePeim.h
+++ b/FatPkg/FatPei/FatLitePeim.h
@@ -1,7 +1,7 @@
 /** @file
   Data structures for FAT recovery PEIM
 
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
 
 This program and the accompanying materials are licensed and made available
 under the terms and conditions of the BSD License which accompanies this
@@ -27,6 +27,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/FatPkg/FatPei/FatPei.inf b/FatPkg/FatPei/FatPei.inf
index 5401f9a10b..2ed11ba0a6 100644
--- a/FatPkg/FatPei/FatPei.inf
+++ b/FatPkg/FatPei/FatPei.inf
@@ -31,6 +31,7 @@
 
 [Sources]
   Mbr.c
+  Gpt.c
   Eltorito.c
   Part.c
   FatLiteApi.c
@@ -49,6 +50,7 @@
 [LibraryClasses]
   PcdLib
   BaseMemoryLib
+  MemoryAllocationLib
   PeimEntryPoint
   BaseLib
   DebugLib
@@ -61,6 +63,7 @@
   gRecoveryOnFatIdeDiskGuid   ## SOMETIMES_CONSUMES   ## 
UNDEFINED
   gRecoveryOnFatFloppyDiskGuid## SOMETIMES_CONSUMES   ## 
UNDEFINED
   gRecoveryOnFatNvmeDiskGuid  ## SOMETIMES_CONSUMES   ## 
UNDEFINED
+  gEfiPartTypeUnusedGuid  ## SOMETIMES_CONSUMES   ## 
UNDEFINED
 
 
 [Ppis]
diff --git a/FatPkg/FatPei/Gpt.c b/FatPkg/FatPei/Gpt.c
new file mode 100644
index 00..0cb640bd6f
--- /dev/null
+++ b/FatPkg/FatPei/Gpt.c
@@ -0,0 +1,552 @@
+/** @file
+  Routines supporting partition discovery and
+  logical device reading
+
+Copyright (c) 2019 Intel Corporation. All rights reserved.
+
+This program and the accompanying materials are licensed and made available
+under the terms and conditions of the BSD License which accompanies this
+distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include 
+#include 
+#include 
+#include "FatLitePeim.h"
+
+//
+// Assumption: 'a' and 'blocksize' are all UINT32 or UINT64.
+// If 'a' and 'blocksize' are not the same type, should use DivU64xU32 to 
calculate.
+//
+#define EFI_SIZE_TO_BLOCKS(a, blocksize)  (((a) / (blocksize)) + (((a) % 
(blocksize)) ? 1 : 0))
+
+//
+// GPT Partition Entry Status
+//
+typedef struct {
+  BOOLEAN OutOfRange;
+  BOOLEAN Overlap;
+  BOOLEAN OsSpecific;
+} EFI_PARTITION_ENTRY_STATUS;
+
+/**
+  Check if the CRC field in the Partition table header is valid
+
+  @param[in]  BlockIo Parent BlockIo interface
+  @param[in]  DiskIo  Disk Io Protocol.
+  @param[in]  PartHeader  Partition table header structure
+
+  @retval TRUE  the CRC is valid
+  @retval FALSE the CRC is invalid
+
+**/
+BOOLEAN
+PartitionCheckGptHeaderCRC (
+  IN  EFI_PARTITION_TABLE_HEADER  *PartHeader
+  )
+{
+  UINT32  GptHdrCrc;
+  UINT32  Crc;
+
+  GptHdrCrc = PartHeader->Header.CRC32;
+
+  //
+  // Set CRC field to zero when doing calcuation
+  //
+  PartHeader->Header.CRC32 = 0;
+
+  Crc = CalculateCrc32 (PartHeader, PartHeader->Header.HeaderSize);
+
+  //
+  // Restore Header CRC
+  //
+  PartHeader->Header.CRC32 = GptHdrCrc;
+
+  return (GptHdrCrc == Crc);
+}
+
+
+/**
+  Check if the CRC field in the Partition table header is valid
+  for Partition entry array.
+
+  @param[in]  BlockIo Parent BlockIo interface
+  @param[in]  DiskIo  Disk Io Protocol.
+  @param[in]  PartHeader  Partition table header structure
+
+  @retval TRUE  the CRC is valid
+  @retval FALSE the CRC is invalid
+
+**/
+BOOLEAN
+PartitionCheckGptEntryArrayCRC (
+  IN  EFI_PARTITION_TABLE_HEADER *PartHeader,
+  IN  EFI_PARTITION_ENTRY*PartEntry
+  )
+{
+  UINT32  Crc;
+  UINTN   Size;
+
+  Size = (UINTN)MultU64x32(PartHeader->NumberOfPartitionEntries, 
PartHeader->SizeOfPartitionEntry);
+  Crc  = CalculateCrc32 (PartEntry, Size);
+
+  return (BOOLEAN) (PartHeader->PartitionEntryArrayCRC32 == Crc);
+}
+
+/**
+  The function is used for valid GPT table. Both for Primary and Backup GPT 
header.
+
+  @param[in]

[edk2] [PATCH v2 2/2] MdeModulePkg/CapsuleApp: Enhance CapsuleApp to support Capsule-on-Disk.

2019-01-27 Thread Chen A Chen
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1482

CapsuleApp is used for trigger capsule update.
Add -OD option in CapsuleApp to support doing capsule update via storage.
Add -F and -L options to support dumping information feature.

Cc: Jian J Wang 
Cc: Hao Wu 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.c   | 153 +++-
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.inf |   8 +
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c  | 535 +-
 .../Application/CapsuleApp/CapsuleOnDisk.c | 802 +
 MdeModulePkg/Include/Library/UefiBootManagerLib.h  |  19 +
 MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c   |  22 +
 6 files changed, 1524 insertions(+), 15 deletions(-)
 create mode 100644 MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c 
b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
index 4d907242f3..ca9baa0a6a 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -105,6 +106,44 @@ DumpEsrtData (
   VOID
   );
 
+/**
+  Dump Provisioned Capsule.
+
+  @param[in]  DumpCapsuleInfo  The flag to indicate whether to dump the 
capsule inforomation.
+**/
+VOID
+DumpProvisionedCapsule (
+  IN BOOLEAN  DumpCapsuleInfo
+  );
+
+/**
+  Dump all EFI System Parition.
+**/
+VOID
+DumpAllEfiSysPartition (
+  VOID
+  );
+
+/**
+  Process Capsule On Disk.
+
+  @param[in]  CapsuleBufferAn array of pointer to capsule images
+  @param[in]  FileSize An array of UINTN to capsule images size
+  @param[in]  OrgFileName  An array of orginal capsule images name
+  @param[in]  NewFileName  An array of new capsule images name
+  @param[in]  CapsuleNum   The count of capsule images
+
+  @retval EFI_SUCCESS   Capsule on disk secceed.
+**/
+EFI_STATUS
+ProcessCapsuleOnDisk (
+  IN VOID  **CapsuleBuffer,
+  IN UINTN *CapsuleBufferSize,
+  IN CHAR16**FilePath,
+  IN CHAR16*Map,
+  IN UINTN CapsuleNum
+  );
+
 /**
   Read a file.
 
@@ -799,19 +838,22 @@ PrintUsage (
   )
 {
   Print(L"CapsuleApp:  usage\n");
-  Print(L"  CapsuleApp  [-NR]\n");
+  Print(L"  CapsuleApp  [-NR] [-OD [FSx]]\n");
   Print(L"  CapsuleApp -S\n");
   Print(L"  CapsuleApp -C\n");
   Print(L"  CapsuleApp -P\n");
   Print(L"  CapsuleApp -E\n");
+  Print(L"  CapsuleApp -L\n");
+  Print(L"  CapsuleApp -L INFO\n");
+  Print(L"  CapsuleApp -F\n");
   Print(L"  CapsuleApp -G  -O \n");
   Print(L"  CapsuleApp -N  -O \n");
   Print(L"  CapsuleApp -D \n");
   Print(L"  CapsuleApp -P GET   -O \n");
   Print(L"Parameter:\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"  -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"  -OD: Delivery of Capsules via file on Mass Storage device.");
   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");
@@ -820,6 +862,8 @@ PrintUsage (
   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"  -L:  Dump provisioned capsule image information.\n");
+  Print(L"  -F:  Dump all EFI System Partition.\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 FMP capsule image\n");
@@ -851,7 +895,7 @@ UefiMain (
 {
   EFI_STATUSStatus;
   RETURN_STATUS RStatus;
-  UINTN FileSize[MAX_CAPSULE_NUM];
+  UINTN CapsuleBufferSize[MAX_CAPSULE_NUM];
   VOID  *CapsuleBuffer[MAX_CAPSULE_NUM];
   EFI_CAPSULE_BLOCK_DESCRIPTOR  *BlockDescriptors;
   EFI_CAPSULE_HEADER*CapsuleHeaderArray[MAX_CAPSULE_NUM + 1];
@@ -859,9 +903,14 @@ UefiMain (
   EFI_RESET_TYPEResetType;
   BOOLEAN   

[edk2] [PATCH v2 1/2] MdePkg/UefiSpec.h: Add definition to support Capsule-on-Disk feature.

2019-01-27 Thread Chen A Chen
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1482

UEFI Spec define this definition to support Capsule-on-Disk.

Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 MdePkg/Include/Uefi/UefiSpec.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/MdePkg/Include/Uefi/UefiSpec.h b/MdePkg/Include/Uefi/UefiSpec.h
index 75af99de50..9d3d7a9a63 100644
--- a/MdePkg/Include/Uefi/UefiSpec.h
+++ b/MdePkg/Include/Uefi/UefiSpec.h
@@ -2201,6 +2201,11 @@ typedef struct {
   #error Unknown Processor Type
 #endif
 
+//
+// The directory within the active EFI System Partition defined for delivery 
of capsule to firmware
+//
+#define EFI_CAPSULE_FROM_FILE_DIRL"\\EFI\\UpdateCapsule\\"
+
 #include 
 #include 
 #include 
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 3/3] MdeModulePkg/CapsuleApp: Enhance CapsuleApp to support Capsule-on-Disk.

2019-01-24 Thread Chen A Chen
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1482

CapsuleApp is used for trigger capsule update.
Add -OD option in CapsuleApp to support doing capsule update via storage.
Add -F and -L options to support dumping information feature.

Cc: Jian J Wang 
Cc: Hao Wu 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.c   | 103 ++-
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.inf |   8 +
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c  | 535 +-
 .../Application/CapsuleApp/CapsuleOnDisk.c | 802 +
 MdeModulePkg/Include/Library/UefiBootManagerLib.h  |  19 +
 MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c   |  23 +
 6 files changed, 1487 insertions(+), 3 deletions(-)
 create mode 100644 MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c 
b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
index acae0fe261..522ba40311 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -48,6 +49,7 @@ UINTN  NumberOfDescriptors = 1;
 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
   {L"-C", TypeFlag},
   {L"-E", TypeFlag},
+  {L"-F", TypeFlag},
   {L"-S", TypeFlag},
 
   {L"-NR", TypeFlag},
@@ -58,6 +60,9 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
   {L"-D", TypeValue},
   {L"-P", TypeValue},
   {L"-I", TypeValue},
+  {L"-L", TypeValue},
+
+  {L"-OD", TypeValue},
 
   {NULL, TypeMax}
   };
@@ -118,6 +123,44 @@ DumpEsrtData (
   VOID
   );
 
+/**
+  Dump Provisioned Capsule.
+
+  @param[in]  DumpCapsuleInfo  The flag to indicate whether to dump the 
capsule inforomation.
+**/
+VOID
+DumpProvisionedCapsule (
+  IN BOOLEAN  DumpCapsuleInfo
+  );
+
+/**
+  Dump all EFI System Parition.
+**/
+VOID
+DumpAllEfiSysPartition (
+  VOID
+  );
+
+/**
+  Process Capsule On Disk.
+
+  @param[in]  CapsuleBufferAn array of pointer to capsule images
+  @param[in]  FileSize An array of UINTN to capsule images size
+  @param[in]  OrgFileName  An array of orginal capsule images name
+  @param[in]  NewFileName  An array of new capsule images name
+  @param[in]  CapsuleNum   The count of capsule images
+
+  @retval EFI_SUCCESS   Capsule on disk secceed.
+**/
+EFI_STATUS
+ProcessCapsuleOnDisk (
+  IN VOID  **CapsuleBuffer,
+  IN UINTN *CapsuleBufferSize,
+  IN CHAR16*Map,
+  IN CHAR16**OutputCapsuleNames,
+  IN UINTN CapsuleNum
+  );
+
 /**
   Read a file.
 
@@ -786,11 +829,14 @@ PrintUsage (
   )
 {
   Print(L"CapsuleApp:  usage\n");
-  Print(L"  CapsuleApp  [-NR]\n");
+  Print(L"  CapsuleApp  [-NR] [-OD [FS]]\n");
   Print(L"  CapsuleApp -S\n");
   Print(L"  CapsuleApp -C\n");
   Print(L"  CapsuleApp -P\n");
   Print(L"  CapsuleApp -E\n");
+  Print(L"  CapsuleApp -L\n");
+  Print(L"  CapsuleApp -L INFO\n");
+  Print(L"  CapsuleApp -F\n");
   Print(L"  CapsuleApp -G  -O \n");
   Print(L"  CapsuleApp -N  -O \n");
   Print(L"  CapsuleApp -D \n");
@@ -806,6 +852,8 @@ PrintUsage (
   Print(L"  -P:  Dump UEFI FMP protocol info, or get image with specified\n");
   Print(L"   ImageTypeId and Index (decimal format) to a file\n");
   Print(L"  -E:  Dump UEFI ESRT table info.\n");
+  Print(L"  -L:  Dump provisioned capsule image information.\n");
+  Print(L"  -F:  Dump all EFI System Partition.\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 FMP capsule image\n");
@@ -815,6 +863,7 @@ PrintUsage (
   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");
+  Print(L"  -OD: Do update capsule via storage.\n");
 }
 
 /**
@@ -846,12 +895,16 @@ UefiMain (
   CHAR16*ProblemParam;
   CHAR16*BmpFileName;
   CHAR16*CapsuleFileName;
+  CHAR16*CapsuleFileNames[MAX_CAPSULE_NUM];
   CHAR16*OutputFileName;
   CHAR16*GuidStr;
   CHAR16*IndexStr;
+  CHAR16*DumpInfoStr;
+  CHAR16*FsMap

[edk2] [PATCH 2/3] MdePkg/UefiSpec.h: Add definition to support Capsule-on-Disk feature.

2019-01-24 Thread Chen A Chen
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1482

UEFI Spec define this definition to support Capsule-on-Disk.

Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 MdePkg/Include/Uefi/UefiSpec.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/MdePkg/Include/Uefi/UefiSpec.h b/MdePkg/Include/Uefi/UefiSpec.h
index 75af99de50..9d3d7a9a63 100644
--- a/MdePkg/Include/Uefi/UefiSpec.h
+++ b/MdePkg/Include/Uefi/UefiSpec.h
@@ -2201,6 +2201,11 @@ typedef struct {
   #error Unknown Processor Type
 #endif
 
+//
+// The directory within the active EFI System Partition defined for delivery 
of capsule to firmware
+//
+#define EFI_CAPSULE_FROM_FILE_DIRL"\\EFI\\UpdateCapsule\\"
+
 #include 
 #include 
 #include 
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 1/3] MdeModulePkg/CapsuleApp: Refine code logic of parsing parameter.

2019-01-24 Thread Chen A Chen
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1482

No change functionality, use ShellLib to parsing command line.

Cc: Jian J Wang 
Cc: Hao Wu 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.c   | 433 +++--
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.inf |   2 +
 2 files changed, 236 insertions(+), 199 deletions(-)

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c 
b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
index 4d907242f3..acae0fe261 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define CAPSULE_HEADER_SIZE  0x20
 
@@ -39,15 +40,27 @@
 
 #define MAX_CAPSULE_NUM 10
 
-extern UINTN  Argc;
-extern CHAR16 **Argv;
-
 //
 // Define how many block descriptors we want to test with.
 //
 UINTN  NumberOfDescriptors = 1;
-UINTN  CapsuleFirstIndex;
-UINTN  CapsuleLastIndex;
+
+STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
+  {L"-C", TypeFlag},
+  {L"-E", TypeFlag},
+  {L"-S", TypeFlag},
+
+  {L"-NR", TypeFlag},
+
+  {L"-G", TypeValue},
+  {L"-O", TypeValue},
+  {L"-N", TypeValue},
+  {L"-D", TypeValue},
+  {L"-P", TypeValue},
+  {L"-I", TypeValue},
+
+  {NULL, TypeMax}
+  };
 
 /**
   Dump capsule information
@@ -161,13 +174,12 @@ GetArg (
 **/
 EFI_STATUS
 CreateBmpFmp (
-  VOID
+  IN CHAR16 *BmpName,
+  IN CHAR16 *OutputCapsuleName
   )
 {
-  CHAR16*OutputCapsuleName;
   VOID  *BmpBuffer;
   UINTN FileSize;
-  CHAR16*BmpName;
   UINT8 *FullCapsuleBuffer;
   UINTN FullCapsuleBufferSize;
   EFI_DISPLAY_CAPSULE   *DisplayCapsule;
@@ -191,22 +203,10 @@ CreateBmpFmp (
   // HorizontalResolution >= BMP_IMAGE_HEADER.PixelWidth
   // VerticalResolution   >= BMP_IMAGE_HEADER.PixelHeight
 
-  if (Argc != 5) {
-Print(L"CapsuleApp: Incorrect parameter count.\n");
-return EFI_UNSUPPORTED;
-  }
-
-  if (StrCmp(Argv[3], L"-O") != 0) {
-Print(L"CapsuleApp: NO output capsule name.\n");
-return EFI_UNSUPPORTED;
-  }
-  OutputCapsuleName = Argv[4];
-
   BmpBuffer = NULL;
   FileSize = 0;
   FullCapsuleBuffer = NULL;
 
-  BmpName = Argv[2];
   Status = ReadFileToBuffer(BmpName, , );
   if (EFI_ERROR(Status)) {
 Print(L"CapsuleApp: BMP image (%s) is not found.\n", BmpName);
@@ -425,13 +425,12 @@ IsFmpCapsuleGuid (
 **/
 EFI_STATUS
 CreateNestedFmp (
-  VOID
+  IN CHAR16 *CapsuleName,
+  IN CHAR16 *OutputCapsuleName
   )
 {
-  CHAR16*OutputCapsuleName;
   VOID  *CapsuleBuffer;
   UINTN FileSize;
-  CHAR16*CapsuleName;
   UINT8 *FullCapsuleBuffer;
   UINTN FullCapsuleBufferSize;
   EFI_CAPSULE_HEADER*NestedCapsuleHeader;
@@ -439,22 +438,10 @@ CreateNestedFmp (
   UINT32FwType;
   EFI_STATUSStatus;
 
-  if (Argc != 5) {
-Print(L"CapsuleApp: Incorrect parameter count.\n");
-return EFI_UNSUPPORTED;
-  }
-
-  if (StrCmp(Argv[3], L"-O") != 0) {
-Print(L"CapsuleApp: NO output capsule name.\n");
-return EFI_UNSUPPORTED;
-  }
-  OutputCapsuleName = Argv[4];
-
   CapsuleBuffer = NULL;
   FileSize = 0;
   FullCapsuleBuffer = NULL;
 
-  CapsuleName = Argv[2];
   Status = ReadFileToBuffer(CapsuleName, , );
   if (EFI_ERROR(Status)) {
 Print(L"CapsuleApp: Capsule image (%s) is not found.\n", CapsuleName);
@@ -807,7 +794,7 @@ PrintUsage (
   Print(L"  CapsuleApp -G  -O \n");
   Print(L"  CapsuleApp -N  -O \n");
   Print(L"  CapsuleApp -D \n");
-  Print(L"  CapsuleApp -P GET   -O \n");
+  Print(L"  CapsuleApp -P  -I  -O \n");
   Print(L"Parameter:\n");
   Print(L"  -NR: No reset will be triggered for the capsule with\n");
   Print(L"   CAPSULE_FLAGS_PERSIST_ACROSS_RESET and without\n");
@@ -817,8 +804,7 @@ PrintUsage (
   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 

[edk2] [PATCH 3/3] FatPkg: Add GPT check in FatPei to support Capsule-on-Disk feature.

2019-01-16 Thread Chen A Chen
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1470
This feature is used for finding GPT partition, follow the following step to 
check.
1) Check Protective MBR.
2) Check GPT primary/backup header.
3) Check GPT primary/backup entry array.

Cc: Ruiyu Ni 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 FatPkg/FatPei/FatLitePeim.h |   1 +
 FatPkg/FatPei/FatPei.inf|   3 +
 FatPkg/FatPei/Gpt.c | 546 
 3 files changed, 550 insertions(+)
 create mode 100644 FatPkg/FatPei/Gpt.c

diff --git a/FatPkg/FatPei/FatLitePeim.h b/FatPkg/FatPei/FatLitePeim.h
index fbf887da5f..afb429c56e 100644
--- a/FatPkg/FatPei/FatLitePeim.h
+++ b/FatPkg/FatPei/FatLitePeim.h
@@ -27,6 +27,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/FatPkg/FatPei/FatPei.inf b/FatPkg/FatPei/FatPei.inf
index 829e87fe92..dd0869f7cd 100644
--- a/FatPkg/FatPei/FatPei.inf
+++ b/FatPkg/FatPei/FatPei.inf
@@ -31,6 +31,7 @@
 
 [Sources]
   Mbr.c
+  Gpt.c
   Eltorito.c
   Part.c
   FatLiteApi.c
@@ -49,6 +50,7 @@
 [LibraryClasses]
   PcdLib
   BaseMemoryLib
+  MemoryAllocationLib
   PeimEntryPoint
   BaseLib
   DebugLib
@@ -61,6 +63,7 @@
   gRecoveryOnFatIdeDiskGuid   ## SOMETIMES_CONSUMES   ## 
UNDEFINED
   gRecoveryOnFatFloppyDiskGuid## SOMETIMES_CONSUMES   ## 
UNDEFINED
   gRecoveryOnFatNvmeDiskGuid  ## SOMETIMES_CONSUMES   ## 
UNDEFINED
+  gEfiPartTypeUnusedGuid  ## SOMETIMES_CONSUMES   ## 
UNDEFINED
 
 
 [Ppis]
diff --git a/FatPkg/FatPei/Gpt.c b/FatPkg/FatPei/Gpt.c
new file mode 100644
index 00..d1f4c1c8b5
--- /dev/null
+++ b/FatPkg/FatPei/Gpt.c
@@ -0,0 +1,546 @@
+/** @file
+  Routines supporting partition discovery and
+  logical device reading
+
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+
+This program and the accompanying materials are licensed and made available
+under the terms and conditions of the BSD License which accompanies this
+distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include 
+#include 
+#include 
+#include "FatLitePeim.h"
+
+//
+// Assumption: 'a' and 'blocksize' are all UINT32 or UINT64.
+// If 'a' and 'blocksize' are not the same type, should use DivU64xU32 to 
calculate.
+//
+#define EFI_SIZE_TO_BLOCKS(a, blocksize)  (((a) / (blocksize)) + (((a) % 
(blocksize)) ? 1 : 0))
+
+//
+// GPT Partition Entry Status
+//
+typedef struct {
+  BOOLEAN OutOfRange;
+  BOOLEAN Overlap;
+  BOOLEAN OsSpecific;
+} EFI_PARTITION_ENTRY_STATUS;
+
+/**
+  Check if the CRC field in the Partition table header is valid
+
+  @param[in]  BlockIo Parent BlockIo interface
+  @param[in]  DiskIo  Disk Io Protocol.
+  @param[in]  PartHeader  Partition table header structure
+
+  @retval TRUE  the CRC is valid
+  @retval FALSE the CRC is invalid
+
+**/
+BOOLEAN
+PartitionCheckGptHeaderCRC (
+  IN  EFI_PARTITION_TABLE_HEADER  *PartHeader
+  )
+{
+  UINT32  GptHdrCrc;
+  UINT32  Crc;
+
+  GptHdrCrc = PartHeader->Header.CRC32;
+
+  //
+  // Set CRC field to zero when doing calcuation
+  //
+  PartHeader->Header.CRC32 = 0;
+
+  Crc = CalculateCrc32 (PartHeader, PartHeader->Header.HeaderSize);
+
+  //
+  // Restore Header CRC
+  //
+  PartHeader->Header.CRC32 = GptHdrCrc;
+
+  return (GptHdrCrc == Crc);
+}
+
+
+/**
+  Check if the CRC field in the Partition table header is valid
+  for Partition entry array.
+
+  @param[in]  BlockIo Parent BlockIo interface
+  @param[in]  DiskIo  Disk Io Protocol.
+  @param[in]  PartHeader  Partition table header structure
+
+  @retval TRUE  the CRC is valid
+  @retval FALSE the CRC is invalid
+
+**/
+BOOLEAN
+PartitionCheckGptEntryArrayCRC (
+  IN  EFI_PARTITION_TABLE_HEADER *PartHeader,
+  IN  EFI_PARTITION_ENTRY*PartEntry
+  )
+{
+  UINT32  Crc;
+  UINTN   Size;
+
+  Size = (UINTN)MultU64x32(PartHeader->NumberOfPartitionEntries, 
PartHeader->SizeOfPartitionEntry);
+  Crc  = CalculateCrc32 (PartEntry, Size);
+
+  return (BOOLEAN) (PartHeader->PartitionEntryArrayCRC32 == Crc);
+}
+
+/**
+  The function is used for valid GPT table. Both for Primary and Backup GPT 
header.
+
+  @param[in]  PrivateData   The global memory map 
+  @param[in]  ParentBlockDevNo  The parent block device
+  @param[in]  IsPrimaryHeader   Indicate to which header will be checked.
+  @param[in]  PartHdr   Stores the partition table that is read
+
+  @retval TRUE  The partition table is valid
+  @retval FALSE The partition table is not valid
+
+**/
+BOOLEAN
+PartitionCheckGptHeader (  
+  IN 

[edk2] [PATCH 2/2] MdePkg/UefiGpt.h: Add new definition for enable GPT support

2019-01-16 Thread Chen A Chen
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1470
This two new definitions are defined for GPT in FatPei diver.

Cc: Liming Gao 
Cc: Michael D Kinney 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 MdePkg/Include/Uefi/UefiGpt.h | 16 
 1 file changed, 16 insertions(+)

diff --git a/MdePkg/Include/Uefi/UefiGpt.h b/MdePkg/Include/Uefi/UefiGpt.h
index f635b05390..8665c8cbc9 100644
--- a/MdePkg/Include/Uefi/UefiGpt.h
+++ b/MdePkg/Include/Uefi/UefiGpt.h
@@ -24,9 +24,25 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 /// EFI Partition Table Signature: "EFI PART".
 ///
 #define EFI_PTAB_HEADER_ID  SIGNATURE_64 ('E','F','I',' ','P','A','R','T')
+///
+/// Minimum bytes reserve for EFI entry array buffer.
+///
+#define GPT_PART_ENTRY_MIN_SIZE 16384
 
 #pragma pack(1)
 
+///
+/// MBR Partition Entry
+///
+typedef struct {
+  UINT8   BootIndicator;
+  UINT8   StartingCHS[3];
+  UINT8   OSType;
+  UINT8   EndingCHS[3];
+  UINT32  StartingLBA;
+  UINT32  SizeInLBA;
+} MBR_PARTITION_ENTRY;
+
 ///
 /// GPT Partition Table Header.
 ///
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 1/2] FatPkg: Break down Part.c file.

2019-01-16 Thread Chen A Chen
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1470
Break down partition parsing logic to 2 parts, Eltorito and MBR.

Cc: Ruiyu Ni 
Cc: Zhang Chao B 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 FatPkg/FatPei/Eltorito.c | 239 +
 FatPkg/FatPei/FatPei.inf |   2 +
 FatPkg/FatPei/Mbr.c  | 182 ++
 FatPkg/FatPei/Part.c | 385 +--
 4 files changed, 424 insertions(+), 384 deletions(-)
 create mode 100644 FatPkg/FatPei/Eltorito.c
 create mode 100644 FatPkg/FatPei/Mbr.c

diff --git a/FatPkg/FatPei/Eltorito.c b/FatPkg/FatPei/Eltorito.c
new file mode 100644
index 00..ffaef51860
--- /dev/null
+++ b/FatPkg/FatPei/Eltorito.c
@@ -0,0 +1,239 @@
+/** @file
+  Routines supporting partition discovery and
+  logical device reading
+
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+
+This program and the accompanying materials are licensed and made available
+under the terms and conditions of the BSD License which accompanies this
+distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include 
+#include "FatLitePeim.h"
+
+/**
+  This function finds Eltorito partitions. Main algorithm
+  is ported from DXE partition driver.
+
+  @param  PrivateData   The global memory map
+  @param  ParentBlockDevNo  The parent block device
+
+  @retval TRUE  New partitions are detected and logical block 
devices
+are  added to block device array
+  @retval FALSE No New partitions are added;
+
+**/
+BOOLEAN
+FatFindEltoritoPartitions (
+  IN  PEI_FAT_PRIVATE_DATA *PrivateData,
+  IN  UINTNParentBlockDevNo
+  )
+{
+  EFI_STATUS  Status;
+  BOOLEAN Found;
+  PEI_FAT_BLOCK_DEVICE*BlockDev;
+  PEI_FAT_BLOCK_DEVICE*ParentBlockDev;
+  UINT32  VolDescriptorLba;
+  UINT32  Lba;
+  CDROM_VOLUME_DESCRIPTOR *VolDescriptor;
+  ELTORITO_CATALOG*Catalog;
+  UINTN   Check;
+  UINTN   Index;
+  UINTN   MaxIndex;
+  UINT16  *CheckBuffer;
+  UINT32  SubBlockSize;
+  UINT32  SectorCount;
+  UINT32  VolSpaceSize;
+
+  if (ParentBlockDevNo > PEI_FAT_MAX_BLOCK_DEVICE - 1) {
+return FALSE;
+  }
+
+  Found   = FALSE;
+  ParentBlockDev  = &(PrivateData->BlockDevice[ParentBlockDevNo]);
+  VolSpaceSize= 0;
+
+  //
+  // CD_ROM has the fixed block size as 2048 bytes
+  //
+  if (ParentBlockDev->BlockSize != 2048) {
+return FALSE;
+  }
+
+  VolDescriptor = (CDROM_VOLUME_DESCRIPTOR *) PrivateData->BlockData;
+  Catalog   = (ELTORITO_CATALOG *) VolDescriptor;
+
+  //
+  // the ISO-9660 volume descriptor starts at 32k on the media
+  // and CD_ROM has the fixed block size as 2048 bytes, so...
+  //
+  VolDescriptorLba = 15;
+  //
+  // ((16*2048) / Media->BlockSize) - 1;
+  //
+  // Loop: handle one volume descriptor per time
+  //
+  while (TRUE) {
+
+VolDescriptorLba += 1;
+if (VolDescriptorLba > ParentBlockDev->LastBlock) {
+  //
+  // We are pointing past the end of the device so exit
+  //
+  break;
+}
+
+Status = FatReadBlock (
+  PrivateData,
+  ParentBlockDevNo,
+  VolDescriptorLba,
+  ParentBlockDev->BlockSize,
+  VolDescriptor
+  );
+if (EFI_ERROR (Status)) {
+  break;
+}
+//
+// Check for valid volume descriptor signature
+//
+if (VolDescriptor->Unknown.Type == CDVOL_TYPE_END ||
+CompareMem (VolDescriptor->Unknown.Id, CDVOL_ID, sizeof 
(VolDescriptor->Unknown.Id)) != 0
+) {
+  //
+  // end of Volume descriptor list
+  //
+  break;
+}
+//
+// Read the Volume Space Size from Primary Volume Descriptor 81-88 byte
+//
+if (VolDescriptor->Unknown.Type == CDVOL_TYPE_CODED) {
+  VolSpaceSize = VolDescriptor->PrimaryVolume.VolSpaceSize[1];
+}
+//
+// Is it an El Torito volume descriptor?
+//
+if (CompareMem (
+  VolDescriptor->BootRecordVolume.SystemId,
+  CDVOL_ELTORITO_ID,
+  sizeof (CDVOL_ELTORITO_ID) - 1
+  ) != 0) {
+  continue;
+}
+//
+// Read in the boot El Torito boot catalog
+//
+Lba = UNPACK_INT32 (VolDescriptor->BootRecordVolume.EltCatalog);
+if (Lba > ParentBlockDev->LastBlock) {
+  continue;
+}
+
+Status = FatReadBlock (
+  PrivateData,
+  ParentBlockDevNo,
+  Lba,
+  ParentBlockDev->

[edk2] [PATCH] SecurityPkg: Remove dead code and inf redundant definitions.

2018-11-27 Thread Chen A Chen
Fix BZ1065, https://bugzilla.tianocore.org/show_bug.cgi?id=1065

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
Cc: Zhang Chao B 
---
 SecurityPkg/Tcg/MemoryOverwriteControl/TcgMor.inf  |   1 -
 SecurityPkg/Tcg/Opal/OpalPassword/OpalAhciMode.c   |  52 
 SecurityPkg/Tcg/Opal/OpalPassword/OpalAhciMode.h   |  23 --
 SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.h|  11 -
 .../Tcg/Opal/OpalPassword/OpalHiiCallbacks.c   |  87 --
 SecurityPkg/Tcg/Opal/OpalPassword/OpalNvmeMode.c   | 321 -
 SecurityPkg/Tcg/Opal/OpalPassword/OpalNvmeMode.h   | 128 
 .../Tcg/Opal/OpalPassword/OpalPasswordDxe.inf  |   2 -
 .../Tcg/Opal/OpalPassword/OpalPasswordPei.inf  |   1 -
 SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf   |   1 -
 SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf|   1 -
 SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf|   1 -
 SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDxe.inf  |   1 -
 .../SecureBootConfigDxe/SecureBootConfigDxe.inf|   2 -
 14 files changed, 632 deletions(-)

diff --git a/SecurityPkg/Tcg/MemoryOverwriteControl/TcgMor.inf 
b/SecurityPkg/Tcg/MemoryOverwriteControl/TcgMor.inf
index 6f9a77b868..a17fa4046d 100644
--- a/SecurityPkg/Tcg/MemoryOverwriteControl/TcgMor.inf
+++ b/SecurityPkg/Tcg/MemoryOverwriteControl/TcgMor.inf
@@ -43,7 +43,6 @@
   UefiDriverEntryPoint
   UefiBootServicesTableLib
   UefiRuntimeServicesTableLib
-  ReportStatusCodeLib
   DebugLib
   UefiLib
   MemoryAllocationLib
diff --git a/SecurityPkg/Tcg/Opal/OpalPassword/OpalAhciMode.c 
b/SecurityPkg/Tcg/Opal/OpalPassword/OpalAhciMode.c
index d51865380f..0c4edd5346 100644
--- a/SecurityPkg/Tcg/Opal/OpalPassword/OpalAhciMode.c
+++ b/SecurityPkg/Tcg/Opal/OpalPassword/OpalAhciMode.c
@@ -969,58 +969,6 @@ AhciReset (
 
 }
 
-/**
-  Send Buffer cmd to specific device.
-
-  @param[in]  AhciContext The pointer to the AHCI_CONTEXT.
-  @param[in]  PortThe port number of attached ATA device.
-  @param[in]  PortMultiplier  The port number of port multiplier of 
attached ATA device.
-  @param[in, out]  Buffer The Data Buffer to store IDENTIFY PACKET 
Data.
-
-  @retval EFI_DEVICE_ERRORThe cmd abort with error occurs.
-  @retval EFI_TIMEOUT The operation is time out.
-  @retval EFI_UNSUPPORTED The device is not ready for executing.
-  @retval EFI_SUCCESS The cmd executes successfully.
-
-**/
-EFI_STATUS
-EFIAPI
-AhciIdentify (
-  IN AHCI_CONTEXT *AhciContext,
-  IN UINT8Port,
-  IN UINT8PortMultiplier,
-  IN OUT ATA_IDENTIFY_DATA*Buffer
-  )
-{
-  EFI_STATUS   Status;
-  EFI_ATA_COMMAND_BLOCKAtaCommandBlock;
-
-  if (AhciContext == NULL || Buffer == NULL) {
-return EFI_INVALID_PARAMETER;
-  }
-
-  ZeroMem (, sizeof (EFI_ATA_COMMAND_BLOCK));
-
-  AtaCommandBlock.AtaCommand = ATA_CMD_IDENTIFY_DRIVE;
-  AtaCommandBlock.AtaSectorCount = 1;
-
-  Status = AhciPioTransfer (
- AhciContext,
- Port,
- PortMultiplier,
- NULL,
- 0,
- TRUE,
- ,
- NULL,
- Buffer,
- sizeof (ATA_IDENTIFY_DATA),
- ATA_TIMEOUT
- );
-
-  return Status;
-}
-
 /**
   Allocate transfer-related data struct which is used at AHCI mode.
 
diff --git a/SecurityPkg/Tcg/Opal/OpalPassword/OpalAhciMode.h 
b/SecurityPkg/Tcg/Opal/OpalPassword/OpalAhciMode.h
index 037f81ac24..2076b0411b 100644
--- a/SecurityPkg/Tcg/Opal/OpalPassword/OpalAhciMode.h
+++ b/SecurityPkg/Tcg/Opal/OpalPassword/OpalAhciMode.h
@@ -293,29 +293,6 @@ typedef struct {
   UINT32AhciBar;
 } AHCI_CONTEXT;
 
-/**
-  Send Buffer cmd to specific device.
-
-  @param  AhciContext The pointer to the AHCI_CONTEXT.
-  @param  PortThe number of port.
-  @param  PortMultiplier  The timeout Value of stop.
-  @param  Buffer  The Data Buffer to store IDENTIFY PACKET Data.
-
-  @retval EFI_DEVICE_ERRORThe cmd abort with error occurs.
-  @retval EFI_TIMEOUT The operation is time out.
-  @retval EFI_UNSUPPORTED The device is not ready for executing.
-  @retval EFI_SUCCESS The cmd executes successfully.
-
-**/
-EFI_STATUS
-EFIAPI
-AhciIdentify (
-  IN AHCI_CONTEXT *AhciContext,
-  IN UINT8Port,
-  IN UINT8PortMultiplier,
-  IN OUT ATA_IDENTIFY_DATA*Buffer
-  );
-
 /**
   Allocate transfer-related data struct which is used at AHCI mode.
 
diff --git a/SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.h 
b/SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.h
index a4bb19ad60..8b368fe995 100644
--- a/SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.h
+++ b/SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.h
@@ -285,17 +285,6 @@ OpalHiiAddPackages(
   VOID
   );
 
-/**
-  Check whether enable feature or not.
-
-  @retval  Return the disk number.
-
-**/
-UINT8

[edk2] [PATCH 3/3] SignedCapsulePkg: Remove the missing PalLib in DSC file.

2018-09-20 Thread Chen A Chen
The PalLib will remove in MdePkg, so remove this lib from DSC file.

Cc: Jiewen Yao 
Cc: Michael D Kinney 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 SignedCapsulePkg/SignedCapsulePkg.dsc | 1 -
 1 file changed, 1 deletion(-)

diff --git a/SignedCapsulePkg/SignedCapsulePkg.dsc 
b/SignedCapsulePkg/SignedCapsulePkg.dsc
index 7ea74d7346..db7f176166 100644
--- a/SignedCapsulePkg/SignedCapsulePkg.dsc
+++ b/SignedCapsulePkg/SignedCapsulePkg.dsc
@@ -77,7 +77,6 @@
   SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf
   CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
-  PalLib|MdePkg/Library/BasePalLibNull/BasePalLibNull.inf
   
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf
   #
   # Misc
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 2/3] MdeModulePkg: Remove the missing PalLib in DSC file.

2018-09-20 Thread Chen A Chen
The PalLib will remove in MdePkg, so remove this lib from DSC file.

Cc: Star Zeng 
Cc: Eric Dong 
Cc: Michael D Kinney 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 MdeModulePkg/MdeModulePkg.dsc | 1 -
 1 file changed, 1 deletion(-)

diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc
index 8a81ea141f..3ff3b1213c 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -79,7 +79,6 @@
   SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf
   CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
-  PalLib|MdePkg/Library/BasePalLibNull/BasePalLibNull.inf
   
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf
   
FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf
   #
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH 1/3] IntelFrameworkModulePkg: Remove the missing PalLib in DSC file.

2018-09-20 Thread Chen A Chen
The PalLib will remove in MdePkg, so remove this lib from DSC file.

Cc: Liming Gao 
Cc: Michael D Kinney 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 IntelFrameworkModulePkg/IntelFrameworkModulePkg.dsc | 1 -
 1 file changed, 1 deletion(-)

diff --git a/IntelFrameworkModulePkg/IntelFrameworkModulePkg.dsc 
b/IntelFrameworkModulePkg/IntelFrameworkModulePkg.dsc
index 84e1d890b5..894c5340a0 100644
--- a/IntelFrameworkModulePkg/IntelFrameworkModulePkg.dsc
+++ b/IntelFrameworkModulePkg/IntelFrameworkModulePkg.dsc
@@ -75,7 +75,6 @@
   
DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
   UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
-  PalLib|MdePkg/Library/BasePalLibNull/BasePalLibNull.inf
 
 [LibraryClasses.common.PEIM]
   HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH V2 4/4] UefiCpuPkg: Removing ipf which is no longer supported from edk2.

2018-07-09 Thread Chen A Chen
Merge [Sources.Ia32, Sources.X64] to [Sources] after removing IPF. Also
change other similar parts in this file.

Cc: Eric Dong 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 .../Library/SecPeiDxeTimerLibUefiCpu/SecPeiDxeTimerLibUefiCpu.inf   | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git 
a/UefiCpuPkg/Library/SecPeiDxeTimerLibUefiCpu/SecPeiDxeTimerLibUefiCpu.inf 
b/UefiCpuPkg/Library/SecPeiDxeTimerLibUefiCpu/SecPeiDxeTimerLibUefiCpu.inf
index f8bf628a66..03ba8a4ad3 100644
--- a/UefiCpuPkg/Library/SecPeiDxeTimerLibUefiCpu/SecPeiDxeTimerLibUefiCpu.inf
+++ b/UefiCpuPkg/Library/SecPeiDxeTimerLibUefiCpu/SecPeiDxeTimerLibUefiCpu.inf
@@ -39,7 +39,7 @@
 #  VALID_ARCHITECTURES   = IA32 X64
 #
 
-[Sources.Ia32, Sources.X64]
+[Sources]
   X86TimerLib.c
 
 [Packages]
@@ -49,11 +49,11 @@
 [LibraryClasses]
   BaseLib
 
-[LibraryClasses.IA32, LibraryClasses.X64]
+[LibraryClasses]
   PcdLib
   DebugLib
   LocalApicLib
 
-[Pcd.IA32, Pcd.X64]
+[Pcd]
   gEfiMdePkgTokenSpaceGuid.PcdFSBClock  ## SOMETIMES_CONSUMES
 
-- 
2.16.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH V2 1/4] CryptoPkg: Removing ipf which is no longer supported from edk2.

2018-07-09 Thread Chen A Chen
Removing rules for Ipf sources file:
* Remove the source file which path with "ipf" and also listed in
  [Sources.IPF] section of INF file.
* Remove the source file which listed in [Components.IPF] section
  of DSC file and not listed in any other [Components] section.
* Remove the embedded Ipf code for MDE_CPU_IPF.

Removing rules for Inf file:
* Remove IPF from VALID_ARCHITECTURES comments.
* Remove DXE_SAL_DRIVER from LIBRARY_CLASS in [Defines] section.
* Remove the INF which only listed in [Components.IPF] section in DSC.
* Remove statements from [BuildOptions] that provide IPF specific flags.
* Remove any IPF sepcific sections.

Removing rules for Dec file:
* Remove [Includes.IPF] section from Dec.

Removing rules for Dsc file:
* Remove IPF from SUPPORTED_ARCHITECTURES in [Defines] section of DSC.
* Remove any IPF specific sections.
* Remove statements from [BuildOptions] that provide IPF specific flags.

The following rules are specially proposed by package owner:
* Remove whole "CryptRuntimeDxe" folder which was designed for IPF.
* Remove whole "Include/Protocol" folder
* Update .Dec and .Dsc file accordingly.

Cc: Qin Long 
Cc: Ting Ye 
Cc: Michael D Kinney 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen 
---
 CryptoPkg/CryptRuntimeDxe/CryptRuntime.c   | 248 
 CryptoPkg/CryptRuntimeDxe/CryptRuntime.h   | 186 -
 CryptoPkg/CryptRuntimeDxe/CryptRuntimeDxe.inf  |  54 ---
 CryptoPkg/CryptRuntimeDxe/CryptRuntimeDxe.uni  |  22 --
 CryptoPkg/CryptRuntimeDxe/CryptRuntimeDxeExtra.uni |  20 -
 CryptoPkg/CryptoPkg.dec|   4 -
 CryptoPkg/CryptoPkg.dsc|  10 +-
 CryptoPkg/Include/Protocol/RuntimeCrypt.h  | 204 --
 CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf|   7 +-
 CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf |   5 +-
 CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf |   3 -
 .../BaseCryptLibRuntimeCryptProtocol.inf   |  76 
 .../BaseCryptLibRuntimeCryptProtocol.uni   |  29 --
 .../Cipher/CryptAesNull.c  | 165 
 .../Cipher/CryptArc4Null.c | 130 ---
 .../Cipher/CryptTdesNull.c | 166 
 .../Hash/CryptMd4Null.c| 124 --
 .../Hash/CryptMd5Null.c| 125 --
 .../Hash/CryptSha1Null.c   | 125 --
 .../Hmac/CryptHmacMd5Null.c| 127 ---
 .../Hmac/CryptHmacSha1Null.c   | 127 ---
 .../InternalCryptLib.h |  23 --
 .../Pem/CryptPemNull.c |  44 ---
 .../Pk/CryptAuthenticodeNull.c |  51 ---
 .../Pk/CryptDhNull.c   | 156 
 .../Pk/CryptPkcs7SignNull.c|  59 ---
 .../Pk/CryptPkcs7VerifyNull.c  | 163 
 .../Pk/CryptRsaExtNull.c   | 125 --
 .../Pk/CryptX509Null.c | 238 
 .../Rand/CryptRandNull.c   |  63 
 .../RuntimeDxeIpfCryptLib.c| 419 -
 CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf|  15 +-
 CryptoPkg/Library/OpensslLib/OpensslLib.inf|   7 +-
 CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf  |   7 +-
 CryptoPkg/Library/TlsLib/TlsLib.inf|   4 +-
 35 files changed, 12 insertions(+), 3319 deletions(-)
 delete mode 100644 CryptoPkg/CryptRuntimeDxe/CryptRuntime.c
 delete mode 100644 CryptoPkg/CryptRuntimeDxe/CryptRuntime.h
 delete mode 100644 CryptoPkg/CryptRuntimeDxe/CryptRuntimeDxe.inf
 delete mode 100644 CryptoPkg/CryptRuntimeDxe/CryptRuntimeDxe.uni
 delete mode 100644 CryptoPkg/CryptRuntimeDxe/CryptRuntimeDxeExtra.uni
 delete mode 100644 CryptoPkg/Include/Protocol/RuntimeCrypt.h
 delete mode 100644 
CryptoPkg/Library/BaseCryptLibRuntimeCryptProtocol/BaseCryptLibRuntimeCryptProtocol.inf
 delete mode 100644 
CryptoPkg/Library/BaseCryptLibRuntimeCryptProtocol/BaseCryptLibRuntimeCryptProtocol.uni
 delete mode 100644 
CryptoPkg/Library/BaseCryptLibRuntimeCryptProtocol/Cipher/CryptAesNull.c
 delete mode 100644 
CryptoPkg/Library/BaseCryptLibRuntimeCryptProtocol/Cipher/CryptArc4Null.c
 delete mode 100644 
CryptoPkg/Library/BaseCryptLibRuntimeCryptProtocol/Cipher/CryptTdesNull.c
 delete mode 100644 
CryptoPkg/Library/BaseCryptLibRuntimeCryptProtocol/Hash/CryptMd4Null.c
 delete mode 100644 
CryptoPkg/Library/BaseCryptLibRuntimeCryptProtocol/Hash/CryptMd5Null.c
 delete mode 100644 
CryptoPkg/Library/BaseCryptLibRuntimeCryptProtocol/Hash/CryptSha1Null.c
 delete mode 100644 
CryptoPkg/Library/BaseCryptLibRuntimeCryptProtocol/Hmac/CryptHmacMd5Null.c
 delete mode 100644 
CryptoPkg/Library/BaseCryptLibRuntimeCryptProtocol/Hmac/CryptHmacSha1Null.c
 delete