summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/compiler.h125
-rw-r--r--include/elf.h10
-rw-r--r--include/environment.h6
-rw-r--r--include/image.h13
-rw-r--r--include/libfdt_env.h53
-rw-r--r--include/u-boot/md5.h2
6 files changed, 138 insertions, 71 deletions
diff --git a/include/compiler.h b/include/compiler.h
new file mode 100644
index 0000000..272fd3c
--- /dev/null
+++ b/include/compiler.h
@@ -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
diff --git a/include/elf.h b/include/elf.h
index f640388..29f276d 100644
--- a/include/elf.h
+++ b/include/elf.h
@@ -33,15 +33,7 @@
#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.
diff --git a/include/environment.h b/include/environment.h
index 507e832..5bed32f 100644
--- a/include/environment.h
+++ b/include/environment.h
@@ -96,11 +96,7 @@
# 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)
diff --git a/include/image.h b/include/image.h
index f183757..beb3a16 100644
--- a/include/image.h
+++ b/include/image.h
@@ -33,10 +33,9 @@
#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);
diff --git a/include/libfdt_env.h b/include/libfdt_env.h
index 1c67015..bf63583 100644
--- a/include/libfdt_env.h
+++ b/include/libfdt_env.h
@@ -21,56 +21,13 @@
#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 */
diff --git a/include/u-boot/md5.h b/include/u-boot/md5.h
index 8b44a7f..08924cc 100644
--- a/include/u-boot/md5.h
+++ b/include/u-boot/md5.h
@@ -6,7 +6,7 @@
#ifndef _MD5_H
#define _MD5_H
-#include <linux/types.h>
+#include "compiler.h"
struct MD5Context {
__u32 buf[4];