[PATCH 1/2] printf: Hack to support gcc printf() optimization

Christian Vogel vogelchr at vogel.cx
Sat Jan 28 20:40:30 UTC 2012


gcc optimizes printf("x") to putchar('x'), but we #define
putchar to be something else.

Now lib/printf.c defines a putchar() function that always prints
on the sercomm port, it will break uart consoles.
---
 src/target/firmware/lib/printf.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/src/target/firmware/lib/printf.c b/src/target/firmware/lib/printf.c
index a4fc687..887b5b4 100644
--- a/src/target/firmware/lib/printf.c
+++ b/src/target/firmware/lib/printf.c
@@ -17,3 +17,19 @@ int printf(const char *fmt, ...)
 
 	return r;
 }
+
+/* HACK: we define putchar to be sercomm_putchar,
+ * but gcc optimizes printf("x") to putchar('x')
+ * so it will generate a call to the function putchar().
+ *
+ * Note: This will break non-sercomm consoles!
+ */
+
+#ifdef putchar
+#undef putchar
+
+int putchar(char c){
+	return sercomm_putchar(c);
+}
+
+#endif
-- 
1.7.0.4





More information about the baseband-devel mailing list