summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/ata/disk_ata_drive.c2
-rw-r--r--drivers/nor/cfi_flash.c10
-rw-r--r--include/common.h18
-rw-r--r--include/cramfs/cramfs_fs.h8
-rw-r--r--include/envfs.h22
-rw-r--r--include/linux/byteorder/generic.h7
-rw-r--r--include/usb/usb.h6
7 files changed, 49 insertions, 24 deletions
diff --git a/drivers/ata/disk_ata_drive.c b/drivers/ata/disk_ata_drive.c
index 4602af3c0d..d5c583790c 100644
--- a/drivers/ata/disk_ata_drive.c
+++ b/drivers/ata/disk_ata_drive.c
@@ -231,7 +231,7 @@ static void __maybe_unused ata_dump_id(uint16_t *id)
*/
static void ata_fix_endianess(uint16_t *buf, unsigned wds)
{
-#if __BYTE_ORDER == __BIG_ENDIAN
+#ifdef __BIG_ENDIAN
unsigned u;
for (u = 0; u < wds; u++)
diff --git a/drivers/nor/cfi_flash.c b/drivers/nor/cfi_flash.c
index 654e6470c1..82c1caed58 100644
--- a/drivers/nor/cfi_flash.c
+++ b/drivers/nor/cfi_flash.c
@@ -82,9 +82,9 @@ static void flash_add_byte (struct flash_info *info, cfiword_t * cword, uchar c)
return;
}
-#if __BYTE_ORDER == __BIG_ENDIAN
+#ifdef __BIG_ENDIAN
*cword = (*cword << 8) | c;
-#else
+#elif defined __LITTLE_ENDIAN
if (bankwidth_is_2(info))
*cword = (*cword >> 8) | (u16)c << 8;
@@ -92,6 +92,8 @@ static void flash_add_byte (struct flash_info *info, cfiword_t * cword, uchar c)
*cword = (*cword >> 8) | (u32)c << 24;
else if (bankwidth_is_8(info))
*cword = (*cword >> 8) | (u64)c << 56;
+#else
+#error "could not determine byte order"
#endif
}
@@ -167,7 +169,7 @@ static void flash_printqry (struct cfi_qry *qry)
uchar flash_read_uchar (struct flash_info *info, uint offset)
{
uchar *cp = flash_make_addr(info, 0, offset);
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if defined __LITTLE_ENDIAN
return flash_read8(cp);
#else
return flash_read8(cp + info->portwidth - 1);
@@ -195,7 +197,7 @@ static ulong flash_read_long (struct flash_info *info, flash_sect_t sect, uint o
debug ("addr[%x] = 0x%x\n", x, flash_read8(addr + x));
}
#endif
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if defined __LITTLE_ENDIAN
retval = ((flash_read8(addr) << 16) |
(flash_read8(addr + info->portwidth) << 24) |
(flash_read8(addr + 2 * info->portwidth)) |
diff --git a/include/common.h b/include/common.h
index d2347f8629..9287a7dd2b 100644
--- a/include/common.h
+++ b/include/common.h
@@ -34,6 +34,24 @@
#include <linux/stddef.h>
#include <asm/common.h>
+/*
+ * 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
+
#define pr_info(fmt, arg...) printf(fmt, ##arg)
#define pr_notice(fmt, arg...) printf(fmt, ##arg)
#define pr_err(fmt, arg...) printf(fmt, ##arg)
diff --git a/include/cramfs/cramfs_fs.h b/include/cramfs/cramfs_fs.h
index af2940be05..8c53fc737d 100644
--- a/include/cramfs/cramfs_fs.h
+++ b/include/cramfs/cramfs_fs.h
@@ -84,11 +84,7 @@ struct cramfs_super {
| CRAMFS_FLAG_WRONG_SIGNATURE \
| CRAMFS_FLAG_SHIFTED_ROOT_OFFSET )
-#ifndef __BYTE_ORDER
-#error "No byte order defined in __BYTE_ORDER"
-#endif
-
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#ifdef __LITTLE_ENDIAN
#define CRAMFS_16(x) (x)
#define CRAMFS_24(x) (x)
#define CRAMFS_32(x) (x)
@@ -96,7 +92,7 @@ struct cramfs_super {
#define CRAMFS_GET_OFFSET(x) ((x)->offset)
#define CRAMFS_SET_OFFSET(x,y) ((x)->offset = (y))
#define CRAMFS_SET_NAMELEN(x,y) ((x)->namelen = (y))
-#elif __BYTE_ORDER ==__BIG_ENDIAN
+#elif defined __BIG_ENDIAN
#ifdef __KERNEL__
#define CRAMFS_16(x) swab16(x)
#define CRAMFS_24(x) ((swab32(x)) >> 8)
diff --git a/include/envfs.h b/include/envfs.h
index 67b890222c..ba976d6d13 100644
--- a/include/envfs.h
+++ b/include/envfs.h
@@ -34,11 +34,25 @@ struct envfs_super {
uint32_t sb_crc; /* crc for the superblock */
};
-#ifndef __BYTE_ORDER
-#error "No byte order defined in __BYTE_ORDER"
+#ifdef __BAREBOX__
+# ifdef __LITTLE_ENDIAN
+# define ENVFS_ORDER_LITTLE
+# elif defined __BIG_ENDIAN
+# define ENVFS_ORDER_BIG
+# else
+# error "could not determine byte order"
+# endif
+#else
+# if __BYTE_ORDER == __LITTLE_ENDIAN
+# define ENVFS_ORDER_LITTLE
+# elif __BYTE_ORDER == __BIG_ENDIAN
+# define ENVFS_ORDER_BIG
+# else
+# error "could not determine byte order"
+# endif
#endif
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#ifdef ENVFS_ORDER_LITTLE
#define ENVFS_16(x) (x)
#define ENVFS_24(x) (x)
#define ENVFS_32(x) (x)
@@ -46,7 +60,7 @@ struct envfs_super {
#define ENVFS_GET_OFFSET(x) ((x)->offset)
#define ENVFS_SET_OFFSET(x,y) ((x)->offset = (y))
#define ENVFS_SET_NAMELEN(x,y) ((x)->namelen = (y))
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif defined ENVFS_ORDER_BIG
#ifdef __KERNEL__
#define ENVFS_16(x) swab16(x)
#define ENVFS_24(x) ((swab32(x)) >> 8)
diff --git a/include/linux/byteorder/generic.h b/include/linux/byteorder/generic.h
index aab8f4b6bf..2d68d99fa4 100644
--- a/include/linux/byteorder/generic.h
+++ b/include/linux/byteorder/generic.h
@@ -78,13 +78,6 @@
*
*/
-#ifndef __LITTLE_ENDIAN
-#define __LITTLE_ENDIAN 1234
-#endif
-#ifndef __BIG_ENDIAN
-#define __BIG_ENDIAN 4321
-#endif
-
#if defined(__KERNEL__)
/*
* inside the kernel, we can use nicknames;
diff --git a/include/usb/usb.h b/include/usb/usb.h
index 296e4e8ea8..8691400014 100644
--- a/include/usb/usb.h
+++ b/include/usb/usb.h
@@ -270,12 +270,14 @@ void usb_rescan(void);
((x_ & 0xFF000000UL) >> 24)); \
})
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#ifdef __LITTLE_ENDIAN
# define swap_16(x) (x)
# define swap_32(x) (x)
-#else
+#elif defined BIG_ENDIAN
# define swap_16(x) __swap_16(x)
# define swap_32(x) __swap_32(x)
+#else
+#error "could not determine byte order"
#endif
/*