[SeaBIOS] [PATCH 2/5] smbios: Move smbios parsing logic from smbios.c to biostables.c.

Kevin O'Connor kevin at koconnor.net
Mon Apr 7 22:48:57 CEST 2014


After this change, src/fw/smbios.c only contains the legacy code for
generating SMBIOS tables.  This change only contains code movement -
no logic is changed.

Signed-off-by: Kevin O'Connor <kevin at koconnor.net>
---
 src/fw/biostables.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/fw/smbios.c     | 70 ----------------------------------------------------
 src/util.h          |  4 +--
 3 files changed, 73 insertions(+), 72 deletions(-)

diff --git a/src/fw/biostables.c b/src/fw/biostables.c
index b2a7231..48325a4 100644
--- a/src/fw/biostables.c
+++ b/src/fw/biostables.c
@@ -231,6 +231,8 @@ find_acpi_features(void)
  * SMBIOS
  ****************************************************************/
 
+struct smbios_entry_point *SMBiosAddr;
+
 void
 copy_smbios(void *pos)
 {
@@ -256,6 +258,75 @@ copy_smbios(void *pos)
 }
 
 void
+display_uuid(void)
+{
+    u32 addr, end;
+    u8 *uuid;
+    u8 empty_uuid[16] = { 0 };
+
+    if (SMBiosAddr == NULL)
+        return;
+
+    addr =        SMBiosAddr->structure_table_address;
+    end  = addr + SMBiosAddr->structure_table_length;
+
+    /* the following takes care of any initial wraparound too */
+    while (addr < end) {
+        const struct smbios_structure_header *hdr;
+
+        /* partial structure header */
+        if (end - addr < sizeof(struct smbios_structure_header))
+            return;
+
+        hdr = (struct smbios_structure_header *)addr;
+
+        /* partial structure */
+        if (end - addr < hdr->length)
+            return;
+
+        /* any Type 1 structure version will do that has the UUID */
+        if (hdr->type == 1 &&
+            hdr->length >= offsetof(struct smbios_type_1, uuid) + 16)
+            break;
+
+        /* done with formatted area, skip string-set */
+        addr += hdr->length;
+
+        while (end - addr >= 2 &&
+               (*(u8 *)addr     != '\0' ||
+                *(u8 *)(addr+1) != '\0'))
+            ++addr;
+
+        /* structure terminator not found */
+        if (end - addr < 2)
+            return;
+
+        addr += 2;
+    }
+
+    /* parsing finished or skipped entirely, UUID not found */
+    if (addr >= end)
+        return;
+
+    uuid = (u8 *)(addr + offsetof(struct smbios_type_1, uuid));
+    if (memcmp(uuid, empty_uuid, sizeof empty_uuid) == 0)
+        return;
+
+    printf("Machine UUID"
+             " %02x%02x%02x%02x"
+             "-%02x%02x"
+             "-%02x%02x"
+             "-%02x%02x"
+             "-%02x%02x%02x%02x%02x%02x\n"
+           , uuid[ 0], uuid[ 1], uuid[ 2], uuid[ 3]
+           , uuid[ 4], uuid[ 5]
+           , uuid[ 6], uuid[ 7]
+           , uuid[ 8], uuid[ 9]
+           , uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]);
+}
+
+
+void
 copy_table(void *pos)
 {
     copy_pir(pos);
diff --git a/src/fw/smbios.c b/src/fw/smbios.c
index 0c6a5b2..902e8ab 100644
--- a/src/fw/smbios.c
+++ b/src/fw/smbios.c
@@ -15,8 +15,6 @@
 #include "util.h" // MaxCountCPUs
 #include "x86.h" // cpuid
 
-struct smbios_entry_point *SMBiosAddr;
-
 static void
 smbios_entry_point_setup(u16 max_structure_size,
                          u16 structure_table_length,
@@ -589,71 +587,3 @@ smbios_setup(void)
     smbios_entry_point_setup(max_struct_size, p - start, start, nr_structs);
     free(start);
 }
-
-void
-display_uuid(void)
-{
-    u32 addr, end;
-    u8 *uuid;
-    u8 empty_uuid[16] = { 0 };
-
-    if (SMBiosAddr == NULL)
-        return;
-
-    addr =        SMBiosAddr->structure_table_address;
-    end  = addr + SMBiosAddr->structure_table_length;
-
-    /* the following takes care of any initial wraparound too */
-    while (addr < end) {
-        const struct smbios_structure_header *hdr;
-
-        /* partial structure header */
-        if (end - addr < sizeof(struct smbios_structure_header))
-            return;
-
-        hdr = (struct smbios_structure_header *)addr;
-
-        /* partial structure */
-        if (end - addr < hdr->length)
-            return;
-
-        /* any Type 1 structure version will do that has the UUID */
-        if (hdr->type == 1 &&
-            hdr->length >= offsetof(struct smbios_type_1, uuid) + 16)
-            break;
-
-        /* done with formatted area, skip string-set */
-        addr += hdr->length;
-
-        while (end - addr >= 2 &&
-               (*(u8 *)addr     != '\0' ||
-                *(u8 *)(addr+1) != '\0'))
-            ++addr;
-
-        /* structure terminator not found */
-        if (end - addr < 2)
-            return;
-
-        addr += 2;
-    }
-
-    /* parsing finished or skipped entirely, UUID not found */
-    if (addr >= end)
-        return;
-
-    uuid = (u8 *)(addr + offsetof(struct smbios_type_1, uuid));
-    if (memcmp(uuid, empty_uuid, sizeof empty_uuid) == 0)
-        return;
-
-    printf("Machine UUID"
-             " %02x%02x%02x%02x"
-             "-%02x%02x"
-             "-%02x%02x"
-             "-%02x%02x"
-             "-%02x%02x%02x%02x%02x%02x\n"
-           , uuid[ 0], uuid[ 1], uuid[ 2], uuid[ 3]
-           , uuid[ 4], uuid[ 5]
-           , uuid[ 6], uuid[ 7]
-           , uuid[ 8], uuid[ 9]
-           , uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]);
-}
diff --git a/src/util.h b/src/util.h
index 2201da2..088437b 100644
--- a/src/util.h
+++ b/src/util.h
@@ -70,7 +70,9 @@ void *find_acpi_rsdp(void);
 u32 find_resume_vector(void);
 void acpi_reboot(void);
 void find_acpi_features(void);
+extern struct smbios_entry_point *SMBiosAddr;
 void copy_smbios(void *pos);
+void display_uuid(void);
 void copy_table(void *pos);
 
 // fw/coreboot.c
@@ -109,9 +111,7 @@ void make_bios_readonly(void);
 void qemu_prep_reset(void);
 
 // fw/smbios.c
-extern struct smbios_entry_point *SMBiosAddr;
 void smbios_setup(void);
-void display_uuid(void);
 
 // fw/smm.c
 void smm_device_setup(void);
-- 
1.9.0




More information about the SeaBIOS mailing list