blob: 8deaf3a3d730a03180e618dfbbdf14f0729f118b [file] [log] [blame]
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001Fix build on big endian systems
2
3The usb_linux_client.c file defines cpu_to_le16/32 by using the C
4library htole16/32 function calls. However, cpu_to_le16/32 are used
5when initializing structures, i.e in a context where a function call
6is not allowed.
7
8It works fine on little endian systems because htole16/32 are defined
9by the C library as no-ops. But on big-endian systems, they are
10actually doing something, which might involve calling a function,
11causing build failures.
12
13To solve this, we simply open-code cpu_to_le16/32 in a way that allows
14them to be used when initializing structures.
15
16Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
17
18Index: b/system/core/adb/usb_linux_client.c
19===================================================================
20--- a/system/core/adb/usb_linux_client.c
21+++ b/system/core/adb/usb_linux_client.c
22@@ -34,8 +34,15 @@
23 #define MAX_PACKET_SIZE_FS 64
24 #define MAX_PACKET_SIZE_HS 512
25
26-#define cpu_to_le16(x) htole16(x)
27-#define cpu_to_le32(x) htole32(x)
28+#if __BYTE_ORDER == __LITTLE_ENDIAN
29+# define cpu_to_le16(x) (x)
30+# define cpu_to_le32(x) (x)
31+#else
32+# define cpu_to_le16(x) ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8))
33+# define cpu_to_le32(x) \
34+ ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8) | \
35+ (((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24))
36+#endif
37
38 struct usb_handle
39 {