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)
Update the README.
I tested native compilation on Linux x86, cross-compilation on Linux for MinGW and DJGPP. 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/os.h =================================================================== --- flashrom-portability-fixes/os.h (Revision 1547) +++ flashrom-portability-fixes/os.h (Arbeitskopie) @@ -26,7 +26,7 @@ #define __FLASHROM_OS__ "SunOS" // OS X #elif defined(__MACH__) && defined(__APPLE__) -#define __FLASHROM_OS__ "Darwin" +#define __FLASHROM_OS__ "OSX" // FreeBSD #elif defined(__FreeBSD__) #define __FLASHROM_OS__ "FreeBSD" Index: flashrom-portability-fixes/Makefile =================================================================== --- flashrom-portability-fixes/Makefile (Revision 1547) +++ flashrom-portability-fixes/Makefile (Arbeitskopie) @@ -53,27 +53,29 @@ # below uses CC itself. override TARGET_OS := $(strip $(shell LC_ALL=C $(CC) $(CPPFLAGS) -E os.h 2>/dev/null | grep -v '^#' | grep '"' | cut -f 2 -d'"'))
-ifeq ($(TARGET_OS), Darwin) +ifeq ($(TARGET_OS), OSX) 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 +86,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 @@ -270,6 +277,7 @@ 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 +539,19 @@ ifeq ($(TARGET_OS), OpenBSD) # For (i386|amd64)_iopl(2). LIBS += -l$(shell uname -m) +else +ifeq ($(TARGET_OS), OSX) +# 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 +586,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/README =================================================================== --- flashrom-portability-fixes/README (Revision 1547) +++ flashrom-portability-fixes/README (Arbeitskopie) @@ -93,7 +93,7 @@ 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:
@@ -108,7 +108,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 +116,24 @@ 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 RPMs of the MinGW cross-compiler and install them: + mingw32-filesystem-52 + mingw32-cross-cpp-4.6.2 + mingw32-cross-binutils-2.22 + mingw32-cross-gcc-4.6.2 + mingw32-runtime-1.0.1 + mingw32-headers-1.0.1 + PCI-based programmers (internal etc.) are not supported on Windows. + Run (change 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 ------------