[coreboot] New patch to review for coreboot: b8e8ccf build: build coreboot on mingw.

Zheng Bao (zheng.bao@amd.com) gerrit at coreboot.org
Mon Oct 22 09:31:17 CEST 2012


Zheng Bao (zheng.bao at amd.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/1604

-gerrit

commit b8e8ccf9b2e26301ef31cf6d591ffcdf5f4ecdec
Author: Zheng Bao <fishbaozi at gmail.com>
Date:   Mon Oct 22 16:41:42 2012 +0800

    build: build coreboot on mingw.
    
    regex, pdcurses, wsock(for itohl) are seperated libraries. mmap and unmmap are
    ported from git.
    
    Issues:
    1. The length of command line is limited. That makes the Thather can not be built
      because too many obj.o need to be built.
    
    Change-Id: I1d60ec5c7720c1e712e246c4cd12e4b718fed05f
    Signed-off-by: Zheng Bao <zheng.bao at amd.com>
    Signed-off-by: Zheng Bao <fishbaozi at gmail.com>
---
 util/kconfig/lxdialog/check-lxdialog.sh |  2 +-
 util/nvramtool/Makefile.inc             |  5 ++++
 util/nvramtool/accessors/layout-bin.c   |  3 +-
 util/nvramtool/cbfs.c                   |  7 +++++
 util/nvramtool/cli/nvramtool.c          |  4 +++
 util/nvramtool/common.h                 | 15 ++++++++++
 util/nvramtool/lbtable.c                |  3 +-
 util/nvramtool/win32mmap.c              | 49 +++++++++++++++++++++++++++++++++
 8 files changed, 85 insertions(+), 3 deletions(-)

diff --git a/util/kconfig/lxdialog/check-lxdialog.sh b/util/kconfig/lxdialog/check-lxdialog.sh
index 751e99d..4184418 100644
--- a/util/kconfig/lxdialog/check-lxdialog.sh
+++ b/util/kconfig/lxdialog/check-lxdialog.sh
@@ -5,7 +5,7 @@
 ldflags()
 {
 	for ext in so a dylib ; do
-		for lib in ncursesw ncurses curses ; do
+		for lib in ncursesw ncurses curses pdcursesw pdcurses; do
 			$cc -print-file-name=lib${lib}.${ext} | grep / >/dev/null
 			if [ $? -eq 0 ]; then
 				echo "-l${lib}"
diff --git a/util/nvramtool/Makefile.inc b/util/nvramtool/Makefile.inc
index 8471b66..76e837a 100644
--- a/util/nvramtool/Makefile.inc
+++ b/util/nvramtool/Makefile.inc
@@ -35,6 +35,11 @@ nvramtoolobj += cmos_lowlevel.o cmos_ops.o common.o compute_ip_checksum.o
 nvramtoolobj += hexdump.o input_file.o layout.o accessors/layout-common.o accessors/layout-text.o accessors/layout-bin.o lbtable.o
 nvramtoolobj += reg_expr.o cbfs.o accessors/cmos-mem.o
 
+ifeq ($(shell uname -s 2>/dev/null | cut -c-7), MINGW32)
+NVRAMTOOLLDFLAGS += -lregex -lwsock32
+nvramtoolobj += win32mmap.o
+endif
+
 $(objutil)/nvramtool $(objutil)/nvramtool/accessors $(objutil)/nvramtool/cli:
 	mkdir -p $@
 
diff --git a/util/nvramtool/accessors/layout-bin.c b/util/nvramtool/accessors/layout-bin.c
index b910e35..fd3e08c 100644
--- a/util/nvramtool/accessors/layout-bin.c
+++ b/util/nvramtool/accessors/layout-bin.c
@@ -35,9 +35,10 @@
  *  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 \*****************************************************************************/
 
-#include <arpa/inet.h>
 #include <string.h>
+#ifndef __MINGW32__
 #include <sys/mman.h>
+#endif
 #include "common.h"
 #include "coreboot_tables.h"
 #include "ip_checksum.h"
diff --git a/util/nvramtool/cbfs.c b/util/nvramtool/cbfs.c
index 801ee58..febe0be 100644
--- a/util/nvramtool/cbfs.c
+++ b/util/nvramtool/cbfs.c
@@ -19,15 +19,22 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
  */
 
+#ifdef __MINGW32__
+#include <winsock.h>
+#else
 #include <arpa/inet.h>
+#endif
 #include <sys/types.h>
 #include <sys/stat.h>
+#ifndef __MINGW32__
 #include <sys/mman.h>
+#endif
 #include <stdlib.h>
 #include <fcntl.h>
 #include <string.h>
 #include <stdio.h>
 #include "cbfs.h"
+#include "common.h"
 
 #define ALIGN(x,a)              __ALIGN_MASK(x,(typeof(x))(a)-1)
 #define __ALIGN_MASK(x,mask)    (((x)+(mask))&~(mask))
diff --git a/util/nvramtool/cli/nvramtool.c b/util/nvramtool/cli/nvramtool.c
index f283463..7716bd8 100644
--- a/util/nvramtool/cli/nvramtool.c
+++ b/util/nvramtool/cli/nvramtool.c
@@ -31,7 +31,9 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
+#ifndef __MINGW32__
 #include <sys/mman.h>
+#endif
 #include "common.h"
 #include "opts.h"
 #include "lbtable.h"
@@ -164,7 +166,9 @@ int main(int argc, char *argv[])
 						nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_FILE].param);
 				exit(1);
 			}
