diff mbox series

lib: fwts_memorymap: fix failure to retrieve BIOS memory map from dmesg e820

Message ID 20250513101420.7086-1-ivan.hu@canonical.com
State Accepted
Headers show
Series lib: fwts_memorymap: fix failure to retrieve BIOS memory map from dmesg e820 | expand

Commit Message

Ivan Hu May 13, 2025, 10:14 a.m. UTC
BugLink: https://bugs.launchpad.net/fwts/+bug/2110534

The current kernel logs memory map entries using the prefix "BIOS-e820:"
instead of the older "BIOS-memory_map:". Update the parser to also check
for "BIOS-e820:" to ensure memory map information can still be extracted
from dmesg.

Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
---
 src/lib/src/fwts_memorymap.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/src/lib/src/fwts_memorymap.c b/src/lib/src/fwts_memorymap.c
index 4c7b6377..4e55b720 100644
--- a/src/lib/src/fwts_memorymap.c
+++ b/src/lib/src/fwts_memorymap.c
@@ -64,9 +64,9 @@  static int fwts_memory_map_str_to_type(const char *str)
 
 	/* Strings from kernel log */
 
-	if (strstr(str, "(usable)"))
+	if (strstr(str, "usable"))
 		return FWTS_MEMORY_MAP_USABLE;
-	if (strstr(str, "(reserved)"))
+	if (strstr(str, "reserved"))
 		return FWTS_MEMORY_MAP_RESERVED;
 	if (strstr(str, "ACPI"))
 		return FWTS_MEMORY_MAP_ACPI;
@@ -199,6 +199,22 @@  static void fwts_memory_map_dmesg_info(void *data, void *private)
 				return;
 			fwts_register_memory_map_line(memory_map_list, start, end - 1, fwts_memory_map_str_to_type(line));
 		}
+	} else if ((str = strstr(line,"BIOS-e820:")) != NULL) {
+		uint64_t start;
+
+		errno = 0;
+		start = strtoull(str + sizeof("BIOS-e820: [mem 0x"), NULL, 16);
+		if (errno != 0)
+			return;
+		str = strstr(line,"-0x");
+		if (str) {
+			uint64_t end;
+			errno = 0;
+			end = strtoull(str + sizeof("-0x"), NULL, 16);
+			if (errno != 0 || end == 0)
+				return;
+			fwts_register_memory_map_line(memory_map_list, start, end - 1, fwts_memory_map_str_to_type(line));
+		}
 	}
 }