U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@arm.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2] SPL: tiny-printf: avoid any BSS usage
Date: Fri,  8 Jul 2016 15:18:35 +0100	[thread overview]
Message-ID: <1467987515-2794-1-git-send-email-andre.przywara@arm.com> (raw)

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>
---
Changes v1 .. v2:
- remove NO_BSS macro, use __attribute__ ... directly instead

 lib/tiny-printf.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
index 451f4f7..b334f05 100644
--- a/lib/tiny-printf.c
+++ b/lib/tiny-printf.c
@@ -13,11 +13,16 @@
 #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.
+ */
+static char *bf __attribute__ ((section(".data")));
+static char zs __attribute__ ((section(".data")));
 
 /* Current position in sprintf() output string */
-static char *outstr;
+static char *outstr __attribute__ ((section(".data")));
 
 static void out(char c)
 {
-- 
2.8.2

             reply	other threads:[~2016-07-08 14:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-08 14:18 Andre Przywara [this message]
2016-07-08 16:50 ` [U-Boot] [U-Boot,v2] SPL: tiny-printf: avoid any BSS usage Tom Rini
2016-07-08 21:48   ` Marek Vasut
2016-07-09  0:28     ` Tom Rini
2016-07-09  8:22       ` Marek Vasut
2016-07-09 14:50         ` Tom Rini
2016-07-09 14:38 ` [U-Boot] [PATCH v2] " Simon Glass
2016-07-09 15:16   ` Marek Vasut
2016-07-09 17:27   ` André Przywara
2016-08-06  0:11     ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1467987515-2794-1-git-send-email-andre.przywara@arm.com \
    --to=andre.przywara@arm.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox