[U-Boot] [PATCH 5/5] nios2: relocate dtb for separated device tree

Simon Glass sjg at chromium.org
Fri Sep 4 06:09:08 CEST 2015


+Marek

Hi Thomas,

On 3 September 2015 at 21:15, Thomas Chou <thomas at wytron.com.tw> wrote:
> The relocation of nios2 is different. We will need to move
> dtb at the end of u-boot-dtb.bin image away from BSS sections.
> Otherwise it will be zeroed during startup.
>
> Signed-off-by: Thomas Chou <thomas at wytron.com.tw>
> ---
>  arch/nios2/cpu/fdt.c   | 20 +++++++++++++++++++-
>  arch/nios2/cpu/start.S | 10 ++++++++++
>  2 files changed, 29 insertions(+), 1 deletion(-)

Can you help me understand the relocation a bit? There is already code
in board_init_f() to relocate the device tree, and until
board_init_r(), BSS should not be used. What is different about NIOS?

>
> diff --git a/arch/nios2/cpu/fdt.c b/arch/nios2/cpu/fdt.c
> index 79f72aa..83d95ba 100644
> --- a/arch/nios2/cpu/fdt.c
> +++ b/arch/nios2/cpu/fdt.c
> @@ -11,9 +11,11 @@
>   */
>
>  #include <common.h>
> +#include <libfdt.h>
> +#include <asm/sections.h>
> +#include <linux/ctype.h>
>
>  #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
> -#include <libfdt.h>
>  #include <fdt_support.h>
>
>  DECLARE_GLOBAL_DATA_PTR;
> @@ -36,3 +38,19 @@ void ft_cpu_setup(void *blob, bd_t *bd)
>         fdt_fixup_ethernet(blob);
>  }
>  #endif /* CONFIG_OF_LIBFDT && CONFIG_OF_BOARD_SETUP */
> +
> +#ifdef CONFIG_OF_SEPARATE
> +void relocate_dtb(ulong cur_start)
> +{
> +       /* This will be called from start.S .
> +        * As dtb is located at the end of u-boot-dtb.bin image,
> +        * we will need to relocate it before zeroing the bss.
> +        * The dtb is moved from _edata to _end, which is markuped
> +        * to __bss_end. Here _end will be used by fdtdec_setup().
> +        */
> +       void *blob = (void *)(cur_start + (ulong)_edata - (ulong)_start);
> +
> +       if (fdt_magic(blob) == FDT_MAGIC)
> +               memmove(_end, blob, fdt_totalsize(blob));
> +}
> +#endif /* CONFIG_OF_SEPARATE */
> diff --git a/arch/nios2/cpu/start.S b/arch/nios2/cpu/start.S
> index dde80f7..58e6826 100644
> --- a/arch/nios2/cpu/start.S
> +++ b/arch/nios2/cpu/start.S
> @@ -96,6 +96,16 @@ _reloc:
>         stw     r0, 4(sp)
>         mov     fp, sp
>
> +#ifdef CONFIG_OF_SEPARATE
> +       /* RELOCATE DTB -- relocate dtb in u-boot-dtb.bin image
> +        * to be used by fdtdec_setup().
> +        */
> +       mov     r4, r8                  /* r8 <- cur _start */
> +       movhi   r2, %hi(relocate_dtb at h)
> +       ori     r2, r2, %lo(relocate_dtb at h)
> +       callr   r2
> +#endif
> +
>         /* ZERO BSS/SBSS -- bss and sbss are assumed to be adjacent
>          * and between __bss_start and __bss_end.
>          */
> --
> 2.1.4
>

Regards,
Simon


More information about the U-Boot mailing list