MIPS: XBurst: fix the JZ4755's clocksource
Subsystems (3)
v2 cover MIPS: XBurst: fix the JZ4755's clocksource
This patch series fixes error in JZ4755's clocksource code.
First, it fixes common {BIG,LITTLE}_ENDIAN defines to make work MIPS little-endian clocksource code.
Next, the patch series fixes the JZ4755's clocksource code itself.
[PATCH v2 1/5] byteorder: fix {BIG,LITTLE}_ENDIAN defines [PATCH v2 2/5] byteorder: add sanity check
[PATCH v2 3/5] clocksource: move the NSEC_PER_SEC constant to common [PATCH v2 4/5] MIPS: XBurst: fix the JZ4755's clocksource input [PATCH v2 5/5] MIPS: XBurst: use clocks_calc_mult_shift() for
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 1/5 byteorder: fix {BIG,LITTLE}_ENDIAN defines
In the Linux kernel sources the only one byteorder macro can be defined (__BIG_ENDIAN or __LITTLE_ENDIAN) at a time.
In barebox we have the __BIG_ENDIAN and __LITTLE_ENDIAN macros defined simultaneously introduced in
commit 9ad1fe64abb12baac918ec177d9a52bbf2980d16
Author: Baruch Siach <[email protected]>
Date: Sun Jun 27 08:46:05 2010 +0300
byteorder: add missing {BIG,LITTLE}_ENDIAN defines
This fixes build warnings when testing __BYTE_ORDER of the other kin
But in arch/mips/lib/libgcc.h (from Linux) we have
#ifdef __BIG_ENDIAN
struct DWstruct {
int high, low;
};
#elif defined(__LITTLE_ENDIAN)
struct DWstruct {
int low, high; };
#else
#error I feel sick.
#endif
This means that regardless of current byteorder the big-endian DWstruct will be selected. By turn this breaks the __lshrdi3() function and the clocksource code on little-endian MIPS.
--- drivers/ata/disk_ata_drive.c | 2 +- drivers/nor/cfi_flash.c | 6 +++--- include/cramfs/cramfs_fs.h | 4 ++-- include/envfs.h | 16 ++++++++++++---- include/linux/byteorder/generic.h | 7 ------- include/usb/usb.h | 2 +- 6 files changed, 19 insertions(+), 18 deletions(-)
drivers/ata/disk_ata_drive.c +1 -1
@@ -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_ENDIANunsigned u;for (u =0 ; u < wds; u++)
drivers/nor/cfi_flash.c +3 -3
@@ -82,7 +82,7 @@ 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
@@ -167,7 +167,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 +#ifdef __LITTLE_ENDIANreturn flash_read8 (cp);#else return flash_read8 (cp + info->portwidth -1 );
@@ -195,7 +195,7 @@ static ulong flash_read_long (struct flash_info *info, flash_sect_t sect, uint odebug ("addr[%x] = 0x%x\n" , x,flash_read8 (addr + x)); }#endif -#if __BYTE_ORDER == __LITTLE_ENDIAN +#ifdef __LITTLE_ENDIAN retval = ((flash_read8(addr) << 16) | (flash_read8(addr + info->portwidth) << 24) | (flash_read8(addr + 2 * info->portwidth)) |
include/cramfs/cramfs_fs.h +2 -2
@@ -88,7 +88,7 @@ struct cramfs_super {#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 +96,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)
include/envfs.h +12 -4
@@ -38,6 +38,11 @@ struct envfs_super {#error "No byte order defined in __BYTE_ORDER"#endif +#if __BYTE_ORDER != __LITTLE_ENDIAN && __BYTE_ORDER != __BIG_ENDIAN +#error "__BYTE_ORDER must be __LITTLE_ENDIAN or __BIG_ENDIAN" +#endif + +#ifdef __LITTLE_ENDIAN#if __BYTE_ORDER == __LITTLE_ENDIAN#define ENVFS_16 (x) (x)#define ENVFS_24 (x) (x)
@@ -46,7 +51,11 @@ 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 +#endif /* __BYTE_ORDER == __LITTLE_ENDIAN */ +#endif /* __LITTLE_ENDIAN */ + +#ifdef __BIG_ENDIAN +#if __BYTE_ORDER == __BIG_ENDIAN#ifdef __KERNEL__#define ENVFS_16 (x) swab16(x)#define ENVFS_24 (x) ((swab32(x)) >> 8)
@@ -60,9 +69,8 @@ struct envfs_super {#define ENVFS_GET_OFFSET (x) ENVFS_32(((x)->offset))#define ENVFS_SET_NAMELEN (x,y)((x)->offset = ENVFS_32((y)))#define ENVFS_SET_OFFSET (x,y) ((x)->namelen = ENVFS_32((y))) -#else -#error "__BYTE_ORDER must be __LITTLE_ENDIAN or __BIG_ENDIAN" -#endif +#endif /* __BYTE_ORDER == __BIG_ENDIAN */ +#endif /* __BIG_ENDIAN */ #endif /* _ENVFS_H */
include/linux/byteorder/generic.h +0 -7
@@ -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;
include/usb/usb.h +1 -1
@@ -271,7 +271,7 @@ 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
Signature · 7 lines
1.7.10 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 3/5 clocksource: move the NSEC_PER_SEC constant to common header
In reply to Antony Pavlov--- arch/ppc/mach-mpc85xx/include/mach/clocks.h | 2 -- include/clock.h | 2 ++ include/linux/time.h | 1 + 3 files changed, 3 insertions(+), 2 deletions(-)
arch/ppc/mach-mpc85xx/include/mach/clocks.h +0 -2
@@ -10,8 +10,6 @@ struct sys_info {unsigned long freqLocalBus; }; -#define NSEC_PER_SEC 1000000000L -unsigned long fsl_get_bus_freq (ulong dummy);unsigned long fsl_get_timebase_clock (void );void fsl_get_sys_info (struct sys_info *sysInfo);
include/clock.h +2 -0
@@ -3,6 +3,8 @@#ifndef CLOCK_H #define CLOCK_H +#include <linux/time.h> +#define CLOCKSOURCE_MASK (bits) (uint64_t)((bits) < 64 ? ((1ULL<<(bits))-1) : -1) struct clocksource {
include/linux/time.h +1 -0
@@ -9,6 +9,7 @@#define _REENT_ONLY +#define NSEC_PER_SEC 1000000000L#define SECSPERMIN 60L#define MINSPERHOUR 60L#define HOURSPERDAY 24L
Signature · 7 lines
1.7.10 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 4/5 MIPS: XBurst: fix the JZ4755's clocksource input frequency value
In reply to Antony PavlovThe 40 KHz frequency value was used to parry __lshrdi3() error on little-endian MIPS because the __lshrdi3() function is used in clocksource code.
The true value of the JZ4755's external clock frequency is 24 MHz.
--- arch/mips/mach-xburst/csrc-jz4750.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/mach-xburst/csrc-jz4750.c +1 -1
@@ -28,7 +28,7 @@#include <io.h> #include <mach/jz4750d_regs.h> -#define JZ_TIMER_CLOCK 40000 +#define JZ_TIMER_CLOCK 24000000static uint64_t jz4750_cs_read (void ) {
Signature · 7 lines
1.7.10 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 2/5 byteorder: add sanity check
In reply to Antony PavlovThe 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/common.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
include/common.h +18 -0
@@ -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_ */
Signature · 7 lines
1.7.10 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 5/5 MIPS: XBurst: use clocks_calc_mult_shift() for JZ4755's clocksource
In reply to Antony Pavlov--- arch/mips/mach-xburst/csrc-jz4750.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
arch/mips/mach-xburst/csrc-jz4750.c +3 -2
@@ -38,12 +38,13 @@ static uint64_t jz4750_cs_read(void)static struct clocksource jz4750_cs = { .read = jz4750_cs_read, .mask =CLOCKSOURCE_MASK (32 ), - .shift =10 , };static int clocksource_init (void ) { - jz4750_cs.mult =clocksource_hz2mult (JZ_TIMER_CLOCK , jz4750_cs.shift); +clocks_calc_mult_shift (&jz4750_cs.mult, &jz4750_cs.shift, +JZ_TIMER_CLOCK ,NSEC_PER_SEC ,10 ); +init_clock (&jz4750_cs); __raw_writel(TCU_OSTCSR_PRESCALE1 | TCU_OSTCSR_EXT_EN,
Signature · 7 lines
1.7.10 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH v2 1/5] byteorder: fix {BIG,LITTLE}_ENDIAN defines
In reply to Antony PavlovQuoted 114 lines · Antony Pavlov
In the Linux kernel sources the only one byteorder macro can be defined (
__BIG_ENDIANor__LITTLE_ENDIAN) at a time.In barebox we have the
__BIG_ENDIANand__LITTLE_ENDIANmacros defined simultaneously introduced incommit
9ad1fe64abb12baac918ec177d9a52bbf2980d16
Author: Baruch Siach <[email protected]>
Date: Sun Jun 27 08:46:05 2010 +0300byteorder: add missing {BIG,LITTLE}_ENDIAN defines
This fixes build warnings when testing
__BYTE_ORDERof the other kinBut in
arch/mips/lib/libgcc.h(from Linux) we have#ifdef
__BIG_ENDIANstruct DWstruct { int high, low; }; #elif defined(__LITTLE_ENDIAN) struct DWstruct { int low, high;};
#else
#error I feel sick.
#endifThis means that regardless of current byteorder the big-endian DWstruct will be selected. By turn this breaks the
__lshrdi3()function and the clocksource code on little-endian MIPS.Signed-off-by Antony Pavlov <[email protected]>--- drivers/ata/disk_ata_drive.c | 2 +- drivers/nor/cfi_flash.c | 6 +++--- include/cramfs/cramfs_fs.h | 4 ++-- include/envfs.h | 16 ++++++++++++---- include/linux/byteorder/generic.h | 7 ------- include/usb/usb.h | 2 +- 6 files changed, 19 insertions(+), 18 deletions(-)drivers/ata/disk_ata_drive.c +1
-1@@ -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_ENDIANunsigned u;for (u =0 ; u < wds; u++)drivers/nor/cfi_flash.c +3
-3@@ -82,7 +82,7 @@ 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 @@ -167,7 +167,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 +#ifdef __LITTLE_ENDIANreturn flash_read8 (cp);#else return flash_read8 (cp + info->portwidth -1 );@@ -195,7 +195,7 @@ static ulong flash_read_long (struct flash_info *info, flash_sect_t sect, uint odebug ("addr[%x] = 0x%x\n" , x,flash_read8 (addr + x)); }#endif -#if __BYTE_ORDER == __LITTLE_ENDIAN +#ifdef __LITTLE_ENDIAN retval = ((flash_read8(addr) << 16) | (flash_read8(addr + info->portwidth) << 24) | (flash_read8(addr + 2 * info->portwidth)) |include/cramfs/cramfs_fs.h +2
-2@@ -88,7 +88,7 @@ struct cramfs_super {#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 +96,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)include/envfs.h +0
-0
include/envfs.h struct envfs_super { · line 43
Quoted 6 lines
include/envfs.h +3
-0@@ -38,6 +38,11 @@ struct envfs_super {#error "No byte order defined in __BYTE_ORDER"#endif +#if __BYTE_ORDER != __LITTLE_ENDIAN && __BYTE_ORDER != __BIG_ENDIAN +#error "__BYTE_ORDER must be __LITTLE_ENDIAN or __BIG_ENDIAN" +#endif
On Big Endian systems __LITTLE_ENDIAN is undefined and this results in:
In file included from common/environment.c:37:include/envfs.h:41:21: warning: "__LITTLE_ENDIAN" is not defined
include/envfs.h struct envfs_super { · line 45
Quoted 2 lines
include/envfs.h +2
-0+ +#ifdef __LITTLE_ENDIAN
As said, this file is included from scripts/bareboxenv.c which is compiled for userspace. __LITTLE_ENDIAN will always be defined in userspace.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH v2 1/5] byteorder: fix {BIG,LITTLE}_ENDIAN defines
Quoted 9 lines · Sascha Hauer
include/envfs.h struct envfs_super { · line 43
Quoted 4 lines
include/envfs.h +3
-0+#if __BYTE_ORDER != __LITTLE_ENDIAN && __BYTE_ORDER != __BIG_ENDIAN +#error "__BYTE_ORDER must be __LITTLE_ENDIAN or __BIG_ENDIAN" +#endif On Big Endian systems
__LITTLE_ENDIANis undefined and this results in:In file included from
common/environment.c:37:include/envfs.h:41:21: warning: "__LITTLE_ENDIAN" is not defined
In the meantime I applied my original patch. Please let me know if there is something wrong with it, we can still change it.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH v2 3/5] clocksource: move the NSEC_PER_SEC constant to common header
In reply to Antony PavlovQuoted 25 lines · Antony Pavlov
Signed-off-by Antony Pavlov <[email protected]>--- arch/ppc/mach-mpc85xx/include/mach/clocks.h | 2 -- include/clock.h | 2 ++ include/linux/time.h | 1 + 3 files changed, 3 insertions(+), 2 deletions(-)arch/ppc/mach-mpc85xx/include/mach/clocks.h +0
-2@@ -10,8 +10,6 @@ struct sys_info {unsigned long freqLocalBus; }; -#define NSEC_PER_SEC 1000000000L -unsigned long fsl_get_bus_freq (ulong dummy);unsigned long fsl_get_timebase_clock (void );void fsl_get_sys_info (struct sys_info *sysInfo);include/clock.h +0
-0
include/clock.h line 6
Quoted 4 lines
include/clock.h +1
-0@@ -3,6 +3,8 @@#ifndef CLOCK_H #define CLOCK_H +#include <linux/time.h>
This breaks compilation on some ARM boards:
In file included from include/clock.h:6:0,
from drivers/i2c/i2c.c:19:
include/linux/time.h: In function 'asctime_r':include/linux/time.h:62:5: warning: implicit declaration of function 'sprintf' [-Wimplicit-function-declaration]
In file included from include/clock.h:6:0,
from drivers/i2c/busses/i2c-imx.c:36:
I'll fold the following into this patch:
8<-----------------------------------------------------
include/linux/time.h: remove dead code
include/linux/time.h contains several unused functions derived from U-Boot code. Since this is a file under include/linux/ it should contain only code from the kernel, so remove all this.
--- include/linux/time.h | 151 -------------------------------------------------- 1 file changed, 151 deletions(-)
include/linux/time.h +0 -151
@@ -3,157 +3,6 @@#include <linux/types.h> -#define _DEFUN (a,b,c) a(c) -#define _CONST const -#define _AND , - -#define _REENT_ONLY -#define NSEC_PER_SEC 1000000000L -#define SECSPERMIN 60L -#define MINSPERHOUR 60L -#define HOURSPERDAY 24L -#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR) -#define SECSPERDAY (SECSPERHOUR * HOURSPERDAY) -#define DAYSPERWEEK 7 -#define MONSPERYEAR 12 - -#define YEAR_BASE 1900 -#define EPOCH_YEAR 1970 -#define EPOCH_WDAY 4 - -#define isleap (y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0) - - -/* Used by other time functions. */ -struct tm { -int tm_sec;/* Seconds. [0-60] (1 leap second) */ -int tm_min;/* Minutes. [0-59] */ -int tm_hour;/* Hours. [0-23] */ -int tm_mday;/* Day. [1-31] */ -int tm_mon;/* Month. [0-11] */ -int tm_year;/* Year - 1900. */ -int tm_wday;/* Day of week. [0-6] */ -int tm_yday;/* Days in year.[0-365] */ -int tm_isdst;/* DST. [-1/0/1]*/ - -# ifdef __USE_BSD -long int tm_gmtoff;/* Seconds east of UTC. */ - __const char *tm_zone; /* Timezone abbreviation. */ -# else -long int __tm_gmtoff;/* Seconds east of UTC. */ - __const char *__tm_zone; /* Timezone abbreviation. */ -# endif -}; - -static inline char * -_DEFUN (asctime_r, (tim_p, result), - _CONST struct tm *tim_p _AND - char *result) -{ - static _CONST char day_name[7][3] = { -"Sun" ,"Mon" ,"Tue" ,"Wed" ,"Thu" ,"Fri" ,"Sat" - }; - static _CONST char mon_name[12][3] = { -"Jan" ,"Feb" ,"Mar" ,"Apr" ,"May" ,"Jun" , -"Jul" ,"Aug" ,"Sep" ,"Oct" ,"Nov" ,"Dec" - }; - -sprintf (result,"%.3s %.3s %.2d %.2d:%.2d:%.2d %d\n" , - day_name[tim_p->tm_wday], - mon_name[tim_p->tm_mon], - tim_p->tm_mday, tim_p->tm_hour, tim_p->tm_min, - tim_p->tm_sec,1900 + tim_p->tm_year); -return result; -} - -static inline struct tm * -_DEFUN (localtime_r, (tim_p, res), - _CONST time_t * tim_p _AND - struct tm *res) -{ - static _CONST int mon_lengths[2][MONSPERYEAR] = { - {31 ,28 ,31 ,30 ,31 ,30 ,31 ,31 ,30 ,31 ,30 ,31 }, - {31 ,29 ,31 ,30 ,31 ,30 ,31 ,31 ,30 ,31 ,30 ,31 } - } ; - - static _CONST int year_lengths[2] = { -365 , -366 - } ; - -long days, rem; -int y; -int yleap; - _CONST int *ip; - - days = ((long ) *tim_p) /SECSPERDAY ; - rem = ((long ) *tim_p) %SECSPERDAY ; -while (rem <0 ) - { - rem +=SECSPERDAY ; - --days; - } -while (rem >=SECSPERDAY ) - { - rem -=SECSPERDAY ; - ++days; - } - -/* compute hour, min, and sec */ - res->tm_hour = (int ) (rem /SECSPERHOUR ); - rem %=SECSPERHOUR ; - res->tm_min = (int ) (rem /SECSPERMIN ); - res->tm_sec = (int ) (rem %SECSPERMIN ); - -/* compute day of week */ -if ((res->tm_wday = ((EPOCH_WDAY + days) %DAYSPERWEEK )) <0 ) - res->tm_wday +=DAYSPERWEEK ; - -/* compute year & day of year */ - y =EPOCH_YEAR ; -if (days >=0 ) - { -for (;;) - { - yleap =isleap (y); -if (days < year_lengths[yleap]) -break ; - y++; - days -= year_lengths[yleap]; - } - } -else - { -do - { - --y; - yleap =isleap (y); - days += year_lengths[yleap]; - }while (days <0 ); - } - - res->tm_year = y -YEAR_BASE ; - res->tm_yday = days; - ip = mon_lengths[yleap]; -for (res->tm_mon =0 ; days >= ip[res->tm_mon]; ++res->tm_mon) - days -= ip[res->tm_mon]; - res->tm_mday = days +1 ; - -/* set daylight saving time flag */ - res->tm_isdst =-1 ; - -return (res); -} - -static inline char * -_DEFUN (ctime_r, (tim_p, result), - _CONST time_t * tim_p _AND - char * result) - -{ -struct tm tm; -return asctime_r (localtime_r (tim_p, &tm), result); -}#endif
Signature · 12 lines
1.7.10 -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH v2 1/5] byteorder: fix {BIG,LITTLE}_ENDIAN defines
In reply to Sascha HauerQuoted 118 lines · Sascha Hauer
Quoted 117 lines · Antony Pavlov
In the Linux kernel sources the only one byteorder macro can be defined (
__BIG_ENDIANor__LITTLE_ENDIAN) at a time.In barebox we have the
__BIG_ENDIANand__LITTLE_ENDIANmacros defined simultaneously introduced incommit
9ad1fe64abb12baac918ec177d9a52bbf2980d16
Author: Baruch Siach <[email protected]>
Date: Sun Jun 27 08:46:05 2010 +0300byteorder: add missing {BIG,LITTLE}_ENDIAN defines
This fixes build warnings when testing
__BYTE_ORDERof the other kinBut in
arch/mips/lib/libgcc.h(from Linux) we have#ifdef
__BIG_ENDIAN
struct DWstruct {
int high, low;
};
#elifdefined(__LITTLE_ENDIAN)
struct DWstruct {
int low, high;
};
#else
#error I feel sick.
#endifThis means that regardless of current byteorder the big-endian DWstruct will be selected. By turn this breaks the
__lshrdi3()function and the clocksource code on little-endian MIPS.Signed-off-by Antony Pavlov <[email protected]>---
drivers/ata/disk_ata_drive.c | 2 +-drivers/nor/cfi_flash.c| 6 +++---include/cramfs/cramfs_fs.h| 4 ++--include/envfs.h| 16 ++++++++++++----include/linux/byteorder/generic.h| 7 -------include/usb/usb.h| 2 +-6 files changed, 19 insertions(+), 18 deletions(-)drivers/ata/disk_ata_drive.c +1
-1@@ -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++)drivers/nor/cfi_flash.c +3
-3@@ -82,7 +82,7 @@ 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@@ -167,7 +167,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 +#ifdef __LITTLE_ENDIAN return flash_read8(cp); #else return flash_read8(cp + info->portwidth - 1);@@ -195,7 +195,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 +#ifdef __LITTLE_ENDIANretval = ((
flash_read8(addr)<< 16) | (flash_read8(addr + info->portwidth)<< 24) | (flash_read8(addr + 2 * info->portwidth)) |include/cramfs/cramfs_fs.h +2
-2@@ -88,7 +88,7 @@ struct cramfs_super { #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 +96,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)include/envfs.h +0
-0@@ -38,6 +38,11 @@ struct envfs_super { #error "No byte order defined in __BYTE_ORDER" #endif
Quoted 8 lines
include/envfs.h struct envfs_super { · line 43
Quoted 3 lines
include/envfs.h +3
-0+#if __BYTE_ORDER != __LITTLE_ENDIAN && __BYTE_ORDER != __BIG_ENDIAN +#error "__BYTE_ORDER must be __LITTLE_ENDIAN or __BIG_ENDIAN" +#endif On Big Endian systems
__LITTLE_ENDIANis undefined and this results in:In file included from
common/environment.c:37:include/envfs.h:41:21: warning: "__LITTLE_ENDIAN" is not defined
You are right.
Quoted 6 lines
include/envfs.h struct envfs_super { · line 45
Quoted 2 lines
include/envfs.h +2
-0+ +#ifdef __LITTLE_ENDIANAs said, this file is included from
scripts/bareboxenv.cwhich is compiled for userspace.__LITTLE_ENDIANwill always be defined in userspace.
But it included from common/environment.c too!
Moreover, in my company there is Processor Core Testing Department. These folks like to rebuild full MIPS Linux distribution on our big-endian MIPS system natively just for testing purposes. So, I have a chance to build MIPS barebox on big-endian system :))
Quoted 6 lines
--
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Signature · 7 lines
Best regards, Antony Pavlov _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH v2 1/5] byteorder: fix {BIG,LITTLE}_ENDIAN defines
Quoted 7 lines · Antony Pavlov
Quoted 3 lines · Sascha Hauer
In file included from
common/environment.c:37:include/envfs.h:41:21: warning: "__LITTLE_ENDIAN" is not definedYou are right.
Quoted 8 lines
Quoted 6 lines
include/envfs.h struct envfs_super { · line 45
Quoted 2 lines
include/envfs.h +2
-0+ +#ifdef __LITTLE_ENDIANAs said, this file is included from
scripts/bareboxenv.cwhich is compiled for userspace.__LITTLE_ENDIANwill always be defined in userspace.But it included from
common/environment.ctoo!
That's why I have the following:
#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
This should work as expected. Maybe the name ENVFS_ORDER_LITTLE and ENVFS_ORDER_BIG are a bit confusing, should probably better ENVFS_ORDER_NATIVE and ENVFS_ORDER_SWAP.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox