git: 09932da03ec4 - stable/13 - stand: Parse BIOS revision from SMBIOS

From: Warner Losh <imp_at_FreeBSD.org>
Date: Tue, 24 Jan 2023 22:12:23 UTC
The branch stable/13 has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=09932da03ec45fc4da2247a73b802ee4083ab8c8

commit 09932da03ec45fc4da2247a73b802ee4083ab8c8
Author:     Kornel Dulęba <kd@FreeBSD.org>
AuthorDate: 2022-09-02 11:08:32 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-01-24 21:49:33 +0000

    stand: Parse BIOS revision from SMBIOS
    
    Add a smbios.bios.revision kenv, which contains the system BIOS revision
    as defined in SMBIOS specification, section 3.3.1.
    Since the revision is stored in two separate byte fields,
    the smbios_setenv helper can't be used.
    Read and construct the kenv manually instead.
    
    Approved by:    mw(mentor)
    Sponsored by:   Stormshield
    Obtained from:  Semihalf
    Differential Revision:  https://reviews.freebsd.org/D36413
    
    (cherry picked from commit 66c73af7ea59382ce5ca7cfb2eedb0491790276c)
---
 stand/libsa/smbios.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/stand/libsa/smbios.c b/stand/libsa/smbios.c
index 5582a2f3ce90..61bd82f9d6f0 100644
--- a/stand/libsa/smbios.c
+++ b/stand/libsa/smbios.c
@@ -298,6 +298,8 @@ smbios_parse_table(const caddr_t addr)
 {
 	caddr_t		cp;
 	int		proc, size, osize, type;
+	uint8_t		bios_minor, bios_major;
+	char		buf[16];
 
 	type = SMBIOS_GET8(addr, 0);	/* 3.1.2 Structure Header Format */
 	switch(type) {
@@ -305,6 +307,13 @@ smbios_parse_table(const caddr_t addr)
 		smbios_setenv("smbios.bios.vendor", addr, 0x04);
 		smbios_setenv("smbios.bios.version", addr, 0x05);
 		smbios_setenv("smbios.bios.reldate", addr, 0x08);
+		bios_major = SMBIOS_GET8(addr, 0x14);
+		bios_minor = SMBIOS_GET8(addr, 0x15);
+		if (bios_minor != 0xFF && bios_major != 0xFF) {
+			snprintf(buf, sizeof(buf), "%u.%u",
+			    bios_major, bios_minor);
+			setenv("smbios.bios.revision", buf, 1);
+		}
 		break;
 
 	case 1:		/* 3.3.2 System Information (Type 1) */