Commit ed8271d11c5c7a31eb49f787fa25eece6b82bb9e

Authored by Jeroen Hofstee
Committed by Tom Rini
1 parent 4a74298c54

tools: compiler.h: Fix build on FreeBSD

Commit 832472 "tools: socfpga: Add socfpga preloader signing
to mkimage" added tools/socfpga.c which relies on htole32,
le32toh and friends. While compiler.h includes these protypes
for linux from endian.h, it doesn't do so for FreeBSD. Hence
include <sys/endian.h> for FreeBSD.

Cc: Marek Vasut <marex@denx.de>
CC: Tom Rini <trini@ti.com>
Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>

Showing 1 changed file with 4 additions and 0 deletions Inline Diff

1 /* 1 /*
2 * Keep all the ugly #ifdef for system stuff here 2 * Keep all the ugly #ifdef for system stuff here
3 */ 3 */
4 4
5 #ifndef __COMPILER_H__ 5 #ifndef __COMPILER_H__
6 #define __COMPILER_H__ 6 #define __COMPILER_H__
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #ifdef USE_HOSTCC 10 #ifdef USE_HOSTCC
11 11
12 #if defined(__BEOS__) || \ 12 #if defined(__BEOS__) || \
13 defined(__NetBSD__) || \ 13 defined(__NetBSD__) || \
14 defined(__FreeBSD__) || \ 14 defined(__FreeBSD__) || \
15 defined(__sun__) || \ 15 defined(__sun__) || \
16 defined(__APPLE__) 16 defined(__APPLE__)
17 # include <inttypes.h> 17 # include <inttypes.h>
18 #elif defined(__linux__) || defined(__WIN32__) || defined(__MINGW32__) 18 #elif defined(__linux__) || defined(__WIN32__) || defined(__MINGW32__)
19 # include <stdint.h> 19 # include <stdint.h>
20 #endif 20 #endif
21 21
22 #include <errno.h> 22 #include <errno.h>
23 #include <stdlib.h> 23 #include <stdlib.h>
24 #include <stdint.h> 24 #include <stdint.h>
25 #include <stdio.h> 25 #include <stdio.h>
26 #include <string.h> 26 #include <string.h>
27 27
28 #if !defined(__WIN32__) && !defined(__MINGW32__) 28 #if !defined(__WIN32__) && !defined(__MINGW32__)
29 # include <sys/mman.h> 29 # include <sys/mman.h>
30 #endif 30 #endif
31 31
32 /* Not all systems (like Windows) has this define, and yes 32 /* Not all systems (like Windows) has this define, and yes
33 * we do replace/emulate mmap() on those systems ... 33 * we do replace/emulate mmap() on those systems ...
34 */ 34 */
35 #ifndef MAP_FAILED 35 #ifndef MAP_FAILED
36 # define MAP_FAILED ((void *)-1) 36 # define MAP_FAILED ((void *)-1)
37 #endif 37 #endif
38 38
39 #include <fcntl.h> 39 #include <fcntl.h>
40 #ifndef O_BINARY /* should be define'd on __WIN32__ */ 40 #ifndef O_BINARY /* should be define'd on __WIN32__ */
41 #define O_BINARY 0 41 #define O_BINARY 0
42 #endif 42 #endif
43 43
44 #ifdef __linux__ 44 #ifdef __linux__
45 # include <endian.h> 45 # include <endian.h>
46 # include <byteswap.h> 46 # include <byteswap.h>
47 #elif defined(__MACH__) || defined(__FreeBSD__) 47 #elif defined(__MACH__) || defined(__FreeBSD__)
48 # include <machine/endian.h> 48 # include <machine/endian.h>
49 typedef unsigned long ulong; 49 typedef unsigned long ulong;
50 #endif 50 #endif
51 #ifdef __FreeBSD__
52 # include <sys/endian.h> /* htole32 and friends */
53 #endif
54
51 #include <time.h> 55 #include <time.h>
52 56
53 typedef uint8_t __u8; 57 typedef uint8_t __u8;
54 typedef uint16_t __u16; 58 typedef uint16_t __u16;
55 typedef uint32_t __u32; 59 typedef uint32_t __u32;
56 typedef unsigned int uint; 60 typedef unsigned int uint;
57 61
58 #define uswap_16(x) \ 62 #define uswap_16(x) \
59 ((((x) & 0xff00) >> 8) | \ 63 ((((x) & 0xff00) >> 8) | \
60 (((x) & 0x00ff) << 8)) 64 (((x) & 0x00ff) << 8))
61 #define uswap_32(x) \ 65 #define uswap_32(x) \
62 ((((x) & 0xff000000) >> 24) | \ 66 ((((x) & 0xff000000) >> 24) | \
63 (((x) & 0x00ff0000) >> 8) | \ 67 (((x) & 0x00ff0000) >> 8) | \
64 (((x) & 0x0000ff00) << 8) | \ 68 (((x) & 0x0000ff00) << 8) | \
65 (((x) & 0x000000ff) << 24)) 69 (((x) & 0x000000ff) << 24))
66 #define _uswap_64(x, sfx) \ 70 #define _uswap_64(x, sfx) \
67 ((((x) & 0xff00000000000000##sfx) >> 56) | \ 71 ((((x) & 0xff00000000000000##sfx) >> 56) | \
68 (((x) & 0x00ff000000000000##sfx) >> 40) | \ 72 (((x) & 0x00ff000000000000##sfx) >> 40) | \
69 (((x) & 0x0000ff0000000000##sfx) >> 24) | \ 73 (((x) & 0x0000ff0000000000##sfx) >> 24) | \
70 (((x) & 0x000000ff00000000##sfx) >> 8) | \ 74 (((x) & 0x000000ff00000000##sfx) >> 8) | \
71 (((x) & 0x00000000ff000000##sfx) << 8) | \ 75 (((x) & 0x00000000ff000000##sfx) << 8) | \
72 (((x) & 0x0000000000ff0000##sfx) << 24) | \ 76 (((x) & 0x0000000000ff0000##sfx) << 24) | \
73 (((x) & 0x000000000000ff00##sfx) << 40) | \ 77 (((x) & 0x000000000000ff00##sfx) << 40) | \
74 (((x) & 0x00000000000000ff##sfx) << 56)) 78 (((x) & 0x00000000000000ff##sfx) << 56))
75 #if defined(__GNUC__) 79 #if defined(__GNUC__)
76 # define uswap_64(x) _uswap_64(x, ull) 80 # define uswap_64(x) _uswap_64(x, ull)
77 #else 81 #else
78 # define uswap_64(x) _uswap_64(x, ) 82 # define uswap_64(x) _uswap_64(x, )
79 #endif 83 #endif
80 84
81 #if __BYTE_ORDER == __LITTLE_ENDIAN 85 #if __BYTE_ORDER == __LITTLE_ENDIAN
82 # define cpu_to_le16(x) (x) 86 # define cpu_to_le16(x) (x)
83 # define cpu_to_le32(x) (x) 87 # define cpu_to_le32(x) (x)
84 # define cpu_to_le64(x) (x) 88 # define cpu_to_le64(x) (x)
85 # define le16_to_cpu(x) (x) 89 # define le16_to_cpu(x) (x)
86 # define le32_to_cpu(x) (x) 90 # define le32_to_cpu(x) (x)
87 # define le64_to_cpu(x) (x) 91 # define le64_to_cpu(x) (x)
88 # define cpu_to_be16(x) uswap_16(x) 92 # define cpu_to_be16(x) uswap_16(x)
89 # define cpu_to_be32(x) uswap_32(x) 93 # define cpu_to_be32(x) uswap_32(x)
90 # define cpu_to_be64(x) uswap_64(x) 94 # define cpu_to_be64(x) uswap_64(x)
91 # define be16_to_cpu(x) uswap_16(x) 95 # define be16_to_cpu(x) uswap_16(x)
92 # define be32_to_cpu(x) uswap_32(x) 96 # define be32_to_cpu(x) uswap_32(x)
93 # define be64_to_cpu(x) uswap_64(x) 97 # define be64_to_cpu(x) uswap_64(x)
94 #else 98 #else
95 # define cpu_to_le16(x) uswap_16(x) 99 # define cpu_to_le16(x) uswap_16(x)
96 # define cpu_to_le32(x) uswap_32(x) 100 # define cpu_to_le32(x) uswap_32(x)
97 # define cpu_to_le64(x) uswap_64(x) 101 # define cpu_to_le64(x) uswap_64(x)
98 # define le16_to_cpu(x) uswap_16(x) 102 # define le16_to_cpu(x) uswap_16(x)
99 # define le32_to_cpu(x) uswap_32(x) 103 # define le32_to_cpu(x) uswap_32(x)
100 # define le64_to_cpu(x) uswap_64(x) 104 # define le64_to_cpu(x) uswap_64(x)
101 # define cpu_to_be16(x) (x) 105 # define cpu_to_be16(x) (x)
102 # define cpu_to_be32(x) (x) 106 # define cpu_to_be32(x) (x)
103 # define cpu_to_be64(x) (x) 107 # define cpu_to_be64(x) (x)
104 # define be16_to_cpu(x) (x) 108 # define be16_to_cpu(x) (x)
105 # define be32_to_cpu(x) (x) 109 # define be32_to_cpu(x) (x)
106 # define be64_to_cpu(x) (x) 110 # define be64_to_cpu(x) (x)
107 #endif 111 #endif
108 112
109 #else /* !USE_HOSTCC */ 113 #else /* !USE_HOSTCC */
110 114
111 #include <linux/string.h> 115 #include <linux/string.h>
112 #include <linux/types.h> 116 #include <linux/types.h>
113 #include <asm/byteorder.h> 117 #include <asm/byteorder.h>
114 118
115 #if __SIZEOF_LONG__ == 8 119 #if __SIZEOF_LONG__ == 8
116 # define __WORDSIZE 64 120 # define __WORDSIZE 64
117 #elif __SIZEOF_LONG__ == 4 121 #elif __SIZEOF_LONG__ == 4
118 # define __WORDSIZE 32 122 # define __WORDSIZE 32
119 #else 123 #else
120 /* 124 /*
121 * Assume 32-bit for now - only newer toolchains support this feature and 125 * Assume 32-bit for now - only newer toolchains support this feature and
122 * this is only required for sandbox support at present. 126 * this is only required for sandbox support at present.
123 */ 127 */
124 #define __WORDSIZE 32 128 #define __WORDSIZE 32
125 #endif 129 #endif
126 130
127 /* Type for `void *' pointers. */ 131 /* Type for `void *' pointers. */
128 typedef unsigned long int uintptr_t; 132 typedef unsigned long int uintptr_t;
129 133
130 #endif /* USE_HOSTCC */ 134 #endif /* USE_HOSTCC */
131 135
132 #define likely(x) __builtin_expect(!!(x), 1) 136 #define likely(x) __builtin_expect(!!(x), 1)
133 #define unlikely(x) __builtin_expect(!!(x), 0) 137 #define unlikely(x) __builtin_expect(!!(x), 0)
134 138
135 #endif 139 #endif
136 140