New version, more improvements.
Move Mac OS X IOKit/DirectHW availability checks in the Makefile from compiler check to pciutils check.
Add DOS libpci in the Makefile includes only if a PCI-based programmer was requested.
Restrict mmap usage in ich_descriptors_tool to Unix style systems.
Build ich_descriptors_tool with the correct .exe extension on DOS/Windows.
Build ich_descriptors_tool by default. (Patch by Stefan Tauner)
Print the Windows version instead of "unknown machine" on Windows.
Don't #define our own __DARWIN__, use the standard OS X detection method.
Update the README.
I tested native compilation on Linux x86, cross-compilation on Linux for MinGW and DJGPP, and cross-compilation for Linux-arm. Tests on OS X and non-x86 platforms appreciated. Simply running "make" with no other parameters should work on every platform/OS if you're compiling native code.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-portability-fixes/hwaccess.h =================================================================== --- flashrom-portability-fixes/hwaccess.h (Revision 1547) +++ flashrom-portability-fixes/hwaccess.h (Arbeitskopie) @@ -180,10 +180,6 @@ #include <asm/sunddi.h> #endif
-#if (defined(__MACH__) && defined(__APPLE__)) -#define __DARWIN__ -#endif - /* Clarification about OUTB/OUTW/OUTL argument order: * OUT[BWL](val, port) */ @@ -203,7 +199,7 @@ #define INW(x) __extension__ ({ u_int inw_tmp = (x); inw(inw_tmp); }) #define INL(x) __extension__ ({ u_int inl_tmp = (x); inl(inl_tmp); }) #else -#if defined(__DARWIN__) +#if defined(__MACH__) && defined(__APPLE__) /* Header is part of the DirectHW library. */ #include <DirectHW/DirectHW.h> #define off64_t off_t @@ -303,7 +299,7 @@ #endif #endif
-#if !defined(__DARWIN__) && !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__) && !defined(__LIBPAYLOAD__) +#if !(defined(__MACH__) && defined(__APPLE__)) && !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__) && !defined(__LIBPAYLOAD__) typedef struct { uint32_t hi, lo; } msr_t; msr_t rdmsr(int addr); int wrmsr(int addr, msr_t msr); Index: flashrom-portability-fixes/Makefile =================================================================== --- flashrom-portability-fixes/Makefile (Revision 1547) +++ flashrom-portability-fixes/Makefile (Arbeitskopie) @@ -20,6 +20,12 @@
PROGRAM = flashrom
+############################################################################### +# Defaults for the toolchain. + +# If you want to cross-compile, just run +# make CC=i586-pc-msdosdjgpp-gcc +# You may have to specify STRIP/AR/RANLIB as well. CC ?= gcc STRIP ?= strip INSTALL = install @@ -31,12 +37,17 @@ AR ?= ar RANLIB ?= ranlib
+# If your compiler spits out excessive warnings, run make WARNERROR=no +# You shouldn't need this flag. WARNERROR ?= yes
ifeq ($(WARNERROR), yes) CFLAGS += -Werror endif
+############################################################################### +# General OS/architecture specific settings. + # HOST_OS is only used to work around local toolchain issues. HOST_OS ?= $(shell uname) ifeq ($(HOST_OS), MINGW32_NT-5.1) @@ -47,7 +58,7 @@ STRIP_ARGS = -s endif
-# Determine the destination processor architecture. +# Determine the destination OS. # IMPORTANT: The following line must be placed before TARGET_OS is ever used # (of course), but should come after any lines setting CC because the line # below uses CC itself. @@ -55,25 +66,27 @@
ifeq ($(TARGET_OS), Darwin) CPPFLAGS += -I/opt/local/include -I/usr/local/include -# DirectHW framework can be found in the DirectHW library. -LDFLAGS += -framework IOKit -framework DirectHW -L/opt/local/lib -L/usr/local/lib +LDFLAGS += -L/opt/local/lib -L/usr/local/lib endif + ifeq ($(TARGET_OS), FreeBSD) CPPFLAGS += -I/usr/local/include LDFLAGS += -L/usr/local/lib endif + ifeq ($(TARGET_OS), OpenBSD) CPPFLAGS += -I/usr/local/include LDFLAGS += -L/usr/local/lib endif + ifeq ($(TARGET_OS), DOS) EXEC_SUFFIX := .exe -CPPFLAGS += -I../libgetopt -I../libpci/include +CPPFLAGS += -I../libgetopt # DJGPP has odd uint*_t definitions which cause lots of format string warnings. CPPFLAGS += -Wno-format # FIXME Check if we can achieve the same effect with -L../libgetopt -lgetopt LIBS += ../libgetopt/libgetopt.a -# Bus Pirate and Serprog are not supported under DOS (missing serial support). +# Bus Pirate, Serprog and PonyProg are not supported under DOS (missing serial support). ifeq ($(CONFIG_BUSPIRATE_SPI), yes) UNSUPPORTED_FEATURES += CONFIG_BUSPIRATE_SPI=yes else @@ -84,6 +97,11 @@ else override CONFIG_SERPROG = no endif +ifeq ($(CONFIG_PONY_SPI), yes) +UNSUPPORTED_FEATURES += CONFIG_PONY_SPI=yes +else +override CONFIG_PONY_SPI = no +endif # Dediprog and FT2232 are not supported under DOS (missing USB support). ifeq ($(CONFIG_DEDIPROG), yes) UNSUPPORTED_FEATURES += CONFIG_DEDIPROG=yes @@ -258,18 +276,31 @@ endif endif
+############################################################################### +# Flash chip drivers and bus support infrastructure. + CHIP_OBJS = jedec.o stm50flw0x0x.o w39.o w29ee011.o \ sst28sf040.o m29f400bt.o 82802ab.o pm49fl00x.o \ sst49lfxxxc.o sst_fwhub.o flashchips.o spi.o spi25.o \ a25.o at25.o opaque.o sfdp.o en29lv640b.o
-LIB_OBJS = layout.o +############################################################################### +# Library code.
-CLI_OBJS = flashrom.o cli_classic.o cli_output.o print.o +LIB_OBJS = layout.o flashrom.o
+############################################################################### +# Frontend related stuff. + +CLI_OBJS = cli_classic.o cli_output.o print.o + +############################################################################### +# Programmer drivers and programmer support infrastructure. + PROGRAMMER_OBJS = udelay.o programmer.o
all: pciutils features $(PROGRAM)$(EXEC_SUFFIX) + @+make -C util/ich_descriptors_tool/ EXEC_SUFFIX=$(EXEC_SUFFIX)
# Set the flashrom version string from the highest revision number # of the checked out flashrom files. @@ -531,10 +562,19 @@ ifeq ($(TARGET_OS), OpenBSD) # For (i386|amd64)_iopl(2). LIBS += -l$(shell uname -m) +else +ifeq ($(TARGET_OS), Darwin) +# DirectHW framework can be found in the DirectHW library. +LIBS += -framework IOKit -framework DirectHW +else +ifeq ($(TARGET_OS), DOS) +CPPFLAGS += -I../libpci/include endif endif endif endif +endif +endif
ifeq ($(CONFIG_PRINT_WIKI), yes) FEATURE_CFLAGS += -D'CONFIG_PRINT_WIKI=1' @@ -569,6 +609,7 @@ # We don't use EXEC_SUFFIX here because we want to clean everything. clean: rm -f $(PROGRAM) $(PROGRAM).exe libflashrom.a *.o *.d + @+make -C util/ich_descriptors_tool/ clean EXEC_SUFFIX=$(EXEC_SUFFIX)
distclean: clean rm -f .features .libdeps Index: flashrom-portability-fixes/util/ich_descriptors_tool/ich_descriptors_tool.c =================================================================== --- flashrom-portability-fixes/util/ich_descriptors_tool/ich_descriptors_tool.c (Revision 1547) +++ flashrom-portability-fixes/util/ich_descriptors_tool/ich_descriptors_tool.c (Arbeitskopie) @@ -25,7 +25,6 @@ #include <stdio.h> #include <stdint.h> #include <stdlib.h> -#include <sys/mman.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -33,6 +32,9 @@ #include <string.h> #include <errno.h> #include "ich_descriptors.h" +#if defined(unix) || defined(__unix__) || defined(__unix) || (defined(__MACH__) && defined(__APPLE__)) +#include <sys/mman.h> +#endif
static void dump_file(const char *basename, const uint32_t *dump, unsigned int len, struct ich_desc_region *reg, unsigned int i) { @@ -161,16 +163,17 @@ if (len < 0) usage(argv, "Seeking to the end of the file failed");
+#if defined(unix) || defined(__unix__) || defined(__unix) || (defined(__MACH__) && defined(__APPLE__)) buf = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0); - if (buf == (void *) -1) { + if (buf == (void *) -1) +#endif + { /* fallback for stupid OSes like cygwin */ - int ret; buf = malloc(len); if (!buf) usage(argv, "Could not allocate memory"); lseek(fd, 0, SEEK_SET); - ret = read(fd, buf, len); - if (ret != len) + if (len != read(fd, buf, len)) usage(argv, "Seeking to the end of the file failed"); } printf("The flash image has a size of %d [0x%x] bytes.\n", len, len); Index: flashrom-portability-fixes/util/ich_descriptors_tool/Makefile =================================================================== --- flashrom-portability-fixes/util/ich_descriptors_tool/Makefile (Revision 1547) +++ flashrom-portability-fixes/util/ich_descriptors_tool/Makefile (Arbeitskopie) @@ -19,7 +19,7 @@
SHAREDOBJ = $(OBJATH)/$(notdir $(SHAREDSRC:%.c=%.o))
-all:$(PROGRAM) +all:$(PROGRAM)$(EXEC_SUFFIX)
$(OBJ): $(OBJATH)/%.o : %.c $(CC) $(CFLAGS) -o $@ -c $< @@ -29,11 +29,11 @@ $(SHAREDOBJ): $(OBJATH)/%.o : $(SHAREDSRCDIR)/%.c $(CC) $(CFLAGS) -o $@ -c $<
-$(PROGRAM): $(OBJ) $(SHAREDOBJ) - $(CC) -o $(PROGRAM) $(OBJ) $(SHAREDOBJ) +$(PROGRAM)$(EXEC_SUFFIX): $(OBJ) $(SHAREDOBJ) + $(CC) -o $(PROGRAM)$(EXEC_SUFFIX) $(OBJ) $(SHAREDOBJ)
clean: - rm -f $(PROGRAM) + rm -f $(PROGRAM) $(PROGRAM).exe rm -rf $(DEPPATH) $(OBJATH)
# Include the dependency files. Index: flashrom-portability-fixes/cbtable.c =================================================================== --- flashrom-portability-fixes/cbtable.c (Revision 1547) +++ flashrom-portability-fixes/cbtable.c (Arbeitskopie) @@ -211,7 +211,7 @@ struct lb_header *lb_table; struct lb_record *rec, *last;
-#ifdef __DARWIN__ +#if defined(__MACH__) && defined(__APPLE__) /* This is a hack. DirectHW fails to map physical address 0x00000000. * Why? */ Index: flashrom-portability-fixes/physmap.c =================================================================== --- flashrom-portability-fixes/physmap.c (Revision 1547) +++ flashrom-portability-fixes/physmap.c (Arbeitskopie) @@ -128,7 +128,7 @@ void cleanup_cpu_msr(void) { } -#elif defined(__DARWIN__) +#elif defined(__MACH__) && defined(__APPLE__)
#define MEM_DEV "DirectHW"
@@ -467,7 +467,7 @@
#else
-#ifdef __DARWIN__ +#if defined(__MACH__) && defined(__APPLE__) int setup_cpu_msr(int cpu) { // Always succeed for now Index: flashrom-portability-fixes/flashrom.c =================================================================== --- flashrom-portability-fixes/flashrom.c (Revision 1547) +++ flashrom-portability-fixes/flashrom.c (Arbeitskopie) @@ -1485,10 +1485,35 @@
void print_sysinfo(void) { -#if HAVE_UTSNAME == 1 +#ifdef _WIN32 + SYSTEM_INFO si; + OSVERSIONINFOEX osvi; + + memset(&si, 0, sizeof(SYSTEM_INFO)); + memset(&osvi, 0, sizeof(OSVERSIONINFOEX)); + msg_ginfo(" on Windows"); + /* Tell Windows which version of the structure we want. */ + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + if (GetVersionEx((OSVERSIONINFO*) &osvi)) + msg_ginfo(" unknown version"); + else + msg_ginfo(" %lu.%lu", osvi.dwMajorVersion, osvi.dwMinorVersion); + GetSystemInfo(&si); + switch (si.wProcessorArchitecture) { + case PROCESSOR_ARCHITECTURE_AMD64: + msg_ginfo(" x86_64"); + break; + case PROCESSOR_ARCHITECTURE_INTEL: + msg_ginfo(" x86"); + break; + default: + msg_ginfo(" unknown arch"); + break; + } +#elif HAVE_UTSNAME == 1 struct utsname osinfo; + uname(&osinfo); - msg_ginfo(" on %s %s (%s)", osinfo.sysname, osinfo.release, osinfo.machine); #else Index: flashrom-portability-fixes/README =================================================================== --- flashrom-portability-fixes/README (Revision 1547) +++ flashrom-portability-fixes/README (Arbeitskopie) @@ -93,14 +93,18 @@ To compile and run on Darwin/Mac OS X:
Install DirectHW from coresystems GmbH. - DirectHW is available at http://www.coresystems.de/en/directhw . + DirectHW is available at http://www.coreboot.org/DirectHW .
To cross-compile on Linux for DOS:
- Get RPMs of the cross compiler from the DJGPP site and install them: + Get packages of the DJGPP cross compiler and install them: + djgpp-filesystem djgpp-gcc djgpp-cpp djgpp-runtime djgpp-binutils + As an alternative, the DJGPP web site offers packages for download as well: djcross-binutils-2.19.1-10ap.i386.rpm djcross-gcc-4.3.2-8ap.i686.rpm djcrx-2.04pre_20090725-13ap.i386.rpm + The cross toolchain packages for your distribution may have slightly different + names (look for packages named *djgpp*). Download pciutils 3.1.5 and apply http://assembler.cz/flashrom/pciutils.patch Download and compile http://assembler.cz/flashrom/libgetopt/ Compile pciutils, see README.DJGPP for instructions. @@ -108,7 +112,7 @@ ../libpci should contain pciutils source and binaries. ../libgetopt should contain getopt.a from libgetopt. Run either (change settings where appropriate) - make CC=i586-pc-msdosdjgpp-gcc STRIP=i586-pc-msdosdjgpp-strip OS_ARCH=DOS + make CC=i586-pc-msdosdjgpp-gcc STRIP=i586-pc-msdosdjgpp-strip or (above settings hardcoded) make djgpp-dos You might have to add WARNERROR=no to the make command line. @@ -116,17 +120,22 @@ http://homer.rice.edu/~sandmann/cwsdpmi/csdpmi7b.zip and make sure CWSDPMI.EXE is in the current directory.
+To cross-compile on Linux for Windows: + + Get packages of the MinGW cross compiler and install them: + mingw32-filesystem mingw32-cross-cpp mingw32-cross-binutils mingw32-cross-gcc + mingw32-runtime mingw32-headers + The cross toolchain packages for your distribution may have slightly different + names (look for packages named *mingw*). + PCI-based programmers (internal etc.) are not supported on Windows. + Run (change CC= and STRIP= settings where appropriate) + make CC=i686-w64-mingw32-gcc STRIP=i686-w64-mingw32-strip + Processor architecture dependent features:
- On non-x86 architectures you have to disable a few programmers because they - use port-based I/O which is not directly available on non-x86. Please add - CONFIG_RAYER_SPI=no CONFIG_NIC3COM=no CONFIG_ATAHPT=no CONFIG_NICREALTEK=no \ - CONFIG_NICNATSEMI=no - as parameters to the "make" invocation. - Besides that, the internal programmer is only supported on x86 and MIPS. On - other architectures, please add - CONFIG_INTERNAL=no - as parameter to the "make" invocation. + On non-x86 architectures a few programmers don't work (yet) because they + use port-based I/O which is not directly available on non-x86. Those + programmers will be disabled automatically if you run "make".
Installation ------------ Index: flashrom-portability-fixes/programmer.h =================================================================== --- flashrom-portability-fixes/programmer.h (Revision 1547) +++ flashrom-portability-fixes/programmer.h (Arbeitskopie) @@ -636,7 +636,7 @@ #endif
/* serial.c */ -#if _WIN32 +#ifdef _WIN32 typedef HANDLE fdtype; #else typedef int fdtype;