[PATCH v2 2/5] byteorder: add sanity check

Antony Pavlov antonynpavlov at gmail.com
Thu Jun 28 14:32:31 EDT 2012


The Linux Kernel defines only one of __LITTLE_ENDIAN and
__BIG_ENDIAN. Endianess can then be tested with #ifdef __xx_ENDIAN.

Userspace always defined both __LITTLE_ENDIAN and __BIG_ENDIAN
and byteorder can then be tested with #if __BYTE_ORDER == __xx_ENDIAN.

As we tend to use a lot of Kernel code in barebox we use
the kernel way of determing the byte order. Make sure here
 that architecture code properly defines it.

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 include/common.h |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/include/common.h b/include/common.h
index 9745aeb..ece3d13 100644
--- a/include/common.h
+++ b/include/common.h
@@ -241,4 +241,22 @@ static inline void barebox_banner(void) {}
 		(__x < 0) ? -__x : __x;         \
 	})
 
+/*
+ * sanity check. The Linux Kernel defines only one of __LITTLE_ENDIAN and
+ * __BIG_ENDIAN. Endianess can then be tested with #ifdef __xx_ENDIAN.
+ * Userspace always defined both __LITTLE_ENDIAN and __BIG_ENDIAN and
+ * byteorder can then be tested with #if __BYTE_ORDER == __xx_ENDIAN.
+ *
+ * As we tend to use a lot of Kernel code in barebox we use the kernel way of
+ * determing the byte order. Make sure here that architecture code properly
+ * defines it.
+ */
+#include <asm/byteorder.h>
+#if defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
+#error "both __LITTLE_ENDIAN and __BIG_ENDIAN are defined"
+#endif
+#if !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN)
+#error "None of __LITTLE_ENDIAN and __BIG_ENDIAN are defined"
+#endif
+
 #endif	/* __COMMON_H_ */
-- 
1.7.10




More information about the barebox mailing list