linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] MIPS: Allow compressed images to be loaded at the usual address
@ 2017-02-05 20:21 Alban
  2017-02-06  8:52 ` Sergei Shtylyov
  2017-02-09 12:22 ` Jonas Gorski
  0 siblings, 2 replies; 5+ messages in thread
From: Alban @ 2017-02-05 20:21 UTC (permalink / raw)
  To: linux-mips; +Cc: Alban Bedel, Ralf Baechle, Jonas Gorski, linux-kernel

From: Alban Bedel <albeu@free.fr>

Normally compressed images have to be loaded at a different address to
allow the decompressor to run. This add an option to let vmlinuz copy
itself to the correct address from the normal vmlinux address.

Signed-off-by: Alban Bedel <albeu@free.fr>
---
 arch/mips/Kconfig                |  8 ++++++++
 arch/mips/boot/compressed/head.S | 13 +++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index b3c5bde..8074fc5 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -2961,6 +2961,14 @@ choice
 		bool "Extend builtin kernel arguments with bootloader arguments"
 endchoice
 
+config ZBOOT_VMLINUZ_AT_VMLINUX_LOAD_ADDRESS
+	bool "Load compressed images at the same address as uncompressed"
+	depends on SYS_SUPPORTS_ZBOOT
+	help
+	  vmlinux and vmlinuz normally have different load addresses, with
+	  this option vmlinuz expect to be loaded at the same address as
+	  vmlinux.
+
 endmenu
 
 config LOCKDEP_SUPPORT
diff --git a/arch/mips/boot/compressed/head.S b/arch/mips/boot/compressed/head.S
index 409cb48..a215171 100644
--- a/arch/mips/boot/compressed/head.S
+++ b/arch/mips/boot/compressed/head.S
@@ -25,6 +25,19 @@ start:
 	move	s2, a2
 	move	s3, a3
 
+#ifdef CONFIG_ZBOOT_VMLINUZ_AT_VMLINUX_LOAD_ADDRESS
+	/* Move the text, data section and DTB to the correct address */
+	PTR_LA	a0, .text
+	PTR_LI	a1, VMLINUX_LOAD_ADDRESS
+	PTR_LA	a2, _edata
+0:
+	lw	a3, 0(a1)
+	sw	a3, 0(a0)
+	addiu	a1, a1, 4
+	bne	a2, a0, 0b
+	 addiu	a0, a0, 4
+#endif
+
 	/* Clear BSS */
 	PTR_LA	a0, _edata
 	PTR_LA	a2, _end
-- 
2.7.4

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

* Re: [PATCH] MIPS: Allow compressed images to be loaded at the usual address
  2017-02-05 20:21 [PATCH] MIPS: Allow compressed images to be loaded at the usual address Alban
@ 2017-02-06  8:52 ` Sergei Shtylyov
  2017-02-09 12:22 ` Jonas Gorski
  1 sibling, 0 replies; 5+ messages in thread
From: Sergei Shtylyov @ 2017-02-06  8:52 UTC (permalink / raw)
  To: Alban, linux-mips; +Cc: Ralf Baechle, Jonas Gorski, linux-kernel

Hello!

On 2/5/2017 11:21 PM, Alban wrote:

> From: Alban Bedel <albeu@free.fr>
>
> Normally compressed images have to be loaded at a different address to
> allow the decompressor to run. This add an option to let vmlinuz copy
> itself to the correct address from the normal vmlinux address.
>
> Signed-off-by: Alban Bedel <albeu@free.fr>
[...]

    Just some grammar nitpicking...

> diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
> index b3c5bde..8074fc5 100644
> --- a/arch/mips/Kconfig
> +++ b/arch/mips/Kconfig
> @@ -2961,6 +2961,14 @@ choice
>  		bool "Extend builtin kernel arguments with bootloader arguments"
>  endchoice
>
> +config ZBOOT_VMLINUZ_AT_VMLINUX_LOAD_ADDRESS
> +	bool "Load compressed images at the same address as uncompressed"
> +	depends on SYS_SUPPORTS_ZBOOT
> +	help
> +	  vmlinux and vmlinuz normally have different load addresses, with
> +	  this option vmlinuz expect to be loaded at the same address as

    Expects.

[...]

