[flashrom] [commit] r1864 - in trunk: . util/ich_descriptors_tool

repository service svn at flashrom.org
Sat Jan 10 10:32:51 CET 2015


Author: stefanct
Date: Sat Jan 10 10:32:50 2015
New Revision: 1864
URL: http://flashrom.org/trac/flashrom/changeset/1864

Log:
Unify target OS and CPU architecture checks.

We do CPU architecture checks once for the makefile in arch.h and
once for HW access abstraction in hwaccess.c. This patch unifies
related files so that they can share the checks to improve
maintainability and reduce the chance of inconsistencies.
Furthermore, it refines some of the definitions, which
 - adds "support" for AARCH64 and PPC64,
 - adds big-endian handling on arm as well as LE handling on PPC64,
 - fixes compilation of internal.c on AARCH64 and PPC64.

Additionally, this patch continues to unify all OS checks in
flashrom by adding a new helper macro IS_WINDOWS.

The old header file for architecture checking is renamed to platform.h
to reflect its broader scope and all new macros are add in there.

Signed-off-by: Stefan Tauner <stefan.tauner at alumni.tuwien.ac.at>
Acked-by: Stefan Tauner <stefan.tauner at alumni.tuwien.ac.at>

Added:
   trunk/archtest.c   (contents, props changed)
   trunk/platform.h   (contents, props changed)
Deleted:
   trunk/arch.h
Modified:
   trunk/Makefile
   trunk/flash.h
   trunk/flashrom.c
   trunk/hwaccess.c
   trunk/hwaccess.h
   trunk/internal.c
   trunk/os.h
   trunk/programmer.h
   trunk/serial.c
   trunk/serprog.c
   trunk/udelay.c
   trunk/util/ich_descriptors_tool/ich_descriptors_tool.c

Modified: trunk/Makefile
==============================================================================
--- trunk/Makefile	Sat Jan 10 10:32:44 2015	(r1863)
+++ trunk/Makefile	Sat Jan 10 10:32:50 2015	(r1864)
@@ -316,7 +316,7 @@
 # IMPORTANT: The following line must be placed before ARCH is ever used
 # (of course), but should come after any lines setting CC because the line
 # below uses CC itself.
-override ARCH := $(strip $(shell LC_ALL=C $(CC) $(CPPFLAGS) -E arch.h 2>/dev/null | grep -v '^\#' | grep '"' | cut -f 2 -d'"'))
+override ARCH := $(strip $(shell LC_ALL=C $(CC) $(CPPFLAGS) -E archtest.c 2>/dev/null | grep -v '^\#' | grep '"' | cut -f 2 -d'"'))
 
 # PCI port I/O support is unimplemented on PPC/MIPS and unavailable on ARM.
 # Right now this means the drivers below only work on x86.

Added: trunk/archtest.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/archtest.c	Sat Jan 10 10:32:50 2015	(r1864)
@@ -0,0 +1,2 @@
+#include "platform.h"
+__FLASHROM_ARCH__

Modified: trunk/flash.h
==============================================================================
--- trunk/flash.h	Sat Jan 10 10:32:44 2015	(r1863)
+++ trunk/flash.h	Sat Jan 10 10:32:50 2015	(r1864)
@@ -24,12 +24,14 @@
 #ifndef __FLASH_H__
 #define __FLASH_H__ 1
 
+#include "platform.h"
+
 #include <inttypes.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <stddef.h>
 #include <stdbool.h>
-#ifdef _WIN32
+#if IS_WINDOWS
 #include <windows.h>
 #undef min
 #undef max

