diff options
91 files changed, 1798 insertions, 304 deletions
diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec index ab3c3b3..a2b7c17 100644 --- a/ArmPkg/ArmPkg.dec +++ b/ArmPkg/ArmPkg.dec @@ -87,6 +87,8 @@ # Include/Guid/ArmMpCoreInfo.h
gArmMpCoreInfoGuid = { 0xa4ee0728, 0xe5d7, 0x4ac5, {0xb2, 0x1e, 0x65, 0x8e, 0xd8, 0x57, 0xe8, 0x34} }
+ gArmTransferListHobGuid = { 0xebe7bae8, 0xfe18, 0x43c5, { 0xbf, 0x3f, 0xf2, 0xb1, 0xaf, 0xb2, 0xdf, 0xb8 } }
+
[Protocols.common]
## Arm System Control and Management Interface(SCMI) Base protocol
## ArmPkg/Include/Protocol/ArmScmiBaseProtocol.h
@@ -106,6 +108,7 @@ [Ppis]
## Include/Ppi/ArmMpCoreInfo.h
gArmMpCoreInfoPpiGuid = { 0x6847cc74, 0xe9ec, 0x4f8f, {0xa2, 0x9d, 0xab, 0x44, 0xe7, 0x54, 0xa8, 0xfc} }
+ gArmTransferListPpiGuid = { 0x6d2e9da1, 0x9414, 0x41c3, {0x86, 0xbe, 0xf9, 0x16, 0x9f, 0xb4, 0x76, 0x38} }
[PcdsFeatureFlag.common]
gArmTokenSpaceGuid.PcdCpuDxeProduceDebugSupport|FALSE|BOOLEAN|0x00000001
diff --git a/ArmPkg/Include/Guid/TransferListHob.h b/ArmPkg/Include/Guid/TransferListHob.h new file mode 100644 index 0000000..b8f9cc0 --- /dev/null +++ b/ArmPkg/Include/Guid/TransferListHob.h @@ -0,0 +1,23 @@ +/** @file
+ GUID for the HOB that contains the copy of the Transfer List
+
+ Copyright (C) 2024, Arm Limited. All rights reserved.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - https://github.com/FirmwareHandoff/firmware_handoff
+
+**/
+
+#ifndef ARM_TRANSFER_LIST_HOB_H__
+#define ARM_TRANSFER_LIST_HOB_H__
+
+#define ARM_TRANSFER_LIST_HOB_GUID {\
+ 0xebe7bae8, 0xfe18, 0x43c5, \
+ { 0xbf, 0x3f, 0xf2, 0xb1, 0xaf, 0xb2, 0xdf, 0xb8 } \
+ }
+
+extern EFI_GUID gArmTransferListHobGuid;
+
+#endif
diff --git a/ArmPkg/Include/IndustryStandard/ArmTransferList.h b/ArmPkg/Include/IndustryStandard/ArmTransferList.h index 455c7d8..3033846 100644 --- a/ArmPkg/Include/IndustryStandard/ArmTransferList.h +++ b/ArmPkg/Include/IndustryStandard/ArmTransferList.h @@ -2,7 +2,7 @@ Header file defining a Transfer List and Transfer Entry as specified by the
A-profile Firmware Handoff Protocol specification.
- Copyright (c) 2024, Arm Limited. All rights reserved.<BR>
+ Copyright (c) 2025, Arm Limited. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@par Reference(s):
@@ -74,6 +74,16 @@ #define TRANSFER_LIST_FL_HAS_CHECKSUM BIT0
/*
+ * Operation codes indicating the validity of the Transfer List.
+ */
+typedef enum {
+ TRANSFER_LIST_OPS_INVALID, /* invalid for any operation */
+ TRANSFER_LIST_OPS_ALL, /* valid for all operations */
+ TRANSFER_LIST_OPS_RO, /* valid for read only */
+ TRANSFER_LIST_OPS_CUSTOM, /* abort or switch to special code to interpret */
+} TRANSFER_LIST_OPS;
+
+/*
* Transfer list starts with the following header.
* Transfer entries followed after the following header.
*/
diff --git a/ArmPkg/Include/Library/ArmTransferListLib.h b/ArmPkg/Include/Library/ArmTransferListLib.h index 96a1227..fb0c699 100644 --- a/ArmPkg/Include/Library/ArmTransferListLib.h +++ b/ArmPkg/Include/Library/ArmTransferListLib.h @@ -2,7 +2,7 @@ Library that implements the helper functions to parse and pack a Transfer
List as specified by the A-profile Firmware Handoff Specification.
- Copyright (c) 2022, Arm Limited. All rights reserved.<BR>
+ Copyright (c) 2022 - 2025, Arm Limited. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@par Reference(s):
@@ -21,7 +21,7 @@ /**
Return the first Transfer Entry Node in the Transfer List.
- @param [in] TransferListHeader TransferListHeader
+ @param [in] TransferListHeader Pointer to the Transfer List Header.
@return Pointer to the Transfer Entry Node if successful otherwise NULL
@@ -103,4 +103,58 @@ TransferListGetEntryData ( IN TRANSFER_ENTRY_HEADER *TransferEntry
);
+/**
+ Dump the transfer list to the debug output.
+
+ @param [in] TransferListHeader Pointer to the Transfer List Header
+
+**/
+VOID
+EFIAPI
+TransferListDump (
+ IN TRANSFER_LIST_HEADER *TransferListHeader
+ );
+
+/**
+ Verify the checksum of the transfer list.
+
+ @param [in] TransferListHeader Pointer to the Transfer List Header
+
+ @retval FALSE Invalid Checksum
+ @retval TRUE Valid Checksum
+**/
+BOOLEAN
+EFIAPI
+TransferListVerifyChecksum (
+ IN TRANSFER_LIST_HEADER *TransferListHeader
+ );
+
+/**
+ Check the header of the Transfer List.
+
+ @param [in] TransferListHeader Pointer to the Transfer List Header
+
+ @return TRANSFER_LIST_OPS code indicating the validity of the Transfer List
+**/
+TRANSFER_LIST_OPS
+EFIAPI
+TransferListCheckHeader (
+ IN TRANSFER_LIST_HEADER *TransferListHeader
+ );
+
+/**
+ Find a Transfer Entry Node in the Transfer List matched with the given tag-id.
+
+ @param [in] TransferListHeader Pointer to the Transfer List Header
+ @param [in] TagId Tag id
+
+ @return Pointer to the Transfer Entry Node if successful otherwise NULL
+**/
+TRANSFER_ENTRY_HEADER *
+EFIAPI
+TransferListFindEntry (
+ IN TRANSFER_LIST_HEADER *TransferListHeader,
+ IN UINT16 TagId
+ );
+
#endif // ARM_TRANSFER_LIST_LIB_
diff --git a/ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.c b/ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.c index 7cd203e..af8170e 100644 --- a/ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.c +++ b/ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.c @@ -2,7 +2,7 @@ Library that implements the helper functions to parse and pack a Transfer
List as specified by the A-profile Firmware Handoff Specification.
- Copyright (c) 2022, Arm Limited. All rights reserved.<BR>
+ Copyright (c) 2022 - 2025, Arm Limited. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@par Reference(s):
@@ -15,6 +15,90 @@ #include <Library/DebugLib.h>
/**
+ This function verifies the checksum of the Transfer List.
+
+ @param [in] TransferListHeader Pointer to the Transfer List Header
+
+ @retval FALSE Invalid Checksum
+ @retval TRUE Valid Checksum
+
+**/
+BOOLEAN
+EFIAPI
+TransferListVerifyChecksum (
+ IN TRANSFER_LIST_HEADER *TransferListHeader
+ )
+{
+ if (TransferListHeader == NULL) {
+ return FALSE;
+ }
+
+ if ((TransferListHeader->Flags & TRANSFER_LIST_FL_HAS_CHECKSUM) == 0) {
+ return TRUE;
+ }
+
+ return (CalculateSum8 ((UINT8 *)TransferListHeader, TransferListHeader->UsedSize) == 0);
+}
+
+/**
+ This function checks the header of the Transfer List.
+
+ @param [in] TransferListHeader Pointer to the Transfer List Header
+
+ @return TRANSFER_LIST_OPS code indicating the validity of the Transfer List
+
+**/
+TRANSFER_LIST_OPS
+EFIAPI
+TransferListCheckHeader (
+ IN TRANSFER_LIST_HEADER *TransferListHeader
+ )
+{
+ if (TransferListHeader == NULL) {
+ return TRANSFER_LIST_OPS_INVALID;
+ }
+
+ if (TransferListHeader->Signature != TRANSFER_LIST_SIGNATURE_64) {
+ DEBUG ((DEBUG_ERROR, "Bad transfer list signature 0x%x\n", TransferListHeader->Signature));
+ return TRANSFER_LIST_OPS_INVALID;
+ }
+
+ if (TransferListHeader->TotalSize == 0) {
+ DEBUG ((DEBUG_ERROR, "Bad transfer list total size 0x%x\n", TransferListHeader->TotalSize));
+ return TRANSFER_LIST_OPS_INVALID;
+ }
+
+ if (TransferListHeader->UsedSize > TransferListHeader->TotalSize) {
+ DEBUG ((DEBUG_ERROR, "Bad transfer list used size 0x%x\n", TransferListHeader->UsedSize));
+ return TRANSFER_LIST_OPS_INVALID;
+ }
+
+ if (TransferListHeader->HeaderSize != sizeof (TRANSFER_LIST_HEADER)) {
+ DEBUG ((DEBUG_ERROR, "Bad transfer list header size 0x%x\n", TransferListHeader->HeaderSize));
+ return TRANSFER_LIST_OPS_INVALID;
+ }
+
+ if (TransferListVerifyChecksum (TransferListHeader) == FALSE) {
+ DEBUG ((DEBUG_ERROR, "Bad transfer list checksum 0x%x\n", TransferListHeader->Checksum));
+ return TRANSFER_LIST_OPS_INVALID;
+ }
+
+ if (TransferListHeader->Version == 0) {
+ DEBUG ((DEBUG_ERROR, "Transfer list version is invalid\n"));
+ return TRANSFER_LIST_OPS_INVALID;
+ } else if (TransferListHeader->Version == ARM_FW_HANDOFF_PROTOCOL_VERSION) {
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Transfer list version is valid for all operations\n"));
+ return TRANSFER_LIST_OPS_ALL;
+ } else if (TransferListHeader->Version > ARM_FW_HANDOFF_PROTOCOL_VERSION) {
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Transfer list version is valid for read-only\n"));
+ return TRANSFER_LIST_OPS_RO;
+ }
+
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Old or custom transfer list version is detected\n"));
+ return TRANSFER_LIST_OPS_CUSTOM;
+}
+
+/**
Return the first Transfer Entry Node in the Transfer List.
@param [in] TransferListHeader TransferListHeader
@@ -165,3 +249,73 @@ TransferListGetEntryData ( return (VOID *)((UINTN)TransferEntry + TransferEntry->HeaderSize);
}
+
+/**
+ Find a Transfer Entry Node in the Transfer List matched with the given tag-id.
+
+ @param [in] TransferListHeader Pointer to the Transfer List Header
+ @param [in] TagId Tag id
+
+ @return Pointer to the Transfer Entry Node if successful otherwise NULL
+**/
+TRANSFER_ENTRY_HEADER *
+EFIAPI
+TransferListFindEntry (
+ IN TRANSFER_LIST_HEADER *TransferListHeader,
+ IN UINT16 TagId
+ )
+{
+ TRANSFER_ENTRY_HEADER *Entry = NULL;
+
+ do {
+ Entry = TransferListGetNextEntry (TransferListHeader, Entry);
+ } while ((Entry != NULL) && (Entry->TagId != TagId));
+
+ return Entry;
+}
+
+/**
+ Dump the transfer list to the debug output.
+
+ @param [in] TransferListHeader Pointer to the Transfer List Header
+
+**/
+VOID
+EFIAPI
+TransferListDump (
+ IN TRANSFER_LIST_HEADER *TransferListHeader
+ )
+{
+ TRANSFER_ENTRY_HEADER *Entry;
+ UINTN Idx;
+
+ Entry = NULL;
+ Idx = 0;
+
+ if (TransferListHeader == NULL) {
+ return;
+ }
+
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Dump transfer list:\n"));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "signature 0x%x\n", TransferListHeader->Signature));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "checksum 0x%x\n", TransferListHeader->Checksum));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "version 0x%x\n", TransferListHeader->Version));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "hdr_size 0x%x\n", TransferListHeader->HeaderSize));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "alignment 0x%x\n", TransferListHeader->Alignment));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "used_size 0x%x\n", TransferListHeader->UsedSize));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "total_size 0x%x\n", TransferListHeader->TotalSize));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "flags 0x%x\n", TransferListHeader->Flags));
+
+ while (TRUE) {
+ Entry = TransferListGetNextEntry (TransferListHeader, Entry);
+ if (Entry == NULL) {
+ break;
+ }
+
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Entry %d:\n", Idx++));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "tag_id 0x%x\n", Entry->TagId));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "hdr_size 0x%x\n", Entry->HeaderSize));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "data_size 0x%x\n", Entry->DataSize));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "data_addr 0x%lx\n", (UINTN)TransferListGetEntryData (Entry)));
+ }
+}
diff --git a/ArmPlatformPkg/ArmPlatformPkg.dsc b/ArmPlatformPkg/ArmPlatformPkg.dsc index 062246d..278d3cf 100644 --- a/ArmPlatformPkg/ArmPlatformPkg.dsc +++ b/ArmPlatformPkg/ArmPlatformPkg.dsc @@ -70,6 +70,7 @@ UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
+ ArmTransferListLib|ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.inf
[LibraryClasses.common.PEIM]
HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
diff --git a/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c b/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c index 60f9bc5..e8e2e1d 100644 --- a/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c +++ b/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c @@ -193,7 +193,7 @@ PL011UartInitializePort ( return RETURN_INVALID_PARAMETER;
}
- Divisor = (UartClkInHz * 4) / *BaudRate;
+ Divisor = (UINT32)((UartClkInHz * 4) / *BaudRate);
Integer = Divisor >> FRACTION_PART_SIZE_IN_BITS;
Fractional = Divisor & FRACTION_PART_MASK;
}
diff --git a/ArmPlatformPkg/PeilessSec/AArch64/ModuleEntryPoint.S b/ArmPlatformPkg/PeilessSec/AArch64/ModuleEntryPoint.S index 5f285f3..94635ef 100644 --- a/ArmPlatformPkg/PeilessSec/AArch64/ModuleEntryPoint.S +++ b/ArmPlatformPkg/PeilessSec/AArch64/ModuleEntryPoint.S @@ -1,13 +1,29 @@ //
-// Copyright (c) 2011 - 2020, Arm Limited. All rights reserved.<BR>
+// Copyright (c) 2011 - 2025, Arm Limited. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
+// @Par Reference(s):
+// - Firmware Handoff specification [https://firmwarehandoff.github.io/firmware_handoff/main]
//
#include <AsmMacroLib.h>
ASM_FUNC(_ModuleEntryPoint)
+
+ // Check if register assignment at handoff matches spec
+ MOV64 (x4, 0x14a0fb10b)
+ cmp x1, x4
+ // Skip TransferList init if x1 is not equal to the TransferList signature
+ b.ne _SkipTransferList
+
+ // Skip TransferList init if x2 is not equal to 0
+ cbnz x2, _SkipTransferList
+
+ // Set the TransferList Base Address from register x3
+ mov x6, x3
+
+_SkipTransferList:
// Do early platform specific actions
bl ASM_PFX(ArmPlatformPeiBootAction)
@@ -76,6 +92,8 @@ _GetStackBase: MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
sub x1, x1, x2
+ // Pass Transfer List Base Address
+ mov x2, x6
// Move sec startup address into a data register
// Ensure we're jumping to FV version of the code (not boot remapped alias)
ldr x4, =ASM_PFX(CEntryPoint)
diff --git a/ArmPlatformPkg/PeilessSec/PeilessSec.c b/ArmPlatformPkg/PeilessSec/PeilessSec.c index 639c374..b9b7196 100644 --- a/ArmPlatformPkg/PeilessSec/PeilessSec.c +++ b/ArmPlatformPkg/PeilessSec/PeilessSec.c @@ -53,13 +53,15 @@ GetPlatformPpi ( @param[in] UefiMemoryBase Start of the PI/UEFI memory region
@param[in] StackBase Start of the stack
@param[in] StartTimeStamp Timer value at start of execution
+ @param[in] TransferListBaseAddr Base address of the Transfer List
**/
STATIC
VOID
SecMain (
IN UINTN UefiMemoryBase,
IN UINTN StackBase,
- IN UINT64 StartTimeStamp
+ IN UINT64 StartTimeStamp,
+ IN UINTN TransferListBaseAddr
)
{
EFI_HOB_HANDOFF_INFO_TABLE *HobList;
@@ -71,6 +73,8 @@ SecMain ( UINTN CharCount;
UINTN StacksSize;
FIRMWARE_SEC_PERFORMANCE Performance;
+ VOID *TransferListBase;
+ UINTN *TransferListHobData;
// If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)
ASSERT (
@@ -134,6 +138,25 @@ SecMain ( }
}
+ // Dump the Transfer List
+ TransferListBase = (VOID *)TransferListBaseAddr;
+ if (TransferListBase != NULL) {
+ if (TransferListCheckHeader (TransferListBase) != TRANSFER_LIST_OPS_INVALID) {
+ DEBUG_CODE_BEGIN ();
+ TransferListDump (TransferListBase);
+ DEBUG_CODE_END ();
+
+ TransferListHobData = BuildGuidHob (&gArmTransferListHobGuid, sizeof (*TransferListHobData));
+ ASSERT (TransferListHobData != NULL);
+
+ *TransferListHobData = (UINTN)TransferListBase;
+ } else {
+ DEBUG ((DEBUG_ERROR, "%a: No valid operations possible on TransferList found @ 0x%p\n", __func__, TransferListBase));
+ }
+ } else {
+ DEBUG ((DEBUG_INFO, "%a: No TransferList found, continuing boot\n", __func__));
+ }
+
// Store timer value logged at the beginning of firmware image execution
Performance.ResetEnd = GetTimeInNanoSecond (StartTimeStamp);
@@ -167,11 +190,13 @@ SecMain ( @param[in] UefiMemoryBase Start of the PI/UEFI memory region
@param[in] StackBase Start of the stack
+ @param[in] TransferListBaseAddr Base address of the Transfer List
**/
VOID
CEntryPoint (
IN UINTN UefiMemoryBase,
- IN UINTN StackBase
+ IN UINTN StackBase,
+ IN UINTN TransferListBaseAddr
)
{
UINT64 StartTimeStamp;
@@ -198,7 +223,7 @@ CEntryPoint ( FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)
);
- SecMain (UefiMemoryBase, StackBase, StartTimeStamp);
+ SecMain (UefiMemoryBase, StackBase, StartTimeStamp, TransferListBaseAddr);
// DXE Core should always load and never return
ASSERT (FALSE);
diff --git a/ArmPlatformPkg/PeilessSec/PeilessSec.h b/ArmPlatformPkg/PeilessSec/PeilessSec.h index 70d78ca..73b6b25 100644 --- a/ArmPlatformPkg/PeilessSec/PeilessSec.h +++ b/ArmPlatformPkg/PeilessSec/PeilessSec.h @@ -24,6 +24,8 @@ #include <Library/PrintLib.h>
#include <Library/SerialPortLib.h>
#include <Library/TimerLib.h>
+#include <Library/ArmTransferListLib.h>
+#include <Guid/TransferListHob.h>
#include <Ppi/ArmMpCoreInfo.h>
#include <Ppi/GuidedSectionExtraction.h>
diff --git a/ArmPlatformPkg/PeilessSec/PeilessSec.inf b/ArmPlatformPkg/PeilessSec/PeilessSec.inf index e210d01..db7449f 100644 --- a/ArmPlatformPkg/PeilessSec/PeilessSec.inf +++ b/ArmPlatformPkg/PeilessSec/PeilessSec.inf @@ -52,6 +52,7 @@ SerialPortLib
TimerLib
StackCheckLib
+ ArmTransferListLib
[Ppis]
gArmMpCoreInfoPpiGuid
@@ -59,6 +60,7 @@ [Guids]
gArmMpCoreInfoGuid
gEfiFirmwarePerformanceGuid
+ gArmTransferListHobGuid
[FeaturePcd]
gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob
diff --git a/ArmPlatformPkg/PlatformPei/PlatformPeim.c b/ArmPlatformPkg/PlatformPei/PlatformPeim.c index 62d1faf..921371a 100644 --- a/ArmPlatformPkg/PlatformPei/PlatformPeim.c +++ b/ArmPlatformPkg/PlatformPei/PlatformPeim.c @@ -24,6 +24,7 @@ #include <Library/PeimEntryPoint.h>
#include <Library/PeiServicesLib.h>
#include <Library/PcdLib.h>
+#include <Guid/TransferListHob.h>
EFI_STATUS
EFIAPI
@@ -76,14 +77,30 @@ InitializePlatformPeim ( IN CONST EFI_PEI_SERVICES **PeiServices
)
{
- EFI_STATUS Status;
- EFI_BOOT_MODE BootMode;
+ EFI_STATUS Status;
+ EFI_BOOT_MODE BootMode;
+ VOID *TransferListBase;
+ UINTN *TransferListHobData;
+ EFI_HOB_GUID_TYPE *GuidHob;
DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Platform PEIM Loaded\n"));
Status = PeiServicesSetBootMode (ArmPlatformGetBootMode ());
ASSERT_EFI_ERROR (Status);
+ // If TransferList PPI is present and TransferListHobGuid is not present,
+ // then create a TransferListHob with the TransferListBase address.
+ Status = PeiServicesLocatePpi (&gArmTransferListPpiGuid, 0, NULL, &TransferListBase);
+ if (!EFI_ERROR (Status)) {
+ GuidHob = GetFirstGuidHob (&gArmTransferListHobGuid);
+ if ((GuidHob == NULL) && (TransferListBase != NULL)) {
+ TransferListHobData = BuildGuidHob (&gArmTransferListHobGuid, sizeof (*TransferListHobData));
+ ASSERT (TransferListHobData != NULL);
+
+ *TransferListHobData = (UINTN)TransferListBase;
+ }
+ }
+
PlatformPeim ();
Status = PeiServicesGetBootMode (&BootMode);
diff --git a/ArmPlatformPkg/PlatformPei/PlatformPeim.inf b/ArmPlatformPkg/PlatformPei/PlatformPeim.inf index f2b0e0f..d9e8f32 100644 --- a/ArmPlatformPkg/PlatformPei/PlatformPeim.inf +++ b/ArmPlatformPkg/PlatformPei/PlatformPeim.inf @@ -43,6 +43,7 @@ [Ppis]
gEfiPeiMasterBootModePpiGuid # PPI ALWAYS_PRODUCED
gEfiPeiBootInRecoveryModePpiGuid # PPI SOMETIMES_PRODUCED
+ gArmTransferListPpiGuid # PPI SOMETIMES_CONSUMED
[FixedPcd]
gArmTokenSpaceGuid.PcdFdBaseAddress
@@ -51,6 +52,9 @@ gArmTokenSpaceGuid.PcdFvBaseAddress
gArmTokenSpaceGuid.PcdFvSize
+[Guids]
+ gArmTransferListHobGuid
+
[Depex]
TRUE
diff --git a/ArmPlatformPkg/Sec/AArch64/ModuleEntryPoint.S b/ArmPlatformPkg/Sec/AArch64/ModuleEntryPoint.S index 154be11..28cd015 100644 --- a/ArmPlatformPkg/Sec/AArch64/ModuleEntryPoint.S +++ b/ArmPlatformPkg/Sec/AArch64/ModuleEntryPoint.S @@ -8,6 +8,19 @@ #include <AsmMacroLib.h>
ASM_FUNC(_ModuleEntryPoint)
+ // Check if register assignment at handoff matches spec
+ MOV64 (x4, 0x14a0fb10b)
+ // Check if x1 holds TransferList signature
+ cmp x1, x4
+ b.ne _SkipTransferList
+
+ // Skip TransferList init if x2 is not equal to 0
+ cbnz x2, _SkipTransferList
+
+ // Set the TransferList Base Address from register x3
+ mov x10, x3
+
+_SkipTransferList:
// Do early platform specific actions
bl ASM_PFX(ArmPlatformPeiBootAction)
@@ -47,7 +60,8 @@ ASM_PFX(MainEntryPoint): // The PEI Core Entry Point has been computed by GenFV and stored in the second entry of the Reset Vector
MOV64 (x2, FixedPcdGet64(PcdFvBaseAddress))
ldr x0, [x2, #8]
-
+ // Pass the TransferList Base Address
+ mov x1, x10
// Move sec startup address into a data register
// Ensure we're jumping to FV version of the code (not boot remapped alias)
ldr x3, =ASM_PFX(CEntryPoint)
diff --git a/ArmPlatformPkg/Sec/Sec.c b/ArmPlatformPkg/Sec/Sec.c index 4535ae7..ec8bec2 100644 --- a/ArmPlatformPkg/Sec/Sec.c +++ b/ArmPlatformPkg/Sec/Sec.c @@ -86,12 +86,14 @@ STATIC CONST EFI_PEI_PPI_DESCRIPTOR gCommonPpiTable[] = { @param[out] PpiListSize Size of the PPI list in bytes
@param[out] PpiList Pointer to the constructed PPI list
+ @param[in] TransferListBase Pointer to the Transfer List base
**/
STATIC
VOID
CreatePpiList (
OUT UINTN *PpiListSize,
- OUT EFI_PEI_PPI_DESCRIPTOR **PpiList
+ OUT EFI_PEI_PPI_DESCRIPTOR **PpiList,
+ IN VOID *TransferListBase
)
{
EFI_PEI_PPI_DESCRIPTOR *PlatformPpiList;
@@ -111,10 +113,20 @@ CreatePpiList ( // Set the Terminate flag on the last PPI entry
LastPpi = (EFI_PEI_PPI_DESCRIPTOR *)ListBase +
((sizeof (gCommonPpiTable) + PlatformPpiListSize) / sizeof (EFI_PEI_PPI_DESCRIPTOR)) - 1;
+ *PpiListSize = sizeof (gCommonPpiTable) + PlatformPpiListSize;
+
+ // Add the Transfer List PPI after the Common and Platform PPIs
+ if (TransferListBase != NULL) {
+ LastPpi++;
+ LastPpi->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI;
+ LastPpi->Guid = &gArmTransferListPpiGuid;
+ LastPpi->Ppi = TransferListBase;
+ *PpiListSize += sizeof (EFI_PEI_PPI_DESCRIPTOR);
+ }
+
LastPpi->Flags |= EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
- *PpiList = (EFI_PEI_PPI_DESCRIPTOR *)ListBase;
- *PpiListSize = sizeof (gCommonPpiTable) + PlatformPpiListSize;
+ *PpiList = (EFI_PEI_PPI_DESCRIPTOR *)ListBase;
}
/**
@@ -151,12 +163,15 @@ PrintFirmwareVersion ( @param[in] PeiCoreEntryPoint Address in ram of the entrypoint of the PEI
core
+ @param[in] TransferListBaseAddr Address of the Transfer List base address
+
**/
STATIC
VOID
EFIAPI
SecMain (
- IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
+ IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint,
+ IN UINTN TransferListBaseAddr
)
{
EFI_SEC_PEI_HAND_OFF SecCoreData;
@@ -164,8 +179,24 @@ SecMain ( EFI_PEI_PPI_DESCRIPTOR *PpiList;
UINTN TemporaryRamBase;
UINTN TemporaryRamSize;
+ VOID *TransferListBase;
+
+ // Dump the Transfer List
+ TransferListBase = (VOID *)TransferListBaseAddr;
+ if (TransferListBase != NULL) {
+ if (TransferListCheckHeader (TransferListBase) != TRANSFER_LIST_OPS_INVALID) {
+ DEBUG_CODE_BEGIN ();
+ TransferListDump (TransferListBase);
+ DEBUG_CODE_END ();
+ } else {
+ TransferListBase = NULL;
+ DEBUG ((DEBUG_ERROR, "%a: No valid operations possible on TransferList found @ 0x%p\n", __func__, TransferListBase));
+ }
+ } else {
+ DEBUG ((DEBUG_INFO, "%a: No TransferList found, continuing boot\n", __func__));
+ }
- CreatePpiList (&PpiListSize, &PpiList);
+ CreatePpiList (&PpiListSize, &PpiList, TransferListBase);
// Adjust the Temporary Ram as the new Ppi List (Common + Platform Ppi Lists) is created at
// the base of the primary core stack
@@ -197,10 +228,13 @@ SecMain ( @param[in] PeiCoreEntryPoint Address in ram of the entrypoint of the PEI
core
+ @param[in] TransferListBaseAddr Address of the Transfer List base address
+
**/
VOID
CEntryPoint (
- IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
+ IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint,
+ IN UINTN TransferListBaseAddr
)
{
if (!ArmMmuEnabled ()) {
@@ -237,7 +271,7 @@ CEntryPoint ( ArmPlatformInitialize (ArmReadMpidr ());
// Goto primary Main.
- SecMain (PeiCoreEntryPoint);
+ SecMain (PeiCoreEntryPoint, TransferListBaseAddr);
// PEI Core should always load and never return
ASSERT (FALSE);
diff --git a/ArmPlatformPkg/Sec/Sec.h b/ArmPlatformPkg/Sec/Sec.h index 56d9f35..c1cd10d 100644 --- a/ArmPlatformPkg/Sec/Sec.h +++ b/ArmPlatformPkg/Sec/Sec.h @@ -23,6 +23,7 @@ #include <Library/SerialPortLib.h>
#include <Ppi/TemporaryRamSupport.h>
+#include <Library/ArmTransferListLib.h>
/**
Helper function to switch to a different stack. Implemented in assembler as
diff --git a/ArmPlatformPkg/Sec/Sec.inf b/ArmPlatformPkg/Sec/Sec.inf index a75ce8d..6206707 100644 --- a/ArmPlatformPkg/Sec/Sec.inf +++ b/ArmPlatformPkg/Sec/Sec.inf @@ -48,9 +48,11 @@ PrintLib
SerialPortLib
StackCheckLib
+ ArmTransferListLib
[Ppis]
gEfiTemporaryRamSupportPpiGuid
+ gArmTransferListPpiGuid
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString
diff --git a/ArmVirtPkg/ArmVirtCloudHv.dsc b/ArmVirtPkg/ArmVirtCloudHv.dsc index 541e7c9..94a4ff1 100644 --- a/ArmVirtPkg/ArmVirtCloudHv.dsc +++ b/ArmVirtPkg/ArmVirtCloudHv.dsc @@ -61,6 +61,7 @@ TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf
TpmPlatformHierarchyLib|SecurityPkg/Library/PeiDxeTpmPlatformHierarchyLibNull/PeiDxeTpmPlatformHierarchyLib.inf
+ ArmTransferListLib|ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.inf
!include MdePkg/MdeLibs.dsc.inc
diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index fadd15f..1e239bb 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -63,6 +63,7 @@ [LibraryClasses.common]
ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf
ArmMmuLib|UefiCpuPkg/Library/ArmMmuLib/ArmMmuBaseLib.inf
+ ArmTransferListLib|ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.inf
# Virtio Support
VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf
diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template index 2108948..0caa1c9 100755 --- a/BaseTools/Conf/tools_def.template +++ b/BaseTools/Conf/tools_def.template @@ -929,18 +929,15 @@ DEFINE GCC_AARCH64_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -mlittle-endian -fno- DEFINE GCC_AARCH64_CC_XIPFLAGS = -mstrict-align -mgeneral-regs-only
DEFINE GCC_RISCV64_CC_XIPFLAGS = -mstrict-align -mgeneral-regs-only
DEFINE GCC_DLINK2_FLAGS_COMMON = -Wl,--script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds
-DEFINE GCC_IA32_X64_DLINK_COMMON = -nostdlib --pie --fatal-warnings -z,noexecstack --gc-sections
-DEFINE GCC_ARM_AARCH64_DLINK_COMMON= -Wl,--emit-relocs -nostdlib -Wl,--gc-sections -u $(IMAGE_ENTRY_POINT) -Wl,-e,$(IMAGE_ENTRY_POINT),-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map -Wl,--fatal-warnings -Wl,-z,noexecstack
+DEFINE GCC_ARM_AARCH64_DLINK_COMMON= -Wl,--emit-relocs -nostdlib -Wl,--gc-sections -u $(IMAGE_ENTRY_POINT) -Wl,-e,$(IMAGE_ENTRY_POINT),-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
DEFINE GCC_LOONGARCH64_DLINK_COMMON= -Wl,--emit-relocs -nostdlib -Wl,--gc-sections -u $(IMAGE_ENTRY_POINT) -Wl,-e,$(IMAGE_ENTRY_POINT),-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
DEFINE GCC_ARM_DLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON) -z common-page-size=0x20 -Wl,--pic-veneer
DEFINE GCC_AARCH64_DLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON) -z common-page-size=0x20
DEFINE GCC_LOONGARCH64_DLINK_FLAGS = DEF(GCC_LOONGARCH64_DLINK_COMMON) -z common-page-size=0x20
DEFINE GCC_ARM_AARCH64_ASLDLINK_FLAGS = -Wl,--defsym=PECOFF_HEADER_SIZE=0 DEF(GCC_DLINK2_FLAGS_COMMON) -z common-page-size=0x20
-DEFINE GCC_IA32_X64_ASLDLINK_FLAGS = DEF(GCC_IA32_X64_DLINK_COMMON) --entry _ReferenceAcpiTable -u $(IMAGE_ENTRY_POINT)
DEFINE GCC_ARM_ASLDLINK_FLAGS = DEF(GCC_ARM_DLINK_FLAGS) -Wl,--entry,ReferenceAcpiTable -u $(IMAGE_ENTRY_POINT) DEF(GCC_ARM_AARCH64_ASLDLINK_FLAGS)
DEFINE GCC_AARCH64_ASLDLINK_FLAGS = DEF(GCC_AARCH64_DLINK_FLAGS) -Wl,--entry,ReferenceAcpiTable -u $(IMAGE_ENTRY_POINT) DEF(GCC_ARM_AARCH64_ASLDLINK_FLAGS)
DEFINE GCC_LOONGARCH64_ASLDLINK_FLAGS = DEF(GCC_LOONGARCH64_DLINK_FLAGS) -Wl,--entry,ReferenceAcpiTable -u $(IMAGE_ENTRY_POINT)
-DEFINE GCC_IA32_X64_DLINK_FLAGS = DEF(GCC_IA32_X64_DLINK_COMMON) --entry _$(IMAGE_ENTRY_POINT) --file-alignment 0x20 --section-alignment 0x20 -Map $(DEST_DIR_DEBUG)/$(BASE_NAME).map
DEFINE GCC_ASM_FLAGS = -c -x assembler -imacros AutoGen.h
DEFINE GCC_PP_FLAGS = -E -x assembler-with-cpp -include AutoGen.h
DEFINE GCC_VFRPP_FLAGS = -x c -E -DVFRCOMPILE --include $(MODULE_NAME)StrDefs.h
@@ -1006,13 +1003,13 @@ DEFINE GCC49_ARM_ASLDLINK_FLAGS = DEF(GCC48_ARM_ASLDLINK_FLAGS) DEFINE GCC49_AARCH64_ASLDLINK_FLAGS = DEF(GCC48_AARCH64_ASLDLINK_FLAGS)
DEFINE GCC49_ASLCC_FLAGS = DEF(GCC48_ASLCC_FLAGS)
+DEFINE GCC5_DLINK_WARNING_FLAGS = -Wl,--fatal-warnings -Wl,-z,noexecstack -Wl,-z,notext
DEFINE GCC5_IA32_CC_FLAGS = DEF(GCC49_IA32_CC_FLAGS)
DEFINE GCC5_X64_CC_FLAGS = DEF(GCC49_X64_CC_FLAGS)
-DEFINE GCC5_IA32_X64_DLINK_COMMON = DEF(GCC49_IA32_X64_DLINK_COMMON)
-DEFINE GCC5_IA32_X64_ASLDLINK_FLAGS = DEF(GCC49_IA32_X64_ASLDLINK_FLAGS)
-DEFINE GCC5_IA32_X64_DLINK_FLAGS = DEF(GCC49_IA32_X64_DLINK_FLAGS)
+DEFINE GCC5_IA32_X64_ASLDLINK_FLAGS = DEF(GCC49_IA32_X64_ASLDLINK_FLAGS) DEF(GCC5_DLINK_WARNING_FLAGS)
+DEFINE GCC5_IA32_X64_DLINK_FLAGS = DEF(GCC49_IA32_X64_DLINK_FLAGS) DEF(GCC5_DLINK_WARNING_FLAGS)
DEFINE GCC5_IA32_DLINK2_FLAGS = DEF(GCC49_IA32_DLINK2_FLAGS) -Wno-error
-DEFINE GCC5_X64_DLINK_FLAGS = DEF(GCC49_X64_DLINK_FLAGS)
+DEFINE GCC5_X64_DLINK_FLAGS = DEF(GCC49_X64_DLINK_FLAGS) DEF(GCC5_DLINK_WARNING_FLAGS)
DEFINE GCC5_X64_DLINK2_FLAGS = DEF(GCC49_X64_DLINK2_FLAGS) -Wno-error
DEFINE GCC5_ASM_FLAGS = DEF(GCC49_ASM_FLAGS)
DEFINE GCC5_ARM_ASM_FLAGS = DEF(GCC49_ARM_ASM_FLAGS)
@@ -1021,16 +1018,16 @@ DEFINE GCC5_ARM_CC_FLAGS = DEF(GCC49_ARM_CC_FLAGS) DEFINE GCC5_ARM_CC_XIPFLAGS = DEF(GCC49_ARM_CC_XIPFLAGS)
DEFINE GCC5_AARCH64_CC_FLAGS = DEF(GCC49_AARCH64_CC_FLAGS)
DEFINE GCC5_AARCH64_CC_XIPFLAGS = DEF(GCC49_AARCH64_CC_XIPFLAGS)
-DEFINE GCC5_ARM_DLINK_FLAGS = DEF(GCC49_ARM_DLINK_FLAGS)
+DEFINE GCC5_ARM_DLINK_FLAGS = DEF(GCC49_ARM_DLINK_FLAGS) DEF(GCC5_DLINK_WARNING_FLAGS)
DEFINE GCC5_ARM_DLINK2_FLAGS = DEF(GCC49_ARM_DLINK2_FLAGS) -Wno-error
-DEFINE GCC5_AARCH64_DLINK_FLAGS = DEF(GCC49_AARCH64_DLINK_FLAGS)
+DEFINE GCC5_AARCH64_DLINK_FLAGS = DEF(GCC49_AARCH64_DLINK_FLAGS) DEF(GCC5_DLINK_WARNING_FLAGS)
DEFINE GCC5_AARCH64_DLINK2_FLAGS = DEF(GCC49_AARCH64_DLINK2_FLAGS) -Wno-error
-DEFINE GCC5_ARM_ASLDLINK_FLAGS = DEF(GCC49_ARM_ASLDLINK_FLAGS)
-DEFINE GCC5_AARCH64_ASLDLINK_FLAGS = DEF(GCC49_AARCH64_ASLDLINK_FLAGS)
+DEFINE GCC5_ARM_ASLDLINK_FLAGS = DEF(GCC49_ARM_ASLDLINK_FLAGS) DEF(GCC5_DLINK_WARNING_FLAGS)
+DEFINE GCC5_AARCH64_ASLDLINK_FLAGS = DEF(GCC49_AARCH64_ASLDLINK_FLAGS) DEF(GCC5_DLINK_WARNING_FLAGS)
DEFINE GCC5_ASLCC_FLAGS = DEF(GCC49_ASLCC_FLAGS) -fno-lto
-DEFINE GCC5_RISCV_ALL_CC_FLAGS = -g -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -ffunction-sections -fdata-sections -include AutoGen.h -fno-common -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings -msmall-data-limit=0
-DEFINE GCC5_RISCV_ALL_DLINK_COMMON = -nostdlib -Wl,-n,-q,--gc-sections -z common-page-size=0x40
+DEFINE GCC5_RISCV_ALL_CC_FLAGS = -g -fshort-wchar -fno-omit-frame-pointer -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -ffunction-sections -fdata-sections -include AutoGen.h -fno-common -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings -msmall-data-limit=0
+DEFINE GCC5_RISCV_ALL_DLINK_COMMON = -nostdlib -Wl,-n,-q,--gc-sections -z common-page-size=0x40 DEF(GCC5_DLINK_WARNING_FLAGS)
DEFINE GCC5_RISCV_ALL_DLINK_FLAGS = DEF(GCC5_RISCV_ALL_DLINK_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
DEFINE GCC5_RISCV_ALL_DLINK2_FLAGS = -Wl,--defsym=PECOFF_HEADER_SIZE=0x220,--script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds
DEFINE GCC5_RISCV_ALL_ASM_FLAGS = -c -x assembler -imacros $(DEST_DIR_DEBUG)/AutoGen.h
@@ -1046,9 +1043,9 @@ DEFINE GCC5_RISCV64_DLINK2_FLAGS = DEF(GCC5_RISCV_ALL_DLINK2_FLAGS) DEFINE GCC5_RISCV64_ASM_FLAGS = DEF(GCC5_RISCV_ALL_ASM_FLAGS) -march=DEF(GCC5_RISCV64_ARCH) -mcmodel=medany -mabi=lp64
DEFINE GCC5_LOONGARCH64_CC_FLAGS = DEF(GCC_LOONGARCH64_CC_FLAGS) -march=loongarch64 -mno-memcpy -Werror -Wno-maybe-uninitialized -Wno-stringop-overflow -Wno-pointer-to-int-cast -no-pie -fno-stack-protector -mno-explicit-relocs
-DEFINE GCC5_LOONGARCH64_DLINK_FLAGS = DEF(GCC_LOONGARCH64_DLINK_FLAGS)
+DEFINE GCC5_LOONGARCH64_DLINK_FLAGS = DEF(GCC_LOONGARCH64_DLINK_FLAGS) DEF(GCC5_DLINK_WARNING_FLAGS)
DEFINE GCC5_LOONGARCH64_DLINK2_FLAGS = DEF(GCC_DLINK2_FLAGS_COMMON) -Wl,--defsym=PECOFF_HEADER_SIZE=0x228
-DEFINE GCC5_LOONGARCH64_ASLDLINK_FLAGS = DEF(GCC_LOONGARCH64_ASLDLINK_FLAGS) DEF(GCC5_LOONGARCH64_DLINK2_FLAGS)
+DEFINE GCC5_LOONGARCH64_ASLDLINK_FLAGS = DEF(GCC_LOONGARCH64_ASLDLINK_FLAGS) DEF(GCC5_LOONGARCH64_DLINK2_FLAGS) DEF(GCC5_DLINK_WARNING_FLAGS)
DEFINE GCC5_LOONGARCH64_ASM_FLAGS = -x assembler-with-cpp -mabi=lp64d -march=loongarch64 -fno-builtin -c -Wall -mno-explicit-relocs
DEFINE GCC5_LOONGARCH64_PP_FLAGS = -mabi=lp64d -march=loongarch64 DEF(GCC_PP_FLAGS)
@@ -2031,10 +2028,11 @@ DEFINE CLANGDWARF_X64_PREFIX = ENV(CLANG_BIN) # LLVM/CLANG doesn't support -n link option. So, it can't share the same IA32_X64_DLINK_COMMON flag.
# LLVM/CLANG doesn't support common page size. So, it can't share the same GccBase.lds script.
-DEFINE CLANGDWARF_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-q,--gc-sections -z common-page-size=0x40
+DEFINE CLANGDWARF_DLINK_WARNING_FLAGS = -Wl,-z,notext
+DEFINE CLANGDWARF_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-q,--gc-sections -z common-page-size=0x40 DEF(CLANGDWARF_DLINK_WARNING_FLAGS)
DEFINE CLANGDWARF_DLINK2_FLAGS_COMMON = -Wl,--script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds
DEFINE CLANGDWARF_IA32_X64_ASLDLINK_FLAGS = DEF(CLANGDWARF_IA32_X64_DLINK_COMMON) -Wl,--defsym=PECOFF_HEADER_SIZE=0 DEF(CLANGDWARF_DLINK2_FLAGS_COMMON) -Wl,--entry,ReferenceAcpiTable -u ReferenceAcpiTable
-DEFINE CLANGDWARF_IA32_X64_DLINK_FLAGS = DEF(CLANGDWARF_IA32_X64_DLINK_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map,--whole-archive -Wl,-z,notext
+DEFINE CLANGDWARF_IA32_X64_DLINK_FLAGS = DEF(CLANGDWARF_IA32_X64_DLINK_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map,--whole-archive
DEFINE CLANGDWARF_IA32_DLINK2_FLAGS = -Wl,--defsym=PECOFF_HEADER_SIZE=0x220 DEF(CLANGDWARF_DLINK2_FLAGS_COMMON)
DEFINE CLANGDWARF_X64_DLINK2_FLAGS = -Wl,--defsym=PECOFF_HEADER_SIZE=0x228 DEF(CLANGDWARF_DLINK2_FLAGS_COMMON)
@@ -2121,7 +2119,7 @@ NOOPT_CLANGDWARF_X64_DLINK2_FLAGS = DEF(CLANGDWARF_X64_DLINK2_FLAGS) -O0 -fu ##################
DEFINE CLANGDWARF_ARM_TARGET = -target arm-linux-gnueabi
DEFINE CLANGDWARF_ARM_CC_FLAGS = DEF(GCC_ARM_CC_FLAGS) DEF(CLANGDWARF_ARM_TARGET) DEF(CLANGDWARF_WARNING_OVERRIDES) -mno-movt -fno-stack-protector
-DEFINE CLANGDWARF_ARM_DLINK_FLAGS = DEF(CLANGDWARF_ARM_TARGET) DEF(GCC_ARM_DLINK_FLAGS)
+DEFINE CLANGDWARF_ARM_DLINK_FLAGS = DEF(CLANGDWARF_ARM_TARGET) DEF(GCC_ARM_DLINK_FLAGS) DEF(CLANGDWARF_DLINK_WARNING_FLAGS)
*_CLANGDWARF_ARM_PP_FLAGS = DEF(GCC_PP_FLAGS)
*_CLANGDWARF_ARM_ASLCC_FLAGS = DEF(GCC_ASLCC_FLAGS)
@@ -2165,7 +2163,7 @@ RELEASE_CLANGDWARF_ARM_DLINK_FLAGS = DEF(CLANGDWARF_ARM_DLINK_FLAGS) -flto -Wl, ##################
DEFINE CLANGDWARF_AARCH64_TARGET = -target aarch64-linux-gnu
DEFINE CLANGDWARF_AARCH64_CC_FLAGS = DEF(GCC_AARCH64_CC_FLAGS) DEF(CLANGDWARF_AARCH64_TARGET) -mcmodel=small DEF(CLANGDWARF_WARNING_OVERRIDES)
-DEFINE CLANGDWARF_AARCH64_DLINK_FLAGS = DEF(CLANGDWARF_AARCH64_TARGET) DEF(GCC_AARCH64_DLINK_FLAGS) -z common-page-size=0x1000
+DEFINE CLANGDWARF_AARCH64_DLINK_FLAGS = DEF(CLANGDWARF_AARCH64_TARGET) DEF(GCC_AARCH64_DLINK_FLAGS) -z common-page-size=0x1000 DEF(CLANGDWARF_DLINK_WARNING_FLAGS)
*_CLANGDWARF_AARCH64_PP_FLAGS = DEF(GCC_PP_FLAGS)
*_CLANGDWARF_AARCH64_ASLCC_FLAGS = DEF(GCC_ASLCC_FLAGS)
@@ -2187,9 +2185,9 @@ DEFINE CLANGDWARF_AARCH64_DLINK_FLAGS = DEF(CLANGDWARF_AARCH64_TARGET) DEF(GCC_ *_CLANGDWARF_AARCH64_RC_PATH = ENV(CLANGDWARF_BIN)llvm-objcopy
*_CLANGDWARF_AARCH64_ASLCC_FLAGS = DEF(GCC_ASLCC_FLAGS) -fno-lto
-*_CLANGDWARF_AARCH64_ASLDLINK_FLAGS = DEF(CLANGDWARF_AARCH64_TARGET) DEF(GCC_AARCH64_ASLDLINK_FLAGS)
+*_CLANGDWARF_AARCH64_ASLDLINK_FLAGS = DEF(CLANGDWARF_AARCH64_TARGET) DEF(GCC_AARCH64_ASLDLINK_FLAGS) DEF(CLANGDWARF_DLINK_WARNING_FLAGS)
*_CLANGDWARF_AARCH64_ASM_FLAGS = DEF(GCC_ASM_FLAGS) DEF(CLANGDWARF_AARCH64_TARGET) $(PLATFORM_FLAGS) -Qunused-arguments
-*_CLANGDWARF_AARCH64_DLINK_FLAGS = DEF(CLANGDWARF_AARCH64_TARGET) DEF(GCC_AARCH64_DLINK_FLAGS) -z common-page-size=0x1000
+*_CLANGDWARF_AARCH64_DLINK_FLAGS = DEF(CLANGDWARF_AARCH64_TARGET) DEF(GCC_AARCH64_DLINK_FLAGS) -z common-page-size=0x1000 DEF(CLANGDWARF_DLINK_WARNING_FLAGS)
*_CLANGDWARF_AARCH64_DLINK_XIPFLAGS = -z common-page-size=0x20
*_CLANGDWARF_AARCH64_DLINK2_FLAGS = DEF(GCC_DLINK2_FLAGS_COMMON) -Wl,--defsym=PECOFF_HEADER_SIZE=0x228
*_CLANGDWARF_AARCH64_PLATFORM_FLAGS =
@@ -2214,7 +2212,7 @@ DEFINE CLANGDWARF_RISCV64_CC_COMMON = DEF(GCC5_RISCV_ALL_CC_FLAGS) DEF(GCC5_RISC DEFINE CLANGDWARF_RISCV64_CC_FLAGS = DEF(CLANGDWARF_RISCV64_CC_COMMON) DEF(CLANGDWARF_RISCV64_TARGET) DEF(CLANGDWARF_WARNING_OVERRIDES)
# This is similar to GCC flags but without -n
-DEFINE CLANGDWARF_RISCV64_ALL_DLINK_COMMON = -nostdlib -Wl,-q,--gc-sections -z common-page-size=0x40
+DEFINE CLANGDWARF_RISCV64_ALL_DLINK_COMMON = -nostdlib -Wl,-q,--gc-sections -z common-page-size=0x40 DEF(CLANGDWARF_DLINK_WARNING_FLAGS)
DEFINE CLANGDWARF_RISCV64_ALL_DLINK_FLAGS = DEF(CLANGDWARF_RISCV64_ALL_DLINK_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
DEFINE CLANGDWARF_RISCV64_DLINK_FLAGS = DEF(CLANGDWARF_RISCV64_TARGET) DEF(CLANGDWARF_RISCV64_ALL_DLINK_FLAGS) -Wl,-melf64lriscv,--oformat=elf64-littleriscv,--no-relax
@@ -2239,9 +2237,9 @@ DEFINE CLANGDWARF_RISCV64_DLINK_FLAGS = DEF(CLANGDWARF_RISCV64_TARGET) DEF *_CLANGDWARF_RISCV64_RC_PATH = ENV(CLANGDWARF_BIN)llvm-objcopy
*_CLANGDWARF_RISCV64_ASLCC_FLAGS = DEF(GCC_ASLCC_FLAGS) -fno-lto
-*_CLANGDWARF_RISCV64_ASLDLINK_FLAGS = DEF(CLANGDWARF_RISCV64_TARGET) DEF(GCC5_RISCV32_RISCV64_ASLDLINK_FLAGS)
+*_CLANGDWARF_RISCV64_ASLDLINK_FLAGS = DEF(CLANGDWARF_RISCV64_TARGET) DEF(GCC5_RISCV32_RISCV64_ASLDLINK_FLAGS) DEF(CLANGDWARF_DLINK_WARNING_FLAGS)
*_CLANGDWARF_RISCV64_ASM_FLAGS = DEF(GCC_ASM_FLAGS) DEF(CLANGDWARF_RISCV64_TARGET) $(PLATFORM_FLAGS) -Qunused-arguments -mabi=lp64 -mno-relax
-*_CLANGDWARF_RISCV64_DLINK_FLAGS = DEF(CLANGDWARF_RISCV64_TARGET) DEF(GCC5_RISCV64_DLINK_FLAGS)
+*_CLANGDWARF_RISCV64_DLINK_FLAGS = DEF(CLANGDWARF_RISCV64_TARGET) DEF(GCC5_RISCV64_DLINK_FLAGS) DEF(CLANGDWARF_DLINK_WARNING_FLAGS)
*_CLANGDWARF_RISCV64_DLINK_XIPFLAGS = -z common-page-size=0x20
*_CLANGDWARF_RISCV64_DLINK2_FLAGS = DEF(CLANGDWARF_DLINK2_FLAGS_COMMON) -Wl,--defsym=PECOFF_HEADER_SIZE=0x240
*_CLANGDWARF_RISCV64_PLATFORM_FLAGS =
diff --git a/EmbeddedPkg/Include/Protocol/HardwareInterrupt2.h b/EmbeddedPkg/Include/Protocol/HardwareInterrupt2.h index d017a9e..d5b2f15 100644 --- a/EmbeddedPkg/Include/Protocol/HardwareInterrupt2.h +++ b/EmbeddedPkg/Include/Protocol/HardwareInterrupt2.h @@ -11,10 +11,10 @@ #include <Protocol/HardwareInterrupt.h>
-// 22838932-1a2d-4a47-aaba-f3f7cf569470
+// 32898322-2da1-474a-baaa-f3f7cf569470
#define EFI_HARDWARE_INTERRUPT2_PROTOCOL_GUID \
- { 0x32898322, 0x2d1a, 0x474a, \
+ { 0x32898322, 0x2da1, 0x474a, \
{ 0xba, 0xaa, 0xf3, 0xf7, 0xcf, 0x56, 0x94, 0x70 } }
typedef enum {
diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c index 8d12f93..71d267b 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -584,6 +584,9 @@ CoreLoadPeImage ( EFI_STATUS Status;
BOOLEAN DstBufAlocated;
UINTN Size;
+ UINTN Index;
+ UINTN StartIndex;
+ CHAR8 EfiFileName[512];
ZeroMem (&Image->ImageContext, sizeof (Image->ImageContext));
@@ -823,12 +826,6 @@ CoreLoadPeImage ( // Print the load address and the PDB file name if it is available
//
- DEBUG_CODE_BEGIN ();
-
- UINTN Index;
- UINTN StartIndex;
- CHAR8 EfiFileName[256];
-
DEBUG ((
DEBUG_INFO | DEBUG_LOAD,
"Loading driver at 0x%11p EntryPoint=0x%11p ",
@@ -877,8 +874,6 @@ CoreLoadPeImage ( DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n"));
- DEBUG_CODE_END ();
-
return EFI_SUCCESS;
Done:
diff --git a/MdeModulePkg/Core/Pei/Image/Image.c b/MdeModulePkg/Core/Pei/Image/Image.c index cee9f09..f74406f 100644 --- a/MdeModulePkg/Core/Pei/Image/Image.c +++ b/MdeModulePkg/Core/Pei/Image/Image.c @@ -623,6 +623,10 @@ PeiLoadImageLoadImage ( UINT16 Machine;
EFI_SECTION_TYPE SearchType1;
EFI_SECTION_TYPE SearchType2;
+ CHAR8 *AsciiString;
+ CHAR8 EfiFileName[512];
+ UINTN Index;
+ UINTN StartIndex;
*EntryPoint = 0;
ImageSize = 0;
@@ -706,12 +710,6 @@ PeiLoadImageLoadImage ( *ImageSizeArg = ImageSize;
}
- DEBUG_CODE_BEGIN ();
- CHAR8 *AsciiString;
- CHAR8 EfiFileName[512];
- INT32 Index;
- INT32 StartIndex;
-
//
// Print debug message: Loading PEIM at 0x12345678 EntryPoint=0x12345688 Driver.efi
//
@@ -764,8 +762,6 @@ PeiLoadImageLoadImage ( DEBUG ((DEBUG_INFO | DEBUG_LOAD, "%a", EfiFileName));
}
- DEBUG_CODE_END ();
-
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n"));
return EFI_SUCCESS;
diff --git a/MdeModulePkg/Core/PiSmmCore/Dispatcher.c b/MdeModulePkg/Core/PiSmmCore/Dispatcher.c index bb789e5..2011db1 100644 --- a/MdeModulePkg/Core/PiSmmCore/Dispatcher.c +++ b/MdeModulePkg/Core/PiSmmCore/Dispatcher.c @@ -325,6 +325,9 @@ SmmLoadImage ( EFI_DEVICE_PATH_PROTOCOL *HandleFilePath;
EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
+ UINTN Index;
+ UINTN StartIndex;
+ CHAR8 EfiFileName[512];
PERF_LOAD_IMAGE_BEGIN (DriverEntry->ImageHandle);
@@ -664,12 +667,6 @@ SmmLoadImage ( // Print the load address and the PDB file name if it is available
//
- DEBUG_CODE_BEGIN ();
-
- UINTN Index;
- UINTN StartIndex;
- CHAR8 EfiFileName[256];
-
DEBUG ((
DEBUG_INFO | DEBUG_LOAD,
"Loading SMM driver at 0x%11p EntryPoint=0x%11p ",
@@ -718,8 +715,6 @@ SmmLoadImage ( DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n"));
- DEBUG_CODE_END ();
-
//
// Free buffer allocated by Fv->ReadSection.
//
diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc index d941d6d..157aa8e 100644 --- a/OvmfPkg/CloudHv/CloudHvX64.dsc +++ b/OvmfPkg/CloudHv/CloudHvX64.dsc @@ -628,7 +628,7 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|FALSE
# UefiCpuPkg PCDs related to initial AP bringup and general AP management.
- gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|64
+ gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|254
gUefiCpuPkgTokenSpaceGuid.PcdCpuBootLogicalProcessorNumber|0
# Set memory encryption mask
diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf b/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf index ebcc7e2..0996968 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf @@ -42,6 +42,7 @@ BaseMemoryLib
CpuLib
DebugLib
+ HobLib
LocalApicLib
MmServicesTableLib
PcdLib
@@ -53,6 +54,9 @@ gEfiMmCpuIoProtocolGuid ## CONSUMES
gEfiSmmCpuServiceProtocolGuid ## CONSUMES
+[Guids]
+ gUefiOvmfPkgPlatformInfoGuid ## CONSUMES
+
[Pcd]
gUefiCpuPkgTokenSpaceGuid.PcdCpuHotPlugDataAddress ## CONSUMES
gUefiOvmfPkgTokenSpaceGuid.PcdCpuHotEjectDataAddress ## CONSUMES
diff --git a/OvmfPkg/CpuHotplugSmm/FirstSmiHandler.nasm b/OvmfPkg/CpuHotplugSmm/FirstSmiHandler.nasm index 5399b5f..b38f94c 100644 --- a/OvmfPkg/CpuHotplugSmm/FirstSmiHandler.nasm +++ b/OvmfPkg/CpuHotplugSmm/FirstSmiHandler.nasm @@ -41,9 +41,12 @@ SMM_DEFAULT_SMBASE: equ 0x3_0000 ; Field offsets in FIRST_SMI_HANDLER_CONTEXT, which resides at
; SMM_DEFAULT_SMBASE.
;
-ApicIdGate: equ 0 ; UINT64
-NewSmbase: equ 8 ; UINT32
-AboutToLeaveSmm: equ 12 ; UINT8
+ApicIdGate: equ 0 ; UINT64
+NewSmbase: equ 8 ; UINT32
+FeatureControlHighValue: equ 12 ; UINT32
+FeatureControlLowValue: equ 16 ; UINT32
+FeatureControl: equ 20 ; UINT8
+AboutToLeaveSmm: equ 21 ; UINT8
;
; SMRAM Save State Map field offsets, per the AMD (not Intel) layout that QEMU
@@ -60,6 +63,11 @@ CPUID_SIGNATURE: equ 0x00 CPUID_EXTENDED_TOPOLOGY: equ 0x0B
CPUID_VERSION_INFO: equ 0x01
+;
+; MSR constants, from "MdePkg/Include/Register/Intel/ArchitecturalMsr.h".
+;
+MSR_IA32_FEATURE_CONTROL: equ 0x0000003A
+
GLOBAL ASM_PFX (mFirstSmiHandler) ; UINT8[]
GLOBAL ASM_PFX (mFirstSmiHandlerSize) ; UINT16
@@ -141,6 +149,18 @@ UpdateSmbase: ; Save it to the SMBASE field whose address we calculated in EBX.
;
mov dword [ds : dword ebx], eax
+
+ ;
+ ; Set MSR_IA32_FEATURE_CONTROL if requested.
+ ;
+ cmp byte [ds : dword (SMM_DEFAULT_SMBASE + FeatureControl)], 0
+ je NoFeatureControl
+ mov ecx, MSR_IA32_FEATURE_CONTROL
+ mov edx, dword [ds : dword (SMM_DEFAULT_SMBASE + FeatureControlHighValue)]
+ mov eax, dword [ds : dword (SMM_DEFAULT_SMBASE + FeatureControlLowValue)]
+ wrmsr
+
+NoFeatureControl:
;
; Set AboutToLeaveSmm.
;
diff --git a/OvmfPkg/CpuHotplugSmm/FirstSmiHandlerContext.h b/OvmfPkg/CpuHotplugSmm/FirstSmiHandlerContext.h index 6039532..0c6deed 100644 --- a/OvmfPkg/CpuHotplugSmm/FirstSmiHandlerContext.h +++ b/OvmfPkg/CpuHotplugSmm/FirstSmiHandlerContext.h @@ -36,6 +36,14 @@ typedef struct { //
UINT32 NewSmbase;
//
+ // The High:Low value for the hot-added CPU to store in
+ // MSR_IA32_FEATURE_CONTROL, assuming MSR_IA32_FEATURE_CONTROL setting is
+ // enabled (i.e., if "FeatureControl" is nonzero).
+ //
+ UINT32 FeatureControlHighValue;
+ UINT32 FeatureControlLowValue;
+ UINT8 FeatureControl;
+ //
// The hot-added CPU sets this field to 1 right before executing the RSM
// instruction. This tells the SMM Monarch to proceed to polling the last
// byte of the normal RAM reserved page (Post-SMM Pen).
diff --git a/OvmfPkg/CpuHotplugSmm/Smbase.c b/OvmfPkg/CpuHotplugSmm/Smbase.c index dc6f4f4..433633d 100644 --- a/OvmfPkg/CpuHotplugSmm/Smbase.c +++ b/OvmfPkg/CpuHotplugSmm/Smbase.c @@ -10,7 +10,9 @@ #include <Library/BaseLib.h> // CpuPause()
#include <Library/BaseMemoryLib.h> // CopyMem()
#include <Library/DebugLib.h> // DEBUG()
+#include <Library/HobLib.h> // GetFirstGuidHob()
#include <Library/LocalApicLib.h> // SendInitSipiSipi()
+#include <Library/PlatformInitLib.h> // EFI_HOB_PLATFORM_INFO
#include <Library/SynchronizationLib.h> // InterlockedCompareExchange64()
#include <Register/Intel/SmramSaveStateMap.h> // SMM_DEFAULT_SMBASE
@@ -132,7 +134,10 @@ SmbaseReleasePostSmmPen ( Note that this effects an "SMRAM to SMRAM" copy.
- Additionally, shut the APIC ID gate in FIRST_SMI_HANDLER_CONTEXT.
+ Additionally, shut the APIC ID gate in FIRST_SMI_HANDLER_CONTEXT, and prepare
+ for configuring MSR_IA32_FEATURE_CONTROL. (The latter depends on a GUID HOB,
+ which does not live in SMRAM; however, if we can't trust the HOB list at this
+ stage, we're doomed anyway.)
This function may only be called from the entry point function of the driver,
and only after PcdQ35SmramAtDefaultSmbase has been determined to be TRUE.
@@ -143,6 +148,7 @@ SmbaseInstallFirstSmiHandler ( )
{
FIRST_SMI_HANDLER_CONTEXT *Context;
+ EFI_HOB_GUID_TYPE *GuidHob;
CopyMem (
(VOID *)(UINTN)(SMM_DEFAULT_SMBASE + SMM_HANDLER_OFFSET),
@@ -152,6 +158,22 @@ SmbaseInstallFirstSmiHandler ( Context = (VOID *)(UINTN)SMM_DEFAULT_SMBASE;
Context->ApicIdGate = MAX_UINT64;
+
+ Context->FeatureControl = 0;
+ GuidHob = GetFirstGuidHob (&gUefiOvmfPkgPlatformInfoGuid);
+ if (GuidHob != NULL) {
+ EFI_HOB_PLATFORM_INFO *Info;
+
+ Info = GET_GUID_HOB_DATA (GuidHob);
+ if (Info->FeatureControl) {
+ Context->FeatureControlHighValue = (UINT32)RShiftU64 (
+ Info->FeatureControlValue,
+ 32
+ );
+ Context->FeatureControlLowValue = (UINT32)Info->FeatureControlValue;
+ Context->FeatureControl = 1;
+ }
+ }
}
/**
diff --git a/OvmfPkg/Include/Library/PlatformInitLib.h b/OvmfPkg/Include/Library/PlatformInitLib.h index 2d9c662..dc0c280 100644 --- a/OvmfPkg/Include/Library/PlatformInitLib.h +++ b/OvmfPkg/Include/Library/PlatformInitLib.h @@ -64,6 +64,7 @@ typedef struct { UINT32 S3AcpiReservedMemoryBase;
UINT32 S3AcpiReservedMemorySize;
+ BOOLEAN FeatureControl;
UINT64 FeatureControlValue;
BOOLEAN QemuFwCfgChecked;
diff --git a/OvmfPkg/PlatformPei/FeatureControl.c b/OvmfPkg/PlatformPei/FeatureControl.c index d2ec496..749a07c 100644 --- a/OvmfPkg/PlatformPei/FeatureControl.c +++ b/OvmfPkg/PlatformPei/FeatureControl.c @@ -143,6 +143,7 @@ InstallFeatureControlCallback ( return;
}
+ PlatformInfoHob->FeatureControl = TRUE;
QemuFwCfgSelectItem (FwCfgItem);
QemuFwCfgReadBytes (
sizeof (PlatformInfoHob->FeatureControlValue),
diff --git a/OvmfPkg/RiscVVirt/Library/PlatformSecLib/SecEntry.S b/OvmfPkg/RiscVVirt/Library/PlatformSecLib/SecEntry.S index de42a90..b52becd 100644 --- a/OvmfPkg/RiscVVirt/Library/PlatformSecLib/SecEntry.S +++ b/OvmfPkg/RiscVVirt/Library/PlatformSecLib/SecEntry.S @@ -8,6 +8,9 @@ #include "PlatformSecLib.h"
ASM_FUNC (_ModuleEntryPoint)
+/* Prevent stack unwinding from going further */
+li s0, 0
+
/* Use Temp memory as the stack for calling to C code */
li a2, FixedPcdGet32 (PcdOvmfSecPeiTempRamBase)
li a3, FixedPcdGet32 (PcdOvmfSecPeiTempRamSize)
diff --git a/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc b/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc index 4c3eff7..47248f2 100644 --- a/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc +++ b/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc @@ -79,7 +79,6 @@ !endif
# RISC-V Architectural Libraries
- CpuExceptionHandlerLib|UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.inf
RiscVSbiLib|MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.inf
RiscVMmuLib|UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.inf
PlatformBootManagerLib|OvmfPkg/RiscVVirt/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
@@ -153,6 +152,7 @@ PrePiHobListPointerLib|OvmfPkg/RiscVVirt/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf
PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf
MemoryAllocationLib|EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf
+ CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
[LibraryClasses.common.PEI_CORE]
HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
@@ -163,6 +163,7 @@ ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
PeiResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf
ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf
+ CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
[LibraryClasses.common.PEIM]
HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
@@ -174,16 +175,19 @@ ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
PeiResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf
ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf
+ CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
[LibraryClasses.common.DXE_CORE]
PerformanceLib|MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.inf
HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf
MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf
DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf
+ CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
[LibraryClasses.common.DXE_DRIVER]
SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
+ CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
[LibraryClasses.common.UEFI_APPLICATION]
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
diff --git a/SecurityPkg/FvReportPei/FvReportPei.c b/SecurityPkg/FvReportPei/FvReportPei.c index 50773db..4376f52 100644 --- a/SecurityPkg/FvReportPei/FvReportPei.c +++ b/SecurityPkg/FvReportPei/FvReportPei.c @@ -71,7 +71,10 @@ InstallPreHashFvPpi ( + HashSize;
PreHashedFvPpi = AllocatePool (PpiSize);
- ASSERT (PreHashedFvPpi != NULL);
+ if (PreHashedFvPpi == NULL) {
+ ASSERT (PreHashedFvPpi != NULL);
+ return;
+ }
PreHashedFvPpi->FvBase = (UINT32)(UINTN)FvBuffer;
PreHashedFvPpi->FvLength = (UINT32)FvLength;
@@ -83,7 +86,11 @@ InstallPreHashFvPpi ( CopyMem (HASH_VALUE_PTR (HashInfo), HashValue, HashSize);
FvInfoPpiDescriptor = AllocatePool (sizeof (EFI_PEI_PPI_DESCRIPTOR));
- ASSERT (FvInfoPpiDescriptor != NULL);
+ if (FvInfoPpiDescriptor == NULL) {
+ ASSERT (FvInfoPpiDescriptor != NULL);
+ FreePool (PreHashedFvPpi);
+ return;
+ }
FvInfoPpiDescriptor->Guid = &gEdkiiPeiFirmwareVolumeInfoPrehashedFvPpiGuid;
FvInfoPpiDescriptor->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
@@ -202,8 +209,11 @@ VerifyHashedFv ( // Copy FV to permanent memory to avoid potential TOC/TOU.
//
FvBuffer = AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)FvInfo[FvIndex].Length));
-
- ASSERT (FvBuffer != NULL);
+ if (FvBuffer == NULL) {
+ ASSERT (FvBuffer != NULL);
+ Status = EFI_OUT_OF_RESOURCES;
+ goto Done;
+ }
if (FvShadowPpi != NULL) {
Status = FvShadowPpi->FirmwareVolumeShadow (
@@ -379,12 +389,17 @@ CheckStoredHashFv ( );
if (!EFI_ERROR (Status) && (StoredHashFvPpi != NULL) && (StoredHashFvPpi->FvNumber > 0)) {
HashInfo = GetHashInfo (StoredHashFvPpi, BootMode);
- Status = VerifyHashedFv (
+ if (HashInfo != NULL) {
+ Status = VerifyHashedFv (
HashInfo,
StoredHashFvPpi->FvInfo,
StoredHashFvPpi->FvNumber,
BootMode
);
+ } else {
+ Status = EFI_NOT_FOUND;
+ }
+
if (!EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "OBB verification passed (%r)\r\n", Status));
diff --git a/SecurityPkg/HddPassword/HddPasswordDxe.c b/SecurityPkg/HddPassword/HddPasswordDxe.c index 6f36b5a..228a9f4 100644 --- a/SecurityPkg/HddPassword/HddPasswordDxe.c +++ b/SecurityPkg/HddPassword/HddPasswordDxe.c @@ -149,7 +149,10 @@ BuildHddPasswordDeviceInfo ( S3InitDevicesExist = FALSE;
} else if (Status == EFI_BUFFER_TOO_SMALL) {
S3InitDevices = AllocatePool (S3InitDevicesLength);
- ASSERT (S3InitDevices != NULL);
+ if (S3InitDevices == NULL) {
+ ASSERT (S3InitDevices != NULL);
+ return;
+ }
Status = RestoreLockBox (
&gS3StorageDeviceInitListGuid,
@@ -184,7 +187,10 @@ BuildHddPasswordDeviceInfo ( FreePool (S3InitDevicesBak);
}
- ASSERT (S3InitDevices != NULL);
+ if (S3InitDevices == NULL) {
+ ASSERT (S3InitDevices != NULL);
+ return;
+ }
TempDevInfo = (HDD_PASSWORD_DEVICE_INFO *)((UINTN)TempDevInfo +
sizeof (HDD_PASSWORD_DEVICE_INFO) +
@@ -2195,8 +2201,14 @@ HddPasswordFormExtractConfig ( // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
//
ConfigRequestHdr = HiiConstructConfigHdr (&mHddPasswordVendorGuid, mHddPasswordVendorStorageName, Private->DriverHandle);
- Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
- ConfigRequest = AllocateZeroPool (Size);
+ if (ConfigRequestHdr == NULL) {
+ ASSERT (ConfigRequestHdr != NULL);
+ FreePool (IfrData);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
+ ConfigRequest = AllocateZeroPool (Size);
ASSERT (ConfigRequest != NULL);
AllocatedRequest = TRUE;
UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
@@ -2386,7 +2398,11 @@ HddPasswordFormCallback ( // In case goto the device configuration form, update the device form title.
//
ConfigFormEntry = HddPasswordGetConfigFormEntryByIndex ((UINT32)(QuestionId - KEY_HDD_DEVICE_ENTRY_BASE));
- ASSERT (ConfigFormEntry != NULL);
+ if (ConfigFormEntry == NULL) {
+ ASSERT (ConfigFormEntry != NULL);
+ FreePool (IfrData);
+ return EFI_NOT_FOUND;
+ }
DeviceFormTitleToken = (EFI_STRING_ID)STR_HDD_SECURITY_HD;
HiiSetString (Private->HiiHandle, DeviceFormTitleToken, ConfigFormEntry->HddString, NULL);
diff --git a/SecurityPkg/Library/AuthVariableLib/AuthService.c b/SecurityPkg/Library/AuthVariableLib/AuthService.c index 706cb67..2d79cc1 100644 --- a/SecurityPkg/Library/AuthVariableLib/AuthService.c +++ b/SecurityPkg/Library/AuthVariableLib/AuthService.c @@ -553,7 +553,7 @@ CheckSignatureListFormat ( // Walk through the input signature list and check the data format.
// If any signature is incorrectly formed, the whole check will fail.
//
- while ((SigDataSize > 0) && (SigDataSize >= SigList->SignatureListSize)) {
+ while ((SigDataSize > 0) && (SigDataSize >= (UINTN)SigList->SignatureListSize)) {
for (Index = 0; Index < (sizeof (mSupportSigItem) / sizeof (EFI_SIGNATURE_ITEM)); Index++ ) {
if (CompareGuid (&SigList->SignatureType, &mSupportSigItem[Index].SigType)) {
//
@@ -1088,7 +1088,7 @@ FilterSignatureList ( Tail = TempData;
NewCertList = (EFI_SIGNATURE_LIST *)NewData;
- while ((*NewDataSize > 0) && (*NewDataSize >= NewCertList->SignatureListSize)) {
+ while ((*NewDataSize > 0) && (*NewDataSize >= (UINTN)NewCertList->SignatureListSize)) {
NewCert = (EFI_SIGNATURE_DATA *)((UINT8 *)NewCertList + sizeof (EFI_SIGNATURE_LIST) + NewCertList->SignatureHeaderSize);
NewCertCount = (NewCertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - NewCertList->SignatureHeaderSize) / NewCertList->SignatureSize;
@@ -1098,7 +1098,7 @@ FilterSignatureList ( Size = DataSize;
CertList = (EFI_SIGNATURE_LIST *)Data;
- while ((Size > 0) && (Size >= CertList->SignatureListSize)) {
+ while ((Size > 0) && (Size >= (UINTN)CertList->SignatureListSize)) {
if (CompareGuid (&CertList->SignatureType, &NewCertList->SignatureType) &&
(CertList->SignatureSize == NewCertList->SignatureSize))
{
diff --git a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c index 2eca39d..23e25a4 100644 --- a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c +++ b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c @@ -883,7 +883,7 @@ IsCertHashFoundInDbx ( return Status;
}
- while ((DbxSize > 0) && (SignatureListSize >= DbxList->SignatureListSize)) {
+ while ((DbxSize > 0) && (SignatureListSize >= (UINTN)DbxList->SignatureListSize)) {
//
// Determine Hash Algorithm of Certificate in the forbidden database.
//
@@ -1028,7 +1028,7 @@ IsSignatureFoundInDatabase ( // Enumerate all signature data in SigDB to check if signature exists for executable.
//
CertList = (EFI_SIGNATURE_LIST *)Data;
- while ((DataSize > 0) && (DataSize >= CertList->SignatureListSize)) {
+ while ((DataSize > 0) && (DataSize >= (UINTN)CertList->SignatureListSize)) {
CertCount = (CertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - CertList->SignatureHeaderSize) / CertList->SignatureSize;
Cert = (EFI_SIGNATURE_DATA *)((UINT8 *)CertList + sizeof (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize);
if ((CertList->SignatureSize == sizeof (EFI_SIGNATURE_DATA) - 1 + SignatureSize) && (CompareGuid (&CertList->SignatureType, CertType))) {
@@ -1193,7 +1193,7 @@ PassTimestampCheck ( }
CertList = (EFI_SIGNATURE_LIST *)DbtData;
- while ((DbtDataSize > 0) && (DbtDataSize >= CertList->SignatureListSize)) {
+ while ((DbtDataSize > 0) && (DbtDataSize >= (UINTN)CertList->SignatureListSize)) {
if (CompareGuid (&CertList->SignatureType, &gEfiCertX509Guid)) {
Cert = (EFI_SIGNATURE_DATA *)((UINT8 *)CertList + sizeof (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize);
CertCount = (CertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - CertList->SignatureHeaderSize) / CertList->SignatureSize;
@@ -1319,7 +1319,7 @@ IsForbiddenByDbx ( //
CertList = (EFI_SIGNATURE_LIST *)Data;
CertListSize = DataSize;
- while ((CertListSize > 0) && (CertListSize >= CertList->SignatureListSize)) {
+ while ((CertListSize > 0) && (CertListSize >= (UINTN)CertList->SignatureListSize)) {
if (CompareGuid (&CertList->SignatureType, &gEfiCertX509Guid)) {
CertData = (EFI_SIGNATURE_DATA *)((UINT8 *)CertList + sizeof (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize);
CertCount = (CertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - CertList->SignatureHeaderSize) / CertList->SignatureSize;
@@ -1524,7 +1524,7 @@ IsAllowedByDb ( // Find X509 certificate in Signature List to verify the signature in pkcs7 signed data.
//
CertList = (EFI_SIGNATURE_LIST *)Data;
- while ((DataSize > 0) && (DataSize >= CertList->SignatureListSize)) {
+ while ((DataSize > 0) && (DataSize >= (UINTN)CertList->SignatureListSize)) {
if (CompareGuid (&CertList->SignatureType, &gEfiCertX509Guid)) {
CertData = (EFI_SIGNATURE_DATA *)((UINT8 *)CertList + sizeof (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize);
CertCount = (CertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - CertList->SignatureHeaderSize) / CertList->SignatureSize;
@@ -2050,8 +2050,9 @@ Failed: // executable information table in either case.
//
NameStr = ConvertDevicePathToText (File, FALSE, TRUE);
- AddImageExeInfo (Action, NameStr, File, SignatureList, SignatureListSize);
+
if (NameStr != NULL) {
+ AddImageExeInfo (Action, NameStr, File, SignatureList, SignatureListSize);
DEBUG ((DEBUG_INFO, "The image doesn't pass verification: %s\n", NameStr));
FreePool (NameStr);
}
diff --git a/SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.c b/SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.c index de4f5e5..f81519d 100644 --- a/SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.c +++ b/SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.c @@ -387,7 +387,10 @@ Tcg2UserConfirm ( NoPpiInfo = FALSE;
BufSize = CONFIRM_BUFFER_SIZE;
ConfirmText = AllocateZeroPool (BufSize);
- ASSERT (ConfirmText != NULL);
+ if (ConfirmText == NULL) {
+ ASSERT (ConfirmText != NULL);
+ return FALSE;
+ }
mTcg2PpStringPackHandle = HiiAddPackages (&gEfiTcg2PhysicalPresenceGuid, gImageHandle, DxeTcg2PhysicalPresenceLibStrings, NULL);
ASSERT (mTcg2PpStringPackHandle != NULL);
@@ -401,10 +404,20 @@ Tcg2UserConfirm ( TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CLEAR));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
+ if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR));
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), L" \n\n", (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
@@ -417,14 +430,29 @@ Tcg2UserConfirm ( TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CLEAR));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_PPI_HEAD_STR));
+ if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_CLEAR));
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR));
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), L" \n\n", (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
@@ -452,14 +480,29 @@ Tcg2UserConfirm ( TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_SET_PCR_BANKS));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
+ if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_SET_PCR_BANKS_1));
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_SET_PCR_BANKS_2));
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
@@ -467,7 +510,11 @@ Tcg2UserConfirm ( Tcg2FillBufferWithBootHashAlg (TempBuffer2, sizeof (TempBuffer2), CurrentPCRBanks);
TmpStr1 = AllocateZeroPool (BufSize);
- ASSERT (TmpStr1 != NULL);
+ if (TmpStr1 == NULL) {
+ ASSERT (TmpStr1 != NULL);
+ return FALSE;
+ }
+
UnicodeSPrint (TmpStr1, BufSize, L"Current PCRBanks is 0x%x. (%s)\nNew PCRBanks is 0x%x. (%s)\n", CurrentPCRBanks, TempBuffer2, TpmPpCommandParameter, TempBuffer);
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
@@ -481,14 +528,29 @@ Tcg2UserConfirm ( TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CHANGE_EPS));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
+ if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CHANGE_EPS_1));
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CHANGE_EPS_2));
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
@@ -498,6 +560,11 @@ Tcg2UserConfirm ( TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_ENABLE_BLOCK_SID));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_HEAD_STR));
+ if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
break;
@@ -506,6 +573,11 @@ Tcg2UserConfirm ( TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_DISABLE_BLOCK_SID));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_HEAD_STR));
+ if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
break;
@@ -515,6 +587,11 @@ Tcg2UserConfirm ( TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_PP_ENABLE_BLOCK_SID));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_PPI_HEAD_STR));
+ if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
break;
@@ -524,6 +601,11 @@ Tcg2UserConfirm ( TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_PP_DISABLE_BLOCK_SID));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_PPI_HEAD_STR));
+ if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
break;
@@ -544,11 +626,21 @@ Tcg2UserConfirm ( TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY));
}
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
if (NoPpiInfo) {
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_INFO));
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
}
@@ -561,11 +653,21 @@ Tcg2UserConfirm ( TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_ACCEPT_KEY));
}
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
if (NoPpiInfo) {
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_NO_PPI_INFO));
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
}
@@ -573,6 +675,11 @@ Tcg2UserConfirm ( TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_REJECT_KEY));
}
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
BufSize -= StrSize (ConfirmText);
UnicodeSPrint (ConfirmText + StrLen (ConfirmText), BufSize, TmpStr1, TmpStr2);
diff --git a/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c b/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c index 597ce77..d38a607 100644 --- a/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c +++ b/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c @@ -540,7 +540,7 @@ UserConfirm ( CHAR16 *TmpStr2;
UINTN BufSize;
BOOLEAN CautionKey;
- UINT16 Index;
+ UINTN Index;
CHAR16 DstStr[81];
TmpStr2 = NULL;
diff --git a/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c b/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c index acba11d..b8eb5d6 100644 --- a/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c +++ b/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c @@ -615,6 +615,9 @@ GetMeasureBootProtocols ( @retval EFI_SUCCESS The file specified by DevicePath and non-NULL
FileBuffer did authenticate, and the platform policy dictates
that the DXE Foundation may use the file.
+
+ @retval EFI_OUT_OF_RESOURCES A necessary memory buffer could not be allocated.
+
@retval other error value
**/
EFI_STATUS
@@ -708,9 +711,16 @@ DxeTpm2MeasureBootHandler ( }
}
- FreePool (OrigDevicePathNode);
+ if (OrigDevicePathNode != NULL) {
+ FreePool (OrigDevicePathNode);
+ }
+
OrigDevicePathNode = DuplicateDevicePath (File);
- ASSERT (OrigDevicePathNode != NULL);
+ if (OrigDevicePathNode == NULL) {
+ ASSERT (OrigDevicePathNode != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
break;
}
}
diff --git a/SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.c b/SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.c index c786c21..7b00833 100644 --- a/SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.c +++ b/SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.c @@ -56,7 +56,10 @@ Sha1HashInit ( CtxSize = Sha1GetContextSize ();
Sha1Ctx = AllocatePool (CtxSize);
- ASSERT (Sha1Ctx != NULL);
+ if (Sha1Ctx == NULL) {
+ ASSERT (Sha1Ctx != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
Sha1Init (Sha1Ctx);
diff --git a/SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.c b/SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.c index 4387740..4fdc5a8 100644 --- a/SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.c +++ b/SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.c @@ -56,7 +56,10 @@ Sha256HashInit ( CtxSize = Sha256GetContextSize ();
Sha256Ctx = AllocatePool (CtxSize);
- ASSERT (Sha256Ctx != NULL);
+ if (Sha256Ctx == NULL) {
+ ASSERT (Sha256Ctx != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
Sha256Init (Sha256Ctx);
diff --git a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c index 2169c5e..5e0bbe5 100644 --- a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c +++ b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c @@ -80,6 +80,11 @@ HashStart ( for (Index = 0; Index < mHashInterfaceCount; Index++) {
HashMask = Tpm2GetHashMaskFromAlgo (&mHashInterface[Index].HashGuid);
+ if (HashCtx == NULL) {
+ // If we fail to get the hash mask we don't have resources.
+ return EFI_OUT_OF_RESOURCES;
+ }
+
if ((HashMask & PcdGet32 (PcdTpm2HashMask)) != 0) {
mHashInterface[Index].HashInit (&HashCtx[Index]);
}
@@ -278,8 +283,16 @@ HashAndExtend ( CheckSupportedHashMaskMismatch ();
- HashStart (&HashHandle);
- HashUpdate (HashHandle, DataToHash, DataToHashLen);
+ Status = HashStart (&HashHandle);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Status = HashUpdate (HashHandle, DataToHash, DataToHashLen);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
Status = HashCompleteAndExtend (HashHandle, PcrIndex, NULL, 0, DigestList);
return Status;
diff --git a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c index eeb424b..156dc04 100644 --- a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c +++ b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c @@ -106,7 +106,10 @@ CheckSupportedHashMaskMismatch ( HASH_INTERFACE_HOB *HashInterfaceHobLast;
HashInterfaceHobLast = InternalGetHashInterfaceHob (&gZeroGuid);
- ASSERT (HashInterfaceHobLast != NULL);
+ if (HashInterfaceHobLast == NULL) {
+ ASSERT (HashInterfaceHobLast != NULL);
+ return;
+ }
if ((HashInterfaceHobLast->SupportedHashMask != 0) &&
(HashInterfaceHobCurrent->SupportedHashMask != HashInterfaceHobLast->SupportedHashMask))
@@ -152,7 +155,10 @@ HashStart ( CheckSupportedHashMaskMismatch (HashInterfaceHob);
HashCtx = AllocatePool (sizeof (*HashCtx) * HashInterfaceHob->HashInterfaceCount);
- ASSERT (HashCtx != NULL);
+ if (HashCtx == NULL) {
+ ASSERT (HashCtx != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
for (Index = 0; Index < HashInterfaceHob->HashInterfaceCount; Index++) {
HashMask = Tpm2GetHashMaskFromAlgo (&HashInterfaceHob->HashInterface[Index].HashGuid);
@@ -305,8 +311,16 @@ HashAndExtend ( CheckSupportedHashMaskMismatch (HashInterfaceHob);
- HashStart (&HashHandle);
- HashUpdate (HashHandle, DataToHash, DataToHashLen);
+ Status = HashStart (&HashHandle);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Status = HashUpdate (HashHandle, DataToHash, DataToHashLen);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
Status = HashCompleteAndExtend (HashHandle, PcrIndex, NULL, 0, DigestList);
return Status;
diff --git a/SecurityPkg/Library/SecureBootVariableProvisionLib/SecureBootVariableProvisionLib.c b/SecurityPkg/Library/SecureBootVariableProvisionLib/SecureBootVariableProvisionLib.c index 7f9fdd2..e45e975 100644 --- a/SecurityPkg/Library/SecureBootVariableProvisionLib/SecureBootVariableProvisionLib.c +++ b/SecurityPkg/Library/SecureBootVariableProvisionLib/SecureBootVariableProvisionLib.c @@ -59,7 +59,11 @@ SecureBootFetchData ( *SigListOut = NULL;
*SigListsSize = 0;
CertInfo = AllocatePool (sizeof (SECURE_BOOT_CERTIFICATE_INFO));
- NewCertInfo = CertInfo;
+ if (CertInfo == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ NewCertInfo = CertInfo;
while (1) {
if (NewCertInfo == NULL) {
Status = EFI_OUT_OF_RESOURCES;
@@ -93,6 +97,9 @@ SecureBootFetchData ( sizeof (SECURE_BOOT_CERTIFICATE_INFO) * (KeyIndex + 1),
CertInfo
);
+ if (NewCertInfo == NULL) {
+ goto Cleanup;
+ }
}
if (Status == EFI_NOT_FOUND) {
diff --git a/SecurityPkg/Library/TcgEventLogRecordLib/TcgEventLogRecordLib.c b/SecurityPkg/Library/TcgEventLogRecordLib/TcgEventLogRecordLib.c index e1e0f99..cbe1da3 100644 --- a/SecurityPkg/Library/TcgEventLogRecordLib/TcgEventLogRecordLib.c +++ b/SecurityPkg/Library/TcgEventLogRecordLib/TcgEventLogRecordLib.c @@ -106,7 +106,7 @@ MeasureFirmwareBlob ( {
if (Description != NULL) {
AsciiSPrint ((CHAR8 *)FvBlob2.BlobDescription, sizeof (FvBlob2.BlobDescription), "%a", Description);
- } else {
+ } else if (FvName != NULL) {
AsciiSPrint ((CHAR8 *)FvBlob2.BlobDescription, sizeof (FvBlob2.BlobDescription), "Fv(%g)", FvName);
}
diff --git a/SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12Tis.c b/SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12Tis.c index 64bea73..5eb1a0b 100644 --- a/SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12Tis.c +++ b/SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12Tis.c @@ -270,7 +270,7 @@ Tpm12TisTpmCommand ( {
EFI_STATUS Status;
UINT16 BurstCount;
- UINT32 Index;
+ UINTN Index;
UINT32 TpmOutSize;
UINT16 Data16;
UINT32 Data32;
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmDump.c b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmDump.c index c83838f..7b2e449 100644 --- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmDump.c +++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmDump.c @@ -421,7 +421,7 @@ DumpTpmPcrCommand ( // If this is an unrecognized command, we can't go much further.
if ((Command != TPM_CC_PCR_Extend) && (Command != TPM_CC_PCR_Event)) {
- DEBUG ((DEBUG_WARN, "%a - Unrecognized command! 0x%X\n", __func__, Command));
+ DEBUG ((DEBUG_SECURITY, "%a - Unrecognized command! 0x%X\n", __func__, Command));
return;
}
@@ -461,7 +461,7 @@ DumpTpmPcrCommand ( default:
// This algorithm hasn't been programmed yet. We need to bail.
- DEBUG ((DEBUG_WARN, "%a - Unknown hash algorithm! 0x%04X\n", __func__, SwapBytes16 (CurrentDigest->hashAlg)));
+ DEBUG ((DEBUG_SECURITY, "%a - Unknown hash algorithm! 0x%04X\n", __func__, SwapBytes16 (CurrentDigest->hashAlg)));
// Zero the count so we can get out of here.
DigestCount = 0;
break;
@@ -635,11 +635,11 @@ DumpTpmInputBlock ( TPM_CC NativeCode;
DEBUG ((DEBUG_SECURITY, "\n=== BEGIN TPM COMMAND ===\n"));
- DEBUG ((DEBUG_VERBOSE, "Size: %d (0x%X), Address: 0x%X\n", InputBlockSize, InputBlockSize, InputBlock));
+ DEBUG ((DEBUG_SECURITY, "Size: %d (0x%X), Address: 0x%X\n", InputBlockSize, InputBlockSize, InputBlock));
// Make sure we've got at least enough data for a valid header.
if (InputBlockSize < sizeof (*CommHeader)) {
- DEBUG ((DEBUG_WARN, "%a - Invalid buffer size!\n", __func__));
+ DEBUG ((DEBUG_SECURITY, "%a - Invalid buffer size!\n", __func__));
return;
}
@@ -704,7 +704,7 @@ DumpTpmOutputBlock ( UINT32 NativeSize;
TPM_CC NativeCode;
- DEBUG ((DEBUG_VERBOSE, "Size: %d (0x%X), Address: 0x%X\n", OutputBlockSize, OutputBlockSize, OutputBlock));
+ DEBUG ((DEBUG_SECURITY, "Size: %d (0x%X), Address: 0x%X\n", OutputBlockSize, OutputBlockSize, OutputBlock));
// Start the debugging by mapping some stuff.
RespHeader = (TPM2_RESPONSE_HEADER *)OutputBlock;
diff --git a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfa.h b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfa.h index 665b594..97a558a 100644 --- a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfa.h +++ b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfa.h @@ -34,6 +34,9 @@ #ifndef TPM2_DEVICE_LIB_FFA_H_
#define TPM2_DEVICE_LIB_FFA_H_
+#define TPM2_FFA_INTERFACE_TYPE_UNKNOWN 0xFF
+#define TPM2_FFA_PARTITION_ID_INVALID 0x0000
+
/**
This function is used to get the TPM interface version.
@@ -188,6 +191,22 @@ FfaTpm2RequestUseTpm ( );
/**
+ This function is used to get the TPM service partition id via FF-A
+
+ @param[out] PartitionId - Supplies the pointer to the TPM service partition id.
+
+ @retval EFI_SUCCESS The TPM command was successfully sent to the TPM
+ and the response was copied to the Output buffer.
+ @retval EFI_INVALID_PARAMETER The TPM command buffer is NULL or the TPM command
+ buffer size is 0.
+ @retval EFI_DEVICE_ERROR An error occurred in communication with the TPM.
+**/
+EFI_STATUS
+FfaTpm2GetServicePartitionId (
+ OUT UINT16 *PartitionId
+ );
+
+/**
Dump PTP register information.
@param[in] Register Pointer to PTP register.
@@ -210,4 +229,35 @@ InternalTpm2DeviceLibFfaConstructor ( VOID
);
+/**
+ This function validate TPM interface type for TPM service over FF-A.
+
+ @retval EFI_SUCCESS TPM interface type is valid.
+
+ @retval EFI_UNSUPPORTED TPM interface type is invalid.
+
+**/
+EFI_STATUS
+EFIAPI
+ValidateTpmInterfaceType (
+ VOID
+ );
+
+/**
+ This function is used to get the TPM service partition id.
+
+ @param[out] PartitionId - Supplies the pointer to the TPM service partition id.
+
+ @retval EFI_SUCCESS The TPM command was successfully sent to the TPM
+ and the response was copied to the Output buffer.
+ @retval EFI_INVALID_PARAMETER The TPM command buffer is NULL or the TPM command
+ buffer size is 0.
+ @retval EFI_DEVICE_ERROR An error occurred in communication with the TPM.
+**/
+EFI_STATUS
+EFIAPI
+GetTpmServicePartitionId (
+ OUT UINT16 *PartitionId
+ );
+
#endif /* _TPM2_DEVICE_LIB_SMC_H_ */
diff --git a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfa.inf b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfa.inf index 68a0094..198a9e5 100644 --- a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfa.inf +++ b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfa.inf @@ -29,6 +29,7 @@ Tpm2DeviceLibFfaBase.c
Tpm2Ptp.c
Tpm2DeviceLibFfa.h
+ Tpm2InfoFfa.c
[Packages]
MdePkg/MdePkg.dec
diff --git a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfaBase.c b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfaBase.c index 85815a0..058d131 100644 --- a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfaBase.c +++ b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfaBase.c @@ -21,8 +21,7 @@ #include "Tpm2DeviceLibFfa.h"
-TPM2_PTP_INTERFACE_TYPE mActiveTpmInterfaceType;
-UINT8 mCRBIdleByPass;
+UINT8 mCRBIdleByPass;
/**
Return cached PTP CRB interface IdleByPass state.
@@ -52,28 +51,18 @@ InternalTpm2DeviceLibFfaConstructor ( {
EFI_STATUS Status;
- mActiveTpmInterfaceType = PcdGet8 (PcdActiveTpmInterfaceType);
- mCRBIdleByPass = 0xFF;
+ mCRBIdleByPass = 0xFF;
if (PcdGet64 (PcdTpmBaseAddress) == 0) {
Status = EFI_NO_MAPPING;
goto Exit;
}
- //
- // Start by checking the PCD out of the gate and read from the CRB if it is invalid
- //
- if (mActiveTpmInterfaceType == 0xFF) {
- mActiveTpmInterfaceType = Tpm2GetPtpInterface ((VOID *)(UINTN)PcdGet64 (PcdTpmBaseAddress));
- PcdSet8S (PcdActiveTpmInterfaceType, mActiveTpmInterfaceType);
- }
-
- if (mActiveTpmInterfaceType != Tpm2PtpInterfaceCrb) {
- Status = EFI_UNSUPPORTED;
+ Status = ValidateTpmInterfaceType ();
+ if (EFI_ERROR (Status)) {
goto Exit;
}
- DEBUG ((DEBUG_INFO, "Setting Tpm Active Interface Type %d\n", mActiveTpmInterfaceType));
mCRBIdleByPass = Tpm2GetIdleByPass ((VOID *)(UINTN)PcdGet64 (PcdTpmBaseAddress));
Status = EFI_SUCCESS;
diff --git a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceSecLibFfa.inf b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceSecLibFfa.inf new file mode 100644 index 0000000..2f4ae52 --- /dev/null +++ b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceSecLibFfa.inf @@ -0,0 +1,51 @@ +## @file
+# Provides function interfaces to communicate with TPM 2.0 device
+#
+# This library helps to use TPM 2.0 device in library function API
+# based on FF-A using Command Response Buffer (CRB).
+#
+# Copyright (c), Microsoft Corporation.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = Tpm2DeviceSecLibFfa
+ FILE_GUID = d66e7482-615c-11f0-91d0-47f6d24396e9
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = Tpm2DeviceLib|SEC
+ CONSTRUCTOR = Tpm2DeviceLibFfaConstructor
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = AARCH64
+#
+
+[Sources.common]
+ Tpm2DeviceLibFfa.c
+ Tpm2ServiceFfaRaw.c
+ Tpm2DeviceLibFfaBase.c
+ Tpm2Ptp.c
+ Tpm2DeviceLibFfa.h
+ Tpm2InfoSecFfa.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ SecurityPkg/SecurityPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ DebugLib
+ TimerLib
+ BaseMemoryLib
+ IoLib
+ ArmFfaLib
+
+[Guids]
+ gTpm2ServiceFfaGuid
+
+[Pcd.common]
+ gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress ## CONSUMES
diff --git a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InfoFfa.c b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InfoFfa.c new file mode 100644 index 0000000..602fe34 --- /dev/null +++ b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InfoFfa.c @@ -0,0 +1,87 @@ +/** @file
+ This library provides an interfaces to access DynamicPcds used
+ in Tpm2DeviceLibFfa.
+
+ Copyright (c) 2025, Arm Ltd. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/PcdLib.h>
+#include <Library/Tpm2DeviceLib.h>
+#include <Uefi/UefiBaseType.h>
+
+#include "Tpm2DeviceLibFfa.h"
+
+TPM2_PTP_INTERFACE_TYPE mActiveTpmInterfaceType;
+
+/**
+ This function validate TPM interface type for TPM service over FF-A.
+
+ @retval EFI_SUCCESS TPM interface type is valid.
+
+ @retval EFI_UNSUPPORTED TPM interface type is invalid.
+
+**/
+EFI_STATUS
+ValidateTpmInterfaceType (
+ VOID
+ )
+{
+ mActiveTpmInterfaceType = PcdGet8 (PcdActiveTpmInterfaceType);
+
+ //
+ // Start by checking the PCD out of the gate and read from the CRB if it is invalid
+ //
+ if (mActiveTpmInterfaceType == TPM2_FFA_INTERFACE_TYPE_UNKNOWN) {
+ mActiveTpmInterfaceType = Tpm2GetPtpInterface ((VOID *)(UINTN)PcdGet64 (PcdTpmBaseAddress));
+ PcdSet8S (PcdActiveTpmInterfaceType, mActiveTpmInterfaceType);
+ }
+
+ if (mActiveTpmInterfaceType != Tpm2PtpInterfaceCrb) {
+ return EFI_UNSUPPORTED;
+ }
+
+ DEBUG ((DEBUG_INFO, "Setting Tpm Active Interface Type %d\n", mActiveTpmInterfaceType));
+
+ return EFI_SUCCESS;
+}
+
+/**
+ This function is used to get the TPM service partition id.
+
+ @param[out] PartitionId - Supplies the pointer to the TPM service partition id.
+
+ @retval EFI_SUCCESS The TPM command was successfully sent to the TPM
+ and the response was copied to the Output buffer.
+ @retval EFI_INVALID_PARAMETER The TPM command buffer is NULL or the TPM command
+ buffer size is 0.
+ @retval EFI_DEVICE_ERROR An error occurred in communication with the TPM.
+**/
+EFI_STATUS
+EFIAPI
+GetTpmServicePartitionId (
+ OUT UINT16 *PartitionId
+ )
+{
+ EFI_STATUS Status;
+
+ if (PartitionId == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (PcdGet16 (PcdTpmServiceFfaPartitionId) != TPM2_FFA_PARTITION_ID_INVALID) {
+ *PartitionId = PcdGet16 (PcdTpmServiceFfaPartitionId);
+ return EFI_SUCCESS;
+ }
+
+ Status = FfaTpm2GetServicePartitionId (PartitionId);
+ if (!EFI_ERROR (Status)) {
+ PcdSet16S (PcdTpmServiceFfaPartitionId, *PartitionId);
+ }
+
+ return Status;
+}
diff --git a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InfoSecFfa.c b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InfoSecFfa.c new file mode 100644 index 0000000..2f264eb --- /dev/null +++ b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InfoSecFfa.c @@ -0,0 +1,62 @@ +/** @file
+ This library provides an interfaces to access DynamicPcds used
+ in Tpm2DeviceLibFfa.
+
+ Copyright (c) 2025, Arm Ltd. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/Tpm2DeviceLib.h>
+#include <Uefi/UefiBaseType.h>
+
+#include "Tpm2DeviceLibFfa.h"
+
+/**
+ This function validate TPM interface type for TPM service over FF-A.
+
+ @retval EFI_SUCCESS TPM interface type is valid.
+
+ @retval EFI_UNSUPPORTED TPM interface type is invalid.
+
+**/
+EFI_STATUS
+EFIAPI
+ValidateTpmInterfaceType (
+ VOID
+ )
+{
+ TPM2_PTP_INTERFACE_TYPE TpmInterfaceType;
+
+ TpmInterfaceType = Tpm2GetPtpInterface ((VOID *)(UINTN)PcdGet64 (PcdTpmBaseAddress));
+ if (TpmInterfaceType != Tpm2PtpInterfaceCrb) {
+ return EFI_UNSUPPORTED;
+ }
+
+ DEBUG ((DEBUG_INFO, "Setting Tpm Active Interface Type %d\n", TpmInterfaceType));
+
+ return EFI_SUCCESS;
+}
+
+/**
+ This function is used to get the TPM service partition id.
+
+ @param[out] PartitionId - Supplies the pointer to the TPM service partition id.
+
+ @retval EFI_SUCCESS The TPM command was successfully sent to the TPM
+ and the response was copied to the Output buffer.
+ @retval EFI_INVALID_PARAMETER The TPM command buffer is NULL or the TPM command
+ buffer size is 0.
+ @retval EFI_DEVICE_ERROR An error occurred in communication with the TPM.
+**/
+EFI_STATUS
+EFIAPI
+GetTpmServicePartitionId (
+ OUT UINT16 *PartitionId
+ )
+{
+ return FfaTpm2GetServicePartitionId (PartitionId);
+}
diff --git a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InstanceLibFfa.inf b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InstanceLibFfa.inf index 0f5d3fa..ecf9a36 100644 --- a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InstanceLibFfa.inf +++ b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InstanceLibFfa.inf @@ -29,6 +29,7 @@ Tpm2DeviceLibFfaBase.c
Tpm2Ptp.c
Tpm2DeviceLibFfa.h
+ Tpm2InfoFfa.c
[Packages]
MdePkg/MdePkg.dec
diff --git a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2ServiceFfaRaw.c b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2ServiceFfaRaw.c index 3e36bcf..44159c9 100644 --- a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2ServiceFfaRaw.c +++ b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2ServiceFfaRaw.c @@ -26,7 +26,7 @@ #include "Tpm2DeviceLibFfa.h"
-UINT32 mFfaTpm2PartitionId = MAX_UINT32;
+UINT16 mFfaTpm2PartitionId = TPM2_FFA_PARTITION_ID_INVALID;
/**
Check the return status from the FF-A call and returns EFI_STATUS
@@ -84,7 +84,7 @@ TranslateTpmReturnStatus ( }
/**
- This function is used to get the TPM service partition id.
+ This function is used to get the TPM service partition id via FF-A.
@param[out] PartitionId - Supplies the pointer to the TPM service partition id.
@@ -92,11 +92,12 @@ TranslateTpmReturnStatus ( and the response was copied to the Output buffer.
@retval EFI_INVALID_PARAMETER The TPM command buffer is NULL or the TPM command
buffer size is 0.
+ @retval EFI_DEVICE_ERROR The TPM partition information is wrong.
@retval EFI_DEVICE_ERROR An error occurred in communication with the TPM.
**/
EFI_STATUS
-GetTpmServicePartitionId (
- OUT UINT32 *PartitionId
+FfaTpm2GetServicePartitionId (
+ OUT UINT16 *PartitionId
)
{
EFI_STATUS Status;
@@ -114,20 +115,6 @@ GetTpmServicePartitionId ( goto Exit;
}
- if (mFfaTpm2PartitionId != MAX_UINT32) {
- *PartitionId = mFfaTpm2PartitionId;
- Status = EFI_SUCCESS;
- goto Exit;
- }
-
- if (PcdGet16 (PcdTpmServiceFfaPartitionId) != 0) {
- mFfaTpm2PartitionId = PcdGet16 (PcdTpmServiceFfaPartitionId);
- *PartitionId = mFfaTpm2PartitionId;
- Status = EFI_SUCCESS;
-
- goto Exit;
- }
-
Status = ArmFfaLibPartitionIdGet (&PartId);
if (EFI_ERROR (Status)) {
DEBUG ((
@@ -164,11 +151,14 @@ GetTpmServicePartitionId ( Status = EFI_INVALID_PARAMETER;
DEBUG ((DEBUG_ERROR, "Invalid partition Info(%g). Count: %d, Size: %d\n", &gTpm2ServiceFfaGuid, Count, Size));
} else {
- TpmPartInfo = (EFI_FFA_PART_INFO_DESC *)RxBuffer;
- mFfaTpm2PartitionId = TpmPartInfo->PartitionId;
- *PartitionId = mFfaTpm2PartitionId;
-
- Status = PcdSet16S (PcdTpmServiceFfaPartitionId, mFfaTpm2PartitionId);
+ TpmPartInfo = (EFI_FFA_PART_INFO_DESC *)RxBuffer;
+ *PartitionId = TpmPartInfo->PartitionId;
+ if (TpmPartInfo->PartitionId == TPM2_FFA_PARTITION_ID_INVALID) {
+ /*
+ * Tpm partition id never be TPM2_FFA_PARTITION_ID_INVALID.
+ */
+ Status = EFI_DEVICE_ERROR;
+ }
}
RxRelease:
@@ -202,7 +192,7 @@ Tpm2GetInterfaceVersion ( goto Exit;
}
- if (mFfaTpm2PartitionId == MAX_UINT32) {
+ if (mFfaTpm2PartitionId == TPM2_FFA_PARTITION_ID_INVALID) {
GetTpmServicePartitionId (&mFfaTpm2PartitionId);
}
@@ -253,7 +243,7 @@ Tpm2GetFeatureInfo ( goto Exit;
}
- if (mFfaTpm2PartitionId == MAX_UINT32) {
+ if (mFfaTpm2PartitionId == TPM2_FFA_PARTITION_ID_INVALID) {
GetTpmServicePartitionId (&mFfaTpm2PartitionId);
}
@@ -296,7 +286,7 @@ Tpm2ServiceStart ( EFI_STATUS Status;
DIRECT_MSG_ARGS FfaDirectReq2Args;
- if (mFfaTpm2PartitionId == MAX_UINT32) {
+ if (mFfaTpm2PartitionId == TPM2_FFA_PARTITION_ID_INVALID) {
GetTpmServicePartitionId (&mFfaTpm2PartitionId);
}
@@ -341,7 +331,7 @@ Tpm2RegisterNotification ( EFI_STATUS Status;
DIRECT_MSG_ARGS FfaDirectReq2Args;
- if (mFfaTpm2PartitionId == MAX_UINT32) {
+ if (mFfaTpm2PartitionId == TPM2_FFA_PARTITION_ID_INVALID) {
GetTpmServicePartitionId (&mFfaTpm2PartitionId);
}
@@ -380,7 +370,7 @@ Tpm2UnregisterNotification ( EFI_STATUS Status;
DIRECT_MSG_ARGS FfaDirectReq2Args;
- if (mFfaTpm2PartitionId == MAX_UINT32) {
+ if (mFfaTpm2PartitionId == TPM2_FFA_PARTITION_ID_INVALID) {
GetTpmServicePartitionId (&mFfaTpm2PartitionId);
}
@@ -417,7 +407,7 @@ Tpm2FinishNotified ( EFI_STATUS Status;
DIRECT_MSG_ARGS FfaDirectReq2Args;
- if (mFfaTpm2PartitionId == MAX_UINT32) {
+ if (mFfaTpm2PartitionId == TPM2_FFA_PARTITION_ID_INVALID) {
GetTpmServicePartitionId (&mFfaTpm2PartitionId);
}
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.c b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.c index 3ac20e8..1b2cddf 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.c @@ -230,6 +230,8 @@ AesEncrypt ( UINTN NbIndex;
UINTN Round;
+ EFI_STATUS Status;
+
if ((Key == NULL) || (InData == NULL) || (OutData == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -237,7 +239,10 @@ AesEncrypt ( //
// Expands AES Key for encryption.
//
- AesExpandKey (Key, 128, &AesKey);
+ Status = AesExpandKey (Key, 128, &AesKey);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
Nr = AesKey.Nk + 6;
Ek = AesKey.EncKey;
diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc index 430b42c..ea6fdc2 100644 --- a/SecurityPkg/SecurityPkg.dsc +++ b/SecurityPkg/SecurityPkg.dsc @@ -91,6 +91,9 @@ [LibraryClasses.ARM, LibraryClasses.AARCH64]
ArmTrngLib|MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.inf
+ ArmSmcLib|MdePkg/Library/ArmSmcLib/ArmSmcLib.inf
+ ArmSvcLib|MdePkg/Library/ArmSvcLib/ArmSvcLib.inf
+ ArmFfaLib|MdeModulePkg/Library/ArmFfaLib/ArmFfaPeiLib.inf
[LibraryClasses.ARM]
RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf
@@ -425,7 +428,9 @@ [Components.AARCH64]
SecurityPkg/Tcg/Tcg2StandaloneMmArm/Tcg2StandaloneMmArm.inf
SecurityPkg/Tcg/Tcg2AcpiFfa/Tcg2AcpiFfa.inf
+ SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigFfaPei.inf
SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfa.inf
+ SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceSecLibFfa.inf
SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InstanceLibFfa.inf
[BuildOptions]
diff --git a/SecurityPkg/Tcg/Opal/OpalPassword/OpalDriver.c b/SecurityPkg/Tcg/Opal/OpalPassword/OpalDriver.c index 0167afd..068c3c7 100644 --- a/SecurityPkg/Tcg/Opal/OpalPassword/OpalDriver.c +++ b/SecurityPkg/Tcg/Opal/OpalPassword/OpalDriver.c @@ -2224,7 +2224,7 @@ ProcessOpalRequest ( //
TempVariable = Variable;
while ((VariableSize > sizeof (OPAL_REQUEST_VARIABLE)) &&
- (VariableSize >= TempVariable->Length) &&
+ (VariableSize >= (UINTN)TempVariable->Length) &&
(TempVariable->Length > sizeof (OPAL_REQUEST_VARIABLE)))
{
DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)TempVariable + sizeof (OPAL_REQUEST_VARIABLE));
diff --git a/SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.c b/SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.c index 1e0b00b..c5f1121 100644 --- a/SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.c +++ b/SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.c @@ -113,7 +113,7 @@ GetSavedOpalRequest ( TempVariable = Variable;
while ((VariableSize > sizeof (OPAL_REQUEST_VARIABLE)) &&
- (VariableSize >= TempVariable->Length) &&
+ (VariableSize >= (UINTN)TempVariable->Length) &&
(TempVariable->Length > sizeof (OPAL_REQUEST_VARIABLE)))
{
DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)TempVariable + sizeof (OPAL_REQUEST_VARIABLE));
@@ -193,7 +193,7 @@ SaveOpalRequest ( TempVariable = Variable;
TempVariableSize = VariableSize;
while ((TempVariableSize > sizeof (OPAL_REQUEST_VARIABLE)) &&
- (TempVariableSize >= TempVariable->Length) &&
+ (TempVariableSize >= (UINTN)TempVariable->Length) &&
(TempVariable->Length > sizeof (OPAL_REQUEST_VARIABLE)))
{
DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)TempVariable + sizeof (OPAL_REQUEST_VARIABLE));
@@ -226,7 +226,11 @@ SaveOpalRequest ( DevicePathSize = GetDevicePathSize (DevicePath);
NewVariableSize = VariableSize + sizeof (OPAL_REQUEST_VARIABLE) + DevicePathSize;
NewVariable = AllocatePool (NewVariableSize);
- ASSERT (NewVariable != NULL);
+ if (NewVariable == NULL) {
+ ASSERT (NewVariable != NULL);
+ return;
+ }
+
CopyMem (NewVariable, Variable, VariableSize);
TempVariable = (OPAL_REQUEST_VARIABLE *)((UINTN)NewVariable + VariableSize);
TempVariable->Length = (UINT32)(sizeof (OPAL_REQUEST_VARIABLE) + DevicePathSize);
@@ -239,7 +243,11 @@ SaveOpalRequest ( DevicePathSize = GetDevicePathSize (DevicePath);
NewVariableSize = sizeof (OPAL_REQUEST_VARIABLE) + DevicePathSize;
NewVariable = AllocatePool (NewVariableSize);
- ASSERT (NewVariable != NULL);
+ if (NewVariable == NULL) {
+ ASSERT (NewVariable != NULL);
+ return;
+ }
+
NewVariable->Length = (UINT32)(sizeof (OPAL_REQUEST_VARIABLE) + DevicePathSize);
CopyMem (&NewVariable->OpalRequest, &OpalRequest, sizeof (OPAL_REQUEST));
DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)NewVariable + sizeof (OPAL_REQUEST_VARIABLE));
@@ -1111,8 +1119,13 @@ ExtractConfig ( //
DriverHandle = HiiGetDriverImageHandleCB ();
ConfigRequestHdr = HiiConstructConfigHdr (&gHiiSetupVariableGuid, OpalPasswordStorageName, DriverHandle);
- Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
- ConfigRequest = AllocateZeroPool (Size);
+ if (ConfigRequestHdr == NULL) {
+ ASSERT (ConfigRequestHdr != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
+ ConfigRequest = AllocateZeroPool (Size);
if (ConfigRequest == NULL) {
return EFI_OUT_OF_RESOURCES;
}
diff --git a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c index edf5f0f..2b93733 100644 --- a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c +++ b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c @@ -103,7 +103,11 @@ InitializeTcg2VersionInfo ( TCG2_VERSION_NAME,
PrivateData->DriverHandle
);
- ASSERT (ConfigRequestHdr != NULL);
+ if (ConfigRequestHdr == NULL) {
+ ASSERT (ConfigRequestHdr != NULL);
+ return;
+ }
+
DataSize = sizeof (Tcg2Version);
Status = gRT->GetVariable (
TCG2_VERSION_NAME,
diff --git a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigFfaPei.inf b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigFfaPei.inf new file mode 100644 index 0000000..e20a1f8 --- /dev/null +++ b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigFfaPei.inf @@ -0,0 +1,53 @@ +## @file
+# Set TPM device type
+#
+# This module initializes TPM device type based on CRB over FF-A interface
+#
+# Copyright (c) 2025, Arm Ltd. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x0001001B
+ BASE_NAME = Tcg2ConfigFfaPei
+ FILE_GUID = ae8c4c50-2cd7-11f0-9e39-a7fbc471b972
+ MODULE_TYPE = PEIM
+ VERSION_STRING = 1.0
+ ENTRY_POINT = Tcg2ConfigFfaPeimEntryPoint
+
+#
+# VALID_ARCHITECTURES = AARCH64
+#
+
+[Sources]
+ Tcg2ConfigFfaPeim.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ SecurityPkg/SecurityPkg.dec
+
+[LibraryClasses]
+ ArmFfaLib
+ BaseLib
+ BaseMemoryLib
+ PeiServicesLib
+ PeimEntryPoint
+ DebugLib
+ PcdLib
+ HobLib
+
+[Guids]
+ gTpm2ServiceFfaGuid ## SOMETIMES_CONSUMES
+ gEfiTpmDeviceInstanceNoneGuid ## SOMETIMES_CONSUMES
+ gEfiTpmDeviceSelectedGuid ## SOMETIMES_PRODUCES
+
+[Ppis]
+ gPeiTpmInitializationDonePpiGuid ## SOMETIMES_PRODUCES
+
+[Pcd]
+ gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid
+
+[Depex]
+ gEfiPeiMasterBootModePpiGuid
diff --git a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigFfaPeim.c b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigFfaPeim.c new file mode 100644 index 0000000..ea01c9b --- /dev/null +++ b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigFfaPeim.c @@ -0,0 +1,198 @@ +/** @file
+ Set TPM device type
+
+ This module initializes the TPM device type based on a CRB over FF-A
+ interface
+
+ Copyright (C) 2025, Arm Ltd.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - https://developer.arm.com/documentation/den0138/latest/
+**/
+
+#include <PiPei.h>
+
+#include <Guid/TpmInstance.h>
+#include <Guid/Tpm2ServiceFfa.h>
+
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/PeiServicesLib.h>
+#include <Library/ArmFfaLib.h>
+
+#define TPM2_FFA_SERVICE_MAJOR_VERSION (1)
+#define TPM2_FFA_SERVICE_MINOR_VERSION (0)
+
+STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmSelectedPpi = {
+ (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+ &gEfiTpmDeviceSelectedGuid,
+ NULL
+};
+
+STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList = {
+ EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
+ &gPeiTpmInitializationDonePpiGuid,
+ NULL
+};
+
+/**
+ Check the Tpm Service Interface version.
+
+ See the CRB over FF-A spec 6.1.
+ all of arguments' value based on the specification.
+
+ @param [in] TpmPartId TPM service partition id.
+
+ @retval EFI_SUCCESS
+ @retval EFI_DEVICE_ERROR Failed to communicate TPM SP.
+ @retval EFI_UNSUPPORTED Unsupported version of TPM service
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+Tpm2FfaCheckInterfaceVersion (
+ IN UINT16 TpmPartId
+ )
+{
+ EFI_STATUS Status;
+ DIRECT_MSG_ARGS TpmArgs;
+ UINT16 MajorVer;
+ UINT16 MinorVer;
+
+ ZeroMem (&TpmArgs, sizeof (DIRECT_MSG_ARGS));
+ TpmArgs.Arg0 = TPM2_FFA_GET_INTERFACE_VERSION;
+
+ Status = ArmFfaLibMsgSendDirectReq2 (TpmPartId, &gTpm2ServiceFfaGuid, &TpmArgs);
+ while (Status == EFI_INTERRUPT_PENDING) {
+ // We are assuming vCPU0 of the TPM SP since it is UP.
+ Status = ArmFfaLibRun (TpmPartId, 0x00);
+ }
+
+ if (EFI_ERROR (Status) || (TpmArgs.Arg0 != TPM2_FFA_SUCCESS_OK_RESULTS_RETURNED)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: Failed to get interface version... Status: %r, TpmArgs.Arg0: 0x%x\n",
+ __func__,
+ Status,
+ TpmArgs.Arg0
+ ));
+
+ return EFI_DEVICE_ERROR;
+ }
+
+ MajorVer = (TpmArgs.Arg1 & TPM2_FFA_SERVICE_MAJOR_VER_MASK) >> TPM2_FFA_SERVICE_MAJOR_VER_SHIFT;
+ MinorVer = (TpmArgs.Arg1 & TPM2_FFA_SERVICE_MINOR_VER_MASK) >> TPM2_FFA_SERVICE_MINOR_VER_SHIFT;
+ if ((MajorVer != TPM2_FFA_SERVICE_MAJOR_VERSION) || (MinorVer < TPM2_FFA_SERVICE_MINOR_VERSION)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: Wrong Tpm Ffa Interface Version...: v%d.%d\n",
+ __func__,
+ MajorVer,
+ MinorVer
+ ));
+ return EFI_UNSUPPORTED;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ The entry point for Tcg2 configuration driver.
+
+ @param FileHandle Handle of the file being invoked.
+ @param PeiServices Describes the list of possible PEI Services.
+**/
+EFI_STATUS
+EFIAPI
+Tcg2ConfigFfaPeimEntryPoint (
+ IN EFI_PEI_FILE_HANDLE FileHandle,
+ IN CONST EFI_PEI_SERVICES **PeiServices
+ )
+{
+ EFI_STATUS Status;
+ UINTN Size;
+ UINT16 PartId;
+ UINT16 TpmPartId;
+ EFI_FFA_PART_INFO_DESC *TpmPartInfo;
+ VOID *TxBuffer;
+ UINT64 TxBufferSize;
+ VOID *RxBuffer;
+ UINT64 RxBufferSize;
+ UINT32 Count;
+ CONST EFI_PEI_PPI_DESCRIPTOR *PpiList;
+ GUID *TpmInstanceGuid;
+
+ DEBUG ((DEBUG_INFO, "%a\n", __func__));
+
+ TpmInstanceGuid = &gEfiTpmDeviceInstanceNoneGuid;
+ PpiList = &mTpmInitializationDonePpiList;
+
+ Status = ArmFfaLibPartitionIdGet (&PartId);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed to get partition-id. Status: %r\n", Status));
+ goto Cleanup;
+ }
+
+ Status = ArmFfaLibGetRxTxBuffers (
+ &TxBuffer,
+ &TxBufferSize,
+ &RxBuffer,
+ &RxBufferSize
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed to get Rx/Tx Buffer. Status: %r\n", Status));
+ goto Cleanup;
+ }
+
+ Status = ArmFfaLibPartitionInfoGet (
+ &gTpm2ServiceFfaGuid,
+ FFA_PART_INFO_FLAG_TYPE_DESC,
+ &Count,
+ (UINT32 *)&Size
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed to get Tpm2 partition info. Status: %r\n", Status));
+ goto Cleanup;
+ }
+
+ if ((Count != 1) || (Size < sizeof (EFI_FFA_PART_INFO_DESC))) {
+ Status = EFI_INVALID_PARAMETER;
+ DEBUG ((DEBUG_ERROR, "Invalid partition Info(%g). Count: %d, Size: %d\n", &gTpm2ServiceFfaGuid, Count, Size));
+ ArmFfaLibRxRelease (PartId);
+ goto Cleanup;
+ }
+
+ TpmPartInfo = (EFI_FFA_PART_INFO_DESC *)RxBuffer;
+ TpmPartId = TpmPartInfo->PartitionId;
+ ArmFfaLibRxRelease (PartId);
+
+ Status = Tpm2FfaCheckInterfaceVersion (TpmPartId);
+ if (EFI_ERROR (Status)) {
+ goto Cleanup;
+ }
+
+ /*
+ * Set the PcdTpmInstanceGuid to TPM using CRB over FF-A
+ * So that Tpm2DeviceLibRouterPei/Dxe can communicate with
+ * TPM secure partition.
+ */
+ TpmInstanceGuid = &gTpm2ServiceFfaGuid;
+ PpiList = &mTpmSelectedPpi;
+
+Cleanup:
+ Size = sizeof (GUID);
+ Status = PcdSetPtrS (
+ PcdTpmInstanceGuid,
+ &Size,
+ TpmInstanceGuid
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ Status = PeiServicesInstallPpi (PpiList);
+
+ return Status;
+}
diff --git a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c index 85a8528..2a0307c 100644 --- a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c +++ b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c @@ -626,7 +626,7 @@ DumpEventLog ( TCG_PCR_EVENT_HDR *EventHdr;
TCG_PCR_EVENT2 *TcgPcrEvent2;
TCG_EfiSpecIDEventStruct *TcgEfiSpecIdEventStruct;
- UINTN NumberOfEvents;
+ UINT64 NumberOfEvents;
if (!DebugPrintLevelEnabled (DEBUG_SECURITY)) {
return;
@@ -637,7 +637,7 @@ DumpEventLog ( switch (EventLogFormat) {
case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2:
EventHdr = (TCG_PCR_EVENT_HDR *)(UINTN)EventLogLocation;
- while ((UINTN)EventHdr <= EventLogLastEntry) {
+ while ((EFI_PHYSICAL_ADDRESS)(UINTN)EventHdr <= EventLogLastEntry) {
DumpEvent (EventHdr);
EventHdr = (TCG_PCR_EVENT_HDR *)((UINTN)EventHdr + sizeof (TCG_PCR_EVENT_HDR) + EventHdr->EventSize);
}
@@ -668,7 +668,7 @@ DumpEventLog ( DumpTcgEfiSpecIdEventStruct (TcgEfiSpecIdEventStruct);
TcgPcrEvent2 = (TCG_PCR_EVENT2 *)((UINTN)TcgEfiSpecIdEventStruct + GetTcgEfiSpecIdEventStructSize (TcgEfiSpecIdEventStruct));
- while ((UINTN)TcgPcrEvent2 <= EventLogLastEntry) {
+ while ((EFI_PHYSICAL_ADDRESS)(UINTN)TcgPcrEvent2 <= EventLogLastEntry) {
DumpEvent2 (TcgPcrEvent2);
TcgPcrEvent2 = (TCG_PCR_EVENT2 *)((UINTN)TcgPcrEvent2 + GetPcrEvent2Size (TcgPcrEvent2));
}
diff --git a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c index 52ea1ac..2b4164c 100644 --- a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c +++ b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c @@ -193,9 +193,19 @@ TcgExtractConfig ( // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
//
ConfigRequestHdr = HiiConstructConfigHdr (&gTcgConfigFormSetGuid, mTcgStorageName, PrivateData->DriverHandle);
- Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
- ConfigRequest = AllocateZeroPool (Size);
- ASSERT (ConfigRequest != NULL);
+ if (ConfigRequestHdr == NULL) {
+ ASSERT (ConfigRequestHdr != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
+ ConfigRequest = AllocateZeroPool (Size);
+ if (ConfigRequest == NULL) {
+ ASSERT (ConfigRequest != NULL);
+ FreePool (ConfigRequestHdr);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
AllocatedRequest = TRUE;
UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, sizeof (TCG_CONFIGURATION));
FreePool (ConfigRequestHdr);
diff --git a/SecurityPkg/Tcg/TcgDxe/TcgDxe.c b/SecurityPkg/Tcg/TcgDxe/TcgDxe.c index ee6c627..ea4516a 100644 --- a/SecurityPkg/Tcg/TcgDxe/TcgDxe.c +++ b/SecurityPkg/Tcg/TcgDxe/TcgDxe.c @@ -286,7 +286,10 @@ TpmCommHashAll ( CtxSize = Sha1GetContextSize ();
Sha1Ctx = AllocatePool (CtxSize);
- ASSERT (Sha1Ctx != NULL);
+ if (Sha1Ctx == NULL) {
+ ASSERT (Sha1Ctx != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
Sha1Init (Sha1Ctx);
Sha1Update (Sha1Ctx, Data, DataLen);
diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c index 5a23dc5..65b3f81 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c @@ -98,7 +98,11 @@ ExtractFileNameFromDevicePath ( ASSERT (DevicePath != NULL);
- String = DevicePathToStr (DevicePath);
+ String = DevicePathToStr (DevicePath);
+ if (String == NULL) {
+ return NULL;
+ }
+
MatchString = String;
LastMatch = String;
FileName = NULL;
diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c index d262904..e79932d 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c @@ -1095,7 +1095,7 @@ IsSignatureFoundInDatabase ( // Enumerate all signature data in SigDB to check if signature exists for executable.
//
CertList = (EFI_SIGNATURE_LIST *)Data;
- while ((DataSize > 0) && (DataSize >= CertList->SignatureListSize)) {
+ while ((DataSize > 0) && (DataSize >= (UINTN)CertList->SignatureListSize)) {
CertCount = (CertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - CertList->SignatureHeaderSize) / CertList->SignatureSize;
Cert = (EFI_SIGNATURE_DATA *)((UINT8 *)CertList + sizeof (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize);
if ((CertList->SignatureSize == sizeof (EFI_SIGNATURE_DATA) - 1 + SignatureSize) && (CompareGuid (&CertList->SignatureType, &gEfiCertX509Guid))) {
@@ -1173,7 +1173,10 @@ CalculateCertHash ( //
CtxSize = mHash[HashAlg].GetContextSize ();
HashCtx = AllocatePool (CtxSize);
- ASSERT (HashCtx != NULL);
+ if (HashCtx == NULL) {
+ ASSERT (HashCtx != NULL);
+ return FALSE;
+ }
//
// 2. Initialize a hash context.
@@ -1261,7 +1264,7 @@ IsCertHashFoundInDbx ( // Check whether the certificate hash exists in the forbidden database.
//
DbxList = (EFI_SIGNATURE_LIST *)Data;
- while ((DataSize > 0) && (DataSize >= DbxList->SignatureListSize)) {
+ while ((DataSize > 0) && (DataSize >= (UINTN)DbxList->SignatureListSize)) {
//
// Determine Hash Algorithm of Certificate in the forbidden database.
//
@@ -1348,7 +1351,7 @@ GetSignaturelistOffset ( SigList = Database;
SiglistSize = DatabaseSize;
- while ((SiglistSize > 0) && (SiglistSize >= SigList->SignatureListSize)) {
+ while ((SiglistSize > 0) && (SiglistSize >= (UINTN)SigList->SignatureListSize)) {
if (CompareGuid (&SigList->SignatureType, SignatureType)) {
*Offset = DatabaseSize - SiglistSize;
return TRUE;
@@ -1888,7 +1891,10 @@ HashPeImage ( CtxSize = mHash[HashAlg].GetContextSize ();
HashCtx = AllocatePool (CtxSize);
- ASSERT (HashCtx != NULL);
+ if (HashCtx == NULL) {
+ ASSERT (HashCtx != NULL);
+ goto Done;
+ }
// 1. Load the image header into memory.
@@ -2540,7 +2546,7 @@ UpdateDeletePage ( )
{
EFI_STATUS Status;
- UINT32 Index;
+ UINTN Index;
UINTN CertCount;
UINTN GuidIndex;
VOID *StartOpCodeHandle;
@@ -2724,7 +2730,7 @@ DeleteKeyExchangeKey ( UINT8 *Data;
UINT8 *OldData;
UINT32 Attr;
- UINT32 Index;
+ UINTN Index;
EFI_SIGNATURE_LIST *CertList;
EFI_SIGNATURE_LIST *NewCertList;
EFI_SIGNATURE_DATA *Cert;
@@ -2928,7 +2934,7 @@ DeleteSignature ( UINT8 *Data;
UINT8 *OldData;
UINT32 Attr;
- UINT32 Index;
+ UINTN Index;
EFI_SIGNATURE_LIST *CertList;
EFI_SIGNATURE_LIST *NewCertList;
EFI_SIGNATURE_DATA *Cert;
@@ -3206,7 +3212,7 @@ DeleteSignatureEx ( //
// Traverse to target EFI_SIGNATURE_LIST but others will be skipped.
//
- while ((RemainingSize > 0) && (RemainingSize >= ListWalker->SignatureListSize) && ListIndex < PrivateData->ListIndex) {
+ while ((RemainingSize > 0) && (RemainingSize >= (UINTN)ListWalker->SignatureListSize) && ListIndex < PrivateData->ListIndex) {
CopyMem ((UINT8 *)NewVariableData + Offset, ListWalker, ListWalker->SignatureListSize);
Offset += ListWalker->SignatureListSize;
@@ -3513,9 +3519,19 @@ SecureBootExtractConfig ( // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
//
ConfigRequestHdr = HiiConstructConfigHdr (&gSecureBootConfigFormSetGuid, mSecureBootStorageName, PrivateData->DriverHandle);
- Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
- ConfigRequest = AllocateZeroPool (Size);
- ASSERT (ConfigRequest != NULL);
+ if (ConfigRequestHdr == NULL) {
+ ASSERT (ConfigRequestHdr != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
+ ConfigRequest = AllocateZeroPool (Size);
+ if (ConfigRequest == NULL) {
+ ASSERT (ConfigRequest != NULL);
+ FreePool (ConfigRequestHdr);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
AllocatedRequest = TRUE;
UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
FreePool (ConfigRequestHdr);
@@ -3794,7 +3810,7 @@ LoadSignatureList ( RemainingSize = DataSize;
ListWalker = (EFI_SIGNATURE_LIST *)VariableData;
- while ((RemainingSize > 0) && (RemainingSize >= ListWalker->SignatureListSize)) {
+ while ((RemainingSize > 0) && (RemainingSize >= (UINTN)ListWalker->SignatureListSize)) {
if (CompareGuid (&ListWalker->SignatureType, &gEfiCertRsa2048Guid)) {
ListType = STRING_TOKEN (STR_LIST_TYPE_RSA2048_SHA256);
} else if (CompareGuid (&ListWalker->SignatureType, &gEfiCertX509Guid)) {
@@ -4210,7 +4226,7 @@ LoadSignatureData ( VOID *EndOpCodeHandle;
UINTN DataSize;
UINTN RemainingSize;
- UINT16 Index;
+ UINT64 Index;
UINT8 *VariableData;
CHAR16 VariableName[BUFFER_MAX_SIZE];
CHAR16 NameBuffer[BUFFER_MAX_SIZE];
@@ -4294,7 +4310,7 @@ LoadSignatureData ( //
// Skip signature list.
//
- while ((RemainingSize > 0) && (RemainingSize >= ListWalker->SignatureListSize) && ListIndex-- > 0) {
+ while ((RemainingSize > 0) && (RemainingSize >= (UINTN)ListWalker->SignatureListSize) && ListIndex-- > 0) {
RemainingSize -= ListWalker->SignatureListSize;
ListWalker = (EFI_SIGNATURE_LIST *)((UINT8 *)ListWalker + ListWalker->SignatureListSize);
}
diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c index 483fe4d..ae3e943 100644 --- a/ShellPkg/Application/Shell/Shell.c +++ b/ShellPkg/Application/Shell/Shell.c @@ -1262,9 +1262,11 @@ LocateStartupScript ( InternalEfiShellSetEnv (L"homefilesystem", StartupScriptPath, TRUE);
- StartupScriptPath = StrnCatGrow (&StartupScriptPath, &Size, ((FILEPATH_DEVICE_PATH *)FileDevicePath)->PathName, 0);
- PathRemoveLastItem (StartupScriptPath);
- StartupScriptPath = StrnCatGrow (&StartupScriptPath, &Size, mStartupScript, 0);
+ if ((DevicePathType (FileDevicePath) == MEDIA_DEVICE_PATH) && (DevicePathSubType (FileDevicePath) == MEDIA_FILEPATH_DP)) {
+ StartupScriptPath = StrnCatGrow (&StartupScriptPath, &Size, ((FILEPATH_DEVICE_PATH *)FileDevicePath)->PathName, 0);
+ PathRemoveLastItem (StartupScriptPath);
+ StartupScriptPath = StrnCatGrow (&StartupScriptPath, &Size, mStartupScript, 0);
+ }
}
//
diff --git a/ShellPkg/Application/Shell/ShellEnvVar.c b/ShellPkg/Application/Shell/ShellEnvVar.c index b97cfe9..9e84d7f 100644 --- a/ShellPkg/Application/Shell/ShellEnvVar.c +++ b/ShellPkg/Application/Shell/ShellEnvVar.c @@ -285,19 +285,23 @@ SetEnvironmentVariableList ( //
// set all the variables from the list
//
- for ( Node = (ENV_VAR_LIST *)GetFirstNode (ListHead)
- ; !IsNull (ListHead, &Node->Link)
- ; Node = (ENV_VAR_LIST *)GetNextNode (ListHead, &Node->Link)
- )
- {
- Size = StrSize (Node->Val) - sizeof (CHAR16);
- if (Node->Atts & EFI_VARIABLE_NON_VOLATILE) {
- Status = SHELL_SET_ENVIRONMENT_VARIABLE_NV (Node->Key, Size, Node->Val);
- } else {
- Status = SHELL_SET_ENVIRONMENT_VARIABLE_V (Node->Key, Size, Node->Val);
- }
+ if ((ListHead != NULL) && !IsListEmpty (ListHead)) {
+ for ( Node = (ENV_VAR_LIST *)GetFirstNode (ListHead)
+ ; !IsNull (ListHead, &Node->Link)
+ ; Node = (ENV_VAR_LIST *)GetNextNode (ListHead, &Node->Link)
+ )
+ {
+ if ((Node->Key != NULL) && (Node->Val != NULL)) {
+ Size = StrSize (Node->Val) - sizeof (CHAR16);
+ if (Node->Atts & EFI_VARIABLE_NON_VOLATILE) {
+ Status = SHELL_SET_ENVIRONMENT_VARIABLE_NV (Node->Key, Size, Node->Val);
+ } else {
+ Status = SHELL_SET_ENVIRONMENT_VARIABLE_V (Node->Key, Size, Node->Val);
+ }
- ASSERT_EFI_ERROR (Status);
+ ASSERT_EFI_ERROR (Status);
+ }
+ }
}
FreeEnvironmentVariableList (ListHead);
@@ -441,7 +445,7 @@ ShellFindEnvVarInList ( ; Node = (ENV_VAR_LIST *)GetNextNode (&gShellEnvVarList.Link, &Node->Link)
)
{
- if ((Node->Key != NULL) && (StrCmp (Key, Node->Key) == 0)) {
+ if ((Node->Key != NULL) && (StrCmp (Key, Node->Key) == 0) && (Node->Val != NULL)) {
*Value = AllocateCopyPool (StrSize (Node->Val), Node->Val);
*ValueSize = StrSize (Node->Val);
if (Atts != NULL) {
diff --git a/ShellPkg/Application/Shell/ShellProtocol.c b/ShellPkg/Application/Shell/ShellProtocol.c index 3bc6239..646294d 100644 --- a/ShellPkg/Application/Shell/ShellProtocol.c +++ b/ShellPkg/Application/Shell/ShellProtocol.c @@ -2853,7 +2853,11 @@ EfiShellGetEnvEx ( ; Node = (ENV_VAR_LIST *)GetNextNode (&gShellEnvVarList.Link, &Node->Link)
)
{
- ASSERT (Node->Key != NULL);
+ if (Node->Key == NULL) {
+ ASSERT (FALSE);
+ continue;
+ }
+
Size += StrSize (Node->Key);
}
diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c index b0c77e4..44c2ed9 100644 --- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c +++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c @@ -398,7 +398,11 @@ ShellCommandIsCommandOnInternalList ( ; Node = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *)GetNextNode (&mCommandList.Link, &Node->Link)
)
{
- ASSERT (Node->CommandString != NULL);
+ if (Node->CommandString == NULL) {
+ ASSERT (FALSE);
+ continue;
+ }
+
if (gUnicodeCollation->StriColl (
gUnicodeCollation,
(CHAR16 *)CommandString,
@@ -485,7 +489,11 @@ ShellCommandGetInternalCommandHelp ( ; Node = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *)GetNextNode (&mCommandList.Link, &Node->Link)
)
{
- ASSERT (Node->CommandString != NULL);
+ if (Node->CommandString == NULL) {
+ ASSERT (FALSE);
+ continue;
+ }
+
if (gUnicodeCollation->StriColl (
gUnicodeCollation,
(CHAR16 *)CommandString,
@@ -672,23 +680,25 @@ ShellCommandRegisterCommandName ( //
// Get Lexical Comparison Value between PrevCommand and Command list entry
//
- LexicalMatchValue = gUnicodeCollation->StriColl (
- gUnicodeCollation,
- PrevCommand->CommandString,
- Command->CommandString
- );
+ if ((PrevCommand->CommandString != NULL) && (Command->CommandString != NULL)) {
+ LexicalMatchValue = gUnicodeCollation->StriColl (
+ gUnicodeCollation,
+ PrevCommand->CommandString,
+ Command->CommandString
+ );
- //
- // Swap PrevCommand and Command list entry if PrevCommand list entry
- // is alphabetically greater than Command list entry
- //
- if (LexicalMatchValue > 0) {
- Command = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *)SwapListEntries (&PrevCommand->Link, &Command->Link);
- } else if (LexicalMatchValue < 0) {
//
- // PrevCommand entry is lexically lower than Command entry
+ // Swap PrevCommand and Command list entry if PrevCommand list entry
+ // is alphabetically greater than Command list entry
//
- break;
+ if (LexicalMatchValue > 0) {
+ Command = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *)SwapListEntries (&PrevCommand->Link, &Command->Link);
+ } else if (LexicalMatchValue < 0) {
+ //
+ // PrevCommand entry is lexically lower than Command entry
+ //
+ break;
+ }
}
}
@@ -758,7 +768,11 @@ ShellCommandRunCommandHandler ( ; Node = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *)GetNextNode (&mCommandList.Link, &Node->Link)
)
{
- ASSERT (Node->CommandString != NULL);
+ if (Node->CommandString == NULL) {
+ ASSERT (FALSE);
+ continue;
+ }
+
if (gUnicodeCollation->StriColl (
gUnicodeCollation,
(CHAR16 *)CommandString,
@@ -831,7 +845,11 @@ ShellCommandGetManFileNameHandler ( ; Node = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *)GetNextNode (&mCommandList.Link, &Node->Link)
)
{
- ASSERT (Node->CommandString != NULL);
+ if (Node->CommandString == NULL) {
+ ASSERT (FALSE);
+ continue;
+ }
+
if (gUnicodeCollation->StriColl (
gUnicodeCollation,
(CHAR16 *)CommandString,
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c index dd3d7a7..37bccea 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c @@ -491,6 +491,11 @@ ShellCommandRunDmem ( continue;
}
+ if (CompareGuid (&gST->ConfigurationTable[TableWalker].VendorGuid, &gFdtTableGuid)) {
+ DtbTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
+ continue;
+ }
+
if (CompareGuid (&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiMemoryAttributesTableGuid)) {
MemoryAttributesTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
continue;
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c index 42d766e..bf68eb1 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c @@ -3011,7 +3011,7 @@ DisplayMmBankConnections ( //
// Divide it to high and low
//
- High = (UINT8)(BankConnections & 0xF0);
+ High = (UINT8)((BankConnections & 0xF0)>>4);
Low = (UINT8)(BankConnections & 0x0F);
if (High != 0xF) {
if (Low != 0xF) {
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf index 91b48e8..0f4068d 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf @@ -96,6 +96,7 @@ MdePkg/MdePkg.dec
ShellPkg/ShellPkg.dec
MdeModulePkg/MdeModulePkg.dec
+ EmbeddedPkg/EmbeddedPkg.dec
[LibraryClasses]
MemoryAllocationLib
@@ -144,3 +145,4 @@ gEfiConfProfilesUefiSpecGuid ## SOMETIMES_CONSUMES ## GUID
gEfiConfProfilesEbbrSpec21Guid ## SOMETIMES_CONSUMES ## GUID
gEfiConfProfilesEbbrSpec22Guid ## SOMETIMES_CONSUMES ## GUID
+ gFdtTableGuid ## SOMETIMES_CONSUMES ## SystemTable
diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c index 4f39863..3bec32b 100644 --- a/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c +++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c @@ -520,10 +520,6 @@ ShellCommandRunConnect ( }
Handle1 = ConvertHandleIndexToHandle ((UINTN)Intermediate);
- if (EFI_ERROR (Status)) {
- ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"connect", Param1);
- ShellStatus = SHELL_INVALID_PARAMETER;
- }
} else {
Handle1 = NULL;
}
diff --git a/ShellPkg/ShellPkg.ci.yaml b/ShellPkg/ShellPkg.ci.yaml index 2c3a70d..4f5c69d 100644 --- a/ShellPkg/ShellPkg.ci.yaml +++ b/ShellPkg/ShellPkg.ci.yaml @@ -35,6 +35,7 @@ "MdePkg/MdePkg.dec",
"MdeModulePkg/MdeModulePkg.dec",
"ShellPkg/ShellPkg.dec",
+ "EmbeddedPkg/EmbeddedPkg.dec",
"NetworkPkg/NetworkPkg.dec"
],
# For host based unit tests
diff --git a/StandaloneMmPkg/Core/Dispatcher.c b/StandaloneMmPkg/Core/Dispatcher.c index 821d9d6..086532e 100644 --- a/StandaloneMmPkg/Core/Dispatcher.c +++ b/StandaloneMmPkg/Core/Dispatcher.c @@ -143,6 +143,9 @@ MmLoadImage ( UINTN PageCount;
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS DstBuffer;
+ UINTN Index;
+ UINTN StartIndex;
+ CHAR8 EfiFileName[512];
DEBUG ((DEBUG_INFO, "MmLoadImage - %g\n", &DriverEntry->FileName));
@@ -254,11 +257,6 @@ MmLoadImage ( //
// Print the load address and the PDB file name if it is available
//
- DEBUG_CODE_BEGIN ();
-
- UINTN Index;
- UINTN StartIndex;
- CHAR8 EfiFileName[256];
DEBUG ((
DEBUG_INFO | DEBUG_LOAD,
@@ -308,8 +306,6 @@ MmLoadImage ( DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n"));
- DEBUG_CODE_END ();
-
return Status;
}
diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.inf deleted file mode 100644 index d804629..0000000 --- a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.inf +++ /dev/null @@ -1,42 +0,0 @@ -## @file
-# RISC-V CPU Exception Handler Library
-#
-# Copyright (c) 2022-2023, Ventana Micro Systems Inc. All rights reserved.<BR>
-#
-# SPDX-License-Identifier: BSD-2-Clause-Patent
-#
-##
-
-[Defines]
- INF_VERSION = 0x0001001B
- BASE_NAME = BaseRiscV64CpuExceptionHandlerLib
- MODULE_UNI_FILE = BaseRiscV64CpuExceptionHandlerLib.uni
- FILE_GUID = 6AB0D5FD-E615-45A3-9374-E284FB061FC9
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = CpuExceptionHandlerLib
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-# VALID_ARCHITECTURES = RISCV64
-#
-
-[Sources]
- SupervisorTrapHandler.S
- CpuExceptionHandlerLib.c
- CpuExceptionHandlerLib.h
-
-[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- UefiCpuPkg/UefiCpuPkg.dec
-
-[LibraryClasses]
- BaseLib
- SerialPortLib
- PrintLib
- SynchronizationLib
- PeCoffGetEntryPointLib
- MemoryAllocationLib
- DebugLib
diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.uni b/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.uni deleted file mode 100644 index 00cca22..0000000 --- a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.uni +++ /dev/null @@ -1,13 +0,0 @@ -// /** @file
-//
-// Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
-//
-// SPDX-License-Identifier: BSD-2-Clause-Patent
-//
-// **/
-
-
-#string STR_MODULE_ABSTRACT #language en-US "RISC-V CPU Exception Handler Librarys."
-
-#string STR_MODULE_DESCRIPTION #language en-US "RISC-V CPU Exception Handler Librarys."
-
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf index 9fcba00..9e0b54e 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf @@ -19,7 +19,7 @@ #
# The following information is for reference only and not required by the build tools.
#
-# VALID_ARCHITECTURES = IA32 X64 LOONGARCH64
+# VALID_ARCHITECTURES = IA32 X64 LOONGARCH64 RISCV64
#
[Sources.Ia32]
@@ -46,6 +46,14 @@ LoongArch/LoongArch64/ArchExceptionHandler.c
LoongArch/LoongArch64/ExceptionHandlerAsm.S | GCC
+[Sources.RISCV64]
+ RiscV/Backtrace.h
+ RiscV/Backtrace.c
+ RiscV/BacktraceHelper.c
+ RiscV/ExceptionLib.c
+ RiscV/ExceptionHandler.h
+ RiscV/ExceptionHandlerAsm.S | GCC
+
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard
gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList
@@ -75,5 +83,8 @@ [LibraryClasses.LoongArch64]
CpuLib
+[Guids.RISCV64]
+ gEfiDebugImageInfoTableGuid
+
[BuildOptions]
XCODE:*_*_X64_NASM_FLAGS = -D NO_ABSOLUTE_RELOCS_IN_TEXT
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/Backtrace.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/Backtrace.c new file mode 100644 index 0000000..9765d72 --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/Backtrace.c @@ -0,0 +1,175 @@ +/** @file
+ RISC-V backtrace implementation.
+
+ Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+ Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>
+ Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "Backtrace.h"
+
+#define MAX_STACK_FRAME_SIZE SIZE_16KB
+
+STATIC
+INTN
+CheckFpValid (
+ IN UINTN Fp,
+ IN UINTN Sp
+ )
+{
+ UINTN Low, High;
+
+ Low = Sp + 2 * sizeof (UINTN);
+ High = ALIGN_VALUE (Sp, MAX_STACK_FRAME_SIZE);
+
+ return !(Fp < Low || Fp > High || Fp & 0x07);
+}
+
+STATIC
+CONST CHAR8 *
+BaseName (
+ IN CONST CHAR8 *FullName
+ )
+{
+ CONST CHAR8 *Str;
+
+ Str = FullName + AsciiStrLen (FullName);
+
+ while (--Str > FullName) {
+ if ((*Str == '/') || (*Str == '\\')) {
+ return Str + 1;
+ }
+ }
+
+ return Str;
+}
+
+/**
+ Helper for displaying a backtrace.
+
+ @param Regs Pointer to SMODE_TRAP_REGISTERS.
+ @param FirstPdb Pointer to the first symbol file used.
+ @param ListImage If true, only show the full path to symbol file, else
+ show the PC value and its decoded components.
+**/
+STATIC
+VOID
+DumpCpuBacktraceHelper (
+ IN SMODE_TRAP_REGISTERS *Regs,
+ IN CHAR8 *FirstPdb,
+ IN BOOLEAN ListImage
+ )
+{
+ UINTN ImageBase;
+ UINTN PeCoffSizeOfHeader;
+ BOOLEAN IsLeaf;
+ UINTN RootFp;
+ UINTN RootRa;
+ UINTN Sp;
+ UINTN Fp;
+ UINTN Ra;
+ UINTN Idx;
+ CHAR8 *Pdb;
+ CHAR8 *PrevPdb;
+
+ RootRa = Regs->ra;
+ RootFp = Regs->s0;
+
+ Idx = 0;
+ IsLeaf = TRUE;
+ Fp = RootFp;
+ Ra = RootRa;
+ PrevPdb = FirstPdb;
+ while (Fp != 0) {
+ Pdb = GetImageName (Ra, &ImageBase, &PeCoffSizeOfHeader);
+ if (Pdb != NULL) {
+ if (Pdb != PrevPdb) {
+ Idx++;
+ if (ListImage) {
+ DEBUG ((DEBUG_ERROR, "[% 2d] %a\n", Idx, Pdb));
+ }
+
+ PrevPdb = Pdb;
+ }
+
+ if (!ListImage) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "PC 0x%012lx (0x%012lx+0x%08x) [% 2d] %a\n",
+ Ra,
+ ImageBase,
+ Ra - ImageBase,
+ Idx,
+ BaseName (Pdb)
+ ));
+ }
+ } else if (!ListImage) {
+ DEBUG ((DEBUG_ERROR, "PC 0x%012lx\n", Ra));
+ }
+
+ /*
+ * After the prologue, the frame pointer register s0 will point
+ * to the Canonical Frame Address or CFA, which is the stack
+ * pointer value on entry to the current procedure. The previous
+ * frame pointer and return address pair will reside just prior
+ * to the current stack address held in s0. This puts the return
+ * address at s0 - XLEN/8, and the previous frame pointer at
+ * s0 - 2 * XLEN/8.
+ */
+ Sp = Fp;
+ Fp -= sizeof (UINTN) * 2;
+ Ra = *(UINTN *)(Fp + sizeof (UINTN));
+ Fp = *(UINTN *)(Fp);
+ if (IsLeaf && CheckFpValid (Ra, Sp)) {
+ /* We hit function where ra is not saved on the stack */
+ Fp = Ra;
+ Ra = RootRa;
+ }
+
+ IsLeaf = FALSE;
+ }
+}
+
+/**
+ Display a backtrace.
+
+ @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
+**/
+VOID
+EFIAPI
+DumpCpuBacktrace (
+ IN EFI_SYSTEM_CONTEXT SystemContext
+ )
+{
+ SMODE_TRAP_REGISTERS *Regs;
+ CHAR8 *Pdb;
+ UINTN ImageBase;
+ UINTN PeCoffSizeOfHeader;
+
+ Regs = (SMODE_TRAP_REGISTERS *)SystemContext.SystemContextRiscV64;
+ Pdb = GetImageName (Regs->sepc, &ImageBase, &PeCoffSizeOfHeader);
+ if (Pdb != NULL) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "PC 0x%012lx (0x%012lx+0x%08x) [ 0] %a\n",
+ Regs->sepc,
+ ImageBase,
+ Regs->sepc - ImageBase,
+ BaseName (Pdb)
+ ));
+ } else {
+ DEBUG ((DEBUG_ERROR, "PC 0x%012lx\n", Regs->sepc));
+ }
+
+ DumpCpuBacktraceHelper (Regs, Pdb, FALSE);
+
+ if (Pdb != NULL) {
+ DEBUG ((DEBUG_ERROR, "\n[ 0] %a\n", Pdb));
+ }
+
+ DumpCpuBacktraceHelper (Regs, Pdb, TRUE);
+}
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/Backtrace.h b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/Backtrace.h new file mode 100644 index 0000000..6e29b90 --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/Backtrace.h @@ -0,0 +1,57 @@ +/** @file
+
+ RISC-V backtrace definition file.
+
+ Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef BACKTRACE_H_
+#define BACKTRACE_H_
+
+#include <PiPei.h>
+#include <Uefi.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseLib.h>
+#include <Library/PeCoffExtraActionLib.h>
+#include <Library/PeCoffGetEntryPointLib.h>
+#include <Library/UefiLib.h>
+#include <Guid/DebugImageInfoTable.h>
+#include "ExceptionHandler.h"
+
+/**
+ Use the EFI Debug Image Table to lookup the FaultAddress and find which PE/COFF image
+ it came from. As long as the PE/COFF image contains a debug directory entry a
+ string can be returned. For ELF and Mach-O images the string points to the Mach-O or ELF
+ image. Microsoft tools contain a pointer to the PDB file that contains the debug information.
+
+ @param FaultAddress Address to find PE/COFF image for.
+ @param ImageBase Return load address of found image
+ @param PeCoffSizeOfHeaders Return the size of the PE/COFF header for the image that was found
+
+ @retval NULL FaultAddress not in a loaded PE/COFF image.
+ @retval Path and file name of PE/COFF image.
+
+**/
+CHAR8 *
+EFIAPI
+GetImageName (
+ IN UINTN FaultAddress,
+ OUT UINTN *ImageBase,
+ OUT UINTN *PeCoffSizeOfHeaders
+ );
+
+/**
+ Display a backtrace.
+
+ @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
+**/
+VOID
+EFIAPI
+DumpCpuBacktrace (
+ IN EFI_SYSTEM_CONTEXT SystemContext
+ );
+
+#endif // BACKTRACE_H_
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/BacktraceHelper.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/BacktraceHelper.c new file mode 100644 index 0000000..fdc5666 --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/BacktraceHelper.c @@ -0,0 +1,71 @@ +/** @file
+ RISC-V backtrace helper functions.
+
+ Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+ Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>
+ Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "Backtrace.h"
+
+/**
+ Use the EFI Debug Image Table to lookup the FaultAddress and find which PE/COFF image
+ it came from. As long as the PE/COFF image contains a debug directory entry a
+ string can be returned. For ELF and Mach-O images the string points to the Mach-O or ELF
+ image. Microsoft tools contain a pointer to the PDB file that contains the debug information.
+
+ @param FaultAddress Address to find PE/COFF image for.
+ @param ImageBase Return load address of found image
+ @param PeCoffSizeOfHeaders Return the size of the PE/COFF header for the image that was found
+
+ @retval NULL FaultAddress not in a loaded PE/COFF image.
+ @retval Path and file name of PE/COFF image.
+
+**/
+CHAR8 *
+EFIAPI
+GetImageName (
+ IN UINTN FaultAddress,
+ OUT UINTN *ImageBase,
+ OUT UINTN *PeCoffSizeOfHeaders
+ )
+{
+ EFI_STATUS Status;
+ EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *DebugTableHeader;
+ EFI_DEBUG_IMAGE_INFO *DebugTable;
+ UINTN Entry;
+ CHAR8 *Address;
+
+ Status = EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid, (VOID **)&DebugTableHeader);
+ if (EFI_ERROR (Status)) {
+ return NULL;
+ }
+
+ DebugTable = DebugTableHeader->EfiDebugImageInfoTable;
+ if (DebugTable == NULL) {
+ return NULL;
+ }
+
+ Address = (CHAR8 *)(UINTN)FaultAddress;
+ for (Entry = 0; Entry < DebugTableHeader->TableSize; Entry++, DebugTable++) {
+ if (DebugTable->NormalImage != NULL) {
+ if ((DebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) &&
+ (DebugTable->NormalImage->LoadedImageProtocolInstance != NULL))
+ {
+ if ((Address >= (CHAR8 *)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase) &&
+ (Address <= ((CHAR8 *)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase + DebugTable->NormalImage->LoadedImageProtocolInstance->ImageSize)))
+ {
+ *ImageBase = (UINTN)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase;
+ *PeCoffSizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID *)(UINTN)*ImageBase);
+ return PeCoffLoaderGetPdbPointer (DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase);
+ }
+ }
+ }
+ }
+
+ return NULL;
+}
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/BacktraceHelperSec.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/BacktraceHelperSec.c new file mode 100644 index 0000000..10e3497 --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/BacktraceHelperSec.c @@ -0,0 +1,42 @@ +/** @file
+ RISC-V backtrace helper functions for SEC.
+
+ Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "Backtrace.h"
+
+/**
+ Use the EFI Debug Image Table to lookup the FaultAddress and find which PE/COFF image
+ it came from. As long as the PE/COFF image contains a debug directory entry a
+ string can be returned. For ELF and Mach-O images the string points to the Mach-O or ELF
+ image. Microsoft tools contain a pointer to the PDB file that contains the debug information.
+
+ @param FaultAddress Address to find PE/COFF image for.
+ @param ImageBase Return load address of found image
+ @param PeCoffSizeOfHeaders Return the size of the PE/COFF header for the image that was found
+
+ @retval NULL FaultAddress not in a loaded PE/COFF image.
+ @retval Path and file name of PE/COFF image.
+
+**/
+CHAR8 *
+EFIAPI
+GetImageName (
+ IN UINTN FaultAddress,
+ OUT UINTN *ImageBase,
+ OUT UINTN *PeCoffSizeOfHeaders
+ )
+{
+ //
+ // This function is not implemented in SEC phase.
+ // It should be implemented in DXE phase.
+ //
+ *ImageBase = 0;
+ *PeCoffSizeOfHeaders = 0;
+
+ return NULL;
+}
diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandlerLib.h b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/ExceptionHandler.h index 9b7e130..0cf8221 100644 --- a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandlerLib.h +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/ExceptionHandler.h @@ -8,16 +8,16 @@ **/
-#ifndef RISCV_CPU_EXECPTION_HANDLER_LIB_H_
-#define RISCV_CPU_EXECPTION_HANDLER_LIB_H_
+#ifndef EXCEPTION_HANDLER_H_
+#define EXCEPTION_HANDLER_H_
#include <Register/RiscV64/RiscVImpl.h>
/**
Trap Handler for S-mode
-
**/
VOID
+EFIAPI
SupervisorModeTrap (
VOID
);
@@ -108,4 +108,4 @@ typedef struct { } SMODE_TRAP_REGISTERS;
#pragma pack()
-#endif
+#endif /* EXCEPTION_HANDLER_H_ */
diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/SupervisorTrapHandler.S b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/ExceptionHandlerAsm.S index 45070b5..815e28b 100644 --- a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/SupervisorTrapHandler.S +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/ExceptionHandlerAsm.S @@ -8,7 +8,7 @@ **/
#include <Base.h>
-#include "CpuExceptionHandlerLib.h"
+#include "ExceptionHandler.h"
.align 3
.section .entry, "ax", %progbits
diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandlerLib.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/ExceptionLib.c index 73a9dd5..d19c992 100644 --- a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandlerLib.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/ExceptionLib.c @@ -2,6 +2,9 @@ RISC-V Exception Handler library implementation.
Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+ Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>
+ Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -14,7 +17,8 @@ #include <Library/SerialPortLib.h>
#include <Library/PrintLib.h>
#include <Register/RiscV64/RiscVEncoding.h>
-#include "CpuExceptionHandlerLib.h"
+#include "Backtrace.h"
+#include "ExceptionHandler.h"
//
// Define the maximum message length
@@ -136,11 +140,21 @@ DumpCpuContext ( )
{
UINTN Printed;
+ UINTN RecursiveException;
SMODE_TRAP_REGISTERS *Regs;
Printed = 0;
Regs = (SMODE_TRAP_REGISTERS *)SystemContext.SystemContextRiscV64;
+ RecursiveException = RiscVGetSupervisorScratch ();
+ if (RecursiveException == 0xdeaddead) {
+ InternalPrintMessage ("\nRecursive exception occurred while dumping the CPU state\n");
+
+ CpuDeadLoop ();
+ }
+
+ RiscVSetSupervisorScratch ((UINTN)0xdeaddead);
+
InternalPrintMessage (
"!!!! RISCV64 Exception Type - %016x(%a) !!!!\n",
ExceptionType,
@@ -171,6 +185,8 @@ DumpCpuContext ( #undef REG
#undef REGS
+ DumpCpuBacktrace (SystemContext);
+
DEBUG_CODE_END ();
}
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf index 64de252..00a5b49 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf @@ -20,7 +20,7 @@ # The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64
-# VALID_ARCHITECTURES = IA32 X64 LOONGARCH64
+# VALID_ARCHITECTURES = IA32 X64 LOONGARCH64 RISCV64
#
[Sources.Ia32]
@@ -46,6 +46,13 @@ LoongArch/LoongArch64/ArchExceptionHandler.c
LoongArch/LoongArch64/ExceptionHandlerAsm.S | GCC
+[Sources.RISCV64]
+ RiscV/Backtrace.h
+ RiscV/Backtrace.c
+ RiscV/BacktraceHelperSec.c
+ RiscV/ExceptionLib.c
+ RiscV/ExceptionHandler.h
+ RiscV/ExceptionHandlerAsm.S | GCC
[Packages]
MdePkg/MdePkg.dec
diff --git a/UefiCpuPkg/UefiCpuPkg.ci.yaml b/UefiCpuPkg/UefiCpuPkg.ci.yaml index a6fd147..57867dd 100644 --- a/UefiCpuPkg/UefiCpuPkg.ci.yaml +++ b/UefiCpuPkg/UefiCpuPkg.ci.yaml @@ -30,7 +30,6 @@ ],
## Both file path and directory path are accepted.
"IgnoreFiles": [
- "Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandlerLib.h"
]
},
"CompilerPlugin": {
diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index aac4668..e011b18 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -218,7 +218,6 @@ UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerLibUnitTest.inf
[Components.RISCV64]
- UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.inf
UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf
UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.inf
UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf
|