]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1, Use PrintLib in Duet loader
authorklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 25 Apr 2008 09:30:24 +0000 (09:30 +0000)
committerklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 25 Apr 2008 09:30:24 +0000 (09:30 +0000)
2, Fix missing compress image in final disk image. I think the raw disk image had better be organized as our FD image format. I will discuss this after enabling DUET for R9.
3, Add more debug output in loader.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5128 6f19259b-4bc3-4df7-8a09-765794883524

DuetPkg/BootSector/Makefile
DuetPkg/DuetPkg.dsc
DuetPkg/EfiLdr/EfiLdr.h
DuetPkg/EfiLdr/EfiLdr.inf
DuetPkg/EfiLdr/EfiLoader.c
DuetPkg/EfiLdr/PeLoader.c
DuetPkg/EfiLdr/TianoDecompress.c
DuetPkg/EfiLdr/TianoDecompress.h
DuetPkg/PostBuild.bat

index cfb2a5faf5ca5d1e11d754deaf08f948aca665a0..e88743d1cf5202729d1a36798cf7af56d8a20dc6 100644 (file)
@@ -126,7 +126,7 @@ $(BUILD_DIR)\FV\DxeIpl.z:$(BUILD_DIR)\IA32\DxeIpl.efi
   $(BASETOOLS_DIR)\TianoCompress -e -o $(BUILD_DIR)\FV\DxeIpl.z $(BUILD_DIR)\IA32\DxeIpl.efi\r
     \r
 $(BUILD_DIR)\FV\Efildr32:$(BUILD_DIR)\IA32\EfiLoader.efi $(BUILD_DIR)\FV\DxeIpl.z $(BUILD_DIR)\FV\DUETEFIMAINFV.z\r
-  $(BASETOOLS_DIR)\EfiLdrImage.exe -o $(BUILD_DIR)\FV\Efildr32 $(BUILD_DIR)\IA32\EfiLoader.efi $(BUILD_DIR)\FV\DxeIpl.z $(BUILD_DIR)\FV\DUETEFIMAINFV.z\r
+  $(BASETOOLS_DIR)\EfiLdrImage.exe -o $(BUILD_DIR)\FV\Efildr32 $(BUILD_DIR)\IA32\EfiLoader.efi $(BUILD_DIR)\FV\DxeIpl.z $(BUILD_DIR)\FV\DxeMain.z $(BUILD_DIR)\FV\DUETEFIMAINFV.z\r
   \r
 $(BUILD_DIR)\FV\Efildr:$(OUTPUT_DIR)\Start.com $(OUTPUT_DIR)\Efi32.com2 $(BUILD_DIR)\FV\Efildr32\r
   copy /b $(OUTPUT_DIR)\Start.com+$(OUTPUT_DIR)\Efi32.com2+$(BUILD_DIR)\FV\Efildr32 $(BUILD_DIR)\FV\Efildr\r
index e1ee50a1f7580d059a6f6f15e72d1fa39530fa7c..8154f1cd9b48e946159a7a10b7b04ed6cdd442b5 100644 (file)
@@ -47,6 +47,7 @@
   CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf\r
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf\r
   OemHookStatusCodeLib|IntelFrameworkModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf\r
+  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf\r
 \r
 [LibraryClasses.common.DXE_DRIVER]\r
   MemoryAllocationLib|MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf\r
index b1d0e1c2724350a250f6f13037fb441127ce8608..1417b761c6770988a3dc54e2fd20756f8985a2ab 100644 (file)
@@ -30,6 +30,7 @@ Revision History:
 #include <IndustryStandard/PeImage.h>\r
 #include <Library/BaseLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
+#include <Library/PrintLib.h>\r
 \r
 #define INT15_E820_AddressRangeMemory   1\r
 #define INT15_E820_AddressRangeReserved 2\r
@@ -80,28 +81,6 @@ typedef struct {
   BIOS_MEMORY_MAP_ENTRY MemoryMapEntry[1];\r
 } BIOS_MEMORY_MAP;\r
 \r
-EFI_STATUS\r
-EFIAPI\r
-UefiDecompressGetInfo (\r
-  IN      EFI_TIANO_DECOMPRESS_PROTOCOL *This,\r
-  IN      VOID                          *Source,\r
-  IN      UINT32                        SrcSize,\r
-  OUT     UINT32                        *DstSize,\r
-  OUT     UINT32                        *ScratchSize\r
-  );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-TianoDecompress (\r
-  IN      EFI_TIANO_DECOMPRESS_PROTOCOL *This,\r
-  IN      VOID                          *Source,\r
-  IN      UINT32                        SrcSize,\r
-  IN OUT  VOID                          *Destination,\r
-  IN      UINT32                        DstSize,\r
-  IN OUT  VOID                          *Scratch,\r
-  IN      UINT32                        ScratchSize\r
-  );\r
-\r
 EFILDR_LOADED_IMAGE    DxeCoreImage;\r
 EFILDR_LOADED_IMAGE    DxeIplImage;\r
 \r
index 4d980bca72ad6aed9dae747fb4c68c8fa955f041..5e9b676ed9afaa3f7233ae413263923d8c2bd2d4 100644 (file)
@@ -37,6 +37,7 @@
   BaseLib\r
   BaseMemoryLib\r
   UefiApplicationEntryPoint\r
+  PrintLib\r
 \r
 [Sources.common]\r
   Debug.h\r
index 382b7802a19d5186be02831646f0f88f01340e85..c8c749ba4d0941ba6d83c6cf6ac50c0b3ba7d4d4 100644 (file)
@@ -22,6 +22,18 @@ Revision History:
 #include "Support.h"\r
 #include "Debug.h"\r
 #include "PeLoader.h"\r
