[SeaBIOS] [PATCH v2 2/6] bios_date: Make bios date appear once in the ROM

Sam Eiderman posted 6 patches 5 years, 3 months ago
[SeaBIOS] [PATCH v2 2/6] bios_date: Make bios date appear once in the ROM
Posted by Sam Eiderman 5 years, 3 months ago
From: Liran Alon <liran.alon@oracle.com>

We find all the places which cause BIOS_DATE to appear in the data
section and remove them - leaving the only place to contain the contents
of BIOS_DATE to be BiosDate at FSEG(0xfff5).

We do this by removing the usages of BIOS_DATE and by changing
strlen(BIOS_DATE) to sizeof(BIOS_DATE) which works at the preprocessing
step - removing the need to add BIOS_DATE as a string in the data
section.

We will use the fact that BiosDate is now the only place in FSEG
containing the date in the next commit.

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Arbel Moshe <arbel.moshe@oracle.com>
Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com>
Signed-off-by: Liran Alon <liran.alon@oracle.com>
---
 src/fw/biostables.c | 14 +++++++++++---
 src/util.h          |  4 ++++
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/fw/biostables.c b/src/fw/biostables.c
index b055c9b2..546e83c6 100644
--- a/src/fw/biostables.c
+++ b/src/fw/biostables.c
@@ -439,7 +439,7 @@ smbios_romfile_setup(void)
     if (need_t0) {
         /* common case: add our own type 0, with 3 strings and 4 '\0's */
         u16 t0_len = sizeof(struct smbios_type_0) + strlen(BIOS_NAME) +
-                     strlen(VERSION) + strlen(BIOS_DATE) + 4;
+                     strlen(VERSION) + sizeof(BIOS_DATE) + 3;
         ep.structure_table_length += t0_len;
         if (t0_len > ep.max_structure_size)
             ep.max_structure_size = t0_len;
@@ -459,8 +459,16 @@ smbios_romfile_setup(void)
     ep.structure_table_address = (u32)tables;
 
     /* populate final blob */
-    if (need_t0)
-        tables = smbios_new_type_0(tables, BIOS_NAME, VERSION, BIOS_DATE);
+    if (need_t0) {
+        char bios_date[sizeof(BIOS_DATE)];
+        memcpy(bios_date, BiosDate, sizeof("mm/dd/") - 1);
+        memcpy(bios_date + sizeof("mm/dd/") - 1, BIOS_DATE_YEAR_PREFIX,
+               sizeof("yy") - 1);
+        memcpy(bios_date + sizeof("mm/dd/yy") - 1,
+               BiosDate + sizeof("mm/dd/") - 1,
+               sizeof("yy"));
+        tables = smbios_new_type_0(tables, BIOS_NAME, VERSION, bios_date);
+    }
     memcpy(tables, qtables, qtables_len);
     free(qtables);
 
diff --git a/src/util.h b/src/util.h
index 6dd080f6..68ba848d 100644
--- a/src/util.h
+++ b/src/util.h
@@ -2,6 +2,7 @@
 #ifndef __UTIL_H
 #define __UTIL_H
 
+#include "config.h" // BIOS_DATE_SHORT
 #include "types.h" // u32
 
 // apm.c
@@ -243,6 +244,9 @@ void lpt_setup(void);
 // version.c
 extern const char VERSION[], BUILDINFO[];
 
+// misc.c
+extern char BiosDate[sizeof(BIOS_DATE_SHORT)] __aligned(1);
+
 // vgahooks.c
 void handle_155f(struct bregs *regs);
 void handle_157f(struct bregs *regs);
-- 
2.13.3
_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org