* [PATCH v4] MIPS: don't overlay relocation data with BSS
@ 2020-01-30 7:38 Oleksij Rempel
2020-02-03 8:18 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Oleksij Rempel @ 2020-01-30 7:38 UTC (permalink / raw)
To: antonynpavlov, barebox; +Cc: Oleksij Rempel, Peter Mamonov
.bss __rel_start (OVERLAY) was used to optimize RAM size used by
barebox. Since .bss and __rel_start overlap, we should clear bss only
after __rel_start was used. Following patch changed initialization
sequence to clear .bss before __rel_start:
1e5aef61fc6a444 ("MIPS: reloc: init bss and cpu")
This make relocation buffer unusable and broke relocation with different
symptoms reported by Antony Pavlov <antonynpavlov@gmail.com>:
* iomem output has no information on sdram regions, so memtest is unusable;
* pc = 0xa081232c, relocation does not work, barebox is located with 8M offset
from start of RAM. The board has 256M and relocation routine
should move barebox code much higher;
* pc = 0xa081232c, so barebox code works from KSEG1 not from KSEG0 as MMU=y option implies.
There is a choice of moving .bss clear sequence after __rel_start or
remove this optimization. Since the use of this optimization is minimal
and danger to trap in to similar issue is still high, i prefer to remove
this optimization.
As result of this change, we need to fix calculation of relocation are
size:
relocate_code() calculates relocation area size as a sum (barebox_image_size +
bss_len). barebox_image_size and bss_len are calculated as (__image_end -
__image_start) and (__bss_stop - __bss_start) respectively. This doesn't take
into account relocation data placed between __image_end and __bss_start.
However relocation preserves BSS position relative to image start, as if
relocation data is still there. This causes RAM overflow during BSS
initialization in main_entry(). This problem may be hidden due to the alignment
of the `relocaddr`.
Reported-by: Antony Pavlov <antonynpavlov@gmail.com>
Fixes: 1e5aef61fc6a444 ("MIPS: reloc: init bss and cpu")
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
---
arch/mips/lib/barebox.lds.S | 2 +-
arch/mips/lib/reloc.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/mips/lib/barebox.lds.S b/arch/mips/lib/barebox.lds.S
index 693a778980..c954df41f3 100644
--- a/arch/mips/lib/barebox.lds.S
+++ b/arch/mips/lib/barebox.lds.S
@@ -59,7 +59,7 @@ SECTIONS
_end = .;
- .bss __rel_start (OVERLAY) : {
+ .bss : {
__bss_start = .;
*(.sbss.*)
*(.bss.*)
diff --git a/arch/mips/lib/reloc.c b/arch/mips/lib/reloc.c
index df9760e38c..4b0e252352 100644
--- a/arch/mips/lib/reloc.c
+++ b/arch/mips/lib/reloc.c
@@ -118,7 +118,7 @@ void relocate_code(void *fdt, u32 fdt_size, u32 ram_size)
memset(__bss_start, 0, bss_len);
cpu_probe();
- length = barebox_image_size + bss_len;
+ length = __bss_stop - __image_start;
relocaddr = ALIGN_DOWN(ram_size - length, SZ_64K);
relocaddr = KSEG0ADDR(relocaddr);
new_stack = relocaddr - MALLOC_SIZE - 16;
--
2.25.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v4] MIPS: don't overlay relocation data with BSS
2020-01-30 7:38 [PATCH v4] MIPS: don't overlay relocation data with BSS Oleksij Rempel
@ 2020-02-03 8:18 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2020-02-03 8:18 UTC (permalink / raw)
To: Oleksij Rempel; +Cc: barebox, Peter Mamonov
On Thu, Jan 30, 2020 at 08:38:57AM +0100, Oleksij Rempel wrote:
> .bss __rel_start (OVERLAY) was used to optimize RAM size used by
> barebox. Since .bss and __rel_start overlap, we should clear bss only
> after __rel_start was used. Following patch changed initialization
> sequence to clear .bss before __rel_start:
> 1e5aef61fc6a444 ("MIPS: reloc: init bss and cpu")
>
> This make relocation buffer unusable and broke relocation with different
> symptoms reported by Antony Pavlov <antonynpavlov@gmail.com>:
> * iomem output has no information on sdram regions, so memtest is unusable;
> * pc = 0xa081232c, relocation does not work, barebox is located with 8M offset
> from start of RAM. The board has 256M and relocation routine
> should move barebox code much higher;
> * pc = 0xa081232c, so barebox code works from KSEG1 not from KSEG0 as MMU=y option implies.
>
> There is a choice of moving .bss clear sequence after __rel_start or
> remove this optimization. Since the use of this optimization is minimal
> and danger to trap in to similar issue is still high, i prefer to remove
> this optimization.
>
> As result of this change, we need to fix calculation of relocation are
> size:
> relocate_code() calculates relocation area size as a sum (barebox_image_size +
> bss_len). barebox_image_size and bss_len are calculated as (__image_end -
> __image_start) and (__bss_stop - __bss_start) respectively. This doesn't take
> into account relocation data placed between __image_end and __bss_start.
> However relocation preserves BSS position relative to image start, as if
> relocation data is still there. This causes RAM overflow during BSS
> initialization in main_entry(). This problem may be hidden due to the alignment
> of the `relocaddr`.
>
> Reported-by: Antony Pavlov <antonynpavlov@gmail.com>
> Fixes: 1e5aef61fc6a444 ("MIPS: reloc: init bss and cpu")
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
> ---
> arch/mips/lib/barebox.lds.S | 2 +-
> arch/mips/lib/reloc.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
Applied, thanks
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-02-03 8:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-30 7:38 [PATCH v4] MIPS: don't overlay relocation data with BSS Oleksij Rempel
2020-02-03 8:18 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox