[SeaBIOS] [PATCH v3] maininit(): print machine UUID under seabios version message

Laszlo Ersek lersek at redhat.com
Fri Dec 14 13:04:15 CET 2012


On 12/14/12 12:59, Laszlo Ersek wrote:
> There are users who would like to see the UUID at startup, and it probably
> won't bother others.
> 
> Related RHBZ: 876250.
> 
> Signed-off-by: Laszlo Ersek <lersek at redhat.com>
> ---
> v2->v3:
> - moved everything to display_uuid() in smbios.c, called from maininit()

Diff with v2:

diff --git a/src/bootsplash.c b/src/bootsplash.c
index a0fea61..78023a5 100644
--- a/src/bootsplash.c
+++ b/src/bootsplash.c
@@ -12,7 +12,6 @@
 #include "jpeg.h" // splash
 #include "vbe.h" // struct vbe_info
 #include "bmp.h" // bmp_alloc
-#include "smbios.h" // smbios_locate_uuid
 
 
 /****************************************************************
@@ -34,24 +33,6 @@ call16_int10(struct bregs *br)
  * VGA text / graphics console
  ****************************************************************/
 
-static void
-print_hello(void)
-{
-    const u8 *uuid;
-    u8 empty_uuid[16] = { 0 };
-
-    printf("SeaBIOS (version %s)\n", VERSION);
-
-    uuid = smbios_locate_uuid(SMBiosAddr);
-    if (uuid != NULL && memcmp(uuid, empty_uuid, sizeof empty_uuid) != 0) {
-        char uuid_str[37];
-
-        format_uuid(uuid_str, uuid);
-        printf("Machine UUID %s\n", uuid_str);
-    }
-    printf("\n");
-}
-
 void
 enable_vga_console(void)
 {
@@ -64,7 +45,7 @@ enable_vga_console(void)
     call16_int10(&br);
 
     // Write to screen.
-    print_hello();
+    printf("SeaBIOS (version %s)\n\n", VERSION);
 }
 
 static int
diff --git a/src/output.c b/src/output.c
index b6263b6..83de7f4 100644
--- a/src/output.c
+++ b/src/output.c
@@ -474,22 +474,6 @@ hexdump(const void *d, int len)
     debug_serial_flush();
 }
 
-void
-format_uuid(char buf[37], const u8 uuid[16])
-{
-    snprintf(buf, 37
-             , "%02x%02x%02x%02x"
-               "-%02x%02x"
-               "-%02x%02x"
-               "-%02x%02x"
-               "-%02x%02x%02x%02x%02x%02x"
-             , 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]);
-}
-
 static void
 dump_regs(struct bregs *regs)
 {
diff --git a/src/post.c b/src/post.c
index 3705c3b..f3b56b8 100644
--- a/src/post.c
+++ b/src/post.c
@@ -261,6 +261,9 @@ maininit(void)
     // Run vga option rom
     vga_setup();
 
+    // SMBIOS tables and VGA console are ready, print UUID
+    display_uuid();
+
     // Do hardware initialization (if running synchronously)
     if (!CONFIG_THREADS || !CONFIG_THREAD_OPTIONROMS) {
         init_hw();
diff --git a/src/smbios.c b/src/smbios.c
index 5874bec..aaa99bc 100644
--- a/src/smbios.c
+++ b/src/smbios.c
@@ -522,16 +522,18 @@ smbios_init(void)
     free(start);
 }
 
-const u8 *
-smbios_locate_uuid(const struct smbios_entry_point *ep)
+void
+display_uuid(void)
 {
     u32 addr, end;
+    u8 *uuid;
+    u8 empty_uuid[16] = { 0 };
 
-    if (ep == NULL)
-        return NULL;
+    if (SMBiosAddr == NULL)
+        return;
 
-    addr =        ep->structure_table_address;
-    end  = addr + ep->structure_table_length;
+    addr =        SMBiosAddr->structure_table_address;
+    end  = addr + SMBiosAddr->structure_table_length;
 
     /* the following takes care of any initial wraparound too */
     while (addr < end) {
@@ -539,18 +541,18 @@ smbios_locate_uuid(const struct smbios_entry_point *ep)
 
         /* partial structure header */
         if (end - addr < sizeof(struct smbios_structure_header))
-            return NULL;
+            return;
 
         hdr = (struct smbios_structure_header *)addr;
 
         /* partial structure */
         if (end - addr < hdr->length)
-            return NULL;
+            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)
-            return (u8 *)(addr + offsetof(struct smbios_type_1, uuid));
+            break;
 
         /* done with formatted area, skip string-set */
         addr += hdr->length;
@@ -562,9 +564,28 @@ smbios_locate_uuid(const struct smbios_entry_point *ep)
 
         /* structure terminator not found */
         if (end - addr < 2)
-            return NULL;
+            return;
 
         addr += 2;
     }
-    return NULL;
+
+    /* parsing finished, 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/smbios.h b/src/smbios.h
index c1fe7f6..5bf0392 100644
--- a/src/smbios.h
+++ b/src/smbios.h
@@ -165,5 +165,5 @@ struct smbios_type_127 {
     struct smbios_structure_header header;
 } PACKED;
 
-const u8 *smbios_locate_uuid(const struct smbios_entry_point *ep);
+void display_uuid(void);
 #endif // smbios.h
diff --git a/src/util.h b/src/util.h
index aafa9b0..7723bb1 100644
--- a/src/util.h
+++ b/src/util.h
@@ -227,7 +227,6 @@ void __set_code_invalid(struct bregs *regs, u32 linecode, const char *fname);
 void __set_code_unimplemented(struct bregs *regs, u32 linecode
                               , const char *fname);
 void hexdump(const void *d, int len);
-void format_uuid(char buf[37], const u8 uuid[16]);
 
 #define dprintf(lvl, fmt, args...) do {                         \
         if (CONFIG_DEBUG_LEVEL && (lvl) <= CONFIG_DEBUG_LEVEL)  \



More information about the SeaBIOS mailing list