[coreboot-gerrit] New patch to review for coreboot: WIP: cbmem: get table start address via /proc/iomem

Matt DeVillier (matt.devillier@gmail.com) gerrit at coreboot.org
Sun Dec 18 07:23:16 CET 2016


Matt DeVillier (matt.devillier at gmail.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/17914

-gerrit

commit 072ff80e405c094bdc808a6890d9d727f4150c3c
Author: Matt DeVillier <matt.devillier at gmail.com>
Date:   Sun Dec 18 00:09:41 2016 -0600

    WIP: cbmem: get table start address via /proc/iomem
    
    The cbmem table forwarding entry located below 1MB isn't always
    available (e.g., when overwritten by the payload), which causes
    lookup to fail.  Since the cbmem table address is exposed thru
    /proc/iomem, parse iomem for the table start address and use
    that as a possible base address.
    
    TEST: run cbmem and retrive console, timestamps etc when forwarding
    entry not available (e.g, CorebootPayloadPkg is used)
    
    Change-Id: I099b7610499aea73242713bc5ba0c0b98fcbb995
    Signed-off-by: Matt DeVillier <matt.devillier at gmail.com>
---
 util/cbmem/cbmem.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 90 insertions(+), 1 deletion(-)

diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c
index 7b434d87..b04d1f7 100644
--- a/util/cbmem/cbmem.c
+++ b/util/cbmem/cbmem.c
@@ -1019,6 +1019,93 @@ static char *dt_find_compat(const char *parent, const char *compat,
 }
 #endif /* __arm__ */
 
+char *_read_proc_iomem(void)
+{
+	int fd;
+	off_t size;
+	char *contents;
+
+	fd = open("/proc/iomem", O_RDONLY);
+
+	if (fd == -1) {
+		fprintf(stderr, "Unable to open /proc/iomem");
+		exit(1);
+	}
+
+	size = 1000000;
+
+	contents = malloc(size + 2);
+
+	if (contents == NULL) {
+		fprintf(stderr, "Unable to allocate buffer for reading /proc/iomem");
+		exit(1);
+	}
+
+	*(contents + size + 1) = 0x00;
+
+	if (read(fd, contents, size) < 1) {
+		fprintf(stderr, "Unable to read /proc/iomem");
+		exit(1);
+	}
+
+	close(fd);
+
+	return contents;
+}
+
+unsigned long long get_cbmem_start_addr(void)
+{
+	off_t size;
+	off_t curoff;
+	char *contents;
+	char *cur;
+	char *curn;
+	char *dash;
+	unsigned long long start = 0;
+
+	contents = _read_proc_iomem();
+
+	curoff = 0;
+
+	size = strlen(contents);
+
+	while (curoff < size)
+	{
+		// break up by newline
+		cur = contents + curoff;
+		curn = strstr(cur, "\n");
+
+		if (curn == NULL)
+			break;
+
+		*curn = 0x00;
+
+		// skip to next line if not CBMEM
+		if (strstr(cur, "GOOGCB00") == NULL)
+		{
+			curoff = curoff + curn - cur + 1;
+			continue;
+		}
+
+		//trim leading whitespace
+		while (cur[0] == 0x20) {
+			cur += 1;
+		}
+
+		dash = strstr(cur, "-");
+
+		if (dash == NULL) {
+			fprintf(stderr, "get_cbmem_start_addr: Line broke parser: %s", cur);
+			exit(1);
+		}
+
+		*dash   = 0x00;
+
+		start = strtoull(cur, NULL, 16);
+	}
+	return start;
+}
+
 int main(int argc, char** argv)
 {
 	int print_defaults = 1;
@@ -1030,6 +1117,7 @@ int main(int argc, char** argv)
 	int print_timestamps = 0;
 	int machine_readable_timestamps = 0;
 	unsigned int rawdump_id = 0;
+	unsigned long long start = 0;
 
 	int opt, option_index = 0;
 	static struct option long_options[] = {
@@ -1156,7 +1244,8 @@ int main(int argc, char** argv)
 	parse_cbtable(baseaddr, cb_table_size, 1);
 #else
 	int j;
-	static const int possible_base_addresses[] = { 0, 0xf0000 };
+	start = get_cbmem_start_addr();
+	int possible_base_addresses[] = { 0, start, 0xf0000 };
 
 	/* Find and parse coreboot table */
 	for (j = 0; j < ARRAY_SIZE(possible_base_addresses); j++) {



More information about the coreboot-gerrit mailing list