From 77158819158d1d7053a737ac090d04fdfbfe9265 Mon Sep 17 00:00:00 2001 From: Joel Stanley Date: Wed, 20 Sep 2017 16:56:57 +0930 Subject: device: remove use of ccan's endian MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When cross compiling with uclibc under buildroot, we get the following clash: ./ccan/endian/endian.h:84:24: error: redefinition of ‘__bswap_32’ static inline uint32_t bswap_32(uint32_t val) ^ In file included from usr/include/bits/byteswap.h:1:0, from usr/include/byteswap.h:22, from usr/include/endian.h:59, from usr/include/bits/pthreadtypes.h:21, from usr/include/bits/uClibc_stdio.h:92, from usr/include/stdio.h:71, from libpdbg/device.c:18: usr/include/bits/byteswap-common.h:44:1: note: previous definition of ‘__bswap_32’ was here __bswap_32 (unsigned int __bsx) ^~~~~~~~~~ Work around it by not using ccan's endian. There's only one call site, and we can use a libc function instead. Signed-off-by: Joel Stanley Signed-off-by: Alistair Popple --- ccan/endian/LICENSE | 1 - ccan/endian/_info | 55 ------ ccan/endian/endian.h | 346 --------------------------------- ccan/endian/test/compile_ok-constant.c | 12 -- ccan/endian/test/run.c | 106 ---------- 5 files changed, 520 deletions(-) delete mode 120000 ccan/endian/LICENSE delete mode 100644 ccan/endian/_info delete mode 100644 ccan/endian/endian.h delete mode 100644 ccan/endian/test/compile_ok-constant.c delete mode 100644 ccan/endian/test/run.c (limited to 'ccan') diff --git a/ccan/endian/LICENSE b/ccan/endian/LICENSE deleted file mode 120000 index b7951da..0000000 --- a/ccan/endian/LICENSE +++ /dev/null @@ -1 +0,0 @@ -../../licenses/CC0 \ No newline at end of file diff --git a/ccan/endian/_info b/ccan/endian/_info deleted file mode 100644 index efe5a8b..0000000 --- a/ccan/endian/_info +++ /dev/null @@ -1,55 +0,0 @@ -#include "config.h" -#include -#include - -/** - * endian - endian conversion macros for simple types - * - * Portable protocols (such as on-disk formats, or network protocols) - * are often defined to be a particular endian: little-endian (least - * significant bytes first) or big-endian (most significant bytes - * first). - * - * Similarly, some CPUs lay out values in memory in little-endian - * order (most commonly, Intel's 8086 and derivatives), or big-endian - * order (almost everyone else). - * - * This module provides conversion routines, inspired by the linux kernel. - * It also provides leint32_t, beint32_t etc typedefs, which are annotated for - * the sparse checker. - * - * Example: - * #include - * #include - * #include - * - * // - * int main(int argc, char *argv[]) - * { - * uint32_t value; - * - * if (argc != 2) - * errx(1, "Usage: %s ", argv[0]); - * - * value = atoi(argv[1]); - * printf("native: %08x\n", value); - * printf("little-endian: %08x\n", cpu_to_le32(value)); - * printf("big-endian: %08x\n", cpu_to_be32(value)); - * printf("byte-reversed: %08x\n", bswap_32(value)); - * exit(0); - * } - * - * License: License: CC0 (Public domain) - * Author: Rusty Russell - */ -int main(int argc, char *argv[]) -{ - if (argc != 2) - return 1; - - if (strcmp(argv[1], "depends") == 0) - /* Nothing */ - return 0; - - return 1; -} diff --git a/ccan/endian/endian.h b/ccan/endian/endian.h deleted file mode 100644 index 0c99cc8..0000000 --- a/ccan/endian/endian.h +++ /dev/null @@ -1,346 +0,0 @@ -/* CC0 (Public domain) - see LICENSE file for details */ -#ifndef CCAN_ENDIAN_H -#define CCAN_ENDIAN_H -#include -#include "config.h" - -/** - * BSWAP_16 - reverse bytes in a constant uint16_t value. - * @val: constant value whose bytes to swap. - * - * Designed to be usable in constant-requiring initializers. - * - * Example: - * struct mystruct { - * char buf[BSWAP_16(0x1234)]; - * }; - */ -#define BSWAP_16(val) \ - ((((uint16_t)(val) & 0x00ff) << 8) \ - | (((uint16_t)(val) & 0xff00) >> 8)) - -/** - * BSWAP_32 - reverse bytes in a constant uint32_t value. - * @val: constant value whose bytes to swap. - * - * Designed to be usable in constant-requiring initializers. - * - * Example: - * struct mystruct { - * char buf[BSWAP_32(0xff000000)]; - * }; - */ -#define BSWAP_32(val) \ - ((((uint32_t)(val) & 0x000000ff) << 24) \ - | (((uint32_t)(val) & 0x0000ff00) << 8) \ - | (((uint32_t)(val) & 0x00ff0000) >> 8) \ - | (((uint32_t)(val) & 0xff000000) >> 24)) - -/** - * BSWAP_64 - reverse bytes in a constant uint64_t value. - * @val: constantvalue whose bytes to swap. - * - * Designed to be usable in constant-requiring initializers. - * - * Example: - * struct mystruct { - * char buf[BSWAP_64(0xff00000000000000ULL)]; - * }; - */ -#define BSWAP_64(val) \ - ((((uint64_t)(val) & 0x00000000000000ffULL) << 56) \ - | (((uint64_t)(val) & 0x000000000000ff00ULL) << 40) \ - | (((uint64_t)(val) & 0x0000000000ff0000ULL) << 24) \ - | (((uint64_t)(val) & 0x00000000ff000000ULL) << 8) \ - | (((uint64_t)(val) & 0x000000ff00000000ULL) >> 8) \ - | (((uint64_t)(val) & 0x0000ff0000000000ULL) >> 24) \ - | (((uint64_t)(val) & 0x00ff000000000000ULL) >> 40) \ - | (((uint64_t)(val) & 0xff00000000000000ULL) >> 56)) - -#if HAVE_BYTESWAP_H -#include -#else -/** - * bswap_16 - reverse bytes in a uint16_t value. - * @val: value whose bytes to swap. - * - * Example: - * // Output contains "1024 is 4 as two bytes reversed" - * printf("1024 is %u as two bytes reversed\n", bswap_16(1024)); - */ -static inline uint16_t bswap_16(uint16_t val) -{ - return BSWAP_16(val); -} - -/** - * bswap_32 - reverse bytes in a uint32_t value. - * @val: value whose bytes to swap. - * - * Example: - * // Output contains "1024 is 262144 as four bytes reversed" - * printf("1024 is %u as four bytes reversed\n", bswap_32(1024)); - */ -static inline uint32_t bswap_32(uint32_t val) -{ - return BSWAP_32(val); -} -#endif /* !HAVE_BYTESWAP_H */ - -#if !HAVE_BSWAP_64 -/** - * bswap_64 - reverse bytes in a uint64_t value. - * @val: value whose bytes to swap. - * - * Example: - * // Output contains "1024 is 1125899906842624 as eight bytes reversed" - * printf("1024 is %llu as eight bytes reversed\n", - * (unsigned long long)bswap_64(1024)); - */ -static inline uint64_t bswap_64(uint64_t val) -{ - return BSWAP_64(val); -} -#endif - -/* Sanity check the defines. We don't handle weird endianness. */ -#if !HAVE_LITTLE_ENDIAN && !HAVE_BIG_ENDIAN -#error "Unknown endian" -#elif HAVE_LITTLE_ENDIAN && HAVE_BIG_ENDIAN -#error "Can't compile for both big and little endian." -#endif - -#ifdef __CHECKER__ -/* sparse needs forcing to remove bitwise attribute from ccan/short_types */ -#define ENDIAN_CAST __attribute__((force)) -#define ENDIAN_TYPE __attribute__((bitwise)) -#else -#define ENDIAN_CAST -#define ENDIAN_TYPE -#endif - -typedef uint64_t ENDIAN_TYPE leint64_t; -typedef uint64_t ENDIAN_TYPE beint64_t; -typedef uint32_t ENDIAN_TYPE leint32_t; -typedef uint32_t ENDIAN_TYPE beint32_t; -typedef uint16_t ENDIAN_TYPE leint16_t; -typedef uint16_t ENDIAN_TYPE beint16_t; - -#if HAVE_LITTLE_ENDIAN -/** - * CPU_TO_LE64 - convert a constant uint64_t value to little-endian - * @native: constant to convert - */ -#define CPU_TO_LE64(native) ((ENDIAN_CAST leint64_t)(native)) - -/** - * CPU_TO_LE32 - convert a constant uint32_t value to little-endian - * @native: constant to convert - */ -#define CPU_TO_LE32(native) ((ENDIAN_CAST leint32_t)(native)) - -/** - * CPU_TO_LE16 - convert a constant uint16_t value to little-endian - * @native: constant to convert - */ -#define CPU_TO_LE16(native) ((ENDIAN_CAST leint16_t)(native)) - -/** - * LE64_TO_CPU - convert a little-endian uint64_t constant - * @le_val: little-endian constant to convert - */ -#define LE64_TO_CPU(le_val) ((ENDIAN_CAST uint64_t)(le_val)) - -/** - * LE32_TO_CPU - convert a little-endian uint32_t constant - * @le_val: little-endian constant to convert - */ -#define LE32_TO_CPU(le_val) ((ENDIAN_CAST uint32_t)(le_val)) - -/** - * LE16_TO_CPU - convert a little-endian uint16_t constant - * @le_val: little-endian constant to convert - */ -#define LE16_TO_CPU(le_val) ((ENDIAN_CAST uint16_t)(le_val)) - -#else /* ... HAVE_BIG_ENDIAN */ -#define CPU_TO_LE64(native) ((ENDIAN_CAST leint64_t)BSWAP_64(native)) -#define CPU_TO_LE32(native) ((ENDIAN_CAST leint32_t)BSWAP_32(native)) -#define CPU_TO_LE16(native) ((ENDIAN_CAST leint16_t)BSWAP_16(native)) -#define LE64_TO_CPU(le_val) BSWAP_64((ENDIAN_CAST uint64_t)le_val) -#define LE32_TO_CPU(le_val) BSWAP_32((ENDIAN_CAST uint32_t)le_val) -#define LE16_TO_CPU(le_val) BSWAP_16((ENDIAN_CAST uint16_t)le_val) -#endif /* HAVE_BIG_ENDIAN */ - -#if HAVE_BIG_ENDIAN -/** - * CPU_TO_BE64 - convert a constant uint64_t value to big-endian - * @native: constant to convert - */ -#define CPU_TO_BE64(native) ((ENDIAN_CAST beint64_t)(native)) - -/** - * CPU_TO_BE32 - convert a constant uint32_t value to big-endian - * @native: constant to convert - */ -#define CPU_TO_BE32(native) ((ENDIAN_CAST beint32_t)(native)) - -/** - * CPU_TO_BE16 - convert a constant uint16_t value to big-endian - * @native: constant to convert - */ -#define CPU_TO_BE16(native) ((ENDIAN_CAST beint16_t)(native)) - -/** - * BE64_TO_CPU - convert a big-endian uint64_t constant - * @le_val: big-endian constant to convert - */ -#define BE64_TO_CPU(le_val) ((ENDIAN_CAST uint64_t)(le_val)) - -/** - * BE32_TO_CPU - convert a big-endian uint32_t constant - * @le_val: big-endian constant to convert - */ -#define BE32_TO_CPU(le_val) ((ENDIAN_CAST uint32_t)(le_val)) - -/** - * BE16_TO_CPU - convert a big-endian uint16_t constant - * @le_val: big-endian constant to convert - */ -#define BE16_TO_CPU(le_val) ((ENDIAN_CAST uint16_t)(le_val)) - -#else /* ... HAVE_LITTLE_ENDIAN */ -#define CPU_TO_BE64(native) ((ENDIAN_CAST beint64_t)BSWAP_64(native)) -#define CPU_TO_BE32(native) ((ENDIAN_CAST beint32_t)BSWAP_32(native)) -#define CPU_TO_BE16(native) ((ENDIAN_CAST beint16_t)BSWAP_16(native)) -#define BE64_TO_CPU(le_val) BSWAP_64((ENDIAN_CAST uint64_t)le_val) -#define BE32_TO_CPU(le_val) BSWAP_32((ENDIAN_CAST uint32_t)le_val) -#define BE16_TO_CPU(le_val) BSWAP_16((ENDIAN_CAST uint16_t)le_val) -#endif /* HAVE_LITTE_ENDIAN */ - - -/** - * cpu_to_le64 - convert a uint64_t value to little-endian - * @native: value to convert - */ -static inline leint64_t cpu_to_le64(uint64_t native) -{ - return CPU_TO_LE64(native); -} - -/** - * cpu_to_le32 - convert a uint32_t value to little-endian - * @native: value to convert - */ -static inline leint32_t cpu_to_le32(uint32_t native) -{ - return CPU_TO_LE32(native); -} - -/** - * cpu_to_le16 - convert a uint16_t value to little-endian - * @native: value to convert - */ -static inline leint16_t cpu_to_le16(uint16_t native) -{ - return CPU_TO_LE16(native); -} - -/** - * le64_to_cpu - convert a little-endian uint64_t value - * @le_val: little-endian value to convert - */ -static inline uint64_t le64_to_cpu(leint64_t le_val) -{ - return LE64_TO_CPU(le_val); -} - -/** - * le32_to_cpu - convert a little-endian uint32_t value - * @le_val: little-endian value to convert - */ -static inline uint32_t le32_to_cpu(leint32_t le_val) -{ - return LE32_TO_CPU(le_val); -} - -/** - * le16_to_cpu - convert a little-endian uint16_t value - * @le_val: little-endian value to convert - */ -static inline uint16_t le16_to_cpu(leint16_t le_val) -{ - return LE16_TO_CPU(le_val); -} - -/** - * cpu_to_be64 - convert a uint64_t value to big endian. - * @native: value to convert - */ -static inline beint64_t cpu_to_be64(uint64_t native) -{ - return CPU_TO_BE64(native); -} - -/** - * cpu_to_be32 - convert a uint32_t value to big endian. - * @native: value to convert - */ -static inline beint32_t cpu_to_be32(uint32_t native) -{ - return CPU_TO_BE32(native); -} - -/** - * cpu_to_be16 - convert a uint16_t value to big endian. - * @native: value to convert - */ -static inline beint16_t cpu_to_be16(uint16_t native) -{ - return CPU_TO_BE16(native); -} - -/** - * be64_to_cpu - convert a big-endian uint64_t value - * @be_val: big-endian value to convert - */ -static inline uint64_t be64_to_cpu(beint64_t be_val) -{ - return BE64_TO_CPU(be_val); -} - -/** - * be32_to_cpu - convert a big-endian uint32_t value - * @be_val: big-endian value to convert - */ -static inline uint32_t be32_to_cpu(beint32_t be_val) -{ - return BE32_TO_CPU(be_val); -} - -/** - * be16_to_cpu - convert a big-endian uint16_t value - * @be_val: big-endian value to convert - */ -static inline uint16_t be16_to_cpu(beint16_t be_val) -{ - return BE16_TO_CPU(be_val); -} - -/* Whichever they include first, they get these definitions. */ -#ifdef CCAN_SHORT_TYPES_H -/** - * be64/be32/be16 - 64/32/16 bit big-endian representation. - */ -typedef beint64_t be64; -typedef beint32_t be32; -typedef beint16_t be16; - -/** - * le64/le32/le16 - 64/32/16 bit little-endian representation. - */ -typedef leint64_t le64; -typedef leint32_t le32; -typedef leint16_t le16; -#endif -#endif /* CCAN_ENDIAN_H */ diff --git a/ccan/endian/test/compile_ok-constant.c b/ccan/endian/test/compile_ok-constant.c deleted file mode 100644 index 1aef1dd..0000000 --- a/ccan/endian/test/compile_ok-constant.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -struct foo { - char one[BSWAP_16(0xFF00)]; - char two[BSWAP_32(0xFF000000)]; - char three[BSWAP_64(0xFF00000000000000ULL)]; -}; - -int main(void) -{ - return 0; -} diff --git a/ccan/endian/test/run.c b/ccan/endian/test/run.c deleted file mode 100644 index 9bf47f1..0000000 --- a/ccan/endian/test/run.c +++ /dev/null @@ -1,106 +0,0 @@ -#include -#include -#include -#include - -int main(void) -{ - union { - uint64_t u64; - unsigned char u64_bytes[8]; - } u64; - union { - uint32_t u32; - unsigned char u32_bytes[4]; - } u32; - union { - uint16_t u16; - unsigned char u16_bytes[2]; - } u16; - - plan_tests(48); - - /* Straight swap tests. */ - u64.u64_bytes[0] = 0x00; - u64.u64_bytes[1] = 0x11; - u64.u64_bytes[2] = 0x22; - u64.u64_bytes[3] = 0x33; - u64.u64_bytes[4] = 0x44; - u64.u64_bytes[5] = 0x55; - u64.u64_bytes[6] = 0x66; - u64.u64_bytes[7] = 0x77; - u64.u64 = bswap_64(u64.u64); - ok1(u64.u64_bytes[7] == 0x00); - ok1(u64.u64_bytes[6] == 0x11); - ok1(u64.u64_bytes[5] == 0x22); - ok1(u64.u64_bytes[4] == 0x33); - ok1(u64.u64_bytes[3] == 0x44); - ok1(u64.u64_bytes[2] == 0x55); - ok1(u64.u64_bytes[1] == 0x66); - ok1(u64.u64_bytes[0] == 0x77); - - u32.u32_bytes[0] = 0x00; - u32.u32_bytes[1] = 0x11; - u32.u32_bytes[2] = 0x22; - u32.u32_bytes[3] = 0x33; - u32.u32 = bswap_32(u32.u32); - ok1(u32.u32_bytes[3] == 0x00); - ok1(u32.u32_bytes[2] == 0x11); - ok1(u32.u32_bytes[1] == 0x22); - ok1(u32.u32_bytes[0] == 0x33); - - u16.u16_bytes[0] = 0x00; - u16.u16_bytes[1] = 0x11; - u16.u16 = bswap_16(u16.u16); - ok1(u16.u16_bytes[1] == 0x00); - ok1(u16.u16_bytes[0] == 0x11); - - /* Endian tests. */ - u64.u64 = cpu_to_le64(0x0011223344556677ULL); - ok1(u64.u64_bytes[0] == 0x77); - ok1(u64.u64_bytes[1] == 0x66); - ok1(u64.u64_bytes[2] == 0x55); - ok1(u64.u64_bytes[3] == 0x44); - ok1(u64.u64_bytes[4] == 0x33); - ok1(u64.u64_bytes[5] == 0x22); - ok1(u64.u64_bytes[6] == 0x11); - ok1(u64.u64_bytes[7] == 0x00); - ok1(le64_to_cpu(u64.u64) == 0x0011223344556677ULL); - - u64.u64 = cpu_to_be64(0x0011223344556677ULL); - ok1(u64.u64_bytes[7] == 0x77); - ok1(u64.u64_bytes[6] == 0x66); - ok1(u64.u64_bytes[5] == 0x55); - ok1(u64.u64_bytes[4] == 0x44); - ok1(u64.u64_bytes[3] == 0x33); - ok1(u64.u64_bytes[2] == 0x22); - ok1(u64.u64_bytes[1] == 0x11); - ok1(u64.u64_bytes[0] == 0x00); - ok1(be64_to_cpu(u64.u64) == 0x0011223344556677ULL); - - u32.u32 = cpu_to_le32(0x00112233); - ok1(u32.u32_bytes[0] == 0x33); - ok1(u32.u32_bytes[1] == 0x22); - ok1(u32.u32_bytes[2] == 0x11); - ok1(u32.u32_bytes[3] == 0x00); - ok1(le32_to_cpu(u32.u32) == 0x00112233); - - u32.u32 = cpu_to_be32(0x00112233); - ok1(u32.u32_bytes[3] == 0x33); - ok1(u32.u32_bytes[2] == 0x22); - ok1(u32.u32_bytes[1] == 0x11); - ok1(u32.u32_bytes[0] == 0x00); - ok1(be32_to_cpu(u32.u32) == 0x00112233); - - u16.u16 = cpu_to_le16(0x0011); - ok1(u16.u16_bytes[0] == 0x11); - ok1(u16.u16_bytes[1] == 0x00); - ok1(le16_to_cpu(u16.u16) == 0x0011); - - u16.u16 = cpu_to_be16(0x0011); - ok1(u16.u16_bytes[1] == 0x11); - ok1(u16.u16_bytes[0] == 0x00); - ok1(be16_to_cpu(u16.u16) == 0x0011); - - exit(exit_status()); -} -- cgit v1.2.1