[edk2] [Patch][edk2-platforms/devel-MinnowBoard3-UDK2017] Initialize SerialNumber of SMBIOS Type 1 Table.

zwei4 posted 1 patch 5 years, 11 months ago
Failed in applying to current master (apply log)
ePyWJcM}iJ(wn`FI-)5^cAlfwyN({UVTnqr(bS7c|
[edk2] [Patch][edk2-platforms/devel-MinnowBoard3-UDK2017] Initialize SerialNumber of SMBIOS Type 1 Table.
Posted by zwei4 5 years, 11 months ago
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 <david.wei@intel.com>
---
 .../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_WMM<Q_JO%@bG)n1GUEtYHks
YP~i*?H#8A3POu0cSPcU&0~Z(r0G&S>RR910

delta 180
zcmew-G(mX66h^a+Q|Gg=Ix@I0cus!E8oqfQYXOsH2tz)D0z(o*Dv(TL$YjU?!c>M7
ouvjIK^k>jxa0OytpcebdWgKoK>JZ^{Ga=dz1|<ew1}-oL0Jq&EyZ`_I

diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Smbios/SmBiosMiscDxe/MiscChassisManufacturer.uni b/Platform/BroxtonPlatformPkg/Common/Features/Smbios/SmBiosMiscDxe/MiscChassisManufacturer.uni
index 8fc00a7beafefa077b932cd2d125b90d349e5c74..fa5f62764f00e5efff56faeaa86c45ec5ca7f458 100644
GIT binary patch
delta 109
zcmX@c|AcQsAEU*_ennPJHwH%rCk6!u$H}tn){{lp>`+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`!ZxQ<N;wmLpehdkW6GKVn|_7U<hMK1&XEsMT#aDa+pt6
zV3(L&!^5$87V8OCV_ceyff{{*T2dHF8FGLIC@{D&I5Ic^X-BXjhqzr79T`f1Dsq8h
dt_;QumJ9|!sK5{mR9ysgN-9G!SY;Z|3jkrKCO7~9

delta 123
zcmaDSbxvx+3P!VyE2pxsIx@I0cy3N)m1oloVaR7tU`S#}1(InDnG88Vn97g>7OMo3
a{tS8yu0ZTNIg!<T@+)o^5_PokyZ`{~K^qeQ

diff --git a/Platform/BroxtonPlatformPkg/Common/Features/Smbios/SmBiosMiscDxe/MiscSystemManufacturerFunction.c b/Platform/BroxtonPlatformPkg/Common/Features/Smbios/SmBiosMiscDxe/MiscSystemManufacturerFunction.c
index 1878ce5742..0000e123b1 100644
--- a/Platform/BroxtonPlatformPkg/Common/Features/Smbios/SmBiosMiscDxe/MiscSystemManufacturerFunction.c
+++ b/Platform/BroxtonPlatformPkg/Common/Features/Smbios/SmBiosMiscDxe/MiscSystemManufacturerFunction.c
@@ -2,7 +2,7 @@
   This driver parses the mMiscSubclassDataTable structure and reports
   any generated data.
 
-  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
@@ -22,7 +22,176 @@
 #include <BoardFunctionsDxe.h>
 #include <Library/HobLib.h>
 #include <Guid/PlatformInfo.h>
+#include <IndustryStandard/Emmc.h>
+#include <Protocol/SdMmcPassThru.h>
+#include <Protocol/DevicePath.h>
 
+/**
+  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.<BR>
+#  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
@@ -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

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel