blob: 79e9d4d3b2c302a93ddfe8da3dfb7a6e63966903 [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001From 548b8ca62c64a16305929e2eaf3d546d48de9c25 Mon Sep 17 00:00:00 2001
2From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
3Date: Tue, 21 Feb 2017 19:46:24 +0100
4Subject: [PATCH] adb: Fix build on big endian systems
5
6The usb_linux_client.c file defines cpu_to_le16/32 by using the C
7library htole16/32 function calls. However, cpu_to_le16/32 are used
8when initializing structures, i.e in a context where a function call
9is not allowed.
10
11It works fine on little endian systems because htole16/32 are defined
12by the C library as no-ops. But on big-endian systems, they are
13actually doing something, which might involve calling a function,
14causing build failures.
15
16To solve this, we simply open-code cpu_to_le16/32 in a way that allows
17them to be used when initializing structures.
18
19Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
20---
21 adb/usb_linux_client.c | 11 +++++++++--
22 1 file changed, 9 insertions(+), 2 deletions(-)
23
24diff --git a/adb/usb_linux_client.c b/adb/usb_linux_client.c
25index 8426e0ea14..6e8b5bbbd2 100644
26--- a/adb/usb_linux_client.c
27+++ b/adb/usb_linux_client.c
28@@ -34,8 +34,15 @@
29 #define MAX_PACKET_SIZE_FS 64
30 #define MAX_PACKET_SIZE_HS 512
31
32-#define cpu_to_le16(x) htole16(x)
33-#define cpu_to_le32(x) htole32(x)
34+#if __BYTE_ORDER == __LITTLE_ENDIAN
35+# define cpu_to_le16(x) (x)
36+# define cpu_to_le32(x) (x)
37+#else
38+# define cpu_to_le16(x) ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8))
39+# define cpu_to_le32(x) \
40+ ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8) | \
41+ (((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24))
42+#endif
43
44 struct usb_handle
45 {