Re: [edk2-devel] [patch 1/5] MdePkg: Merge TianoCustomDecompress algorithm into

2019-05-13 Thread Liming Gao
Dandan:

  UefiTianoDecompress() API function header doesn't describe the parameter 
Version and the assert condition when Version is not 1 or 2. Please update the 
function comments in header file and C source file. 
  With this change, Reviewed-by: Liming Gao 

Thanks
Liming
> -Original Message-
> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of Dandan 
> Bi
> Sent: Monday, May 13, 2019 10:16 AM
> To: devel@edk2.groups.io
> Cc: Kinney, Michael D ; Gao, Liming 
> 
> Subject: [edk2-devel] [patch 1/5] MdePkg: Merge TianoCustomDecompress 
> algorithm into
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1722
> 
> We plan to merge the BaseUefiTianoCustomDecompressLib
> in MdeModulePkg into the BaseUefDecompressLib in MdePkg.
> In order to reduce the duplicated codes and maintain
> easily.
> This patch adds a new fdf file in BaseUefDecompressLib
> (BaseUefiTianoCustomDecompressLib.inf) to keep the same
> functionality and usage model with the one in MdeModulePkg,
> and then update consumer to use this new one one and
> remove the one in MdeModulePkg finally.
> 
> Cc: Michael D Kinney 
> Cc: Liming Gao 
> Signed-off-by: Dandan Bi 
> ---
>  .../BaseUefiDecompressLib.c   |  69 --
>  .../BaseUefiDecompressLib.uni |   6 +-
>  .../BaseUefiDecompressLibInternals.h  |  44 +++-
>  .../BaseUefiTianoCustomDecompressLib.c| 213 ++
>  .../BaseUefiTianoCustomDecompressLib.inf  |  42 
>  MdePkg/MdePkg.dec |   5 +
>  MdePkg/MdePkg.dsc |   1 +
>  7 files changed, 363 insertions(+), 17 deletions(-)
>  create mode 100644 
> MdePkg/Library/BaseUefiDecompressLib/BaseUefiTianoCustomDecompressLib.c
>  create mode 100644 
> MdePkg/Library/BaseUefiDecompressLib/BaseUefiTianoCustomDecompressLib.inf
> 
> diff --git a/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c
> b/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c
> index 8e502b0fdb..d2c40bf1ca 100644
> --- a/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c
> +++ b/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c
> @@ -1,21 +1,14 @@
>  /** @file
>UEFI Decompress Library implementation refer to UEFI specification.
> 
> -  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
> +  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
>Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
>SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> 
> -
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -
>  #include "BaseUefiDecompressLibInternals.h"
> 
>  /**
>Read NumOfBit of bits from source into mBitBuf.
> 
> @@ -746,15 +739,15 @@ UefiDecompressGetInfo (
>@retval  RETURN_INVALID_PARAMETER
>The source buffer specified by Source is corrupted
>(not in a valid compressed format).
>  **/
>  RETURN_STATUS
> -EFIAPI
> -UefiDecompress (
> +UefiTianoDecompress (
>IN CONST VOID  *Source,
>IN OUT VOID*Destination,
> -  IN OUT VOID*Scratch  OPTIONAL
> +  IN OUT VOID*Scratch,
> +  IN UINT32  Version
>)
>  {
>UINT32   CompSize;
>UINT32   OrigSize;
>SCRATCH_DATA *Sd;
> @@ -784,12 +777,22 @@ UefiDecompress (
>SetMem (Sd, sizeof (SCRATCH_DATA), 0);
> 
>//
>// The length of the field 'Position Set Code Length Array Size' in Block 
> Header.
>// For UEFI 2.0 de/compression algorithm(Version 1), mPBit = 4
> -  //
> -  Sd->mPBit = 4;
> +  // For Tiano de/compression algorithm(Version 2), mPBit = 5
> +  //
> +  switch (Version) {
> +case 1 :
> +  Sd->mPBit = 4;
> +  break;
> +case 2 :
> +  Sd->mPBit = 5;
> +  break;
> +default:
> +  ASSERT (FALSE);
> +  }
>Sd->mSrcBase  = (UINT8 *)Src;
>Sd->mDstBase  = Dst;
>//
>// CompSize and OrigSize are calculated in bytes
>//
> @@ -813,5 +816,45 @@ UefiDecompress (
>  return RETURN_INVALID_PARAMETER;
>}
> 
>return RETURN_SUCCESS;
>  }
> +
> +/**
> +  Decompresses a UEFI compressed source buffer.
> +
> +  Extracts decompressed data to its original form.
> +  This function is designed so that the decompression algorithm can be 
> implemented
> +  without using any memory services.  As a result, this function is not 
> allowed to
> +  call any memory allocation services in its implementation.  It is the 
> caller's
> +  responsibility to allocate and free the Destination and S

[edk2-devel] [patch 1/5] MdePkg: Merge TianoCustomDecompress algorithm into

2019-05-12 Thread Dandan Bi
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1722

We plan to merge the BaseUefiTianoCustomDecompressLib
in MdeModulePkg into the BaseUefDecompressLib in MdePkg.
In order to reduce the duplicated codes and maintain
easily.
This patch adds a new fdf file in BaseUefDecompressLib
(BaseUefiTianoCustomDecompressLib.inf) to keep the same
functionality and usage model with the one in MdeModulePkg,
and then update consumer to use this new one one and
remove the one in MdeModulePkg finally.

Cc: Michael D Kinney 
Cc: Liming Gao 
Signed-off-by: Dandan Bi 
---
 .../BaseUefiDecompressLib.c   |  69 --
 .../BaseUefiDecompressLib.uni |   6 +-
 .../BaseUefiDecompressLibInternals.h  |  44 +++-
 .../BaseUefiTianoCustomDecompressLib.c| 213 ++
 .../BaseUefiTianoCustomDecompressLib.inf  |  42 
 MdePkg/MdePkg.dec |   5 +
 MdePkg/MdePkg.dsc |   1 +
 7 files changed, 363 insertions(+), 17 deletions(-)
 create mode 100644 
MdePkg/Library/BaseUefiDecompressLib/BaseUefiTianoCustomDecompressLib.c
 create mode 100644 
MdePkg/Library/BaseUefiDecompressLib/BaseUefiTianoCustomDecompressLib.inf

diff --git a/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c 
b/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c
index 8e502b0fdb..d2c40bf1ca 100644
--- a/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c
+++ b/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c
@@ -1,21 +1,14 @@
 /** @file
   UEFI Decompress Library implementation refer to UEFI specification.
 
-  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
   Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
 
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
 #include "BaseUefiDecompressLibInternals.h"
 
 /**
   Read NumOfBit of bits from source into mBitBuf.
 
@@ -746,15 +739,15 @@ UefiDecompressGetInfo (
   @retval  RETURN_INVALID_PARAMETER
   The source buffer specified by Source is corrupted
   (not in a valid compressed format).
 **/
 RETURN_STATUS
-EFIAPI
-UefiDecompress (
+UefiTianoDecompress (
   IN CONST VOID  *Source,
   IN OUT VOID*Destination,
-  IN OUT VOID*Scratch  OPTIONAL
+  IN OUT VOID*Scratch,
+  IN UINT32  Version
   )
 {
   UINT32   CompSize;
   UINT32   OrigSize;
   SCRATCH_DATA *Sd;
@@ -784,12 +777,22 @@ UefiDecompress (
   SetMem (Sd, sizeof (SCRATCH_DATA), 0);
 
   //
   // The length of the field 'Position Set Code Length Array Size' in Block 
Header.
   // For UEFI 2.0 de/compression algorithm(Version 1), mPBit = 4
-  //
-  Sd->mPBit = 4;
+  // For Tiano de/compression algorithm(Version 2), mPBit = 5
+  //
+  switch (Version) {
+case 1 :
+  Sd->mPBit = 4;
+  break;
+case 2 :
+  Sd->mPBit = 5;
+  break;
+default:
+  ASSERT (FALSE);
+  }
   Sd->mSrcBase  = (UINT8 *)Src;
   Sd->mDstBase  = Dst;
   //
   // CompSize and OrigSize are calculated in bytes
   //
@@ -813,5 +816,45 @@ UefiDecompress (
 return RETURN_INVALID_PARAMETER;
   }
 
   return RETURN_SUCCESS;
 }
+
+/**
+  Decompresses a UEFI compressed source buffer.
+
+  Extracts decompressed data to its original form.
+  This function is designed so that the decompression algorithm can be 
implemented
+  without using any memory services.  As a result, this function is not 
allowed to
+  call any memory allocation services in its implementation.  It is the 
caller's
+  responsibility to allocate and free the Destination and Scratch buffers.
+  If the compressed source data specified by Source is successfully 
decompressed
+  into Destination, then RETURN_SUCCESS is returned.  If the compressed source 
data
+  specified by Source is not in a valid compressed data format,
+  then RETURN_INVALID_PARAMETER is returned.
+
+  If Source is NULL, then ASSERT().
+  If Destination is NULL, then ASSERT().
+  If the required scratch buffer size > 0 and Scratch is NULL, then ASSERT().
+
+  @param  Source  The source buffer containing the compressed data.
+  @param  Destination The destination buffer to store the decompressed data
+  @param  Scratch A temporary scratch buffer that is used to perform the 
decompression.
+  This is an optional parameter that may be NULL if the
+  required scratch buffer size is 0.
+
+  @retval  RETURN_SUCCESS Decompression completed successfully, and
+  the uncompressed buffer is returned in Destination.
+  @retval  RETURN_INVALID_PARAMETER
+  The source buffer specified by Source is corrupted
+  (not in a valid compressed format).
+**/
+RETURN_STATUS
+EFIAPI
+UefiDecompress (
+  IN CONST VOID  *Source,
+  IN