Modified: trunk/flashrom.c
==============================================================================
--- trunk/flashrom.c	Sat Jan 10 10:32:44 2015	(r1863)
+++ trunk/flashrom.c	Sat Jan 10 10:32:50 2015	(r1864)
@@ -1661,7 +1661,7 @@
 
 void print_sysinfo(void)
 {
-#ifdef _WIN32
+#if IS_WINDOWS
 	SYSTEM_INFO si;
 	OSVERSIONINFOEX osvi;
 

Modified: trunk/hwaccess.c
==============================================================================
--- trunk/hwaccess.c	Sat Jan 10 10:32:44 2015	(r1863)
+++ trunk/hwaccess.c	Sat Jan 10 10:32:50 2015	(r1864)
@@ -18,19 +18,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#define IS_X86	(defined(__i386__) || defined(__x86_64__) || defined(__amd64__))
-#define IS_MIPS	(defined (__mips) || defined (__mips__) || defined (__MIPS__) || defined (mips))
-#define IS_PPC	(defined(__powerpc__) || defined(__powerpc64__) || defined(__ppc__) || defined(__ppc64__))
-#define IS_ARM	(defined (__arm__) || defined (_ARM))
-#if !(IS_X86 || IS_MIPS || IS_PPC || IS_ARM)
-#error Unknown architecture
-#endif
-
-#define IS_LINUX	(defined(__gnu_linux__) || defined(__linux__))
-#define IS_MACOSX	(defined(__APPLE__) && defined(__MACH__))
-#if !(IS_LINUX || IS_MACOSX || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__DJGPP__) || defined(__LIBPAYLOAD__) || defined(__sun))
-#error "Unknown operating system"
-#endif
+#include "platform.h"
 
 #include <stdint.h>
 #include <string.h>
@@ -45,6 +33,10 @@
 #include "flash.h"
 #include "hwaccess.h"
 
+#if !(IS_LINUX || IS_MACOSX || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__DJGPP__) || defined(__LIBPAYLOAD__) || defined(__sun))
+#error "Unknown operating system"
+#endif
+
 #define USE_IOPL	(IS_LINUX || IS_MACOSX || defined(__NetBSD__) || defined(__OpenBSD__))
 #define USE_DEV_IO	(defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__))
 
@@ -62,7 +54,7 @@
  * - MIPS uses uncached accesses in mode 2 on /dev/mem which has also a strongly ordered memory model
  * - ARM uses a strongly ordered memory model for device memories.
  */
-#if IS_PPC
+#if IS_PPC // cf. http://lxr.free-electrons.com/source/arch/powerpc/include/asm/barrier.h
 	asm("eieio" : : : "memory");
 #endif
 }

Modified: trunk/hwaccess.h
==============================================================================
--- trunk/hwaccess.h	Sat Jan 10 10:32:44 2015	(r1863)
+++ trunk/hwaccess.h	Sat Jan 10 10:32:50 2015	(r1864)
@@ -24,7 +24,9 @@
 #ifndef __HWACCESS_H__
 #define __HWACCESS_H__ 1
 
-#if defined (__i386__) || defined (__x86_64__)
+#include "platform.h"
+
+#if IS_X86
 #if defined(__GLIBC__)
 #include <sys/io.h>
 #endif
@@ -45,14 +47,22 @@
 #endif
 
 #undef index
+#endif /* NEED_PCI == 1 */
+
+
+/* The next big hunk tries to guess endianess from various preprocessor macros */
+/* First some error checking in case some weird header has defines both.
+ * NB: OpenBSD always defines _BIG_ENDIAN and _LITTLE_ENDIAN. */
+#if defined (__LITTLE_ENDIAN__) && defined (__BIG_ENDIAN__)
+#error Conflicting endianness #define
 #endif
 
-#if defined (__i386__) || defined (__x86_64__)
+#if IS_X86
 
 /* All x86 is little-endian. */
 #define __FLASHROM_LITTLE_ENDIAN__ 1
 
-#elif defined (__mips) || defined (__mips__) || defined (_mips) || defined (mips)
+#elif IS_MIPS
 
 /* MIPS can be either endian. */
 #if defined (__MIPSEL) || defined (__MIPSEL__) || defined (_MIPSEL) || defined (MIPSEL)
@@ -61,29 +71,45 @@
 #define __FLASHROM_BIG_ENDIAN__ 1
 #endif
 
