[coreboot] r4013 - trunk/util/nvramtool

svn at coreboot.org svn at coreboot.org
Tue Mar 17 15:39:36 CET 2009


Author: stepan
Date: 2009-03-17 15:39:36 +0100 (Tue, 17 Mar 2009)
New Revision: 4013

Modified:
   trunk/util/nvramtool/coreboot_tables.h
   trunk/util/nvramtool/lbtable.c
Log:
This patch adds "high coreboot table support" to coreboot version 2.

Some bootloaders seem to overwrite memory starting at 0x600, thus destroying
the coreboot table integrity, rendering the table useless.

By moving the table to the high tables area (if it's activated), this problem
is fixed.

In order to move the table, a 40 bytes mini coreboot table with a single sub
table is placed at 0x500/0x530 that points to the real coreboot table. This is
comparable to the ACPI RSDT or the MP floating table.

This patch also adds "table forward" support to flashrom and nvramtool.

Signed-off-by: Stefan Reinauer <stepan at coresystems.de>
Acked-by: Peter Stuge <peter at stuge.se>




Modified: trunk/util/nvramtool/coreboot_tables.h
===================================================================
--- trunk/util/nvramtool/coreboot_tables.h	2009-03-17 14:39:25 UTC (rev 4012)
+++ trunk/util/nvramtool/coreboot_tables.h	2009-03-17 14:39:36 UTC (rev 4013)
@@ -146,6 +146,14 @@
         uint32_t size;
         uint8_t  string[0];
 };
+#define LB_TAG_SERIAL		0x000f
+#define LB_TAG_CONSOLE		0x0010
+#define LB_TAG_FORWARD		0x0011
+struct lb_forward {
+	uint32_t tag;
+	uint32_t size;
+	uint64_t forward;
+};
 
 /* The following structures are for the cmos definitions table */
 #define LB_TAG_CMOS_OPTION_TABLE 200

Modified: trunk/util/nvramtool/lbtable.c
===================================================================
--- trunk/util/nvramtool/lbtable.c	2009-03-17 14:39:25 UTC (rev 4012)
+++ trunk/util/nvramtool/lbtable.c	2009-03-17 14:39:36 UTC (rev 4013)
@@ -149,6 +149,8 @@
 "%s: Item %s not found in coreboot table. Apparently, you are "
 "using coreboot v1.\n";
 
+int fd;
+
 /* This is the number of items from the coreboot table that may be displayed
  * using the -l option.
  */
@@ -240,6 +242,7 @@
  * /dev/mem.
  */
 static const void *low_phys_mem;
+static unsigned long low_phys_base = 0;
 
 /* Pointer to coreboot table. */
 static const struct lb_header *lbtable = NULL;
@@ -261,7 +264,7 @@
  * /dev/mem.  This macro converts 'vaddr' to a physical address.
  ****************************************************************************/
 #define vtophys(vaddr) (((unsigned long) vaddr) -       \
-                        ((unsigned long) low_phys_mem))
+                        ((unsigned long) low_phys_mem) + low_phys_base)
 
 /****************************************************************************
  * phystov
@@ -272,7 +275,7 @@
  * by calling mmap() on /dev/mem.
  ****************************************************************************/
 #define phystov(paddr) (((unsigned long) low_phys_mem) + \
-                        ((unsigned long) paddr))
+                        ((unsigned long) paddr) - low_phys_base)
 
 /****************************************************************************
  * get_lbtable
@@ -280,7 +283,7 @@
  * Find the coreboot table and set global variable lbtable to point to it.
  ****************************************************************************/
 void get_lbtable (void)
- { int fd, i, bad_header_count, bad_table_count, bad_headers, bad_tables;
+ { int i, bad_header_count, bad_table_count, bad_headers, bad_tables;
 
    if (lbtable != NULL)
       return;
@@ -494,6 +497,7 @@
                                               int *bad_table_count)
  { static const char signature[] = { 'L', 'B', 'I', 'O' };
    const struct lb_header *table;
+   const struct lb_forward *forward;
    const uint32_t *p;
    uint32_t sig;
 
@@ -534,6 +538,25 @@
        }
 
       /* checksums are ok: we found it! */
+      /* But it may just be a forwarding table, so look if there's a forwarder */
+      lbtable = table;
+      forward = (struct lb_forward *)find_lbrec(LB_TAG_FORWARD);
+      lbtable = NULL;
+
+      if (forward) {
+        uint64_t new_phys = forward->forward;
+
+	new_phys &= ~(getpagesize()-1);
+	
+        munmap((void *)low_phys_mem, BYTES_TO_MAP);
+        if ((low_phys_mem = mmap(NULL, BYTES_TO_MAP, PROT_READ, MAP_SHARED, fd, (off_t)new_phys)) == MAP_FAILED)
+        { fprintf(stderr, "%s: Failed to mmap /dev/mem: %s\n", prog_name,
+              strerror(errno));
+          exit(1);
+        }
+	low_phys_base = new_phys;
+	table = lbtable_scan(phystov(low_phys_base), phystov(low_phys_base + BYTES_TO_MAP), bad_header_count, bad_table_count);
+      }
       return table;
     }
 
@@ -865,6 +888,15 @@
       case LB_TAG_ASSEMBLER:
          return "ASSEMBLER";
 
+      case LB_TAG_SERIAL:
+         return "SERIAL";
+
+      case LB_TAG_CONSOLE:
+	 return "CONSOLE";
+
+      case LB_TAG_FORWARD:
+	 return "FORWARD";
+
       case LB_TAG_CMOS_OPTION_TABLE:
          return "CMOS_OPTION_TABLE";
 





More information about the coreboot mailing list