All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] SPL: tiny-printf: avoid any BSS usage
@ 2016-07-03 23:56 Andre Przywara
  2016-07-04 12:30 ` Marek Vasut
  2016-07-05 10:17 ` Vignesh R
  0 siblings, 2 replies; 4+ messages in thread
From: Andre Przywara @ 2016-07-03 23:56 UTC (permalink / raw)
  To: u-boot

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@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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH] SPL: tiny-printf: avoid any BSS usage
  2016-07-03 23:56 [U-Boot] [PATCH] SPL: tiny-printf: avoid any BSS usage Andre Przywara
@ 2016-07-04 12:30 ` Marek Vasut
  2016-07-04 17:05   ` Tom Rini
  2016-07-05 10:17 ` Vignesh R
  1 sibling, 1 reply; 4+ messages in thread
From: Marek Vasut @ 2016-07-04 12:30 UTC (permalink / raw)
  To: u-boot

On 07/04/2016 01:56 AM, Andre Przywara wrote:
> 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@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")))

Please don't introduce new macros, it's really not necessary here, the 
comment is enough.

> +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)
>  {
>


-- 
Best regards,
Marek Vasut

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH] SPL: tiny-printf: avoid any BSS usage
  2016-07-04 12:30 ` Marek Vasut
@ 2016-07-04 17:05   ` Tom Rini
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Rini @ 2016-07-04 17:05 UTC (permalink / raw)
  To: u-boot

On Mon, Jul 04, 2016 at 02:30:20PM +0200, Marek Vasut wrote:
> On 07/04/2016 01:56 AM, Andre Przywara wrote:
> >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@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")))
> 
> Please don't introduce new macros, it's really not necessary here,
> the comment is enough.

And would also match the other areas where we have to do something
"ugly" like this in order to function within constraints.  Frankly, I
don't see this exactly as a hack, but it should be tested on a few more
platforms just to be safe.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160704/4a24901a/attachment.sig>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH] SPL: tiny-printf: avoid any BSS usage
  2016-07-03 23:56 [U-Boot] [PATCH] SPL: tiny-printf: avoid any BSS usage Andre Przywara
  2016-07-04 12:30 ` Marek Vasut
@ 2016-07-05 10:17 ` Vignesh R
  1 sibling, 0 replies; 4+ messages in thread
From: Vignesh R @ 2016-07-05 10:17 UTC (permalink / raw)
  To: u-boot



On Monday 04 July 2016 05:26 AM, Andre Przywara wrote:
> 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@arm.com>
> ---

There is atleast one place where I encountered same issue:
drivers/i2c/i2c-uclass-compact.c:
static int cur_busnum;

I could verify that the below macro helps in that case as well.


> 
>  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)
>  {
> 

-- 
Regards
Vignesh

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-07-05 10:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-03 23:56 [U-Boot] [PATCH] SPL: tiny-printf: avoid any BSS usage Andre Przywara
2016-07-04 12:30 ` Marek Vasut
2016-07-04 17:05   ` Tom Rini
2016-07-05 10:17 ` Vignesh R

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.