Reduce code size of libnet
v2 cover Reduce code size of libnet
This patch series should change no functionality, but just reduce code size slightly to what it was before the tftpput series.
Each patch is independent and each can be accepted or rejected as required. Overall the effect is to reduce the code size to about 36 bytes lower than it was before tftp when in on ARMv7 and PowerPC (IAD210) with my toolchains.
Since this changes core net code, it needs to be examined carefully.
Changes in v2:
- Add net_transfer() fix
- Add patch with #ifdefs for cases which can only happen with tftpput
- Fix commit message to say memset() instead of memcpy()
Simon Glass (6):
net: Hide more code behind CONFIG_CMD_TFTPPUT
net: Make net_transfer() a static function
net: Add more #ifdefs for tftpput to reduce code size
net: Change for loop to memset()
net: Be less picky about decoding the netretry env var
net: Export auto_load, use it in rarp
README | 4 ++++ include/net.h | 6 ++++++ net/bootp.c | 34 ++-------------------------------- net/net.c | 52 +++++++++++++++++++++++++++++++++++++++++++--------- net/rarp.c | 18 +----------------- net/tftp.c | 19 +++++++++++++++---- 6 files changed, 71 insertions(+), 62 deletions(-)
Signature · 1 line
1.7.3.1
PATCH v2 1/6 net: Hide more code behind CONFIG_CMD_TFTPPUT
This commit reduces code size a little by making the ICMP handler only available to tftpput. This is reasonable since it is the only user at present (ping just uses the normal handler).
---
net/net.c | 8 ++++++++ net/tftp.c | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-)
net/net.c +8 -0
@@ -215,7 +215,9 @@ volatile uchar *NetRxPackets[PKTBUFSRX];/* Current RX packet handler */ static rxhand_f *packetHandler; +#ifdef CONFIG_CMD_TFTPPUT static rxhand_icmp_f *packet_icmp_handler;/* Current ICMP rx handler */ +#endif /* Current timeout handler */ static thand_f *timeHandler;/* Time base value */
@@ -576,9 +578,11 @@ restart: } done: +#ifdef CONFIG_CMD_TFTPPUT/* Clear out the handlers */ NetSetHandler (NULL );net_set_icmp_handler (NULL ); +#endif return ret; }
@@ -653,10 +657,12 @@ NetSetHandler(rxhand_f *f) packetHandler = f; } +#ifdef CONFIG_CMD_TFTPPUT void net_set_icmp_handler (rxhand_icmp_f *f) { packet_icmp_handler = f; } +#endif void NetSetTimeout (ulong iv,thand_f *f)
@@ -1397,10 +1403,12 @@ static void receive_icmp(IP_t *ip, int len, IPaddr_t src_ip, Ethernet_t *et)break ;#endif default : +#ifdef CONFIG_CMD_TFTPPUT if (packet_icmp_handler)packet_icmp_handler (icmph->type, icmph->code,ntohs (ip->udp_dst), src_ip,ntohs (ip->udp_src), icmph->un.data,ntohs (ip->udp_len)); +#endif break ; } }
net/tftp.c +4 -2
@@ -421,7 +421,7 @@ TftpSend(void) TftpOurPort, len); } - +#ifdef CONFIG_CMD_TFTPPUT static void icmp_handler (unsigned type,unsigned code,unsigned dest,IPaddr_t sip,unsigned src,uchar *pkt,unsigned len) {
@@ -430,6 +430,7 @@ static void icmp_handler(unsigned type, unsigned code, unsigned dest, restart("TFTP server died"); } } +#endif static void TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
@@ -771,8 +772,9 @@ void TftpStart(enum proto_t protocol)NetSetTimeout (TftpTimeoutMSecs, TftpTimeout);NetSetHandler (TftpHandler); +#ifdef CONFIG_CMD_TFTPPUT net_set_icmp_handler (icmp_handler); - +#endif TftpRemotePort =WELL_KNOWN_PORT ; TftpTimeoutCount =0 ;/* Use a pseudo-random port unless a specific port is set */
Signature · 1 line
1.7.3.1
PATCH v2 1/6 net: Hide more code behind CONFIG_CMD_TFTPPUT
i wish there was a way we could be clever and give gcc hints to do better DCE rather than sprinkling #ifdef's. but maybe this is a pipe dream.
-mike
Wolfgang Denk
AppliedPATCH v2 1/6 net: Hide more code behind CONFIG_CMD_TFTPPUT
In reply to Simon GlassDear Simon Glass,
Quoted 6 lines · In message <[email protected]> you wrote:
This commit reduces code size a little by making the ICMP handler only available to tftpput. This is reasonable since it is the only user at present (ping just uses the normal handler).
Signed-off-by Simon Glass <[email protected]>---
Applied, thanks.
Best regards,
Wolfgang Denk
Signature · 4 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 God is real, unless declared integer.
PATCH v2 2/6 net: Make net_transfer() a static function
In reply to Simon GlassThis should be a static function so it can be inlined.
---
Changes in v2:
- Add net_transfer() fix
net/tftp.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
net/tftp.c +1 -1
@@ -198,7 +198,7 @@ store_block(unsigned block, uchar *src, unsigned len) }/* Clear our state ready for a new transfer */ -void new_transfer (void ) +static void new_transfer (void ) { TftpLastBlock =0 ; TftpBlockWrap =0 ;
Signature · 1 line
1.7.3.1
PATCH v2 2/6 net: Make net_transfer() a static function
-mike
Wolfgang Denk
AppliedPATCH v2 2/6 net: Make net_transfer() a static function
In reply to Simon GlassDear Simon Glass,
Quoted 9 lines · In message <[email protected]> you wrote:
This should be a static function so it can be inlined.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Addnet_transfer()fixnet/tftp.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
Signature · 5 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 "Most people would like to be delivered from temptation but would like it to keep in touch." - Robert Orben
PATCH v2 3/6 net: Add more #ifdefs for tftpput to reduce code size
In reply to Simon GlassIf CONFIG_CMD_TFTPPUT is not enabled, we want minimal code size impact on the tftp code. This introduces a few more #ifdefs.
---
Changes in v2:
- Add patch with #ifdefs for cases which can only happen with tftpput
net/tftp.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-)
net/tftp.c +10 -1
@@ -332,8 +332,12 @@ TftpSend(void)case STATE_SEND_WRQ : xp = pkt; s = (ushort *)pkt; +#ifdef CONFIG_CMD_TFTPPUT *s++ =htons (TftpState ==STATE_SEND_RRQ ?TFTP_RRQ :TFTP_WRQ ); +#else + *s++ =htons (TFTP_RRQ ); +#endif pkt = (uchar *)s;strcpy ((char *)pkt, tftp_filename); pkt +=strlen (tftp_filename) +1 ;
@@ -730,7 +734,12 @@ void TftpStart(enum proto_t protocol)printf ("Using %s device\n" ,eth_get_name ()); printf("TFTP %s server %pI4; our IP address is %pI4", - protocol ==TFTPPUT ?"to" :"from" , &TftpRemoteIP, &NetOurIP); +#ifdef CONFIG_CMD_TFTPPUT + protocol ==TFTPPUT ?"to" :"from" , +#else +"from" , +#endif + &TftpRemoteIP, &NetOurIP);/* Check if we need to send across this subnet */ if (NetOurGatewayIP && NetOurSubnetMask) {
Signature · 1 line
1.7.3.1
Wolfgang Denk
AppliedPATCH v2 3/6 net: Add more #ifdefs for tftpput to reduce code size
Dear Simon Glass,
Quoted 10 lines · In message <[email protected]> you wrote:
If
CONFIG_CMD_TFTPPUTis not enabled, we want minimal code size impact on the tftp code. This introduces a few more #ifdefs.Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Add patch with #ifdefs for cases which can only happen with tftpputnet/tftp.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
Signature · 5 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 "The two most common things in the universe are hydrogen and stupi- dity."
PATCH v2 4/6 net: Change for loop to memset()
In reply to Simon GlassThis is intended purely as a code size reduction.
---
Changes in v2:
- Fix commit message to say memset() instead of memcpy()
net/net.c | 8 ++------ 1 files changed, 2 insertions(+), 6 deletions(-)
net/net.c +2 -6
@@ -246,7 +246,6 @@ int NetArpWaitTry;void ArpRequest (void ) { -int i;volatile uchar *pkt;ARP_t *arp;
@@ -268,11 +267,8 @@ void ArpRequest(void)memcpy (&arp->ar_data[0 ], NetOurEther,6 );/* source IP addr */ NetWriteIP ((uchar *) &arp->ar_data[6 ], NetOurIP); -for (i =10 ; i <16 ; ++i) { -/* dest ET addr = 0 */ - arp->ar_data[i] =0 ; - } - +/* dest ET addr = 0 */ +memset (&arp->ar_data[10 ],'\0' ,6 );if ((NetArpWaitPacketIP & NetOurSubnetMask) != (NetOurIP & NetOurSubnetMask)) {if (NetOurGatewayIP ==0 ) {
Signature · 1 line
1.7.3.1
PATCH v2 4/6 net: Change for loop to memset()
-mike
Wolfgang Denk
AppliedPATCH v2 4/6 net: Change for loop to memset()
In reply to Simon GlassDear Simon Glass,
Quoted 9 lines · In message <[email protected]> you wrote:
This is intended purely as a code size reduction.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Fix commit message to saymemset()instead ofmemcpy()net/net.c | 8 ++------ 1 files changed, 2 insertions(+), 6 deletions(-)
Applied, thanks.
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
Perfection is reached, not when there is no longer anything to add,
but when there is no longer anything to take away.
- Antoine de Saint-ExuperyPATCH v2 5/6 net: Be less picky about decoding the netretry env var
In reply to Simon GlassThis is intended purely as a code size reduction.
---
README | 4 ++++ net/net.c | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-)
README +4 -0
@@ -3579,6 +3579,10 @@ List of environment variables (most likely not complete): are tried once without success. Useful on scripts which control the retry operation themselves. + When unset, or set to "yes", each network operation + will retry forever. Note that only the first letter + is significant (any word beginning with y, n, o + will select the corressponding option). npe_ucode - set load address for the NPE microcode
net/net.c +3 -3
@@ -605,11 +605,11 @@ void NetStartAgain(void) nretry =getenv ("netretry" );if (nretry) { -if (!strcmp (nretry,"yes" )) +if (*nretry =='y' ) retry_forever =1 ; -else if (!strcmp (nretry,"no" )) +else if (!*nretry =='n' ) retrycnt =0 ; -else if (!strcmp (nretry,"once" )) +else if (*nretry =='o' )/* "once" */ retrycnt =1 ;else retrycnt =simple_strtoul (nretry,NULL ,0 );
Signature · 1 line
1.7.3.1
PATCH v2 5/6 net: Be less picky about decoding the netretry env var
Dear Simon Glass,
Quoted 14 lines · In message <[email protected]> you wrote:
This is intended purely as a code size reduction.
Signed-off-by Simon Glass <[email protected]>---
README | 4 ++++ net/net.c | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-)README +0
-0
README List of environment variables (most likely not complete): · line 3585
Quoted 7 lines
README +4
-0@@ -3579,6 +3579,10 @@ List of environment variables (most likely not complete): are tried once without success. Useful on scripts which control the retry operation themselves. + When unset, or set to "yes", each network operation + will retry forever. Note that only the first letter + is significant (any word beginning with y, n, o + will select the corressponding option).
Sorry, but especially the 'o' scares me.
May I drop this one?
Best regards,
Wolfgang Denk
Signature · 5 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 if" is a trademark of Hewlett Packard, so stop using it in your sentences without permission, or risk being sued.
PATCH v2 5/6 net: Be less picky about decoding the netretry env var
Hi Wolfgang,
Quoted 27 lines · Wolfgang Denk
Dear Simon Glass,
Quoted 14 lines · In message <[email protected]> you wrote:
This is intended purely as a code size reduction.
Signed-off-by Simon Glass <[email protected]>---
?README ? ?| ? ?4 ++++
?net/net.c | ? ?6 +++---
?2 files changed, 7 insertions(+), 3 deletions(-)README +0
-0@@ -3579,6 +3579,10 @@ List of environment variables (most likely not complete):Quoted 7 lines
? ? ? ? ? ? ? ? are tried once without success.
? ? ? ? ? ? ? ? Useful on scripts which control the retry operation ? ? ? ? ? ? ? ? themselves.
+ ? ? ? ? ? ? ? When unset, or set to "yes", each network operation
+ ? ? ? ? ? ? ? will retry forever. Note that only the first letter
+ ? ? ? ? ? ? ? is significant (any word beginning with y, n, o
+ ? ? ? ? ? ? ? will select the corressponding option).Sorry, but especially the 'o' scares me.
Quoted 1 line
May I drop this one?
Yes of course, these are just ideas and I agree about the 'o'.
Regards,
Simon
Quoted 12 lines
Best regards,
Wolfgang Denk
--
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 if" is a trademark of Hewlett Packard, so stop using it in your sentences without permission, or risk being sued.
PATCH v2 6/6 net: Export auto_load, use it in rarp
In reply to Simon GlassThe rarp code includes another instance of the auto_load logic, so call what is now net_auto_load() instead.
This also fixes an incorrect call to TftpStart() which was never seen since apparently no boards enable rarp.
---
include/net.h | 6 ++++++ net/bootp.c | 34 ++-------------------------------- net/net.c | 30 ++++++++++++++++++++++++++++++ net/rarp.c | 18 +----------------- 4 files changed, 39 insertions(+), 49 deletions(-)
include/net.h +6 -0
@@ -430,6 +430,12 @@ extern int NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, iextern void NetReceive (volatile uchar *,int );/* +* Check if autoload is enabled. If so, use either NFS or TFTP to download +* the boot file. +*/ +void net_auto_load (void ); + +/* * The following functions are a bit ugly, but necessary to deal with * alignment restrictions on ARM. *
net/bootp.c +2 -32
@@ -138,36 +138,6 @@ static int truncate_sz (const char *name, int maxlen, int curlen)return (curlen); } -/* -* Check if autoload is enabled. If so, use either NFS or TFTP to download -* the boot file. -*/ -static void auto_load (void ) -{ -const char *s =getenv ("autoload" ); - -if (s !=NULL ) { -if (*s =='n' ) { -/* -* Just use BOOTP to configure system; -* Do not use TFTP to load the bootfile. -*/ - NetState =NETLOOP_SUCCESS ; -return ; - } -#if defined(CONFIG_CMD_NFS ) -if (strcmp (s,"NFS" ) ==0 ) { -/* -* Use NFS to load the bootfile. -*/ -NfsStart (); -return ; - } -#endif - } -TftpStart (TFTPGET ); -} -#if !defined(CONFIG_CMD_DHCP )static void BootpVendorFieldProcess (u8 * ext)
@@ -354,7 +324,7 @@ BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,debug ("Got good BOOTP\n" ); - auto_load(); + net_auto_load(); }#endif
@@ -979,7 +949,7 @@ DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, dhcp_state =BOUND ;printf ("DHCP client bound to address %pI4\n" , &NetOurIP); -auto_load (); +net_auto_load ();return ; }break ;
net/net.c +30 -0
@@ -309,6 +309,36 @@ void ArpTimeoutCheck(void) } } +/* +* Check if autoload is enabled. If so, use either NFS or TFTP to download +* the boot file. +*/ +void net_auto_load (void ) +{ +const char *s =getenv ("autoload" ); + +if (s !=NULL ) { +if (*s =='n' ) { +/* +* Just use BOOTP/RARP to configure system; +* Do not use TFTP to load the bootfile. +*/ + NetState =NETLOOP_SUCCESS ; +return ; + } +#if defined(CONFIG_CMD_NFS ) +if (strcmp (s,"NFS" ) ==0 ) { +/* +* Use NFS to load the bootfile. +*/ +NfsStart (); +return ; + } +#endif + } +TftpStart (TFTPGET ); +} +static void NetInitLoop (enum proto_t protocol) {static int env_changed_id;
net/rarp.c +1 -17
@@ -46,24 +46,8 @@ static void RarpHandler(uchar *dummi0, unsigned dummi1, IPaddr_t sip, unsigned dummi2, unsigned dummi3) { -char *s;debug ("Got good RARP\n" ); -if ((s =getenv ("autoload" )) !=NULL ) { -if (*s =='n' ) { -/* -* Just use RARP to configure system; -* Do not use TFTP/NFS to to load the bootfile. -*/ - NetState =NETLOOP_SUCCESS ; -return ; -#if defined(CONFIG_CMD_NFS ) - } else if ((s != NULL) && !strcmp(s, "NFS")) { -NfsStart (); -return ; -#endif - } - } -TftpStart (); +net_auto_load (); }
Signature · 1 line
1.7.3.1
PATCH v2 6/6 net: Export auto_load, use it in rarp
Quoted 2 lines · Simon Glass
The rarp code includes another instance of the
auto_loadlogic, so call what is nownet_auto_load()instead.
Quoted 2 lines
This also fixes an incorrect call to
TftpStart()which was never seen since apparently no boards enable rarp.
i wonder if we shouldn't just drop rarp then if no one actually uses it ... -mike
PATCH v2 6/6 net: Export auto_load, use it in rarp
Hi Mike,
Quoted 4 lines · Mike Frysinger
Quoted 2 lines · Simon Glass
The rarp code includes another instance of the
auto_loadlogic, so call what is nownet_auto_load()instead.
Quoted 8 lines
Acked-by Mike Frysinger <[email protected]>Quoted 2 lines
This also fixes an incorrect call to
TftpStart()which was never seen since apparently no boards enable rarp.i wonder if we shouldn't just drop rarp then if no one actually uses it ... -mike
Well that's the definition of dead code, but of course there may be thousands of boards out there that use it, where the code is not upstream. I suppose we could take the code out and see if anyone notices :-) It is at least in a separate file and not built unless requested.
Regards,
Simon
PATCH v2 6/6 net: Export auto_load, use it in rarp
Quoted 5 lines · Simon Glass
Quoted 4 lines · Mike Frysinger
Quoted 2 lines · Simon Glass
This also fixes an incorrect call to
TftpStart()which was never seen since apparently no boards enable rarp.
Quoted 7 lines
Quoted 1 line
i wonder if we shouldn't just drop rarp then if no one actually uses it ...
Well that's the definition of dead code, but of course there may be thousands of boards out there that use it, where the code is not upstream. I suppose we could take the code out and see if anyone notices :-) It is at least in a separate file and not built unless requested.
i think our (reasonable) position is that if no one is using it, and no one is noticing when it breaks, then we should simply drop it. if out of tree boards cared, they'd be in tree.
i like to think that the barrier for inclusion in u-boot is significantly lower than the linux kernel ... -mike
PATCH v2 6/6 net: Export auto_load, use it in rarp
Quoted 14 lines · Mike Frysinger
Quoted 5 lines · Simon Glass
Quoted 4 lines · Mike Frysinger
Quoted 2 lines · Simon Glass
This also fixes an incorrect call to
TftpStart()which was never seen since apparently no boards enable rarp.Quoted 7 lines
Quoted 1 line
i wonder if we shouldn't just drop rarp then if no one actually uses it ...
Well that's the definition of dead code, but of course there may be thousands of boards out there that use it, where the code is not upstream. I suppose we could take the code out and see if anyone notices :-) It is at least in a separate file and not built unless requested.
Quoted 3 lines
i think our (reasonable) position is that if no one is using it, and no one is noticing when it breaks, then we should simply drop it. if out of tree boards cared, they'd be in tree.
For features like this that are user-enableable, rather than e.g. a board code dependency, it's users that care, not boards. I don't think we're asking people to submit a variant "board" config with their own personal preferences/requirements, if they differ from the board maintainer's. Unfortunately U-Boot lacks the ability to do an "allyesconfig" to at least build-test such features.
Of course, if it's actually been broken for a while, that suggests that the users don't care either. :-) Or perhaps are running older versions, but might upgrade at some point.
It's probably best to follow the normal feature removal process to see if anyone's interested in maintaining it, before removing it.
-Scott
PATCH v2 6/6 net: Export auto_load, use it in rarp
Quoted 19 lines · Scott Wood
Quoted 14 lines · Mike Frysinger
Quoted 5 lines · Simon Glass
Quoted 4 lines · Mike Frysinger
Quoted 2 lines · Simon Glass
This also fixes an incorrect call to
TftpStart()which was never seen since apparently no boards enable rarp.Quoted 7 lines
Quoted 1 line
i wonder if we shouldn't just drop rarp then if no one actually uses it ...
Well that's the definition of dead code, but of course there may be thousands of boards out there that use it, where the code is not upstream. I suppose we could take the code out and see if anyone notices :-) It is at least in a separate file and not built unless requested.
Quoted 3 lines
i think our (reasonable) position is that if no one is using it, and no one is noticing when it breaks, then we should simply drop it. ?if out of tree boards cared, they'd be in tree.
Quoted 6 lines
For features like this that are user-enableable, rather than e.g. a board code dependency, it's users that care, not boards. ?I don't think we're asking people to submit a variant "board" config with their own personal preferences/requirements, if they differ from the board maintainer's. ?Unfortunately U-Boot lacks the ability to do an "allyesconfig" to at least build-test such features.
i'd submit that the boards in the tree are a fairly good sampling of what people actually deploy. by virtue of no default board config enabling this, it's most likely that no user does either.
Quoted 2 lines
It's probably best to follow the normal feature removal process to see if anyone's interested in maintaining it, before removing it.
certainly
-mike