-#elif defined(__powerpc__) || defined(__powerpc64__) || defined(__ppc__) || defined(__ppc64__)
+#elif IS_PPC
 
 /* PowerPC can be either endian. */
 #if defined (_BIG_ENDIAN) || defined (__BIG_ENDIAN__)
 #define __FLASHROM_BIG_ENDIAN__ 1
-/* Error checking in case some weird header has #defines for LE as well. */
-#if defined (_LITTLE_ENDIAN) || defined (__LITTLE_ENDIAN__)
-#error Conflicting endianness #define
-#endif
-#else
-#error Little-endian PowerPC #defines are unknown
+#elif defined (_LITTLE_ENDIAN) || defined (__LITTLE_ENDIAN__)
+#define __FLASHROM_LITTLE_ENDIAN__ 1
 #endif
 
-#elif defined (__arm__)
-#if defined (__ARMEL__)
+#elif IS_ARM
+
+/* ARM can be either endian. */
+#if defined (__ARMEB__)
+#define __FLASHROM_BIG_ENDIAN__ 1
+#elif defined (__ARMEL__)
 #define __FLASHROM_LITTLE_ENDIAN__ 1
-#else
-#error Big-endian ARM #defines are unknown
 #endif
 
+#endif /* IS_? */
+
+#if !defined (__FLASHROM_BIG_ENDIAN__) && !defined (__FLASHROM_LITTLE_ENDIAN__)
+
+/* If architecture-specific approaches fail try generic variants. First: BSD (works about everywhere). */
+#if !IS_WINDOWS
+#include <sys/param.h>
+
+#if defined (__BYTE_ORDER)
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define __FLASHROM_LITTLE_ENDIAN__
+#elif __BYTE_ORDER == __BIG_ENDIAN
+#define __FLASHROM_BIG_ENDIAN__
+#else
+#error Unknown byte order!
 #endif
+#endif /* defined __BYTE_ORDER */
+#endif /* !IS_WINDOWS */
 
 #if !defined (__FLASHROM_BIG_ENDIAN__) && !defined (__FLASHROM_LITTLE_ENDIAN__)
+
 /* Nonstandard libc-specific macros for determining endianness. */
 #if defined(__GLIBC__)
 #include <endian.h>
@@ -95,8 +121,10 @@
 #endif
 #endif
 
+#endif
+
 #if !defined (__FLASHROM_BIG_ENDIAN__) && !defined (__FLASHROM_LITTLE_ENDIAN__)
-#error Unable to determine endianness. Please add support for your arch or libc.
+#error Unable to determine endianness.
 #endif
 
 #define ___constant_swab8(x) ((uint8_t) (				\
@@ -158,11 +186,7 @@
 #define cpu_to_le32
 #define cpu_to_le64
 
-#else
-
-#error Could not determine endianness.
-
-#endif
+#endif /* __FLASHROM_BIG_ENDIAN__ / __FLASHROM_LITTLE_ENDIAN__ */
 
 #define be_to_cpu8 cpu_to_be8
 #define be_to_cpu16 cpu_to_be16
@@ -174,12 +198,12 @@
 #define le_to_cpu64 cpu_to_le64
 
 #if NEED_PCI == 1
-#if defined (__i386__) || defined (__x86_64__)
+#if IS_X86
 
 #define __FLASHROM_HAVE_OUTB__ 1
 
 /* for iopl and outb under Solaris */
-#if defined (__sun) && (defined(__i386) || defined(__amd64))
+#if defined (__sun)
 #include <sys/sysi86.h>
 #include <sys/psw.h>
 #include <asm/sunddi.h>
@@ -202,11 +226,13 @@
   #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(__MACH__) && defined(__APPLE__)
     /* Header is part of the DirectHW library. */
     #include <DirectHW/DirectHW.h>
-#endif
-#if defined (__sun) && (defined(__i386) || defined(__amd64))
+#else
+
+#if defined (__sun)
   /* Note different order for outb */
   #define OUTB(x,y) outb(y, x)
   #define OUTW(x,y) outw(y, x)
