Consolidate strmhz() implementation
PATCH 1/1 Consolidate strmhz() implementation
ARM, i386, m68k and ppc all have identical implementations of strmhz(). Other architectures don't provide this function at all.
This patch moves strmhz() into lib_generic, reducing code duplication and providing a more unified API across architectures.
--- include/common.h | 4 +++- lib_arm/board.c | 13 ------------- lib_generic/Makefile | 1 + lib_generic/strmhz.c | 36 ++++++++++++++++++++++++++++++++++++ lib_i386/board.c | 13 ------------- lib_m68k/board.c | 17 ----------------- lib_ppc/board.c | 13 ------------- 7 files changed, 40 insertions(+), 57 deletions(-) create mode 100644 lib_generic/strmhz.c
include/common.h +3 -1
@@ -222,7 +222,6 @@ void board_init_r (gd_t *, ulong) __attribute__ ((noreturn));int checkboard (void );int checkflash (void );int checkdram (void ); -char *strmhz (char *buf,long hz);int last_stage_init (void );extern ulong monitor_flash_len;int mac_read_from_eeprom (void );
@@ -613,6 +612,9 @@ int sprintf(char * buf, const char *fmt, ...) __attribute__ ((format (__printf__, 2, 3)));int vsprintf (char *buf,const char *fmt,va_list args); +/* lib_generic/strmhz.c */ +char *strmhz (char *buf,long hz); +/* lib_generic/crc32.c */ uint32_t crc32 (uint32_t ,const unsigned char *,uint );uint32_t crc32_wd (uint32_t ,const unsigned char *,uint ,uint );
lib_arm/board.c +0 -13
@@ -115,19 +115,6 @@ void *sbrk (ptrdiff_t increment)return ((void *) old); } -char *strmhz (char *buf,long hz) -{ -long l, n; -long m; - - n = hz /1000000L ; - l =sprintf (buf,"%ld" , n); - m = (hz %1000000L ) /1000L ; -if (m !=0 ) -sprintf (buf + l,".%03ld" , m); -return (buf); -} -/************************************************************************ * Coloured LED functionality
lib_generic/Makefile +1 -0
@@ -40,6 +40,7 @@ COBJS-$(CONFIG_MD5) += md5.o COBJS-y += sha1.o COBJS-$(CONFIG_SHA256) += sha256.o COBJS-y += string.o +COBJS-y += strmhz.o COBJS-y += vsprintf.o COBJS-y += zlib.o
lib_generic/strmhz.c new file +36 -0
@@ -0,0 +1,36 @@ +/* +* (C) Copyright 2002-2006 +* Wolfgang Denk, DENX Software Engineering, wd at denx.de. +* +* See file CREDITS for list of people who contributed to this +* project. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +*/ +#include <common.h> + +char *strmhz (char *buf,long hz) +{ +long l, n; +long m; + + n = hz /1000000L ; + l =sprintf (buf,"%ld" , n); + m = (hz %1000000L ) /1000L ; +if (m !=0 ) +sprintf (buf + l,".%03ld" , m); +return (buf); +}
lib_i386/board.c +0 -13
@@ -108,19 +108,6 @@ void *sbrk (ptrdiff_t increment)return ((void *) old); } -char *strmhz (char *buf,long hz) -{ -long l, n; -long m; - - n = hz /1000000L ; - l =sprintf (buf,"%ld" , n); - m = (hz %1000000L ) /1000L ; -if (m !=0 ) -sprintf (buf + l,".%03ld" , m); -return (buf); -} -/************************************************************************ * Init Utilities * ************************************************************************
lib_m68k/board.c +0 -17
@@ -136,23 +136,6 @@ void *sbrk (ptrdiff_t increment)return ((void *)old); } -char *strmhz (char *buf,long hz) -{ -long l, n; -long m; - - n = hz /1000000L ; - - l =sprintf (buf,"%ld" , n); - - m = (hz %1000000L ) /1000L ; - -if (m !=0 ) -sprintf (buf+l,".%03ld" , m); - -return (buf); -} -/* * All attempts to come up with a "common" initialization sequence * that works for all boards and architectures failed: some of the
lib_ppc/board.c +0 -13
@@ -168,19 +168,6 @@ void *sbrk (ptrdiff_t increment)return ((void *) old); } -char *strmhz (char *buf,long hz) -{ -long l, n; -long m; - - n = hz /1000000L ; - l =sprintf (buf,"%ld" , n); - m = (hz %1000000L ) /1000L ; -if (m !=0 ) -sprintf (buf + l,".%03ld" , m); -return (buf); -} -/* * All attempts to come up with a "common" initialization sequence * that works for all boards and architectures failed: some of the
Signature · 1 line
1.5.6.3
PATCH 1/1 Consolidate strmhz() implementation
Quoted 7 lines · Haavard Skinnemoen
ARM, i386, m68k and ppc all have identical implementations of
strmhz(). Other architectures don't provide this function at all.This patch moves
strmhz()intolib_generic, reducing code duplication and providing a more unified API across architectures.Signed-off-by Haavard Skinnemoen <[email protected]>
Quoted 11 lines
--- include/common.h | 4 +++- lib_arm/board.c | 13 ------------- lib_generic/Makefile | 1 + lib_generic/strmhz.c | 36 ++++++++++++++++++++++++++++++++++++ lib_i386/board.c | 13 ------------- lib_m68k/board.c | 17 ----------------- lib_ppc/board.c | 13 ------------- 7 files changed, 40 insertions(+), 57 deletions(-) create mode 100644 lib_generic/strmhz.c
When I read the patch, I really like it. But when I take a look on all board.c
I've seen 2 others functions which are commom.
Could we use the patch that reply to this message instead?
Best Regards,
J.
PATCH 1/1 Consolidate strmhz() implementation
Dear Jean-Christophe PLAGNIOL-VILLARD,
Quoted 6 lines · In message <[email protected]> you wrote:
When I read the patch, I really like it. But when I take a look on all
board.cI've seen 2 others functions which are commom.
Could we use the patch that reply to this message instead?
Sorry, which specific patch are you talking about? Do you have a message ID or URL or somthing we can look up?
Best regards,
Wolfgang Denk
Signature · 8 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de "What happened to the crewman?" "The M-5 computer needed a new power source, the crewman merely got in the way." -- Kirk and Dr. Richard Daystrom, "The Ultimate Computer", stardate 4731.3.
PATCH 1/1 Consolidate strmhz() and init_baudrate() implementation
In reply to Jean-Christophe PLAGNIOL-VILLARDFrom: Haavard Skinnemoen <[email protected]>
ARM, i386, m68k and ppc all have identical implementations of strmhz(). Other architectures don't provide this function at all.
ARM, avr32, blackfin, i386, m68k, mips and sparc all have identical implementations of init_baudrate().
Other architectures don't provide this function at all.
This patch moves strmhz() and init_baudrate() into lib_generic, reducing code duplication and providing a more unified API across architectures.
--- include/common.h | 5 +++- lib_arm/board.c | 25 ----------------------- lib_avr32/board.c | 15 ------------- lib_blackfin/board.c | 10 --------- lib_generic/Makefile | 1 + lib_generic/board.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib_i386/board.c | 25 ----------------------- lib_m68k/board.c | 30 --------------------------- lib_mips/board.c | 13 ------------ lib_ppc/board.c | 14 ------------- lib_sparc/board.c | 13 ------------ 11 files changed, 59 insertions(+), 146 deletions(-) create mode 100644 lib_generic/board.c
include/common.h +4 -1
@@ -224,7 +224,6 @@ void board_init_r (gd_t *, ulong) __attribute__ ((noreturn));int checkboard (void );int checkflash (void );int checkdram (void ); -char *strmhz (char *buf,long hz);int last_stage_init (void );extern ulong monitor_flash_len;int mac_read_from_eeprom (void );
@@ -615,6 +614,10 @@ int sprintf(char * buf, const char *fmt, ...) __attribute__ ((format (__printf__, 2, 3)));int vsprintf (char *buf,const char *fmt,va_list args); +/* lib_generic/strmhz.c */ +char *strmhz (char *buf,long hz); +int init_baudrate (void ); +/* lib_generic/crc32.c */ uint32_t crc32 (uint32_t ,const unsigned char *,uint );uint32_t crc32_wd (uint32_t ,const unsigned char *,uint ,uint );
lib_arm/board.c +0 -25
@@ -115,20 +115,6 @@ void *sbrk (ptrdiff_t increment)return ((void *) old); } -char *strmhz (char *buf,long hz) -{ -long l, n; -long m; - - n = hz /1000000L ; - l =sprintf (buf,"%ld" , n); - m = (hz %1000000L ) /1000L ; -if (m !=0 ) -sprintf (buf + l,".%03ld" , m); -return (buf); -} - -/************************************************************************ * Coloured LED functionality ************************************************************************
@@ -157,17 +143,6 @@ void inline yellow_LED_off(void)__attribute__((weak, alias("__yellow_LED_off")))* but let's get it working (again) first... */ -static int init_baudrate (void ) -{ -char tmp[64 ];/* long enough for environment variables */ -int i =getenv_r ("baudrate" , tmp,sizeof (tmp)); - gd->bd->bi_baudrate = gd->baudrate = (i >0 ) - ? (int )simple_strtoul (tmp,NULL ,10 ) - :CONFIG_BAUDRATE ; - -return (0 ); -} -static int display_banner (void ) {printf ("\n\n%s\n\n" , version_string);
lib_avr32/board.c +0 -15
@@ -120,21 +120,6 @@ static inline void dma_alloc_init(void) }#endif -static int init_baudrate (void ) -{ -char tmp[64 ]; -int i; - - i =getenv_r ("baudrate" , tmp,sizeof (tmp)); -if (i >0 ) { - gd->baudrate =simple_strtoul (tmp,NULL ,10 ); - }else { - gd->baudrate =CONFIG_BAUDRATE ; - } -return 0 ; -} - -static int display_banner (void ) {printf ("\n\n%s\n\n" , version_string);
lib_blackfin/board.c +0 -10
@@ -117,16 +117,6 @@ static int display_banner(void)return 0 ; } -static int init_baudrate (void ) -{ -char baudrate[15 ]; -int i =getenv_r ("baudrate" , baudrate,sizeof (baudrate)); - gd->bd->bi_baudrate = gd->baudrate = (i >0 ) - ?simple_strtoul (baudrate,NULL ,10 ) - :CONFIG_BAUDRATE ; -return 0 ; -} -static void display_global_data (void ) {#ifdef CONFIG_DEBUG_EARLY_SERIAL
lib_generic/Makefile +1 -0
@@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk LIB = $(obj)libgeneric.a +COBJS-y += board.o COBJS-y += bzlib.o COBJS-y += bzlib_crctable.o COBJS-y += bzlib_decompress.o
lib_generic/board.c new file +54 -0
54 lines not on this page · raw message
lib_i386/board.c +0 -25
@@ -108,19 +108,6 @@ void *sbrk (ptrdiff_t increment)return ((void *) old); } -char *strmhz (char *buf,long hz) -{ -long l, n; -long m; - - n = hz /1000000L ; - l =sprintf (buf,"%ld" , n); - m = (hz %1000000L ) /1000L ; -if (m !=0 ) -sprintf (buf + l,".%03ld" , m); -return (buf); -} -/************************************************************************ * Init Utilities * ************************************************************************
@@ -128,18 +115,6 @@ char *strmhz (char *buf, long hz)* or dropped completely, * but let's get it working (again) first... */ -static int init_baudrate (void ) -{ -char tmp[64 ];/* long enough for environment variables */ -int i =getenv_r ("baudrate" , tmp,64 ); - - gd->baudrate = (i !=0 ) - ? (int )simple_strtoul (tmp,NULL ,10 ) - :CONFIG_BAUDRATE ; - -return (0 ); -} -static int display_banner (void ) {
lib_m68k/board.c +0 -30
@@ -140,23 +140,6 @@ void *sbrk (ptrdiff_t increment)return ((void *)old); } -char *strmhz (char *buf,long hz) -{ -long l, n; -long m; - - n = hz /1000000L ; - - l =sprintf (buf,"%ld" , n); - - m = (hz %1000000L ) /1000L ; - -if (m !=0 ) -sprintf (buf+l,".%03ld" , m); - -return (buf); -} -/* * All attempts to come up with a "common" initialization sequence * that works for all boards and architectures failed: some of the
@@ -178,19 +161,6 @@ typedef int (init_fnc_t) (void);* but let's get it working (again) first... */ -static int init_baudrate (void ) -{ -char tmp[64 ];/* long enough for environment variables */ -int i =getenv_r ("baudrate" , tmp,sizeof (tmp)); - - gd->baudrate = (i >0 ) - ? (int )simple_strtoul (tmp,NULL ,10 ) - :CONFIG_BAUDRATE ; -return (0 ); -} - -/***********************************************************************/ -static int init_func_ram (void ) {int board_type =0 ;/* use dummy arg */
lib_mips/board.c +0 -13
@@ -131,19 +131,6 @@ static void display_flash_config(ulong size) }#endif -static int init_baudrate (void ) -{ -char tmp[64 ];/* long enough for environment variables */ -int i =getenv_r ("baudrate" , tmp,sizeof (tmp)); - - gd->baudrate = (i >0 ) - ? (int )simple_strtoul (tmp,NULL ,10 ) - :CONFIG_BAUDRATE ; - -return (0 ); -} - -/* * Breath some life into the board... *
lib_ppc/board.c +0 -14
@@ -167,20 +167,6 @@ void *sbrk (ptrdiff_t increment) mem_malloc_brk = new;return ((void *) old); } - -char *strmhz (char *buf,long hz) -{ -long l, n; -long m; - - n = hz /1000000L ; - l =sprintf (buf,"%ld" , n); - m = (hz %1000000L ) /1000L ; -if (m !=0 ) -sprintf (buf + l,".%03ld" , m); -return (buf); -} -/* * All attempts to come up with a "common" initialization sequence * that works for all boards and architectures failed: some of the
lib_sparc/board.c +0 -13
@@ -118,19 +118,6 @@ void *sbrk(ptrdiff_t increment)* but let's get it working (again) first... */ -static int init_baudrate (void ) -{ -char tmp[64 ];/* long enough for environment variables */ -int i =getenv_r ("baudrate" , tmp,sizeof (tmp)); - - gd->baudrate = (i >0 ) - ? (int )simple_strtoul (tmp,NULL ,10 ) - :CONFIG_BAUDRATE ; -return (0 ); -} - -/***********************************************************************/ -/* * All attempts to come up with a "common" initialization sequence * that works for all boards and architectures failed: some of the
Signature · 1 line
1.5.6.3
PATCH 1/1 Consolidate strmhz() implementation
In reply to Jean-Christophe PLAGNIOL-VILLARDQuoted 3 lines · Jean-Christophe PLAGNIOL-VILLARD
I've seen 2 others functions which are commom.
Could we use the patch that reply to this message instead?
The only downside that I can think of is that configuration that truly don't require strmhz() and don't use --gc-sections will end up slightly larger.
All the configurations I care about use --gc-sections, so it's fine with me.
Haavard
PATCH 1/1 Consolidate strmhz() implementation
Dear Jean-Christophe,
In message <[email protected]>
Quoted 8 lines · Haavard Skinnemoen
Quoted 4 lines
I've seen 2 others functions which are commom.
Could we use the patch that reply to this message instead?
The only downside that I can think of is that configuration that truly don't require
strmhz()and don't use --gc-sections will end up slightly larger.
I agree with Haavard's comment - the other functions should be added as separate source files, too.
BTW: you mentioned "two other functions", but your patch handles only one other function - init_baudrate() ?
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de There is, however, a strange, musty smell in the air that reminds me of something...hmm...yes...I've got it...there's a VMS nearby, or I'm a Blit. - Larry Wall in Configure from the perl distribution