From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.15891.1591952236169507876 for ; Fri, 12 Jun 2020 01:57:16 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ard.biesheuvel@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 105411FB; Fri, 12 Jun 2020 01:57:15 -0700 (PDT) Received: from [192.168.1.69] (unknown [10.37.8.184]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3C97C3F73C; Fri, 12 Jun 2020 01:57:14 -0700 (PDT) Subject: Re: [edk2-devel] [edk2-platform][PATCH v2 1/1] Platforms/RaspberryPi: Add Asset Tag support To: devel@edk2.groups.io, samer.el-haj-mahmoud@arm.com References: <20200608204114.15240-1-Samer.El-Haj-Mahmoud@arm.com> From: "Ard Biesheuvel" Message-ID: <88ac458d-1f1e-e810-6b46-26d407f05c70@arm.com> Date: Fri, 12 Jun 2020 10:57:11 +0200 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200608204114.15240-1-Samer.El-Haj-Mahmoud@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit On 6/8/20 10:41 PM, Samer El-Haj-Mahmoud via groups.io wrote: > Add support for configuring the Chassis Asset Tag in the UI as well as > UEFI Shell, and carry the configured value as the Asset Tag string > in SMBIOS Types 2 and 3. > > To configure using the UEFI Shell, use 'setvar' command to read/write > the UEFI variable with GUID = gConfigDxeFormSetGuid and Name="AssetTag". > For example: > > Shell> setvar AssetTag -guid CD7CC258-31DB-22E6-9F22-63B0B8EED6B5 -bs > -rt -nv =L"ABC123" =0x0000 > > This resolves this Github issue: https://github.com/pftf/RPi4/issues/54 > > Signed-off-by: Samer El-Haj-Mahmoud > Reviewed-by: Andrei Warkentin Pushed as 4c8c8868bbdb..6d4fed696d00 Thanks > --- > Platform/RaspberryPi/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.inf | 2 ++ > Platform/RaspberryPi/Include/ConfigVars.h | 7 ++++++ > Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr | 14 +++++++++++ > Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c | 23 ++++++++++++++--- > Platform/RaspberryPi/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c | 26 ++++++++++++++++++-- > Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni | 4 +++ > 6 files changed, 71 insertions(+), 5 deletions(-) > > diff --git a/Platform/RaspberryPi/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.inf b/Platform/RaspberryPi/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.inf > index 1ed6338c69cb..59b2fefdf0fd 100644 > --- a/Platform/RaspberryPi/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.inf > +++ b/Platform/RaspberryPi/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.inf > @@ -43,7 +43,9 @@ [LibraryClasses] > [Protocols] > gEfiSmbiosProtocolGuid # PROTOCOL SOMETIMES_CONSUMED > gRaspberryPiFirmwareProtocolGuid ## CONSUMES > + > [Guids] > + gConfigDxeFormSetGuid > > [Depex] > gEfiSmbiosProtocolGuid AND gRaspberryPiFirmwareProtocolGuid > diff --git a/Platform/RaspberryPi/Include/ConfigVars.h b/Platform/RaspberryPi/Include/ConfigVars.h > index cefddbafcd8f..9e5a69c7a657 100644 > --- a/Platform/RaspberryPi/Include/ConfigVars.h > +++ b/Platform/RaspberryPi/Include/ConfigVars.h > @@ -1,6 +1,7 @@ > /** @file > * > * Copyright (c) 2020, Andrei Warkentin > + * Copyright (c) 2020, ARM Limited. All rights reserved. > * > * SPDX-License-Identifier: BSD-2-Clause-Patent > * > @@ -82,6 +83,12 @@ typedef struct { > UINT32 Mode; > } SYSTEM_TABLE_MODE_VARSTORE_DATA; > > +#define ASSET_TAG_STR_MAX_LEN 32 > +#define ASSET_TAG_STR_STORAGE_SIZE 33 > +typedef struct { > + CHAR16 AssetTag[ASSET_TAG_STR_STORAGE_SIZE]; > +} ADVANCED_ASSET_TAG_VARSTORE_DATA; > + > typedef struct { > /* > * 0 - uSD slot routed to Broadcom SDHOST on Pi 3 or eMMC2 on Pi 4. > diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr > index 72cc90ae0bec..b4b2a3a7abde 100644 > --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr > +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr > @@ -1,6 +1,7 @@ > /** @file > * > * Copyright (c) 2018 Andrei Warkentin > + * Copyright (c) 2020, ARM Limited. All rights reserved. > * > * SPDX-License-Identifier: BSD-2-Clause-Patent > * > @@ -49,6 +50,11 @@ formset > name = SystemTableMode, > guid = CONFIGDXE_FORM_SET_GUID; > > + efivarstore ADVANCED_ASSET_TAG_VARSTORE_DATA, > + attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, > + name = AssetTag, > + guid = CONFIGDXE_FORM_SET_GUID; > + > efivarstore MMC_SD_VARSTORE_DATA, > attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, > name = SdIsArasan, > @@ -172,6 +178,14 @@ formset > option text = STRING_TOKEN(STR_ADVANCED_SYSTAB_BOTH), value = SYSTEM_TABLE_MODE_BOTH, flags = DEFAULT; > option text = STRING_TOKEN(STR_ADVANCED_SYSTAB_DT), value = SYSTEM_TABLE_MODE_DT, flags = DEFAULT; > endoneof; > + > + string varid = AssetTag.AssetTag, > + prompt = STRING_TOKEN(STR_ADVANCED_ASSET_TAG_PROMPT), > + help = STRING_TOKEN(STR_ADVANCED_ASSET_TAG_HELP), > + flags = INTERACTIVE | RESET_REQUIRED, > + minsize = 0, > + maxsize = ASSET_TAG_STR_MAX_LEN, > + endstring; > endform; > > form formid = 0x1003, > diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c > index 52e37ba68ffd..b73dbdcde99d 100644 > --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c > +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c > @@ -186,9 +186,10 @@ SetupVariables ( > VOID > ) > { > - UINTN Size; > - UINT8 Var8; > - UINT32 Var32; > + UINTN Size; > + UINT8 Var8; > + UINT32 Var32; > + CHAR16 AssetTagVar[ASSET_TAG_STR_STORAGE_SIZE] = L""; > EFI_STATUS Status; > > /* > @@ -238,6 +239,22 @@ SetupVariables ( > PcdSet32 (PcdSystemTableMode, PcdGet32 (PcdSystemTableMode)); > } > > + Size = sizeof(AssetTagVar); > + > + Status = gRT->GetVariable(L"AssetTag", > + &gConfigDxeFormSetGuid, > + NULL, &Size, AssetTagVar); > + > + if (EFI_ERROR (Status)) { > + Status = gRT->SetVariable ( > + L"AssetTag", > + &gConfigDxeFormSetGuid, > + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, > + sizeof(AssetTagVar), > + AssetTagVar > + ); > + } > + > Size = sizeof (UINT32); > Status = gRT->GetVariable (L"SdIsArasan", > &gConfigDxeFormSetGuid, > diff --git a/Platform/RaspberryPi/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c b/Platform/RaspberryPi/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c > index 3351fea2ec32..7b86e76a1248 100644 > --- a/Platform/RaspberryPi/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c > +++ b/Platform/RaspberryPi/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c > @@ -20,6 +20,7 @@ > * Copyright (c) 2013, Linaro.org > * Copyright (c) 2012, Apple Inc. All rights reserved.
> * Copyright (c) Microsoft Corporation. All rights reserved. > + * Copyright (c) 2020, ARM Limited. All rights reserved. > * > * SPDX-License-Identifier: BSD-2-Clause-Patent > * > @@ -40,7 +41,9 @@ > #include > #include > #include > +#include > #include > +#include > > #define SMB_IS_DIGIT(c) (((c) >= '0') && ((c) <= '9')) > > @@ -164,7 +167,7 @@ SMBIOS_TABLE_TYPE2 mBoardInfoType2 = { > 2, // ProductName String > 3, // Version String > 4, // SerialNumber String > - 0, // AssetTag String > + 5, // AssetTag String > { // FeatureFlag > 1, // Motherboard :1; > 0, // RequiresDaughterCard :1; > @@ -179,11 +182,15 @@ SMBIOS_TABLE_TYPE2 mBoardInfoType2 = { > 0, // NumberOfContainedObjectHandles; > { 0 } // ContainedObjectHandles[1]; > }; > + > +CHAR8 mChassisAssetTag[128]; > + > CHAR8 *mBoardInfoType2Strings[] = { > mSysInfoManufName, > mSysInfoProductName, > mSysInfoVersionName, > mSysInfoSerial, > + mChassisAssetTag, > NULL > }; > > @@ -196,7 +203,7 @@ SMBIOS_TABLE_TYPE3 mEnclosureInfoType3 = { > MiscChassisEmbeddedPc, // Type; > 2, // Version String > 3, // SerialNumber String > - 0, // AssetTag String > + 4, // AssetTag String > ChassisStateSafe, // BootupState; > ChassisStateSafe, // PowerSupplyState; > ChassisStateSafe, // ThermalState; > @@ -212,6 +219,7 @@ CHAR8 *mEnclosureInfoType3Strings[] = { > mSysInfoManufName, > mSysInfoProductName, > mSysInfoSerial, > + mChassisAssetTag, > NULL > }; > > @@ -760,6 +768,20 @@ BoardInfoUpdateSmbiosType2 ( > VOID > ) > { > + UINTN Size; > + CHAR16 AssetTagVar[ASSET_TAG_STR_STORAGE_SIZE] = L""; > + EFI_STATUS Status; > + > + Size = sizeof(AssetTagVar); > + Status = gRT->GetVariable(L"AssetTag", > + &gConfigDxeFormSetGuid, > + NULL, &Size, AssetTagVar); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Failed to get Asset Tag: %r\n", Status)); > + } > + UnicodeStrToAsciiStrS(AssetTagVar, mChassisAssetTag, sizeof(mChassisAssetTag)); > + DEBUG ((DEBUG_INFO, "System Asset Tag : %a\n", mChassisAssetTag)); > + > LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mBoardInfoType2, mBoardInfoType2Strings, NULL); > } > > diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni > index 7195e497f986..2a468760c6a9 100644 > --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni > +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni > @@ -1,6 +1,7 @@ > /** @file > * > * Copyright (c) 2018, Andrei Warkentin > + * Copyright (c) 2020, ARM Limited. All rights reserved. > * > * SPDX-License-Identifier: BSD-2-Clause-Patent > * > @@ -47,6 +48,9 @@ > #string STR_ADVANCED_SYSTAB_BOTH #language en-US "ACPI + Devicetree" > #string STR_ADVANCED_SYSTAB_DT #language en-US "Devicetree" > > +#string STR_ADVANCED_ASSET_TAG_PROMPT #language en-US "Asset Tag" > +#string STR_ADVANCED_ASSET_TAG_HELP #language en-US "Set the system Asset Tag" > + > /* > * MMC/SD configuration. > */ >