[U-Boot] [PATCH] SPL: tiny-printf: avoid any BSS usage
Andre Przywara
andre.przywara at arm.com
Mon Jul 4 01:56:46 CEST 2016
As printf calls may be executed quite early, we should avoid using any
BSS stored variables, since some boards put BSS in DRAM, which may not
have been initialised yet.
Explicitly mark those "static global" variables as belonging to the
.data section, to keep tiny-printf clear of any BSS usage.
Please note that this is quite a hack (which may need to be extended to
other source files) and more sustainable solutions are warmly welcomed.
Signed-off-by: Andre Przywara <andre.przywara at arm.com>
---
Hi,
as mentioned before I don't like this hack very much, but as this fixes
the WIP Pine64 SPL code I propose this solution for 2016.07.
Cheers,
Andre
lib/tiny-printf.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
index 451f4f7..bc2995b 100644
--- a/lib/tiny-printf.c
+++ b/lib/tiny-printf.c
@@ -13,11 +13,18 @@
#include <stdarg.h>
#include <serial.h>
-static char *bf;
-static char zs;
+/*
+ * This code in here may execute before the DRAM is initialised, so
+ * we should make sure that it doesn't touch BSS, which some boards
+ * put in DRAM.
+ */
+#define NO_BSS __attribute__((section(".data")))
+
+static char *bf NO_BSS;
+static char zs NO_BSS;
/* Current position in sprintf() output string */
-static char *outstr;
+static char *outstr NO_BSS;
static void out(char c)
{
--
2.8.2
More information about the U-Boot
mailing list