Hi folks,

I want to put forth this patch for your review.

In my opinion, it is very useful to know just after your machine has
POSTed how much system RAM the machine has access to.

This patch prints out to the screen just under the UUID the following line:
        System RAM: X MB

where X is the number of whole megabytes available to the system.

Since the memory map is already available to SeaBIOS, I think it makes
sense to total up the sizes of regions marked as E820_RAM and print the
grand total.

I have tested this on a coreboot QEMU bios with custom SeaBIOS built:

        SeaBIOS (version rel-1.11.0-46-g18e193d)
        System RAM: 1022 MB

When I tried flashing a compatible image to my Lenovo X220 laptop it
bricked it.  I'm not sure why, maybe I compiled it wrong or inserted it
into my image wrongly with cbfstool.

Cheers,
Damien
>From 18e193deeebee1deabf64d3189b49390246d46f9 Mon Sep 17 00:00:00 2001
From: Damien Zammit <[email protected]>
Date: Sat, 8 Sep 2018 11:47:27 +1000
Subject: [PATCH] Add total usable memory in MB to console bootsplash

---
 src/bootsplash.c |  2 ++
 src/e820map.c    | 22 ++++++++++++++++++++++
 src/e820map.h    |  1 +
 3 files changed, 25 insertions(+)

diff --git a/src/bootsplash.c b/src/bootsplash.c
index 165c98d..9ca9062 100644
--- a/src/bootsplash.c
+++ b/src/bootsplash.c
@@ -15,6 +15,7 @@
 #include "std/vbe.h" // struct vbe_info
 #include "string.h" // memset
 #include "util.h" // enable_bootsplash
+#include "e820map.h" // print total mem
 
 
 /****************************************************************
@@ -50,6 +51,7 @@ enable_vga_console(void)
     // Write to screen.
     printf("SeaBIOS (version %s)\n", VERSION);
     display_uuid();
+    e820_total_memory();
 }
 
 static int
diff --git a/src/e820map.c b/src/e820map.c
index 39445cf..61c5eeb 100644
--- a/src/e820map.c
+++ b/src/e820map.c
@@ -72,6 +72,21 @@ dump_map(void)
     }
 }
 
+// Get the total usable memory in MB
+static u32
+get_total_mb(void)
+{
+    int i;
+    u64 total = 0;
+    for (i=0; i<e820_count; i++) {
+        struct e820entry *e = &e820_list[i];
+        if (e->type == E820_RAM) {
+            total += e->size;
+        }
+    }
+    return (u32)(total >> 20);
+}
+
 #define E820_HOLE         ((u32)-1) // Used internally to remove entries
 
 // Add a new entry to the list.  This scans for overlaps and keeps the
@@ -150,3 +165,10 @@ e820_prepboot(void)
 {
     dump_map();
 }
+
+// Print total memory in MB
+void
+e820_total_memory(void)
+{
+    printf("System RAM: %d MB\n", get_total_mb());
+}
diff --git a/src/e820map.h b/src/e820map.h
index de8b523..34e7265 100644
--- a/src/e820map.h
+++ b/src/e820map.h
@@ -18,6 +18,7 @@ struct e820entry {
 void e820_add(u64 start, u64 size, u32 type);
 void e820_remove(u64 start, u64 size);
 void e820_prepboot(void);
+void e820_total_memory(void);
 
 // e820 map storage
 extern struct e820entry e820_list[];
-- 
2.13.1

_______________________________________________
SeaBIOS mailing list
[email protected]
https://mail.coreboot.org/mailman/listinfo/seabios

Reply via email to