All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@arm.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 2/3] spl: add relocation support【请注意,邮件由sjg@google.com代发】
Date: Mon, 20 May 2019 16:58:58 +0100	[thread overview]
Message-ID: <20190520165858.532e6f1e@donnerap.cambridge.arm.com> (raw)
In-Reply-To: <99b9d595-7d1e-4cb5-63bf-12826570a0d7@rock-chips.com>

On Mon, 20 May 2019 14:34:01 +0800
Andy Yan <andy.yan@rock-chips.com> wrote:

Hi,

> On 2019/5/19 上午12:26, Simon Glass wrote:
> > Hi Andy,
> >
> > Instead of this could you:
> >
> > - move ATF?  
> 
> All rockchip based arm64 ATF run from the start 64KB of dram as this 
> will give convenient for kernel manage the memory.

This is just BL31 of ATF, right?
ATF recently gained PIE support for BL31 [1], so by just enabling this in platform.mk you will get a relocatable BL31 image, with a very minimal runtime linker. Worked out of the box on Allwinner for me, but YMMV.
So you could load newer ATF builds everywhere.

Does that help you?

> On the other hand, change the ATF load address will break the 
> compatibility of the exiting firmware.

I am not sure what you mean with "compatibility of existing firmware"? Surely you combine all the firmware components (SPL/TPL/ATF/U-Boot proper) into one image? And there would be no real mix and match, with older pre-compiled builds? So by changing the ATF base address and the load address in TPL at the same time you won't have issues?

Cheers,
Andre.

[1] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/commit/?id=fc922ca87cc6af8277dc0eb710fc63a2957f0194

