From c01990789f533316e10c5fc3b5ca08ae866b8033 Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Mon, 7 Jan 2013 16:26:10 -0800 Subject: [PATCH] cbmem utility: Find actual CBMEM area ... without the need for a coreboot table entry for each of them. Change-Id: I2917710fb9d00c4533d81331a362bf0c40a30353 Signed-off-by: Stefan Reinauer Reviewed-on: http://review.coreboot.org/2117 Tested-by: build bot (Jenkins) Reviewed-by: Ronald G. Minnich --- util/cbmem/cbmem.c | 84 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c index 59d054046e..a777a8f302 100644 --- a/util/cbmem/cbmem.c +++ b/util/cbmem/cbmem.c @@ -118,6 +118,7 @@ static void unmap_memory(void) static struct lb_cbmem_ref timestamps; static struct lb_cbmem_ref console; +static struct lb_memory_range cbmem; static int parse_cbtable(u64 address) { @@ -157,6 +158,22 @@ static int parse_cbtable(u64 address) lbr_p = (struct lb_record*) ((char *)lbtable + j); debug(" coreboot table entry 0x%02x\n", lbr_p->tag); switch (lbr_p->tag) { + case LB_TAG_MEMORY: { + int i = 0; + debug(" Found memory map.\n"); + struct lb_memory *memory = + (struct lb_memory *)lbr_p; + while ((char *)&memory->map[i] < ((char *)lbtable + + lbr_p->size)) { + if (memory->map[i].type == LB_MEM_TABLE) { + debug(" LB_MEM_TABLE found.\n"); + /* The last one found is CBMEM */ + cbmem = memory->map[i]; + } + i++; + } + continue; + } case LB_TAG_TIMESTAMPS: { debug(" Found timestamp table.\n"); timestamps = *(struct lb_cbmem_ref *) lbr_p; @@ -320,6 +337,61 @@ static void dump_console(void) unmap_memory(); } +#define CBMEM_MAGIC 0x434f5245 +#define MAX_CBMEM_ENTRIES 16 + +struct cbmem_entry { + uint32_t magic; + uint32_t id; + uint64_t base; + uint64_t size; +}; + +void dump_cbmem_toc(void) +{ + int i; + uint64_t start; + struct cbmem_entry *entries; + + if (cbmem.type != LB_MEM_TABLE) { + fprintf(stderr, "No coreboot table area found!\n"); + return; + } + + start = unpack_lb64(cbmem.start); + + entries = (struct cbmem_entry *)map_memory(start); + + printf("CBMEM table of contents:\n"); + printf(" ID START LENGTH\n"); + for (i=0; i