1*4882a593SmuzhiyunFix build on big endian systems 2*4882a593Smuzhiyun 3*4882a593SmuzhiyunThe usb_linux_client.c file defines cpu_to_le16/32 by using the C 4*4882a593Smuzhiyunlibrary htole16/32 function calls. However, cpu_to_le16/32 are used 5*4882a593Smuzhiyunwhen initializing structures, i.e in a context where a function call 6*4882a593Smuzhiyunis not allowed. 7*4882a593Smuzhiyun 8*4882a593SmuzhiyunIt works fine on little endian systems because htole16/32 are defined 9*4882a593Smuzhiyunby the C library as no-ops. But on big-endian systems, they are 10*4882a593Smuzhiyunactually doing something, which might involve calling a function, 11*4882a593Smuzhiyuncausing build failures. 12*4882a593Smuzhiyun 13*4882a593SmuzhiyunTo solve this, we simply open-code cpu_to_le16/32 in a way that allows 14*4882a593Smuzhiyunthem to be used when initializing structures. 15*4882a593Smuzhiyun 16*4882a593SmuzhiyunSigned-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> 17*4882a593Smuzhiyun 18*4882a593SmuzhiyunIndex: b/core/adb/usb_linux_client.c 19*4882a593Smuzhiyun=================================================================== 20*4882a593Smuzhiyun--- a/core/adb/usb_linux_client.c 21*4882a593Smuzhiyun+++ b/core/adb/usb_linux_client.c 22*4882a593Smuzhiyun@@ -34,8 +34,15 @@ 23*4882a593Smuzhiyun #define MAX_PACKET_SIZE_FS 64 24*4882a593Smuzhiyun #define MAX_PACKET_SIZE_HS 512 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun-#define cpu_to_le16(x) htole16(x) 27*4882a593Smuzhiyun-#define cpu_to_le32(x) htole32(x) 28*4882a593Smuzhiyun+#if __BYTE_ORDER == __LITTLE_ENDIAN 29*4882a593Smuzhiyun+# define cpu_to_le16(x) (x) 30*4882a593Smuzhiyun+# define cpu_to_le32(x) (x) 31*4882a593Smuzhiyun+#else 32*4882a593Smuzhiyun+# define cpu_to_le16(x) ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8)) 33*4882a593Smuzhiyun+# define cpu_to_le32(x) \ 34*4882a593Smuzhiyun+ ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8) | \ 35*4882a593Smuzhiyun+ (((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24)) 36*4882a593Smuzhiyun+#endif 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun struct usb_handle 39*4882a593Smuzhiyun { 40*4882a593SmuzhiyunIndex: b/core/adbd/usb_linux_client.c 41*4882a593Smuzhiyun=================================================================== 42*4882a593Smuzhiyun--- a/core/adbd/usb_linux_client.c 43*4882a593Smuzhiyun+++ b/core/adbd/usb_linux_client.c 44*4882a593Smuzhiyun@@ -34,8 +34,15 @@ 45*4882a593Smuzhiyun #define MAX_PACKET_SIZE_FS 64 46*4882a593Smuzhiyun #define MAX_PACKET_SIZE_HS 512 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun-#define cpu_to_le16(x) htole16(x) 49*4882a593Smuzhiyun-#define cpu_to_le32(x) htole32(x) 50*4882a593Smuzhiyun+#if __BYTE_ORDER == __LITTLE_ENDIAN 51*4882a593Smuzhiyun+# define cpu_to_le16(x) (x) 52*4882a593Smuzhiyun+# define cpu_to_le32(x) (x) 53*4882a593Smuzhiyun+#else 54*4882a593Smuzhiyun+# define cpu_to_le16(x) ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8)) 55*4882a593Smuzhiyun+# define cpu_to_le32(x) \ 56*4882a593Smuzhiyun+ ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8) | \ 57*4882a593Smuzhiyun+ (((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24)) 58*4882a593Smuzhiyun+#endif 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun struct usb_handle 61*4882a593Smuzhiyun { 62