All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/2] [RFC] lib: Implement support for tiny sprintf()
@ 2016-05-26 16:00 Marek Vasut
  2016-05-26 16:00 ` [U-Boot] [PATCH 2/2] [RFC] ARM: omap: Enable tiny printf/sprintf on omap3_logic Marek Vasut
  2016-05-30 17:55 ` [U-Boot] [PATCH 1/2] [RFC] lib: Implement support for tiny sprintf() Tom Rini
  0 siblings, 2 replies; 9+ messages in thread
From: Marek Vasut @ 2016-05-26 16:00 UTC (permalink / raw)
  To: u-boot

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 <marex@denx.de>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>
---
 lib/tiny-printf.c | 38 +++++++++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)

diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
index a06abed..b9fba97 100644
--- a/lib/tiny-printf.c
+++ b/lib/tiny-printf.c
@@ -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;
-- 
2.7.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 2/2] [RFC] ARM: omap: Enable tiny printf/sprintf on omap3_logic
  2016-05-26 16:00 [U-Boot] [PATCH 1/2] [RFC] lib: Implement support for tiny sprintf() Marek Vasut
@ 2016-05-26 16:00 ` Marek Vasut
  2016-05-30 17:55   ` Tom Rini
  2016-05-30 17:55 ` [U-Boot] [PATCH 1/2] [RFC] lib: Implement support for tiny sprintf() Tom Rini
  1 sibling, 1 reply; 9+ messages in thread
From: Marek Vasut @ 2016-05-26 16:00 UTC (permalink / raw)
  To: u-boot

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.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>
---
 include/configs/omap3_logic.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/include/configs/omap3_logic.h b/include/configs/omap3_logic.h
index 3c11e2a..8ff5f66 100644
--- a/include/configs/omap3_logic.h
+++ b/include/configs/omap3_logic.h
@@ -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
-- 
2.7.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 2/2] [RFC] ARM: omap: Enable tiny printf/sprintf on omap3_logic
  2016-05-26 16:00 ` [U-Boot] [PATCH 2/2] [RFC] ARM: omap: Enable tiny printf/sprintf on omap3_logic Marek Vasut
@ 2016-05-30 17:55   ` Tom Rini
  2016-05-30 23:31     ` Marek Vasut
  0 siblings, 1 reply; 9+ messages in thread
From: Tom Rini @ 2016-05-30 17:55 UTC (permalink / raw)
  To: u-boot

On Thu, May 26, 2016 at 06:00:25PM +0200, Marek Vasut wrote:

> 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.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Simon Glass <sjg@chromium.org>
> Cc: Tom Rini <trini@konsulko.com>

Reviewed-by: Tom Rini <trini@konsulko.com>

... but can you Kconfig this after? :)

-- 
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>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 1/2] [RFC] lib: Implement support for tiny sprintf()
  2016-05-26 16:00 [U-Boot] [PATCH 1/2] [RFC] lib: Implement support for tiny sprintf() Marek Vasut
  2016-05-26 16:00 ` [U-Boot] [PATCH 2/2] [RFC] ARM: omap: Enable tiny printf/sprintf on omap3_logic Marek Vasut
@ 2016-05-30 17:55 ` Tom Rini
  2016-05-30 23:30   ` Marek Vasut
  2016-05-31 18:19   ` Simon Glass
  1 sibling, 2 replies; 9+ messages in thread
From: Tom Rini @ 2016-05-30 17:55 UTC (permalink / raw)
  To: u-boot

On Thu, May 26, 2016 at 06:00:24PM +0200, Marek Vasut wrote:

> 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 <marex@denx.de>
> Cc: Simon Glass <sjg@chromium.org>
> Cc: Tom Rini <trini@konsulko.com>

Reviewed-by: Tom Rini <trini@konsulko.com>

-- 
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>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 1/2] [RFC] lib: Implement support for tiny sprintf()
  2016-05-30 17:55 ` [U-Boot] [PATCH 1/2] [RFC] lib: Implement support for tiny sprintf() Tom Rini
@ 2016-05-30 23:30   ` Marek Vasut
  2016-05-31 18:19   ` Simon Glass
  1 sibling, 0 replies; 9+ messages in thread
From: Marek Vasut @ 2016-05-30 23:30 UTC (permalink / raw)
  To: u-boot

On 05/30/2016 07:55 PM, Tom Rini wrote:
> On Thu, May 26, 2016 at 06:00:24PM +0200, Marek Vasut wrote:
> 
>> 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 <marex@denx.de>
>> Cc: Simon Glass <sjg@chromium.org>
>> Cc: Tom Rini <trini@konsulko.com>
> 
> Reviewed-by: Tom Rini <trini@konsulko.com>
> 
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 ?

-- 
Best regards,
Marek Vasut

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 2/2] [RFC] ARM: omap: Enable tiny printf/sprintf on omap3_logic
  2016-05-30 17:55   ` Tom Rini
