Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1 | Fix build on big endian systems |
| 2 | |
| 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 |
| 6 | is not allowed. |
| 7 | |
| 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. |
| 12 | |
| 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. |
| 15 | |
| 16 | Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> |
| 17 | |
| 18 | Index: 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 | { |