Author: stuge
Date: 2009-01-26 02:23:31 +0100 (Mon, 26 Jan 2009)
New Revision: 3905

Modified:
   trunk/util/flashrom/Makefile
   trunk/util/flashrom/cbtable.c
   trunk/util/flashrom/flash.h
   trunk/util/flashrom/physmap.c
Log:
flashrom: Darwin / Mac OS X

Through DirectIO from coresystems GmbH we now support Darwin/Mac OS X.
DirectIO is available at http://www.coresystems.de/en/directio

Signed-off-by: Stefan Reinauer <[email protected]>
Signed-off-by: Peter Stuge <[email protected]>
Acked-by: Peter Stuge <[email protected]>


Modified: trunk/util/flashrom/Makefile
===================================================================
--- trunk/util/flashrom/Makefile        2009-01-26 01:16:09 UTC (rev 3904)
+++ trunk/util/flashrom/Makefile        2009-01-26 01:23:31 UTC (rev 3905)
@@ -18,6 +18,10 @@
 ifneq ($(OS_ARCH), SunOS)
 STRIP_ARGS = -s
 endif
+ifeq ($(OS_ARCH), Darwin)
+CFLAGS += -I/usr/local/include
+LDFLAGS += -framework IOKit -framework DirectIO -L/usr/local/lib
+endif
 ifeq ($(OS_ARCH), FreeBSD)
 CFLAGS += -I/usr/local/include
 LDFLAGS += -L/usr/local/lib

Modified: trunk/util/flashrom/cbtable.c
===================================================================
--- trunk/util/flashrom/cbtable.c       2009-01-26 01:16:09 UTC (rev 3904)
+++ trunk/util/flashrom/cbtable.c       2009-01-26 01:23:31 UTC (rev 3905)
@@ -184,11 +184,20 @@
 int coreboot_init(void)
 {
        uint8_t *low_1MB;
-       unsigned long addr;
+       unsigned long addr, start;
        struct lb_header *lb_table;
        struct lb_record *rec, *last;
 
-       low_1MB = physmap("low megabyte", 0x0, 1024*1024);
+#ifdef __DARWIN__
+       /* This is a hack. DirectIO fails to map physical address 0x00000000.
+        * Why?
+        */
+       start = 0x400;
+#else
+       start = 0x0;
+#endif
+       low_1MB = physmap("low megabyte", start, 1024*1024);
+
        lb_table = find_lb_table(low_1MB, 0x00000, 0x1000);
        if (!lb_table)
                lb_table = find_lb_table(low_1MB, 0xf0000, 1024*1024);
@@ -197,8 +206,8 @@
                return -1;
        }
 
-       addr = ((char *)lb_table) - ((char *)low_1MB);
-       printf_debug("coreboot table found at %p.\n", lb_table);
+       addr = ((char *)lb_table) - ((char *)low_1MB) + start;
+       printf_debug("coreboot table found at %p.\n", lb_table + start);
        rec = (struct lb_record *)(((char *)lb_table) + lb_table->header_bytes);
        last = (struct lb_record *)(((char *)rec) + lb_table->table_bytes);
        printf_debug("coreboot header(%d) checksum: %04x table(%d) checksum: 
%04x entries: %d\n",

Modified: trunk/util/flashrom/flash.h
===================================================================
--- trunk/util/flashrom/flash.h 2009-01-26 01:16:09 UTC (rev 3904)
+++ trunk/util/flashrom/flash.h 2009-01-26 01:23:31 UTC (rev 3905)
@@ -30,6 +30,10 @@
 #include <stdint.h>
 #include <stdio.h>
 
+#if (defined(__MACH__) && defined(__APPLE__))
+#define __DARWIN__
+#endif
+
 #if defined(__FreeBSD__)
   #include <machine/cpufunc.h>
   #define off64_t off_t
@@ -41,6 +45,11 @@
   #define INW(x) __extension__ ({ u_int tmp = (x); inw(tmp); })
   #define INL(x) __extension__ ({ u_int tmp = (x); inl(tmp); })
 #else
+#if defined(__DARWIN__)
+    #include <DirectIO/darwinio.h>
+    #define off64_t off_t
+    #define lseek64 lseek
+#endif
   #define OUTB outb
   #define OUTW outw
   #define OUTL outl

Modified: trunk/util/flashrom/physmap.c
===================================================================
--- trunk/util/flashrom/physmap.c       2009-01-26 01:16:09 UTC (rev 3904)
+++ trunk/util/flashrom/physmap.c       2009-01-26 01:23:31 UTC (rev 3905)
@@ -1,4 +1,3 @@
-#include <sys/mman.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -6,6 +5,24 @@
 #include <errno.h>
 #include "flash.h"
 
+#ifdef __DARWIN__
+#include <DirectIO/darwinio.h>
+
+#define MEM_DEV "DirectIO"
+
+void *sys_physmap(unsigned long phys_addr, size_t len)
+{
+       return map_physical(phys_addr, len);
+}
+
+void physunmap(void *virt_addr, size_t len)
+{
+       unmap_physical(virt_addr, len);
+}
+
+#else
+#include <sys/mman.h>
+
 #if defined (__sun) && (defined(__i386) || defined(__amd64))
 #  define MEM_DEV "/dev/xsvc"
 #else
@@ -34,6 +51,7 @@
 {
        munmap(virt_addr, len);
 }
+#endif
 
 void *physmap(const char *descr, unsigned long phys_addr, size_t len)
 {


--
coreboot mailing list: [email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to