+#ifndef __MINGW32__
 			fsync(fd);
+#endif
 		}
 
 		cmos_default = mmap(NULL, 128, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
diff --git a/util/nvramtool/common.h b/util/nvramtool/common.h
index 8ad0f65..0ca2829 100644
--- a/util/nvramtool/common.h
+++ b/util/nvramtool/common.h
@@ -58,6 +58,21 @@
 #define LINE_EOF (COMMON_RESULT_START + 0)
 #define LINE_TOO_LONG (COMMON_RESULT_START + 1)
 
+#ifdef __MINGW32__
+#define PROT_READ 1
+#define PROT_WRITE 2
+#define MAP_PRIVATE 1
+
+void *win32_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);
+int win32_munmap(void *start, size_t length);
+
+#define mmap win32_mmap
+#define munmap win32_munmap
+
+#define MAP_FAILED ((void *)-1)
+#define MAP_SHARED 1
+#endif
+
 /* basename of this program, as reported by argv[0] */
 extern const char prog_name[];
 
diff --git a/util/nvramtool/lbtable.c b/util/nvramtool/lbtable.c
index 83597e4..7a968b7 100644
--- a/util/nvramtool/lbtable.c
+++ b/util/nvramtool/lbtable.c
@@ -31,9 +31,10 @@
 
 #include <stdint.h>
 #include <inttypes.h>
-#include <arpa/inet.h>
 #include <string.h>
+#ifndef __MINGW32__
 #include <sys/mman.h>
+#endif
 #include "common.h"
 #include "coreboot_tables.h"
 #include "ip_checksum.h"
diff --git a/util/nvramtool/win32mmap.c b/util/nvramtool/win32mmap.c
new file mode 100644
index 0000000..f44dec8
--- /dev/null
+++ b/util/nvramtool/win32mmap.c
@@ -0,0 +1,49 @@
+#include "common.h"
+#include <windows.h>
+
+static inline size_t xsize_t(off_t len)
+{
+        if (len > (size_t) len)
+                die("Cannot handle files this big");
+        return (size_t)len;
+}
+
+void *win32_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
+{
+	HANDLE hmap;
+	void *temp;
+	off_t len;
+	struct stat st;
+	uint64_t o = offset;
+	uint32_t l = o & 0xFFFFFFFF;
+	uint32_t h = (o >> 32) & 0xFFFFFFFF;
+
+	if (!fstat(fd, &st))
+		len = st.st_size;
+	else
+		printf("mmap: could not determine filesize");
+
+	if ((length + offset) > len)
+		length = xsize_t(len - offset);
+
+	if (!(flags & MAP_PRIVATE))
+		printf("Invalid usage of mmap when built with USE_WIN32_MMAP");
+
+	hmap = CreateFileMapping((HANDLE)_get_osfhandle(fd), 0, PAGE_WRITECOPY,
+		0, 0, 0);
+
+	if (!hmap)
+		return MAP_FAILED;
+
+	temp = MapViewOfFileEx(hmap, FILE_MAP_COPY, h, l, length, start);
+
+	if (!CloseHandle(hmap))
+		printf("unable to close file mapping handle");
+
+	return temp ? temp : MAP_FAILED;
+}
+
+int win32_munmap(void *start, size_t length)
+{
+	return !UnmapViewOfFile(start);
+}




More information about the coreboot mailing list