diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2012-06-28 09:56:23 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2012-06-28 13:49:16 +0200 |
commit | 51885a7d7321c3e6395c36bc4fe8dde7e78cf562 (patch) | |
tree | c656f1c1e2571181aed4870aaa2e63861120d783 /drivers/nor | |
parent | a6e358b2f5b219fda18a7bc9348cb969043c19d5 (diff) | |
download | barebox-51885a7d7321c3e6395c36bc4fe8dde7e78cf562.tar.gz barebox-51885a7d7321c3e6395c36bc4fe8dde7e78cf562.tar.xz |
Change byte order detection mechanism to kernel style
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 switch to use the kernel
way of determing the byte order.
As this always causes a lot of confusion add a check to include/common.h to
make sure only one of __LITTLE_ENDIAN and __BIG_ENDIAN is defined.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/nor')
-rw-r--r-- | drivers/nor/cfi_flash.c | 10 |
1 files changed, 6 insertions, 4 deletions
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)) | |