MBR, Sergei

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

* Re: [PATCH] MIPS: Allow compressed images to be loaded at the usual address
  2017-02-05 20:21 [PATCH] MIPS: Allow compressed images to be loaded at the usual address Alban
  2017-02-06  8:52 ` Sergei Shtylyov
@ 2017-02-09 12:22 ` Jonas Gorski
  2017-02-13  8:37   ` Alban
  1 sibling, 1 reply; 5+ messages in thread
From: Jonas Gorski @ 2017-02-09 12:22 UTC (permalink / raw)
  To: Alban; +Cc: MIPS Mailing List, Ralf Baechle, linux-kernel

Hi,

On 5 February 2017 at 21:21, Alban <albeu@free.fr> wrote:
> From: Alban Bedel <albeu@free.fr>
>
> Normally compressed images have to be loaded at a different address to
> allow the decompressor to run. This add an option to let vmlinuz copy
> itself to the correct address from the normal vmlinux address.
>
> Signed-off-by: Alban Bedel <albeu@free.fr>
> ---
>  arch/mips/Kconfig                |  8 ++++++++
>  arch/mips/boot/compressed/head.S | 13 +++++++++++++
>  2 files changed, 21 insertions(+)
>
> diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
> index b3c5bde..8074fc5 100644
> --- a/arch/mips/Kconfig
> +++ b/arch/mips/Kconfig
> @@ -2961,6 +2961,14 @@ choice
>                 bool "Extend builtin kernel arguments with bootloader arguments"
>  endchoice
>
> +config ZBOOT_VMLINUZ_AT_VMLINUX_LOAD_ADDRESS
> +       bool "Load compressed images at the same address as uncompressed"
> +       depends on SYS_SUPPORTS_ZBOOT
> +       help
> +         vmlinux and vmlinuz normally have different load addresses, with
> +         this option vmlinuz expect to be loaded at the same address as
> +         vmlinux.
> +
>  endmenu

Okay, it took me a while to understand the intention of this change. I
thought it was for supporting the case that VMLINUZ_LOAD_ADDRESS ==
VMLINUX_LOAD_ADDRESS, but it is indented for  VMLINUZ_LOAD_ADDRESS !=
VMLINUX_LOAD_ADDRESS, but still being loaded at VMLINUX_LOAD_ADDRESS.

So I guess that this can only happen with vmlinuz.bin, as vmlinux's
ELF header will cause it to be loaded at the expected address (for
sane bootloaders at least).

>  config LOCKDEP_SUPPORT
> diff --git a/arch/mips/boot/compressed/head.S b/arch/mips/boot/compressed/head.S
> index 409cb48..a215171 100644
> --- a/arch/mips/boot/compressed/head.S
> +++ b/arch/mips/boot/compressed/head.S
> @@ -25,6 +25,19 @@ start:
>         move    s2, a2
>         move    s3, a3
>
> +#ifdef CONFIG_ZBOOT_VMLINUZ_AT_VMLINUX_LOAD_ADDRESS

With a bit of BAL trickery you could easily detect this at runtime and
then conditionally copy without requiring any additional config
symbols. Then you aren't limited to being executed from
VMLINUX_LOAD_ADDRESS.

> +       /* Move the text, data section and DTB to the correct address */
> +       PTR_LA  a0, .text
> +       PTR_LI  a1, VMLINUX_LOAD_ADDRESS
> +       PTR_LA  a2, _edata
> +0:
> +       lw      a3, 0(a1)
> +       sw      a3, 0(a0)
> +       addiu   a1, a1, 4
> +       bne     a2, a0, 0b
> +        addiu  a0, a0, 4
> +#endif
> +
>         /* Clear BSS */
>         PTR_LA  a0, _edata
>         PTR_LA  a2, _end

Regards
Jonas

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

* Re: [PATCH] MIPS: Allow compressed images to be loaded at the usual address
  2017-02-09 12:22 ` Jonas Gorski
@ 2017-02-13  8:37   ` Alban
  2017-02-13 10:52     ` Jonas Gorski
  0 siblings, 1 reply; 5+ messages in thread
From: Alban @ 2017-02-13  8:37 UTC (permalink / raw)
  To: Jonas Gorski; +Cc: Aban Bedel, MIPS Mailing List, Ralf Baechle, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2816 bytes --]