> > - change the SPL load address so it is not in the way (since TPL can
> > load to any address)  
> 
> The SPL is loaded by bootrom after TPL back to bootrom, so the load 
> address if fixed by bootrom code.
> 
> I know we can build mmc or other storage driver into TPL so we can use 
> tpl load spl on some platform that sram is big enough, but there are 
> also many rockchip soc has very small sram, so we tend to only do dram  
> initialization in tpl, and let bootrom load next stage .
> 
> > - (in extremis) create a function which does a memmove() and a jump,
> > copy it somewhere and run it (I think x86 does this)
> >
> > Regards,
> > Simon
> >
> > On Thu, 16 May 2019 at 06:22, Andy Yan <andy.yan@rock-chips.com> wrote:  
> >> Some times we want to relocate spl code to dram after dram
> >> initialization or relocate spl code to a high memory to avoid
> >> code overid.
> >>
> >> For example on Rockchip armv8 platform, we run with boot flow
> >> TPL->SPL->ATF->U-Boot.
> >> TPL run in sram and is responsible for dram initialization.
> >> SPL run from the start address of dram and is responsible for
> >> loading ATF and U-Boot.
> >>
> >> The case here is that the ATF load address is from 64KB of dram,
> >> which overlaps with spl code itself.
> >>
> >> So we want to relocate spl itself to high memory to aovid this.
> >>
> >> Signed-off-by: Andy Yan <andy.yan@rock-chips.com>
> >> ---
> >>
> >> Changes in v2:
> >> - Move Kconfig modification to PATCH 1/3
> >>
> >>   common/spl/spl.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++
> >>   1 file changed, 55 insertions(+)
> >>
> >> diff --git a/common/spl/spl.c b/common/spl/spl.c
> >> index 88d4b8a9bf..affb65ccbd 100644
> >> --- a/common/spl/spl.c
> >> +++ b/common/spl/spl.c
> >> @@ -12,6 +12,7 @@
> >>   #include <dm.h>
> >>   #include <handoff.h>
> >>   #include <spl.h>
> >> +#include <asm/sections.h>
> >>   #include <asm/u-boot.h>
> >>   #include <nand.h>
> >>   #include <fat.h>
> >> @@ -439,6 +440,28 @@ static int spl_common_init(bool setup_malloc)
> >>          return 0;
> >>   }
> >>
> >> +#if !defined(CONFIG_SPL_SKIP_RELOCATE) && !defined(CONFIG_TPL_BUILD)
> >> +static void spl_setup_relocate(void)
> >> +{
> >> +       gd->relocaddr = CONFIG_SPL_RELOC_TEXT_BASE;
> >> +       gd->new_gd = (gd_t *)gd;
> >> +       gd->start_addr_sp = gd->relocaddr;
> >> +       gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
> >> +
> >> +       gd->start_addr_sp -= gd->fdt_size;
> >> +       gd->new_fdt = (void *)gd->start_addr_sp;
> >> +       memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
> >> +       gd->fdt_blob = gd->new_fdt;
> >> +
> >> +       gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start;
> >> +}
> >> +#else
> >> +static void spl_setup_relocate(void)
> >> +{
> >> +
> >> +}
> >> +#endif
> >> +
> >>   void spl_set_bd(void)
> >>   {
> >>          /*
> >> @@ -460,6 +483,8 @@ int spl_early_init(void)
> >>                  return ret;
> >>          gd->flags |= GD_FLG_SPL_EARLY_INIT;
> >>
> >> +       spl_setup_relocate();
> >> +
> >>          return 0;
> >>   }
> >>
> >> @@ -563,6 +588,34 @@ static int boot_from_devices(struct spl_image_info *spl_image,
> >>          return -ENODEV;
> >>   }
> >>
> >> +#if defined(CONFIG_DM) && !defined(CONFIG_SPL_SKIP_RELOCATE) && !defined(CONFIG_TPL_BUILD)
> >> +static int spl_initr_dm(void)
> >> +{
> >> +       int ret;
> >> +
> >> +       /* Save the pre-reloc driver model and start a new one */
> >> +       gd->dm_root_f = gd->dm_root;
> >> +       gd->dm_root = NULL;
> >> +       bootstage_start(BOOTSTATE_ID_ACCUM_DM_R, "dm_r");
> >> +       ret = dm_init_and_scan(false);
> >> +       bootstage_accum(BOOTSTATE_ID_ACCUM_DM_R);
> >> +       if (ret)
> >> +               return ret;
> >> +
> >> +#if defined(CONFIG_TIMER)
> >> +       gd->timer = NULL;
> >> +#endif
> >> +       serial_init();
> >> +
> >> +       return 0;
> >> +}
> >> +#else
> >> +static int spl_initr_dm(void)
> >> +{
> >> +       return 0;
> >> +}
> >> +#endif
> >> +
> >>   void board_init_r(gd_t *dummy1, ulong dummy2)
> >>   {
> >>          u32 spl_boot_list[] = {
> >> @@ -577,6 +630,8 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
> >>  
> >>          debug(">>" SPL_TPL_PROMPT "board_init_r()\n");  
> >>
> >> +       spl_initr_dm();
> >> +
> >>          spl_set_bd();
> >>
> >>   #if defined(CONFIG_SYS_SPL_MALLOC_START)
> >> --
> >> 2.17.1
> >>
> >>
> >>  
> >
> >  
> 
> 

  parent reply	other threads:[~2019-05-20 15:58 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-16 12:19 [U-Boot] [PATCH v2 0/3] Enable spl relocation on arm Andy Yan
2019-05-16 12:21 ` [U-Boot] [PATCH v2 1/3] powerpc: Convert CONFIG_SPL_RELOC_TEXT_BASE to Kconfig Andy Yan
2019-05-16 12:21 ` [U-Boot] [PATCH v2 2/3] spl: add relocation support Andy Yan
2019-05-17  8:34   ` Lukasz Majewski
2019-05-17  9:03     ` Andy Yan
2019-05-18 16:26   ` Simon Glass
2019-05-20  6:34     ` [U-Boot] [PATCH v2 2/3] spl: add relocation support【请注意,邮件由sjg@google.com代发】 Andy Yan
2019-05-20 15:35       ` Simon Glass
2019-05-21  6:50         ` Andy Yan
2019-05-22  0:28           ` Simon Glass
2019-05-22  1:56             ` Andy Yan
2019-05-22 19:39               ` Simon Glass
2019-05-28  8:33                 ` Andy Yan
2019-06-22 19:10                   ` Simon Glass
2019-06-24 10:36                     ` Andy Yan
2019-06-30 13:03                       ` [U-Boot] [PATCH v2 2/3] spl: add relocation support Kever Yang
2019-07-06 17:16                       ` [U-Boot] [PATCH v2 2/3] spl: add relocation support【请注意,邮件由sjg@google.com代发】 Simon Glass
2019-07-07  0:36                         ` Andy Yan
2019-08-13  9:35                           ` Simon Glass
2019-05-20 15:58       ` Andre Przywara [this message]
2019-05-22  1:42         ` Andy Yan
2019-05-22 19:39           ` Simon Glass
2019-05-28  8:47             ` Andy Yan
2019-06-22 19:10               ` Simon Glass
2019-05-16 12:22 ` [U-Boot] [PATCH v2 3/3] arm: add spl relocation support for arm Andy Yan

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=20190520165858.532e6f1e@donnerap.cambridge.arm.com \
    --to=andre.przywara@arm.com \
    --cc=u-boot@lists.denx.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.