public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Pete Batard" <pete@akeo.ie>
To: devel@edk2.groups.io
Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org
Subject: [edk2-platforms][PATCH v2 4/5] Platform/RPi3/PlatformSmbiosDxe: Populate BIOS major/minor from PCD
Date: Tue,  8 Oct 2019 13:38:40 +0100	[thread overview]
Message-ID: <20191008123841.12952-5-pete@akeo.ie> (raw)
In-Reply-To: <20191008123841.12952-1-pete@akeo.ie>

String parsing code is added to BIOSInfoUpdateSmbiosType0() so that
any numeric "x.y" value being passed in PcdFirmwareVersionString is
now used to populate the BIOS major and minor.

Signed-off-by: Pete Batard <pete@akeo.ie>
---
 Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c | 44 +++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c b/Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c
index 8a4840267780..66ffadd0cade 100644
--- a/Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c
+++ b/Platform/RaspberryPi/RPi3/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c
@@ -41,7 +41,9 @@
 #include <Library/UefiBootServicesTableLib.h>
 #include <Library/PrintLib.h>
 
-static RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol;
+#define SMB_IS_DIGIT(c)  (((c) >= '0') && ((c) <= '9'))
+
+STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol;
 
 /***********************************************************************
         SMBIOS data definition  TYPE0  BIOS Information
@@ -618,6 +620,46 @@ BIOSInfoUpdateSmbiosType0 (
   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);
 }
 
-- 
2.21.0.windows.1


  parent reply	other threads:[~2019-10-08 12:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-08 12:38 [edk2-platforms][PATCH v2 0/5] Platform/RPi3: Various SMBIOS improvements Pete Batard
2019-10-08 12:38 ` [edk2-platforms][PATCH v2 1/5] Platform/RPi3/RpiFirmwareDxe: Add more query functions Pete Batard
2019-10-10  8:39   ` Leif Lindholm
2019-10-10 12:41     ` Pete Batard
2019-10-10 16:43       ` Leif Lindholm
2019-10-10 17:27         ` Pete Batard
2019-10-08 12:38 ` [edk2-platforms][PATCH v2 2/5] Platform/RPi3/RpiFirmwareDxe: Improve serial number population Pete Batard
2019-10-10  8:43   ` Leif Lindholm
2019-10-10 12:41     ` Pete Batard
2019-10-10 16:49       ` Leif Lindholm
2019-10-10 17:28         ` Pete Batard
2019-10-08 12:38 ` [edk2-platforms][PATCH v2 3/5] Platform/RPi3/PlatformSmbiosDxe: Improve population of SMBIOS entries Pete Batard
2019-10-10  8:59   ` Leif Lindholm
2019-10-08 12:38 ` Pete Batard [this message]
2019-10-10  9:01   ` [edk2-platforms][PATCH v2 4/5] Platform/RPi3/PlatformSmbiosDxe: Populate BIOS major/minor from PCD Leif Lindholm
2019-10-08 12:38 ` [edk2-platforms][PATCH v2 5/5] Platform/RPi3/PlatformSmbiosDxe: Derive RAM size from board revision Pete Batard
2019-10-10  9:03   ` Leif Lindholm

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=20191008123841.12952-5-pete@akeo.ie \
    --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