Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1579609

Re: [PATCH] MIPS: Allow compressed images to be loaded at the usual address

Path csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!bofh.it!news.nic.it!robomod
From Jonas Gorski <jonas.gorski@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH] MIPS: Allow compressed images to be loaded at the usual address
Date Mon, 13 Feb 2017 12:00:01 +0100
Message-ID <tamwp-2Cb-3@gated-at.bofh.it> (permalink)
References <t7BBG-3FO-81@gated-at.bofh.it> <t8W1k-66e-11@gated-at.bofh.it> <takkW-1fk-3@gated-at.bofh.it>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=uZ6PniQpfSZgOeLcsrSnsls7R+T8+13NnD9paj4GZf4=; b=U5ZoWZGM5WYQ0ASMkoxy5zdmUXfOvSEDQDZibs8zTcTVR8brPc5z0AKRkCLwzi3dm4 /baOGfUrc5acDT2FDWGAsWAyb3JSi2wSH6BnfKOi0gkyguScz05HjPGvkbRU+I9M7ZAk vtws+u6mdUhPoL69nLUooB0Cn322kJgMaOxzsPj7j4CktmwcgTxlH+P564JmL8ZOiC7J XMyTJ6iTnYPSe53pSn7TkKmKv3gFRF2f+PdgbvqgfCWG12UyXMKh5oAuI5/S2OjLvcFc hHY1MDbsxVAWsYQtewk9MVDGQZr0v2IhnJ8ubs8Tvx5J+CEN/PvoJo0Q3TgBzL79d7JN JTTg==
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=uZ6PniQpfSZgOeLcsrSnsls7R+T8+13NnD9paj4GZf4=; b=MMFaK6Stp1CuP4Inknr9kAww9RuVLn1w0c50m62kPv24+fNlG6Qx8woJdJxosV0t5S JTNESBSVcMDylFkw7EX2VjN/5XaXzCwk91Mf6VeSI32KTTqikZ5PbMK2K+XxnHhTVLDm eXmO+i0n68dAhFjpxb+twcvi4TD17iMMi6qFmjmGannip7itOb+BJWcvQhPdBeYMvf5P 2c5yw0Me4hOnAq7PjHd025eu+jD0sY95yA0Bco8sOxWE4dpAh/fvbXOELcojbYUaUk/P aIiC9J3/xM9Lofl8+40ExFHqwLjFnH02g/jRTB9dgFXO9dY1jQwhVAtu5LWxgYcdDXVK qZgg==
X-Gm-Message-State AMke39na1DQ45JkwajSaugfWAgyYoqJTJ/+mEHRgD4vyADbJUSgQWOFQQXCqC8KPKUaVLSHfTjp1G+qD3KnynQ==
X-Received by 10.31.208.133 with SMTP id h127mr11323192vkg.96.1486983169522; Mon, 13 Feb 2017 02:52:49 -0800 (PST)
MIME-Version 1.0
Content-Type text/plain; charset=UTF-8
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 103
Organization linux.* mail to news gateway
X-Original-Cc MIPS Mailing List <linux-mips@linux-mips.org>, Ralf Baechle <ralf@linux-mips.org>, "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
X-Original-Date Mon, 13 Feb 2017 11:52:29 +0100
X-Original-Message-ID <CAOiHx=kkE2z9z83ctukh4XpOUpRqRo=mXqia417ABt9jymgCtQ@mail.gmail.com>
X-Original-References <1486326077-17091-1-git-send-email-albeu@free.fr> <CAOiHx=nwBgVnZp1x2TcDVNx1hA2KYwwQnYSbCsCOJpNo-SLJPg@mail.gmail.com> <20170213093736.1ee183f3@tock>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1579609

Show key headers only | View raw


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

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH] MIPS: Allow compressed images to be loaded at the usual address Alban <albeu@free.fr> - 2017-02-05 21:30 +0100
  Re: [PATCH] MIPS: Allow compressed images to be loaded at the usual  address Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2017-02-06 10:00 +0100
  Re: [PATCH] MIPS: Allow compressed images to be loaded at the usual address Jonas Gorski <jonas.gorski@gmail.com> - 2017-02-09 13:30 +0100
    Re: [PATCH] MIPS: Allow compressed images to be loaded at the usual  address Alban <albeu@free.fr> - 2017-02-13 09:40 +0100
      Re: [PATCH] MIPS: Allow compressed images to be loaded at the usual address Jonas Gorski <jonas.gorski@gmail.com> - 2017-02-13 12:00 +0100

csiph-web