+#include "TianoDecompress.h"\r
+\r
+STATIC\r
+VOID\r
+SystemHang(\r
+  VOID\r
+  )\r
+{\r
+  CHAR8 PrintBuffer[256];\r
+  AsciiSPrint (PrintBuffer, 256, "## FATEL ERROR ##: Fail to load DUET images! System hang!\n");\r
+  CpuDeadLoop();\r
+}\r
 \r
 VOID\r
 EfiLoader (\r
@@ -39,18 +51,18 @@ EfiLoader (
   UINTN                 BfvPageNumber;\r
   UINTN                 BfvBase;\r
   EFI_MAIN_ENTRYPOINT   EfiMainEntrypoint;\r
+  CHAR8                 PrintBuffer[256];\r
   static EFILDRHANDOFF  Handoff;\r
 \r
-PrintHeader ('A');\r
-\r
   ClearScreen();\r
-  PrintString("EFI Loader\n");\r
+  \r
+  PrintHeader ('A');\r
 \r
-//  PrintString("&BiosMemoryMapBaseAddress = ");   \r
-//  PrintValue64 ((UINT64)(&BiosMemoryMapBaseAddress));\r
-//  PrintString("  BiosMemoryMapBaseAddress = ");   \r
-//  PrintValue(BiosMemoryMapBaseAddress);\r
-//  PrintString("\n");\r
+  AsciiSPrint (PrintBuffer, 256, "Enter DUET Loader ...\n", BiosMemoryMapBaseAddress);\r
+  PrintString (PrintBuffer);\r
+\r
+  AsciiSPrint (PrintBuffer, 256, "BiosMemoryMapBaseAddress = 0x%x\n", BiosMemoryMapBaseAddress);\r
+  PrintString (PrintBuffer);\r
 \r
   //\r
   // Add all EfiConventionalMemory descriptors to the table.  If there are partial pages, then\r
@@ -60,6 +72,9 @@ PrintHeader ('A');
   NumberOfMemoryMapEntries = 0;\r
   GenMemoryMap (&NumberOfMemoryMapEntries, EfiMemoryDescriptor, BiosMemoryMap);\r
 \r
+  AsciiSPrint (PrintBuffer, 256, "Get %d entries of memory map!\n", NumberOfMemoryMapEntries);\r
+  PrintString (PrintBuffer);\r
+\r
   //\r
   // Get information on where the image is in memory\r
   //\r
@@ -67,7 +82,6 @@ PrintHeader ('A');
   EFILDRHeader = (EFILDR_HEADER *)(UINTN)(EFILDR_HEADER_ADDRESS);\r
   EFILDRImage  = (EFILDR_IMAGE *)(UINTN)(EFILDR_HEADER_ADDRESS + sizeof(EFILDR_HEADER));\r
 \r
-PrintHeader ('D');\r
 \r
   //\r
   // Point to the 4th image (Bfv)\r
@@ -79,19 +93,25 @@ PrintHeader ('D');
   // Decompress the image\r
   //\r
 \r
-  Status = UefiDecompressGetInfo (\r
-             NULL, \r
+  AsciiSPrint (PrintBuffer, 256, "Decompress BFV image, Image Address=0x%x! Offset=0x%x\n", \r
+               (UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
+               EFILDRImage->Offset);\r
+  PrintString (PrintBuffer);\r
+\r
+  Status = TianoGetInfo (\r
              (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
              EFILDRImage->Length,\r
              &DestinationSize, \r
              &ScratchSize\r
              );\r
+\r
   if (EFI_ERROR (Status)) {\r
-    CpuDeadLoop();\r
+    AsciiSPrint (PrintBuffer, 256, "Fail to get decompress information for BFV!\n");\r
+    PrintString (PrintBuffer);\r
+    SystemHang();\r
   }\r
 \r
   Status = TianoDecompress (\r
-             NULL, \r
              (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
              EFILDRImage->Length,\r
              (VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS,\r
@@ -99,19 +119,22 @@ PrintHeader ('D');
              (VOID *)(UINTN)((EFI_DECOMPRESSED_BUFFER_ADDRESS + DestinationSize + 0x1000) & 0xfffff000),\r
              ScratchSize\r
              );\r
+\r
   if (EFI_ERROR (Status)) {\r
-    CpuDeadLoop();\r
+    AsciiSPrint (PrintBuffer, 256, "Fail to decompress BFV!\n");\r
+    PrintString (PrintBuffer);\r
+    SystemHang();\r
   }\r
 \r
   BfvPageNumber = EFI_SIZE_TO_PAGES (DestinationSize);\r
   BfvBase = (UINTN) FindSpace (BfvPageNumber, &NumberOfMemoryMapEntries, EfiMemoryDescriptor, EfiRuntimeServicesData, EFI_MEMORY_WB);\r
   if (BfvBase == 0) {\r
-    CpuDeadLoop();\r
+    SystemHang();\r
   }\r
   ZeroMem ((VOID *)(UINTN)BfvBase, BfvPageNumber * EFI_PAGE_SIZE);\r
   CopyMem ((VOID *)(UINTN)BfvBase, (VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS, DestinationSize);\r
 \r
-PrintHeader ('B');\r
+  PrintHeader ('B');\r
 \r
   //\r
   // Point to the 2nd image (DxeIpl)\r
@@ -122,20 +145,23 @@ PrintHeader ('B');
   //\r
   // Decompress the image\r
   //\r
+  AsciiSPrint (PrintBuffer, 256, "Decompress DxeIpl image, Image Address=0x%x! Offset=0x%x\n", \r
+               (UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
+               EFILDRImage->Offset);\r
 \r
-  Status = UefiDecompressGetInfo (\r
-             NULL, \r
+  Status = TianoGetInfo (\r
              (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
              EFILDRImage->Length,\r
              &DestinationSize, \r
              &ScratchSize\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    CpuDeadLoop();\r
+    AsciiSPrint (PrintBuffer, 256, "Fail to get decompress information for DxeIpl!\n");\r
+    PrintString (PrintBuffer);\r
+    SystemHang();\r
   }\r
 \r
   Status = TianoDecompress (\r
-             NULL, \r
              (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
              EFILDRImage->Length,\r
              (VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS,\r
@@ -144,9 +170,14 @@ PrintHeader ('B');
              ScratchSize\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    CpuDeadLoop();\r
+    AsciiSPrint (PrintBuffer, 256, "Fail to decompress DxeIpl image\n");\r
+    PrintString (PrintBuffer);\r
+    SystemHang();\r
   }\r
 \r
+  AsciiSPrint (PrintBuffer, 256, "Start load DxeIpl PE image\n");\r
+  PrintString (PrintBuffer);  \r
+\r
   //\r
   // Load and relocate the EFI PE/COFF Firmware Image \r
   //\r
@@ -157,7 +188,9 @@ PrintHeader ('B');
              EfiMemoryDescriptor\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    CpuDeadLoop();\r
+    AsciiSPrint (PrintBuffer, 256, "Fail to load and relocate DxeIpl PE image!\n");\r
+    PrintString (PrintBuffer);\r
+    SystemHang();\r
   }\r
 \r
 //  PrintString("Image.NoPages = ");   \r
@@ -176,19 +209,17 @@ PrintHeader ('C');
   // Decompress the image\r
   //\r
 \r
-  Status = UefiDecompressGetInfo (\r
-             NULL, \r
+  Status = TianoGetInfo (\r
              (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
              EFILDRImage->Length,\r
              &DestinationSize, \r
              &ScratchSize\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    CpuDeadLoop();\r
+    SystemHang();\r
   }\r
 \r
   Status = TianoDecompress (\r
-             NULL, \r
              (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
              EFILDRImage->Length,\r
              (VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS,\r
@@ -197,7 +228,7 @@ PrintHeader ('C');
              ScratchSize\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    CpuDeadLoop();\r
+    SystemHang();\r
   }\r
 \r
   //\r
@@ -210,7 +241,7 @@ PrintHeader ('C');
              EfiMemoryDescriptor\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    CpuDeadLoop();\r
+    SystemHang();\r
   }\r
 \r
 PrintHeader ('E');\r
@@ -261,6 +292,6 @@ PrintHeader ('F');
   // There was a problem loading the image, so HALT the system.\r
   //\r
 \r
-  CpuDeadLoop();\r
+  SystemHang();\r
 }\r
 \r
index 73608da1611636aef5d9f5a9b0e354784978f410..e5b6d931469e32623b95d021c1fe20b7e9c64e0d 100644 (file)
@@ -138,6 +138,7 @@ EfiLdrPeCoffLoadPeImage (
   UINT32                          NumberOfRvaAndSizes;\r
   EFI_IMAGE_DATA_DIRECTORY        *DataDirectory;\r
   UINT64                          ImageBase;\r
+  CHAR8                           PrintBuffer[256];\r
 \r
   ZeroMem (&DosHdr, sizeof(DosHdr));\r
   ZeroMem (&PeHdr, sizeof(PeHdr));\r
@@ -148,16 +149,18 @@ EfiLdrPeCoffLoadPeImage (
 \r
   EfiLdrPeCoffImageRead (FHand, 0, sizeof(DosHdr), &DosHdr);\r
   if (DosHdr.e_magic != EFI_IMAGE_DOS_SIGNATURE) {\r
-//    DEBUG ((D_LOAD, "PeCoffLoadPeImage: Dos header signature not found\n"));\r
-PrintHeader ('F');\r
+    AsciiSPrint (PrintBuffer, 256, "PeCoffLoadPeImage: Dos header signature not found\n");\r
+    PrintString (PrintBuffer);\r
+    PrintHeader ('F');\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
   EfiLdrPeCoffImageRead (FHand, DosHdr.e_lfanew, sizeof(PeHdr), &PeHdr);\r
 \r
   if (PeHdr.Pe32.Signature != EFI_IMAGE_NT_SIGNATURE) {\r
-//    DEBUG ((D_LOAD, "PeCoffLoadPeImage: PE image header signature not found\n"));\r
-PrintHeader ('G');\r
+    AsciiSPrint (PrintBuffer, 256, "PeCoffLoadPeImage: PE image header signature not found\n");\r
+    PrintString (PrintBuffer);\r
+    PrintHeader ('G');\r
     return EFI_UNSUPPORTED;\r
   }\r
     \r
@@ -167,8 +170,9 @@ PrintHeader ('G');
 \r
   Status = EfiLdrPeCoffSetImageType (Image, PeHdr.Pe32.OptionalHeader.Subsystem);\r
   if (EFI_ERROR(Status)) {\r
-//    DEBUG ((D_LOAD, "PeCoffLoadPeImage: Subsystem type not known\n"));\r
-PrintHeader ('H');\r
+    AsciiSPrint (PrintBuffer, 256, "PeCoffLoadPeImage: Subsystem type not known\n");\r
+    PrintString (PrintBuffer);\r
+    PrintHeader ('H');\r
     return Status;\r
   }\r
 \r
@@ -178,8 +182,9 @@ PrintHeader ('H');
 \r
   Status = EfiLdrPeCoffCheckImageMachineType (PeHdr.Pe32.FileHeader.Machine);\r
   if (EFI_ERROR(Status)) {\r
-//    DEBUG ((D_LOAD, "PeCoffLoadPeImage: Incorrect machine type\n"));\r
-PrintHeader ('I');\r
+    AsciiSPrint (PrintBuffer, 256, "PeCoffLoadPeImage: Incorrect machine type\n");\r
+    PrintString (PrintBuffer);\r
+    PrintHeader ('I');\r
     return Status;\r
   }\r
 \r
@@ -232,11 +237,12 @@ PrintHeader ('I');
   }\r
 \r
   if (EFI_ERROR(Status)) {\r
-PrintHeader ('J');\r
+    PrintHeader ('J');\r
     return Status;\r
   }\r
 \r
-//  DEBUG((D_LOAD, "LoadPe: new image base %lx\n", Image->ImageBasePage));\r
+  AsciiSPrint (PrintBuffer, 256, "LoadPe: new image base %lx\n", Image->ImageBasePage);\r
+  PrintString (PrintBuffer);\r
   Image->Info.ImageBase = (VOID *)(UINTN)Image->ImageBasePage;\r
   Image->Info.ImageSize = (Image->NoPages << EFI_PAGE_SHIFT) - 1;\r
   Image->ImageBase      = (UINT8 *)(UINTN)Image->ImageBasePage;\r
@@ -254,7 +260,7 @@ PrintHeader ('J');
              );\r
 \r
   if (EFI_ERROR(Status)) {\r
-PrintHeader ('K');\r
+    PrintHeader ('K');\r
     return Status;\r
   }\r
 \r
@@ -319,7 +325,7 @@ PrintHeader ('K');
         \r
     if (EFI_ERROR(Status) || !Base || !End) {\r
 //      DEBUG((D_LOAD|D_ERROR, "LoadPe: Section %d was not loaded\n", Index));\r
-PrintHeader ('L');\r
+    PrintHeader ('L');\r
       return EFI_LOAD_ERROR;\r
     }\r
 \r
@@ -381,7 +387,7 @@ PrintHeader ('M');
                );\r
 \r
     if (EFI_ERROR(Status)) {\r
-PrintHeader ('N');\r
+      PrintHeader ('N');\r
       return Status;\r
     }\r
   }\r
index d020c6a7b77ef7bfd3892009c9d09029e7d80bc3..9a9ab70be449380881cccec0717fd7eece9765cb 100644 (file)
@@ -1,10 +1,6 @@
-/**@file\r
-  UEFI and Custom Decompress Library \r
-  The function of UefiTianoDecompress() is interface for this module,\r
-  it will do tiano or uefi decompress with different verison parameter.\r
-  See EFI specification 1.1 Chapter 17 to get LZ77 compress/decompress.\r
-  \r
-Copyright (c) 2006, Intel Corporation                                                         \r
+/*++\r
+\r
+Copyright (c) 2004 - 2006, Intel Corporation                                                         \r
 All rights reserved. This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
@@ -13,22 +9,91 @@ http://opensource.org/licenses/bsd-license.php
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
 \r
-**/\r
+Module Name:\r
 \r
-#include <Guid/CustomDecompress.h>\r
-#include "TianoDecompress.h"\r
+  Decompress.c\r
 \r
-/**\r
-  Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.\r
+Abstract:\r
+\r
+  Decompressor. Algorithm Ported from OPSD code (Decomp.asm)\r
   \r
-  @param Sd         The global scratch data\r
-  @param NumOfBits  The number of bits to shift and read.  \r
-**/\r
+--*/\r
+#include <TianoDecompress.h>\r
+//\r
+// Decompression algorithm begins here\r
+//\r
+#define BITBUFSIZ 32\r
+#define MAXMATCH  256\r
+#define THRESHOLD 3\r
+#define CODE_BIT  16\r
+#define UINT8_MAX 0xff\r
+#define BAD_TABLE - 1\r
+\r
+//\r
+// C: Char&Len Set; P: Position Set; T: exTra Set\r
+//\r
+#define NC      (0xff + MAXMATCH + 2 - THRESHOLD)\r
+#define CBIT    9\r
+#define MAXPBIT 5\r
+#define TBIT    5\r
+#define MAXNP   ((1U << MAXPBIT) - 1)\r
+#define NT      (CODE_BIT + 3)\r
+#if NT > MAXNP\r
+#define NPT NT\r
+#else\r
+#define NPT MAXNP\r
+#endif\r
+\r
+typedef struct {\r
+  UINT8   *mSrcBase;  // Starting address of compressed data\r
+  UINT8   *mDstBase;  // Starting address of decompressed data\r
+  UINT32  mOutBuf;\r
+  UINT32  mInBuf;\r
+\r
+  UINT16  mBitCount;\r
+  UINT32  mBitBuf;\r
+  UINT32  mSubBitBuf;\r
+  UINT16  mBlockSize;\r
+  UINT32  mCompSize;\r
+  UINT32  mOrigSize;\r
+\r
+  UINT16  mBadTableFlag;\r
+\r
+  UINT16  mLeft[2 * NC - 1];\r
+  UINT16  mRight[2 * NC - 1];\r
+  UINT8   mCLen[NC];\r
+  UINT8   mPTLen[NPT];\r
+  UINT16  mCTable[4096];\r
+  UINT16  mPTTable[256];\r
+\r
+  //\r
+  // The length of the field 'Position Set Code Length Array Size' in Block Header.\r
+  // For EFI 1.1 de/compression algorithm, mPBit = 4\r
+  // For Tiano de/compression algorithm, mPBit = 5\r
+  //\r
+  UINT8   mPBit;\r
+} SCRATCH_DATA;\r
+\r
+STATIC\r
 VOID\r
 FillBuf (\r
   IN  SCRATCH_DATA  *Sd,\r
   IN  UINT16        NumOfBits\r
   )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.\r
+\r
+Arguments:\r
+\r
+  Sd        - The global scratch data\r
+  NumOfBits  - The number of bits to shift and read.\r
+\r
+Returns: (VOID)\r
+\r
+--*/\r
 {\r
   Sd->mBitBuf = (UINT32) (Sd->mBitBuf << NumOfBits);\r
 \r
@@ -59,24 +124,30 @@ FillBuf (
   Sd->mBitBuf |= Sd->mSubBitBuf >> Sd->mBitCount;\r
 }\r
 \r
-/**\r
-  Get NumOfBits of bits out from mBitBuf\r
+STATIC\r
+UINT32\r
+GetBits (\r
+  IN  SCRATCH_DATA  *Sd,\r
+  IN  UINT16        NumOfBits\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
 \r
   Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent \r
   NumOfBits of bits from source. Returns NumOfBits of bits that are \r
   popped out.\r
 \r
-  @param  Sd        The global scratch data.\r
-  @param  NumOfBits The number of bits to pop and read.\r
+Arguments:\r
 \r
-  @return The bits that are popped out.\r
+  Sd            - The global scratch data.\r
+  NumOfBits     - The number of bits to pop and read.\r
 \r
-**/\r
-UINT32\r
-GetBits (\r
-  IN  SCRATCH_DATA  *Sd,\r
-  IN  UINT16        NumOfBits\r
-  )\r
+Returns:\r
+\r
+  The bits that are popped out.\r
+\r
+--*/\r
 {\r
   UINT32  OutBits;\r
 \r
@@ -87,22 +158,7 @@ GetBits (
   return OutBits;\r
 }\r
 \r
-/**\r
-  Creates Huffman Code mapping table according to code length array.\r
-\r
-  Creates Huffman Code mapping table for Extra Set, Char&Len Set \r
-  and Position Set according to code length array.\r
-\r
-  @param  Sd        The global scratch data\r
-  @param  NumOfChar Number of symbols in the symbol set\r
-  @param  BitLen    Code length array\r
-  @param  TableBits The width of the mapping table\r
-  @param  Table     The table\r
-\r
-  @retval  0 OK.\r
-  @retval  BAD_TABLE The table is corrupted.\r
-\r
-**/\r
+STATIC\r
 UINT16\r
 MakeTable (\r
   IN  SCRATCH_DATA  *Sd,\r
@@ -111,21 +167,39 @@ MakeTable (
   IN  UINT16        TableBits,\r
   OUT UINT16        *Table\r
   )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Creates Huffman Code mapping table according to code length array.\r
+\r
+Arguments:\r
+\r
+  Sd        - The global scratch data\r
+  NumOfChar - Number of symbols in the symbol set\r
+  BitLen    - Code length array\r
+  TableBits - The width of the mapping table\r
+  Table     - The table\r
+  \r
+Returns:\r
+  \r
+  0         - OK.\r
+  BAD_TABLE - The table is corrupted.\r
+\r
+--*/\r
 {\r
   UINT16  Count[17];\r
   UINT16  Weight[17];\r
   UINT16  Start[18];\r
   UINT16  *Pointer;\r
   UINT16  Index3;\r
-  volatile UINT16  Index;\r
+  UINT16  Index;\r
   UINT16  Len;\r
   UINT16  Char;\r
   UINT16  JuBits;\r
   UINT16  Avail;\r
   UINT16  NextCode;\r
   UINT16  Mask;\r
-  UINT16  WordOfStart;\r
-  UINT16  WordOfCount;\r
 \r
   for (Index = 1; Index <= 16; Index++) {\r
     Count[Index] = 0;\r
@@ -138,9 +212,7 @@ MakeTable (
   Start[1] = 0;\r
 \r
   for (Index = 1; Index <= 16; Index++) {\r
-    WordOfStart = Start[Index];\r
-    WordOfCount = Count[Index];\r
-    Start[Index + 1] = (UINT16) (WordOfStart + (WordOfCount << (16 - Index)));\r
+    Start[Index + 1] = (UINT16) (Start[Index] + (Count[Index] << (16 - Index)));\r
   }\r
 \r
   if (Start[17] != 0) {\r
@@ -156,8 +228,7 @@ MakeTable (
   }\r
 \r
   while (Index <= 16) {\r
-    Weight[Index] = (UINT16) (1U << (16 - Index));\r
-    Index++;\r
+    Weight[Index++] = (UINT16) (1U << (16 - Index));\r
   }\r
 \r
   Index = (UINT16) (Start[TableBits + 1] >> JuBits);\r
@@ -221,17 +292,26 @@ MakeTable (
   return 0;\r
 }\r
 \r
-/**\r
-  Decodes a position value.\r
-  \r
-  @param Sd      the global scratch data\r
-  \r
-  @return The position value decoded.\r
-**/\r
+STATIC\r
 UINT32\r
 DecodeP (\r
   IN  SCRATCH_DATA  *Sd\r
   )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Decodes a position value.\r
+\r
+Arguments:\r
+\r
+  Sd      - the global scratch data\r
+\r
+Returns:\r
+\r
+  The position value decoded.\r
+\r
+--*/\r
 {\r
   UINT16  Val;\r
   UINT32  Mask;\r
@@ -266,21 +346,7 @@ DecodeP (
   return Pos;\r
 }\r
 \r
-/**\r
-  Reads code lengths for the Extra Set or the Position Set.\r
-\r
-  Read in the Extra Set or Pointion Set Length Arrary, then\r
-  generate the Huffman code mapping for them.\r
-\r
-  @param  Sd      The global scratch data.\r
-  @param  nn      Number of symbols.\r
-  @param  nbit    Number of bits needed to represent nn.\r
-  @param  Special The special symbol that needs to be taken care of.\r
-\r
-  @retval  0 OK.\r
-  @retval  BAD_TABLE Table is corrupted.\r
-\r
-**/\r
+STATIC\r
 UINT16\r
 ReadPTLen (\r
   IN  SCRATCH_DATA  *Sd,\r
@@ -288,10 +354,29 @@ ReadPTLen (
   IN  UINT16        nbit,\r
   IN  UINT16        Special\r
   )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Reads code lengths for the Extra Set or the Position Set\r
+\r
+Arguments:\r
+\r
+  Sd        - The global scratch data\r
+  nn        - Number of symbols\r
+  nbit      - Number of bits needed to represent nn\r
+  Special   - The special symbol that needs to be taken care of \r
+\r
+Returns:\r
+\r
+  0         - OK.\r
+  BAD_TABLE - Table is corrupted.\r
+\r
+--*/\r
 {\r
   UINT16  Number;\r
   UINT16  CharC;\r
-  volatile UINT16  Index;\r
+  UINT16  Index;\r
   UINT32  Mask;\r
 \r
   Number = (UINT16) GetBits (Sd, nbit);\r
@@ -343,23 +428,28 @@ ReadPTLen (
   return MakeTable (Sd, nn, Sd->mPTLen, 8, Sd->mPTTable);\r
 }\r
 \r
-/**\r
-  Reads code lengths for Char&Len Set.\r
-  \r
-  Read in and decode the Char&Len Set Code Length Array, then\r
-  generate the Huffman Code mapping table for the Char&Len Set.\r
-\r
-  @param  Sd the global scratch data\r
-\r
-**/\r
+STATIC\r
 VOID\r
 ReadCLen (\r
   SCRATCH_DATA  *Sd\r
   )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Reads code lengths for Char&Len Set.\r
+\r
+Arguments:\r
+\r
+  Sd    - the global scratch data\r
+\r
+Returns: (VOID)\r
+\r
+--*/\r
 {\r
   UINT16  Number;\r
   UINT16  CharC;\r
-  volatile UINT16  Index;\r
+  UINT16  Index;\r
   UINT32  Mask;\r
 \r
   Number = (UINT16) GetBits (Sd, CBIT);\r
@@ -432,22 +522,26 @@ ReadCLen (
   return ;\r
 }\r
 \r
-/**\r
-  Decode a character/length value.\r
-  \r
-  Read one value from mBitBuf, Get one code from mBitBuf. If it is at block boundary, generates\r
-  Huffman code mapping table for Extra Set, Code&Len Set and\r
-  Position Set.\r
-\r
-  @param  Sd The global scratch data.\r
-\r
-  @return The value decoded.\r
-\r
-**/\r
+STATIC\r
 UINT16\r
 DecodeC (\r
   SCRATCH_DATA  *Sd\r
   )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Decode a character/length value.\r
+\r
+Arguments:\r
+\r
+  Sd    - The global scratch data.\r
+\r
+Returns:\r
+\r
+  The value decoded.\r
+\r
+--*/\r
 {\r
   UINT16  Index2;\r
   UINT32  Mask;\r
@@ -494,15 +588,24 @@ DecodeC (
   return Index2;\r
 }\r
 \r
-/**\r
-  Decode the source data ad put the resulting data into the destination buffer.\r
-  \r
-  @param Sd            - The global scratch data\r
-**/\r
+STATIC\r
 VOID\r
 Decode (\r
   SCRATCH_DATA  *Sd\r
   )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Decode the source data and put the resulting data into the destination buffer.\r
+\r
+Arguments:\r
+\r
+  Sd            - The global scratch data\r
+\r
+Returns: (VOID)\r
+\r
+ --*/\r
 {\r
   UINT16  BytesRemain;\r
   UINT32  DataIdx;\r
@@ -515,7 +618,7 @@ Decode (
   for (;;) {\r
     CharC = DecodeC (Sd);\r
     if (Sd->mBadTableFlag != 0) {\r
-      goto Done ;\r
+      return ;\r
     }\r
 \r
     if (CharC < 256) {\r
@@ -523,7 +626,7 @@ Decode (
       // Process an Original character\r
       //\r
       if (Sd->mOutBuf >= Sd->mOrigSize) {\r
-        goto Done ;\r
+        return ;\r
       } else {\r
         Sd->mDstBase[Sd->mOutBuf++] = (UINT8) CharC;\r
       }\r
@@ -542,7 +645,7 @@ Decode (
       while ((INT16) (BytesRemain) >= 0) {\r
         Sd->mDstBase[Sd->mOutBuf++] = Sd->mDstBase[DataIdx++];\r
         if (Sd->mOutBuf >= Sd->mOrigSize) {\r
-          goto Done ;\r
+          return ;\r
         }\r
 \r
         BytesRemain--;\r
@@ -550,87 +653,106 @@ Decode (
     }\r
   }\r
 \r
-Done:\r
   return ;\r
 }\r
 \r
-/**\r
-  The internal implementation of *_DECOMPRESS_PROTOCOL.GetInfo().\r
-  \r
-  @param Source           The source buffer containing the compressed data.\r
-  @param SourceSize       The size of source buffer\r
-  @param DestinationSize  The size of destination buffer.\r
-  @param ScratchSize      The size of scratch buffer.\r
-\r
-  @retval RETURN_SUCCESS           - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
-  @retval RETURN_INVALID_PARAMETER - The source data is corrupted\r
-**/\r
-RETURN_STATUS\r
-EFIAPI\r
-UefiDecompressGetInfo (\r
-  IN  CONST VOID  *Source,\r
-  IN  UINT32      SourceSize,\r
-  OUT UINT32      *DestinationSize,\r
-  OUT UINT32      *ScratchSize\r
+EFI_STATUS\r
+GetInfo (\r
+  IN      VOID    *Source,\r
+  IN      UINT32  SrcSize,\r
+  OUT     UINT32  *DstSize,\r
+  OUT     UINT32  *ScratchSize\r
   )\r
-{\r
-  UINT32  CompressedSize;\r
+/*++\r
 \r
-  ASSERT (Source != NULL);\r
-  ASSERT (DestinationSize != NULL);\r
-  ASSERT (ScratchSize != NULL);\r
+Routine Description:\r
 \r
-  if (SourceSize < 8) {\r
-    return RETURN_INVALID_PARAMETER;\r
-  }\r
+  The internal implementation of *_DECOMPRESS_PROTOCOL.GetInfo().\r
 \r
-  CompressedSize   = *(UINT32 *) Source;\r
-  if (SourceSize < (CompressedSize + 8)) {\r
-    return RETURN_INVALID_PARAMETER;\r
-  }\r
+Arguments:\r
+\r
+  Source      - The source buffer containing the compressed data.\r
+  SrcSize     - The size of source buffer\r
+  DstSize     - The size of destination buffer.\r
+  ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
+  EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+{\r
+  UINT8 *Src;\r
 \r
   *ScratchSize  = sizeof (SCRATCH_DATA);\r
-  *DestinationSize = *((UINT32 *) Source + 1);\r
 \r
-  return RETURN_SUCCESS;\r
+  Src           = Source;\r
+  if (SrcSize < 8) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *DstSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);\r
+  return EFI_SUCCESS;\r
 }\r
 \r
-/**\r
+EFI_STATUS\r
+Decompress (\r
+  IN      VOID    *Source,\r
+  IN      UINT32  SrcSize,\r
+  IN OUT  VOID    *Destination,\r
+  IN      UINT32  DstSize,\r
+  IN OUT  VOID    *Scratch,\r
+  IN      UINT32  ScratchSize,\r
+  IN      UINT8   Version\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
   The internal implementation of *_DECOMPRESS_PROTOCOL.Decompress().\r
 \r
-  @param Source           The source buffer containing the compressed data.\r
-  @param Destination      The destination buffer to store the decompressed data\r
-  @param Scratch          The buffer used internally by the decompress routine. This  buffer is needed to store intermediate data.\r
-  @param Version          1 for UEFI Decompress algoruthm, 2 for Tiano Decompess algorithm\r
+Arguments:\r
 \r
-  @retval RETURN_SUCCESS            Decompression is successfull\r
-  @retval RETURN_INVALID_PARAMETER  The source data is corrupted\r
-**/\r
-RETURN_STATUS\r
-EFIAPI\r
-UefiTianoDecompress (\r
-  IN CONST VOID  *Source,\r
-  IN OUT VOID    *Destination,\r
-  IN OUT VOID    *Scratch,\r
-  IN UINT32      Version\r
-  )\r
-{\r
-  volatile UINT32  Index;\r
-  UINT32           CompSize;\r
-  UINT32           OrigSize;\r
-  SCRATCH_DATA     *Sd;\r
-  CONST UINT8      *Src;\r
-  UINT8            *Dst;\r
+  Source      - The source buffer containing the compressed data.\r
+  SrcSize     - The size of source buffer\r
+  Destination - The destination buffer to store the decompressed data\r
+  DstSize     - The size of destination buffer.\r
+  Scratch     - The buffer used internally by the decompress routine. This  buffer is needed to store intermediate data.\r
+  ScratchSize - The size of scratch buffer.\r
+  Version     - The version of de/compression algorithm.\r
+                Version 1 for EFI 1.1 de/compression algorithm.\r
+                Version 2 for Tiano de/compression algorithm.\r
+\r
+Returns:\r
 \r
-  ASSERT (Source != NULL);\r
-  ASSERT (Destination != NULL);\r
-  ASSERT (Scratch != NULL);\r
+  EFI_SUCCESS           - Decompression is successfull\r
+  EFI_INVALID_PARAMETER - The source data is corrupted\r
 \r
+--*/\r
+{\r
+  UINT32        Index;\r
+  UINT32        CompSize;\r
+  UINT32        OrigSize;\r
+  EFI_STATUS    Status;\r
+  SCRATCH_DATA  *Sd;\r
+  UINT8         *Src;\r
+  UINT8         *Dst;\r
+\r
+  Status  = EFI_SUCCESS;\r
   Src     = Source;\r
   Dst     = Destination;\r
 \r
+  if (ScratchSize < sizeof (SCRATCH_DATA)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   Sd = (SCRATCH_DATA *) Scratch;\r
 \r
+  if (SrcSize < 8) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   CompSize  = Src[0] + (Src[1] << 8) + (Src[2] << 16) + (Src[3] << 24);\r
   OrigSize  = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);\r
 \r
@@ -638,7 +760,15 @@ UefiTianoDecompress (
   // If compressed file size is 0, return\r
   //\r
   if (OrigSize == 0) {\r
-    return RETURN_SUCCESS;\r
+    return Status;\r
+  }\r
+\r
+  if (SrcSize < CompSize + 8) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (DstSize != OrigSize) {\r
+    return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   Src = Src + 8;\r
@@ -648,20 +778,26 @@ UefiTianoDecompress (
   }\r
   //\r
   // The length of the field 'Position Set Code Length Array Size' in Block Header.\r
-  // For UEFI 2.0 de/compression algorithm(Version 1), mPBit = 4\r
+  // For EFI 1.1 de/compression algorithm(Version 1), mPBit = 4\r
   // For Tiano de/compression algorithm(Version 2), mPBit = 5\r
   //\r
   switch (Version) {\r
-    case 1 :\r
-      Sd->mPBit = 4;\r
-      break;\r
-    case 2 :\r
-      Sd->mPBit = 5;\r
-      break;\r
-    default:\r
-      ASSERT (FALSE);\r
+  case 1:\r
+    Sd->mPBit = 4;\r
+    break;\r
+\r
+  case 2:\r
+    Sd->mPBit = 5;\r
+    break;\r
+\r
+  default:\r
+    //\r
+    // Currently, only have 2 versions\r
+    //\r
+    return EFI_INVALID_PARAMETER;\r
   }\r
-  Sd->mSrcBase  = (UINT8 *)Src;\r
+\r
+  Sd->mSrcBase  = Src;\r
   Sd->mDstBase  = Dst;\r
   Sd->mCompSize = CompSize;\r
   Sd->mOrigSize = OrigSize;\r
@@ -680,133 +816,177 @@ UefiTianoDecompress (
     //\r
     // Something wrong with the source\r
     //\r
-    return RETURN_INVALID_PARAMETER;\r
+    Status = EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  return RETURN_SUCCESS;\r
+  return Status;\r
 }\r
 \r
-/**\r
-  The internal implementation of *_DECOMPRESS_PROTOCOL.Decompress().\r
-  \r
-  @param Source          - The source buffer containing the compressed data.\r
-  @param Destination     - The destination buffer to store the decompressed data\r
-  @param Scratch         - The buffer used internally by the decompress routine. This  buffer is needed to store intermediate data.\r
-\r
-  @retval RETURN_SUCCESS           - Decompression is successfull\r
-  @retval RETURN_INVALID_PARAMETER - The source data is corrupted  \r
-**/\r
-RETURN_STATUS\r
+EFI_STATUS\r
 EFIAPI\r
-UefiDecompress (\r
-  IN CONST VOID  *Source,\r
-  IN OUT VOID    *Destination,\r
-  IN OUT VOID    *Scratch\r
+EfiGetInfo (\r
+  IN      VOID                    *Source,\r
+  IN      UINT32                  SrcSize,\r
+  OUT     UINT32                  *DstSize,\r
+  OUT     UINT32                  *ScratchSize\r
   )\r
-{\r
-  return UefiTianoDecompress (Source, Destination, Scratch, 1);\r
-}\r
+/*++\r
+\r
+Routine Description:\r
 \r
-/**\r
-  The internal implementation of Tiano decompress GetInfo.\r
+  The implementation is same as that  of EFI_DECOMPRESS_PROTOCOL.GetInfo().\r
 \r
-  @param InputSection          Buffer containing the input GUIDed section to be processed. \r
-  @param OutputBufferSize      The size of OutputBuffer.\r
-  @param ScratchBufferSize     The size of ScratchBuffer.\r
-  @param SectionAttribute      The attribute of the input guided section.\r
+Arguments:\r
 \r
-  @retval RETURN_SUCCESS           - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
-  @retval RETURN_INVALID_PARAMETER - The source data is corrupted\r
-                             The GUID in InputSection does not match this instance guid.\r
-**/\r
-RETURN_STATUS\r
+  This        - The protocol instance pointer\r
+  Source      - The source buffer containing the compressed data.\r
+  SrcSize     - The size of source buffer\r
+  DstSize     - The size of destination buffer.\r
+  ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
+  EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+{\r
+  return GetInfo (\r
+          Source,\r
+          SrcSize,\r
+          DstSize,\r
+          ScratchSize\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
 EFIAPI\r
-TianoDecompressGetInfo (\r
-  IN  CONST VOID  *InputSection,\r
-  OUT UINT32      *OutputBufferSize,\r
-  OUT UINT32      *ScratchBufferSize,\r
-  OUT UINT16      *SectionAttribute\r
+EfiDecompress (\r
+  IN      VOID                    *Source,\r
+  IN      UINT32                  SrcSize,\r
+  IN OUT  VOID                    *Destination,\r
+  IN      UINT32                  DstSize,\r
+  IN OUT  VOID                    *Scratch,\r
+  IN      UINT32                  ScratchSize\r
   )\r
+/*++\r
 \r
-{\r
-  ASSERT (SectionAttribute != NULL);\r
+Routine Description:\r
 \r
-  if (InputSection == NULL) {\r
-    return RETURN_INVALID_PARAMETER;\r
-  }\r
+  The implementation is same as that of EFI_DECOMPRESS_PROTOCOL.Decompress().\r
 \r
-  if (!CompareGuid (\r
-        &gTianoCustomDecompressGuid, \r
-        &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
-    return RETURN_INVALID_PARAMETER;\r
-  }\r
-  //\r
-  // Get guid attribute of guid section. \r
-  //\r
-  *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;\r
+Arguments:\r
+\r
+  This        - The protocol instance pointer\r
+  Source      - The source buffer containing the compressed data.\r
+  SrcSize     - The size of source buffer\r
+  Destination - The destination buffer to store the decompressed data\r
+  DstSize     - The size of destination buffer.\r
+  Scratch     - The buffer used internally by the decompress routine. This  buffer is needed to store intermediate data.\r
+  ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
 \r
+  EFI_SUCCESS           - Decompression is successfull\r
+  EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+{\r
   //\r
-  // Call Tiano GetInfo to get the required size info.\r
+  // For EFI 1.1 de/compression algorithm, the version is 1.\r
   //\r
-  return UefiDecompressGetInfo (\r
-          (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
-          (*(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size) & 0x00ffffff) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
-          OutputBufferSize,\r
-          ScratchBufferSize\r
-         );\r
+  return Decompress (\r
+          Source,\r
+          SrcSize,\r
+          Destination,\r
+          DstSize,\r
+          Scratch,\r
+          ScratchSize,\r
+          1\r
+          );\r
 }\r
 \r
-/**\r
-  The implementation of Tiano Decompress().\r
+EFI_STATUS\r
+EFIAPI\r
+TianoGetInfo (\r
+  IN      VOID                          *Source,\r
+  IN      UINT32                        SrcSize,\r
+  OUT     UINT32                        *DstSize,\r
+  OUT     UINT32                        *ScratchSize\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The implementation is same as that of EFI_TIANO_DECOMPRESS_PROTOCOL.GetInfo().\r
+\r
+Arguments:\r
+\r
+  This        - The protocol instance pointer\r
+  Source      - The source buffer containing the compressed data.\r
+  SrcSize     - The size of source buffer\r
+  DstSize     - The size of destination buffer.\r
+  ScratchSize - The size of scratch buffer.\r
 \r
-  @param InputSection           Buffer containing the input GUIDed section to be processed. \r
-  @param OutputBuffer           OutputBuffer to point to the start of the section's contents.\r
-                                if guided data is not prcessed. Otherwise,\r
-                                OutputBuffer to contain the output data, which is allocated by the caller.\r
-  @param ScratchBuffer          A pointer to a caller-allocated buffer for function internal use. \r
-  @param AuthenticationStatus   A pointer to a caller-allocated UINT32 that indicates the\r
-                                authentication status of the output buffer. \r
+Returns:\r
 \r
-  @retval RETURN_SUCCESS            Decompression is successfull\r
-  @retval RETURN_INVALID_PARAMETER  The source data is corrupted, or\r
-                                    The GUID in InputSection does not match this instance guid.\r
+  EFI_SUCCESS           - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
+  EFI_INVALID_PARAMETER - The source data is corrupted\r
 \r
-**/\r
-RETURN_STATUS\r
+--*/\r
+{\r
+  return GetInfo (\r
+          Source,\r
+          SrcSize,\r
+          DstSize,\r
+          ScratchSize\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
 EFIAPI\r
 TianoDecompress (\r
-  IN CONST  VOID    *InputSection,\r
-  OUT       VOID    **OutputBuffer,\r
-  IN        VOID    *ScratchBuffer,        OPTIONAL\r
-  OUT       UINT32  *AuthenticationStatus\r
+  IN      VOID                          *Source,\r
+  IN      UINT32                        SrcSize,\r
+  IN OUT  VOID                          *Destination,\r
+  IN      UINT32                        DstSize,\r
+  IN OUT  VOID                          *Scratch,\r
+  IN      UINT32                        ScratchSize\r
   )\r
-{\r
-  ASSERT (OutputBuffer != NULL);\r
+/*++\r
 \r
-  if (InputSection == NULL) {\r
-    return RETURN_INVALID_PARAMETER;\r
-  }\r
+Routine Description:\r
 \r
-  if (!CompareGuid (\r
-        &gTianoCustomDecompressGuid, \r
-        &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
-    return RETURN_INVALID_PARAMETER;\r
-  }\r
+  The implementation is same as that  of EFI_TIANO_DECOMPRESS_PROTOCOL.Decompress().\r
 \r
+Arguments:\r
+\r
+  This        - The protocol instance pointer\r
+  Source      - The source buffer containing the compressed data.\r
+  SrcSize     - The size of source buffer\r
+  Destination - The destination buffer to store the decompressed data\r
+  DstSize     - The size of destination buffer.\r
+  Scratch     - The buffer used internally by the decompress routine. This  buffer is needed to store intermediate data.\r
+  ScratchSize - The size of scratch buffer.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - Decompression is successfull\r
+  EFI_INVALID_PARAMETER - The source data is corrupted\r
+\r
+--*/\r
+{\r
   //\r
-  // Set Authentication to Zero.\r
-  //\r
-  *AuthenticationStatus = 0;\r
-  \r
-  //\r
-  // Call Tiano Decompress to get the raw data\r
+  // For Tiano de/compression algorithm, the version is 2.\r
   //\r
-  return UefiTianoDecompress (\r
-          (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
-          *OutputBuffer,\r
-          ScratchBuffer,\r
+  return Decompress (\r
+          Source,\r
+          SrcSize,\r
+          Destination,\r
+          DstSize,\r
+          Scratch,\r
+          ScratchSize,\r
           2\r
-         );\r
+          );\r
 }\r
 \r
-\r
index 54ae620996190beb2ec86dd668358a186da668ee..dad51ed4a54ac3ce84a5429c3f0859c7450c2ced 100644 (file)
 #include <Library/DebugLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 \r
-//\r
-// Decompression algorithm begins here\r
-//\r
-#define BITBUFSIZ 32\r
-#define MAXMATCH  256\r
-#define THRESHOLD 3\r
-#define CODE_BIT  16\r
-#define BAD_TABLE - 1\r
-\r
-//\r
-// C: Char&Len Set; P: Position Set; T: exTra Set\r
-//\r
-#define NC      (0xff + MAXMATCH + 2 - THRESHOLD)\r
-#define CBIT    9\r
-#define MAXPBIT 5\r
-#define TBIT    5\r
-#define MAXNP   ((1U << MAXPBIT) - 1)\r
-#define NT      (CODE_BIT + 3)\r
-#if NT > MAXNP\r
-#define NPT NT\r
-#else\r
-#define NPT MAXNP\r
-#endif\r
-\r
-typedef struct {\r
-  UINT8   *mSrcBase;  // Starting address of compressed data\r
-  UINT8   *mDstBase;  // Starting address of decompressed data\r
-  UINT32  mOutBuf;\r
-  UINT32  mInBuf;\r
-\r
-  UINT16  mBitCount;\r
-  UINT32  mBitBuf;\r
-  UINT32  mSubBitBuf;\r
-  UINT16  mBlockSize;\r
-  UINT32  mCompSize;\r
-  UINT32  mOrigSize;\r
-\r
-  UINT16  mBadTableFlag;\r
-\r
-  UINT16  mLeft[2 * NC - 1];\r
-  UINT16  mRight[2 * NC - 1];\r
-  UINT8   mCLen[NC];\r
-  UINT8   mPTLen[NPT];\r
-  UINT16  mCTable[4096];\r
-  UINT16  mPTTable[256];\r
-\r
-  //\r
-  // The length of the field 'Position Set Code Length Array Size' in Block Header.\r
-  // For UEFI 2.0 de/compression algorithm, mPBit = 4\r
-  // For Tiano de/compression algorithm, mPBit = 5\r
-  //\r
-  UINT8   mPBit;\r
-} SCRATCH_DATA;\r
-\r
-/**\r
-  Read NumOfBit of bits from source into mBitBuf\r
-\r
-  Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.\r
-\r
-  @param  Sd        The global scratch data\r
-  @param  NumOfBits The number of bits to shift and read.\r
-\r
-**/\r
-VOID\r
-FillBuf (\r
-  IN  SCRATCH_DATA  *Sd,\r
-  IN  UINT16        NumOfBits\r
-  );\r
-\r
-/**\r
-  Get NumOfBits of bits out from mBitBuf\r
-\r
-  Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent \r
-  NumOfBits of bits from source. Returns NumOfBits of bits that are \r
-  popped out.\r
-\r
-  @param  Sd        The global scratch data.\r
-  @param  NumOfBits The number of bits to pop and read.\r
-\r
-  @return The bits that are popped out.\r
-\r
-**/\r
-UINT32\r
-GetBits (\r
-  IN  SCRATCH_DATA  *Sd,\r
-  IN  UINT16        NumOfBits\r
-  );\r
-\r
-/**\r
-  Creates Huffman Code mapping table according to code length array.\r
-\r
-  Creates Huffman Code mapping table for Extra Set, Char&Len Set \r
-  and Position Set according to code length array.\r
-\r
-  @param  Sd        The global scratch data\r
-  @param  NumOfChar Number of symbols in the symbol set\r
-  @param  BitLen    Code length array\r
-  @param  TableBits The width of the mapping table\r
-  @param  Table     The table\r
-\r
-  @retval  0 OK.\r
-  @retval  BAD_TABLE The table is corrupted.\r
-\r
-**/\r
-UINT16\r
-MakeTable (\r
-  IN  SCRATCH_DATA  *Sd,\r
-  IN  UINT16        NumOfChar,\r
-  IN  UINT8         *BitLen,\r
-  IN  UINT16        TableBits,\r
-  OUT UINT16        *Table\r
-  );\r
-\r
-/**\r
-  Decodes a position value.\r
-\r
-  Get a position value according to Position Huffman Table.\r
-  \r
-  @param  Sd the global scratch data\r
-\r
-  @return The position value decoded.\r
+EFI_STATUS\r
+EFIAPI\r
+TianoGetInfo (\r
+  IN      VOID                          *Source,\r
+  IN      UINT32                        SrcSize,\r
+  OUT     UINT32                        *DstSize,\r
+  OUT     UINT32                        *ScratchSize\r
+  )\r
+/*++\r
 \r
-**/\r
-UINT32\r
-DecodeP (\r
-  IN  SCRATCH_DATA  *Sd\r
-  );\r
+Routine Description:\r
 \r
-/**\r
-  Reads code lengths for the Extra Set or the Position Set.\r
+  The implementation is same as that of EFI_TIANO_DECOMPRESS_PROTOCOL.GetInfo().\r
 \r
-  Read in the Extra Set or Pointion Set Length Arrary, then\r
-  generate the Huffman code mapping for them.\r
+Arguments:\r
 \r
-  @param  Sd      The global scratch data.\r
-  @param  nn      Number of symbols.\r
-  @param  nbit    Number of bits needed to represent nn.\r
-  @param  Special The special symbol that needs to be taken care of.\r
+  This        - The protocol instance pointer\r
+  Source      - The source buffer containing the compressed data.\r
+  SrcSize     - The size of source buffer\r
+  DstSize     - The size of destination buffer.\r
+  ScratchSize - The size of scratch buffer.\r
 \r
-  @retval  0 OK.\r
-  @retval  BAD_TABLE Table is corrupted.\r
+Returns:\r
 \r
-**/\r
-UINT16\r
-ReadPTLen (\r
-  IN  SCRATCH_DATA  *Sd,\r
-  IN  UINT16        nn,\r
-  IN  UINT16        nbit,\r
-  IN  UINT16        Special\r
-  );\r
-\r
-/**\r
-  Reads code lengths for Char&Len Set.\r
-  \r
-  Read in and decode the Char&Len Set Code Length Array, then\r
-  generate the Huffman Code mapping table for the Char&Len Set.\r
-\r
-  @param  Sd the global scratch data\r
+  EFI_SUCCESS           - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
+  EFI_INVALID_PARAMETER - The source data is corrupted\r
 \r
-**/\r
-VOID\r
-ReadCLen (\r
-  SCRATCH_DATA  *Sd\r
-  );\r
+--*/\r
+;\r
 \r
-/**\r
-  Decode a character/length value.\r
-  \r
-  Read one value from mBitBuf, Get one code from mBitBuf. If it is at block boundary, generates\r
-  Huffman code mapping table for Extra Set, Code&Len Set and\r
-  Position Set.\r
+EFI_STATUS\r
+EFIAPI\r
+TianoDecompress (\r
+  IN      VOID                          *Source,\r
+  IN      UINT32                        SrcSize,\r
+  IN OUT  VOID                          *Destination,\r
+  IN      UINT32                        DstSize,\r
+  IN OUT  VOID                          *Scratch,\r
+  IN      UINT32                        ScratchSize\r
+  )\r
+/*++\r
 \r
-  @param  Sd The global scratch data.\r
+Routine Description:\r
 \r
-  @return The value decoded.\r
+  The implementation is same as that  of EFI_TIANO_DECOMPRESS_PROTOCOL.Decompress().\r
 \r
-**/\r
-UINT16\r
-DecodeC (\r
-  SCRATCH_DATA  *Sd\r
-  );\r
+Arguments:\r
 \r
-/**\r
-  Decode the source data and put the resulting data into the destination buffer.\r
+  This        - The protocol instance pointer\r
+  Source      - The source buffer containing the compressed data.\r
+  SrcSize     - The size of source buffer\r
+  Destination - The destination buffer to store the decompressed data\r
+  DstSize     - The size of destination buffer.\r
+  Scratch     - The buffer used internally by the decompress routine. This  buffer is needed to store intermediate data.\r
+  ScratchSize - The size of scratch buffer.\r
 \r
-  Decode the source data and put the resulting data into the destination buffer.\r
-  \r
-  @param  Sd The global scratch data\r
+Returns:\r
 \r
-**/\r
-VOID\r
-Decode (\r
-  SCRATCH_DATA  *Sd\r
-  );\r
+  EFI_SUCCESS           - Decompression is successfull\r
+  EFI_INVALID_PARAMETER - The source data is corrupted\r
 \r
-RETURN_STATUS\r
-EFIAPI\r
-UefiTianoDecompress (\r
-  IN CONST VOID  *Source,\r
-  IN OUT VOID    *Destination,\r
-  IN OUT VOID    *Scratch,\r
-  IN UINT32      Version\r
-  );\r
+--*/\r
+;\r
 \r
 #endif\r
index cbc0babc1c8263f3bb3bf4c1c69934b3b18ec86a..52cf07a94284e3f420e8ac7eec423d2c5042ba92 100644 (file)
@@ -11,5 +11,5 @@ set OUTPUT_DIR=%BUILD_DIR%\IA32\DuetPkg\BootSector\BootSector\OUTPUT
 %BASETOOLS_DIR%\TianoCompress -e -o %BUILD_DIR%\FV\DUETEFIMAINFV.z %BUILD_DIR%\FV\DUETEFIMAINFV.Fv\r
 %BASETOOLS_DIR%\TianoCompress -e -o %BUILD_DIR%\FV\DxeMain.z %BUILD_DIR%\IA32\DxeMain.efi\r
 %BASETOOLS_DIR%\TianoCompress -e -o %BUILD_DIR%\FV\DxeIpl.z %BUILD_DIR%\IA32\DxeIpl.efi\r
-%BASETOOLS_DIR%\EfiLdrImage.exe -o %BUILD_DIR%\FV\Efildr32 %BUILD_DIR%\IA32\EfiLoader.efi %BUILD_DIR%\FV\DxeIpl.z %BUILD_DIR%\FV\DUETEFIMAINFV.z\r
+%BASETOOLS_DIR%\EfiLdrImage.exe -o %BUILD_DIR%\FV\Efildr32 %BUILD_DIR%\IA32\EfiLoader.efi %BUILD_DIR%\FV\DxeIpl.z %BUILD_DIR%\FV\DxeMain.z %BUILD_DIR%\FV\DUETEFIMAINFV.z\r
 copy /b %OUTPUT_DIR%\Start.com+%OUTPUT_DIR%\Efi32.com2+%BUILD_DIR%\FV\Efildr32 %BUILD_DIR%\FV\Efildr\r