@@ -236,9 +262,8 @@
   #define INB  inb
   #define INW  inw
   #define INL  inl
-
 #endif
-
+#endif
 #endif
 #endif
 
@@ -324,15 +349,15 @@
 #define wrmsr libpayload_wrmsr
 #endif
 
-#elif defined(__powerpc__) || defined(__powerpc64__) || defined(__ppc__) || defined(__ppc64__)
+#elif IS_PPC
 
 /* PCI port I/O is not yet implemented on PowerPC. */
 
-#elif defined (__mips) || defined (__mips__) || defined (_mips) || defined (mips)
+#elif IS_MIPS
 
 /* PCI port I/O is not yet implemented on MIPS. */
 
-#elif defined(__arm__)
+#elif IS_ARM
 
 /* Non memory mapped I/O is not supported on ARM. */
 
@@ -340,7 +365,7 @@
 
 #error Unknown architecture, please check if it supports PCI port IO.
 
-#endif
-#endif
+#endif /* IS_* */
+#endif /* NEED_PCI == 1 */
 
 #endif /* !__HWACCESS_H__ */

Modified: trunk/internal.c
==============================================================================
--- trunk/internal.c	Sat Jan 10 10:32:44 2015	(r1863)
+++ trunk/internal.c	Sat Jan 10 10:32:50 2015	(r1864)
@@ -160,14 +160,14 @@
 
 int internal_init(void)
 {
-#if __FLASHROM_LITTLE_ENDIAN__
+#if defined __FLASHROM_LITTLE_ENDIAN__
 	int ret = 0;
 #endif
 	int force_laptop = 0;
 	int not_a_laptop = 0;
 	const char *board_vendor = NULL;
 	const char *board_model = NULL;
-#if defined (__i386__) || defined (__x86_64__) || defined (__arm__)
+#if IS_X86 || IS_ARM
 	const char *cb_vendor = NULL;
 	const char *cb_model = NULL;
 #endif
@@ -249,7 +249,7 @@
 		return 1;
 	}
 
-#if defined(__i386__) || defined(__x86_64__) || defined (__arm__)
+#if IS_X86 || IS_ARM
 	if ((cb_parse_table(&cb_vendor, &cb_model) == 0) && (board_vendor != NULL) && (board_model != NULL)) {
 		if (strcasecmp(board_vendor, cb_vendor) || strcasecmp(board_model, cb_model)) {
 			msg_pwarn("Warning: The mainboard IDs set by -p internal:mainboard (%s:%s) do not\n"
@@ -262,7 +262,7 @@
 	}
 #endif
 
-#if defined(__i386__) || defined(__x86_64__)
+#if IS_X86
 	dmi_init();
 
 	/* In case Super I/O probing would cause pretty explosions. */
@@ -312,7 +312,7 @@
 		}
 	}
 
-#if __FLASHROM_LITTLE_ENDIAN__
+#ifdef __FLASHROM_LITTLE_ENDIAN__
 	/* try to enable it. Failure IS an option, since not all motherboards
 	 * really need this to be done, etc., etc.
 	 */
@@ -323,18 +323,18 @@
 	} else if (ret == ERROR_FATAL)
 		return ret;
 
-#if defined(__i386__) || defined(__x86_64__)
+#if IS_X86
 	/* Probe unconditionally for ITE Super I/O chips. This enables LPC->SPI translation on IT87* and
 	 * parallel writes on IT8705F. Also, this handles the manual chip select for Gigabyte's DualBIOS. */
 	init_superio_ite();
-#endif
 
 	if (board_flash_enable(board_vendor, board_model, cb_vendor, cb_model)) {
 		msg_perr("Aborting to be safe.\n");
 		return 1;
 	}
+#endif
 
-#if defined(__i386__) || defined(__x86_64__) || defined (__mips)
+#if IS_X86 || IS_MIPS
 	register_par_master(&par_master_internal, internal_buses_supported);
 	return 0;
 #else

