[U-Boot] [PATCH v2 2/3] spl: add relocation support【请注意,邮件由sjg at google.com代发】

Andy Yan andy.yan at rock-chips.com
Tue May 21 06:50:38 UTC 2019


Hi Simon:

On 2019/5/20 下午11:35, Simon Glass wrote:
> Hi Andy,
>
> On Mon, 20 May 2019 at 00:34, Andy Yan <andy.yan at rock-chips.com> wrote:
>> Hi Simon:
>>
>> 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.
>>
>> On the other hand, change the ATF load address will break the
>> compatibility of the exiting firmware.
>>
>>> - 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 think you are creating a nightmare here. If you have to do things
> like this for older and smaller SoCs, OK. But it should not be used
> for newer ones that can do things properly.


Most rockchip based SOC sram is small,  even in the future soc roadmap, 
this situation  will still exist, larger sram means more cost.

As for the current spl for rockchip soc in mainline, we use a workaround 
by reserve large space at the head of spl(see 
CONFIG_ROCKCHIP_SPL_RESERVE_IRAM ), this generate a very large spl binary.

As for my patch, the spl relocation is disabled default, we only enable 
it on necessary platform, so it won't hurt others .

> The bootrom has so many limitations that it just creates pain.
>
>> 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 .
> See above
>
For the consideration of software development, we also want to keep TPL 
clean,  only do dram initialization(as it current status), this make our 
internal dram team work more simple, they don't need to care about other 
modules like mmc.


>>> - (in extremis) create a function which does a memmove() and a jump,
>>> copy it somewhere and run it (I think x86 does this)
> ?
I am not very understand about this, just a memmove may not work, we 
need to link the code by pie, and fix the rela.dyn sections after copy. 
see arm/relocate_64.S
>
> - Simon
>
>>> Regards,
>>> Simon
>>>
>>> On Thu, 16 May 2019 at 06:22, Andy Yan <andy.yan at 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 at 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
>>>>
>>>>
>>>>
>>>
>>
>
>




More information about the U-Boot mailing list