1 Fix build on big endian systems
3 The usb_linux_client.c file defines cpu_to_le16/32 by using the C
4 library htole16/32 function calls. However, cpu_to_le16/32 are used
5 when initializing structures, i.e in a context where a function call
8 It works fine on little endian systems because htole16/32 are defined
9 by the C library as no-ops. But on big-endian systems, they are
10 actually doing something, which might involve calling a function,
11 causing build failures.
13 To solve this, we simply open-code cpu_to_le16/32 in a way that allows
14 them to be used when initializing structures.
16 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
18 Index: b/core/adb/usb_linux_client.c
19 ===================================================================
20 --- a/core/adb/usb_linux_client.c
21 +++ b/core/adb/usb_linux_client.c
23 #define MAX_PACKET_SIZE_FS 64
24 #define MAX_PACKET_SIZE_HS 512
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)
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))
40 Index: b/core/adbd/usb_linux_client.c
41 ===================================================================
42 --- a/core/adbd/usb_linux_client.c
43 +++ b/core/adbd/usb_linux_client.c
45 #define MAX_PACKET_SIZE_FS 64
46 #define MAX_PACKET_SIZE_HS 512
48 -#define cpu_to_le16(x) htole16(x)
49 -#define cpu_to_le32(x) htole32(x)
50 +#if __BYTE_ORDER == __LITTLE_ENDIAN
51 +# define cpu_to_le16(x) (x)
52 +# define cpu_to_le32(x) (x)
54 +# define cpu_to_le16(x) ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8))
55 +# define cpu_to_le32(x) \
56 + ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8) | \
57 + (((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24))