From 7d9cde1031040a4931d6e12da7d9767b7e1d85d4 Mon Sep 17 00:00:00 2001 From: Stefan Roese Date: Mon, 23 Nov 2015 07:00:22 +0100 Subject: lib/tiny-printf.c: Add tiny printf function for space limited environments This patch adds a small printf() version that supports all basic formats. Its intented to be used in U-Boot SPL versions on platforms with very limited internal RAM sizes. To enable it, just define CONFIG_USE_TINY_PRINTF in your defconfig. This will result in the SPL using this tiny function and the main U-Boot still using the full-blown printf() function. This code was copied from: http://www.sparetimelabs.com/printfrevisited With mostly only coding style related changes so that its checkpatch clean. The size reduction is about 2.5KiB. Here a comparison for the db-mv784mp-gp (Marvell AXP) SPL: Without this patch: 58963 18536 1928 79427 13643 ./spl/u-boot-spl With this patch: 56542 18536 1956 77034 12cea ./spl/u-boot-spl Note: To make it possible to compile tiny-printf.c instead of vsprintf.c when CONFIG_USE_TINY_PRINTF is defined, the functions printf() and vprintf() are moved from common/console.c into vsprintf.c in this patch. Signed-off-by: Stefan Roese Cc: Simon Glass Cc: Hans de Goede Cc: Tom Rini Cc: Albert Aribaud --- examples/api/libgenwrap.c | 40 ++++------------------------------------ 1 file changed, 4 insertions(+), 36 deletions(-) (limited to 'examples') diff --git a/examples/api/libgenwrap.c b/examples/api/libgenwrap.c index c1afa5bc09..ba51007b14 100644 --- a/examples/api/libgenwrap.c +++ b/examples/api/libgenwrap.c @@ -16,46 +16,14 @@ #include "glue.h" -/* - * printf() and vprintf() are stolen from u-boot/common/console.c - */ -int printf (const char *fmt, ...) -{ - va_list args; - uint i; - char printbuffer[256]; - - va_start (args, fmt); - - /* For this to work, printbuffer must be larger than - * anything we ever want to print. - */ - i = vsprintf (printbuffer, fmt, args); - va_end (args); - - /* Print the string */ - ub_puts (printbuffer); - return i; -} - -int vprintf (const char *fmt, va_list args) +void putc(const char c) { - uint i; - char printbuffer[256]; - - /* For this to work, printbuffer must be larger than - * anything we ever want to print. - */ - i = vsprintf (printbuffer, fmt, args); - - /* Print the string */ - ub_puts (printbuffer); - return i; + ub_putc(c); } -void putc (const char c) +void puts(const char *s) { - ub_putc(c); + ub_puts(s); } void __udelay(unsigned long usec) -- cgit