瀏覽代碼

SPL: tiny-printf: avoid any BSS usage

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.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Andre Przywara 8 年之前
父節點
當前提交
59d07ee08e
共有 1 個文件被更改,包括 8 次插入3 次删除
  1. 8 3
      lib/tiny-printf.c

+ 8 - 3
lib/tiny-printf.c

@@ -13,11 +13,16 @@
 #include <stdarg.h>
 #include <stdarg.h>
 #include <serial.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.
+ */
+static char *bf __attribute__ ((section(".data")));
+static char zs __attribute__ ((section(".data")));
 
 
 /* Current position in sprintf() output string */
 /* Current position in sprintf() output string */
-static char *outstr;
+static char *outstr __attribute__ ((section(".data")));
 
 
 static void out(char c)
 static void out(char c)
 {
 {