mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Peter Mamonov <pmamonov@gmail.com>
To: o.rempel@pengutronix.de
Cc: barebox@lists.infradead.org, Peter Mamonov <pmamonov@gmail.com>
Subject: [PATCH] MIPS: relocate_code: fix relocation area size
Date: Tue, 28 Jan 2020 20:53:07 +0300	[thread overview]
Message-ID: <20200128175307.13584-1-pmamonov@gmail.com> (raw)

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`.

Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
---
 arch/mips/lib/reloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/lib/reloc.c b/arch/mips/lib/reloc.c
index 32d776a6a6..41e2d5c75f 100644
--- a/arch/mips/lib/reloc.c
+++ b/arch/mips/lib/reloc.c
@@ -121,7 +121,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.24.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2020-01-28 17:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-28 17:53 Peter Mamonov [this message]
2020-01-28 18:29 ` Oleksij Rempel
2020-01-28 20:31   ` Peter Mamonov
2020-01-29  5:20     ` Oleksij Rempel

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=20200128175307.13584-1-pmamonov@gmail.com \
    --to=pmamonov@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=o.rempel@pengutronix.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