On Thu, 9 Feb 2017 13:22:37 +0100
Jonas Gorski <jonas.gorski@gmail.com> wrote:

> Hi,
> 
> On 5 February 2017 at 21:21, Alban <albeu@free.fr> wrote:
> > From: Alban Bedel <albeu@free.fr>
> >
> > Normally compressed images have to be loaded at a different address to
> > allow the decompressor to run. This add an option to let vmlinuz copy
> > itself to the correct address from the normal vmlinux address.
> >
> > Signed-off-by: Alban Bedel <albeu@free.fr>
> > ---
> >  arch/mips/Kconfig                |  8 ++++++++
> >  arch/mips/boot/compressed/head.S | 13 +++++++++++++
> >  2 files changed, 21 insertions(+)
> >
> > diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
> > index b3c5bde..8074fc5 100644
> > --- a/arch/mips/Kconfig
> > +++ b/arch/mips/Kconfig
> > @@ -2961,6 +2961,14 @@ choice
> >                 bool "Extend builtin kernel arguments with bootloader arguments"
> >  endchoice
> >
> > +config ZBOOT_VMLINUZ_AT_VMLINUX_LOAD_ADDRESS
> > +       bool "Load compressed images at the same address as uncompressed"
> > +       depends on SYS_SUPPORTS_ZBOOT
> > +       help
> > +         vmlinux and vmlinuz normally have different load addresses, with
> > +         this option vmlinuz expect to be loaded at the same address as
> > +         vmlinux.
> > +
> >  endmenu  
> 
> Okay, it took me a while to understand the intention of this change. I
> thought it was for supporting the case that VMLINUZ_LOAD_ADDRESS ==
> VMLINUX_LOAD_ADDRESS, but it is indented for  VMLINUZ_LOAD_ADDRESS !=
> VMLINUX_LOAD_ADDRESS, but still being loaded at VMLINUX_LOAD_ADDRESS.
> 
> So I guess that this can only happen with vmlinuz.bin, as vmlinux's
> ELF header will cause it to be loaded at the expected address (for
> sane bootloaders at least).

Yes, this is for bootloaders that use raw images. Having to configure
different load addresses for compressed and uncompressed images was just
too annoying.

> >  config LOCKDEP_SUPPORT
> > diff --git a/arch/mips/boot/compressed/head.S b/arch/mips/boot/compressed/head.S
> > index 409cb48..a215171 100644
> > --- a/arch/mips/boot/compressed/head.S
> > +++ b/arch/mips/boot/compressed/head.S
> > @@ -25,6 +25,19 @@ start:
> >         move    s2, a2
> >         move    s3, a3
> >
> > +#ifdef CONFIG_ZBOOT_VMLINUZ_AT_VMLINUX_LOAD_ADDRESS  
> 
> With a bit of BAL trickery you could easily detect this at runtime and
> then conditionally copy without requiring any additional config
> symbols. Then you aren't limited to being executed from
> VMLINUX_LOAD_ADDRESS.

Could you expand a bit on what you mean with "BAL trickery"? I hoped
that it would be possible to auto detect the current running address,
but as I know very little about MIPS assembly I didn't found how that
could be done.

Alban

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH] MIPS: Allow compressed images to be loaded at the usual address
  2017-02-13  8:37   ` Alban
@ 2017-02-13 10:52     ` Jonas Gorski
  0 siblings, 0 replies; 5+ messages in thread
From: Jonas Gorski @ 2017-02-13 10:52 UTC (permalink / raw)
  To: Alban; +Cc: MIPS Mailing List, Ralf Baechle, linux-kernel

Hi,

