net: eth_common: Don't use %pM when USE_TINY_PRINTF is enabled
PATCH v2 1/1 net: eth_common: Don't use %pM when USE_TINY_PRINTF is enabled
Tiny printf doesn't support %pM, so when CONFIG_USE_TINY_PRINTF is enabled use %x to manually print MAC address.
---
v2: use positive logic.
net/eth_common.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/eth_common.c +7 -0
@@ -37,7 +37,14 @@ int eth_setenv_enetaddr(const char *name, const uchar *enetaddr)if (eth_getenv_enetaddr (name, (uchar *)buf))return -EEXIST ; +#ifdef CONFIG_USE_TINY_PRINTF +sprintf (buf,"%x:%x:%x:%x:%x:%x" , (unsigned int )enetaddr[0 ], + (unsigned int )enetaddr[1 ], (unsigned int )enetaddr[2 ], + (unsigned int )enetaddr[3 ], (unsigned int )enetaddr[4 ], + (unsigned int )enetaddr[5 ]); +#else sprintf (buf,"%pM" , enetaddr); +#endif return setenv (name, buf); }
Signature · 1 line
2.11.0
PATCH v2 1/1 net: eth_common: Don't use %pM when USE_TINY_PRINTF is enabled
Dear Vignesh,
Quoted 2 lines · In message <[email protected]> you wrote:
Tiny printf doesn't support %pM, so when
CONFIG_USE_TINY_PRINTFis enabled use %x to manually print MAC address.
...
Quoted 2 lines
net/eth_common.c | 7 +++++++ 1 file changed, 7 insertions(+)
I wonder if this is sufficient. There is a ton of other files which use the %pM format:
arch/arm/mach-davinci/misc.c board/BuR/common/common.c board/bct-brettl2/bct-brettl2.c board/keymile/common/ivm.c board/pdm360ng/pdm360ng.c board/spear/common/spr_misc.c drivers/net/dm9000x.c drivers/net/fec_mxc.c drivers/net/lan91c96.c drivers/net/ne2000_base.c drivers/net/sandbox.c drivers/net/smc91111.c drivers/net/smc911x.c drivers/usb/eth/asix.c drivers/usb/eth/asix88179.c drivers/usb/eth/mcs7830.c drivers/usb/eth/r8152.c drivers/usb/eth/smsc95xx.c drivers/usb/gadget/ether.c net/arp.c net/eth-uclass.c net/eth_common.c net/eth_legacy.c net/link_local.c net/net.c
Adding similar #ifdef's to all of these seems to be a really bad idea to me.
Also, it would result in a lot of code duplication which is exactly what the introduction of the %p? formats intends to avoid.
So hat we need here is a way to determin if the code for a given configuration uses a specific %p? format, and then enable this even with CONFIG_USE_TINY_PRINTF.
OTOH - what is the use case for CONFIG_USE_TINY_PRINTF in combination with network related code? I would expect to see this config option in memory restricted environments like SPL, but there you don't include support for networking - or do you?
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk 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 X11 source code style is ATROCIOUS and should not be used as a model." - Doug Gwyn
PATCH v2 1/1 net: eth_common: Don't use %pM when USE_TINY_PRINTF is enabled
Dear Wolfgang Denk,
Quoted 42 lines · Wolfgang Denk
Dear Vignesh,
Quoted 2 lines · In message <[email protected]> you wrote:
Tiny printf doesn't support %pM, so when
CONFIG_USE_TINY_PRINTFis enabled use %x to manually print MAC address....
Quoted 2 lines
net/eth_common.c | 7 +++++++ 1 file changed, 7 insertions(+)I wonder if this is sufficient. There is a ton of other files which use the %pM format:
arch/arm/mach-davinci/misc.c board/BuR/common/common.c board/bct-brettl2/bct-brettl2.c board/keymile/common/ivm.c board/pdm360ng/pdm360ng.c board/spear/common/spr_misc.c drivers/net/dm9000x.c drivers/net/fec_mxc.c drivers/net/lan91c96.c drivers/net/ne2000_base.c drivers/net/sandbox.c drivers/net/smc91111.c drivers/net/smc911x.c drivers/usb/eth/asix.c drivers/usb/eth/asix88179.c drivers/usb/eth/mcs7830.c drivers/usb/eth/r8152.c drivers/usb/eth/smsc95xx.c drivers/usb/gadget/ether.c net/arp.c net/eth-uclass.c net/eth_common.c net/eth_legacy.c net/link_local.c net/net.cAdding similar #ifdef's to all of these seems to be a really bad idea to me.
Quoted 7 lines
Also, it would result in a lot of code duplication which is exactly what the introduction of the %p? formats intends to avoid.
So hat we need here is a way to determin if the code for a given configuration uses a specific %p? format, and then enable this even with
CONFIG_USE_TINY_PRINTF.
I agree, networking widely uses %pM for printing mac addresses. Are you suggesting to port %pM support from lib/vsprintf.c to lib/tiny-printf.c and make it available based on CONFIG_CMD_NET?
Quoted 5 lines
OTOH - what is the use case for
CONFIG_USE_TINY_PRINTFin combination with network related code? I would expect to see this config option in memory restricted environments like SPL, but there you don't include support for networking - or do you?
I am trying to use RNDIS boot on am437x/am335x boards with CONFIG_USE_TINY_PRINTF(to reduce code size due to internal SRAM size constraint) and therefore need networking support in SPL.
Signature · 2 lines
Regards Vignesh
PATCH v2 1/1 net: eth_common: Don't use %pM when USE_TINY_PRINTF is enabled
Dear Vignesh,
Quoted 4 lines · In message <[email protected]> you wrote:
I agree, networking widely uses %pM for printing mac addresses. Are you suggesting to port %pM support from
lib/vsprintf.ctolib/tiny-printf.cand make it available based onCONFIG_CMD_NET?
I don't think we should add another #ifdef for this. How much (in terms of number of bytes) does it hurt to add it without an #ifdef?
I guess we cannot handle this in some intelligent automatic way similar to dead code elimination?
Quoted 3 lines
I am trying to use RNDIS boot on am437x/am335x boards with
CONFIG_USE_TINY_PRINTF(to reduce code size due to internal SRAM size constraint)and therefore need networking support in SPL.
So you need networking _and_ USB and still care about the printf() size? Ouch...
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
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
"Plan to throw one away. You will anyway."
- Fred Brooks, "The Mythical Man Month"PATCH v2 1/1 net: eth_common: Don't use %pM when USE_TINY_PRINTF is enabled
Quoted 11 lines · Wolfgang Denk
Dear Vignesh,
Quoted 4 lines · In message <[email protected]> you wrote:
I agree, networking widely uses %pM for printing mac addresses. Are you suggesting to port %pM support from
lib/vsprintf.ctolib/tiny-printf.cand make it available based onCONFIG_CMD_NET?I don't think we should add another #ifdef for this. How much (in terms of number of bytes) does it hurt to add it without an #ifdef?
I ported minimal support for %p? to tiny-printf and here are the stats:
With changes to support %p?(%p %pa[p], %pI[46], %pm, %pM) format in tiny printf SPL size increases by 509 bytes.
With changes to support just %p, %pa[p] formats in tiny-printf delta is ~75 bytes wrt plain SPL
Therefore, if %pM and other net related printf formats are disabled based on CONFIG_CMD_NET savings is ~434 bytes
Compiler used is: arm-linux-gnueabihf-gcc (Linaro GCC 6.2-2016.11) 6.2.1 20161016
Quoted 10 lines
I guess we cannot handle this in some intelligent automatic way similar to dead code elimination?
Quoted 3 lines
I am trying to use RNDIS boot on am437x/am335x boards with
CONFIG_USE_TINY_PRINTF(to reduce code size due to internal SRAM size constraint)and therefore need networking support in SPL.So you need networking _and_ USB and still care about the
printf()size? Ouch...
USB RNDIS boot has been supported on am335x platform in mainline u-boot for quite some time. But the SPL size is steadily increasing due to which CONFIG_USE_TINY_PRINTF needs to be enabled to avoid SRAM overflow.
Quoted 4 lines
Best regards,
Wolfgang Denk
Signature · 2 lines
Regards Vignesh