Stefan Reinauer (stefan.reina...@coreboot.org) just uploaded a new patch set to 
gerrit, which you can find at http://review.coreboot.org/2117

-gerrit

commit 47f24e8b47fe7521650f5766451b28354828fa63
Author: Stefan Reinauer <stefan.reina...@coreboot.org>
Date:   Mon Jan 7 16:26:10 2013 -0800

    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 <reina...@google.com>
---
 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 4c0bd68..4d1a7b5 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;
@@ -319,6 +336,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<MAX_CBMEM_ENTRIES; i++) {
+               if (entries[i].magic != CBMEM_MAGIC)
+                       break;
+               
+               printf("%2d. ", i);
+               switch (entries[i].id) {
+               case CBMEM_ID_FREESPACE: printf("FREE SPACE  "); break;
+               case CBMEM_ID_GDT:       printf("GDT         "); break;
+               case CBMEM_ID_ACPI:      printf("ACPI        "); break;
+               case CBMEM_ID_ACPI_GNVS: printf("ACPI GNVS   "); break;
+               case CBMEM_ID_CBTABLE:   printf("COREBOOTE   "); break;
+               case CBMEM_ID_PIRQ:      printf("IRQ TABLE   "); break;
+               case CBMEM_ID_MPTABLE:   printf("SMP TABLE   "); break;
+               case CBMEM_ID_RESUME:    printf("ACPI RESUME "); break;
+               case CBMEM_ID_RESUME_SCRATCH: printf("ACPI SCRATCH"); break;
+               case CBMEM_ID_SMBIOS:    printf("SMBIOS      "); break;
+               case CBMEM_ID_TIMESTAMP: printf("TIME STAMP  "); break;
+               case CBMEM_ID_MRCDATA:   printf("MRC DATA    "); break;
+               case CBMEM_ID_CONSOLE:   printf("CONSOLE     "); break;
+               case CBMEM_ID_ELOG:      printf("ELOG        "); break;
+               default:                 printf("%08x    ",
+                                               entries[i].id); break;
+               }
+               printf(" 0x%08jx 0x%08jx\n", (uintmax_t)entries[i].base,
+                        (uintmax_t)entries[i].size);
+       }
+       unmap_memory();
+}
 
 void print_version(void)
 {
@@ -341,6 +413,7 @@ void print_usage(const char *name)
        printf("usage: %s [-vh?]\n", name);
        printf("\n"
             "   -c | --console:                   print cbmem console\n"
+            "   -l | --list:                      print cbmem table of 
contents\n"
             "   -t | --timestamps:                print timestamp 
information\n"
             "   -V | --verbose:                   verbose (debugging) output\n"
             "   -v | --version:                   print the version\n"
@@ -356,24 +429,30 @@ int main(int argc, char** argv)
 
        int print_defaults = 1;
        int print_console = 0;
+       int print_list = 0;
        int print_timestamps = 0;
 
        int opt, option_index = 0;
        static struct option long_options[] = {
                {"console", 0, 0, 'c'},
+               {"list", 0, 0, 'l'},
                {"timestamps", 0, 0, 't'},
                {"verbose", 0, 0, 'V'},
                {"version", 0, 0, 'v'},
                {"help", 0, 0, 'h'},
                {0, 0, 0, 0}
        };
-       while ((opt = getopt_long(argc, argv, "ctVvh?",
+       while ((opt = getopt_long(argc, argv, "cltVvh?",
                                  long_options, &option_index)) != EOF) {
                switch (opt) {
                case 'c':
                        print_console = 1;
                        print_defaults = 0;
                        break;
+               case 'l':
+                       print_list = 1;
+                       print_defaults = 0;
+                       break;
                case 't':
                        print_timestamps = 1;
                        print_defaults = 0;
@@ -410,6 +489,9 @@ int main(int argc, char** argv)
        if (print_console)
                dump_console();
 
+       if (print_list)
+               dump_cbmem_toc();
+
        if (print_defaults || print_timestamps)
                dump_timestamps();
 

-- 
coreboot mailing list: coreboot@coreboot.org
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to