* [edk2-platforms PATCH 0/2] Platform/RPi3: PlatformSmbios improvements @ 2019-09-04 12:14 Pete Batard 2019-09-04 12:14 ` [edk2-platforms PATCH 1/2] Platform/RPi3: Add more query functions in RpiFirmwareDxe Pete Batard 2019-09-04 12:14 ` [edk2-platforms PATCH 2/2] Platform/RPi3: Improve the population of PlatformSmbiosDxe elements Pete Batard 0 siblings, 2 replies; 5+ messages in thread From: Pete Batard @ 2019-09-04 12:14 UTC (permalink / raw) To: devel; +Cc: ard.biesheuvel, leif.lindholm This series of patches improves the data reported by the firmware for SMB queries. This is achieved by first introducing new calls in RpiFirmwareDxe and then cleaning up the existing PlatformSmbiosDxe code. These modifications should ensure that the drivers can be reused on other Raspberry Pi platforms (such as the Pi 4). It should be noted that, with these changes, if one passes a build option like --pcd gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString=L"UEFI Firmware v1.7" the BIOS major and minor will be populated from that version data. Attached below is the report from dmidecode on Linux/Debian for a Raspberry Pi 3 B+ using a firmware with the above. Similar data can also be obtained through smbiosview in the UEFI Shell. Regards, /Pete ---------------------------------------------------------------------------------- root@pi3:~# dmidecode # dmidecode 3.2 Getting SMBIOS data from sysfs. SMBIOS 3.2.0 present. Table at 0x37260000. Handle 0x0000, DMI type 0, 26 bytes BIOS Information Vendor: TianoCore Version: UEFI Firmware v1.7 Release Date: Sep 3 2019 19:44:54 ROM Size: 2048 kB Characteristics: Selectable boot is supported ACPI is supported Function key-initiated network boot is supported Targeted content distribution is supported UEFI is supported BIOS Revision: 1.7 Firmware Revision: 85.210 Handle 0x0001, DMI type 1, 27 bytes System Information Manufacturer: Sony UK Product Name: Raspberry Pi 3 Model B+ Version: A020D3 Serial Number: 0000B827EB123456 UUID: 00a020d3-0000-0000-0000-b827eb123456 Wake-up Type: Power Switch SKU Number: 0000000000A020D3 Family: Raspberry Pi Handle 0x0002, DMI type 2, 17 bytes Base Board Information Manufacturer: Sony UK Product Name: Raspberry Pi 3 Model B+ Version: A020D3 Serial Number: 0000B827EB123456 Asset Tag: Not Specified Features: Board is a hosting board Location In Chassis: Not Specified Chassis Handle: 0x0000 Type: Motherboard Contained Object Handles: 0 Handle 0x0003, DMI type 3, 24 bytes Chassis Information Manufacturer: Sony UK Type: Embedded PC Lock: Not Present Version: Raspberry Pi 3 Model B+ Serial Number: 0000B827EB123456 Asset Tag: Not Specified Boot-up State: Safe Power Supply State: Safe Thermal State: Safe Security Status: None OEM Information: 0x00000000 Height: Unspecified Number Of Power Cords: Unspecified Contained Elements: 0 SKU Number: Not Specified Handle 0x0004, DMI type 4, 48 bytes Processor Information Socket Designation: Socket Type: Central Processor Family: ARM Manufacturer: Broadcom ID: 00 00 00 00 00 00 00 00 Version: BCM2837 (ARM Cortex-A53) Voltage: 5.0 V 3.3 V 2.9 V External Clock: Unknown Max Speed: 1400 MHz Current Speed: 600 MHz Status: Populated, Enabled Upgrade: Other L1 Cache Handle: 0x0000 L2 Cache Handle: 0x0000 L3 Cache Handle: 0x0000 Serial Number: Not Specified Asset Tag: Not Specified Part Number: Not Specified Core Count: 4 Core Enabled: 4 Thread Count: 4 Characteristics: 64-bit capable Multi-Core Execute Protection Enhanced Virtualization Handle 0x0005, DMI type 7, 27 bytes Cache Information Socket Designation: Cache1 Configuration: Enabled, Socketed, Level 3 Operational Mode: Write Back Location: Internal Installed Size: 0 kB Maximum Size: 0 kB Supported SRAM Types: Burst Synchronous Installed SRAM Type: Burst Synchronous Speed: Unknown Error Correction Type: Multi-bit ECC System Type: Unknown Associativity: 2-way Set-associative Handle 0x0006, DMI type 9, 24 bytes System Slot Information Designation: SD Card Type: Other Current Usage: Available Length: Other Characteristics: Unknown Bus Address: 0000:00:00.0 Handle 0x0007, DMI type 16, 23 bytes Physical Memory Array Location: System Board Or Motherboard Use: System Memory Error Correction Type: Unknown Maximum Capacity: 1 TB Error Information Handle: Not Provided Number Of Devices: 1 Handle 0x0008, DMI type 17, 84 bytes Memory Device Array Handle: 0x0007 Error Information Handle: Not Provided Total Width: Unknown Data Width: Unknown Size: 1024 MB Form Factor: Unknown Set: Unknown Locator: OS Virtual Memory Bank Locator: malloc Type: DRAM Type Detail: Unknown Speed: Unknown Manufacturer: OSV Serial Number: Not Specified Asset Tag: Not Specified Part Number: Not Specified Rank: Unknown Configured Memory Speed: Unknown Minimum Voltage: Unknown Maximum Voltage: Unknown Configured Voltage: Unknown Memory Technology: <OUT OF SPEC> Memory Operating Mode Capability: None Firmware Version: Not Specified Module Manufacturer ID: Unknown Module Product ID: Unknown Memory Subsystem Controller Manufacturer ID: Unknown Memory Subsystem Controller Product ID: Unknown Non-Volatile Size: None Volatile Size: None Cache Size: None Logical Size: None Handle 0x0009, DMI type 19, 31 bytes Memory Array Mapped Address Starting Address: 0x00000000000 Ending Address: 0x0003B3FFFFF Range Size: 948 MB Physical Array Handle: 0x0000 Partition Width: 1 Handle 0x000A, DMI type 32, 11 bytes System Boot Information Status: No errors detected Handle 0xFEFF, DMI type 127, 4 bytes End Of Table ---------------------------------------------------------------------------------- Pete Batard (2): Platform/RPi3: Add more query functions in RpiFirmwareDxe Platform/RPi3: Improve the population of PlatformSmbiosDxe elements Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c | 193 ++++++++++++-------- Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.inf | 1 + Platform/RaspberryPi/RPi3/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c | 166 ++++++++++++++++- Platform/RaspberryPi/RPi3/Include/Protocol/RpiFirmware.h | 58 ++++-- Platform/RaspberryPi/RPi3/RPi3.dsc | 2 +- 5 files changed, 322 insertions(+), 98 deletions(-) -- 2.21.0.windows.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [edk2-platforms PATCH 1/2] Platform/RPi3: Add more query functions in RpiFirmwareDxe 2019-09-04 12:14 [edk2-platforms PATCH 0/2] Platform/RPi3: PlatformSmbios improvements Pete Batard @ 2019-09-04 12:14 ` Pete Batard 2019-09-27 18:34 ` Leif Lindholm 2019-09-04 12:14 ` [edk2-platforms PATCH 2/2] Platform/RPi3: Improve the population of PlatformSmbiosDxe elements Pete Batard 1 sibling, 1 reply; 5+ messages in thread From: Pete Batard @ 2019-09-04 12:14 UTC (permalink / raw) To: devel; +Cc: ard.biesheuvel, leif.lindholm This patch introduces the capability to also query the Model Name/ Manufacturer Name/CPU Name/Firmware Revision using the RpiFirmware protocol. This is aims at making the driver more suitable to cater for platforms other than the Raspberry Pi 3 as well as simplifying the population of entries in PlatformSmbiosDxe. Also fixes a typo where "%s" was used instead of "%a" and improves RpiFirmwareGetSerial() to derive a serial from the the MAC address in case the platform returns 0 for the serial. Signed-off-by: Pete Batard <pete@akeo.ie> --- Platform/RaspberryPi/RPi3/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c | 166 +++++++++++++++++++- Platform/RaspberryPi/RPi3/Include/Protocol/RpiFirmware.h | 58 +++++-- 2 files changed, 205 insertions(+), 19 deletions(-) diff --git a/Platform/RaspberryPi/RPi3/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c b/Platform/RaspberryPi/RPi3/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c index 9b5ee1946279..c2344252d2c0 100644 --- a/Platform/RaspberryPi/RPi3/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c +++ b/Platform/RaspberryPi/RPi3/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c @@ -219,7 +219,7 @@ RpiFirmwareSetPowerState ( if (!EFI_ERROR (Status) && PowerState ^ (Cmd->TagBody.PowerState & RPI_MBOX_POWER_STATE_ENABLE)) { - DEBUG ((DEBUG_ERROR, "%a: failed to %sable power for device %d\n", + DEBUG ((DEBUG_ERROR, "%a: failed to %aable power for device %d\n", __FUNCTION__, PowerState ? "en" : "dis", DeviceId)); Status = EFI_DEVICE_ERROR; } @@ -393,7 +393,14 @@ RpiFirmwareGetSerial ( } *Serial = Cmd->TagBody.Serial; - return EFI_SUCCESS; + // Some platforms return 0 for serial. For those, try to use the MAC address. + if (*Serial == 0) { + Status = RpiFirmwareGetMacAddress ((UINT8*) Serial); + // Convert to a more user-friendly value + *Serial = SwapBytes64 (*Serial << 16); + } + + return Status; } #pragma pack() @@ -461,7 +468,7 @@ typedef struct { RPI_FW_TAG_HEAD TagHead; RPI_FW_MODEL_REVISION_TAG TagBody; UINT32 EndTag; -} RPI_FW_GET_MODEL_REVISION_CMD; +} RPI_FW_GET_REVISION_CMD; #pragma pack() STATIC @@ -471,7 +478,7 @@ RpiFirmwareGetModelRevision ( OUT UINT32 *Revision ) { - RPI_FW_GET_MODEL_REVISION_CMD *Cmd; + RPI_FW_GET_REVISION_CMD *Cmd; EFI_STATUS Status; UINT32 Result; @@ -506,6 +513,153 @@ RpiFirmwareGetModelRevision ( return EFI_SUCCESS; } +STATIC +EFI_STATUS +EFIAPI +RpiFirmwareGetFirmwareRevision ( + OUT UINT32 *Revision + ) +{ + RPI_FW_GET_REVISION_CMD *Cmd; + EFI_STATUS Status; + UINT32 Result; + + if (!AcquireSpinLockOrFail (&mMailboxLock)) { + DEBUG ((DEBUG_ERROR, "%a: failed to acquire spinlock\n", __FUNCTION__)); + return EFI_DEVICE_ERROR; + } + + Cmd = mDmaBuffer; + ZeroMem (Cmd, sizeof (*Cmd)); + + Cmd->BufferHead.BufferSize = sizeof (*Cmd); + Cmd->BufferHead.Response = 0; + Cmd->TagHead.TagId = RPI_MBOX_GET_REVISION; + Cmd->TagHead.TagSize = sizeof (Cmd->TagBody); + Cmd->TagHead.TagValueSize = 0; + Cmd->EndTag = 0; + + Status = MailboxTransaction (Cmd->BufferHead.BufferSize, RPI_MBOX_VC_CHANNEL, &Result); + + ReleaseSpinLock (&mMailboxLock); + + if (EFI_ERROR (Status) || + Cmd->BufferHead.Response != RPI_MBOX_RESP_SUCCESS) { + DEBUG ((DEBUG_ERROR, + "%a: mailbox transaction error: Status == %r, Response == 0x%x\n", + __FUNCTION__, Status, Cmd->BufferHead.Response)); + return EFI_DEVICE_ERROR; + } + + *Revision = Cmd->TagBody.Revision; + return EFI_SUCCESS; +} + +STATIC +CHAR8* +EFIAPI +RpiFirmwareGetModelName ( + IN INTN ModelId + ) +{ + UINT32 Revision; + + // If a negative ModelId is passed, detect it. + if ((ModelId < 0) && (RpiFirmwareGetModelRevision (&Revision) == EFI_SUCCESS)) + ModelId = (Revision >> 4) & 0xFF; + + switch (ModelId) { + // www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md + case 0x00: + return "Raspberry Pi Model A"; + case 0x01: + return "Raspberry Pi Model B"; + case 0x02: + return "Raspberry Pi Model A+"; + case 0x03: + return "Raspberry Pi Model B+"; + case 0x04: + return "Raspberry Pi 2 Model B"; + case 0x06: + return "Raspberry Pi Compute Module 1"; + case 0x08: + return "Raspberry Pi 3 Model B"; + case 0x09: + return "Raspberry Pi Zero"; + case 0x0A: + return "Raspberry Pi Compute Module 3"; + case 0x0C: + return "Raspberry Pi Zero W"; + case 0x0D: + return "Raspberry Pi 3 Model B+"; + case 0x0E: + return "Raspberry Pi 3 Model A+"; + case 0x11: + return "Raspberry Pi 4 Model B"; + default: + return "Unknown Raspberry Pi Model"; + } +} + +STATIC +CHAR8* +EFIAPI +RpiFirmwareGetManufacturerName ( + IN INTN ManufacturerId + ) +{ + UINT32 Revision; + + // If a negative ModelId is passed, detect it. + if ((ManufacturerId < 0) && (RpiFirmwareGetModelRevision (&Revision) == EFI_SUCCESS)) + ManufacturerId = (Revision >> 16) & 0x0F; + + switch (ManufacturerId) { + // www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md + case 0x00: + return "Sony UK"; + case 0x01: + return "Egoman"; + case 0x02: + case 0x04: + return "Embest"; + case 0x03: + return "Sony Japan"; + case 0x05: + return "Stadium"; + default: + return "Unknown Manufacturer"; + } +} + +STATIC +CHAR8* +EFIAPI +RpiFirmwareGetCpuName ( + IN INTN CpuId + ) +{ + UINT32 Revision; + + // If a negative CpuId is passed, detect it. + if ((CpuId < 0) && (RpiFirmwareGetModelRevision (&Revision) == EFI_SUCCESS)) + CpuId = (Revision >> 12) & 0x0F; + + switch (CpuId) { + // www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md + case 0x00: + return "BCM2835 (ARM11)"; + case 0x01: + return "BCM2836 (ARM Cortex-A7)"; + case 0x02: + return "BCM2837 (ARM Cortex-A53)"; + case 0x03: + return "BCM2711 (ARM Cortex-A72)"; + default: + return "Unknown CPU Model"; + } +} + #pragma pack() typedef struct { UINT32 Width; @@ -1009,6 +1163,10 @@ STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL mRpiFirmwareProtocol = { RpiFirmwareGetSerial, RpiFirmwareGetModel, RpiFirmwareGetModelRevision, + RpiFirmwareGetModelName, + RpiFirmwareGetFirmwareRevision, + RpiFirmwareGetManufacturerName, + RpiFirmwareGetCpuName, RpiFirmwareGetArmMemory }; diff --git a/Platform/RaspberryPi/RPi3/Include/Protocol/RpiFirmware.h b/Platform/RaspberryPi/RPi3/Include/Protocol/RpiFirmware.h index ec70f28efe1a..e49d6e6132d9 100644 --- a/Platform/RaspberryPi/RPi3/Include/Protocol/RpiFirmware.h +++ b/Platform/RaspberryPi/RPi3/Include/Protocol/RpiFirmware.h @@ -96,6 +96,30 @@ EFI_STATUS UINT32 *Revision ); +typedef +CHAR8* +(EFIAPI *GET_MODEL_NAME) ( + INTN ModelId + ); + +typedef +EFI_STATUS +(EFIAPI *GET_FIRMWARE_REVISION) ( + UINT32 *Revision + ); + +typedef +CHAR8* +(EFIAPI *GET_MANUFACTURER_NAME) ( + INTN ManufacturerId + ); + +typedef +CHAR8* +(EFIAPI *GET_CPU_NAME) ( + INTN CpuId + ); + typedef EFI_STATUS (EFIAPI *GET_ARM_MEM) ( @@ -104,21 +128,25 @@ EFI_STATUS ); typedef struct { - SET_POWER_STATE SetPowerState; - GET_MAC_ADDRESS GetMacAddress; - GET_COMMAND_LINE GetCommandLine; - GET_CLOCK_RATE GetClockRate; - GET_CLOCK_RATE GetMaxClockRate; - GET_CLOCK_RATE GetMinClockRate; - SET_CLOCK_RATE SetClockRate; - GET_FB GetFB; - FREE_FB FreeFB; - GET_FB_SIZE GetFBSize; - SET_LED SetLed; - GET_SERIAL GetSerial; - GET_MODEL GetModel; - GET_MODEL_REVISION GetModelRevision; - GET_ARM_MEM GetArmMem; + SET_POWER_STATE SetPowerState; + GET_MAC_ADDRESS GetMacAddress; + GET_COMMAND_LINE GetCommandLine; + GET_CLOCK_RATE GetClockRate; + GET_CLOCK_RATE GetMaxClockRate; + GET_CLOCK_RATE GetMinClockRate; + SET_CLOCK_RATE SetClockRate; + GET_FB GetFB; + FREE_FB FreeFB; + GET_FB_SIZE GetFBSize; + SET_LED SetLed; + GET_SERIAL GetSerial; + GET_MODEL GetModel; + GET_MODEL_REVISION GetModelRevision; + GET_MODEL_NAME GetModelName; + GET_FIRMWARE_REVISION GetFirmwareRevision; + GET_MANUFACTURER_NAME GetManufacturerName; + GET_CPU_NAME GetCpuName; + GET_ARM_MEM GetArmMem; } RASPBERRY_PI_FIRMWARE_PROTOCOL; extern EFI_GUID gRaspberryPiFirmwareProtocolGuid; -- 2.21.0.windows.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [edk2-platforms PATCH 1/2] Platform/RPi3: Add more query functions in RpiFirmwareDxe 2019-09-04 12:14 ` [edk2-platforms PATCH 1/2] Platform/RPi3: Add more query functions in RpiFirmwareDxe Pete Batard @ 2019-09-27 18:34 ` Leif Lindholm 0 siblings, 0 replies; 5+ messages in thread From: Leif Lindholm @ 2019-09-27 18:34 UTC (permalink / raw) To: Pete Batard; +Cc: devel, ard.biesheuvel On Wed, Sep 04, 2019 at 01:14:17PM +0100, Pete Batard wrote: > This patch introduces the capability to also query the Model Name/ > Manufacturer Name/CPU Name/Firmware Revision using the RpiFirmware > protocol. This is aims at making the driver more suitable to cater > for platforms other than the Raspberry Pi 3 as well as simplifying > the population of entries in PlatformSmbiosDxe. > > Also fixes a typo where "%s" was used instead of "%a" and improves > RpiFirmwareGetSerial() to derive a serial from the the MAC address > in case the platform returns 0 for the serial. Can you please break those bits out into separate patches? (The word "also" in a commit message is a good harbinger of commit splitting.) Also (sorry), could you spell out "serial number" in the commit message? No other issues with the code. Best Regards, Leif > Signed-off-by: Pete Batard <pete@akeo.ie> > --- > Platform/RaspberryPi/RPi3/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c | 166 +++++++++++++++++++- > Platform/RaspberryPi/RPi3/Include/Protocol/RpiFirmware.h | 58 +++++-- > 2 files changed, 205 insertions(+), 19 deletions(-) > > diff --git a/Platform/RaspberryPi/RPi3/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c b/Platform/RaspberryPi/RPi3/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c > index 9b5ee1946279..c2344252d2c0 100644 > --- a/Platform/RaspberryPi/RPi3/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c > +++ b/Platform/RaspberryPi/RPi3/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c > @@ -219,7 +219,7 @@ RpiFirmwareSetPowerState ( > > if (!EFI_ERROR (Status) && > PowerState ^ (Cmd->TagBody.PowerState & RPI_MBOX_POWER_STATE_ENABLE)) { > - DEBUG ((DEBUG_ERROR, "%a: failed to %sable power for device %d\n", > + DEBUG ((DEBUG_ERROR, "%a: failed to %aable power for device %d\n", > __FUNCTION__, PowerState ? "en" : "dis", DeviceId)); > Status = EFI_DEVICE_ERROR; > } > @@ -393,7 +393,14 @@ RpiFirmwareGetSerial ( > } > > *Serial = Cmd->TagBody.Serial; > - return EFI_SUCCESS; > + // Some platforms return 0 for serial. For those, try to use the MAC address. > + if (*Serial == 0) { > + Status = RpiFirmwareGetMacAddress ((UINT8*) Serial); > + // Convert to a more user-friendly value > + *Serial = SwapBytes64 (*Serial << 16); > + } > + > + return Status; > } > > #pragma pack() > @@ -461,7 +468,7 @@ typedef struct { > RPI_FW_TAG_HEAD TagHead; > RPI_FW_MODEL_REVISION_TAG TagBody; > UINT32 EndTag; > -} RPI_FW_GET_MODEL_REVISION_CMD; > +} RPI_FW_GET_REVISION_CMD; > #pragma pack() > > STATIC > @@ -471,7 +478,7 @@ RpiFirmwareGetModelRevision ( > OUT UINT32 *Revision > ) > { > - RPI_FW_GET_MODEL_REVISION_CMD *Cmd; > + RPI_FW_GET_REVISION_CMD *Cmd; > EFI_STATUS Status; > UINT32 Result; > > @@ -506,6 +513,153 @@ RpiFirmwareGetModelRevision ( > return EFI_SUCCESS; > } > > +STATIC > +EFI_STATUS > +EFIAPI > +RpiFirmwareGetFirmwareRevision ( > + OUT UINT32 *Revision > + ) > +{ > + RPI_FW_GET_REVISION_CMD *Cmd; > + EFI_STATUS Status; > + UINT32 Result; > + > + if (!AcquireSpinLockOrFail (&mMailboxLock)) { > + DEBUG ((DEBUG_ERROR, "%a: failed to acquire spinlock\n", __FUNCTION__)); > + return EFI_DEVICE_ERROR; > + } > + > + Cmd = mDmaBuffer; > + ZeroMem (Cmd, sizeof (*Cmd)); > + > + Cmd->BufferHead.BufferSize = sizeof (*Cmd); > + Cmd->BufferHead.Response = 0; > + Cmd->TagHead.TagId = RPI_MBOX_GET_REVISION; > + Cmd->TagHead.TagSize = sizeof (Cmd->TagBody); > + Cmd->TagHead.TagValueSize = 0; > + Cmd->EndTag = 0; > + > + Status = MailboxTransaction (Cmd->BufferHead.BufferSize, RPI_MBOX_VC_CHANNEL, &Result); > + > + ReleaseSpinLock (&mMailboxLock); > + > + if (EFI_ERROR (Status) || > + Cmd->BufferHead.Response != RPI_MBOX_RESP_SUCCESS) { > + DEBUG ((DEBUG_ERROR, > + "%a: mailbox transaction error: Status == %r, Response == 0x%x\n", > + __FUNCTION__, Status, Cmd->BufferHead.Response)); > + return EFI_DEVICE_ERROR; > + } > + > + *Revision = Cmd->TagBody.Revision; > + return EFI_SUCCESS; > +} > + > +STATIC > +CHAR8* > +EFIAPI > +RpiFirmwareGetModelName ( > + IN INTN ModelId > + ) > +{ > + UINT32 Revision; > + > + // If a negative ModelId is passed, detect it. > + if ((ModelId < 0) && (RpiFirmwareGetModelRevision (&Revision) == EFI_SUCCESS)) > + ModelId = (Revision >> 4) & 0xFF; > + > + switch (ModelId) { > + // www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md > + case 0x00: > + return "Raspberry Pi Model A"; > + case 0x01: > + return "Raspberry Pi Model B"; > + case 0x02: > + return "Raspberry Pi Model A+"; > + case 0x03: > + return "Raspberry Pi Model B+"; > + case 0x04: > + return "Raspberry Pi 2 Model B"; > + case 0x06: > + return "Raspberry Pi Compute Module 1"; > + case 0x08: > + return "Raspberry Pi 3 Model B"; > + case 0x09: > + return "Raspberry Pi Zero"; > + case 0x0A: > + return "Raspberry Pi Compute Module 3"; > + case 0x0C: > + return "Raspberry Pi Zero W"; > + case 0x0D: > + return "Raspberry Pi 3 Model B+"; > + case 0x0E: > + return "Raspberry Pi 3 Model A+"; > + case 0x11: > + return "Raspberry Pi 4 Model B"; > + default: > + return "Unknown Raspberry Pi Model"; > + } > +} > + > +STATIC > +CHAR8* > +EFIAPI > +RpiFirmwareGetManufacturerName ( > + IN INTN ManufacturerId > + ) > +{ > + UINT32 Revision; > + > + // If a negative ModelId is passed, detect it. > + if ((ManufacturerId < 0) && (RpiFirmwareGetModelRevision (&Revision) == EFI_SUCCESS)) > + ManufacturerId = (Revision >> 16) & 0x0F; > + > + switch (ManufacturerId) { > + // www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md > + case 0x00: > + return "Sony UK"; > + case 0x01: > + return "Egoman"; > + case 0x02: > + case 0x04: > + return "Embest"; > + case 0x03: > + return "Sony Japan"; > + case 0x05: > + return "Stadium"; > + default: > + return "Unknown Manufacturer"; > + } > +} > + > +STATIC > +CHAR8* > +EFIAPI > +RpiFirmwareGetCpuName ( > + IN INTN CpuId > + ) > +{ > + UINT32 Revision; > + > + // If a negative CpuId is passed, detect it. > + if ((CpuId < 0) && (RpiFirmwareGetModelRevision (&Revision) == EFI_SUCCESS)) > + CpuId = (Revision >> 12) & 0x0F; > + > + switch (CpuId) { > + // www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md > + case 0x00: > + return "BCM2835 (ARM11)"; > + case 0x01: > + return "BCM2836 (ARM Cortex-A7)"; > + case 0x02: > + return "BCM2837 (ARM Cortex-A53)"; > + case 0x03: > + return "BCM2711 (ARM Cortex-A72)"; > + default: > + return "Unknown CPU Model"; > + } > +} > + > #pragma pack() > typedef struct { > UINT32 Width; > @@ -1009,6 +1163,10 @@ STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL mRpiFirmwareProtocol = { > RpiFirmwareGetSerial, > RpiFirmwareGetModel, > RpiFirmwareGetModelRevision, > + RpiFirmwareGetModelName, > + RpiFirmwareGetFirmwareRevision, > + RpiFirmwareGetManufacturerName, > + RpiFirmwareGetCpuName, > RpiFirmwareGetArmMemory > }; > > diff --git a/Platform/RaspberryPi/RPi3/Include/Protocol/RpiFirmware.h b/Platform/RaspberryPi/RPi3/Include/Protocol/RpiFirmware.h > index ec70f28efe1a..e49d6e6132d9 100644 > --- a/Platform/RaspberryPi/RPi3/Include/Protocol/RpiFirmware.h > +++ b/Platform/RaspberryPi/RPi3/Include/Protocol/RpiFirmware.h > @@ -96,6 +96,30 @@ EFI_STATUS > UINT32 *Revision > ); > > +typedef > +CHAR8* > +(EFIAPI *GET_MODEL_NAME) ( > + INTN ModelId > + ); > + > +typedef > +EFI_STATUS > +(EFIAPI *GET_FIRMWARE_REVISION) ( > + UINT32 *Revision > + ); > + > +typedef > +CHAR8* > +(EFIAPI *GET_MANUFACTURER_NAME) ( > + INTN ManufacturerId > + ); > + > +typedef > +CHAR8* > +(EFIAPI *GET_CPU_NAME) ( > + INTN CpuId > + ); > + > typedef > EFI_STATUS > (EFIAPI *GET_ARM_MEM) ( > @@ -104,21 +128,25 @@ EFI_STATUS > ); > > typedef struct { > - SET_POWER_STATE SetPowerState; > - GET_MAC_ADDRESS GetMacAddress; > - GET_COMMAND_LINE GetCommandLine; > - GET_CLOCK_RATE GetClockRate; > - GET_CLOCK_RATE GetMaxClockRate; > - GET_CLOCK_RATE GetMinClockRate; > - SET_CLOCK_RATE SetClockRate; > - GET_FB GetFB; > - FREE_FB FreeFB; > - GET_FB_SIZE GetFBSize; > - SET_LED SetLed; > - GET_SERIAL GetSerial; > - GET_MODEL GetModel; > - GET_MODEL_REVISION GetModelRevision; > - GET_ARM_MEM GetArmMem; > + SET_POWER_STATE SetPowerState; > + GET_MAC_ADDRESS GetMacAddress; > + GET_COMMAND_LINE GetCommandLine; > + GET_CLOCK_RATE GetClockRate; > + GET_CLOCK_RATE GetMaxClockRate; > + GET_CLOCK_RATE GetMinClockRate; > + SET_CLOCK_RATE SetClockRate; > + GET_FB GetFB; > + FREE_FB FreeFB; > + GET_FB_SIZE GetFBSize; > + SET_LED SetLed; > + GET_SERIAL GetSerial; > + GET_MODEL GetModel; > + GET_MODEL_REVISION GetModelRevision; > + GET_MODEL_NAME GetModelName; > + GET_FIRMWARE_REVISION GetFirmwareRevision; > + GET_MANUFACTURER_NAME GetManufacturerName; > + GET_CPU_NAME GetCpuName; > + GET_ARM_MEM GetArmMem; > } RASPBERRY_PI_FIRMWARE_PROTOCOL; > > extern EFI_GUID gRaspberryPiFirmwareProtocolGuid; > -- > 2.21.0.windows.1 > ^ permalink raw reply [flat|nested] 5+ messages in thread
* [edk2-platforms PATCH 2/2] Platform/RPi3: Improve the population of PlatformSmbiosDxe elements 2019-09-04 12:14 [edk2-platforms PATCH 0/2] Platform/RPi3: PlatformSmbios improvements Pete Batard 2019-09-04 12:14 ` [edk2-platforms PATCH 1/2] Platform/RPi3: Add more query functions in RpiFirmwareDxe Pete Batard @ 2019-09-04 12:14 ` Pete Batard 2019-09-27 19:03 ` Leif Lindholm 1 sibling, 1 reply; 5+ messages in thread From: Pete Batard @ 2019-09-04 12:14 UTC (permalink / raw) To: devel; +Cc: ard.biesheuvel, leif.lindholm This patch cleans up the population SMBIOS entries by removing elements that we don't have data for, as well as properly filling the ones for which we do, through the newly added queries from RpiFirmwareDxe. String parsing code is also added to BIOSInfoUpdateSmbiosType0() so that any numeric "x.y" value being passed in PcdFirmwareVersionString will now be used to populate the BIOS major and minor. Additional minor improvements are also applied, such as consistent use of uppercase values. Signed-off-by: Pete Batard <pete@akeo.ie> --- Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c | 193 ++++++++++++-------- Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.inf | 1 + Platform/RaspberryPi/RPi3/RPi3.dsc | 2 +- 3 files changed, 117 insertions(+), 79 deletions(-) diff --git a/Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c b/Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c index bc35175279f2..66ffadd0cade 100644 --- a/Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c +++ b/Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c @@ -35,11 +35,14 @@ #include <Library/UefiDriverEntryPoint.h> #include <Library/UefiLib.h> #include <Library/BaseLib.h> +#include <Library/PcdLib.h> #include <Library/BaseMemoryLib.h> #include <Library/MemoryAllocationLib.h> #include <Library/UefiBootServicesTableLib.h> #include <Library/PrintLib.h> +#define SMB_IS_DIGIT(c) (((c) >= '0') && ((c) <= '9')) + STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol; /*********************************************************************** @@ -49,7 +52,7 @@ SMBIOS_TABLE_TYPE0 mBIOSInfoType0 = { { EFI_SMBIOS_TYPE_BIOS_INFORMATION, sizeof (SMBIOS_TABLE_TYPE0), 0 }, 1, // Vendor String 2, // BiosVersion String - 0x0, // BiosSegment + 0, // BiosSegment 3, // BiosReleaseDate String 0x1F, // BiosSize { // BiosCharacteristics @@ -97,23 +100,25 @@ SMBIOS_TABLE_TYPE0 mBIOSInfoType0 = { // Boot1394IsSupported :1; // SmartBatteryIsSupported :1; // BIOSCharacteristicsExtensionBytes[1] - 0x0e, // BiosBootSpecIsSupported :1; + 0x0E, // BiosBootSpecIsSupported :1; // FunctionKeyNetworkBootIsSupported :1; // TargetContentDistributionEnabled :1; // UefiSpecificationSupported :1; // VirtualMachineSupported :1; // ExtensionByte2Reserved :3; }, - 0xFF, // SystemBiosMajorRelease - 0xFF, // SystemBiosMinorRelease - 0xFF, // EmbeddedControllerFirmwareMajorRelease - 0xFF, // EmbeddedControllerFirmwareMinorRelease + 0, // SystemBiosMajorRelease + 0, // SystemBiosMinorRelease + 0, // EmbeddedControllerFirmwareMajorRelease + 0, // EmbeddedControllerFirmwareMinorRelease }; +CHAR8 mBiosVersion[128] = "EDK2-DEV"; + CHAR8 *mBIOSInfoType0Strings[] = { - "https://github.com/andreiw/RaspberryPiPkg", // Vendor String - "Raspberry Pi 64-bit UEFI (" __DATE__ " " __TIME__ ")", // BiosVersion String - __DATE__, + "TianoCore", // Vendor + mBiosVersion, // Version + __DATE__ " " __TIME__, // Release Date NULL }; @@ -132,42 +137,19 @@ SMBIOS_TABLE_TYPE1 mSysInfoType1 = { 6, // Family String }; -#define PROD_BASE 8 -#define PROD_KNOWN 13 -#define PROD_UNKNOWN 11 -CHAR8 *ProductNames[] = { - /* 8 */ "3", - /* 9 */ "Zero", - /* 10 */ "CM3", - /* 11 */ "???", - /* 12 */ "Zero W", - /* 13 */ "3B+" -}; - -#define MANU_UNKNOWN 0 -#define MANU_KNOWN 4 -#define MANU_BASE 1 -CHAR8 *ManufNames[] = { - "???", - /* 0 */ "Sony", - /* 1 */ "Egoman", - /* 2 */ "Embest", - /* 3 */ "Sony Japan", - /* 4 */ "Embest" -}; - -CHAR8 mSysInfoManufName[sizeof ("Sony Japan")]; -CHAR8 mSysInfoProductName[sizeof ("64-bit Raspberry Pi XXXXXX (rev. xxxxxxxx)")]; +CHAR8 mSysInfoManufName[128]; +CHAR8 mSysInfoProductName[128]; +CHAR8 mSysInfoVersionName[128]; CHAR8 mSysInfoSerial[sizeof (UINT64) * 2 + 1]; CHAR8 mSysInfoSKU[sizeof (UINT64) * 2 + 1]; CHAR8 *mSysInfoType1Strings[] = { mSysInfoManufName, mSysInfoProductName, - mSysInfoProductName, + mSysInfoVersionName, mSysInfoSerial, mSysInfoSKU, - "edk2", + "Raspberry Pi", NULL }; @@ -180,7 +162,7 @@ SMBIOS_TABLE_TYPE2 mBoardInfoType2 = { 2, // ProductName String 3, // Version String 4, // SerialNumber String - 5, // AssetTag String + 0, // AssetTag String { // FeatureFlag 1, // Motherboard :1; 0, // RequiresDaughterCard :1; @@ -189,7 +171,7 @@ SMBIOS_TABLE_TYPE2 mBoardInfoType2 = { 0, // HotSwappable :1; 0, // Reserved :3; }, - 6, // LocationInChassis String + 0, // LocationInChassis String 0, // ChassisHandle; BaseBoardTypeMotherBoard, // BoardType; 0, // NumberOfContainedObjectHandles; @@ -198,10 +180,8 @@ SMBIOS_TABLE_TYPE2 mBoardInfoType2 = { CHAR8 *mBoardInfoType2Strings[] = { mSysInfoManufName, mSysInfoProductName, - mSysInfoProductName, + mSysInfoVersionName, mSysInfoSerial, - "None", - mSysInfoSKU, NULL }; @@ -214,7 +194,7 @@ SMBIOS_TABLE_TYPE3 mEnclosureInfoType3 = { MiscChassisEmbeddedPc, // Type; 2, // Version String 3, // SerialNumber String - 4, // AssetTag String + 0, // AssetTag String ChassisStateSafe, // BootupState; ChassisStateSafe, // PowerSupplyState; ChassisStateSafe, // ThermalState; @@ -230,7 +210,6 @@ CHAR8 *mEnclosureInfoType3Strings[] = { mSysInfoManufName, mSysInfoProductName, mSysInfoSerial, - "None", NULL }; @@ -240,9 +219,9 @@ CHAR8 *mEnclosureInfoType3Strings[] = { SMBIOS_TABLE_TYPE4 mProcessorInfoType4 = { { EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION, sizeof (SMBIOS_TABLE_TYPE4), 0}, 1, // Socket String - CentralProcessor, // ProcessorType; ///< The enumeration value from PROCESSOR_TYPE_DATA. + CentralProcessor, // ProcessorType; ///< The enumeration value from PROCESSOR_TYPE_DATA. ProcessorFamilyIndicatorFamily2, // ProcessorFamily; ///< The enumeration value from PROCESSOR_FAMILY2_DATA. - 2, // ProcessorManufacture String; + 2, // ProcessorManufacturer String; { // ProcessorId; { // PROCESSOR_SIGNATURE 0, // ProcessorSteppingId:4; @@ -306,9 +285,9 @@ SMBIOS_TABLE_TYPE4 mProcessorInfoType4 = { 0, // L1CacheHandle; 0, // L2CacheHandle; 0, // L3CacheHandle; - 4, // SerialNumber; - 5, // AssetTag; - 6, // PartNumber; + 0, // SerialNumber; + 0, // AssetTag; + 0, // PartNumber; 4, // CoreCount; 4, // EnabledCoreCount; 4, // ThreadCount; @@ -316,13 +295,12 @@ SMBIOS_TABLE_TYPE4 mProcessorInfoType4 = { ProcessorFamilyARM, // ARM Processor Family; }; +CHAR8 mCpuName[128] = "Unknown ARM CPU"; + CHAR8 *mProcessorInfoType4Strings[] = { "Socket", - "ARM", - "BCM2837 ARMv8", - "1.0", - "1.0", - "1.0", + "Broadcom", + mCpuName, NULL }; @@ -430,7 +408,7 @@ SMBIOS_TABLE_TYPE17 mMemDevInfoType17 = { 0x0400, // Size; // When bit 15 is 0: Size in MB // When bit 15 is 1: Size in KB, and continues in ExtendedSize MemoryFormFactorUnknown, // FormFactor; ///< The enumeration value from MEMORY_FORM_FACTOR. - 0xff, // DeviceSet; + 0xFF, // DeviceSet; 1, // DeviceLocator String 2, // BankLocator String MemoryTypeDram, // MemoryType; ///< The enumeration value from MEMORY_DEVICE_TYPE. @@ -618,6 +596,70 @@ BIOSInfoUpdateSmbiosType0 ( VOID ) { + UINT32 FirmwareRevision = 0; + EFI_STATUS Status = EFI_SUCCESS; + INTN i; + INTN State = 0; + INTN Value[2]; + + // Populate the Firmware major and minor. + Status = mFwProtocol->GetFirmwareRevision (&FirmwareRevision); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to get firmware revision: %r\n", Status)); + } else { + // This expects Broadcom / The Raspberry Pi Foundation to switch to + // less nonsensical VideoCore firmware revisions in the future... + mBIOSInfoType0.EmbeddedControllerFirmwareMajorRelease = + (UINT8)((FirmwareRevision >> 16) & 0xFF); + mBIOSInfoType0.EmbeddedControllerFirmwareMinorRelease = + (UINT8)(FirmwareRevision & 0xFF); + } + + // mBiosVersion, which is referenced in mBIOSInfoType0Strings, + // is not modified if the following call fails. + UnicodeStrToAsciiStrS ((CHAR16*)PcdGetPtr (PcdFirmwareVersionString), + mBiosVersion, sizeof (mBiosVersion)); + + // Look for a "x.y" numeric string anywhere in mBiosVersion and + // try to parse it to populate the BIOS major and minor. + for (i = 0; (i < AsciiStrLen (mBiosVersion)) && (State < 4); i++) { + switch (State) { + case 0: + if (!SMB_IS_DIGIT (mBiosVersion[i])) + break; + Value[0] = Value[1] = 0; + State++; + // Fall through + case 1: + case 3: + if (SMB_IS_DIGIT (mBiosVersion[i])) { + Value[State / 2] = (Value[State / 2] * 10) + (mBiosVersion[i] - '0'); + if (Value[State / 2] > 255) { + while (SMB_IS_DIGIT (mBiosVersion[i + 1])) + i++; + // Reset our state (we may have something like "Firmware X83737.1 v1.23") + State = 0; + } + } else { + State++; + } + if (State != 2) + break; + // Fall through + case 2: + if ((mBiosVersion[i] == '.') && (SMB_IS_DIGIT (mBiosVersion[i + 1]))) { + State++; + } else { + State = 0; + } + break; + } + } + if ((State == 3) || (State == 4)) { + mBIOSInfoType0.SystemBiosMajorRelease = (UINT8)Value[0]; + mBIOSInfoType0.SystemBiosMinorRelease = (UINT8)Value[1]; + } + LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mBIOSInfoType0, mBIOSInfoType0Strings, NULL); } @@ -631,7 +673,7 @@ I64ToHexString ( IN UINT64 Value ) { - static CHAR8 ItoH[] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' }; + STATIC CHAR8 ItoH[] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' }; UINT8 StringInx; INT8 NibbleInx; @@ -664,34 +706,25 @@ SysInfoUpdateSmbiosType1 ( UINT32 BoardRevision = 0; EFI_STATUS Status = EFI_SUCCESS; UINT64 BoardSerial = 0; - UINTN Prod = PROD_UNKNOWN; - UINTN Manu = MANU_UNKNOWN; + INTN Prod = -1; + INTN Manu = -1; Status = mFwProtocol->GetModelRevision (&BoardRevision); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "Failed to get board model: %r\n", Status)); } else { Prod = (BoardRevision >> 4) & 0xFF; + Manu = (BoardRevision >> 16) & 0x0F; } - if (Prod > PROD_KNOWN) { - Prod = PROD_UNKNOWN; - } - Prod -= PROD_BASE; - AsciiSPrint (mSysInfoProductName, sizeof (mSysInfoProductName), - "64-bit Raspberry Pi %a (rev. %x)", ProductNames[Prod], BoardRevision); - - Manu = (BoardRevision >> 16) & 0xF; - if (Manu > MANU_KNOWN) { - Manu = MANU_UNKNOWN; - } else { - Manu += MANU_BASE; - } - AsciiSPrint (mSysInfoManufName, sizeof (mSysInfoManufName), "%a", ManufNames[Manu]); + AsciiStrCpyS (mSysInfoProductName, sizeof (mSysInfoProductName), + mFwProtocol->GetModelName (Prod)); + AsciiStrCpyS (mSysInfoManufName, sizeof (mSysInfoManufName), + mFwProtocol->GetManufacturerName (Manu)); + AsciiSPrint (mSysInfoVersionName, sizeof (mSysInfoVersionName), + "%X", BoardRevision); - I64ToHexString (mSysInfoSKU, - sizeof (mSysInfoSKU), - BoardRevision); + I64ToHexString (mSysInfoSKU, sizeof (mSysInfoSKU), BoardRevision); Status = mFwProtocol->GetSerial (&BoardSerial); if (EFI_ERROR (Status)) { @@ -702,9 +735,11 @@ SysInfoUpdateSmbiosType1 ( DEBUG ((DEBUG_ERROR, "Board Serial Number: %a\n", mSysInfoSerial)); - mSysInfoType1.Uuid.Data1 = *(UINT32*)"RPi3"; - mSysInfoType1.Uuid.Data2 = 0x0; - mSysInfoType1.Uuid.Data3 = 0x0; + mSysInfoType1.Uuid.Data1 = BoardRevision; + mSysInfoType1.Uuid.Data2 = 0; + mSysInfoType1.Uuid.Data3 = 0; + // Swap endianness, so that the serial is more user-friendly as a UUID + BoardSerial = SwapBytes64 (BoardSerial); CopyMem (mSysInfoType1.Uuid.Data4, &BoardSerial, sizeof (BoardSerial)); LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mSysInfoType1, mSysInfoType1Strings, NULL); @@ -763,6 +798,8 @@ ProcessorInfoUpdateSmbiosType4 ( DEBUG ((DEBUG_INFO, "Current CPU speed: %uHz\n", Rate)); } + AsciiStrCpyS (mCpuName, sizeof (mCpuName), mFwProtocol->GetCpuName (-1)); + LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mProcessorInfoType4, mProcessorInfoType4Strings, NULL); } diff --git a/Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.inf b/Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.inf index f7c74f7f5456..fde194ea5d90 100644 --- a/Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.inf +++ b/Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.inf @@ -48,3 +48,4 @@ [Depex] [Pcd] gArmTokenSpaceGuid.PcdSystemMemorySize + gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3/RPi3.dsc index 2b9e619ad55c..138d3691dc56 100644 --- a/Platform/RaspberryPi/RPi3/RPi3.dsc +++ b/Platform/RaspberryPi/RPi3/RPi3.dsc @@ -309,7 +309,7 @@ [PcdsFixedAtBuild.common] gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset|0xc0000000 - gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString|L"edk2-1.0" + gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString|L"EDK2-DEV" !if $(SECURE_BOOT_ENABLE) == TRUE # override the default values from SecurityPkg to ensure images from all sources are verified in secure boot -- 2.21.0.windows.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [edk2-platforms PATCH 2/2] Platform/RPi3: Improve the population of PlatformSmbiosDxe elements 2019-09-04 12:14 ` [edk2-platforms PATCH 2/2] Platform/RPi3: Improve the population of PlatformSmbiosDxe elements Pete Batard @ 2019-09-27 19:03 ` Leif Lindholm 0 siblings, 0 replies; 5+ messages in thread From: Leif Lindholm @ 2019-09-27 19:03 UTC (permalink / raw) To: Pete Batard; +Cc: devel, ard.biesheuvel On Wed, Sep 04, 2019 at 01:14:18PM +0100, Pete Batard wrote: > This patch cleans up the population SMBIOS entries by removing elements > that we don't have data for, as well as properly filling the ones for > which we do, through the newly added queries from RpiFirmwareDxe. > > String parsing code is also added to BIOSInfoUpdateSmbiosType0() so > that any numeric "x.y" value being passed in PcdFirmwareVersionString > will now be used to populate the BIOS major and minor. > > Additional minor improvements are also applied, such as consistent use > of uppercase values. Could you split out the alsos? / Leif > Signed-off-by: Pete Batard <pete@akeo.ie> > --- > Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c | 193 ++++++++++++-------- > Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.inf | 1 + > Platform/RaspberryPi/RPi3/RPi3.dsc | 2 +- > 3 files changed, 117 insertions(+), 79 deletions(-) > > diff --git a/Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c b/Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c > index bc35175279f2..66ffadd0cade 100644 > --- a/Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c > +++ b/Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c > @@ -35,11 +35,14 @@ > #include <Library/UefiDriverEntryPoint.h> > #include <Library/UefiLib.h> > #include <Library/BaseLib.h> > +#include <Library/PcdLib.h> > #include <Library/BaseMemoryLib.h> > #include <Library/MemoryAllocationLib.h> > #include <Library/UefiBootServicesTableLib.h> > #include <Library/PrintLib.h> > > +#define SMB_IS_DIGIT(c) (((c) >= '0') && ((c) <= '9')) > + > STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol; > > /*********************************************************************** > @@ -49,7 +52,7 @@ SMBIOS_TABLE_TYPE0 mBIOSInfoType0 = { > { EFI_SMBIOS_TYPE_BIOS_INFORMATION, sizeof (SMBIOS_TABLE_TYPE0), 0 }, > 1, // Vendor String > 2, // BiosVersion String > - 0x0, // BiosSegment > + 0, // BiosSegment > 3, // BiosReleaseDate String > 0x1F, // BiosSize > { // BiosCharacteristics > @@ -97,23 +100,25 @@ SMBIOS_TABLE_TYPE0 mBIOSInfoType0 = { > // Boot1394IsSupported :1; > // SmartBatteryIsSupported :1; > // BIOSCharacteristicsExtensionBytes[1] > - 0x0e, // BiosBootSpecIsSupported :1; > + 0x0E, // BiosBootSpecIsSupported :1; > // FunctionKeyNetworkBootIsSupported :1; > // TargetContentDistributionEnabled :1; > // UefiSpecificationSupported :1; > // VirtualMachineSupported :1; > // ExtensionByte2Reserved :3; > }, > - 0xFF, // SystemBiosMajorRelease > - 0xFF, // SystemBiosMinorRelease > - 0xFF, // EmbeddedControllerFirmwareMajorRelease > - 0xFF, // EmbeddedControllerFirmwareMinorRelease > + 0, // SystemBiosMajorRelease > + 0, // SystemBiosMinorRelease > + 0, // EmbeddedControllerFirmwareMajorRelease > + 0, // EmbeddedControllerFirmwareMinorRelease > }; > > +CHAR8 mBiosVersion[128] = "EDK2-DEV"; > + > CHAR8 *mBIOSInfoType0Strings[] = { > - "https://github.com/andreiw/RaspberryPiPkg", // Vendor String > - "Raspberry Pi 64-bit UEFI (" __DATE__ " " __TIME__ ")", // BiosVersion String > - __DATE__, > + "TianoCore", // Vendor > + mBiosVersion, // Version > + __DATE__ " " __TIME__, // Release Date > NULL > }; > > @@ -132,42 +137,19 @@ SMBIOS_TABLE_TYPE1 mSysInfoType1 = { > 6, // Family String > }; > > -#define PROD_BASE 8 > -#define PROD_KNOWN 13 > -#define PROD_UNKNOWN 11 > -CHAR8 *ProductNames[] = { > - /* 8 */ "3", > - /* 9 */ "Zero", > - /* 10 */ "CM3", > - /* 11 */ "???", > - /* 12 */ "Zero W", > - /* 13 */ "3B+" > -}; > - > -#define MANU_UNKNOWN 0 > -#define MANU_KNOWN 4 > -#define MANU_BASE 1 > -CHAR8 *ManufNames[] = { > - "???", > - /* 0 */ "Sony", > - /* 1 */ "Egoman", > - /* 2 */ "Embest", > - /* 3 */ "Sony Japan", > - /* 4 */ "Embest" > -}; > - > -CHAR8 mSysInfoManufName[sizeof ("Sony Japan")]; > -CHAR8 mSysInfoProductName[sizeof ("64-bit Raspberry Pi XXXXXX (rev. xxxxxxxx)")]; > +CHAR8 mSysInfoManufName[128]; > +CHAR8 mSysInfoProductName[128]; > +CHAR8 mSysInfoVersionName[128]; > CHAR8 mSysInfoSerial[sizeof (UINT64) * 2 + 1]; > CHAR8 mSysInfoSKU[sizeof (UINT64) * 2 + 1]; > > CHAR8 *mSysInfoType1Strings[] = { > mSysInfoManufName, > mSysInfoProductName, > - mSysInfoProductName, > + mSysInfoVersionName, > mSysInfoSerial, > mSysInfoSKU, > - "edk2", > + "Raspberry Pi", > NULL > }; > > @@ -180,7 +162,7 @@ SMBIOS_TABLE_TYPE2 mBoardInfoType2 = { > 2, // ProductName String > 3, // Version String > 4, // SerialNumber String > - 5, // AssetTag String > + 0, // AssetTag String > { // FeatureFlag > 1, // Motherboard :1; > 0, // RequiresDaughterCard :1; > @@ -189,7 +171,7 @@ SMBIOS_TABLE_TYPE2 mBoardInfoType2 = { > 0, // HotSwappable :1; > 0, // Reserved :3; > }, > - 6, // LocationInChassis String > + 0, // LocationInChassis String > 0, // ChassisHandle; > BaseBoardTypeMotherBoard, // BoardType; > 0, // NumberOfContainedObjectHandles; > @@ -198,10 +180,8 @@ SMBIOS_TABLE_TYPE2 mBoardInfoType2 = { > CHAR8 *mBoardInfoType2Strings[] = { > mSysInfoManufName, > mSysInfoProductName, > - mSysInfoProductName, > + mSysInfoVersionName, > mSysInfoSerial, > - "None", > - mSysInfoSKU, > NULL > }; > > @@ -214,7 +194,7 @@ SMBIOS_TABLE_TYPE3 mEnclosureInfoType3 = { > MiscChassisEmbeddedPc, // Type; > 2, // Version String > 3, // SerialNumber String > - 4, // AssetTag String > + 0, // AssetTag String > ChassisStateSafe, // BootupState; > ChassisStateSafe, // PowerSupplyState; > ChassisStateSafe, // ThermalState; > @@ -230,7 +210,6 @@ CHAR8 *mEnclosureInfoType3Strings[] = { > mSysInfoManufName, > mSysInfoProductName, > mSysInfoSerial, > - "None", > NULL > }; > > @@ -240,9 +219,9 @@ CHAR8 *mEnclosureInfoType3Strings[] = { > SMBIOS_TABLE_TYPE4 mProcessorInfoType4 = { > { EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION, sizeof (SMBIOS_TABLE_TYPE4), 0}, > 1, // Socket String > - CentralProcessor, // ProcessorType; ///< The enumeration value from PROCESSOR_TYPE_DATA. > + CentralProcessor, // ProcessorType; ///< The enumeration value from PROCESSOR_TYPE_DATA. > ProcessorFamilyIndicatorFamily2, // ProcessorFamily; ///< The enumeration value from PROCESSOR_FAMILY2_DATA. > - 2, // ProcessorManufacture String; > + 2, // ProcessorManufacturer String; > { // ProcessorId; > { // PROCESSOR_SIGNATURE > 0, // ProcessorSteppingId:4; > @@ -306,9 +285,9 @@ SMBIOS_TABLE_TYPE4 mProcessorInfoType4 = { > 0, // L1CacheHandle; > 0, // L2CacheHandle; > 0, // L3CacheHandle; > - 4, // SerialNumber; > - 5, // AssetTag; > - 6, // PartNumber; > + 0, // SerialNumber; > + 0, // AssetTag; > + 0, // PartNumber; > 4, // CoreCount; > 4, // EnabledCoreCount; > 4, // ThreadCount; > @@ -316,13 +295,12 @@ SMBIOS_TABLE_TYPE4 mProcessorInfoType4 = { > ProcessorFamilyARM, // ARM Processor Family; > }; > > +CHAR8 mCpuName[128] = "Unknown ARM CPU"; > + > CHAR8 *mProcessorInfoType4Strings[] = { > "Socket", > - "ARM", > - "BCM2837 ARMv8", > - "1.0", > - "1.0", > - "1.0", > + "Broadcom", > + mCpuName, > NULL > }; > > @@ -430,7 +408,7 @@ SMBIOS_TABLE_TYPE17 mMemDevInfoType17 = { > 0x0400, // Size; // When bit 15 is 0: Size in MB > // When bit 15 is 1: Size in KB, and continues in ExtendedSize > MemoryFormFactorUnknown, // FormFactor; ///< The enumeration value from MEMORY_FORM_FACTOR. > - 0xff, // DeviceSet; > + 0xFF, // DeviceSet; > 1, // DeviceLocator String > 2, // BankLocator String > MemoryTypeDram, // MemoryType; ///< The enumeration value from MEMORY_DEVICE_TYPE. > @@ -618,6 +596,70 @@ BIOSInfoUpdateSmbiosType0 ( > VOID > ) > { > + UINT32 FirmwareRevision = 0; > + EFI_STATUS Status = EFI_SUCCESS; > + INTN i; > + INTN State = 0; > + INTN Value[2]; > + > + // Populate the Firmware major and minor. > + Status = mFwProtocol->GetFirmwareRevision (&FirmwareRevision); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Failed to get firmware revision: %r\n", Status)); > + } else { > + // This expects Broadcom / The Raspberry Pi Foundation to switch to > + // less nonsensical VideoCore firmware revisions in the future... > + mBIOSInfoType0.EmbeddedControllerFirmwareMajorRelease = > + (UINT8)((FirmwareRevision >> 16) & 0xFF); > + mBIOSInfoType0.EmbeddedControllerFirmwareMinorRelease = > + (UINT8)(FirmwareRevision & 0xFF); > + } > + > + // mBiosVersion, which is referenced in mBIOSInfoType0Strings, > + // is not modified if the following call fails. > + UnicodeStrToAsciiStrS ((CHAR16*)PcdGetPtr (PcdFirmwareVersionString), > + mBiosVersion, sizeof (mBiosVersion)); > + > + // Look for a "x.y" numeric string anywhere in mBiosVersion and > + // try to parse it to populate the BIOS major and minor. > + for (i = 0; (i < AsciiStrLen (mBiosVersion)) && (State < 4); i++) { > + switch (State) { > + case 0: > + if (!SMB_IS_DIGIT (mBiosVersion[i])) > + break; > + Value[0] = Value[1] = 0; > + State++; > + // Fall through > + case 1: > + case 3: > + if (SMB_IS_DIGIT (mBiosVersion[i])) { > + Value[State / 2] = (Value[State / 2] * 10) + (mBiosVersion[i] - '0'); > + if (Value[State / 2] > 255) { > + while (SMB_IS_DIGIT (mBiosVersion[i + 1])) > + i++; > + // Reset our state (we may have something like "Firmware X83737.1 v1.23") > + State = 0; > + } > + } else { > + State++; > + } > + if (State != 2) > + break; > + // Fall through > + case 2: > + if ((mBiosVersion[i] == '.') && (SMB_IS_DIGIT (mBiosVersion[i + 1]))) { > + State++; > + } else { > + State = 0; > + } > + break; > + } > + } > + if ((State == 3) || (State == 4)) { > + mBIOSInfoType0.SystemBiosMajorRelease = (UINT8)Value[0]; > + mBIOSInfoType0.SystemBiosMinorRelease = (UINT8)Value[1]; > + } > + > LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mBIOSInfoType0, mBIOSInfoType0Strings, NULL); > } > > @@ -631,7 +673,7 @@ I64ToHexString ( > IN UINT64 Value > ) > { > - static CHAR8 ItoH[] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' }; > + STATIC CHAR8 ItoH[] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' }; > UINT8 StringInx; > INT8 NibbleInx; > > @@ -664,34 +706,25 @@ SysInfoUpdateSmbiosType1 ( > UINT32 BoardRevision = 0; > EFI_STATUS Status = EFI_SUCCESS; > UINT64 BoardSerial = 0; > - UINTN Prod = PROD_UNKNOWN; > - UINTN Manu = MANU_UNKNOWN; > + INTN Prod = -1; > + INTN Manu = -1; > > Status = mFwProtocol->GetModelRevision (&BoardRevision); > if (EFI_ERROR (Status)) { > DEBUG ((DEBUG_ERROR, "Failed to get board model: %r\n", Status)); > } else { > Prod = (BoardRevision >> 4) & 0xFF; > + Manu = (BoardRevision >> 16) & 0x0F; > } > > - if (Prod > PROD_KNOWN) { > - Prod = PROD_UNKNOWN; > - } > - Prod -= PROD_BASE; > - AsciiSPrint (mSysInfoProductName, sizeof (mSysInfoProductName), > - "64-bit Raspberry Pi %a (rev. %x)", ProductNames[Prod], BoardRevision); > - > - Manu = (BoardRevision >> 16) & 0xF; > - if (Manu > MANU_KNOWN) { > - Manu = MANU_UNKNOWN; > - } else { > - Manu += MANU_BASE; > - } > - AsciiSPrint (mSysInfoManufName, sizeof (mSysInfoManufName), "%a", ManufNames[Manu]); > + AsciiStrCpyS (mSysInfoProductName, sizeof (mSysInfoProductName), > + mFwProtocol->GetModelName (Prod)); > + AsciiStrCpyS (mSysInfoManufName, sizeof (mSysInfoManufName), > + mFwProtocol->GetManufacturerName (Manu)); > + AsciiSPrint (mSysInfoVersionName, sizeof (mSysInfoVersionName), > + "%X", BoardRevision); > > - I64ToHexString (mSysInfoSKU, > - sizeof (mSysInfoSKU), > - BoardRevision); > + I64ToHexString (mSysInfoSKU, sizeof (mSysInfoSKU), BoardRevision); > > Status = mFwProtocol->GetSerial (&BoardSerial); > if (EFI_ERROR (Status)) { > @@ -702,9 +735,11 @@ SysInfoUpdateSmbiosType1 ( > > DEBUG ((DEBUG_ERROR, "Board Serial Number: %a\n", mSysInfoSerial)); > > - mSysInfoType1.Uuid.Data1 = *(UINT32*)"RPi3"; > - mSysInfoType1.Uuid.Data2 = 0x0; > - mSysInfoType1.Uuid.Data3 = 0x0; > + mSysInfoType1.Uuid.Data1 = BoardRevision; > + mSysInfoType1.Uuid.Data2 = 0; > + mSysInfoType1.Uuid.Data3 = 0; > + // Swap endianness, so that the serial is more user-friendly as a UUID > + BoardSerial = SwapBytes64 (BoardSerial); > CopyMem (mSysInfoType1.Uuid.Data4, &BoardSerial, sizeof (BoardSerial)); > > LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mSysInfoType1, mSysInfoType1Strings, NULL); > @@ -763,6 +798,8 @@ ProcessorInfoUpdateSmbiosType4 ( > DEBUG ((DEBUG_INFO, "Current CPU speed: %uHz\n", Rate)); > } > > + AsciiStrCpyS (mCpuName, sizeof (mCpuName), mFwProtocol->GetCpuName (-1)); > + > LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER*)&mProcessorInfoType4, mProcessorInfoType4Strings, NULL); > } > > diff --git a/Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.inf b/Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.inf > index f7c74f7f5456..fde194ea5d90 100644 > --- a/Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.inf > +++ b/Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.inf > @@ -48,3 +48,4 @@ [Depex] > > [Pcd] > gArmTokenSpaceGuid.PcdSystemMemorySize > + gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString > diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3/RPi3.dsc > index 2b9e619ad55c..138d3691dc56 100644 > --- a/Platform/RaspberryPi/RPi3/RPi3.dsc > +++ b/Platform/RaspberryPi/RPi3/RPi3.dsc > @@ -309,7 +309,7 @@ [PcdsFixedAtBuild.common] > > gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset|0xc0000000 > > - gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString|L"edk2-1.0" > + gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString|L"EDK2-DEV" > > !if $(SECURE_BOOT_ENABLE) == TRUE > # override the default values from SecurityPkg to ensure images from all sources are verified in secure boot > -- > 2.21.0.windows.1 > ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-09-27 19:03 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2019-09-04 12:14 [edk2-platforms PATCH 0/2] Platform/RPi3: PlatformSmbios improvements Pete Batard 2019-09-04 12:14 ` [edk2-platforms PATCH 1/2] Platform/RPi3: Add more query functions in RpiFirmwareDxe Pete Batard 2019-09-27 18:34 ` Leif Lindholm 2019-09-04 12:14 ` [edk2-platforms PATCH 2/2] Platform/RPi3: Improve the population of PlatformSmbiosDxe elements Pete Batard 2019-09-27 19:03 ` Leif Lindholm
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox