Skip to content

Commit

Permalink
feat: add uuid generator for smbios type1 table
Browse files Browse the repository at this point in the history
Add a UUID generator for SMBIOS type 1 table.

Signed-off-by: Girish Mahadevan <gmahadevan@nvidia.com>
Tested-by: Jake Garver <jake@nvidia.com>
Reviewed-by: Jake Garver <jake@nvidia.com>
  • Loading branch information
gmahadevan authored and UEFI Builder committed Feb 12, 2025
1 parent d61d9d6 commit 711062e
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 4 deletions.
81 changes: 78 additions & 3 deletions Silicon/NVIDIA/Library/OemMiscLib/OemMiscLib.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file
* OemMiscLib.c
*
* SPDX-FileCopyrightText: Copyright (c) 2021-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-FileCopyrightText: Copyright (c) 2021-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*
Expand All @@ -11,6 +11,7 @@
#include <PiDxe.h>

#include <Library/BaseMemoryLib.h>
#include <Library/BaseCryptLib.h>
#include <Library/DebugLib.h>
#include <Library/HiiLib.h>
#include <Library/MemoryAllocationLib.h>
Expand Down Expand Up @@ -925,9 +926,61 @@ OemGetChassisNumPowerCords (
}
}

/**
CreateUuid5
Creates a version 5 UUID per RFC 9562
@param [in] Namespace
@param [in] Serial Number
@param[out] Uuid
@return EFI_SUCCESS Successful installation
@retval !(EFI_SUCCESS) Other errors
**/
STATIC
EFI_STATUS
CreateUuid5 (
IN CONST EFI_GUID *Namespace,
IN CONST CHAR8 *Name,
OUT GUID *Uuid
)
{
VOID *Sha1Ctx;
UINTN CtxSize;
UINT8 Digest[SHA1_DIGEST_SIZE];

if ((Namespace == NULL) || (Name == NULL) || (Uuid == NULL)) {
return EFI_INVALID_PARAMETER;
}

CtxSize = Sha1GetContextSize ();
Sha1Ctx = AllocatePool (CtxSize);
if (Sha1Ctx == NULL) {
DEBUG ((DEBUG_ERROR, "%a: Failed to allocate memory for SHA1 context\n", __func__));
return EFI_OUT_OF_RESOURCES;
}

Sha1Init (Sha1Ctx);
Sha1Update (Sha1Ctx, Namespace, sizeof (GUID));
Sha1Update (Sha1Ctx, Name, AsciiStrLen (Name));
Sha1Final (Sha1Ctx, Digest);

// Construct the UUID from the hash
CopyMem (Uuid, Digest, sizeof (GUID));
Uuid->Data3 = (Uuid->Data3 & 0x0FFF) | (5 << 12); // Set the version to 5
Uuid->Data4[0] = (Uuid->Data4[0] & 0x3F) | 0x80; // Set the variant to 0b10 per RFC 9562
FreePool (Sha1Ctx);

return EFI_SUCCESS;
}

/**
OemGetSystemUuid
Fetches the system UUID.
Generate the Uuid for SMBIOS Type 1 table. The DynamicTables Pkg SMBIOS generator
will try to fetch the System UUID from BMC for Server systems first before trying
to generate a UUID.
But the OemMiscLib implementation will always generate the UUID.
@param[out] SystemUuid The pointer to the buffer to store the System UUID.
Expand All @@ -938,7 +991,29 @@ OemGetSystemUuid (
OUT GUID *SystemUuid
)
{
CopyGuid (SystemUuid, &gZeroGuid);
EFI_STATUS Status;
CHAR8 *SerialNum;

if (SmEepromData == NULL) {
DEBUG ((
DEBUG_ERROR,
"%a:%d: EepromData is NULL. Can't generate UUID",
__FUNCTION__,
__LINE__
));
return;
}

SerialNum = SmEepromData->SerialNumber;

Status = CreateUuid5 (
&gNVIDIASerialNumberNamespaceGuid,
SerialNum,
SystemUuid
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a %d: Failed to generate UUID %r \n", __FUNCTION__, __LINE__, Status));
}
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Silicon/NVIDIA/Library/OemMiscLib/OemMiscLib.inf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#/** @file
# OemMiscLib.inf
#
# SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-FileCopyrightText: Copyright (c) 2021-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# Copyright (c) 2021, NUVIA Inc. All rights reserved.
# Copyright (c) 2018, Hisilicon Limited. All rights reserved.
# Copyright (c) 2018, Linaro Limited. All rights reserved.
Expand Down Expand Up @@ -30,8 +30,10 @@
NetworkPkg/NetworkPkg.dec
Silicon/NVIDIA/NVIDIA.dec
DynamicTablesPkg/DynamicTablesPkg.dec
CryptoPkg/CryptoPkg.dec

[LibraryClasses]
BaseCryptLib
BaseMemoryLib
DebugLib
HobLib
Expand Down Expand Up @@ -67,6 +69,7 @@
[Guids]
gNVIDIAPlatformResourceDataGuid
gZeroGuid
gNVIDIASerialNumberNamespaceGuid

[Protocols]
gNVIDIATegraCpuFrequencyProtocolGuid
Expand Down
2 changes: 2 additions & 0 deletions Silicon/NVIDIA/NVIDIA.dec
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@
gNVIDIAEndOfPostToBmcGuid = { 0xfb6ed506, 0x0f9c, 0x49e2, { 0x9e, 0xf0, 0xac, 0x91, 0x84, 0x61, 0x50, 0xc2 } }
# L2 Reset Msg to RASFW
gNVIDIAMmRasResetReqGuid = { 0x6a0d9b18, 0x3bb7, 0x45c8, { 0xa3, 0xcd, 0x57, 0x01, 0x05, 0x11, 0xf9, 0xf0 } }
# Namespace GUID used for UUID generation from serial number
gNVIDIASerialNumberNamespaceGuid = { 0x765695f0, 0x9c75, 0x4670, { 0xad, 0x57, 0x6d, 0x3a, 0xf4, 0xd1, 0x88, 0x03 } }

[Protocols]
gNVIDIADeviceTreeCompatibilityProtocolGuid = { 0x1e710608, 0x28a3, 0x4c0b, { 0x9b, 0xec, 0x1c, 0x75, 0x49, 0xa7, 0x0d, 0x90 } }
Expand Down

0 comments on commit 711062e

Please sign in to comment.