@ 2016-05-30 23:31     ` Marek Vasut
  0 siblings, 0 replies; 9+ messages in thread
From: Marek Vasut @ 2016-05-30 23:31 UTC (permalink / raw)
  To: u-boot

On 05/30/2016 07:55 PM, Tom Rini wrote:
> On Thu, May 26, 2016 at 06:00:25PM +0200, Marek Vasut wrote:
> 
>> 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.
>>
>> Signed-off-by: Marek Vasut <marex@denx.de>
>> Cc: Simon Glass <sjg@chromium.org>
>> Cc: Tom Rini <trini@konsulko.com>
> 
> Reviewed-by: Tom Rini <trini@konsulko.com>
> 
> ... but can you Kconfig this after? :)
> 
I can, but I'd like comments on patch 1/2 . Are you OK with this stuff ?

-- 
Best regards,
Marek Vasut

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 1/2] [RFC] lib: Implement support for tiny sprintf()
  2016-05-30 17:55 ` [U-Boot] [PATCH 1/2] [RFC] lib: Implement support for tiny sprintf() Tom Rini
  2016-05-30 23:30   ` Marek Vasut
@ 2016-05-31 18:19   ` Simon Glass
  2016-05-31 19:36     ` Marek Vasut
  1 sibling, 1 reply; 9+ messages in thread
From: Simon Glass @ 2016-05-31 18:19 UTC (permalink / raw)
  To: u-boot

Hi,

On 31 May 2016 at 05:55, Tom Rini <trini@konsulko.com> wrote:
> On Thu, May 26, 2016 at 06:00:24PM +0200, Marek Vasut wrote:
>
>> 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 <marex@denx.de>
>> Cc: Simon Glass <sjg@chromium.org>
>> Cc: Tom Rini <trini@konsulko.com>
>
> Reviewed-by: Tom Rini <trini@konsulko.com>

Also please see this one:

http://patchwork.ozlabs.org/patch/622267/

It uses a function passed in.

Regards,
Simon

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 1/2] [RFC] lib: Implement support for tiny sprintf()
  2016-05-31 18:19   ` Simon Glass
@ 2016-05-31 19:36     ` Marek Vasut
  2016-05-31 19:51       ` Simon Glass
  0 siblings, 1 reply; 9+ messages in thread
From: Marek Vasut @ 2016-05-31 19:36 UTC (permalink / raw)
  To: u-boot

On 05/31/2016 08:19 PM, Simon Glass wrote:
> Hi,
> 
> On 31 May 2016 at 05:55, Tom Rini <trini@konsulko.com> wrote:
>> On Thu, May 26, 2016 at 06:00:24PM +0200, Marek Vasut wrote:
>>
>>> 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 <marex@denx.de>
>>> Cc: Simon Glass <sjg@chromium.org>
>>> Cc: Tom Rini <trini@konsulko.com>
>>
>> Reviewed-by: Tom Rini <trini@konsulko.com>
> 
> 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 :)

-- 
Best regards,
Marek Vasut

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [U-Boot] [PATCH 1/2] [RFC] lib: Implement support for tiny sprintf()
  2016-05-31 19:36     ` Marek Vasut
@ 2016-05-31 19:51       ` Simon Glass
  0 siblings, 0 replies; 9+ messages in thread
From: Simon Glass @ 2016-05-31 19:51 UTC (permalink / raw)
  To: u-boot

Hi Marek,

On 1 June 2016 at 07:36, Marek Vasut <marex@denx.de> wrote:
> On 05/31/2016 08:19 PM, Simon Glass wrote:
>> Hi,
>>
>> On 31 May 2016 at 05:55, Tom Rini <trini@konsulko.com> wrote:
>>> On Thu, May 26, 2016 at 06:00:24PM +0200, Marek Vasut wrote:
>>>
>>>> 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 <marex@denx.de>
>>>> Cc: Simon Glass <sjg@chromium.org>
>>>> Cc: Tom Rini <trini@konsulko.com>
>>>
>>> Reviewed-by: Tom Rini <trini@konsulko.com>
>>
>> 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-05-31 19:51 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-26 16:00 [U-Boot] [PATCH 1/2] [RFC] lib: Implement support for tiny sprintf() Marek Vasut
2016-05-26 16:00 ` [U-Boot] [PATCH 2/2] [RFC] ARM: omap: Enable tiny printf/sprintf on omap3_logic Marek Vasut
2016-05-30 17:55   ` Tom Rini
2016-05-30 23:31     ` Marek Vasut
2016-05-30 17:55 ` [U-Boot] [PATCH 1/2] [RFC] lib: Implement support for tiny sprintf() Tom Rini
2016-05-30 23:30   ` Marek Vasut
2016-05-31 18:19   ` Simon Glass
2016-05-31 19:36     ` Marek Vasut
2016-05-31 19:51       ` Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.