From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=david.wei@intel.com; receiver=edk2-devel@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 9ECB4203B8CE8 for ; Mon, 21 May 2018 18:12:05 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 May 2018 18:12:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,428,1520924400"; d="scan'208";a="57899209" Received: from unknown (HELO zwei4-MOBL1.ccr.corp.intel.com) ([10.239.193.66]) by orsmga001.jf.intel.com with ESMTP; 21 May 2018 18:12:04 -0700 From: zwei4 To: edk2-devel@lists.01.org Date: Tue, 22 May 2018 09:11:59 +0800 Message-Id: <20180522011159.16468-1-david.wei@intel.com> X-Mailer: git-send-email 2.14.1.windows.1 Subject: [Patch][edk2-platforms/devel-MinnowBoard3-UDK2017] Initialize SerialNumber of SMBIOS Type 1 Table. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 May 2018 01:12:05 -0000 Get NIC MAC address and fill it into SerialNumber field of SMBIOS Type 1 Table. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: zwei4 --- .../SmBiosMiscDxe/MiscBaseBoardManufacturer.uni | Bin 2448 -> 2430 bytes .../SmBiosMiscDxe/MiscChassisManufacturer.uni | Bin 1990 -> 1892 bytes .../SmBiosMiscDxe/MiscSystemManufacturer.uni | Bin 3406 -> 3438 bytes .../SmBiosMiscDxe/MiscSystemManufacturerFunction.c | 230 ++++++++++++++++++--- .../Smbios/SmBiosMiscDxe/SmBiosMiscDxe.inf | 4 +- .../Common/PlatformSettings/PlatformDxe/Platform.c | 4 +- 6 files changed, 207 insertions(+), 31 deletions(-) diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Smbios/SmBiosMiscDxe/MiscBaseBoardManufacturer.uni b/Platform/BroxtonPlatformPkg/Common/Features/Smbios/SmBiosMiscDxe/MiscBaseBoardManufacturer.uni index e53c866ce87e1aeef7f60321f975f2ac2b5c809d..4bb96b13a67a808ebba0000620e5ad979c92d765 100644 GIT binary patch delta 96 zcmbOr{7-1Y6h@1UQ|GfxzQiWQoyw5MkiwA9P{g1#c_WMMRR910 delta 180 zcmew-G(mX66h^a+Q|Gg=Ix@I0cus!E8oqfQYXOsH2tz)D0z(o*Dv(TL$YjU?!c>M7 ouvjIK^k>jxa0OytpcebdWgKoK>JZ^{Ga=dz1|`+83CvRbMQ1@lXWXJ=;e1>wM g+I)sYh9ZU(pq?-WV<3raLZtwl$DqW(%fQ6|042l}VgLXD delta 203 zcmaFDcZ`2RAEVjEennQz5QcmP1%@PsR3Mqgkjan(gsBWEV6jRd>Cd3Y;0naPlW((G ePyWJcM}iJ(wn`FI-)5^cAlfwyN({UVTnqr(bS7c| diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Smbios/SmBiosMiscDxe/MiscSystemManufacturer.uni b/Platform/BroxtonPlatformPkg/Common/Features/Smbios/SmBiosMiscDxe/MiscSystemManufacturer.uni index da8647f6c7d31b1388c601885014a9dea40065b7..3567f72b9cfcec53748b4d5f82560a4a17ba9120 100644 GIT binary patch delta 167 zcmX>n^-gNS3Py{KE2pw3`!ZxQ7OMo3 a{tS8yu0ZTNIg! + Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -22,7 +22,176 @@ #include #include #include +#include +#include +#include +/** + Return the description for network boot device. + + @param Handle Controller handle. + + @return The description string. +**/ +CHAR16 * +GetNetworkDescription ( + IN EFI_HANDLE Handle + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + MAC_ADDR_DEVICE_PATH *Mac; + VLAN_DEVICE_PATH *Vlan; + EFI_DEVICE_PATH_PROTOCOL *Ip; + EFI_DEVICE_PATH_PROTOCOL *Uri; + CHAR16 *Description; + UINTN DescriptionSize; + + Status = gBS->OpenProtocol ( + Handle, + &gEfiLoadFileProtocolGuid, + NULL, + gImageHandle, + Handle, + EFI_OPEN_PROTOCOL_TEST_PROTOCOL + ); + if (EFI_ERROR (Status)) { + return NULL; + } + + Status = gBS->OpenProtocol ( + Handle, + &gEfiDevicePathProtocolGuid, + (VOID **) &DevicePath, + gImageHandle, + Handle, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status) || (DevicePath == NULL)) { + return NULL; + } + + // + // The PXE device path is like: + // ....../Mac(...)[/Vlan(...)][/Wi-Fi(...)] + // ....../Mac(...)[/Vlan(...)][/Wi-Fi(...)]/IPv4(...) + // ....../Mac(...)[/Vlan(...)][/Wi-Fi(...)]/IPv6(...) + // + // The HTTP device path is like: + // ....../Mac(...)[/Vlan(...)][/Wi-Fi(...)]/IPv4(...)/Uri(...) + // ....../Mac(...)[/Vlan(...)][/Wi-Fi(...)]/IPv6(...)/Uri(...) + // + while (!IsDevicePathEnd (DevicePath) && + ((DevicePathType (DevicePath) != MESSAGING_DEVICE_PATH) || + (DevicePathSubType (DevicePath) != MSG_MAC_ADDR_DP)) + ) { + DevicePath = NextDevicePathNode (DevicePath); + } + + if (IsDevicePathEnd (DevicePath)) { + return NULL; + } + + Mac = (MAC_ADDR_DEVICE_PATH *) DevicePath; + DevicePath = NextDevicePathNode (DevicePath); + + // + // Locate the optional Vlan node + // + if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) && + (DevicePathSubType (DevicePath) == MSG_VLAN_DP) + ) { + Vlan = (VLAN_DEVICE_PATH *) DevicePath; + DevicePath = NextDevicePathNode (DevicePath); + } else { + Vlan = NULL; + } + + // + // Skip the optional Wi-Fi node + // + if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) && + (DevicePathSubType (DevicePath) == MSG_WIFI_DP) + ) { + DevicePath = NextDevicePathNode (DevicePath); + } + + // + // Locate the IP node + // + if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) && + ((DevicePathSubType (DevicePath) == MSG_IPv4_DP) || + (DevicePathSubType (DevicePath) == MSG_IPv6_DP)) + ) { + Ip = DevicePath; + DevicePath = NextDevicePathNode (DevicePath); + } else { + Ip = NULL; + } + + // + // Locate the URI node + // + if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) && + (DevicePathSubType (DevicePath) == MSG_URI_DP) + ) { + Uri = DevicePath; + DevicePath = NextDevicePathNode (DevicePath); + } else { + Uri = NULL; + } + + // + // Build description like below: + // "PXEv6 (MAC:112233445566 VLAN1)" + // "HTTPv4 (MAC:112233445566)" + // + DescriptionSize = sizeof (L"112233445566"); + Description = AllocatePool (DescriptionSize); + ASSERT (Description != NULL); + UnicodeSPrint ( + Description, DescriptionSize, + L"%02x%02x%02x%02x%02x%02x", + Mac->MacAddress.Addr[0], Mac->MacAddress.Addr[1], Mac->MacAddress.Addr[2], + Mac->MacAddress.Addr[3], Mac->MacAddress.Addr[4], Mac->MacAddress.Addr[5] + ); + return Description; +} + +CHAR16 * +GetMacAddressString( + ) +{ + EFI_HANDLE *Handles; + UINTN HandleCount; + UINT8 Index; + CHAR16 *MacAddressString = NULL; + + // + // Parse load file protocol + // + gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiLoadFileProtocolGuid, + NULL, + &HandleCount, + &Handles + ); + for (Index = 0; Index < HandleCount; Index++) { + + MacAddressString = GetNetworkDescription (Handles[Index]); + + if (MacAddressString != NULL) { + break; + } + } + + if (HandleCount != 0) { + FreePool (Handles); + } + + return MacAddressString; +} /** Publish the smbios type 1. @@ -61,10 +230,16 @@ AddSmbiosManuCallback ( EFI_SMBIOS_PROTOCOL *Smbios; CHAR16 Buffer[40]; CHAR16 PlatformNameBuffer[40]; + CHAR16 SerialNumberBuffer[sizeof (L"112233445566")]; EFI_PEI_HOB_POINTERS GuidHob; GET_BOARD_NAME GetBoardNameFunc; EFI_PLATFORM_INFO_HOB *PlatformInfo = NULL; + CHAR16 *MacAddressString = NULL; + STATIC BOOLEAN mType1Installed = FALSE; + if (mType1Installed == TRUE) { + return; + } GuidHob.Raw = GetHobList (); if (GuidHob.Raw != NULL) { @@ -177,6 +352,11 @@ AddSmbiosManuCallback ( return; } + MacAddressString = GetMacAddressString(); + if ( MacAddressString != NULL) { + UnicodeSPrint (SerialNumberBuffer, sizeof (L"112233445566"), L"%s", GetMacAddressString()); + HiiSetString (mHiiHandle, STRING_TOKEN (STR_MISC_SYSTEM_SERIAL_NUMBER), SerialNumberBuffer, NULL); + } TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SERIAL_NUMBER); SerialNumber = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL); SerialNumStrLen = StrLen (SerialNumber); @@ -236,9 +416,16 @@ AddSmbiosManuCallback ( // // Unique UUID // - ForType1InputData->SystemUuid.Data1 = PcdGet32 (PcdProductSerialNumber); - ForType1InputData->SystemUuid.Data4[0] = PcdGet8 (PcdEmmcManufacturerId); - + //ForType1InputData->SystemUuid.Data1 = PcdGet32 (PcdProductSerialNumber); + //ForType1InputData->SystemUuid.Data4[0] = PcdGet8 (PcdEmmcManufacturerId); + ForType1InputData->SystemUuid.Data1 = (UINT32)MacAddressString [0] + (((UINT32)MacAddressString [1]) << 16); + ForType1InputData->SystemUuid.Data2 = (UINT16)MacAddressString [2]; + ForType1InputData->SystemUuid.Data3 = (UINT16)MacAddressString [3]; + ForType1InputData->SystemUuid.Data4[0] = (UINT8)MacAddressString [4]; + ForType1InputData->SystemUuid.Data4[1] = (UINT8)(MacAddressString [4] >> 8); + ForType1InputData->SystemUuid.Data4[2] = (UINT8)MacAddressString [5]; + ForType1InputData->SystemUuid.Data4[3] = (UINT8)(MacAddressString [5] >> 8); + CopyMem ((UINT8 *) (&SmbiosRecord->Uuid),&ForType1InputData->SystemUuid,16); SmbiosRecord->WakeUpType = (UINT8) ForType1InputData->SystemWakeupType; @@ -262,6 +449,9 @@ AddSmbiosManuCallback ( (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord ); FreePool (SmbiosRecord); + + mType1Installed = TRUE; + return; } @@ -279,9 +469,8 @@ AddSmbiosManuCallback ( **/ MISC_SMBIOS_TABLE_FUNCTION(MiscSystemManufacturer) { - EFI_STATUS Status; + EFI_STATUS Status = EFI_SUCCESS; static BOOLEAN CallbackIsInstalledManu = FALSE; - VOID *AddSmbiosManuCallbackNotifyReg; EFI_EVENT AddSmbiosManuCallbackEvent; @@ -289,32 +478,17 @@ MISC_SMBIOS_TABLE_FUNCTION(MiscSystemManufacturer) CallbackIsInstalledManu = TRUE; // Prevent more than 1 callback. DEBUG ((EFI_D_INFO, "Create Smbios Manu callback.\n")); - // - // gEfiDxeSmmReadyToLockProtocolGuid is ready - // - Status = gBS->CreateEvent ( - EVT_NOTIFY_SIGNAL, - TPL_CALLBACK, - AddSmbiosManuCallback, - RecordData, - &AddSmbiosManuCallbackEvent - ); - - ASSERT_EFI_ERROR (Status); - if (EFI_ERROR (Status)) { - return Status; - } - Status = gBS->RegisterProtocolNotify ( - &gEfiDxeSmmReadyToLockProtocolGuid, - AddSmbiosManuCallbackEvent, - &AddSmbiosManuCallbackNotifyReg - ); + Status = EfiCreateEventReadyToBootEx ( + TPL_CALLBACK, + (EFI_EVENT_NOTIFY)AddSmbiosManuCallback, + RecordData, + &AddSmbiosManuCallbackEvent + ); - return Status; } - return EFI_SUCCESS; + return Status; } diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Smbios/SmBiosMiscDxe/SmBiosMiscDxe.inf b/Platform/BroxtonPlatformPkg/Common/Features/Smbios/SmBiosMiscDxe/SmBiosMiscDxe.inf index 12ffea3c90..31fd8406b2 100644 --- a/Platform/BroxtonPlatformPkg/Common/Features/Smbios/SmBiosMiscDxe/SmBiosMiscDxe.inf +++ b/Platform/BroxtonPlatformPkg/Common/Features/Smbios/SmBiosMiscDxe/SmBiosMiscDxe.inf @@ -1,7 +1,7 @@ ## @file # Component name for module MiscSubclass. # -# Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
+# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License @@ -129,6 +129,8 @@ gEfiMpServiceProtocolGuid gMemInfoProtocolGuid gCpuInfoProtocolGuid + gEfiLoadFileProtocolGuid + gEfiDevicePathProtocolGuid [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareReleaseDateString diff --git a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/Platform.c b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/Platform.c index b03f825f89..712d5cd14f 100644 --- a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/Platform.c +++ b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/Platform.c @@ -699,7 +699,7 @@ InitializePlatform ( EFI_HOB_GUID_TYPE *FdoEnabledGuidHob = NULL; EFI_PLATFORM_INFO_HOB *PlatformInfoHob; EFI_PEI_HOB_POINTERS Hob; - EFI_EVENT EfiShellEvent = NULL; + EFI_EVENT EfiShellEvent = NULL; VOID *mEfiShellProtocolRegistration; mImageHandle = ImageHandle; @@ -916,7 +916,7 @@ InitializePlatform ( EfiShellEvent, &mEfiShellProtocolRegistration ); - } + } return EFI_SUCCESS; } -- 2.14.1.windows.1