* [Patch][edk2-platforms/devel-IntelAtomProcessorE3900] EEPROM change
@ 2018-08-17 9:59 Guo, Mang
0 siblings, 0 replies; only message in thread
From: Guo, Mang @ 2018-08-17 9:59 UTC (permalink / raw)
To: edk2-devel@lists.01.org; +Cc: Wei, David
Fixed 32-bit build failure in the EEPROM code.
Cleaned up the EEPROM code .
Define an EEPROM FPGA structure to hold FPGA bitstreams.
Cc: David Wei <david.wei@intel.com>
Cc: Mike Wu <mike.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Kelly Steele <kelly.steele@intel.com>
Signed-off-by: Guo Mang <mang.guo@intel.com>
---
.../Common/Features/Eeprom/EepromApp/EepromApp.c | 78 +-
.../Eeprom/EepromBinary/Docs/EepromLayout.txt | 33 +-
.../Docs/HowToInstallAnEepromBinary.txt | 1 +
.../Common/Features/Eeprom/EepromBinary/ReadMe.txt | 189 ++++
.../EepromDataLib/EEPROM/EepromDataEepromLib.c | 20 +-
.../EepromDataLib/EEPROM/EepromDataEepromLib.h | 3 +-
.../Features/Eeprom/EepromDataLib/EEPROM/HobData.c | 2 +-
.../Features/Eeprom/EepromDataLib/EEPROM/I2cLib.c | 1164 --------------------
.../Features/Eeprom/EepromDataLib/EEPROM/I2cLib.h | 181 ---
.../Features/Eeprom/EepromDataLib/EepromDataLib.c | 64 --
.../Features/Eeprom/EepromDataLib/EepromDataLib.h | 5 +
.../Eeprom/EepromDataLib/EepromDataLib.inf | 7 +-
.../EepromDataLib/EepromDataLibConstructor.c | 61 +
.../Eeprom/EepromDataLib/EepromDataNullLib.inf | 3 +
.../EepromDataLib/EepromDataNullLibConstructor.c | 36 +
.../Eeprom/EepromDataLib/EepromDataNullPeiLib.inf | 46 +
.../Eeprom/EepromDataLib/EepromDataPeiLib.inf | 7 +-
.../Features/Eeprom/EepromDataLib/Memory/HobData.c | 2 +-
.../Eeprom/EepromDataLib/MemoryAllocation.c | 17 +
.../Eeprom/EepromDataLib/MemoryAllocationPei.c | 21 +
.../Common/Features/Eeprom/EepromLib/EepromLib.c | 308 +++---
.../Common/Features/Eeprom/EepromLib/EepromLib.h | 9 +-
.../Features/Eeprom/EepromLib/Null/EepromNullLib.c | 5 +-
.../Eeprom/EepromLib/Pei/ValidateHashPei.c | 76 +-
.../Features/Eeprom/EepromLib/ValidateHash.c | 149 ++-
.../Common/Features/Eeprom/Include/EepromStruct.h | 45 +-
.../Eeprom/Include/Library/EepromDataLib.h | 7 +
.../Features/Eeprom/Include/Library/EepromLib.h | 24 +-
.../Eeprom/Include/Library/EepromPlatformLib.h | 117 ++
29 files changed, 942 insertions(+), 1738 deletions(-)
delete mode 100644 Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPROM/I2cLib.c
delete mode 100644 Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPROM/I2cLib.h
create mode 100644 Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataLibConstructor.c
create mode 100644 Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataNullLibConstructor.c
create mode 100644 Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataNullPeiLib.inf
create mode 100644 Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Library/EepromPlatformLib.h
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromApp/EepromApp.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromApp/EepromApp.c
index 9e1eb66..3b1b48b 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromApp/EepromApp.c
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromApp/EepromApp.c
@@ -85,7 +85,7 @@ ShellAppMain (
//
// Skip this if we are doing a scan.
//
- Print (L"- GetValidEepromLibrary() = %a\n", mEepromLibraryString[GetValidEepromLibrary (TRUE, TRUE)]);
+ Print (L"- GetValidEepromLibrary() = %a\n", mEepromLibraryString[GetValidEepromLibrary (TRUE)]);
} else {
// Scanning
Status = ScanOption (&ProgramInfo);
@@ -546,7 +546,7 @@ DumpHumanOption (
IN PROGRAM_INFO *ProgramInfo
)
{
- CHAR8 AsciiData[16];
+ CHAR8 AsciiData[32];
VOID *Buffer;
UINT32 BufferSize;
UINT32 count;
@@ -648,7 +648,7 @@ DumpHumanOption (
//
// Check for $AcpiTbl
//
- if (AsciiStrnCmp (GenericHeader->signature, "$AcpiTbl", 8) == 0) {
+ if (AsciiStrnCmp (GenericHeader->signature, EEPROM_ACPI_TABLE_SIGNATURE, 8) == 0) {
ACPI_TABLE *AcpiTable;
AcpiTable = (ACPI_TABLE *) Buffer;
Ptr = (UINT8 *) Buffer + sizeof (ACPI_TABLE);
@@ -657,7 +657,7 @@ DumpHumanOption (
//
// Check for $BrdInfo
//
- if (AsciiStrnCmp (GenericHeader->signature, "$BrdInfo", 8) == 0) {
+ if (AsciiStrnCmp (GenericHeader->signature, EEPROM_BOARD_INFO_SIGNATURE, 8) == 0) {
BOARD_INFO_TABLE *BoardInfo;
BoardInfo = (BOARD_INFO_TABLE *) Buffer;
ZeroMem (AsciiData, 17);
@@ -673,10 +673,10 @@ DumpHumanOption (
Print (L"Fab ID = %08x\n", BoardInfo->fabid);
Print (L"EC ID = %08x\n", BoardInfo->ecid);
Print (L"Board type = ");
- if (BoardInfo->boardtype == 0) {
+ if (BoardInfo->boardtype == EEPROM_BOARD_TYPE_REDBOX) {
Print (L"Main board (RedBox)\n");
} else
- if (BoardInfo->boardtype == 1) {
+ if (BoardInfo->boardtype == EEPROM_BOARD_TYPE_PLUGIN) {
Print (L"Plug-in board\n");
} else
{
@@ -686,7 +686,7 @@ DumpHumanOption (
//
// Check for $EeprMap
//
- if (AsciiStrnCmp (GenericHeader->signature, "$EeprMap", 8) == 0) {
+ if (AsciiStrnCmp (GenericHeader->signature, EEPROM_MAP_SIGNATURE, 8) == 0) {
EEPROM_MAP *EepromMap;
EEPROM_MAP_RECORD *MapRecord;
EepromMap = (EEPROM_MAP *) Buffer;
@@ -709,13 +709,13 @@ DumpHumanOption (
Print (L"[%02x] - Unknown\n", EepromMap->master);
}
Print (L"I2C speed = ");
- if (EepromMap->speed == 1) {
+ if (EepromMap->speed == EEPROM_SPEED_STANDARD) {
Print (L"100KHz (Standard speed)\n");
} else
- if (EepromMap->speed == 2) {
+ if (EepromMap->speed == EEPROM_SPEED_FAST) {
Print (L"400KHz (Fast speed)\n");
} else
- if (EepromMap->speed == 3) {
+ if (EepromMap->speed == EEPROM_SPEED_HIGH) {
Print (L"3.4MHz (High speed)\n");
} else
{
@@ -740,7 +740,7 @@ DumpHumanOption (
//
// Check for $Eeprom$ structure
//
- if (AsciiStrnCmp (GenericHeader->signature, "$Eeprom$", 8) == 0) {
+ if (AsciiStrnCmp (GenericHeader->signature, EEPROM_HEADER_SIGNATURE, 8) == 0) {
EEPROM_HEADER *EepromHeader;
EepromHeader = (EEPROM_HEADER *) Buffer;
Print (L"Image length = %08x\n", EepromHeader->structlength);
@@ -751,7 +751,7 @@ DumpHumanOption (
//
// Check for $GpioDat
//
- if (AsciiStrnCmp (GenericHeader->signature, "$GpioDat", 8) == 0) {
+ if (AsciiStrnCmp (GenericHeader->signature, EEPROM_GPIO_SIGNATURE, 8) == 0) {
GPIO_DATA_HEADER *GpioHeader;
GPIO_DATA_RECORD *GpioRecord;
GpioHeader = (GPIO_DATA_HEADER *) Buffer;
@@ -769,19 +769,19 @@ DumpHumanOption (
Print (L" - GPIO OR data = %08x\n", GpioRecord->ordata);
Print (L" - GPIO data size = %08x\n", GpioRecord->datasize);
Print (L" - GPIO data type = ");
- if (GpioRecord->datasize == 0) {
+ if (GpioRecord->datasize == EEPROM_GPIO_TYPE_IO) {
Print (L"IO\n");
} else
- if (GpioRecord->datasize == 1) {
+ if (GpioRecord->datasize == EEPROM_GPIO_TYPE_MMIO) {
Print (L"MMIO\n");
} else
- if (GpioRecord->datasize == 2) {
+ if (GpioRecord->datasize == EEPROM_GPIO_TYPE_PCI) {
Print (L"PCI\n");
} else
- if (GpioRecord->datasize == 3) {
+ if (GpioRecord->datasize == EEPROM_GPIO_TYPE_PCIE) {
Print (L"PCIe\n");
} else
- if (GpioRecord->datasize == 4) {
+ if (GpioRecord->datasize == EEPROM_GPIO_TYPE_PAD_OFFSET) {
Print (L"PAD offset\n");
} else
{
@@ -796,7 +796,7 @@ DumpHumanOption (
//
// Check for $HdCodec
//
- if (AsciiStrnCmp (GenericHeader->signature, "$HdCodec", 8) == 0) {
+ if (AsciiStrnCmp (GenericHeader->signature, EEPROM_HDA_CODEC_SIGNATURE, 8) == 0) {
HDA_CODEC *HdaCodec;
HdaCodec = (HDA_CODEC *) Buffer;
Ptr = (UINT8 *) Buffer + sizeof (HDA_CODEC);
@@ -805,7 +805,7 @@ DumpHumanOption (
//
// Check for $Logo$
//
- if (AsciiStrnCmp (GenericHeader->signature, "$Logo$", 6) == 0) {
+ if (AsciiStrnCmp (GenericHeader->signature, EEPROM_LOGO_DATA_SIGNATURE, 6) == 0) {
LOGO_DATA *LogoData;
LogoData = (LOGO_DATA *) Buffer;
Ptr = (UINT8 *) Buffer + sizeof (LOGO_DATA);
@@ -814,7 +814,7 @@ DumpHumanOption (
//
// Check for $MacInfo
//
- if (AsciiStrnCmp (GenericHeader->signature, "$MacInfo", 8) == 0) {
+ if (AsciiStrnCmp (GenericHeader->signature, EEPROM_NIC_INFO_SIGNATURE, 8) == 0) {
NIC_INFO *NicInfo;
NicInfo = (NIC_INFO *) Buffer;
ZeroMem (AsciiData, 9);
@@ -828,50 +828,54 @@ DumpHumanOption (
//
// Check for $MemCnfg
//
- if (AsciiStrnCmp (GenericHeader->signature, "$MemCnfg", 8) == 0) {
- UINT8 Slot;
- MEMORY_SPD *MemoryData;
- MemoryData = (MEMORY_SPD *) Buffer;
+ if (AsciiStrnCmp (GenericHeader->signature, EEPROM_MEMORY_DATA_SIGNATURE, 8) == 0) {
+ UINT8 Slot;
+ MEMORY_DATA *MemoryData;
+ MemoryData = (MEMORY_DATA *) Buffer;
Print (L"SPD slot flags = %04x\n", MemoryData->spdslot);
- for (Slot = 0; Slot < 16; Slot++) {
- if (MemoryData->spdslot & (1 << Slot)) {
- Print (L" - Slot %d support.\n", Slot + 1);
+ if (MemoryData->spdslot == 0) {
+ Print (L" - SMIP binary.\n");
+ } else {
+ for (Slot = 0; Slot < 16; Slot++) {
+ if (MemoryData->spdslot & (1 << Slot)) {
+ Print (L" - Slot %d support.\n", Slot + 1);
+ }
}
}
- Ptr = (UINT8 *) Buffer + sizeof (MEMORY_SPD);
+ Ptr = (UINT8 *) Buffer + sizeof (MEMORY_DATA);
if (ProgramInfo->VerboseFlag) DumpParagraph (Ptr, (MemoryData->length - (Ptr - (UINT8 *) Buffer)));
} else
//
// Check for $PromSig
//
- if (AsciiStrnCmp (GenericHeader->signature, "$PromSig", 8) == 0) {
+ if (AsciiStrnCmp (GenericHeader->signature, EEPROM_SIGNATURE_SIGNATURE, 8) == 0) {
UINT16 HashType;
SIGNATURE_DATA *SignatureData;
SignatureData = (SIGNATURE_DATA *) Buffer;
Hash = (UINT8 *) Buffer + sizeof (SIGNATURE_DATA);
HashType = (SignatureData->hashtype & 0x7FFF);
Print (L"Hash type = ");
- if (HashType == HASH_NONE) {
+ if (HashType == EEPROM_SIGNATURE_TYPE_NONE) {
Print (L"None\n");
HashSize = 0;
} else
- if (HashType == HASH_MD5) {
+ if (HashType == EEPROM_SIGNATURE_TYPE_MD5) {
Print (L"MD5\n");
HashSize = MD5DigestSize;
} else
- if (HashType == HASH_SHA1) {
+ if (HashType == EEPROM_SIGNATURE_TYPE_SHA1) {
Print (L"SHA1\n");
HashSize = SHA1DigestSize;
} else
- if (HashType == HASH_SHA256) {
+ if (HashType == EEPROM_SIGNATURE_TYPE_SHA256) {
Print (L"SHA256\n");
HashSize = SHA256DigestSize;
} else
- if (HashType == HASH_SHA384) {
+ if (HashType == EEPROM_SIGNATURE_TYPE_SHA384) {
Print (L"SHA384\n");
HashSize = SHA384DigestSize;
} else
- if (HashType == HASH_SHA512) {
+ if (HashType == EEPROM_SIGNATURE_TYPE_SHA512) {
Print (L"SHA512\n");
HashSize = SHA512DigestSize;
} else
@@ -912,7 +916,7 @@ DumpHumanOption (
//
// Check for $uCode$
//
- if (AsciiStrnCmp (GenericHeader->signature, "$uCode$", 7) == 0) {
+ if (AsciiStrnCmp (GenericHeader->signature, EEPROM_MICROCODE_SIGNATURE, 7) == 0) {
MICROCODE *MicrocodeData;
MicrocodeData = (MICROCODE *) Buffer;
Ptr = (UINT8 *) Buffer + sizeof (MICROCODE);
@@ -921,7 +925,7 @@ DumpHumanOption (
//
// Check for $Video$
//
- if (AsciiStrnCmp (GenericHeader->signature, "$Video$", 7) == 0) {
+ if (AsciiStrnCmp (GenericHeader->signature, EEPROM_VIDEO_DATA_SIGNATURE, 7) == 0) {
VIDEO_DATA *VideoData;
VideoData = (VIDEO_DATA *) Buffer;
Ptr = (UINT8 *) Buffer + sizeof (VIDEO_DATA);
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBinary/Docs/EepromLayout.txt b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBinary/Docs/EepromLayout.txt
index 19a64a5..7a4f004 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBinary/Docs/EepromLayout.txt
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBinary/Docs/EepromLayout.txt
@@ -13,8 +13,8 @@
#
##
-Version: 1.00
-Dated: 07-02-2018
+Version: 1.10
+Dated: 07-31-2018
- The first 4KB of the EEPROM data MUST be accessible from I2C bus
gPlatformModuleTokenSpaceGuid.PcdEepromBus, address
@@ -75,6 +75,7 @@ Dated: 07-02-2018
- GPIO data records are applied in order. IE - Start at the beginning and apply the records
in order.
+ WARNING: Care must be exercised to ensure that non-whitelisted data is not programmed.
- If characters in a Signature[8] or a Label[16] don't fill the entire allocated length,
append string with $ as a sentinel value. IE - Signature[8] : "$uCode" shall be "$uCode$"
@@ -165,6 +166,7 @@ Offset | Length | Label | Default value | Description
0x2A | 0x01 | BusNumber | 0x00 | I2C Device Bus
0x2B | 0x01 | Master | 0x00 | Set to 1 if EEPROM is master, 0 otherwise
0x2C | 0x01 | Speed | 0x00 | The speed the EEPROM part should run at
+ | | | | 0 - Unknown
| | | | 1 - 100KHz (Standard speed)
| | | | 2 - 400KHz (Fast speed)
| | | | 3 - 3.4MHz (High speed)
@@ -180,6 +182,24 @@ Offset | Length | Label | Default value | Description
0x18 | 0x01 | Address | 0x00 | I2C Device address, 7-bit
0x19 | 0x07 | Reserved | 0x0000 | Reserved for future info
+FPGA info structure
+Offset | Length | Label | Default value | Description
+=======+========+===========+===============+==============================================
+ 0x00 | 0x08 | Signature | "$FPGAnfo" | Marks the beginning of the FPGA Info structure
+ 0x08 | 0x02 | VerMajor | 0x0001 | Version, major
+ 0x0A | 0x02 | VerMinor | 0x0000 | Version, minor
+ 0x0C | 0x04 | Length | 0x0000???? | Length in bytes of this structure
+ 0x10 | 0x01 | DataType | 0x00 | How is the data getting to the FPGA?
+ | | | | 0 - Unknown
+ | | | | 1 - UART
+ | | | | 2 - I2C
+ | | | | 3 - SPI
+ | | | | 4 - PCI
+ 0x11 | 0x01 | DevNum | 0x00 | Device the FPGA connected to
+ 0x12 | 0x01 | FuncNum | 0x00 | Function/chip select the FPGA connected to
+ 0x13 | 0x0D | Reserved | 0x00 | Reserved for future info
+ 0x20 | ???? | FpgaData | 0x00 | FPGA bitstream
+
GPIO data structure
Offset | Length | Label | Default value | Description
=======+========+===========+===============+==============================================
@@ -232,18 +252,19 @@ Offset | Length | Label | Default value | Description
0x10 | 0x10 | Reserved | 0x00 | Reserved for future info
0x20 | ???? | LogoData | 0x00 | Logo data
-Memory SPD structure
+Memory data structure
Offset | Length | Label | Default value | Description
=======+========+===========+===============+==============================================
- 0x00 | 0x08 | Signature | "$MemCnfg" | Marks the beginning of the memory SPD structure
+ 0x00 | 0x08 | Signature | "$MemCnfg" | Marks the beginning of the memory data structure
0x08 | 0x02 | VerMajor | 0x0001 | Version, major
0x0A | 0x02 | VerMinor | 0x0000 | Version, minor
0x0C | 0x04 | Length | 0x0000???? | Length in bytes of this structure
- 0x10 | 0x02 | SpdSlot | 0x0000 | Which slot this SPD data belongs to in bit flag format
+ 0x10 | 0x02 | SpdSlot | 0x0000 | Which slot this memory data belongs to in bit flag format
+ | | | | - 0x0000 - SMIP data
| | | | - 0x0001 - This is for Slot 1 only
| | | | - 0x0005 - This is for Slot 1 & 3 only
0x12 | 0x0E | Reserved | 0x00 | Reserved for future info
- 0x20 | ???? | SpdData | 0x00 | SPD data for memory
+ 0x20 | ???? | MemData | 0x00 | Memory data
NIC info structure
Offset | Length | Label | Default value | Description
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBinary/Docs/HowToInstallAnEepromBinary.txt b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBinary/Docs/HowToInstallAnEepromBinary.txt
index a9b319c..155e6ca 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBinary/Docs/HowToInstallAnEepromBinary.txt
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBinary/Docs/HowToInstallAnEepromBinary.txt
@@ -13,6 +13,7 @@
#
##
+How to install an EEPROM image into an EEPROM:
1. Generate the EEPROM binary.
2. Copy the EEPROM binary and EepromApp.efi onto a USB drive.
3. Insert the USB drive into the target system.
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBinary/ReadMe.txt b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBinary/ReadMe.txt
index b413fad..d161e4d 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBinary/ReadMe.txt
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromBinary/ReadMe.txt
@@ -165,8 +165,197 @@ EepromApp.efi
===========================================================================================
+ UEFI EEPROM PCDs
+===========================================================================================
+ [PcdsDynamic,PcdsDynamicEx]
+ ## Used to store the EEPROM memory buffer pointer
+ gPlatformModuleTokenSpaceGuid.PcdEepromMemoryPointer|0|UINT64|0xEEEE0000
+ ## Used to store the EEPROM memory buffer size
+ gPlatformModuleTokenSpaceGuid.PcdEepromMemorySize|0|UINT32|0xEEEE0001
+ ## Used to store the EEPROM data library valid flags
+ gPlatformModuleTokenSpaceGuid.PcdEepromLibraryValid|{0x00, 0x00, 0x00, 0x00}|VOID*|0xEEEE0002
+ ## Flag to indicate that a HOB exists with EEPROM_MEMORY data
+ gPlatformModuleTokenSpaceGuid.PcdEepromMemoryHobPresent|FALSE|BOOLEAN|0xEEEE0003
+ ## Pointer to the Part head link
+ gPlatformModuleTokenSpaceGuid.PcdEepromPartsHeadLink|0|UINT64|0xEEEE0004
+ ## Pointer to the Parts table
+ gPlatformModuleTokenSpaceGuid.PcdEepromParts|0|UINT64|0xEEEE0005
+ ## Flag to tell if EEPROM Map is in memory
+ gPlatformModuleTokenSpaceGuid.PcdEepromInMemoryFlag|0|BOOLEAN|0xEEEE0006
+ ## Flag to tell if EEPROM Map is in HOB
+ gPlatformModuleTokenSpaceGuid.PcdEepromMapHobValid|0|BOOLEAN|0xEEEE0007
+
+ [PcdsFixedAtBuild]
+ ## I2C bus the master EEPROM is hanging on
+ gPlatformModuleTokenSpaceGuid.PcdEepromBus|0x06|UINT8|0xEEEE2000
+ ## 7-bit address of the master EEPROM
+ gPlatformModuleTokenSpaceGuid.PcdEepromAddress|0x50|UINT8|0xEEEE2001
+ ## Priority order of EEPROM data libraries
+ ## 00 - Null; 01 - EEPROM; 02 - FV; 03 - Memory; FF - End of list
+ ## Memory should be first
+ gPlatformModuleTokenSpaceGuid.PcdEepromAutoPriority|{0x03, 0x01, 0x02, 0x00, 0xFF}|VOID*|0xEEEE2002
+ ## Public key file GUID - 5D8A38A3-FBBD-4077-8105-11170C2AF54D
+ gPlatformModuleTokenSpaceGuid.PcdEepromPublicKeyFile|{0xA3, 0x38, 0x8A, 0x5D, 0xBD, 0xFB, 0x77, 0x40, 0x81, 0x05, 0x11, 0x17, 0x0C, 0x2A, 0xF5, 0x4D}|VOID*|0xEEEE2003
+ ## FV EEPROM Image file GUID - BFBD3DAC-01EB-4FEB-A9DE-BCC9D1BA5531
+ gPlatformModuleTokenSpaceGuid.PcdEepromFvImageFile|{0xAC, 0x3D, 0xBD, 0xBF, 0xEB, 0x01, 0xEB, 0x4F, 0xA9, 0xDE, 0xBC, 0xC9, 0xD1, 0xBA, 0x55, 0x31}|VOID*|0xEEEE2004
+ ## GPIO PAD whitelist | END OF ARRAY |
+ gPlatformModuleTokenSpaceGuid.PcdGpioWhiteList|{0xFF, 0xFF, 0xFF, 0xFF}|VOID*|0xEEEE2005
+
+
+===========================================================================================
UEFI EEPROM Libraries
===========================================================================================
+ EepromLib.h
+ UINTN
+ EFIAPI
+ DisplayStackPointer (
+ IN CHAR8 *Function,
+ IN UINTN LineNumber
+ );
+
+ EFI_STATUS
+ EFIAPI
+ EraseEeprom (
+ IN UINT8 LibraryIndex
+ );
+
+ EFI_STATUS
+ EFIAPI
+ GetEepromStructure (
+ IN UINT8 LibraryIndex,
+ IN OUT CHAR8 Signature[EEPROM_SIGNATURE_SIZE],
+ IN OUT UINT8 **Buffer,
+ IN OUT UINT32 *Size
+ );
+
+ UINT32
+ EFIAPI
+ GetImageSize (
+ IN UINT8 LibraryIndex
+ );
+
+ EFI_STATUS
+ EFIAPI
+ GetNextEepromStructure (
+ IN UINT8 LibraryIndex,
+ IN OUT UINT32 *Index,
+ IN OUT UINT8 **Buffer,
+ IN OUT UINT32 *Size
+ );
+
+ UINT8
+ EFIAPI
+ GetValidEepromLibrary (
+ IN BOOLEAN CopyToMemory,
+ IN BOOLEAN MemoryInitialized
+ );
+
+ BOOLEAN
+ EFIAPI
+ InPeiPhase (VOID);
+
+ EFI_STATUS
+ EFIAPI
+ ValidateEeprom (
+ IN UINT8 LibraryIndex
+ );
+
+ //
+ // Desc: Registers the raw data libraries
+ // Variables: None
+ // Return: EFI_SUCCESS
+ //
+ EFI_STATUS
+ EFIAPI
+ EepromInitConstructor (VOID);
+
+ EepromDataLib.h
+ //
+ // Desc: Copies the contents of an existing memory pool into a new memory pool of equal or greater size.
+ // Variables: Size Size of the pool to copy existing pool into
+ // SourcePointer Pointer to the source buffer to copy
+ // Return: Pointer Pointer to your copy of the pool
+ //
+ VOID*
+ EFIAPI
+ EepromAllocateCopyPool (
+ IN UINTN Size,
+ IN VOID *SourcePointer
+ );
+
+ //
+ // Desc: Creates a new memory pool.
+ // Variables: Size Size of the pool requested
+ // Return: Pointer Pointer the new pool
+ //
+ VOID*
+ EFIAPI
+ EepromAllocatePool (
+ IN UINTN Size
+ );
+
+ EFI_STATUS
+ EFIAPI
+ EepromDataLibNemToMemory (VOID);
+
+ //
+ // Desc: Frees a memory pool.
+ // Variables: Pointer Pointer to the beginning of the pool to be freed
+ // Return: Pointer NULL
+ //
+ VOID*
+ EFIAPI
+ EepromFreePool (
+ IN VOID *Pointer
+ );
+
+ //
+ // Desc: Reads from the EEPROM and copies to the passed in buffer.
+ // Variables: LibraryIndex Determines which raw data library to use
+ // Offset Start copying from the offset
+ // Size Size of the buffer and the number of bytes to copy
+ // - If set to 0, then return size of EEPROM binary
+ // Buffer Storage buffer for the copied data from the EEPROM
+ // FunctionInfo Pointer to function specific data
+ // Return: EFI_SUCCESS Data copied successfully
+ // EFI_UNSUPPORTED This function is not supported
+ // EFI_INVALID_PARAMETER One of the parameters is invalid
+ // EFI_NOT_READY Called before all necessary library available
+ // EFI_DEVICE_ERROR Communication error with device
+ //
+ EFI_STATUS
+ EFIAPI
+ ReadEeprom (
+ IN UINT8 LibraryIndex,
+ IN UINT32 Offset,
+ IN OUT UINT32 *Size,
+ IN OUT UINT8 *Buffer,
+ IN OUT VOID *FunctionInfo
+ );
+
+ //
+ // Desc: Writes to the EEPROM and copies to the passed in buffer.
+ // Variables: LibraryIndex Determines which raw data library to use
+ // Offset Start copying from the offset
+ // Size Size of the buffer and the number of bytes to copy
+ // - If set to 0, then return size of EEPROM binary
+ // Buffer Data to be copied to the EEPROM
+ // FunctionInfo Pointer to function specific data
+ // Return: EFI_SUCCESS Data copied successfully
+ // EFI_UNSUPPORTED This function is not supported
+ // EFI_INVALID_PARAMETER One of the parameters is invalid
+ // EFI_NOT_READY Called before all necessary library available
+ // EFI_DEVICE_ERROR Communication error with device
+ //
+ EFI_STATUS
+ EFIAPI
+ WriteEeprom (
+ IN UINT8 LibraryIndex,
+ IN UINT32 Offset,
+ IN OUT UINT32 *Size,
+ IN OUT UINT8 *Buffer,
+ IN OUT VOID *FunctionInfo
+ );
===========================================================================================
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPROM/EepromDataEepromLib.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPROM/EepromDataEepromLib.c
index 6f8e98c..09171fd 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPROM/EepromDataEepromLib.c
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPROM/EepromDataEepromLib.c
@@ -378,7 +378,7 @@ FillEepromMap (
// Sanity check EEPROM contents
//
AsciiSPrint (AsciiBuffer, 32, "%8a", (CHAR8 *) Ptr);
- if (AsciiStrnCmp (AsciiBuffer, "$Eeprom$", 0x08) != 0) {
+ if (AsciiStrnCmp (AsciiBuffer, EEPROM_HEADER_SIGNATURE, 0x08) != 0) {
//
// Not a vallid EEPROM image. Bail.
//
@@ -406,7 +406,7 @@ FillEepromMap (
AsciiSPrint (AsciiBuffer, 32, "%8a", EepromHeader->signature);
AsciiBuffer[8] = 0;
if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Structure = %a @ 0x%08x\n", __FUNCTION__, __LINE__, AsciiBuffer, EepromHeader));
- if (AsciiStrnCmp (EepromHeader->signature, "$EeprMap", 0x08) != 0) {
+ if (AsciiStrnCmp (EepromHeader->signature, EEPROM_MAP_SIGNATURE, 0x08) != 0) {
//
// This is not our structure. Skip to next structure.
//
@@ -924,6 +924,20 @@ EFI_STATUS
EFIAPI
LoadEepromMap (VOID)
{
+//KES: //
+//KES: // Initialize variables
+//KES: //
+//KES: gEepromParts = (EEPROM_PART_INFO *) (UINTN) PcdGet64 (PcdEepromParts);
+//KES: gEepromPartsHeadLink = (LIST_ENTRY *) (UINTN) PcdGet64 (PcdEepromPartsHeadLink);
+//KES:
+//KES: //
+//KES: // Load from HOB if present
+//KES: //
+//KES: if (PcdGetBool (PcdEepromMapHobValid)) {
+//KES: //
+//KES: // HOB is valid, load it into memory.
+//KES: //
+//KES: }
return EFI_SUCCESS;
}
@@ -1226,7 +1240,7 @@ ScanI2cBusForImages (
//
if (mEepromDataLibDebugFlag &&((index % 0x10) == 0)) DEBUG ((DEBUG_INFO, "."));
Status = I2cReadPages (I2cBus, index, 0, sizeof (EEPROM_HEADER), (UINT8 *) &EepromHeader);
- if (!EFI_ERROR (Status) && (AsciiStrnCmp (EepromHeader.signature, "$Eeprom$", 0x08) == 0)) {
+ if (!EFI_ERROR (Status) && (AsciiStrnCmp (EepromHeader.signature, EEPROM_HEADER_SIGNATURE, 0x08) == 0)) {
//
// Update array and count, since this devices starts with $Eeprom$
//
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPROM/EepromDataEepromLib.h b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPROM/EepromDataEepromLib.h
index 931d778..d47eca7 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPROM/EepromDataEepromLib.h
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPROM/EepromDataEepromLib.h
@@ -22,11 +22,12 @@
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/EepromDataLib.h>
+#include <Library/I2cLib.h>
+#include <Library/EepromPlatformLib.h>
#include <Library/PrintLib.h>
#include <Library/TimerLib.h>
#include <EepromStruct.h>
-#include "I2cLib.h"
//
// Defines
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPROM/HobData.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPROM/HobData.c
index 46523db..ebc62a1 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPROM/HobData.c
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPROM/HobData.c
@@ -72,7 +72,7 @@ GetEepromDataHobData (VOID)
//
// Yep. Copy existing buffer to larger buffer.
//
- Buffer = EepromAllocateCopyPool (PcdGet32 (PcdEepromMemorySize) + BlockSize, (UINT8 *) PcdGet64 (PcdEepromMemoryPointer));
+ Buffer = EepromAllocateCopyPool (PcdGet32 (PcdEepromMemorySize) + BlockSize, (UINT8 *) (UINTN) PcdGet64 (PcdEepromMemoryPointer));
if (Buffer == NULL) {
DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Unable to allocate buffer!\n", __FUNCTION__, __LINE__));
Status = EFI_OUT_OF_RESOURCES;
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPROM/I2cLib.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPROM/I2cLib.c
deleted file mode 100644
index 32f9d3f..0000000
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPROM/I2cLib.c
+++ /dev/null
@@ -1,1164 +0,0 @@
-/** @file
- I2C library instance.
-
- Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>
-
- 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 "I2cLib.h"
-
-//
-// List of I2C controllers
-//
-LPSS_PCI_DEVICE_INFO mLpssPciDeviceList[] = {
- {0, DEFAULT_PCI_BUS_NUMBER_SC, PCI_DEVICE_NUMBER_LPSS_I2C0, PCI_FUNCTION_NUMBER_LPSS_I2C0, LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*0), LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*0) + LPSS_I2C_TMP_BAR1_OFFSET},
- {0, DEFAULT_PCI_BUS_NUMBER_SC, PCI_DEVICE_NUMBER_LPSS_I2C0, PCI_FUNCTION_NUMBER_LPSS_I2C1, LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*1), LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*1) + LPSS_I2C_TMP_BAR1_OFFSET},
- {0, DEFAULT_PCI_BUS_NUMBER_SC, PCI_DEVICE_NUMBER_LPSS_I2C0, PCI_FUNCTION_NUMBER_LPSS_I2C2, LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*2), LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*2) + LPSS_I2C_TMP_BAR1_OFFSET},
- {0, DEFAULT_PCI_BUS_NUMBER_SC, PCI_DEVICE_NUMBER_LPSS_I2C0, PCI_FUNCTION_NUMBER_LPSS_I2C3, LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*3), LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*3) + LPSS_I2C_TMP_BAR1_OFFSET},
- {0, DEFAULT_PCI_BUS_NUMBER_SC, PCI_DEVICE_NUMBER_LPSS_I2C1, PCI_FUNCTION_NUMBER_LPSS_I2C4, LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*4), LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*4) + LPSS_I2C_TMP_BAR1_OFFSET},
- {0, DEFAULT_PCI_BUS_NUMBER_SC, PCI_DEVICE_NUMBER_LPSS_I2C1, PCI_FUNCTION_NUMBER_LPSS_I2C5, LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*5), LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*5) + LPSS_I2C_TMP_BAR1_OFFSET},
- {0, DEFAULT_PCI_BUS_NUMBER_SC, PCI_DEVICE_NUMBER_LPSS_I2C1, PCI_FUNCTION_NUMBER_LPSS_I2C6, LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*6), LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*6) + LPSS_I2C_TMP_BAR1_OFFSET},
- {0, DEFAULT_PCI_BUS_NUMBER_SC, PCI_DEVICE_NUMBER_LPSS_I2C1, PCI_FUNCTION_NUMBER_LPSS_I2C7, LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*7), LPSS_I2C0_TMP_BAR0 + (LPSS_I2C_TMP_BAR0_DELTA*7) + LPSS_I2C_TMP_BAR1_OFFSET}
-};
-#define LPSS_PCI_DEVICE_NUMBER (sizeof (mLpssPciDeviceList) / sizeof (LPSS_PCI_DEVICE_INFO))
-
-//
-// List of I2C controller clock values
-//
-LPSS_I2C_CLOCK_SCL_INFO mLPSS_I2C_CLOCK_SCL_INFO[] = {
- {0x244, 0x2D0, 0x64, 0xC8, 0x06, 0x13},
- {0x244, 0x2D0, 0x64, 0xC8, 0x06, 0x13},
- {0x244, 0x2D0, 0x64, 0xC8, 0x06, 0x13},
- {0x244, 0x2DA, 0x1E, 0x3C, 0x06, 0x13},
- {0x244, 0x2DA, 0x1E, 0x50, 0x06, 0x13},
- {0x244, 0x2D0, 0x69, 0xC8, 0x06, 0x13},
- {0x244, 0x2D0, 0x69, 0xC8, 0x06, 0x13},
- {0x244, 0x2D0, 0x70, 0xC8, 0x06, 0x13}
-};
-#define LPSS_I2C_CLOCK_SCL_INFO_NUMBER (sizeof (mLPSS_I2C_CLOCK_SCL_INFO) / sizeof (LPSS_I2C_CLOCK_SCL_INFO))
-
-//
-// List of I2C controller PAD settings
-//
-BXT_GPIO_PAD_INIT mLPSS_PAD_INFO[] = {
- BXT_GPIO_PAD_CONF (L"GPIO_124 LPSS_I2C0_SDA", M1, NA, NA, NA, NA, Wake_Disabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0000, WEST),
- BXT_GPIO_PAD_CONF (L"GPIO_125 LPSS_I2C0_SCL", M1, NA, NA, NA, NA, Wake_Disabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0008, WEST),
- BXT_GPIO_PAD_CONF (L"GPIO_126 LPSS_I2C1_SDA", M1, NA, NA, NA, NA, Wake_Disabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0010, WEST),
- BXT_GPIO_PAD_CONF (L"GPIO_127 LPSS_I2C1_SCL", M1, NA, NA, NA, NA, Wake_Disabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0018, WEST),
- BXT_GPIO_PAD_CONF (L"GPIO_128 LPSS_I2C2_SDA", M1, NA, NA, NA, NA, Wake_Disabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0020, WEST),
- BXT_GPIO_PAD_CONF (L"GPIO_129 LPSS_I2C2_SCL", M1, NA, NA, NA, NA, Wake_Disabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0028, WEST),
- BXT_GPIO_PAD_CONF (L"GPIO_130 LPSS_I2C3_SDA", M1, NA, NA, NA, NA, Wake_Disabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0030, WEST),
- BXT_GPIO_PAD_CONF (L"GPIO_131 LPSS_I2C3_SCL", M1, NA, NA, NA, NA, Wake_Disabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0038, WEST),
- BXT_GPIO_PAD_CONF (L"GPIO_132 LPSS_I2C4_SDA", M1, NA, NA, NA, NA, Wake_Disabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0040, WEST),
- BXT_GPIO_PAD_CONF (L"GPIO_133 LPSS_I2C4_SCL", M1, NA, NA, NA, NA, Wake_Disabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0048, WEST),
- BXT_GPIO_PAD_CONF (L"GPIO_134 LPSS_I2C5_SDA", M1, NA, NA, NA, NA, Wake_Disabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0050, WEST),
- BXT_GPIO_PAD_CONF (L"GPIO_135 LPSS_I2C5_SCL", M1, NA, NA, NA, NA, Wake_Disabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0058, WEST),
- BXT_GPIO_PAD_CONF (L"GPIO_136 LPSS_I2C6_SDA", M1, NA, NA, NA, NA, Wake_Disabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0060, WEST),
- BXT_GPIO_PAD_CONF (L"GPIO_137 LPSS_I2C6_SCL", M1, NA, NA, NA, NA, Wake_Disabled, P_20K_H, NA, NA, D1RxDRx1I, EnPu, GPIO_PADBAR + 0x0068, WEST),
- BXT_GPIO_PAD_CONF (L"GPIO_138 LPSS_I2C7_SDA", M1, NA, NA, NA, NA, Wake_Disabled, P_20K_H, NA, NA, D0RxDRx0I, EnPu, GPIO_PADBAR + 0x0070, WEST),
- BXT_GPIO_PAD_CONF (L"GPIO_139 LPSS_I2C7_SCL", M1, NA, NA, NA, NA, Wake_Disabled, P_20K_H, NA, NA, D0RxDRx0I, EnPu, GPIO_PADBAR + 0x0078, WEST)
-};
-
-BOOLEAN gI2cDebugFlag = FALSE;
-
-////
-//// Internal I2C functions
-////
-//
-// Desc: Clears the interrupts on this I2C controller
-// Input: I2cBaseAddress - Pointer to the MMIO base address for the I2C controller
-// Output: NA
-//
-VOID
-I2cClearInterrupts (
- IN UINT32 I2cBaseAddress
- )
-{
- MmioRead32 (I2cBaseAddress + R_IC_CLR_INTR);
- return;
-}
-
-//
-// Desc: Clears the TX Abort on this I2C controller
-// Input: I2cBaseAddress - Pointer to the MMIO base address for the I2C controller
-// Output: NA
-//
-VOID
-I2cClearTxAbort (
- IN UINT32 I2cBaseAddress
- )
-{
- MmioRead32 (I2cBaseAddress + R_IC_CLR_TX_ABRT);
- return;
-}
-
-//
-// Desc: Disable this I2C controller
-// Input: I2cBaseAddress - Pointer to the MMIO base address for the I2C controller
-// Output: Status - EFI_SUCCESS - I2C host controller is completely inactive
-// EFI_NOT_READY - I2C host controller is still in an enabled state
-//
-EFI_STATUS
-I2cDisable (
- IN UINT32 I2cBaseAddress
- )
-{
- UINT32 NumTries;
- EFI_STATUS Status;
-
- //
- // Initialize variables
- //
- Status = EFI_SUCCESS;
-
- //
- // Disable I2C controller
- //
- MmioWrite32 (I2cBaseAddress + R_IC_ENABLE, 0);
- NumTries = 10000; // 0.1 seconds
- while (0 != (MmioRead32 (I2cBaseAddress + R_IC_ENABLE_STATUS) & 0x03)) {
- MicroSecondDelay (10);
- NumTries --;
- if (0 == NumTries) {
- Status = EFI_NOT_READY;
- goto Exit;
- }
- }
-
-Exit:
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __LINE__, Status));
- }
- return Status;
-}
-
-/**
- Enable I2C host controller
-
- @param[in] I2CBaseAddress - BAR0 address of I2C host controller
-
- @retval EFI_SUCCESS - I2C host controller is in an enabled state.
- @retval EFI_NOT_READY - I2C host controller is still inactive.
-**/
-EFI_STATUS
-I2cEnable (
- IN UINT32 I2cBaseAddress
- )
-{
- UINT32 NumTries;
- EFI_STATUS Status;
-
- //
- // Initialize variables
- //
- NumTries = 10000; // 0.1 seconds
- Status = EFI_SUCCESS;
-
- //
- // Enable I2C controller
- //
- MmioWrite32 (I2cBaseAddress + R_IC_ENABLE, I2C_ENABLE_ENABLE);
- while (I2C_ENABLE_ENABLE != (MmioRead32 (I2cBaseAddress + R_IC_ENABLE_STATUS) & I2C_ENABLE_ENABLE)) {
- MicroSecondDelay (10);
- NumTries --;
- if (0 == NumTries) {
- Status = EFI_NOT_READY;
- goto Exit;
- }
- }
-
-Exit:
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __LINE__, Status));
- }
- return Status;
-}
-
-UINT16
-I2cGetTxAbortStatus (
- IN UINT32 I2cBaseAddress
- )
-{
- UINT16 TxAbortStatus;
-
- if (I2cBaseAddress == 0) {
- TxAbortStatus = 0xFFFF;
- } else {
- TxAbortStatus = (UINT16) (MmioRead32 (I2cBaseAddress + R_IC_TX_ABRT_SOURCE) & 0xFFFF);
- }
- return TxAbortStatus;
-}
-
-/**
- Get I2C controller raw interrupt status
-
- @param[in] I2CBaseAddress - BAR0 address of I2C host controller
-
- @retval UINT16 - Raw interrupt status bit flags
-**/
-UINT16
-I2cGetRawStatus (
- IN UINT32 I2cBaseAddress
- )
-{
- UINT16 RawStatus;
-
- if (I2cBaseAddress == 0) {
- RawStatus = 0xFFFF;
- } else {
- RawStatus = (UINT16) (MmioRead32 (I2cBaseAddress + R_IC_RAW_INTR_STAT) & 0x3FFF);
- }
-
- return RawStatus;
-}
-
-/**
- Get I2C controller RX FIFO count
-
- @param[in] I2CBaseAddress - BAR0 address of I2C host controller
-
- @retval UINT16 - RX FIFO count
-**/
-UINT16
-I2cGetRxFifo (
- IN UINT32 I2cBaseAddress
- )
-{
- UINT16 RxFifo;
-
- if (I2cBaseAddress == 0) {
- RxFifo = 0xFFFF;
- } else {
- RxFifo = (UINT16) (MmioRead32 (I2cBaseAddress + R_IC_RXFLR) & 0x01FF);
- }
-
- return RxFifo;
-}
-
-/**
- Get I2C controller status
-
- @param[in] I2CBaseAddress - BAR0 address of I2C host controller
-
- @retval UINT16 - Status bit flags
-**/
-UINT16
-I2cGetStatus (
- IN UINT32 I2cBaseAddress
- )
-{
- UINT16 I2cStatus;
-
- if (I2cBaseAddress == 0) {
- I2cStatus = 0xFFFF;
- } else {
- I2cStatus = (UINT16) (MmioRead32 (I2cBaseAddress + R_IC_STATUS) & 0x007F);
- }
-
- return I2cStatus;
-}
-
-/**
- Get I2C controller TX FIFO count
-
- @param[in] I2CBaseAddress - BAR0 address of I2C host controller
-
- @retval UINT16 - TX FIFO count
-**/
-UINT16
-I2cGetTxFifo (
- IN UINT32 I2cBaseAddress
- )
-{
- UINT16 TxFifo;
-
- if (I2cBaseAddress == 0) {
- TxFifo = 0xFFFF;
- } else {
- TxFifo = (UINT16) (MmioRead32 (I2cBaseAddress + R_IC_TXFLR) & 0x01FF);
- }
-
- return TxFifo;
-}
-
-EFI_STATUS
-I2cProgramPad (
- IN UINT8 Bus
- )
-{
- UINT8 index;
- EFI_STATUS Status;
-
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Programming PADs for bus #%d\n", __FUNCTION__, __LINE__, Bus));
-
- //
- // Initialize variables
- //
- Status = EFI_SUCCESS;
-
- //
- // Sanity checks
- //
- if (Bus > MAX_I2C_BUS) {
- Status = EFI_INVALID_PARAMETER;
- goto Exit;
- }
-
- //
- // Program SDA/SCL
- //
- for (index = 0; index < 2; index++) {
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Programming PAD %s\n", __FUNCTION__, __LINE__, mLPSS_PAD_INFO[(Bus * 2) + index].pad_name));
- GpioPadConfigTable (1, &mLPSS_PAD_INFO[(Bus * 2) + index]);
- }
-
- //
- // Pause a bit
- //
- MicroSecondDelay (EEPROM_ROUTINE_DELAY);
-
-Exit:
- return Status;
-}
-
-/**
- Set the I2C controller bus clock frequency.
-
- The software and controller do a best case effort of using the specified
- frequency for the I2C bus. If the frequency does not match exactly then
- the controller will use a slightly lower frequency for the I2C to avoid
- exceeding the operating conditions for any of the I2C devices on the bus.
- For example if 400 KHz was specified and the controller's divide network
- only supports 402 KHz or 398 KHz then the controller would be set to 398
- KHz. However if the desired frequency is 400 KHz and the controller only
- supports 1 MHz and 100 KHz then this routine would return EFI_UNSUPPORTED.
-
- @param[in] Bus - I2C Bus number to which the I2C device has been connected
- @param[in] I2CBaseAddress - BAR0 address of I2C host controller
-
- @retval EFI_SUCCESS - The bus frequency was set successfully.
-**/
-EFI_STATUS
-I2cSetBusFrequency (
- IN UINT8 Bus,
- IN UINT32 I2cBaseAddress
- )
-{
- EFI_STATUS Status;
-
- //
- // Initialize variables
- //
- Status = EFI_SUCCESS;
-
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - I2cBusFrequencySet bus: %d\n", __FUNCTION__, __LINE__, Bus));
- ASSERT ((Bus < LPSS_I2C_CLOCK_SCL_INFO_NUMBER));
- //
- // Set the 100 KHz clock divider according to SV result and I2C spec
- //
- MmioWrite32 (I2cBaseAddress + R_IC_SS_SCL_HCNT, (UINT16) mLPSS_I2C_CLOCK_SCL_INFO[Bus].SS_SCL_HCNT);
- MmioWrite32 (I2cBaseAddress + R_IC_SS_SCL_LCNT, (UINT16) mLPSS_I2C_CLOCK_SCL_INFO[Bus].SS_SCL_LCNT);
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - I2cBusFrequencySet R_IC_SS_SCL_HCNT: 0x%08X, R_IC_SS_SCL_LCNT: 0x%08X\r\n",
- __FUNCTION__,
- __LINE__,
- MmioRead32 (I2cBaseAddress + R_IC_SS_SCL_HCNT),
- MmioRead32 (I2cBaseAddress + R_IC_SS_SCL_LCNT)));
- //
- // Set the 400 KHz clock divider according to SV result and I2C spec
- //
- MmioWrite32 (I2cBaseAddress + R_IC_FS_SCL_HCNT, (UINT16) mLPSS_I2C_CLOCK_SCL_INFO[Bus].FS_SCL_HCNT);
- MmioWrite32 (I2cBaseAddress + R_IC_FS_SCL_LCNT, (UINT16) mLPSS_I2C_CLOCK_SCL_INFO[Bus].FS_SCL_LCNT);
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - I2cBusFrequencySet R_IC_FS_SCL_HCNT: 0x%08X, R_IC_FS_SCL_LCNT: 0x%08X\r\n",
- __FUNCTION__,
- __LINE__,
- MmioRead32 (I2cBaseAddress + R_IC_FS_SCL_HCNT),
- MmioRead32 (I2cBaseAddress + R_IC_FS_SCL_LCNT)));
- //
- // Set the 3.4MHz clock divider according to SV result and I2C spec
- //
- MmioWrite32 (I2cBaseAddress + R_IC_HS_SCL_HCNT, (UINT16)mLPSS_I2C_CLOCK_SCL_INFO[Bus].HS_SCL_HCNT);
- MmioWrite32 (I2cBaseAddress + R_IC_HS_SCL_LCNT, (UINT16)mLPSS_I2C_CLOCK_SCL_INFO[Bus].HS_SCL_LCNT);
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - I2cBusFrequencySet R_IC_HS_SCL_HCNT: 0x%08X, R_IC_HS_SCL_LCNT: 0x%08X\r\n",
- __FUNCTION__,
- __LINE__,
- MmioRead32 (I2cBaseAddress + R_IC_HS_SCL_HCNT),
- MmioRead32 (I2cBaseAddress + R_IC_HS_SCL_LCNT)));
-
- //
- // Set hold register
- //
- MmioWrite32 (I2cBaseAddress + R_IC_SDA_HOLD, (UINT16) 0x06);
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - I2cBusFrequencySet R_IC_SDA_HOLD: 0x%08X\r\n", __FUNCTION__, __LINE__, MmioRead32 (I2cBaseAddress + R_IC_SDA_HOLD)));
-
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __LINE__, Status));
- }
- return Status;
-}
-
-/**
- Program LPSS I2C PCI controller's BAR0 and enable memory decode.
-
- @param[in] Bus - I2C Bus number to which the I2C device has been connected
-
- @retval EFI_SUCCESS - I2C controller's BAR0 is programmed and memory decode enabled.
- @retval EFI_NOT_READY - I2C controller's is not exist or its function has been disabled.
- @retval EFI_DEVICE_ERROR - I2C controller can't be enabled.
-**/
-EFI_STATUS
-ProgramPciLpssI2C (
- IN UINT8 Bus
- )
-{
- UINT32 Data32;
- UINT32 I2CBar0;
- UINT32 I2CBar1;
- UINTN PciMmBase;
- UINT32 PmcBase;
- EFI_STATUS Status;
- UINT32 I2cPortDisable[] = {
- B_PMC_FUNC_DIS_LPSS_I2C0,
- B_PMC_FUNC_DIS_LPSS_I2C1,
- B_PMC_FUNC_DIS_LPSS_I2C2,
- B_PMC_FUNC_DIS_LPSS_I2C3,
- B_PMC_FUNC_DIS_LPSS_I2C4,
- B_PMC_FUNC_DIS_LPSS_I2C5,
- B_PMC_FUNC_DIS_LPSS_I2C6,
- B_PMC_FUNC_DIS_LPSS_I2C7
- };
-
- //
- // Initialize variables
- //
- PciMmBase = 0;
- Status = EFI_SUCCESS;
-
- //
- // Set PADs to I2C mode
- //
- I2cProgramPad (Bus);
-
- //
- // Check PMC disable register
- //
- PmcBase = PMC_BASE_ADDRESS;
- Data32 = MmioRead32 (PmcBase + R_PMC_FUNC_DIS);
-
- if (Data32 == 0xFFFFFFFF) {
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - ProgramPciLpssI2C() PMC disable register not available. [%08x]\n", __FUNCTION__, __LINE__, PMC_BASE_ADDRESS));
- } else {
- if ((Data32 & I2cPortDisable[Bus]) != 0) {
- // This I2C port is disabled. Turn it on.
- Data32 &= ~I2cPortDisable[Bus];
- MmioWrite32 (PmcBase + R_PMC_FUNC_DIS, Data32);
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - ProgramPciLpssI2C() enable I2C controller #%x\n", __FUNCTION__, __LINE__, Bus));
- // Make sure it took.
- if (Data32 != MmioRead32 (PmcBase + R_PMC_FUNC_DIS)) {
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - ProgramPciLpssI2C() failed to enable I2C controller #%x [%08x:%08x]\n",
- __FUNCTION__,
- __LINE__,
- Bus,
- Data32,
- MmioRead32 (PmcBase + R_PMC_FUNC_DIS)));
- Status = EFI_DEVICE_ERROR;
- goto Exit;
- }
- }
- }
-
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - ProgramPciLpssI2C()------------BusNo=%x\n", __FUNCTION__, __LINE__, Bus));
-
- PciMmBase = MmPciAddress (
- mLpssPciDeviceList[Bus].Segment,
- mLpssPciDeviceList[Bus].BusNum,
- mLpssPciDeviceList[Bus].DeviceNum,
- mLpssPciDeviceList[Bus].FunctionNum,
- 0
- );
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Program Pci Lpss I2C Device %x %x %x PciMmBase:%x\n",
- __FUNCTION__,
- __LINE__,
- mLpssPciDeviceList[Bus].BusNum,
- mLpssPciDeviceList[Bus].DeviceNum,
- mLpssPciDeviceList[Bus].FunctionNum, PciMmBase));
-
- //
- // Check if device present
- //
- if (MmioRead32 (PciMmBase) != 0xFFFFFFFF) {
- if ((MmioRead32 (PciMmBase + R_LPSS_IO_STSCMD) & B_LPSS_IO_STSCMD_MSE)) {
- //
- // In Pei stage, we always disable Bus master, and memory space enabling for BAR re-programming
- // In DXE stage, will read existing BAR value instead of re-programming
- //
- I2CBar0 = MmioRead32 (PciMmBase + R_LPSS_IO_BAR) & B_LPSS_IO_BAR_BA;
- I2CBar1 = MmioRead32 (PciMmBase + R_LPSS_IO_BAR1) & B_LPSS_IO_BAR_BA;
- if ((I2CBar0 != (UINT32) mLpssPciDeviceList[Bus].Bar0) || (I2CBar1 != (UINT32) mLpssPciDeviceList[Bus].Bar1)) {
- mLpssPciDeviceList[Bus].Bar0 = MmioRead32 (PciMmBase + R_LPSS_IO_BAR) & B_LPSS_IO_BAR_BA; // get the address allocated.
- mLpssPciDeviceList[Bus].Bar1 = MmioRead32 (PciMmBase + R_LPSS_IO_BAR1) & B_LPSS_IO_BAR_BA;
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Get bar0:0x%x bar1:0x%x\n",
- __FUNCTION__,
- __LINE__,
- mLpssPciDeviceList[Bus].Bar0,
- mLpssPciDeviceList[Bus].Bar1));
- }
- } else {
- //
- // Program BAR 0
- //
- ASSERT (((mLpssPciDeviceList[Bus].Bar0 & B_LPSS_IO_BAR_BA) == mLpssPciDeviceList[Bus].Bar0) && (mLpssPciDeviceList[Bus].Bar0 != 0));
- MmioWrite32 ((UINTN) (PciMmBase + R_LPSS_IO_BAR), (UINT32) (mLpssPciDeviceList[Bus].Bar0 & B_LPSS_IO_BAR_BA));
- //
- // Program BAR 1
- //
- ASSERT (((mLpssPciDeviceList[Bus].Bar1 & B_LPSS_IO_BAR1_BA) == mLpssPciDeviceList[Bus].Bar1) && (mLpssPciDeviceList[Bus].Bar1 != 0));
- MmioWrite32 ((UINTN) (PciMmBase + R_LPSS_IO_BAR1), (UINT32) (mLpssPciDeviceList[Bus].Bar1 & B_LPSS_IO_BAR1_BA));
- //
- // Bus Master Enable & Memory Space Enable
- //
- MmioOr32 ((UINTN) (PciMmBase + R_LPSS_IO_STSCMD), (UINT32) (B_LPSS_IO_STSCMD_BME | B_LPSS_IO_STSCMD_MSE));
- ASSERT (MmioRead32 (mLpssPciDeviceList[Bus].Bar0) != 0xFFFFFFFF);
- }
-
- //
- // Release Resets
- //
- MmioWrite32 (mLpssPciDeviceList[Bus].Bar0 + R_LPSS_IO_MEM_RESETS, B_LPSS_IO_MEM_HC_RESET_REL | B_LPSS_IO_MEM_iDMA_RESET_REL);
-
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - ProgramPciLpssI2C() Programmed()\n", __FUNCTION__, __LINE__));
- Status = EFI_SUCCESS;
- goto Exit;
- } else {
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - Pci Lpss I2C Device %x %x %x does not exist!\n",
- __FUNCTION__,
- __LINE__,
- mLpssPciDeviceList[Bus].BusNum,
- mLpssPciDeviceList[Bus].DeviceNum,
- mLpssPciDeviceList[Bus].FunctionNum));
-
- Status = EFI_NOT_READY;
- goto Exit;
- }
-
-Exit:
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __LINE__, Status));
- }
- return Status;
-}
-
-////
-//// Public I2C functions
-////
-//
-// Desc: Initializes the controller and returns the MMIO base address
-// Input: Bus - I2C controller, 0 based
-// Address - 7-bit slave address
-// Speed - Uses the I2C_SPEED enum to set the controller speed
-// I2cBaseAddress - Pointer to the MMIO base address for the I2C controller
-// Output: EFI_SUCCESS - Initialization completed successfully
-// EFI_DEVICE_ERROR - I2C controller error
-// EFI_INVALID_PARAMETER - Invalid input parameter
-//
-EFI_STATUS
-I2cInit (
- IN UINT8 Bus,
- IN UINT16 Address,
- IN UINT8 Speed,
- IN OUT UINT32 *I2cBaseAddress
- )
-{
- UINT32 BaseAddress;
- UINTN PciMmBase;
- EFI_STATUS Status;
-
- //
- // Sanity checks
- //
- if (Bus > MAX_I2C_BUS) {
- Status = EFI_INVALID_PARAMETER;
- goto Exit;
- }
- if (Address > MAX_I2C_ADDRESS) {
- Status = EFI_INVALID_PARAMETER;
- goto Exit;
- }
- if (Speed > Max_Speed) {
- Status = EFI_INVALID_PARAMETER;
- goto Exit;
- }
- if (I2cBaseAddress == NULL) {
- Status = EFI_INVALID_PARAMETER;
- goto Exit;
- }
-
- //
- // Initialize variables
- //
- *I2cBaseAddress = 0;
-
- //
- // Get current MMIO base address
- //
- PciMmBase = MmPciAddress (
- mLpssPciDeviceList[Bus].Segment,
- mLpssPciDeviceList[Bus].BusNum,
- mLpssPciDeviceList[Bus].DeviceNum,
- mLpssPciDeviceList[Bus].FunctionNum,
- 0
- );
- BaseAddress = MmioRead32 (PciMmBase + R_LPSS_IO_BAR) & B_LPSS_IO_BAR_BA;
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - I2CBaseAddress = 0x%08x:0x%08x \n", __FUNCTION__, __LINE__, BaseAddress, (UINT32) mLpssPciDeviceList[Bus].Bar0));
-
- //
- // Skip reinit if targeting the same I2C bus
- //
- if (BaseAddress == (UINT32) mLpssPciDeviceList[Bus].Bar0) {
- MmioWrite32 (BaseAddress + R_IC_TAR, Address);
- *I2cBaseAddress = BaseAddress;
- Status = EFI_SUCCESS;
- goto Exit;
- }
-
- //
- // Program I2C controller
- //
- Status = ProgramPciLpssI2C (Bus);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - ProgramPciLpssI2C failed! %r\n", __FUNCTION__, __LINE__, Status));
- goto Exit;
- }
-
- //
- // Retrieve I2C MMIO base address
- //
- BaseAddress = (UINT32) mLpssPciDeviceList[Bus].Bar0;
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - I2CBaseAddress = 0x%x \n", __FUNCTION__, __LINE__, BaseAddress));
-
- //
- // Reset controller
- //
- Status = I2cReset (BaseAddress, Bus, Address, Speed);
- if (EFI_ERROR (Status)) {
- goto Exit;
- }
-
- //
- // Pause a bit
- //
- MicroSecondDelay (EEPROM_ROUTINE_DELAY);
-
- //
- // Pass out MMIO base
- //
- *I2cBaseAddress = BaseAddress;
- Status = EFI_SUCCESS;
-
-Exit:
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __LINE__, Status));
- }
- return Status;
-}
-
-//
-// Desc: Polls the I2C controller with reads until it responds.
-// Input: I2cBaseAddress - Pointer to the MMIO base address for the I2C controller
-// Output: EFI_SUCCESS - Initialization completed successfully
-// EFI_DEVICE_ERROR - I2C controller error
-//
-EFI_STATUS
-I2cPoll (
- IN UINT32 I2cBaseAddress
- )
-{
- EFI_STATUS Status;
- UINT16 Timeout;
- UINT8 Value;
-
- //
- // Use a read to poll the slave
- //
- Status = EFI_DEVICE_ERROR;
- Timeout = 0;
- while (EFI_ERROR (Status) && Timeout < 1000) {
- MicroSecondDelay (10);
- Status = I2cRead (I2cBaseAddress, &Value, TRUE, TRUE);
- Timeout++;
- }
-
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __LINE__, Status));
- }
- return Status;
-}
-
-//
-// Desc: Read a byte from the I2C controller
-// Input: I2cBaseAddress - MMIO base address for the I2C controller
-// Data - Pointer to where to store the data
-// Start - Send start bit?
-// End - Send end bit?
-// Output: EFI_SUCCESS - Read completed successfully
-// EFI_DEVICE_ERROR - I2C controller error
-// EFI_INVALID_PARAMETER - Invalid input parameter
-//
-EFI_STATUS
-I2cRead (
- IN UINT32 I2cBaseAddress,
- IN OUT UINT8 *Data,
- IN BOOLEAN Start,
- IN BOOLEAN End
- )
-{
- UINT32 Data32;
- EFI_STATUS Status;
-
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Starting\n", __FUNCTION__, __LINE__));
-
- //
- // Sanity checks
- //
- if (Data == NULL) {
- Status = EFI_INVALID_PARAMETER;
- goto Exit;
- }
-
- //
- // Send CMD for read
- //
- Data32 = B_READ_CMD;
- Status = I2cSendCommand (I2cBaseAddress, &Data32, Start, End);
- *Data = (UINT8) (Data32 & 0xFF);
-
-Exit:
- //
- // Pause a bit
- //
- MicroSecondDelay (EEPROM_ROUTINE_DELAY);
- //
- // Display error messages
- //
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __LINE__, Status));
- }
- return Status;
-}
-
-//
-// Desc: Resets the I2C controller into a known good state
-// Input: I2cBaseAddress - MMIO base address for the I2C controller
-// Bus - I2C controller, 0 based
-// Address - 7-bit slave address
-// Speed - Uses the I2C_SPEED enum to set the controller speed
-// Output: EFI_SUCCESS - Write completed successfully
-// EFI_DEVICE_ERROR - I2C controller error
-// EFI_INVALID_PARAMETER - Invalid input parameter
-//
-EFI_STATUS
-I2cReset (
- IN UINT32 I2cBaseAddress,
- IN UINT8 Bus,
- IN UINT16 Address,
- IN UINT8 Speed
- )
-{
- UINT16 I2cMode;
- UINT32 NumTries;
- EFI_STATUS Status;
-
- //
- // Wait for master activity to stop
- //
- NumTries = 10000; // 1 seconds
- while ((STAT_MST_ACTIVITY == (I2cGetStatus (I2cBaseAddress) & STAT_MST_ACTIVITY))) {
- MicroSecondDelay (10);
- NumTries--;
- if (0 == NumTries) {
- DEBUG ((DEBUG_ERROR, "%a(#%4d) - Try timeout\n", __FUNCTION__, __LINE__));
- Status = EFI_DEVICE_ERROR;
- goto Exit;
- }
- }
- //
- // Abort controller
- //
- MmioWrite32 (I2cBaseAddress + R_IC_ENABLE, I2C_ENABLE_ABORT);
- MicroSecondDelay (10 * EEPROM_ROUTINE_DELAY);
- //
- // Disable I2C controller
- //
- Status = I2cDisable (I2cBaseAddress);
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - I2cDisable Status = %r\n", __FUNCTION__, __LINE__, Status));
- if (EFI_ERROR (Status)) {
- goto Exit;
- }
- MicroSecondDelay (EEPROM_ROUTINE_DELAY);
- //
- // Set I2C controller speed
- //
- I2cSetBusFrequency (Bus, I2cBaseAddress); // Set I2cMode
- MicroSecondDelay (EEPROM_ROUTINE_DELAY);
- switch (Speed) {
- case Standard_Speed:
- //100K
- I2cMode = V_SPEED_STANDARD;
- break;
-
- case Fast_Speed:
- //400K
- I2cMode = V_SPEED_FAST;
- break;
-
- case High_Speed:
- //3.4M
- I2cMode = V_SPEED_HIGH;
- break;
-
- default:
- //400K
- I2cMode = V_SPEED_FAST;
- }
- I2cMode |= B_IC_RESTART_EN | B_IC_SLAVE_DISABLE | B_MASTER_MODE;
- //
- // Set slave address
- //
- MmioWrite32 (I2cBaseAddress + R_IC_INTR_MASK, 0x0);
- if (Address > MAX_I2C_ADDRESS) {
- Address = (Address & 0x3FF) | IC_TAR_10BITADDR_MASTER;
- }
- MmioWrite32 (I2cBaseAddress + R_IC_TAR, Address);
- MicroSecondDelay (EEPROM_ROUTINE_DELAY);
- //
- // Set RX & TX FIFO full threshold to 1 byte
- //
- MmioWrite32 (I2cBaseAddress + R_IC_RX_TL, 0);
- MmioWrite32 (I2cBaseAddress + R_IC_TX_TL, 0);
- MicroSecondDelay (EEPROM_ROUTINE_DELAY);
- //
- // Set I2C Mode
- //
- MmioWrite32 (I2cBaseAddress + R_IC_CON, I2cMode);
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - I2cMode: 0x%04x\r\n", __FUNCTION__, __LINE__, I2cMode));
- MicroSecondDelay (EEPROM_ROUTINE_DELAY);
- //
- // Enable I2C controller
- //
- Status = I2cEnable (I2cBaseAddress);
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - I2cEnable Status = %r\n", __FUNCTION__, __LINE__, Status));
- if (EFI_ERROR (Status)) {
- goto Exit;
- }
- MicroSecondDelay (EEPROM_ROUTINE_DELAY);
- //
- // Clear TX abort
- //
- I2cClearTxAbort (I2cBaseAddress);
- MicroSecondDelay (EEPROM_ROUTINE_DELAY);
- //
- // Clear interrupts
- //
- I2cClearInterrupts (I2cBaseAddress);
- MicroSecondDelay (EEPROM_ROUTINE_DELAY);
-
-Exit:
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __LINE__, Status));
- }
- return Status;
-}
-
-//
-// Desc: Write a byte to the I2C controller
-// Input: I2cBaseAddress - MMIO base address for the I2C controller
-// Data - Data from the I2C controller
-// Start - Send start bit?
-// End - Send end bit?
-// Output: EFI_SUCCESS - Write completed successfully
-// EFI_DEVICE_ERROR - I2C controller error
-// EFI_INVALID_PARAMETER - Invalid input parameter
-//
-EFI_STATUS
-I2cSendCommand (
- IN UINT32 I2cBaseAddress,
- IN UINT32 *Data,
- IN BOOLEAN Start,
- IN BOOLEAN End
- )
-{
- BOOLEAN CommandSent;
- UINT32 Count;
- UINT32 CountOut;
- UINT32 Data32;
- BOOLEAN ReadFlag;
- EFI_STATUS Status;
- UINT16 TxAbortStatus;
-
- //
- // Initialize variables
- //
- CommandSent = FALSE;
- Count = 0;
- CountOut = 0x00000100;
- Status = EFI_NOT_READY;
- if ((*Data & B_READ_CMD) == B_READ_CMD) {
- ReadFlag = TRUE;
- } else {
- ReadFlag = FALSE;
- }
-
- //
- // Send a command byte
- //
- while (CountOut-- > 0) {
- //
- // Check for NACK
- //
- if ((I2cGetRawStatus (I2cBaseAddress) & I2C_INTR_TX_ABRT) != 0) {
- TxAbortStatus = I2cGetTxAbortStatus (I2cBaseAddress);
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - TX ABRT [%04x]\n", __FUNCTION__, __LINE__, TxAbortStatus));
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - RX FIFO = %04x\n", __FUNCTION__, __LINE__, I2cGetRxFifo (I2cBaseAddress)));
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - TX FIFO = %04x\n", __FUNCTION__, __LINE__, I2cGetTxFifo (I2cBaseAddress)));
- //
- // Clear TX Abort
- //
- I2cClearTxAbort (I2cBaseAddress);
- MicroSecondDelay (EEPROM_WRITE_TIMEOUT);
- //
- // Clear interrupts
- //
- I2cClearInterrupts (I2cBaseAddress);
- MicroSecondDelay (EEPROM_WRITE_TIMEOUT);
- //
- // Set status
- //
- if (TxAbortStatus & (I2C_ABRT_7B_ADDR_NOACK | I2C_ABRT_10ADDR1_NOACK | I2C_ABRT_10ADDR2_NOACK)) {
- DEBUG ((DEBUG_ERROR, "%a(#%4d) - Nobody home!\n", __FUNCTION__, __LINE__));
- Status = EFI_NO_RESPONSE;
- } else {
- Status = EFI_DEVICE_ERROR;
- }
- goto Exit;
- }
- //
- // Determine if another byte was received and we were expecting it
- //
- if (((I2cGetStatus (I2cBaseAddress) & STAT_RFNE) != 0) && ReadFlag) {
- *Data = MmioRead32 (I2cBaseAddress + R_IC_DATA_CMD) & 0xFF;
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - MmioRead32, byte 0x%02x was received [%d:%d]\n", __FUNCTION__, __LINE__, *Data, Start, End));
- MicroSecondDelay (FIFO_WRITE_DELAY);
- //
- // Now empty the RX FIFO if stop bit set
- //
- while (End && ((I2cGetStatus (I2cBaseAddress) & STAT_RFNE) == STAT_RFNE)) {
- MmioRead32 (I2cBaseAddress + R_IC_DATA_CMD);
- MicroSecondDelay (FIFO_WRITE_DELAY);
- }
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - RX FIFO = %04x\n", __FUNCTION__, __LINE__, I2cGetRxFifo (I2cBaseAddress)));
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - TX FIFO = %04x\n", __FUNCTION__, __LINE__, I2cGetTxFifo (I2cBaseAddress)));
- Status = EFI_SUCCESS;
- goto Exit;
- }
- //
- // Wait for room in TX buffer
- //
- if ((I2cGetStatus (I2cBaseAddress) & STAT_TFNF) == 0) {
- MicroSecondDelay (FIFO_WRITE_DELAY);
- continue;
- }
- if (!CommandSent) {
- //
- // Send CMD
- //
- Data32 = *Data;
- if (Start) Data32 |= B_CMD_RESTART;
- if (End) Data32 |= B_CMD_STOP;
- MmioWrite32 (I2cBaseAddress + R_IC_DATA_CMD, Data32);
- CommandSent = TRUE;
- }
- //
- // Add a small delay to work around some odd behavior being seen. Without this delay bytes get dropped.
- //
- MicroSecondDelay (EEPROM_WRITE_TIMEOUT);
- //
- // Time out check for write CMD
- //
- while (!ReadFlag) {
- if ((I2cGetRawStatus (I2cBaseAddress) & I2C_INTR_TX_ABRT) != 0) {
- TxAbortStatus = I2cGetTxAbortStatus (I2cBaseAddress);
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - TX ABRT [%04x]\n", __FUNCTION__, __LINE__, TxAbortStatus));
- //
- // Clear TX Abort
- //
- I2cClearTxAbort (I2cBaseAddress);
- MicroSecondDelay (EEPROM_WRITE_TIMEOUT);
- //
- // Clear interrupts
- //
- I2cClearInterrupts (I2cBaseAddress);
- MicroSecondDelay (EEPROM_WRITE_TIMEOUT);
- //
- // Set status
- //
- if (TxAbortStatus & (I2C_ABRT_7B_ADDR_NOACK | I2C_ABRT_10ADDR1_NOACK | I2C_ABRT_10ADDR2_NOACK)) {
- DEBUG ((DEBUG_ERROR, "%a(#%4d) - Nobody home!\n", __FUNCTION__, __LINE__));
- Status = EFI_NO_RESPONSE;
- } else {
- Status = EFI_DEVICE_ERROR;
- }
- }
- if (I2cGetTxFifo (I2cBaseAddress) == 0) {
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - MmioRead32, byte 0x%04x was sent [%d:%d]\n", __FUNCTION__, __LINE__, Data32, Start, End));
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - RX FIFO = %04x\n", __FUNCTION__, __LINE__, I2cGetRxFifo (I2cBaseAddress)));
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - TX FIFO = %04x\n", __FUNCTION__, __LINE__, I2cGetTxFifo (I2cBaseAddress)));
- Status = EFI_SUCCESS;
- goto Exit;
- }
- MicroSecondDelay (EEPROM_WRITE_TIMEOUT);
- if (Count++ < 1024) { //to avoid sys hung without ul-pmc device on RVP
- continue; //Waiting the last request to get data and make (ReceiveDataEnd > ReadBuffer) =TRUE.
- } else {
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - hardware timeout, 1024 times try!\n", __FUNCTION__, __LINE__));
- Status = EFI_TIMEOUT;
- goto Exit;
- }
- }
- }
-
- //
- // Check for count out
- //
- if (CountOut == 0) {
- Status = EFI_TIMEOUT;
- }
-
-Exit:
- //
- // Pause a bit
- //
- MicroSecondDelay (EEPROM_ROUTINE_DELAY);
- //
- // Display error messages
- //
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r [%x]\n", __FUNCTION__, __LINE__, Status, CountOut));
- }
- return Status;
-}
-
-//
-// Desc: Set I2C target slave offset
-// Input: I2cBaseAddress - MMIO base address for the I2C controller
-// Offset - Pointer to offset data
-// Size - Size of the offset data
-// Output: EFI_SUCCESS - Write completed successfully
-// EFI_DEVICE_ERROR - I2C controller error
-// EFI_INVALID_PARAMETER - Invalid input parameter
-//
-EFI_STATUS
-I2cSetOffset (
- IN UINT32 I2cBaseAddress,
- IN UINT8 *Offset,
- IN UINT8 Size
- )
-{
- UINT8 index;
- EFI_STATUS Status;
-
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Starting\n", __FUNCTION__, __LINE__));
-
- //
- // Sanity checks
- //
- if (Offset == NULL) {
- Status = EFI_INVALID_PARAMETER;
- goto Exit;
- }
- if (Size == 0) {
- Status = EFI_INVALID_PARAMETER;
- goto Exit;
- }
- //
- // Set offset
- //
- for (index = 0; index < Size; index++) {
- if (index == 0) {
- //
- // First byte of the offset
- //
- Status = I2cWrite (I2cBaseAddress, Offset[index], TRUE, FALSE);
- } else {
- Status = I2cWrite (I2cBaseAddress, Offset[index], FALSE, FALSE);
- }
- if (EFI_ERROR (Status)) {
- goto Exit;
- }
- //
- // Pause a bit
- //
- MicroSecondDelay (EEPROM_WRITE_TIMEOUT);
- }
-
-Exit:
- //
- // Pause a bit
- //
- MicroSecondDelay (EEPROM_ROUTINE_DELAY);
- //
- // Display error messages
- //
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __LINE__, Status));
- }
- return Status;
-}
-
-//
-// Desc: Write a byte to the I2C controller
-// Input: I2cBaseAddress - MMIO base address for the I2C controller
-// Data - Data from the I2C controller
-// Start - Send start bit?
-// End - Send end bit?
-// Output: EFI_SUCCESS - Write completed successfully
-// EFI_DEVICE_ERROR - I2C controller error
-// EFI_INVALID_PARAMETER - Invalid input parameter
-//
-EFI_STATUS
-I2cWrite (
- IN UINT32 I2cBaseAddress,
- IN UINT8 Data,
- IN BOOLEAN Start,
- IN BOOLEAN End
- )
-{
- UINT32 Data32;
- EFI_STATUS Status;
-
- if (gI2cDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Starting\n", __FUNCTION__, __LINE__));
-
- //
- // Send CMD for write
- //
- Data32 = Data;
- Status = I2cSendCommand (I2cBaseAddress, &Data32, Start, End);
- //
- // Pause a bit
- //
- MicroSecondDelay (EEPROM_ROUTINE_DELAY);
- //
- // Display error messages
- //
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __LINE__, Status));
- }
- return Status;
-}
-
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPROM/I2cLib.h b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPROM/I2cLib.h
deleted file mode 100644
index 4134caa..0000000
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EEPROM/I2cLib.h
+++ /dev/null
@@ -1,181 +0,0 @@
-/** @file
- Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
-
- 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.
-
-**/
-
-#ifndef _EEPROM_I2C_LIB_
-#define _EEPROM_I2C_LIB_
-////
-//// Header files
-////
-#include <Uefi.h>
-
-#include <Library/BaseLib.h>
-#include <Library/DebugLib.h>
-#include <Library/EepromDataLib.h>
-#include <Library/GpioLib.h>
-#include <Library/PcdLib.h>
-#include <Library/TimerLib.h>
-
-#include <PlatformBaseAddresses.h>
-#include <SaAccess.h>
-#include <ScAccess.h>
-#include <ScRegs/RegsI2c.h>
-
-//
-// Defines
-//
-#define EEPROM_WRITE_TIMEOUT 5
-#define FIFO_WRITE_DELAY 5
-#define EEPROM_ROUTINE_DELAY 10
-#define INVALID_I2C_ADDRESS 0xFF
-#define MAX_I2C_ADDRESS 0x7F
-#define MAX_I2C_BUS 7
-
-//
-// Enums
-//
-typedef enum {
- Standard_Speed = 1,
- Fast_Speed = 2,
- High_Speed = 3,
- Max_Speed = 3
-} I2C_SPEED;
-
-//
-// Externs
-//
-extern BOOLEAN gI2cDebugFlag;
-
-//
-// Structures
-//
-typedef struct _LPSS_PCI_DEVICE_INFO {
- UINT8 Segment;
- UINT8 BusNum;
- UINT8 DeviceNum;
- UINT8 FunctionNum;
- UINT32 Bar0;
- UINT32 Bar1;
-} LPSS_PCI_DEVICE_INFO;
-
-typedef struct _LPSS_I2C_CLOCK_SCL_INFO {
- UINT16 SS_SCL_HCNT;
- UINT16 SS_SCL_LCNT;
- UINT16 FS_SCL_HCNT;
- UINT16 FS_SCL_LCNT;
- UINT16 HS_SCL_HCNT;
- UINT16 HS_SCL_LCNT;
-} LPSS_I2C_CLOCK_SCL_INFO;
-
-//
-// Functions
-//
-//
-// Desc: Initializes the controller and returns the MMIO base address
-// Input: Bus - I2C controller, 0 based
-// Address - 7-bit slave address
-// Speed - Uses the I2C_SPEED enum to set the controller speed
-// I2cBaseAddress - Pointer to the MMIO base address for the I2C controller
-// Output: EFI_SUCCESS - Initialization completed successfully
-// EFI_DEVICE_ERROR - I2C controller error
-// EFI_INVALID_PARAMETER - Invalid input parameter
-//
-EFI_STATUS
-I2cInit (
- IN UINT8 Bus,
- IN UINT16 Address,
- IN UINT8 Speed,
- IN OUT UINT32 *I2cBaseAddress
- );
-
-EFI_STATUS
-I2cPoll (
- IN UINT32 I2cBaseAddress
- );
-
-//
-// Desc: Read a byte from the I2C controller
-// Input: I2cBaseAddress - MMIO base address for the I2C controller
-// Data - Pointer to where to store the data
-// Start - Send start bit?
-// End - Send end bit?
-// Output: EFI_SUCCESS - Read completed successfully
-// EFI_DEVICE_ERROR - I2C controller error
-// EFI_INVALID_PARAMETER - Invalid input parameter
-//
-EFI_STATUS
-I2cRead (
- IN UINT32 I2cBaseAddress,
- IN OUT UINT8 *Data,
- IN BOOLEAN Start,
- IN BOOLEAN End
- );
-
-//
-// Desc: Resets the I2C controller into a known good state
-// Input: I2cBaseAddress - MMIO base address for the I2C controller
-// Output: EFI_SUCCESS - Write completed successfully
-// EFI_DEVICE_ERROR - I2C controller error
-// EFI_INVALID_PARAMETER - Invalid input parameter
-//
-EFI_STATUS
-I2cReset (
- IN UINT32 I2cBaseAddress,
- IN UINT8 Bus,
- IN UINT16 Address,
- IN UINT8 Speed
- );
-
-EFI_STATUS
-I2cSendCommand (
- IN UINT32 I2cBaseAddress,
- IN UINT32 *Data,
- IN BOOLEAN Start,
- IN BOOLEAN End
- );
-
-//
-// Desc: Set I2C slave offset
-// Input: I2cBaseAddress - MMIO base address for the I2C controller
-// Offset - Pointer to offset data
-// Size - Size of the offset data
-// Output: EFI_SUCCESS - Write completed successfully
-// EFI_DEVICE_ERROR - I2C controller error
-// EFI_INVALID_PARAMETER - Invalid input parameter
-//
-EFI_STATUS
-I2cSetOffset (
- IN UINT32 I2cBaseAddress,
- IN UINT8 *Offset,
- IN UINT8 Size
- );
-
-//
-// Desc: Write a byte to the I2C controller
-// Input: I2cBaseAddress - MMIO base address for the I2C controller
-// Data - Data from the I2C controller
-// Start - Send start bit?
-// End - Send end bit?
-// Output: EFI_SUCCESS - Write completed successfully
-// EFI_DEVICE_ERROR - I2C controller error
-// EFI_INVALID_PARAMETER - Invalid input parameter
-//
-EFI_STATUS
-I2cWrite (
- IN UINT32 I2cBaseAddress,
- IN UINT8 Data,
- IN BOOLEAN Start,
- IN BOOLEAN End
- );
-
-#endif // _EEPROM_I2C_LIB_
-
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataLib.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataLib.c
index e5ffc85..eff1a75 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataLib.c
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataLib.c
@@ -150,67 +150,3 @@ Exit:
return Status;
}
-//
-// Desc: Registers the raw data libraries
-// Variables: None
-// Return: EFI_SUCCESS, anything else will cause an ASSERT
-//
-EFI_STATUS
-EFIAPI
-EepromDataNullInitConstructor (VOID)
-{
- //
- // 00 - NULL raw library
- //
- if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Loading EEPROM NULL raw data library into slot #%02x\n", __FUNCTION__, __LINE__, EEPROM_NULL));
- mEepromDataLibIndex[EEPROM_NULL].Active = TRUE;
- mEepromDataLibIndex[EEPROM_NULL].ReadFunction = ReadEepromNull;
- mEepromDataLibIndex[EEPROM_NULL].WriteFunction = WriteEepromNull;
-
- return EFI_SUCCESS;
-}
-
-//
-// Desc: Registers the raw data libraries
-// Variables: None
-// Return: EFI_SUCCESS, anything else will cause an ASSERT
-//
-EFI_STATUS
-EFIAPI
-EepromDataInitConstructor (VOID)
-{
- //
- // 00 - NULL raw library
- //
- if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Loading EEPROM NULL raw data library into slot #%02x\n", __FUNCTION__, __LINE__, EEPROM_NULL));
- mEepromDataLibIndex[EEPROM_NULL].Active = TRUE;
- mEepromDataLibIndex[EEPROM_NULL].ReadFunction = ReadEepromNull;
- mEepromDataLibIndex[EEPROM_NULL].WriteFunction = WriteEepromNull;
-
- //
- // 01 - EEPROM raw library
- //
- if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Loading EEPROM raw data library into slot #%02x\n", __FUNCTION__, __LINE__, EEPROM_EEPROM));
- mEepromDataLibIndex[EEPROM_EEPROM].Active = TRUE;
- mEepromDataLibIndex[EEPROM_EEPROM].ReadFunction = ReadEepromEeprom;
- mEepromDataLibIndex[EEPROM_EEPROM].WriteFunction = WriteEepromEeprom;
-
- //
- // 02 - FV raw library
- //
- if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Loading EEPROM FV raw data library into slot #%02x\n", __FUNCTION__, __LINE__, EEPROM_FV));
- mEepromDataLibIndex[EEPROM_FV].Active = TRUE;
- mEepromDataLibIndex[EEPROM_FV].ReadFunction = ReadEepromFv;
- mEepromDataLibIndex[EEPROM_FV].WriteFunction = WriteEepromFv;
-
- //
- // 03 - Memory raw library
- //
- if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Loading EEPROM memory raw data library into slot #%02x\n", __FUNCTION__, __LINE__, EEPROM_MEMORY));
- mEepromDataLibIndex[EEPROM_MEMORY].Active = TRUE;
- mEepromDataLibIndex[EEPROM_MEMORY].ReadFunction = ReadEepromMemory;
- mEepromDataLibIndex[EEPROM_MEMORY].WriteFunction = WriteEepromMemory;
-
- return EFI_SUCCESS;
-}
-
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataLib.h b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataLib.h
index 899487a..9a22ec3 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataLib.h
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataLib.h
@@ -72,6 +72,11 @@ typedef struct {
} EEPROM_ALLOCATION_STRUCT;
////
+//// Externs
+////
+extern EEPROM_DATA_LIBRARY_INDEX mEepromDataLibIndex[];
+
+////
//// Functions
////
//
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataLib.inf b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataLib.inf
index 67416ae..0ce2aaf 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataLib.inf
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataLib.inf
@@ -32,7 +32,7 @@
BaseLib
BaseMemoryLib
DebugLib
- GpioLib
+ EepromPlatformLib
HobLib
MemoryAllocationLib
PcdLib
@@ -53,8 +53,6 @@
gPlatformModuleTokenSpaceGuid.PcdEepromMemorySize
gPlatformModuleTokenSpaceGuid.PcdEepromParts
gPlatformModuleTokenSpaceGuid.PcdEepromPartsHeadLink
- gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress ## SOMETIMES_CONSUMES
- gEfiBxtTokenSpaceGuid.PcdPmcGcrBaseAddress ## SOMETIMES_CONSUMES
[Protocols]
gEfiLoadedImageProtocolGuid
@@ -63,12 +61,11 @@
[Sources]
EepromDataLib.c
EepromDataLib.h
+ EepromDataLibConstructor.c
MemoryAllocation.c
EEPROM/EepromDataEepromLib.c
EEPROM/EepromDataEepromLib.h
EEPROM/HobData.c
- EEPROM/I2cLib.c
- EEPROM/I2cLib.h
FV/EepromDataFvLib.c
FV/EepromDataFvLib.h
FV/GetImage.c
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataLibConstructor.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataLibConstructor.c
new file mode 100644
index 0000000..45041dd
--- /dev/null
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataLibConstructor.c
@@ -0,0 +1,61 @@
+/** @file
+ Common EEPROM raw data library instance.
+
+ Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
+
+ 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 "EepromDataLib.h"
+
+//
+// Desc: Registers the raw data libraries
+// Variables: None
+// Return: EFI_SUCCESS, anything else will cause an ASSERT
+//
+EFI_STATUS
+EFIAPI
+EepromDataInitConstructor (VOID)
+{
+ //
+ // 00 - NULL raw library
+ //
+ if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Loading EEPROM NULL raw data library into slot #%02x\n", __FUNCTION__, __LINE__, EEPROM_NULL));
+ mEepromDataLibIndex[EEPROM_NULL].Active = TRUE;
+ mEepromDataLibIndex[EEPROM_NULL].ReadFunction = ReadEepromNull;
+ mEepromDataLibIndex[EEPROM_NULL].WriteFunction = WriteEepromNull;
+
+ //
+ // 01 - EEPROM raw library
+ //
+ if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Loading EEPROM raw data library into slot #%02x\n", __FUNCTION__, __LINE__, EEPROM_EEPROM));
+ mEepromDataLibIndex[EEPROM_EEPROM].Active = TRUE;
+ mEepromDataLibIndex[EEPROM_EEPROM].ReadFunction = ReadEepromEeprom;
+ mEepromDataLibIndex[EEPROM_EEPROM].WriteFunction = WriteEepromEeprom;
+
+ //
+ // 02 - FV raw library
+ //
+ if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Loading EEPROM FV raw data library into slot #%02x\n", __FUNCTION__, __LINE__, EEPROM_FV));
+ mEepromDataLibIndex[EEPROM_FV].Active = TRUE;
+ mEepromDataLibIndex[EEPROM_FV].ReadFunction = ReadEepromFv;
+ mEepromDataLibIndex[EEPROM_FV].WriteFunction = WriteEepromFv;
+
+ //
+ // 03 - Memory raw library
+ //
+ if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Loading EEPROM memory raw data library into slot #%02x\n", __FUNCTION__, __LINE__, EEPROM_MEMORY));
+ mEepromDataLibIndex[EEPROM_MEMORY].Active = TRUE;
+ mEepromDataLibIndex[EEPROM_MEMORY].ReadFunction = ReadEepromMemory;
+ mEepromDataLibIndex[EEPROM_MEMORY].WriteFunction = WriteEepromMemory;
+
+ return EFI_SUCCESS;
+}
+
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataNullLib.inf b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataNullLib.inf
index 71cec04..d980eb5 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataNullLib.inf
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataNullLib.inf
@@ -31,10 +31,13 @@
[Packages]
MdePkg/MdePkg.dec
+ BroxtonPlatformPkg/PlatformPkg.dec
[Sources]
EepromDataLib.c
EepromDataLib.h
+ EepromDataNullLibConstructor.c
+ MemoryAllocation.c
Null/EepromDataNullLib.c
Null/EepromDataNullLib.h
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataNullLibConstructor.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataNullLibConstructor.c
new file mode 100644
index 0000000..6bb4cf5
--- /dev/null
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataNullLibConstructor.c
@@ -0,0 +1,36 @@
+/** @file
+ Common EEPROM raw data library instance.
+
+ Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
+
+ 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 "EepromDataLib.h"
+
+//
+// Desc: Registers the raw data libraries
+// Variables: None
+// Return: EFI_SUCCESS, anything else will cause an ASSERT
+//
+EFI_STATUS
+EFIAPI
+EepromDataNullInitConstructor (VOID)
+{
+ //
+ // 00 - NULL raw library
+ //
+ if (mEepromDataLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Loading EEPROM NULL raw data library into slot #%02x\n", __FUNCTION__, __LINE__, EEPROM_NULL));
+ mEepromDataLibIndex[EEPROM_NULL].Active = TRUE;
+ mEepromDataLibIndex[EEPROM_NULL].ReadFunction = ReadEepromNull;
+ mEepromDataLibIndex[EEPROM_NULL].WriteFunction = WriteEepromNull;
+
+ return EFI_SUCCESS;
+}
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataNullPeiLib.inf b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataNullPeiLib.inf
new file mode 100644
index 0000000..456d75d
--- /dev/null
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataNullPeiLib.inf
@@ -0,0 +1,46 @@
+## @file
+# Library producing EEPROM raw data functionality.
+#
+# Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
+#
+# 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.
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010017
+ BASE_NAME = EepromDataNullPeiLib
+ FILE_GUID = F4A687F7-BC3C-4BFB-AB8E-EA6599B2F62F
+ VERSION_STRING = 1.0
+ MODULE_TYPE = BASE
+ LIBRARY_CLASS = EepromDataNullPeiLib
+ CONSTRUCTOR = EepromDataNullInitConstructor
+
+[Depex]
+ TRUE
+
+[Guids]
+ gEepromVariableGuid
+
+[LibraryClasses]
+ BaseLib
+ DebugLib
+
+[Packages]
+ MdePkg/MdePkg.dec
+ BroxtonPlatformPkg/PlatformPkg.dec
+
+[Sources]
+ EepromDataLib.c
+ EepromDataLib.h
+ EepromDataNullLibConstructor.c
+ MemoryAllocationPei.c
+ Null/EepromDataNullLib.c
+ Null/EepromDataNullLib.h
+
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataPeiLib.inf b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataPeiLib.inf
index 86a047e..de14765 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataPeiLib.inf
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/EepromDataPeiLib.inf
@@ -32,7 +32,7 @@
BaseLib
BaseMemoryLib
DebugLib
- GpioLib
+ EepromPlatformLib
HobLib
PcdLib
PeiServicesLib
@@ -52,18 +52,15 @@
gPlatformModuleTokenSpaceGuid.PcdEepromMemorySize
gPlatformModuleTokenSpaceGuid.PcdEepromParts
gPlatformModuleTokenSpaceGuid.PcdEepromPartsHeadLink
- gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress ## SOMETIMES_CONSUMES
- gEfiBxtTokenSpaceGuid.PcdPmcGcrBaseAddress ## SOMETIMES_CONSUMES
[Sources]
EepromDataLib.c
EepromDataLib.h
+ EepromDataLibConstructor.c
MemoryAllocationPei.c
EEPROM/EepromDataEepromLib.c
EEPROM/EepromDataEepromLib.h
EEPROM/HobDataPei.c
- EEPROM/I2cLib.c
- EEPROM/I2cLib.h
FV/EepromDataFvLib.c
FV/EepromDataFvLib.h
FV/GetImagePei.c
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Memory/HobData.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Memory/HobData.c
index 03e263e..1b19b52 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Memory/HobData.c
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/Memory/HobData.c
@@ -72,7 +72,7 @@ GetEepromDataHobData (VOID)
//
// Yep. Copy existing buffer to larger buffer.
//
- Buffer = EepromAllocateCopyPool (PcdGet32 (PcdEepromMemorySize) + BlockSize, (UINT8 *) PcdGet64 (PcdEepromMemoryPointer));
+ Buffer = EepromAllocateCopyPool (PcdGet32 (PcdEepromMemorySize) + BlockSize, (UINT8 *) (UINTN) PcdGet64 (PcdEepromMemoryPointer));
if (Buffer == NULL) {
DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Unable to allocate buffer!\n", __FUNCTION__, __LINE__));
Status = EFI_OUT_OF_RESOURCES;
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/MemoryAllocation.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/MemoryAllocation.c
index 4d4b9ed..7ec8218 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/MemoryAllocation.c
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/MemoryAllocation.c
@@ -17,6 +17,23 @@
#include <Library/MemoryAllocationLib.h>
+UINTN
+EFIAPI
+DisplayStackPointer (
+ IN CHAR8 *Function,
+ IN UINTN LineNumber
+ )
+{
+ UINT8 *Temp;
+
+ Temp = AllocatePool (1);
+ if (mEepromDataLibDebugFlag) {
+ DEBUG ((DEBUG_INFO, "%a (#%4d) - INFO: FreeBottom = %08x\n", __FUNCTION__, __LINE__, Temp));
+ }
+
+ return (UINTN) Temp;
+}
+
//
// Desc: Copies the contents of an existing memory pool into a new memory pool of equal or greater size.
// Variables: Size Size of the pool to copy existing pool into
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/MemoryAllocationPei.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/MemoryAllocationPei.c
index 250666f..9bfccc7 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/MemoryAllocationPei.c
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromDataLib/MemoryAllocationPei.c
@@ -102,6 +102,27 @@ Exit:
return Status;
}
+UINTN
+EFIAPI
+DisplayStackPointer (
+ IN CHAR8 *Function,
+ IN UINTN LineNumber
+ )
+{
+ EFI_HOB_HANDOFF_INFO_TABLE *Hob;
+ UINTN Temp;
+
+ Hob = GetHobList ();
+ Temp = 0;
+ if ((Hob != NULL) & (mEepromDataLibDebugFlag)) {
+ DEBUG ((DEBUG_INFO, "%a (#%4d) - INFO: FreeTop = %08x\n", __FUNCTION__, __LINE__, Hob->EfiFreeMemoryTop));
+ DEBUG ((DEBUG_INFO, "%a (#%4d) - INFO: FreeBottom = %08x\n", __FUNCTION__, __LINE__, Hob->EfiFreeMemoryBottom));
+ Temp = (UINTN) Hob->EfiFreeMemoryBottom;
+ }
+
+ return Temp;
+}
+
//
// Desc: Dumps the EEPROM memory allocation status.
// Variables: HobPointer Pointer to the EEPROM memory allocation HOB
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/EepromLib.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/EepromLib.c
index 6ab06da..eccd28f 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/EepromLib.c
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/EepromLib.c
@@ -61,19 +61,59 @@ InitializeCrc32Table (
UINTN Index;
UINT32 Value;
- for (TableEntry = 0; TableEntry < 256; TableEntry++) {
- Value = ReverseBits ((UINT32) TableEntry);
- for (Index = 0; Index < 8; Index++) {
- if ((Value & 0x80000000) != 0) {
- Value = (Value << 1) ^ 0x04C11DB7;
- } else {
- Value = Value << 1;
+ if (!mCrcInitFlag) {
+ for (TableEntry = 0; TableEntry < 256; TableEntry++) {
+ Value = ReverseBits ((UINT32) TableEntry);
+ for (Index = 0; Index < 8; Index++) {
+ if ((Value & 0x80000000) != 0) {
+ Value = (Value << 1) ^ 0x04C11DB7;
+ } else {
+ Value = Value << 1;
+ }
}
+ mCrcTable[TableEntry] = ReverseBits (Value);
}
+ mCrcInitFlag = TRUE;
+ }
+}
+
+UINT32
+EFIAPI
+StartCrc32 (VOID)
+{
+ // Table initialized?
+ InitializeCrc32Table ();
+
+ return 0xFFFFFFFF;
+}
- mCrcTable[TableEntry] = ReverseBits (Value);
+UINT32
+EFIAPI
+AddToCrc32 (
+ IN VOID *Data,
+ IN UINTN DataSize,
+ IN UINT32 Crc
+ )
+{
+ UINT32 Crc32;
+ UINTN Index;
+ UINT8 *Ptr;
+
+ Crc32 = Crc;
+ Ptr = (UINT8 *) Data;
+ for (Index = 0; Index < DataSize; Index++) {
+ Crc32 = (Crc32 >> 8) ^ mCrcTable[(UINT8) Crc32 ^ Ptr[Index]];
}
- mCrcInitFlag = TRUE;
+ return Crc32;
+}
+
+UINT32
+EFIAPI
+FinishCrc32 (
+ IN UINT32 Crc32
+ )
+{
+ return (Crc32 ^ 0xFFFFFFFF);
}
/*++
@@ -87,7 +127,7 @@ Arguments:
Data - The buffer contaning the data to be processed
DataSize - The size of data to be processed
CrcOut - A pointer to the caller allocated UINT32 that on
- contains the CRC32 checksum of Data
+ exits, contains the CRC32 checksum of Data
Returns:
@@ -97,15 +137,13 @@ Returns:
--*/
EFI_STATUS
EFIAPI
-CalculateCrc32 (
+EepromCalculateCrc32 (
IN UINT8 *Data,
IN UINTN DataSize,
IN OUT UINT32 *CrcOut
)
{
- UINT32 Crc;
- UINTN Index;
- UINT8 *Ptr;
+ UINT32 Crc32;
if (mEepromLibDebugFlag) DEBUG ((DEBUG_INFO, "%a (#%4d) - Starting...\n", __FUNCTION__, __LINE__));
@@ -114,15 +152,9 @@ CalculateCrc32 (
return EFI_INVALID_PARAMETER;
}
- // Table initialized?
- if (!mCrcInitFlag) InitializeCrc32Table ();
-
- Crc = 0xFFFFFFFF;
- for (Index = 0, Ptr = Data; Index < DataSize; Index++, Ptr++) {
- Crc = (Crc >> 8) ^ mCrcTable[(UINT8) Crc ^ *Ptr];
- }
-
- *CrcOut = Crc ^ 0xFFFFFFFF;
+ Crc32 = StartCrc32 ();
+ Crc32 = AddToCrc32 (Data, DataSize, Crc32);
+ *CrcOut = FinishCrc32 (Crc32);
return EFI_SUCCESS;
}
@@ -319,7 +351,7 @@ GetImageSize (
Size = sizeof (EEPROM_HEADER);
ZeroMem (&EepromHeader, Size);
Status = ReadEeprom (LibraryIndex, 0, &Size, (UINT8 *) &EepromHeader, &EepromInfo);
- if (EFI_ERROR (Status) || (AsciiStrnCmp (EepromHeader.signature, "$Eeprom$", 8) != 0)) {
+ if (EFI_ERROR (Status) || (AsciiStrnCmp (EepromHeader.signature, EEPROM_HEADER_SIGNATURE, 8) != 0)) {
//
// Oops!
//
@@ -430,7 +462,7 @@ GetNextEepromStructure (
Status = EFI_END_OF_FILE;
goto Exit;
}
-
+
//
// Read in the next header
//
@@ -502,8 +534,7 @@ Exit:
UINT8
EFIAPI
GetValidEepromLibrary (
- IN BOOLEAN CopyToMemory,
- IN BOOLEAN MemoryInitialized
+ IN BOOLEAN CopyToMemory
)
{
UINT8 *EepromAutoList;
@@ -542,9 +573,8 @@ GetValidEepromLibrary (
// Display current stack pointer
//
DisplayStackPointer (__FUNCTION__, __LINE__);
-
//
- // Loop thru PcdEepromAutoPriority looking for a validated image.
+ // Loop thru PcdEepromAutoPriority looking for a previously validated image.
//
index = 0;
while (EepromAutoList[index] != 0xFF) {
@@ -569,15 +599,7 @@ GetValidEepromLibrary (
//
index++;
}
- //
- // Check to see if we need to validate and copy into memory
- //
- if (!CopyToMemory) {
- //
- // Nope. Bail.
- //
- goto Exit;
- }
+
//
// Display current stack pointer
//
@@ -609,6 +631,7 @@ GetValidEepromLibrary (
index++;
}
}
+
//
// Display current stack pointer
//
@@ -646,13 +669,13 @@ GetValidEepromLibrary (
// Get BoardInfo records
//
Size = 0;
- Status = GetEepromStructure (EEPROM_EEPROM, "$BrdInfo", (UINT8 **) &EepromBoardInfo, &Size);
+ Status = GetEepromStructure (EEPROM_EEPROM, EEPROM_BOARD_INFO_SIGNATURE, (UINT8 **) &EepromBoardInfo, &Size);
if (EFI_ERROR (Status) || (Size == 0) || (EepromBoardInfo == NULL)) {
DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Failed to get EEPROM Board Info structure! (%r)\n", __FUNCTION__, __LINE__, Status));
Library = EEPROM_FV;
} else {
Size = 0;
- Status = GetEepromStructure (EEPROM_FV, "$BrdInfo", (UINT8 **) &FvBoardInfo, &Size);
+ Status = GetEepromStructure (EEPROM_FV, EEPROM_BOARD_INFO_SIGNATURE, (UINT8 **) &FvBoardInfo, &Size);
if (EFI_ERROR (Status) || (Size == 0) || (FvBoardInfo == NULL)) {
DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Failed to get FV Board Info structure! (%r)\n", __FUNCTION__, __LINE__, Status));
Library = EEPROM_EEPROM;
@@ -670,13 +693,13 @@ GetValidEepromLibrary (
// Get EepromHeader records
//
Size = 0;
- Status = GetEepromStructure (EEPROM_EEPROM, "$Eeprom$", (UINT8 **) &EepromEepromHeader, &Size);
+ Status = GetEepromStructure (EEPROM_EEPROM, EEPROM_HEADER_SIGNATURE, (UINT8 **) &EepromEepromHeader, &Size);
if (EFI_ERROR (Status) || (Size == 0) || (EepromEepromHeader == NULL)) {
DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Failed to get EEPROM header structure! (%r)\n", __FUNCTION__, __LINE__, Status));
Library = EEPROM_FV;
} else {
Size = 0;
- Status = GetEepromStructure (EEPROM_FV, "$Eeprom$", (UINT8 **) &FvEepromHeader, &Size);
+ Status = GetEepromStructure (EEPROM_FV, EEPROM_HEADER_SIGNATURE, (UINT8 **) &FvEepromHeader, &Size);
if (EFI_ERROR (Status) || (Size == 0) || (FvEepromHeader == NULL)) {
DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Failed to get FV header structure! (%r)\n", __FUNCTION__, __LINE__, Status));
Library = EEPROM_EEPROM;
@@ -711,10 +734,14 @@ GetValidEepromLibrary (
// Display current stack pointer
//
DisplayStackPointer (__FUNCTION__, __LINE__);
+
//
- // If we don't have memory, then bail so we don't take up all of the stack space in NEM.
+ // Check to see if we need to copy into memory and not in PEI
//
- if (!MemoryInitialized) {
+ if (!CopyToMemory || InPeiPhase ()) {
+ //
+ // Nope. Bail.
+ //
goto Exit;
}
//
@@ -793,19 +820,18 @@ ValidateEeprom (
IN UINT8 LibraryIndex
)
{
+ UINT32 BufferSize;
UINT32 Count;
UINT32 Crc32;
UINT32 Crc32Size;
EEPROM_HEADER *EepromHeader;
EEPROM_FUNCTION_INFO EepromInfo;
- UINT8 *Hash;
UINT32 HashSize;
- UINT16 HashType;
UINT8 *ImageBuffer;
UINT32 ImageSize;
- SIGNATURE_DATA *Signature;
- UINT8 *SignedHash;
- UINT32 SignedHashSize;
+ UINT32 Offset;
+ UINT32 OriginalCrc32;
+ UINT32 Size;
EFI_STATUS Status;
GENERIC_HEADER *Structure;
INTN Test;
@@ -821,10 +847,7 @@ ValidateEeprom (
EepromInfo.Bus = PcdGet8 (PcdEepromBus);
EepromInfo.Address = PcdGet8 (PcdEepromAddress);
EepromInfo.LibraryIndex = EEPROM_EEPROM;
- Hash = NULL;
ImageBuffer = NULL;
- SignedHash = NULL;
- SignedHashSize = 0;
Status = EFI_SUCCESS;
Structure = NULL;
@@ -848,117 +871,133 @@ ValidateEeprom (
Status = EFI_NOT_FOUND;
goto Exit;
}
- //
- // Get a buffer to hold the image
- //
- ImageBuffer = EepromAllocatePool (ImageSize);
- if (ImageBuffer == NULL) {
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Unable to allocate 0x%08x bytes for the image buffer!\n", __FUNCTION__, __LINE__, ImageSize));
- Status = EFI_OUT_OF_RESOURCES;
- goto Exit;
- }
- //
- // Read in the image
- //
- Status = ReadEeprom (LibraryIndex, 0, &ImageSize, ImageBuffer, &EepromInfo);
- if (EFI_ERROR (Status)) {
- //
- // Oops!!!
- //
- goto Exit;
- }
- EepromHeader = (EEPROM_HEADER *) ImageBuffer;
+
//
// Verify structure order
//
- Count = 0;
- Structure = (GENERIC_HEADER *) ImageBuffer;
- while ((UINT8 *) Structure < (UINT8 *) (ImageBuffer + ImageSize)) {
- //
- // Increment count
- //
- Count++;
- //
- // Sanity check header
- //
- if (Count == 1) {
- //
- // First structure must be $Eeprom$
- //
- Test = AsciiStrnCmp (Structure->signature, "$Eeprom$", 8);
- //
- // Set CRC32 size
- //
- Crc32Size = EepromHeader->crclength;
- } else if (Count == 2) {
- //
- // Second structure must be $EeprMap
- //
- Test = AsciiStrnCmp (Structure->signature, "$EeprMap", 8);
- } else if (Count == 3) {
- //
- // Third structure must be $BrdInfo
- //
- Test = AsciiStrnCmp (Structure->signature, "$BrdInfo", 8);
- } else {
- //
- // All header signatures begin with $
- //
- Test = AsciiStrnCmp (Structure->signature, "$", 0x01);
- }
- if (Test != 0) {
+ Count = 0;
+ Offset = 0;
+ Status = EFI_SUCCESS;
+ while (!EFI_ERROR (Status) && (Offset < ImageSize)) {
+ Status = GetNextEepromStructure (LibraryIndex, &Offset, (UINT8 **) &ImageBuffer, &BufferSize);
+ if (!EFI_ERROR (Status)) {
//
- // Sanity check failed! Bail.
+ // Increment count
//
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Image is corrupted!\n", __FUNCTION__, __LINE__));
- Status = EFI_VOLUME_CORRUPTED;
- goto Exit;
- }
- if (AsciiStrnCmp (Structure->signature, "$PromSig", 8) == 0) {
+ Count++;
+ Structure = (GENERIC_HEADER *) ImageBuffer;
//
- // Check if this is the last structure
+ // Sanity check header
//
- Signature = (SIGNATURE_DATA *) Structure;
- HashSize = Signature->length - sizeof (SIGNATURE_DATA);
- Hash = ((UINT8 *) Signature) + sizeof (SIGNATURE_DATA);
- HashType = Signature->hashtype;
- if (((UINT8 *) Signature - ImageBuffer) + Signature->length + (Structure->length % 0x10) != ImageSize) {
+ if (Count == 1) {
+ //
+ // First structure must be $Eeprom$
//
- // Oops! $PromSig is not the last structure.
+ Test = AsciiStrnCmp (Structure->signature, EEPROM_HEADER_SIGNATURE, 8);
+ } else if (Count == 2) {
//
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: $PromSig structure is not the last structure!\n", __FUNCTION__, __LINE__));
+ // Second structure must be $EeprMap
+ //
+ Test = AsciiStrnCmp (Structure->signature, EEPROM_MAP_SIGNATURE, 8);
+ } else if (Count == 3) {
+ //
+ // Third structure must be $BrdInfo
+ //
+ Test = AsciiStrnCmp (Structure->signature, EEPROM_BOARD_INFO_SIGNATURE, 8);
+ } else {
+ //
+ // All header signatures begin with $
+ //
+ Test = AsciiStrnCmp (Structure->signature, "$", 0x01);
+ }
+ if (Test != 0) {
+ //
+ // Sanity check failed! Bail.
+ //
+ DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Image is corrupted!\n", __FUNCTION__, __LINE__));
Status = EFI_VOLUME_CORRUPTED;
goto Exit;
}
+ if (AsciiStrnCmp (Structure->signature, EEPROM_SIGNATURE_SIGNATURE, 8) == 0) {
+ //
+ // Check if this is the last structure
+ //
+ HashSize = Structure->length - sizeof (SIGNATURE_DATA);
+ if (Offset < ImageSize) {
+ //
+ // Oops! $PromSig is not the last structure.
+ //
+ DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: $PromSig structure is not the last structure!\n", __FUNCTION__, __LINE__));
+ Status = EFI_VOLUME_CORRUPTED;
+ goto Exit;
+ }
+ }
}
- //
- // Get next structure on paragraph boundary
- //
- Structure = (GENERIC_HEADER *) ((UINT8 *) Structure + Structure->length + (Structure->length % 0x10));
+ }
+ ImageBuffer = EepromFreePool (ImageBuffer);
+
+ //
+ // Get $Eeprom$ structure
+ //
+ Size = 0;
+ Status = GetEepromStructure (LibraryIndex, EEPROM_HEADER_SIGNATURE, (UINT8 **) &EepromHeader, &Size);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Image is corrupted!\n", __FUNCTION__, __LINE__));
+ Status = EFI_VOLUME_CORRUPTED;
+ goto Exit;
}
//
- // Verify CRC32
+ // Start CRC32 calculations with $Eeprom$
//
- Crc32 = EepromHeader->crc32;
+ OriginalCrc32 = EepromHeader->crc32;
+ Crc32Size = EepromHeader->crclength;
EepromHeader->crc32 = 0;
- CalculateCrc32 (ImageBuffer, Crc32Size, &EepromHeader->crc32);
- if (EepromHeader->crc32 != Crc32) {
+ Crc32 = StartCrc32 ();
+ Crc32 = AddToCrc32 (EepromHeader, Size, Crc32);
+ Offset = Size;
+ //
+ // Add the rest of the binary
+ //
+ Size = 1024;
+ ImageBuffer = EepromAllocatePool (Size);
+ if (ImageBuffer == NULL) {
+ //
+ // Failed to allocate pool
+ //
+ DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Failed to allocate pool for Buffer!\n", __FUNCTION__, __LINE__));
+ Status = EFI_OUT_OF_RESOURCES;
+ goto Exit;
+ }
+ Status = EFI_SUCCESS;
+ while (!EFI_ERROR (Status) && (Offset < Crc32Size)) {
+ if ((Offset + Size) > Crc32Size) {
+ Size = Crc32Size - Offset;
+ }
+ Status = ReadEeprom (LibraryIndex, Offset, &Size, ImageBuffer, &EepromInfo);
+ Offset += Size;
+ if (!EFI_ERROR (Status)) {
+ Crc32 = AddToCrc32 (ImageBuffer, Size, Crc32);
+ }
+ }
+ Crc32 = FinishCrc32 (Crc32);
+ if (OriginalCrc32 != Crc32) {
//
// Oops!
//
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: CRC32 check failed! [%08x:%08x]\n", __FUNCTION__, __LINE__, EepromHeader->crc32, Crc32));
+ DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: CRC32 check failed! [%08x:%08x]\n", __FUNCTION__, __LINE__, OriginalCrc32, Crc32));
Status = EFI_SECURITY_VIOLATION;
goto Exit;
}
+ EepromHeader = EepromFreePool (EepromHeader);
+
//
// Verify hash
//
- Status = EFI_SUCCESS;
if (HashSize > 0) {
//
// Check hash
//
- Status = SignedHashCheck (LibraryIndex, ImageBuffer, Crc32Size, Signature);
+ Status = SignedHashCheck (LibraryIndex);
if (EFI_ERROR (Status) && (Status != EFI_MEDIA_CHANGED)) {
DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Failed to verify the hash!\n", __FUNCTION__, __LINE__));
goto Exit;
@@ -969,7 +1008,8 @@ Exit:
//
// Free resources
//
- ImageBuffer = EepromFreePool (ImageBuffer);
+ EepromHeader = EepromFreePool (EepromHeader);
+ ImageBuffer = EepromFreePool (ImageBuffer);
if (EFI_ERROR (Status) && (Status != EFI_MEDIA_CHANGED)) {
gImageValidFlag[LibraryIndex] = FALSE;
DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __LINE__, Status));
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/EepromLib.h b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/EepromLib.h
index 83871a4..047b559 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/EepromLib.h
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/EepromLib.h
@@ -23,7 +23,6 @@
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
-#include <Library/EepromDataLib.h>
#include <Library/EepromLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PrintLib.h>
@@ -34,7 +33,6 @@
////
//// Defines
////
-#define HASH_SIGNED_FLAG (1 << 15)
#define HASH_TYPE_MASK 0x00FF
#define MAX_HASH_TYPE 5
#define MAX_DIGEST_SIZE SHA512_DIGEST_SIZE
@@ -53,7 +51,7 @@
////
EFI_STATUS
EFIAPI
-CalculateCrc32 (
+EepromCalculateCrc32 (
IN UINT8 *Data,
IN UINTN DataSize,
IN OUT UINT32 *CrcOut
@@ -66,10 +64,7 @@ EepromLibNemToMemory (VOID);
EFI_STATUS
EFIAPI
SignedHashCheck (
- IN UINT8 LibraryIndex,
- IN UINT8 *ImageBuffer,
- IN UINT32 Crc32Size,
- IN SIGNATURE_DATA *Signature
+ IN UINT8 LibraryIndex
);
#endif // _EEPROM_LIB_COMMON_
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/Null/EepromNullLib.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/Null/EepromNullLib.c
index 612408a..a235d8a 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/Null/EepromNullLib.c
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/Null/EepromNullLib.c
@@ -42,7 +42,7 @@ GetImageSize (
IN UINT8 LibraryIndex
)
{
- return EFI_UNSUPPORTED;
+ return 0;
}
EFI_STATUS
@@ -60,8 +60,7 @@ GetNextEepromStructure (
UINT8
EFIAPI
GetValidEepromLibrary (
- IN BOOLEAN CopyToMemory,
- IN BOOLEAN MemoryInitialized
+ IN BOOLEAN CopyToMemory
)
{
return EEPROM_NULL;
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/Pei/ValidateHashPei.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/Pei/ValidateHashPei.c
index b039d98..a0f7b6b 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/Pei/ValidateHashPei.c
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/Pei/ValidateHashPei.c
@@ -20,27 +20,6 @@
#include <Library/PeiServicesLib.h>
#include <Ppi/ReadOnlyVariable2.h>
-UINTN
-EFIAPI
-DisplayStackPointer (
- IN CHAR8 *Function,
- IN UINTN LineNumber
- )
-{
- EFI_HOB_HANDOFF_INFO_TABLE *Hob;
- UINTN Temp;
-
- Hob = GetHobList ();
- Temp = 0;
- if ((Hob != NULL) & (mEepromDataLibDebugFlag)) {
- DEBUG ((DEBUG_INFO, "%a (#%4d) - INFO: FreeTop = %08x\n", __FUNCTION__, __LINE__, Hob->EfiFreeMemoryTop));
- DEBUG ((DEBUG_INFO, "%a (#%4d) - INFO: FreeBottom = %08x\n", __FUNCTION__, __LINE__, Hob->EfiFreeMemoryBottom));
- Temp = (UINTN) Hob->EfiFreeMemoryBottom;
- }
-
- return Temp;
-}
-
EFI_STATUS
EFIAPI
GetEepromVariable (
@@ -165,26 +144,16 @@ InPeiPhase (VOID)
EFI_STATUS
EFIAPI
SignedHashCheck (
- IN UINT8 LibraryIndex,
- IN UINT8 *ImageBuffer,
- IN UINT32 Crc32Size,
- IN SIGNATURE_DATA *Signature
+ IN UINT8 LibraryIndex
)
{
- UINT8 *Hash;
- UINT32 HashSize;
- EFI_STATUS Status;
- UINT8 *Variable;
- UINT32 VariableSize;
-
- //
- // Initialize variables
- //
- Hash = ((UINT8 *) Signature) + sizeof (SIGNATURE_DATA);
- HashSize = Signature->length - sizeof (SIGNATURE_DATA);
- Status = EFI_UNSUPPORTED;
- Variable = NULL;
- VariableSize = 0;
+ UINT8 *Hash;
+ UINT32 HashSize;
+ SIGNATURE_DATA *Signature;
+ UINT32 Size;
+ EFI_STATUS Status;
+ UINT8 *Variable;
+ UINT32 VariableSize;
//
// Sanity checks
@@ -194,22 +163,25 @@ SignedHashCheck (
Status = EFI_INVALID_PARAMETER;
goto Exit;
}
- if (Signature == NULL) {
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Buffer is NULL!\n", __FUNCTION__, __LINE__));
- Status = EFI_INVALID_PARAMETER;
- goto Exit;
- }
- if (Signature->hashtype == 0) {
- //
- // Nothing to do. Bail.
- //
- Status = EFI_SUCCESS;
+
+ //
+ // Get $PromSig structure
+ //
+ Size = 0;
+ Status = GetEepromStructure (LibraryIndex, EEPROM_SIGNATURE_SIGNATURE, (UINT8 **) &Signature, &Size);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Image is corrupted!\n", __FUNCTION__, __LINE__));
+ Status = EFI_VOLUME_CORRUPTED;
goto Exit;
}
+ Hash = ((UINT8 *) Signature) + sizeof (SIGNATURE_DATA);
+ HashSize = Signature->length - sizeof (SIGNATURE_DATA);
//
// Get stored hash
//
+ Variable = NULL;
+ VariableSize = 0;
Status = GetEepromVariable (LibraryIndex, &Variable, &VariableSize);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Failed to get variable! [%r]\n", __FUNCTION__, __LINE__, Status));
@@ -245,7 +217,11 @@ SignedHashCheck (
}
Exit:
- Variable = EepromFreePool (Variable);
+ //
+ // Clear resources
+ //
+ Signature = EepromFreePool (Signature);
+ Variable = EepromFreePool (Variable);
return Status;
}
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/ValidateHash.c b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/ValidateHash.c
index 355033c..7d670c5 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/ValidateHash.c
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/EepromLib/ValidateHash.c
@@ -28,23 +28,6 @@ CONST UINT8 mHashSizeLookup[] = {
SHA512_DIGEST_SIZE
};
-UINTN
-EFIAPI
-DisplayStackPointer (
- IN CHAR8 *Function,
- IN UINTN LineNumber
- )
-{
- UINT8 *Temp;
-
- Temp = AllocatePool (1);
- if (mEepromDataLibDebugFlag) {
- DEBUG ((DEBUG_INFO, "%a (#%4d) - INFO: FreeBottom = %08x\n", __FUNCTION__, __LINE__, Temp));
- }
-
- return (UINTN) Temp;
-}
-
BOOLEAN
EFIAPI
InPeiPhase (VOID)
@@ -102,47 +85,47 @@ Exit:
EFI_STATUS
EFIAPI
SignedHashCheck (
- IN UINT8 LibraryIndex,
- IN UINT8 *ImageBuffer,
- IN UINT32 Crc32Size,
- IN SIGNATURE_DATA *Signature
+ IN UINT8 LibraryIndex
)
{
- UINT8 Digest[MAX_DIGEST_SIZE];
- FV_FUNCTION_INFO FvInfo;
- EFI_GUID FvPublicKeyFile;
- UINT8 *Hash;
- UINT32 HashSize;
- BOOLEAN HashStatus;
- UINT16 HashType;
- UINT8 *PublicKey;
- UINT32 PublicKeySize;
- VOID *Rsa;
- BOOLEAN RsaStatus;
- UINT8 *SignedHash;
- UINT32 SignedHashSize;
- EFI_STATUS Status;
+ UINT32 Crc32Size;
+ UINT8 Digest[MAX_DIGEST_SIZE];
+ EEPROM_HEADER *EepromHeader;
+ EEPROM_FUNCTION_INFO EepromInfo;
+ FV_FUNCTION_INFO FvInfo;
+ EFI_GUID FvPublicKeyFile;
+ UINT8 *Hash;
+ UINT32 HashSize;
+ BOOLEAN HashStatus;
+ UINT16 HashType;
+ UINT8 *ImageBuffer;
+ UINT32 ImageSize;
+ UINT8 *PublicKey;
+ UINT32 PublicKeySize;
+ VOID *Rsa;
+ BOOLEAN RsaStatus;
+ SIGNATURE_DATA *Signature;
+ UINT8 *SignedHash;
+ UINT32 SignedHashSize;
+ UINT32 Size;
+ EFI_STATUS Status;
//
// Initialize variables
//
CopyMem (&FvPublicKeyFile, PcdGetPtr (PcdEepromPublicKeyFile), sizeof (EFI_GUID));
ZeroMem (&FvInfo, sizeof (FV_FUNCTION_INFO));
+ EepromInfo.Bus = PcdGet8 (PcdEepromBus);
+ EepromInfo.Address = PcdGet8 (PcdEepromAddress);
+ EepromInfo.LibraryIndex = EEPROM_EEPROM;
FvInfo.LibraryIndex = EEPROM_FV;
FvInfo.FvFileGuid = &FvPublicKeyFile;
- Hash = ((UINT8 *) Signature) + sizeof (SIGNATURE_DATA);
- HashType = Signature->hashtype;
- HashSize = mHashSizeLookup[HashType & HASH_TYPE_MASK];
PublicKey = NULL;
PublicKeySize = 0;
Rsa = NULL;
SignedHash = NULL;
SignedHashSize = 0;
Status = EFI_UNSUPPORTED;
- if (HashType & HASH_SIGNED_FLAG) {
- SignedHash = ((UINT8 *) Signature) + sizeof (SIGNATURE_DATA) + HashSize;
- SignedHashSize = Signature->length - sizeof (SIGNATURE_DATA) - HashSize;
- }
//
// Sanity checks
@@ -152,16 +135,53 @@ SignedHashCheck (
Status = EFI_INVALID_PARAMETER;
goto Exit;
}
- if ((ImageBuffer == NULL) || (Signature == NULL)) {
- DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Buffer is NULL!\n", __FUNCTION__, __LINE__));
- Status = EFI_INVALID_PARAMETER;
+
+ //
+ // Get binary image size
+ //
+ ImageSize = GetImageSize (LibraryIndex);
+ if (ImageSize == 0) {
+ //
+ // Oops!
+ //
+ Status = EFI_NOT_FOUND;
+ goto Exit;
+ }
+
+ //
+ // Get $Eeprom$ structure
+ //
+ Size = 0;
+ Status = GetEepromStructure (LibraryIndex, EEPROM_HEADER_SIGNATURE, (UINT8 **) &EepromHeader, &Size);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Image is corrupted!\n", __FUNCTION__, __LINE__));
+ Status = EFI_VOLUME_CORRUPTED;
goto Exit;
}
+ Crc32Size = EepromHeader->crclength;
if (Crc32Size == 0) {
DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Buffer size is 0!\n", __FUNCTION__, __LINE__));
Status = EFI_INVALID_PARAMETER;
goto Exit;
}
+
+ //
+ // Get $PromSig structure
+ //
+ Size = 0;
+ Status = GetEepromStructure (LibraryIndex, EEPROM_SIGNATURE_SIGNATURE, (UINT8 **) &Signature, &Size);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Image is corrupted!\n", __FUNCTION__, __LINE__));
+ Status = EFI_VOLUME_CORRUPTED;
+ goto Exit;
+ }
+ Hash = ((UINT8 *) Signature) + sizeof (SIGNATURE_DATA);
+ HashType = Signature->hashtype;
+ HashSize = mHashSizeLookup[HashType & HASH_TYPE_MASK];
+ if (HashType & EEPROM_SIGNATURE_TYPE_SIGNED) {
+ SignedHash = ((UINT8 *) Signature) + sizeof (SIGNATURE_DATA) + HashSize;
+ SignedHashSize = Signature->length - sizeof (SIGNATURE_DATA) - HashSize;
+ }
if (HashType == 0) {
//
// Nothing to do. Bail.
@@ -186,6 +206,26 @@ SignedHashCheck (
}
//
+ // Get binary image
+ //
+ ImageBuffer = EepromAllocatePool (ImageSize);
+ if (ImageBuffer == NULL) {
+ //
+ // Failed to allocate pool
+ //
+ DEBUG ((DEBUG_ERROR, "%a (#%4d) - ERROR: Failed to allocate pool for Buffer!\n", __FUNCTION__, __LINE__));
+ Status = EFI_OUT_OF_RESOURCES;
+ goto Exit;
+ }
+ Status = ReadEeprom (LibraryIndex, 0, &ImageSize, ImageBuffer, &EepromInfo);
+ if (EFI_ERROR (Status)) {
+ //
+ // Oops!!!
+ //
+ goto Exit;
+ }
+
+ //
// Clear existing NvStorage variable if it exists. gEepromVariableGuid:L"PromSig-#"
//
Status = SetEepromVariable (LibraryIndex, NULL, 0);
@@ -198,12 +238,12 @@ SignedHashCheck (
// Figure out what hash is being used
//
switch (HashType & HASH_TYPE_MASK) {
- case HASH_NONE:
+ case EEPROM_SIGNATURE_TYPE_NONE:
//
// Nothing to do. Bail.
//
break;
- case HASH_MD5:
+ case EEPROM_SIGNATURE_TYPE_MD5:
//
// MD5 hashing
//
@@ -221,7 +261,7 @@ SignedHashCheck (
}
HashSize = MD5_DIGEST_SIZE;
break;
- case HASH_SHA1:
+ case EEPROM_SIGNATURE_TYPE_SHA1:
//
// SHA1 hashing
//
@@ -239,7 +279,7 @@ SignedHashCheck (
}
HashSize = SHA1_DIGEST_SIZE;
break;
- case HASH_SHA256:
+ case EEPROM_SIGNATURE_TYPE_SHA256:
//
// SHA256 hashing
//
@@ -257,7 +297,7 @@ SignedHashCheck (
}
HashSize = SHA256_DIGEST_SIZE;
break;
- case HASH_SHA384:
+ case EEPROM_SIGNATURE_TYPE_SHA384:
//
// SHA384 hashing
//
@@ -275,7 +315,7 @@ SignedHashCheck (
}
HashSize = SHA384_DIGEST_SIZE;
break;
- case HASH_SHA512:
+ case EEPROM_SIGNATURE_TYPE_SHA512:
//
// SHA512 hashing
//
@@ -306,7 +346,7 @@ SignedHashCheck (
//
// Does this have a signed hash?
//
- if ((HashType & HASH_SIGNED_FLAG) != HASH_SIGNED_FLAG) {
+ if ((HashType & EEPROM_SIGNATURE_TYPE_SIGNED) != EEPROM_SIGNATURE_TYPE_SIGNED) {
//
// Nope. Bail.
//
@@ -382,7 +422,10 @@ Exit:
if (Rsa != NULL) {
RsaFree (Rsa);
}
- PublicKey = EepromFreePool (PublicKey);
+ EepromHeader = EepromFreePool (EepromHeader);
+ ImageBuffer = EepromFreePool (ImageBuffer);
+ PublicKey = EepromFreePool (PublicKey);
+ Signature = EepromFreePool (Signature);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a (#%4d) - Ending with %r\n", __FUNCTION__, __LINE__, Status));
} else if (HashType != 0) {
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/EepromStruct.h b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/EepromStruct.h
index e3d0fa6..0c4f6bd 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/EepromStruct.h
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/EepromStruct.h
@@ -36,6 +36,8 @@ typedef struct {
CHAR8 reserved[16];
}EEPROM_HEADER;
+#define EEPROM_HEADER_SIGNATURE "$Eeprom$"
+
typedef struct {
CHAR8 signature[8];
@@ -46,6 +48,8 @@ typedef struct {
// UINT8 acpitbl[0];
}ACPI_TABLE;
+#define EEPROM_ACPI_TABLE_SIGNATURE "$AcpiTbl"
+
typedef struct {
CHAR8 signature[8];
@@ -62,6 +66,10 @@ typedef struct {
CHAR8 reserved[19];
}BOARD_INFO_TABLE;
+#define EEPROM_BOARD_INFO_SIGNATURE "$BrdInfo"
+#define EEPROM_BOARD_TYPE_REDBOX 0x00
+#define EEPROM_BOARD_TYPE_PLUGIN 0x01
+
typedef struct {
CHAR8 signature[8];
@@ -79,6 +87,8 @@ typedef struct {
// UINT8 mapdata[0];
}EEPROM_MAP;
+#define EEPROM_MAP_SIGNATURE "$EeprMap"
+
typedef struct {
CHAR8 maplabel[16];
@@ -88,6 +98,10 @@ typedef struct {
CHAR8 reserved[7];
}EEPROM_MAP_RECORD;
+#define EEPROM_SPEED_STANDARD 0x01
+#define EEPROM_SPEED_FAST 0x02
+#define EEPROM_SPEED_HIGH 0x03
+
typedef struct {
CHAR8 signature[8];
@@ -98,6 +112,8 @@ typedef struct {
// UINT8 gpiodata[0];
}GPIO_DATA_HEADER;
+#define EEPROM_GPIO_SIGNATURE "$GpioDat"
+
typedef struct {
CHAR8 gpiolabel[16];
@@ -110,6 +126,12 @@ typedef struct {
CHAR8 reserved[14];
}GPIO_DATA_RECORD;
+#define EEPROM_GPIO_TYPE_IO 0x00
+#define EEPROM_GPIO_TYPE_MMIO 0x01
+#define EEPROM_GPIO_TYPE_PCI 0x02
+#define EEPROM_GPIO_TYPE_PCIE 0x03
+#define EEPROM_GPIO_TYPE_PAD_OFFSET 0x04
+
typedef struct {
CHAR8 signature[8];
@@ -120,6 +142,8 @@ typedef struct {
// UINT8 hdacodec[0];
}HDA_CODEC;
+#define EEPROM_HDA_CODEC_SIGNATURE "$HdCodec"
+
typedef struct {
CHAR8 signature[8];
@@ -129,7 +153,9 @@ typedef struct {
UINT16 spdslot;
CHAR8 reserved[14];
// UINT8 spddata[0];
-}MEMORY_SPD;
+}MEMORY_DATA;
+
+#define EEPROM_MEMORY_DATA_SIGNATURE "$MemCnfg"
typedef struct {
@@ -144,6 +170,8 @@ typedef struct {
// UINT8 nicdata[0];
}NIC_INFO;
+#define EEPROM_NIC_INFO_SIGNATURE "$MacInfo"
+
typedef struct {
CHAR8 signature[8];
@@ -155,6 +183,15 @@ typedef struct {
// UINT8 eepromsig[0];
}SIGNATURE_DATA;
+#define EEPROM_SIGNATURE_SIGNATURE "$PromSig"
+#define EEPROM_SIGNATURE_TYPE_NONE 0x0000
+#define EEPROM_SIGNATURE_TYPE_MD5 0x0001
+#define EEPROM_SIGNATURE_TYPE_SHA1 0x0002
+#define EEPROM_SIGNATURE_TYPE_SHA256 0x0003
+#define EEPROM_SIGNATURE_TYPE_SHA384 0x0004
+#define EEPROM_SIGNATURE_TYPE_SHA512 0x0005
+#define EEPROM_SIGNATURE_TYPE_SIGNED 0x8000
+
typedef struct {
CHAR8 signature[8];
@@ -165,6 +202,8 @@ typedef struct {
// UINT8 ucodedata[0];
}MICROCODE;
+#define EEPROM_MICROCODE_SIGNATURE "$uCode$"
+
typedef struct {
CHAR8 signature[8];
@@ -175,6 +214,8 @@ typedef struct {
// UINT8 videodata[0];
}VIDEO_DATA;
+#define EEPROM_VIDEO_DATA_SIGNATURE "$Video$"
+
typedef struct {
CHAR8 signature[8];
@@ -185,5 +226,7 @@ typedef struct {
// UINT8 logodata[0];
}LOGO_DATA;
+#define EEPROM_LOGO_DATA_SIGNATURE "$Logo$"
+
#pragma pack()
#endif
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Library/EepromDataLib.h b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Library/EepromDataLib.h
index 0d71b3d..0c9fcfe 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Library/EepromDataLib.h
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Library/EepromDataLib.h
@@ -67,6 +67,13 @@ typedef struct {
////
//// Functions
////
+UINTN
+EFIAPI
+DisplayStackPointer (
+ IN CHAR8 *Function,
+ IN UINTN LineNumber
+ );
+
//
// Desc: Copies the contents of an existing memory pool into a new memory pool of equal or greater size.
// Variables: Size Size of the pool to copy existing pool into
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Library/EepromLib.h b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Library/EepromLib.h
index b386e8c..f9bcdb6 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Library/EepromLib.h
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Library/EepromLib.h
@@ -19,6 +19,7 @@
#include <Uefi.h>
#include <EepromStruct.h>
+#include <Library/EepromDataLib.h>
////
@@ -28,28 +29,8 @@
////
-//// Enums
-////
-typedef enum {
- HASH_NONE = 0,
- HASH_MD5 = 1,
- HASH_SHA1 = 2,
- HASH_SHA256 = 3,
- HASH_SHA384 = 4,
- HASH_SHA512 = 5
-} EEPROM_HASH_TYPE;
-
-
-////
//// Functions
////
-UINTN
-EFIAPI
-DisplayStackPointer (
- IN CHAR8 *Function,
- IN UINTN LineNumber
- );
-
EFI_STATUS
EFIAPI
EraseEeprom (
@@ -83,8 +64,7 @@ GetNextEepromStructure (
UINT8
EFIAPI
GetValidEepromLibrary (
- IN BOOLEAN CopyToMemory,
- IN BOOLEAN MemoryInitialized
+ IN BOOLEAN CopyToMemory
);
BOOLEAN
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Library/EepromPlatformLib.h b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Library/EepromPlatformLib.h
new file mode 100644
index 0000000..b585327
--- /dev/null
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Eeprom/Include/Library/EepromPlatformLib.h
@@ -0,0 +1,117 @@
+/** @file
+ Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
+
+ 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.
+
+**/
+
+#ifndef _EEPROM_PLATFORM_LIB_
+#define _EEPROM_PLATFORM_LIB_
+////
+//// Header files
+////
+#include <Uefi.h>
+
+#include <EepromStruct.h>
+#include <Library/EepromDataLib.h>
+#include <Library/EepromLib.h>
+
+
+////
+//// defines
+////
+#define END_OF_GPIO_ARRAY 0xFFFFFFFF
+
+
+////
+//// Functions
+////
+/**
+ Returns the $BrdInfo structure
+
+ @param[out] BoardInfo Buffer containing the BOARD_INFO_TABLE structure
+ - Up to the caller to free the buffer
+
+ @retval EFI_SUCCESS $BrdInfo structure found
+ @retval EFI_NOT_FOUND $BrdInfo structure not found
+**/
+EFI_STATUS
+EepromGetBoardInfo (
+ OUT BOARD_INFO_TABLE **BoardInfo
+ );
+
+/**
+ Returns the $Logo$ data
+
+ @param[out] LogoData Buffer containing the $Logo$ data
+ @param[out] LogoSize Size of the LogoData buffer
+
+ @retval EFI_SUCCESS $Logo$ data found
+ @retval EFI_NOT_FOUND $Logo$ data not found
+**/
+EFI_STATUS
+EepromGetLogo (
+ OUT UINT8 **LogoData,
+ OUT UINT32 *LogoSize
+ );
+
+/**
+ Returns the $Video$ data
+
+ @param[out] VideoData Buffer containing the $Video$ data
+ @param[out] VideoSize Size of the VideoData buffer
+
+ @retval EFI_SUCCESS $Logo$ data found
+ @retval EFI_NOT_FOUND $Logo$ data not found
+**/
+
+EFI_STATUS
+EepromGetVbt (
+ OUT UINT8 **VideoData,
+ OUT UINT32 *VideoSize
+ );
+
+/**
+ Checks whether the PadOffset is in the platform GPIO whitelist.
+
+ @param[in] PadOffset The PAD offset to check against the platform whitelist
+
+ @retval TRUE PAD offset is in the whitelist
+ @retval FALSE PAD offset is not in the whitelist
+**/
+BOOLEAN
+EepromPadCheck (
+ IN UINT32 PadOffset
+ );
+
+/**
+ Programs the ACPI SSDT data in $AcpiTbl
+
+ @param[in] VOID
+
+ @retval EFI_SUCCESS $AcpiTbl data found
+ @retval EFI_NOT_FOUND $AcpiTbl data not found
+ @retval EFI_NOT_READY $AcpiTbl data not ready to be programmed
+**/
+EFI_STATUS
+EepromProgramAcpi (VOID);
+
+/**
+ Program GPIOs per binary and whitelist.
+
+ @param[in] VOID
+
+ @retval EFI_SUCCESS GPIOs programmed successfully.
+ @retval EFI_NOT_FOUND GPIO data not found.
+**/
+EFI_STATUS
+EepromProgramGpioPads (VOID);
+
+#endif // _EEPROM_PLATFORM_LIB_
+
--
2.10.1.windows.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2018-08-17 9:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-17 9:59 [Patch][edk2-platforms/devel-IntelAtomProcessorE3900] EEPROM change Guo, Mang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox