lib: Implement support for tiny sprintf()
RFC PATCH 1/2 lib: Implement support for tiny sprintf()
Tweak the tiny printf code to also provide similarly tiny sprintf() implementation. This is not comformant with POSIX for sure, but it keeps the size down while still behaving rather reasonably.
--- lib/tiny-printf.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-)
lib/tiny-printf.c +33 -5
@@ -40,7 +40,17 @@ static void div_out(unsigned int *num, unsigned int div)out_dgt (dgt); } -int vprintf (const char *fmt,va_list va) +#ifdef CONFIG_USE_TINY_SPRINTF +#define local_putc (pbuf, ch) \ + if (pbuf) \ + *(pbuf)++ = (ch); \ + else \ + putc(ch); +#else +#define local_putc (pbuf, ch) putc(ch) +#endif + +static int local_xprintf (char *pbuf,const char *fmt,va_list va) {char ch;char *p;
@@ -50,7 +60,7 @@ int vprintf(const char *fmt, va_list va)while ((ch = *(fmt++))) {if (ch !='%' ) { -putc (ch); +local_putc (pbuf, ch); }else {char lz =0 ;char w =0 ;
@@ -115,10 +125,10 @@ int vprintf(const char *fmt, va_list va)while (*bf++ && w >0 ) w--;while (w-- >0 ) -putc (lz ?'0' :' ' ); +local_putc (pbuf, lz ?'0' :' ' );if (p) {while ((ch = *p++)) -putc (ch); +local_putc (pbuf, ch); } } }
@@ -127,13 +137,31 @@ abort:return 0 ; } + +int vprintf (const char *fmt,va_list va) +{ +return local_xprintf (NULL , fmt, va); +} +int printf (const char *fmt, ...) {va_list va;int ret;va_start (va, fmt); - ret =vprintf (fmt, va); + ret =local_xprintf (NULL , fmt, va); +va_end (va); + +return ret; +} + +int sprintf (char *buf,const char *fmt, ...) +{ +va_list va; +int ret; + +va_start (va, fmt); + ret =local_xprintf (buf, fmt, va);va_end (va);return ret;
Signature · 1 line
2.7.0
RFC PATCH 2/2 ARM: omap: Enable tiny printf/sprintf on omap3_logic
Enable support for tiny printf and tiny sprintf on the omap3_logic board to trim down the SPL size. This makes the SPL actually build again and fit into the SRAM.
--- include/configs/omap3_logic.h | 5 +++++ 1 file changed, 5 insertions(+)
include/configs/omap3_logic.h +5 -0
@@ -290,6 +290,11 @@#define CONFIG_SPL_OMAP3_ID_NAND +#ifdef CONFIG_SPL_BUILD +#define CONFIG_USE_TINY_PRINTF +#define CONFIG_USE_TINY_SPRINTF +#endif +/* NAND: SPL falcon mode configs */ #ifdef CONFIG_SPL_OS_BOOT #define CONFIG_CMD_SPL_NAND_OFS 0x240000
Signature · 1 line
2.7.0
RFC PATCH 2/2 ARM: omap: Enable tiny printf/sprintf on omap3_logic
Quoted 7 lines · Marek Vasut
Enable support for tiny printf and tiny sprintf on the
omap3_logicboard to trim down the SPL size. This makes the SPL actually build again and fit into the SRAM.Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>
... but can you Kconfig this after? :)
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160530/0e0f42b8/attachment.sig>
RFC PATCH 1/2 lib: Implement support for tiny sprintf()
In reply to Marek VasutQuoted 7 lines · Marek Vasut
Tweak the tiny printf code to also provide similarly tiny
sprintf()implementation. This is not comformant with POSIX for sure, but it keeps the size down while still behaving rather reasonably.Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160530/125c3f77/attachment.sig>
RFC PATCH 1/2 lib: Implement support for tiny sprintf()
Quoted 6 lines · Tom Rini
Quoted 4 lines · Marek Vasut
Tweak the tiny printf code to also provide similarly tiny
sprintf()implementation. This is not comformant with POSIX for sure, but it keeps the size down while still behaving rather reasonably.
Quoted 6 lines
Quoted 3 lines
Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Reviewed-by Tom Rini <[email protected]>
Mind you, I really dislike how I "implemented" this, it's really more of a vulgar hack. Do you have any comments on this patch ?
Signature · 2 lines
Best regards, Marek Vasut
RFC PATCH 2/2 ARM: omap: Enable tiny printf/sprintf on omap3_logic
In reply to Tom RiniQuoted 6 lines · Tom Rini
Quoted 4 lines · Marek Vasut
Enable support for tiny printf and tiny sprintf on the
omap3_logicboard to trim down the SPL size. This makes the SPL actually build again and fit into the SRAM.
Quoted 8 lines
Quoted 3 lines
Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Reviewed-by Tom Rini <[email protected]>... but can you
Kconfigthis after? :)
I can, but I'd like comments on patch 1/2 . Are you OK with this stuff ?
Signature · 2 lines
Best regards, Marek Vasut
RFC PATCH 1/2 lib: Implement support for tiny sprintf()
In reply to Tom RiniHi,
Quoted 11 lines · Tom Rini
Quoted 7 lines · Marek Vasut
Tweak the tiny printf code to also provide similarly tiny
sprintf()implementation. This is not comformant with POSIX for sure, but it keeps the size down while still behaving rather reasonably.Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Reviewed-by Tom Rini <[email protected]>
Also please see this one:
http://patchwork.ozlabs.org/patch/622267/
It uses a function passed in.
Regards,
Simon
RFC PATCH 1/2 lib: Implement support for tiny sprintf()
Quoted 13 lines · Simon Glass
Hi,
Quoted 10 lines · Tom Rini
Quoted 7 lines · Marek Vasut
Tweak the tiny printf code to also provide similarly tiny
sprintf()implementation. This is not comformant with POSIX for sure, but it keeps the size down while still behaving rather reasonably.Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>
Quoted 7 lines
Quoted 1 line
Reviewed-by Tom Rini <[email protected]>Also please see this one:
http://patchwork.ozlabs.org/patch/622267/
It uses a function passed in.
Oh, I knew I saw some s*printf() stuff from you. Works for me :)
Signature · 2 lines
Best regards, Marek Vasut
RFC PATCH 1/2 lib: Implement support for tiny sprintf()
Hi Marek,
Quoted 16 lines · Marek Vasut
Quoted 15 lines · Simon Glass
Hi,
Quoted 11 lines · Tom Rini
Quoted 7 lines · Marek Vasut
Tweak the tiny printf code to also provide similarly tiny
sprintf()implementation. This is not comformant with POSIX for sure, but it keeps the size down while still behaving rather reasonably.Signed-off-by Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Reviewed-by Tom Rini <[email protected]>
Quoted 7 lines
Quoted 5 lines
Also please see this one:
http://patchwork.ozlabs.org/patch/622267/
It uses a function passed in.
Oh, I knew I saw some s*printf() stuff from you. Works for me :)
OK good. It works for me too but I'm sure it can be improved (code size, use of division, etc.), so see how you go.
Regards,
Simon