]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
compiler.h: unify system ifdef cruft here
authorMike Frysinger <vapier@gentoo.org>
Thu, 2 Jul 2009 23:23:25 +0000 (19:23 -0400)
committerWolfgang Denk <wd@denx.de>
Sun, 19 Jul 2009 19:41:46 +0000 (21:41 +0200)
Shove a lot of the HOSTCC and related #ifdef checking crap into the new
compiler.h header so that we can keep all other headers nice and clean.

Also introduce custom uswap functions so we don't have to rely on the non
standard implementations that a host may (or may not in the case of OS X)
provide.  This allows mkimage to finally build cleanly on an OS X system.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
15 files changed:
include/compiler.h [new file with mode: 0644]
include/elf.h
include/environment.h
include/image.h
include/libfdt_env.h
include/u-boot/md5.h
lib_generic/md5.c
tools/bmp_logo.c
tools/img2srec.c
tools/mingw_support.h
tools/mkimage.c
tools/mkimage.h
tools/os_support.c
tools/os_support.h
tools/ubsha1.c

diff --git a/include/compiler.h b/include/compiler.h
new file mode 100644 (file)
index 0000000..272fd3c
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ * Keep all the ugly #ifdef for system stuff here
+ */
+
+#ifndef __COMPILER_H__
+#define __COMPILER_H__
+
+#include <stddef.h>
+
+#ifdef USE_HOSTCC
+
+#if defined(__BEOS__)   || \
+    defined(__NetBSD__)  || \
+    defined(__FreeBSD__) || \
+    defined(__sun__)    || \
+    defined(__APPLE__)
+# include <inttypes.h>
+#elif defined(__linux__) || defined(__WIN32__) || defined(__MINGW32__)
+# include <stdint.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+extern int errno;
+
+#if !defined(__WIN32__) && !defined(__MINGW32__)
+# include <sys/mman.h>
+#endif
+
+/* Not all systems (like Windows) has this define, and yes
+ * we do replace/emulate mmap() on those systems ...
+ */
+#ifndef MAP_FAILED
+# define MAP_FAILED ((void *)-1)
+#endif
+
+#include <fcntl.h>
+#ifndef O_BINARY               /* should be define'd on __WIN32__ */
+#define O_BINARY       0
+#endif
+
+#ifdef __linux__
+# include <endian.h>
+# include <byteswap.h>
+#elif defined(__MACH__)
+# include <machine/endian.h>
+typedef unsigned long ulong;
+typedef unsigned int  uint;
+#endif
+
+typedef uint8_t __u8;
+typedef uint16_t __u16;
+typedef uint32_t __u32;
+
+#define uswap_16(x) \
+       ((((x) & 0xff00) >> 8) | \
+        (((x) & 0x00ff) << 8))
+#define uswap_32(x) \
+       ((((x) & 0xff000000) >> 24) | \
+        (((x) & 0x00ff0000) >>  8) | \
+        (((x) & 0x0000ff00) <<  8) | \
+        (((x) & 0x000000ff) << 24))
+#define _uswap_64(x, sfx) \
+       ((((x) & 0xff00000000000000##sfx) >> 56) | \
+        (((x) & 0x00ff000000000000##sfx) >> 40) | \
+        (((x) & 0x0000ff0000000000##sfx) >> 24) | \
+        (((x) & 0x000000ff00000000##sfx) >>  8) | \
+        (((x) & 0x00000000ff000000##sfx) <<  8) | \
+        (((x) & 0x0000000000ff0000##sfx) << 24) | \
+        (((x) & 0x000000000000ff00##sfx) << 40) | \
+        (((x) & 0x00000000000000ff##sfx) << 56))
+#if defined(__GNUC__)
+# define uswap_64(x) _uswap_64(x, ull)
+#else
+# define uswap_64(x) _uswap_64(x, )
+#endif
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+# define cpu_to_le16(x)                (x)
+# define cpu_to_le32(x)                (x)
+# define cpu_to_le64(x)                (x)
+# define le16_to_cpu(x)                (x)
+# define le32_to_cpu(x)                (x)
+# define le64_to_cpu(x)                (x)
+# define cpu_to_be16(x)                uswap_16(x)
+# define cpu_to_be32(x)                uswap_32(x)
+# define cpu_to_be64(x)                uswap_64(x)
+# define be16_to_cpu(x)                uswap_16(x)
+# define be32_to_cpu(x)                uswap_32(x)
+# define be64_to_cpu(x)                uswap_64(x)
+#else
+# define cpu_to_le16(x)                uswap_16(x)
+# define cpu_to_le32(x)                uswap_32(x)
+# define cpu_to_le64(x)                uswap_64(x)
+# define le16_to_cpu(x)                uswap_16(x)
+# define le32_to_cpu(x)                uswap_32(x)
+# define le64_to_cpu(x)                uswap_64(x)
+# define cpu_to_be16(x)                (x)
+# define cpu_to_be32(x)                (x)
+# define cpu_to_be64(x)                (x)
+# define be16_to_cpu(x)                (x)
+# define be32_to_cpu(x)                (x)
+# define be64_to_cpu(x)                (x)
+#endif
+
+#else /* !USE_HOSTCC */
+
+#include <linux/string.h>
+#include <linux/types.h>
+#include <asm/byteorder.h>
+
+/* Types for `void *' pointers. */
+#if __WORDSIZE == 64
+typedef unsigned long int       uintptr_t;
+#else
+typedef unsigned int            uintptr_t;
+#endif
+
+#endif
+
+#endif
index f6403881bff19f5f7d4ae09308ef0a14fc92c5ce..29f276d3f029320bbab74d64a08432b185ef5588 100644 (file)
 #ifndef _ELF_H
 #define _ELF_H
 
-#if defined(__BEOS__)   || \
-    defined(__NetBSD__)  || \
-    defined(__FreeBSD__) || \
-    defined(__sun__)    || \
-    defined(__APPLE__)
-#include <inttypes.h>
-#elif (defined(__linux__) && defined(USE_HOSTCC)) || defined(__WIN32__)
-#include <stdint.h>
-#endif
+#include "compiler.h"
 
 /*
  *  This version doesn't work for 64-bit ABIs - Erik.
index 507e8326a3a64d6a2363366156351682f8d8ec28..5bed32fd47914b76d9c3b42893b8f060757a5b4f 100644 (file)
 # endif
 #endif /* CONFIG_ENV_IS_IN_MG_DISK */
 
-#ifdef USE_HOSTCC
-# include <stdint.h>
-#else
-# include <linux/types.h>
-#endif
+#include "compiler.h"
 
 #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
 # define ENV_HEADER_SIZE       (sizeof(uint32_t) + 1)
index f183757c8530c44faf8f5edac95b95df26f92f17..beb3a16cd1f18e966aaa01750ae6fdbc8cb56d85 100644 (file)
 #ifndef __IMAGE_H__
 #define __IMAGE_H__
 
-#if USE_HOSTCC
-#ifndef __MINGW32__
-#include <endian.h>
-#endif
+#include "compiler.h"
+
+#ifdef USE_HOSTCC
 
 /* new uImage format support enabled on host */
 #define CONFIG_FIT             1
@@ -46,9 +45,7 @@
 #else
 
 #include <lmb.h>
-#include <linux/string.h>
 #include <asm/u-boot.h>
-#include <asm/byteorder.h>
 
 #endif /* USE_HOSTCC */
 
@@ -284,8 +281,8 @@ typedef struct bootm_headers {
 #define CHUNKSZ_SHA1 (64 * 1024)
 #endif
 
-#define uimage_to_cpu(x)               ntohl(x)
-#define cpu_to_uimage(x)               htonl(x)
+#define uimage_to_cpu(x)               be32_to_cpu(x)
+#define cpu_to_uimage(x)               cpu_to_be32(x)
 
 const char *genimg_get_os_name (uint8_t os);
 const char *genimg_get_arch_name (uint8_t arch);
index 1c67015a4a9a349a9301084fa32dae98e09421db..bf63583d53a9adcea1d9151698b5a9fc03d4e157 100644 (file)
 #ifndef _LIBFDT_ENV_H
 #define _LIBFDT_ENV_H
 
-#ifdef USE_HOSTCC
-#include <stdint.h>
-#include <string.h>
-#ifdef __MINGW32__
-#include <linux/types.h>
-#include <linux/byteorder/swab.h>
-#else
-#include <endian.h>
-#include <byteswap.h>
-#endif /* __MINGW32__ */
-#else
-#include <linux/string.h>
-#include <linux/types.h>
-#include <asm/byteorder.h>
-#endif /* USE_HOSTCC */
+#include "compiler.h"
 
-#include <stddef.h>
 extern struct fdt_header *working_fdt;  /* Pointer to the working fdt */
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#ifdef __MINGW32__
-#define fdt32_to_cpu(x)                ___swab32(x)
-#define cpu_to_fdt32(x)                ___swab32(x)
-#define fdt64_to_cpu(x)                ___swab64(x)
-#define cpu_to_fdt64(x)                ___swab64(x)
-#else
-#define fdt32_to_cpu(x)                bswap_32(x)
-#define cpu_to_fdt32(x)                bswap_32(x)
-#define fdt64_to_cpu(x)                bswap_64(x)
-#define cpu_to_fdt64(x)                bswap_64(x)
-#endif
-#else
-#define fdt32_to_cpu(x)                (x)
-#define cpu_to_fdt32(x)                (x)
-#define fdt64_to_cpu(x)                (x)
-#define cpu_to_fdt64(x)                (x)
-#endif
-
-#ifndef USE_HOSTCC
-/*
- * Types for `void *' pointers.
- *
- * Note: libfdt uses this definition from /usr/include/stdint.h.
- * Define it here rather than pulling in all of stdint.h.
- */
-#if __WORDSIZE == 64
-typedef unsigned long int       uintptr_t;
-#else
-typedef unsigned int            uintptr_t;
-#endif
-#endif /* not USE_HOSTCC */
+#define fdt32_to_cpu(x)                be32_to_cpu(x)
+#define cpu_to_fdt32(x)                cpu_to_be32(x)
+#define fdt64_to_cpu(x)                be64_to_cpu(x)
+#define cpu_to_fdt64(x)                cpu_to_be64(x)
 
 #endif /* _LIBFDT_ENV_H */
index 8b44a7f8441e53916d5e9d755ed97c8717e4b41b..08924cce3cf0b520d64f922dcb61953c9fa9f58a 100644 (file)
@@ -6,7 +6,7 @@
 #ifndef _MD5_H
 #define _MD5_H
 
-#include <linux/types.h>
+#include "compiler.h"
 
 struct MD5Context {
        __u32 buf[4];
index 9150510bbcefc78d16c068c2920617cd3c425e72..81a09e3f904f3226f52c704b63bd7dc6aa28f3f1 100644 (file)
    and to fit the cifs vfs by
    Steve French sfrench@us.ibm.com */
 
+#include "compiler.h"
+
 #ifndef USE_HOSTCC
 #include <common.h>
-#include <linux/string.h>
-#else
-#include <string.h>
-#endif /* USE_HOSTCC */
 #include <watchdog.h>
-#include <linux/types.h>
+#endif /* USE_HOSTCC */
 #include <u-boot/md5.h>
 
 static void
index e8dd8c80046c2513f1dabfde62df86dfc9b76911..47228d255b344a755790f7cfdcbe6e27246cea86 100644 (file)
@@ -1,15 +1,4 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-#if defined(__linux__)
-#include <stdint.h>
-#else
-#ifdef __CYGWIN__
-#include "elf.h"
-#else
-#include <inttypes.h>
-#endif
-#endif
+#include "compiler.h"
 
 typedef struct bitmap_s {              /* bitmap description */
        uint16_t width;
index b04abbd8b48976885e60340fe39432f2cad67652..f10379fe42b253f1c2ff5195fa9638fc99aeac87 100644 (file)
@@ -52,6 +52,7 @@
 |  INCLUDES
 |*************************************************************************/
 
+#include "os_support.h"
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -61,8 +62,6 @@
 #include <unistd.h>
 #include <errno.h>
 
-extern int errno;
-
 /*************************************************************************
 |  DEFINES
 |*************************************************************************/
index 1fb6c93824cb56c355d868c49788caef33b925e1..9e45e64911b6ff9d643f5ab5da285a610a39c2fd 100644 (file)
@@ -34,9 +34,6 @@
 #define MAP_SHARED     0x01            /* Share changes */
 #define MAP_PRIVATE    0x02            /* Changes are private */
 
-/* Return value of `mmap' in case of an error */
-#define MAP_FAILED     ((void *) -1)
-
 /* Windows 64-bit access macros */
 #define LODWORD(x) ((DWORD)((DWORDLONG)(x)))
 #define HIDWORD(x) ((DWORD)(((DWORDLONG)(x) >> 32) & 0xffffffff))
index 967fe9a776a87c9e88a2f68a295a0a48d5da8d85..02cdb953877b9287ce55d564078a6c3fb53ffd5a 100644 (file)
 #include "mkimage.h"
 #include <image.h>
 
-extern int errno;
-
-#ifndef MAP_FAILED
-#define MAP_FAILED (void *)(-1)
-#endif
-
 extern unsigned long   crc32 (unsigned long crc, const char *buf, unsigned int len);
 static void            copy_file (int, const char *, int);
 static void            usage (void);
@@ -502,7 +496,7 @@ image_verify_header (char *ptr, int image_size)
         */
        memcpy (hdr, ptr, sizeof(image_header_t));
 
-       if (ntohl(hdr->ih_magic) != IH_MAGIC) {
+       if (be32_to_cpu(hdr->ih_magic) != IH_MAGIC) {
                fprintf (stderr,
                        "%s: Bad Magic Number: \"%s\" is no valid image\n",
                        cmdname, imagefile);
@@ -512,8 +506,8 @@ image_verify_header (char *ptr, int image_size)
        data = (char *)hdr;
        len  = sizeof(image_header_t);
 
-       checksum = ntohl(hdr->ih_hcrc);
-       hdr->ih_hcrc = htonl(0);        /* clear for re-calculation */
+       checksum = be32_to_cpu(hdr->ih_hcrc);
+       hdr->ih_hcrc = cpu_to_be32(0);  /* clear for re-calculation */
 
        if (crc32 (0, data, len) != checksum) {
                fprintf (stderr,
@@ -525,7 +519,7 @@ image_verify_header (char *ptr, int image_size)
        data = ptr + sizeof(image_header_t);
        len  = image_size - sizeof(image_header_t) ;
 
-       if (crc32 (0, data, len) != ntohl(hdr->ih_dcrc)) {
+       if (crc32 (0, data, len) != be32_to_cpu(hdr->ih_dcrc)) {
                fprintf (stderr,
                        "%s: ERROR: \"%s\" has corrupted data!\n",
                        cmdname, imagefile);
index c8df6e1f64f95282fb35207090b542816ff54f9e..70c53add1696c3e6e77022071fabbeb35a24a7f7 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#ifndef __WIN32__
-#include <netinet/in.h>                /* for host / network byte order conversions    */
-#endif
-#ifdef __MINGW32__
-#include <stdint.h>
-#else
-#include <sys/mman.h>
-#endif
 #include <sys/stat.h>
 #include <time.h>
 #include <unistd.h>
 #define MKIMAGE_DEFAULT_DTC_OPTIONS    "-I dts -O dtb -p 500"
 #define MKIMAGE_MAX_DTC_CMDLINE_LEN    512
 #define MKIMAGE_DTC                    "dtc"   /* assume dtc is in $PATH */
-
-#if defined(__BEOS__) || defined(__NetBSD__) || defined(__APPLE__)
-#include <inttypes.h>
-#endif
-
-#ifdef __WIN32__
-typedef unsigned int __u32;
-
-#define SWAP_LONG(x) \
-       ((__u32)( \
-               (((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
-               (((__u32)(x) & (__u32)0x0000ff00UL) <<  8) | \
-               (((__u32)(x) & (__u32)0x00ff0000UL) >>  8) | \
-               (((__u32)(x) & (__u32)0xff000000UL) >> 24) ))
-typedef                unsigned char   uint8_t;
-typedef                unsigned short  uint16_t;
-typedef                unsigned int    uint32_t;
-
-#define     ntohl(a)   SWAP_LONG(a)
-#define     htonl(a)   SWAP_LONG(a)
-#endif /* __WIN32__ */
-
-#ifndef        O_BINARY                /* should be define'd on __WIN32__ */
-#define O_BINARY       0
-#endif
index 001fe6476436db9e3022df5de465c35772a03076..5b919aa867e6dabb03e4581f97173841ce8252b8 100644 (file)
@@ -19,6 +19,7 @@
 /*
  * Include additional files required for supporting different operating systems
  */
+#include "compiler.h"
 #ifdef __MINGW32__
 #include "mingw_support.c"
 #endif
index f6f86b04d5749e70dbfc3375623135f4bb79f043..7bf930e22a3152c47ea620bba4d3b213759fc224 100644 (file)
@@ -19,6 +19,8 @@
 #ifndef __OS_SUPPORT_H_
 #define __OS_SUPPORT_H_
 
+#include "compiler.h"
+
 /*
  * Include additional files required for supporting different operating systems
  */
index c4203ed99e3da8e55fcb93c4a1edd09d132530e6..9774eea32e59ff94c21336e825dab88bdbe19a60 100644 (file)
@@ -28,9 +28,6 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <string.h>
-#ifndef __MINGW32__
-#include <sys/mman.h>
-#endif
 #include <sys/stat.h>
 #include "sha1.h"
 
 #include <config.h>
 #undef __ASSEMBLY__
 
-#ifndef        O_BINARY                /* should be define'd on __WIN32__ */
-#define O_BINARY       0
-#endif
-
-#ifndef MAP_FAILED
-#define MAP_FAILED (-1)
-#endif
-
-extern int errno;
-
 extern void sha1_csum (unsigned char *input, int ilen, unsigned char output[20]);
 
 int main (int argc, char **argv)