Modified: trunk/os.h
==============================================================================
--- trunk/os.h	Sat Jan 10 10:32:44 2015	(r1863)
+++ trunk/os.h	Sat Jan 10 10:32:50 2015	(r1864)
@@ -21,6 +21,8 @@
  * Header file for OS checking.
  */
 
+#include "platform.h"
+
 // Solaris
 #if defined (__sun) && (defined(__i386) || defined(__amd64))
 #define __FLASHROM_OS__ "SunOS"

Added: trunk/platform.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/platform.h	Sat Jan 10 10:32:50 2015	(r1864)
@@ -0,0 +1,54 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright (C) 2011 Carl-Daniel Hailfinger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+/*
+ * Header file to determine target OS and CPU architecture.
+ */
+
+#ifndef __PLATFORM_H__
+#define __PLATFORM_H__ 1
+
+// Helper defines for operating systems
+#define IS_LINUX	(defined(__gnu_linux__) || defined(__linux__))
+#define IS_MACOSX	(defined(__APPLE__) && defined(__MACH__)) /* yes, both. */
+#define IS_WINDOWS	(defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__WINDOWS__))
+
+// Likewise for target architectures
+#if defined (__i386__) || defined (__x86_64__) || defined(__amd64__)
+	#define __FLASHROM_ARCH__ "x86"
+	#define IS_X86 1
+#elif defined (__mips) || defined (__mips__) || defined (__MIPS__) || defined (mips)
+	#define __FLASHROM_ARCH__ "mips"
+	#define IS_MIPS 1
+#elif defined(__powerpc) || defined(__powerpc__) || defined(__powerpc64__) || defined(__POWERPC__) || \
+      defined(__ppc__) || defined(__ppc64__) || defined(_M_PPC) || defined(_ARCH_PPC) || \
+      defined(_ARCH_PPC64) || defined(__ppc)
+	#define __FLASHROM_ARCH__ "ppc"
+	#define IS_PPC 1
+#elif defined(__arm__) || defined(__TARGET_ARCH_ARM) || defined(_ARM) || defined(_M_ARM) || defined(__arm) || \
+      defined(__aarch64__)
+	#define __FLASHROM_ARCH__ "arm"
+	#define IS_ARM 1
+#endif
+
+#if !(IS_X86 || IS_MIPS || IS_PPC || IS_ARM)
+#error Unknown architecture
+#endif
+
+#endif /* !__PLATFORM_H__ */

Modified: trunk/programmer.h
==============================================================================
--- trunk/programmer.h	Sat Jan 10 10:32:44 2015	(r1863)
+++ trunk/programmer.h	Sat Jan 10 10:32:50 2015	(r1864)
@@ -700,7 +700,7 @@
 #endif
 
 /* serial.c */
-#ifdef _WIN32
+#if IS_WINDOWS
 typedef HANDLE fdtype;
 #define SER_INV_FD	INVALID_HANDLE_VALUE
 #else

Modified: trunk/serial.c
==============================================================================
--- trunk/serial.c	Sat Jan 10 10:32:44 2015	(r1863)
+++ trunk/serial.c	Sat Jan 10 10:32:50 2015	(r1864)
@@ -19,6 +19,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include "platform.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -28,7 +30,7 @@
 #include <sys/stat.h>
 #include <errno.h>
 #include <inttypes.h>
-#ifdef _WIN32
+#if IS_WINDOWS
 #include <conio.h>
 #else
 #include <termios.h>
@@ -41,7 +43,7 @@
 
 fdtype sp_fd = SER_INV_FD;
 
