mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alban <albeu@free.fr>
To: linux-mips@linux-mips.org
Cc: Alban Bedel <albeu@free.fr>, Ralf Baechle <ralf@linux-mips.org>,
	Jonas Gorski <jogo@openwrt.org>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2] MIPS: Allow compressed images to be loaded at any address
Date: Mon, 13 Feb 2017 21:38:08 +0100	[thread overview]
Message-ID: <1487018290-10451-1-git-send-email-albeu@free.fr> (raw)

From: Alban Bedel <albeu@free.fr>

Compressed images (vmlinuz.bin) have to be loaded at a specific
address that differ from the address normaly used for vmlinux.bin.
This is because the decompressor just write its output at the address
vmlinux.bin should be loaded at, and it shouldn't overwrite itself.
This limitation mean that the bootloader must be configured differently
when loading a vmlinux.bin or a vmlinuz.bin image, this is annoying
and a source of error.

To workaround this we extend the compressed loader to cope with being
loaded at (nearly) any address. During the early init a jump is used
to compute the offset between the current address and the linked
address, if they differ the whole image is first copied to the linked
address before proceeding.

Some load address won't work, for example if there is an overlap with
the range where vmlinuz.bin should be loaded. However for the typical
case of using the vmlinux.bin address that won't be the case.

Signed-off-by: Alban Bedel <albeu@free.fr>
Suggested-by: Jonas Gorski <jonas.gorski@gmail.com>
---
Changelog:
v2: * Rework the code as suggested by Jonas Gorski to autodetect the
      load address and remove the need for a Kconfig option.
---
 arch/mips/boot/compressed/head.S | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/arch/mips/boot/compressed/head.S b/arch/mips/boot/compressed/head.S
index 409cb48..3c25a96 100644
--- a/arch/mips/boot/compressed/head.S
+++ b/arch/mips/boot/compressed/head.S
@@ -25,6 +25,29 @@ start:
 	move	s2, a2
 	move	s3, a3
 
+	/* Get the offset between the current address and linked address */
+	PTR_LA	t0, reloc_label
+	bal	reloc_label
+	 nop
+reloc_label:
+	subu	t0, ra, t0
+
+	/* If there is no offset no reloc is needed */
+	beqz	t0, clear_bss
+	 nop
+
+	/* Move the text, data section and DTB to the correct address */
+	PTR_LA	a0, .text
+	addu	a1, t0, a0
+	PTR_LA	a2, _edata
+copy_vmlinuz:
+	lw	a3, 0(a1)
+	sw	a3, 0(a0)
+	addiu	a0, a0, 4
+	bne	a2, a0, copy_vmlinuz
+	 addiu	a1, a1, 4
+
+clear_bss:
 	/* Clear BSS */
 	PTR_LA	a0, _edata
 	PTR_LA	a2, _end
-- 
2.7.4

             reply	other threads:[~2017-02-13 20:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-13 20:38 Alban [this message]
2017-02-13 22:19 ` James Hogan
2018-03-12 18:02   ` Alban

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=1487018290-10451-1-git-send-email-albeu@free.fr \
    --to=albeu@free.fr \
    --cc=jogo@openwrt.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=ralf@linux-mips.org \
    /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

all inboxes | Powered by JetHome®