From 7223f4c3ce7c943982fdc14da3bb2c6ac7b5fdc8 Mon Sep 17 00:00:00 2001 From: Nickle Wang Date: Wed, 4 Sep 2024 15:49:17 +0800 Subject: [PATCH 1/5] ManageabilityPkg/PldmSmbiosTransferDxe: fix GCC5 build error Add missing "EFIAPI" to fix GCC5 build failure. Signed-off-by: Nickle Wang --- .../Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Features/ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.c b/Features/ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.c index 81e9adf5713..5cedf1e7664 100644 --- a/Features/ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.c +++ b/Features/ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.c @@ -2,6 +2,7 @@ This file provides edk2 PLDM SMBIOS Transfer Protocol implementation. Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+ Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent @par Revision Reference: @@ -44,6 +45,7 @@ UINT32 SetSmbiosStructureTableHandle; PLDM terminus ID. **/ EFI_STATUS +EFIAPI SetPldmSmbiosTransferTerminusId ( IN UINT8 SourceId, IN UINT8 DestinationId From 6caea43c7532a33a7a701939c29f1e16a44161bc Mon Sep 17 00:00:00 2001 From: Nickle Wang Date: Wed, 4 Sep 2024 15:50:19 +0800 Subject: [PATCH 2/5] ManageabilityPkg/IpmiProtocolSmm: fix build error Add missing PCD: PcdIpmiSsifSmbusSlaveAddr. Signed-off-by: Nickle Wang --- .../Universal/IpmiProtocol/Smm/IpmiProtocolSmm.inf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Features/ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocolSmm.inf b/Features/ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocolSmm.inf index 3b24c13e42a..d3073513713 100644 --- a/Features/ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocolSmm.inf +++ b/Features/ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocolSmm.inf @@ -2,6 +2,7 @@ # IPMI Protocol SMM Driver. # # Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+# Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-2-Clause-Patent ## @@ -47,6 +48,7 @@ [FixedPcd] gEfiMdePkgTokenSpaceGuid.PcdIpmiKcsIoBaseAddress # Used as default KCS I/O base adddress + gEfiMdePkgTokenSpaceGuid.PcdIpmiSsifSmbusSlaveAddr [Depex] TRUE From a2b112e492af3c069c561ffed28dc9067c311ff7 Mon Sep 17 00:00:00 2001 From: Nickle Wang Date: Wed, 4 Sep 2024 16:02:25 +0800 Subject: [PATCH 3/5] ManageabilityPkg/IpmiSmbiosTransferDxe: Add SMBIOS transfer support Adding support to transfer SMBIOS binary blob to the BMC by using the IpmiBlobTransfer protocol. Signed-off-by: Nick Ramirez Co-authored-by: Nickle Wang --- .../ManageabilityPkg/ManageabilityPkg.dec | 9 + .../IpmiSmbiosTransferDxe.c | 318 ++++++++++++++++++ .../IpmiSmbiosTransferDxe.inf | 55 +++ 3 files changed, 382 insertions(+) create mode 100644 Features/ManageabilityPkg/Universal/IpmiSmbiosTransferDxe/IpmiSmbiosTransferDxe.c create mode 100644 Features/ManageabilityPkg/Universal/IpmiSmbiosTransferDxe/IpmiSmbiosTransferDxe.inf diff --git a/Features/ManageabilityPkg/ManageabilityPkg.dec b/Features/ManageabilityPkg/ManageabilityPkg.dec index 78a356c7dcd..203f1fedab2 100644 --- a/Features/ManageabilityPkg/ManageabilityPkg.dec +++ b/Features/ManageabilityPkg/ManageabilityPkg.dec @@ -60,6 +60,9 @@ # Manageability Protocol PLDM gManageabilityProtocolPldmGuid = { 0x3958090D, 0x69DD, 0x4868, { 0x9C, 0x41, 0xC9, 0xAC, 0x31, 0xB5, 0x25, 0xC5 } } + # Manageability variable Guid + gManageabilityVariableGuid = { 0xac4cf43f, 0x3f64, 0x416a, { 0x96, 0x1d, 0x03, 0x1b, 0x53, 0x5b, 0x91, 0x5f } } + [Protocols] gEdkiiPldmProtocolGuid = { 0x60997616, 0xDB70, 0x4B5F, { 0x86, 0xA4, 0x09, 0x58, 0xA3, 0x71, 0x47, 0xB4 } } gEdkiiPldmSmbiosTransferProtocolGuid = { 0xFA431C3C, 0x816B, 0x4B32, { 0xA3, 0xE0, 0xAD, 0x9B, 0x7F, 0x64, 0x27, 0x2E } } @@ -104,9 +107,15 @@ gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxeIpmiFrb|FALSE|BOOLEAN|0x1000000B gManageabilityPkgTokenSpaceGuid.PcdManageabilityPeiIpmiFrb|FALSE|BOOLEAN|0x1000000C gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxeIpmiBmcAcpi|FALSE|BOOLEAN|0x1000000D + gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxeIpmiSmbiosTransferEnable|FALSE|BOOLEAN|0x1000000E [PcdsDynamic, PcdsDynamicEx] gManageabilityPkgTokenSpaceGuid.PcdFRB2EnabledFlag|TRUE|BOOLEAN|0x20000001 ## This is the timeout value in milliseconds, default set to 360 milliseconds # @Prompt IPMI Fault Resilient Booting timeout value in milliseconds. gManageabilityPkgTokenSpaceGuid.PcdFRBTimeoutValue|360|UINT16|0x20000002 + ## The BlobId of SMBIOS Blob in OpenBMC Phosphor Blob Transfer architecture + gManageabilityPkgTokenSpaceGuid.PcdBmcSmbiosBlobTransferId|"/smbios"|VOID*|0x20000003 + ## When this PCD is set to TRUE, IpmiSmbiosTransferDxe only sends SMBIOS table to + # BMC when SMBIOS table is changed. + gManageabilityPkgTokenSpaceGuid.PcdSendSmbiosOnChanged|TRUE|BOOLEAN|0x20000004 diff --git a/Features/ManageabilityPkg/Universal/IpmiSmbiosTransferDxe/IpmiSmbiosTransferDxe.c b/Features/ManageabilityPkg/Universal/IpmiSmbiosTransferDxe/IpmiSmbiosTransferDxe.c new file mode 100644 index 00000000000..a96d9833858 --- /dev/null +++ b/Features/ManageabilityPkg/Universal/IpmiSmbiosTransferDxe/IpmiSmbiosTransferDxe.c @@ -0,0 +1,318 @@ +/** @file + + A driver that sends SMBIOS tables to an OpenBMC receiver + + SPDX-FileCopyrightText: copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define SMBIOS_HASH_VARIABLE L"SmbiosHash" +#define SMBIOS_TRANSFER_DEBUG DEBUG_MANAGEABILITY +#define SMBIOS_EC_DESC_NO_SMBIOS_TABLE "No SMBIOS table installed" +#define SMBIOS_EC_DESC_SMBIOS_TRANSFER_FAILED "Failed to send SMBIOS tables to BMC" +#define SMBIOS_IPMI_COMMIT_RETRY 10 + +/** + This function will calculate smbios hash, compares it with stored + hash, updates UEFI variable if smbios data changed and return status. + + @param[in] SmbiosData The smbios data to detect if changed. + @param[in] SmbiosDataSize The smbios data size. + + @retval TRUE If smbios data changed, otherwise FALSE. +**/ +BOOLEAN +DetectSmbiosChange ( + UINT8 *SmbiosData, + UINT32 SmbiosDataSize + ) +{ + BOOLEAN DeleteVar; + BOOLEAN Response; + UINT8 ComputedHashValue[SHA256_DIGEST_SIZE]; + UINT8 StoredHashValue[SHA256_DIGEST_SIZE]; + UINTN StoredHashValueSize; + EFI_STATUS Status; + + DeleteVar = FALSE; + Response = Sha256HashAll ((VOID *)SmbiosData, SmbiosDataSize, ComputedHashValue); + + if (!Response) { + // Delete the SmbiosHash variable and continue with smbios transfer to BMC + Status = gRT->SetVariable ( + SMBIOS_HASH_VARIABLE, + &gManageabilityVariableGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + 0, + NULL + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to delete UEFI Variable SmbiosHash %r\n", __func__, Status)); + } + + DeleteVar = TRUE; + } else { + StoredHashValueSize = SHA256_DIGEST_SIZE; + // Get the stored smbios data hash + Status = gRT->GetVariable ( + SMBIOS_HASH_VARIABLE, + &gManageabilityVariableGuid, + NULL, + &StoredHashValueSize, + (VOID *)StoredHashValue + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: Failed to get UEFI Variable SmbiosHash %r\n", __func__, Status)); + } else { + // Compare StoredHash with currently ComputedHash + if (StoredHashValueSize != SHA256_DIGEST_SIZE) { + DEBUG ((DEBUG_ERROR, "%a: Invalid Hash Size %u\n", __func__, StoredHashValueSize)); + } + + if (CompareMem (StoredHashValue, ComputedHashValue, SHA256_DIGEST_SIZE) == 0) { + DEBUG ((DEBUG_INFO, "%a: Same Keys , Hash values match\n", __func__)); + return FALSE; + } + } + } + + if (!DeleteVar) { + // + // ComputedHashValue is valid + // store the computed hash and transfer smbios tables if smbios hash variable not found or hash mismatched. + // + Status = gRT->SetVariable ( + SMBIOS_HASH_VARIABLE, + &gManageabilityVariableGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + SHA256_DIGEST_SIZE, + (VOID *)ComputedHashValue + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to set UEFI Variable SmbiosHash %r\n", __func__, Status)); + } + } + + return TRUE; +} + +/** + This function will send all installed SMBIOS tables to the BMC + + @param Event The event of notify protocol. + @param Context Notify event context. +**/ +VOID +EFIAPI +IpmiSmbiosTransferSendTables ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + SMBIOS_TABLE_3_0_ENTRY_POINT *Smbios30Table; + SMBIOS_TABLE_3_0_ENTRY_POINT *Smbios30TableModified; + EDKII_IPMI_BLOB_TRANSFER_PROTOCOL *IpmiBlobTransfer; + UINT16 Index; + UINT16 SessionId; + UINT8 *SendData; + UINT32 SendDataSize; + UINT32 RemainingDataSize; + BOOLEAN SmbiosTransferRequired; + UINTN RetryIndex; + UINT16 BlobState; + + gBS->CloseEvent (Event); + + Status = gBS->LocateProtocol (&gEdkiiIpmiBlobTransferProtocolGuid, NULL, (VOID **)&IpmiBlobTransfer); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: No IpmiBlobTransferProtocol available. Exiting\n", __func__)); + goto ErrorExit; + } + + SmbiosTransferRequired = TRUE; + Smbios30Table = NULL; + Status = EfiGetSystemConfigurationTable (&gEfiSmbios3TableGuid, (VOID **)&Smbios30Table); + if (EFI_ERROR (Status) || (Smbios30Table == NULL)) { + DEBUG ((DEBUG_ERROR, "%a: No SMBIOS Table found: %r\n", __func__, Status)); + REPORT_STATUS_CODE_WITH_EXTENDED_DATA ( + EFI_ERROR_CODE | EFI_ERROR_MAJOR, + EFI_SOFTWARE_EFI_APPLICATION, + SMBIOS_EC_DESC_NO_SMBIOS_TABLE, + sizeof (SMBIOS_EC_DESC_NO_SMBIOS_TABLE) + ); + return; + } + + // + // BMC expects the Smbios Entry Point to point to the address within the binary data sent + // The value is initially pointing to the location in memory where the table lives + // So we will save off that value and then modify the entry point to make the BMC happy + // + Smbios30TableModified = AllocateZeroPool (sizeof (SMBIOS_TABLE_3_0_ENTRY_POINT)); + CopyMem (Smbios30TableModified, Smbios30Table, sizeof (SMBIOS_TABLE_3_0_ENTRY_POINT)); + Smbios30TableModified->TableAddress = sizeof (SMBIOS_TABLE_3_0_ENTRY_POINT); + // + // Fixup checksums in the Entry Point Structure + // + Smbios30TableModified->EntryPointStructureChecksum = 0; + Smbios30TableModified->EntryPointStructureChecksum = + CalculateCheckSum8 ((UINT8 *)Smbios30TableModified, Smbios30TableModified->EntryPointLength); + + SendData = AllocateZeroPool (sizeof (SMBIOS_TABLE_3_0_ENTRY_POINT) + Smbios30Table->TableMaximumSize); + CopyMem (SendData, Smbios30TableModified, sizeof (SMBIOS_TABLE_3_0_ENTRY_POINT)); + CopyMem (SendData + sizeof (SMBIOS_TABLE_3_0_ENTRY_POINT), (UINT8 *)Smbios30Table->TableAddress, Smbios30Table->TableMaximumSize); + SendDataSize = sizeof (SMBIOS_TABLE_3_0_ENTRY_POINT) + Smbios30Table->TableMaximumSize; + RemainingDataSize = SendDataSize; + + if (PcdGetBool (PcdSendSmbiosOnChanged)) { + SmbiosTransferRequired = DetectSmbiosChange (SendData, SendDataSize); + + if (!SmbiosTransferRequired) { + DEBUG ((DEBUG_INFO, "%a: Smbios tables are not changed, skipping transfer to BMC\n", __func__)); + return; + } + } + + DEBUG_CODE_BEGIN (); + DEBUG ((SMBIOS_TRANSFER_DEBUG, "%a: SMBIOS BINARY DATA OUTPUT\n", __func__)); + DEBUG ((SMBIOS_TRANSFER_DEBUG, "%a: Table Address: 0x%x\n", __func__, Smbios30Table->TableAddress)); + DEBUG ((SMBIOS_TRANSFER_DEBUG, "%a: Table Length: %d\n", __func__, Smbios30Table->TableMaximumSize)); + for (Index = 0; Index < SendDataSize; Index++) { + if (((Index % BLOB_MAX_DATA_PER_PACKET) / 2) == 0) { + DEBUG ((SMBIOS_TRANSFER_DEBUG, "\n%04x: ", Index)); + } + + DEBUG ((SMBIOS_TRANSFER_DEBUG, "%02x ", *(SendData + Index))); + } + + DEBUG ((SMBIOS_TRANSFER_DEBUG, "\n")); + DEBUG_CODE_END (); + + Status = IpmiBlobTransfer->BlobOpen ((CHAR8 *)PcdGetPtr (PcdBmcSmbiosBlobTransferId), BLOB_TRANSFER_STAT_OPEN_W, &SessionId); + if (EFI_ERROR (Status)) { + if (Status == EFI_UNSUPPORTED) { + return; + } + + DEBUG ((DEBUG_ERROR, "%a: Unable to open Blob with Id %a: %r\n", __func__, PcdGetPtr (PcdBmcSmbiosBlobTransferId), Status)); + goto ErrorExit; + } + + for (Index = 0; Index < (SendDataSize / BLOB_MAX_DATA_PER_PACKET); Index++) { + Status = IpmiBlobTransfer->BlobWrite (SessionId, Index * BLOB_MAX_DATA_PER_PACKET, SendData, BLOB_MAX_DATA_PER_PACKET); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failure writing to blob: %r\n", __func__, Status)); + goto ErrorExit; + } + + SendData = (UINT8 *)SendData + BLOB_MAX_DATA_PER_PACKET; + RemainingDataSize -= BLOB_MAX_DATA_PER_PACKET; + } + + ASSERT (RemainingDataSize < BLOB_MAX_DATA_PER_PACKET); + if (RemainingDataSize) { + Status = IpmiBlobTransfer->BlobWrite (SessionId, Index * BLOB_MAX_DATA_PER_PACKET, SendData, RemainingDataSize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failure writing final block to blob: %r\n", __func__, Status)); + goto ErrorExit; + } + } + + Status = IpmiBlobTransfer->BlobCommit (SessionId, 0, NULL); + if (EFI_ERROR (Status)) { + // Poll the stat for the blob committed + for (RetryIndex = 0, BlobState = 0; RetryIndex < SMBIOS_IPMI_COMMIT_RETRY; RetryIndex++, BlobState = 0) { + Status = IpmiBlobTransfer->BlobSessionStat (SessionId, &BlobState, NULL, NULL, NULL); + if (!EFI_ERROR (Status)) { + if ((BlobState & BLOB_TRANSFER_STAT_COMMITTED) != 0) { + DEBUG ((DEBUG_INFO, "%a: Blob committed %r\n", __func__)); + break; + } + + if ((BlobState & BLOB_TRANSFER_STAT_COMMIT_ERROR) != 0) { + DEBUG ((DEBUG_ERROR, "%a: Failure sending commit to blob: %r\n", __func__, Status)); + break; + } + } + + MicroSecondDelay (200 * 1000); // 200ms + } + + if ((BlobState & BLOB_TRANSFER_STAT_COMMITTED) == 0) { + DEBUG ((DEBUG_ERROR, "%a: Failure sending commit to blob: %r\n", __func__, Status)); + goto ErrorExit; + } + } + + Status = IpmiBlobTransfer->BlobClose (SessionId); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Sent SMBIOS Tables to BMC: %r\n", __func__, Status)); + goto ErrorExit; + } + + return; + +ErrorExit: + REPORT_STATUS_CODE_WITH_EXTENDED_DATA ( + EFI_ERROR_CODE | EFI_ERROR_MAJOR, + EFI_SOFTWARE_EFI_APPLICATION, + SMBIOS_EC_DESC_SMBIOS_TRANSFER_FAILED, + sizeof (SMBIOS_EC_DESC_SMBIOS_TRANSFER_FAILED) + ); +} + +/** + This is the declaration of an EFI image entry point. This entry point is + the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including + both device drivers and bus drivers. + + @param[in] ImageHandle The firmware allocated handle for the UEFI image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The operation completed successfully. + @retval Others An unexpected error occurred. + +**/ +EFI_STATUS +EFIAPI +IpmiSmbiosTransferEntry ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_EVENT ReadyToBootEvent; + + // + // Register ReadyToBoot event to send the SMBIOS tables once they have all been installed + // + Status = gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + IpmiSmbiosTransferSendTables, + NULL, + &gEfiEventReadyToBootGuid, + &ReadyToBootEvent + ); + + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/Features/ManageabilityPkg/Universal/IpmiSmbiosTransferDxe/IpmiSmbiosTransferDxe.inf b/Features/ManageabilityPkg/Universal/IpmiSmbiosTransferDxe/IpmiSmbiosTransferDxe.inf new file mode 100644 index 00000000000..4b0569e2422 --- /dev/null +++ b/Features/ManageabilityPkg/Universal/IpmiSmbiosTransferDxe/IpmiSmbiosTransferDxe.inf @@ -0,0 +1,55 @@ +## @file +# A simple implementation to transfer SMBIOS tables to a BMC + +# SPDX-FileCopyrightText: copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = IpmiSmbiosTransfer + FILE_GUID = 1e2f6b56-4675-446b-9c0a-1eb66e50c840 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = IpmiSmbiosTransferEntry + +# +# VALID_ARCHITECTURES = IA32 X64 EBC AARCH64 +# + +[Sources] + IpmiSmbiosTransferDxe.c + +[LibraryClasses] + BaseCryptLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + ReportStatusCodeLib + TimerLib + UefiBootServicesTableLib + UefiRuntimeServicesTableLib + UefiLib + UefiDriverEntryPoint + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + CryptoPkg/CryptoPkg.dec + ManageabilityPkg/ManageabilityPkg.dec + +[Pcd] + gManageabilityPkgTokenSpaceGuid.PcdBmcSmbiosBlobTransferId + gManageabilityPkgTokenSpaceGuid.PcdSendSmbiosOnChanged + +[Guids] + gEfiSmbios3TableGuid ## CONSUMES ## SystemTable + gEfiEventReadyToBootGuid ## CONSUMES ## Event + gManageabilityVariableGuid ## CONSUMES ## Variable + +[Protocols] + gEdkiiIpmiBlobTransferProtocolGuid ## CONSUMES + +[Depex] + gEdkiiIpmiBlobTransferProtocolGuid From f423d1c0e64d33a3da30abbdd282a5bf89e7e370 Mon Sep 17 00:00:00 2001 From: Nickle Wang Date: Mon, 21 Oct 2024 15:18:35 +0800 Subject: [PATCH 4/5] ManageabilityPkg: add IpmiSmbiosTransferDxe Add IpmiSmbiosTransferDxe to ManageabilityPkg. Signed-off-by: Nickle Wang --- Features/ManageabilityPkg/Include/Manageability.dsc | 4 ++++ Features/ManageabilityPkg/Include/PostMemory.fdf | 5 +++++ Features/ManageabilityPkg/ManageabilityPkg.dsc | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/Features/ManageabilityPkg/Include/Manageability.dsc b/Features/ManageabilityPkg/Include/Manageability.dsc index aae343a7330..aba4d10e81a 100644 --- a/Features/ManageabilityPkg/Include/Manageability.dsc +++ b/Features/ManageabilityPkg/Include/Manageability.dsc @@ -41,6 +41,10 @@ ManageabilityPkg/Universal/IpmiBlobTransferDxe/IpmiBlobTransferDxe.inf !endif +!if gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxeIpmiSmbiosTransferEnable == TRUE + ManageabilityPkg/Universal/IpmiSmbiosTransferDxe/IpmiSmbiosTransferDxe.inf +!endif + [Components.X64] !if gManageabilityPkgTokenSpaceGuid.PcdManageabilitySmmIpmiEnable == TRUE ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocolSmm.inf diff --git a/Features/ManageabilityPkg/Include/PostMemory.fdf b/Features/ManageabilityPkg/Include/PostMemory.fdf index 8afd8bde89b..e2ed1ce0932 100644 --- a/Features/ManageabilityPkg/Include/PostMemory.fdf +++ b/Features/ManageabilityPkg/Include/PostMemory.fdf @@ -3,6 +3,7 @@ # volume description. # # Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+# Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -19,6 +20,10 @@ INF ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocolDxe.inf !endif +!if gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxeIpmiSmbiosTransferEnable == TRUE + INF ManageabilityPkg/Universal/IpmiSmbiosTransferDxe/IpmiSmbiosTransferDxe.inf +!endif + !if gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxePldmSmbiosTransferEnable == TRUE INF ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.inf !endif diff --git a/Features/ManageabilityPkg/ManageabilityPkg.dsc b/Features/ManageabilityPkg/ManageabilityPkg.dsc index 4d421a8850e..8472c7d0f0f 100644 --- a/Features/ManageabilityPkg/ManageabilityPkg.dsc +++ b/Features/ManageabilityPkg/ManageabilityPkg.dsc @@ -5,6 +5,7 @@ # # Copyright (C) 2023-2024 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2024, Ampere Computing LLC. All rights reserved.
+# Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -37,6 +38,7 @@ gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxeIpmiFrb |TRUE gManageabilityPkgTokenSpaceGuid.PcdManageabilityPeiIpmiFrb |TRUE gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxeIpmiBmcAcpi |TRUE + gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxeIpmiSmbiosTransferEnable|TRUE [Components] ManageabilityPkg/Library/PlatformBmcReadyLibNull/PlatformBmcReadyLibNull.inf @@ -88,6 +90,11 @@ ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf + OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf + IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf + TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf + RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf [LibraryClasses.common.DXE_SMM_DRIVER] SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableLib.inf From b6392852c20ad65abd11d5bd057ba9f7afb930fb Mon Sep 17 00:00:00 2001 From: Nickle Wang Date: Thu, 24 Oct 2024 14:42:19 +0800 Subject: [PATCH 5/5] ManageabilityPkg/IpmiBlobTransferDxe: response data is optional While calling IpmiBlobTransferSendIpmi(), it is expected that there is no response data for certain command. Enhance this function to accept NULL response data parameter. Signed-off-by: Nickle Wang --- .../IpmiBlobTransferDxe/IpmiBlobTransferDxe.c | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/Features/ManageabilityPkg/Universal/IpmiBlobTransferDxe/IpmiBlobTransferDxe.c b/Features/ManageabilityPkg/Universal/IpmiBlobTransferDxe/IpmiBlobTransferDxe.c index dc3934cd7c9..a909d1f74e7 100644 --- a/Features/ManageabilityPkg/Universal/IpmiBlobTransferDxe/IpmiBlobTransferDxe.c +++ b/Features/ManageabilityPkg/Universal/IpmiBlobTransferDxe/IpmiBlobTransferDxe.c @@ -74,14 +74,15 @@ CalculateCrc16Ccitt ( /** This function does blob transfer over IPMI command. - @param[in] SubCommand The specific sub-command to be executed as part of - the blob transfer operation. - @param[in] SendData A pointer to the data buffer that contains the data to be sent. - When SendDataSize is zero, SendData is not used. - @param[in] SendDataSize The size of the data to be sent, in bytes. This is optional. - @param[out] ResponseData A pointer to the buffer where the response data will be stored. - @param[out] ResponseDataSize A pointer to a variable that will hold the size of the response - data received. + @param[in] SubCommand The specific sub-command to be executed as part of + the blob transfer operation. + @param[in] SendData A pointer to the data buffer that contains the data to be sent. + When SendDataSize is zero, SendData is not used. + @param[in] SendDataSize The size of the data to be sent, in bytes. This is optional. + @param[out] ResponseData A pointer to the buffer where the response data will be stored. + @param[in,out] ResponseDataSize A pointer to a variable that will hold the size of the response + data received. When ResponseDataSize is zero, ResponseData is + not used. @retval EFI_SUCCESS Successfully sends blob data. @retval EFI_OUT_OF_RESOURCES Memory allocation fails. @@ -92,11 +93,11 @@ CalculateCrc16Ccitt ( **/ EFI_STATUS IpmiBlobTransferSendIpmi ( - IN UINT8 SubCommand, - IN UINT8 *SendData OPTIONAL, - IN UINT32 SendDataSize OPTIONAL, - OUT UINT8 *ResponseData, - OUT UINT32 *ResponseDataSize + IN UINT8 SubCommand, + IN UINT8 *SendData OPTIONAL, + IN UINT32 SendDataSize OPTIONAL, + OUT UINT8 *ResponseData OPTIONAL, + IN OUT UINT32 *ResponseDataSize ) { EFI_STATUS Status; @@ -110,7 +111,7 @@ IpmiBlobTransferSendIpmi ( UINT32 IpmiResponseDataSize; IPMI_BLOB_TRANSFER_HEADER Header; - if (((SendDataSize > 0) && (SendData == NULL)) || (ResponseData == NULL) || (ResponseDataSize == NULL)) { + if (((SendDataSize > 0) && (SendData == NULL)) || ((ResponseData == NULL) && (((ResponseDataSize != NULL) && (*ResponseDataSize > 0))))) { return EFI_INVALID_PARAMETER; } @@ -161,12 +162,12 @@ IpmiBlobTransferSendIpmi ( DEBUG ((BLOB_TRANSFER_DEBUG, "\n")); DEBUG_CODE_END (); - IpmiResponseDataSize = (*ResponseDataSize + PROTOCOL_RESPONSE_OVERHEAD); + IpmiResponseDataSize = PROTOCOL_RESPONSE_OVERHEAD; // // If expecting data to be returned, we have to also account for the 16 bit CRC // - if (*ResponseDataSize) { - IpmiResponseDataSize += sizeof (Crc); + if ((ResponseDataSize != NULL) && (*ResponseDataSize > 0)) { + IpmiResponseDataSize += (*ResponseDataSize + sizeof (Crc)); } IpmiResponseData = AllocateZeroPool (IpmiResponseDataSize); @@ -225,7 +226,10 @@ IpmiBlobTransferSendIpmi ( // In this case, there was no response data sent. This is not an error. // Some messages do not require a response. // - *ResponseDataSize = 0; + if (ResponseDataSize != NULL) { + *ResponseDataSize = 0; + } + FreePool (IpmiResponseData); return Status; // Now we need to validate the CRC then send the Response body back @@ -239,8 +243,11 @@ IpmiBlobTransferSendIpmi ( IpmiResponseDataSize -= sizeof (Crc); if (Crc == CalculateCrc16Ccitt (ModifiedResponseData, IpmiResponseDataSize)) { - CopyMem (ResponseData, ModifiedResponseData, IpmiResponseDataSize); - CopyMem (ResponseDataSize, &IpmiResponseDataSize, sizeof (IpmiResponseDataSize)); + if ((ResponseData != NULL) && (ResponseDataSize != NULL)) { + CopyMem (ResponseData, ModifiedResponseData, IpmiResponseDataSize); + CopyMem (ResponseDataSize, &IpmiResponseDataSize, sizeof (IpmiResponseDataSize)); + } + FreePool (IpmiResponseData); return EFI_SUCCESS; } else {