-#ifdef _WIN32
+#if IS_WINDOWS
 struct baudentry {
 	DWORD flag;
 	unsigned int baud;
@@ -137,7 +139,7 @@
 static void msg_perr_strerror(const char *msg)
 {
 	msg_perr("Error: %s", msg);
-#ifdef _WIN32
+#if IS_WINDOWS
 	char *lpMsgBuf;
 	DWORD nErr = GetLastError();
 	FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, nErr,
@@ -159,7 +161,7 @@
 		return 1;
 	}
 
-#ifdef _WIN32
+#if IS_WINDOWS
 	DCB dcb;
 	if (!GetCommState(fd, &dcb)) {
 		msg_perr_strerror("Could not fetch original serial port configuration: ");
@@ -224,7 +226,7 @@
 fdtype sp_openserport(char *dev, unsigned int baud)
 {
 	fdtype fd;
-#ifdef _WIN32
+#if IS_WINDOWS
 	char *dev2 = dev;
 	if ((strlen(dev) > 3) &&
 	    (tolower((unsigned char)dev[0]) == 'c') &&
@@ -266,7 +268,7 @@
 }
 
 void sp_set_pin(enum SP_PIN pin, int val) {
-#ifdef _WIN32
+#if IS_WINDOWS
 	DWORD ctl;
 
 	if(pin == PIN_TXD) {
@@ -302,7 +304,7 @@
 
 int sp_get_pin(enum SP_PIN pin) {
 	int s;
-#ifdef _WIN32
+#if IS_WINDOWS
 	DWORD ctl;
 
 	s = (pin == PIN_CTS) ? MS_CTS_ON : MS_DSR_ON;
@@ -319,7 +321,7 @@
 
 void sp_flush_incoming(void)
 {
-#ifdef _WIN32
+#if IS_WINDOWS
 	PurgeComm(sp_fd, PURGE_RXCLEAR);
 #else
 	/* FIXME: error handling */
@@ -330,7 +332,7 @@
 
 int serialport_shutdown(void *data)
 {
-#ifdef _WIN32
+#if IS_WINDOWS
 	CloseHandle(sp_fd);
 #else
 	close(sp_fd);
@@ -340,7 +342,7 @@
 
 int serialport_write(const unsigned char *buf, unsigned int writecnt)
 {
-#ifdef _WIN32
+#if IS_WINDOWS
 	DWORD tmp = 0;
 #else
 	ssize_t tmp = 0;
@@ -348,7 +350,7 @@
 	unsigned int empty_writes = 250; /* results in a ca. 125ms timeout */
 
 	while (writecnt > 0) {
-#ifdef _WIN32
+#if IS_WINDOWS
 		WriteFile(sp_fd, buf, writecnt, &tmp, NULL);
 #else
 		tmp = write(sp_fd, buf, writecnt);
@@ -375,14 +377,14 @@
 
 int serialport_read(unsigned char *buf, unsigned int readcnt)
 {
-#ifdef _WIN32
+#if IS_WINDOWS
 	DWORD tmp = 0;
 #else
 	ssize_t tmp = 0;
 #endif
 
 	while (readcnt > 0) {
-#ifdef _WIN32
+#if IS_WINDOWS
 		ReadFile(sp_fd, buf, readcnt, &tmp, NULL);
 #else
 		tmp = read(sp_fd, buf, readcnt);
@@ -407,7 +409,7 @@
 {
 	int ret = 1;
 	/* disable blocked i/o and declare platform-specific variables */
-#ifdef _WIN32
+#if IS_WINDOWS
 	DWORD rv;
 	COMMTIMEOUTS oldTimeout;
 	COMMTIMEOUTS newTimeout = {
@@ -442,7 +444,7 @@
 	int rd_bytes = 0;
 	for (i = 0; i < timeout; i++) {
 		msg_pspew("readcnt %d rd_bytes %d\n", readcnt, rd_bytes);
-#ifdef _WIN32
+#if IS_WINDOWS
 		ReadFile(sp_fd, c + rd_bytes, readcnt - rd_bytes, &rv, NULL);
 		msg_pspew("read %lu bytes\n", rv);
 #else
@@ -466,7 +468,7 @@
 		*really_read = rd_bytes;
 
 	/* restore original blocking behavior */
-#ifdef _WIN32
+#if IS_WINDOWS
 	if (!SetCommTimeouts(sp_fd, &oldTimeout)) {
 		msg_perr_strerror("Could not restore serial port timeout settings: ");
 		ret = -1;
@@ -487,7 +489,7 @@
 {
 	int ret = 1;
 	/* disable blocked i/o and declare platform-specific variables */
-#ifdef _WIN32
+#if IS_WINDOWS
 	DWORD rv;
 	COMMTIMEOUTS oldTimeout;
 	COMMTIMEOUTS newTimeout = {
@@ -522,7 +524,7 @@
 	int wr_bytes = 0;
 	for (i = 0; i < timeout; i++) {
 		msg_pspew("writecnt %d wr_bytes %d\n", writecnt, wr_bytes);
-#ifdef _WIN32
+#if IS_WINDOWS
 		WriteFile(sp_fd, buf + wr_bytes, writecnt - wr_bytes, &rv, NULL);
 		msg_pspew("wrote %lu bytes\n", rv);
 #else
@@ -548,7 +550,7 @@
 		*really_wrote = wr_bytes;
 
 	/* restore original blocking behavior */
-#ifdef _WIN32
+#if IS_WINDOWS
 	if (!SetCommTimeouts(sp_fd, &oldTimeout)) {
 		msg_perr_strerror("Could not restore serial port timeout settings: ");
 		return -1;

Modified: trunk/serprog.c
==============================================================================
--- trunk/serprog.c	Sat Jan 10 10:32:44 2015	(r1863)
+++ trunk/serprog.c	Sat Jan 10 10:32:50 2015	(r1864)
@@ -19,8 +19,10 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include "platform.h"
+
 #include <stdio.h>
-#ifndef _WIN32 /* stuff (presumably) needed for sockets only */
+#if ! IS_WINDOWS /* stuff (presumably) needed for sockets only */
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -30,7 +32,7 @@
 #include <netinet/tcp.h>
 #include <netdb.h>
 #endif
-#ifdef _WIN32
+#if IS_WINDOWS
 #include <conio.h>
 #else
 #include <termios.h>
@@ -83,7 +85,7 @@
 	whether the command is supported before doing it */
 static int sp_check_avail_automatic = 0;
 
-#ifndef WIN32
+#if ! IS_WINDOWS
 static int sp_opensocket(char *ip, unsigned int port)
 {
 	int flag = 1;
@@ -375,7 +377,7 @@
 	}
 	free(device);
 
-#ifndef _WIN32
+#if !IS_WINDOWS
 	device = extract_programmer_param("ip");
 	if (have_device && device) {
 		msg_perr("Error: Both host and device specified.\n"

Modified: trunk/udelay.c
==============================================================================
--- trunk/udelay.c	Sat Jan 10 10:32:44 2015	(r1863)
+++ trunk/udelay.c	Sat Jan 10 10:32:50 2015	(r1864)
@@ -172,7 +172,7 @@
 /* Not very precise sleep. */
 void internal_sleep(unsigned int usecs)
 {
-#ifdef _WIN32
+#if IS_WINDOWS
 	Sleep((usecs + 999) / 1000);
 #else
 	sleep(usecs / 1000000);

Modified: trunk/util/ich_descriptors_tool/ich_descriptors_tool.c
==============================================================================
--- trunk/util/ich_descriptors_tool/ich_descriptors_tool.c	Sat Jan 10 10:32:44 2015	(r1863)
+++ trunk/util/ich_descriptors_tool/ich_descriptors_tool.c	Sat Jan 10 10:32:50 2015	(r1864)
@@ -35,7 +35,7 @@
 /* Some DJGPP builds define __unix__ although they don't support mmap().
  * Cygwin defines __unix__ and supports mmap(), but it does not work well.
  */
-#if !defined(__MSDOS__) && !defined(_WIN32) && (defined(unix) || defined(__unix__) || defined(__unix)) || (defined(__MACH__) && defined(__APPLE__))
+#if !defined(__MSDOS__) && !IS_WINDOWS && (defined(unix) || defined(__unix__) || defined(__unix)) || (defined(__MACH__) && defined(__APPLE__))
 #define HAVE_MMAP 1
 #include <sys/mman.h>
 #endif




More information about the flashrom mailing list