On 13 February 2017 at 09:37, Alban <albeu@free.fr> wrote:
> On Thu, 9 Feb 2017 13:22:37 +0100
> Jonas Gorski <jonas.gorski@gmail.com> wrote:
>
>> Hi,
>>
>> On 5 February 2017 at 21:21, Alban <albeu@free.fr> wrote:
>> > From: Alban Bedel <albeu@free.fr>
>> >
>> > Normally compressed images have to be loaded at a different address to
>> > allow the decompressor to run. This add an option to let vmlinuz copy
>> > itself to the correct address from the normal vmlinux address.
>> >
>> > Signed-off-by: Alban Bedel <albeu@free.fr>
>> > ---
>> >  arch/mips/Kconfig                |  8 ++++++++
>> >  arch/mips/boot/compressed/head.S | 13 +++++++++++++
>> >  2 files changed, 21 insertions(+)
>> >
>> > diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
>> > index b3c5bde..8074fc5 100644
>> > --- a/arch/mips/Kconfig
>> > +++ b/arch/mips/Kconfig
>> > @@ -2961,6 +2961,14 @@ choice
>> >                 bool "Extend builtin kernel arguments with bootloader arguments"
>> >  endchoice
>> >
>> > +config ZBOOT_VMLINUZ_AT_VMLINUX_LOAD_ADDRESS
>> > +       bool "Load compressed images at the same address as uncompressed"
>> > +       depends on SYS_SUPPORTS_ZBOOT
>> > +       help
>> > +         vmlinux and vmlinuz normally have different load addresses, with
>> > +         this option vmlinuz expect to be loaded at the same address as
>> > +         vmlinux.
>> > +
>> >  endmenu
>>
>> Okay, it took me a while to understand the intention of this change. I
>> thought it was for supporting the case that VMLINUZ_LOAD_ADDRESS ==
>> VMLINUX_LOAD_ADDRESS, but it is indented for  VMLINUZ_LOAD_ADDRESS !=
>> VMLINUX_LOAD_ADDRESS, but still being loaded at VMLINUX_LOAD_ADDRESS.
>>
>> So I guess that this can only happen with vmlinuz.bin, as vmlinux's
>> ELF header will cause it to be loaded at the expected address (for
>> sane bootloaders at least).
>
> Yes, this is for bootloaders that use raw images. Having to configure
> different load addresses for compressed and uncompressed images was just
> too annoying.
>
>> >  config LOCKDEP_SUPPORT
>> > diff --git a/arch/mips/boot/compressed/head.S b/arch/mips/boot/compressed/head.S
>> > index 409cb48..a215171 100644
>> > --- a/arch/mips/boot/compressed/head.S
>> > +++ b/arch/mips/boot/compressed/head.S
>> > @@ -25,6 +25,19 @@ start:
>> >         move    s2, a2
>> >         move    s3, a3
>> >
>> > +#ifdef CONFIG_ZBOOT_VMLINUZ_AT_VMLINUX_LOAD_ADDRESS
>>
>> With a bit of BAL trickery you could easily detect this at runtime and
>> then conditionally copy without requiring any additional config
>> symbols. Then you aren't limited to being executed from
>> VMLINUX_LOAD_ADDRESS.
>
> Could you expand a bit on what you mean with "BAL trickery"? I hoped
> that it would be possible to auto detect the current running address,
> but as I know very little about MIPS assembly I didn't found how that
> could be done.

With BAL (branch and link) you can do a pc-relative jump, and the
current address will be stored in $ra. comparing it with the expected
address will give you the offset by which you were loaded. To quote
the lzma-loader from OpenWrt/Lede[1]:

        la      t0, __reloc_label       # get linked address of label
        bal     __reloc_label           # branch and link to label to
        nop                             # get actual address
__reloc_label:
        subu    t0, ra, t0              # get reloc_delta
        beqz    t0, __reloc_done         # if delta is 0 we are in the
right place
        nop

        /* Copy our code to the right place */
        la      t1, _code_start         # get linked address of _code_start
        la      t2, _code_end           # get linked address of _code_end
        addu    t0, t0, t1              # calculate actual address of
_code_start

__reloc_copy:
...
__reloc_done:
...


Regards
Jonas

[1] https://git.lede-project.org/?p=source.git;a=blob;f=target/linux/ar71xx/image/lzma-loader/src/head.S;h=47a7c9bd6300ad92e6a0d426c5f44bc0f3e7e85f;hb=HEAD#l49

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

end of thread, other threads:[~2017-02-13 10:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-05 20:21 [PATCH] MIPS: Allow compressed images to be loaded at the usual address Alban
2017-02-06  8:52 ` Sergei Shtylyov
2017-02-09 12:22 ` Jonas Gorski
2017-02-13  8:37   ` Alban
2017-02-13 10:52     ` Jonas Gorski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).