public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ard Biesheuvel" <ard.biesheuvel@arm.com>
To: devel@edk2.groups.io, samer.el-haj-mahmoud@arm.com
Subject: Re: [edk2-devel] [edk2-platform][PATCH v2 1/1] Platforms/RaspberryPi: Add Asset Tag support
Date: Fri, 12 Jun 2020 10:57:11 +0200	[thread overview]
Message-ID: <88ac458d-1f1e-e810-6b46-26d407f05c70@arm.com> (raw)
In-Reply-To: <20200608204114.15240-1-Samer.El-Haj-Mahmoud@arm.com>

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 <samer.el-haj-mahmoud@arm.com>
> Reviewed-by: Andrei Warkentin <andrey.warkentin@gmail.com>

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 <andrey.warkentin@gmail.com>
> + *  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 <andrey.warkentin@gmail.com>
> + *  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.<BR>
>    *  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 <Library/MemoryAllocationLib.h>
>   #include <Library/TimeBaseLib.h>
>   #include <Library/UefiBootServicesTableLib.h>
> +#include <Library/UefiRuntimeServicesTableLib.h>
>   #include <Library/PrintLib.h>
> +#include <ConfigVars.h>
>   
>   #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 <andrey.warkentin@gmail.com>
> + *  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.
>    */
> 


      reply	other threads:[~2020-06-12  8:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-08 20:41 [edk2-platform][PATCH v2 1/1] Platforms/RaspberryPi: Add Asset Tag support Samer El-Haj-Mahmoud
2020-06-12  8:57 ` Ard Biesheuvel [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=88ac458d-1f1e-e810-6b46-26d407f05c70@arm.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox