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>
This commit is contained in:
Zheng Bao 2012-10-22 16:41:42 +08:00 committed by Patrick Georgi
parent c31cdd8662
commit 545167252d
8 changed files with 85 additions and 3 deletions

View File

@ -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}"

View File

@ -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 $@

View File

@ -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"

View File

@ -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))

View File

@ -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);

View File

@ -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[];

View File

@ -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"

View File

@ -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);
}