summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2009-07-02 19:23:25 -0400
committerWolfgang Denk <wd@denx.de>2009-07-19 21:41:46 +0200
commit37566090766d61beef70c62986b90749920255d8 (patch)
tree6770441ddc1bc0b9e662e2ea7102da8e10b62d61 /tools
parent2a2ed845c085eb093b69fa6382fcf7534bb1f4b0 (diff)
compiler.h: unify system ifdef cruft here
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>
Diffstat (limited to 'tools')
-rw-r--r--tools/bmp_logo.c13
-rw-r--r--tools/img2srec.c3
-rw-r--r--tools/mingw_support.h3
-rw-r--r--tools/mkimage.c14
-rw-r--r--tools/mkimage.h33
-rw-r--r--tools/os_support.c1
-rw-r--r--tools/os_support.h2
-rw-r--r--tools/ubsha1.c13
8 files changed, 9 insertions, 73 deletions
diff --git a/tools/bmp_logo.c b/tools/bmp_logo.c
index e8dd8c80046..47228d255b3 100644
--- a/tools/bmp_logo.c
+++ b/tools/bmp_logo.c
@@ -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;
diff --git a/tools/img2srec.c b/tools/img2srec.c
index b04abbd8b48..f10379fe42b 100644
--- a/tools/img2srec.c
+++ b/tools/img2srec.c
@@ -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
|*************************************************************************/
diff --git a/tools/mingw_support.h b/tools/mingw_support.h
index 1fb6c93824c..9e45e64911b 100644
--- a/tools/mingw_support.h
+++ b/tools/mingw_support.h
@@ -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))
diff --git a/tools/mkimage.c b/tools/mkimage.c
index 967fe9a776a..02cdb953877 100644
--- a/tools/mkimage.c
+++ b/tools/mkimage.c
@@ -25,12 +25,6 @@
#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);
diff --git a/tools/mkimage.h b/tools/mkimage.h
index c8df6e1f64f..70c53add169 100644
--- a/tools/mkimage.h
+++ b/tools/mkimage.h
@@ -26,14 +26,6 @@
#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>
@@ -53,28 +45,3 @@
#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
diff --git a/tools/os_support.c b/tools/os_support.c
index 001fe647643..5b919aa867e 100644
--- a/tools/os_support.c
+++ b/tools/os_support.c
@@ -19,6 +19,7 @@
/*
* Include additional files required for supporting different operating systems
*/
+#include "compiler.h"
#ifdef __MINGW32__
#include "mingw_support.c"
#endif
diff --git a/tools/os_support.h b/tools/os_support.h
index f6f86b04d57..7bf930e22a3 100644
--- a/tools/os_support.h
+++ b/tools/os_support.h
@@ -19,6 +19,8 @@
#ifndef __OS_SUPPORT_H_
#define __OS_SUPPORT_H_
+#include "compiler.h"
+
/*
* Include additional files required for supporting different operating systems
*/
diff --git a/tools/ubsha1.c b/tools/ubsha1.c
index c4203ed99e3..9774eea32e5 100644
--- a/tools/ubsha1.c
+++ b/tools/ubsha1.c
@@ -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"
@@ -40,16 +37,6 @@
#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)