summaryrefslogtreecommitdiff
path: root/util/nvramtool
diff options
context:
space:
mode:
authorZheng Bao <fishbaozi@gmail.com>2012-10-22 16:41:42 +0800
committerPatrick Georgi <patrick@georgi-clan.de>2012-10-22 21:49:54 +0200
commit545167252d564ed13a669f62a29a5a2640c55a43 (patch)
tree3b75a5fde02b94291440edccb3899950b4502493 /util/nvramtool
parentc31cdd8662e770fb17a9c78e2fc508967c4795f2 (diff)
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@amd.com> Signed-off-by: Zheng Bao <fishbaozi@gmail.com> Reviewed-on: http://review.coreboot.org/1604 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <patrick@georgi-clan.de>
Diffstat (limited to 'util/nvramtool')
-rw-r--r--util/nvramtool/Makefile.inc5
-rw-r--r--util/nvramtool/accessors/layout-bin.c3
-rw-r--r--util/nvramtool/cbfs.c7
-rw-r--r--util/nvramtool/cli/nvramtool.c4
-rw-r--r--util/nvramtool/common.h15
-rw-r--r--util/nvramtool/lbtable.c3
-rw-r--r--util/nvramtool/win32mmap.c49
7 files changed, 84 insertions, 2 deletions
diff --git a/util/nvramtool/Makefile.inc b/util/nvramtool/Makefile.inc
index 8471b66cbc..76e837a981 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 b910e358b6..fd3e08cdf0 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 801ee586b3..febe0bed07 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 f283463f94..7716bd8710 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 8ad0f65a38..0ca2829417 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 83597e4ee9..7a968b7222 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 0000000000..f44dec88fc
--- /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);
+}