]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
x86: Support relocation of FDT on start-up
authorSimon Glass <sjg@chromium.org>
Thu, 28 Feb 2013 19:26:15 +0000 (19:26 +0000)
committerSimon Glass <sjg@chromium.org>
Mon, 4 Mar 2013 23:57:47 +0000 (15:57 -0800)
With CONFIG_OF_CONTROL we may have an FDT in the BSS region. Relocate
it up with the rest of U-Boot to keep the rest of memory free.

Signed-off-by: Simon Glass <sjg@chromium.org>
arch/x86/include/asm/global_data.h
arch/x86/include/asm/init_helpers.h
arch/x86/include/asm/relocate.h
arch/x86/lib/board.c
arch/x86/lib/init_helpers.c
arch/x86/lib/init_wrappers.c
arch/x86/lib/relocate.c

index 2f84abd7856cfe441a283b657539f99b70068de9..4fdb08090a02bebda2851f4c147994043fe72d7a 100644 (file)
@@ -32,6 +32,7 @@ struct arch_global_data {
        uint64_t tsc_base;              /* Initial value returned by rdtsc() */
        uint32_t tsc_base_kclocks;      /* Initial tsc as a kclocks value */
        uint32_t tsc_prev;              /* For show_boot_progress() */
        uint64_t tsc_base;              /* Initial value returned by rdtsc() */
        uint32_t tsc_base_kclocks;      /* Initial tsc as a kclocks value */
        uint32_t tsc_prev;              /* For show_boot_progress() */
+       void *new_fdt;                  /* Relocated FDT */
 };
 
 #endif
 };
 
 #endif
index 2f437e034313f9734e05d1c9e9d5389a04cc3d7b..d018b290c1b1622bfdf1d3333d6eb038cbcd6a84 100644 (file)
@@ -38,5 +38,7 @@ int flash_init_r(void);
 int status_led_set_r(void);
 int set_load_addr_r(void);
 int init_func_spi(void);
 int status_led_set_r(void);
 int set_load_addr_r(void);
 int init_func_spi(void);
+int find_fdt(void);
+int prepare_fdt(void);
 
 #endif /* !_INIT_HELPERS_H_ */
 
 #endif /* !_INIT_HELPERS_H_ */
index 33129ef64b0973a1dbc2d81fac0ead241ead39c3..d371c9d641826688d6ffb9372310f4e799adc0bd 100644 (file)
@@ -27,6 +27,7 @@
 #include <common.h>
 
 int copy_uboot_to_ram(void);
 #include <common.h>
 
 int copy_uboot_to_ram(void);
+int copy_fdt_to_ram(void);
 int clear_bss(void);
 int do_elf_reloc_fixups(void);
 
 int clear_bss(void);
 int do_elf_reloc_fixups(void);
 
index 22bc26dde90643f1e8a82ae88564624c8f6bdd70..2441a66ae226dee55e029f0d26777791d3fd7615 100644 (file)
@@ -32,6 +32,7 @@
  */
 
 #include <common.h>
  */
 
 #include <common.h>
+#include <fdtdec.h>
 #include <watchdog.h>
 #include <stdio_dev.h>
 #include <asm/u-boot-x86.h>
 #include <watchdog.h>
 #include <stdio_dev.h>
 #include <asm/u-boot-x86.h>
@@ -131,6 +132,7 @@ init_fnc_t *init_sequence_f[] = {
 init_fnc_t *init_sequence_f_r[] = {
        init_cache_f_r,
        copy_uboot_to_ram,
 init_fnc_t *init_sequence_f_r[] = {
        init_cache_f_r,
        copy_uboot_to_ram,
+       copy_fdt_to_ram,
        clear_bss,
        do_elf_reloc_fixups,
 
        clear_bss,
        do_elf_reloc_fixups,
 
@@ -217,6 +219,7 @@ static void do_init_loop(init_fnc_t **init_fnc_ptr)
 
 void board_init_f(ulong boot_flags)
 {
 
 void board_init_f(ulong boot_flags)
 {
+       gd->fdt_blob = gd->arch.new_fdt = NULL;
        gd->flags = boot_flags;
 
        do_init_loop(init_sequence_f);
        gd->flags = boot_flags;
 
        do_init_loop(init_sequence_f);
index ff2d21f4c580d52dd716c84b784629ba148834f1..414fdcc4c901bd4599eb2a5ef64b241ac490723c 100644 (file)
@@ -22,6 +22,7 @@
  */
 #include <common.h>
 #include <command.h>
  */
 #include <common.h>
 #include <command.h>
+#include <fdtdec.h>
 #include <stdio_dev.h>
 #include <version.h>
 #include <malloc.h>
 #include <stdio_dev.h>
 #include <version.h>
 #include <malloc.h>
@@ -85,17 +86,35 @@ int calculate_relocation_address(void)
                        (uintptr_t)&__text_start;
        ulong total_size;
        ulong dest_addr;
                        (uintptr_t)&__text_start;
        ulong total_size;
        ulong dest_addr;
+       ulong fdt_size = 0;
 
 
+#if defined(CONFIG_OF_SEPARATE) && defined(CONFIG_OF_CONTROL)
+       if (gd->fdt_blob)
+               fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
+#endif
        total_size = ALIGN(uboot_size, 1 << 12) + CONFIG_SYS_MALLOC_LEN +
        total_size = ALIGN(uboot_size, 1 << 12) + CONFIG_SYS_MALLOC_LEN +
-               CONFIG_SYS_STACK_SIZE;
+               CONFIG_SYS_STACK_SIZE + fdt_size;
 
 
+       dest_addr = board_get_usable_ram_top(total_size);
        /*
         * NOTE: All destination address are rounded down to 16-byte
         *       boundary to satisfy various worst-case alignment
         *       requirements
         */
        /*
         * NOTE: All destination address are rounded down to 16-byte
         *       boundary to satisfy various worst-case alignment
         *       requirements
         */
-       dest_addr = board_get_usable_ram_top(total_size);
+       dest_addr &= ~15;
 
 
+#if defined(CONFIG_OF_SEPARATE) && defined(CONFIG_OF_CONTROL)
+       /*
+        * If the device tree is sitting immediate above our image then we
+        * must relocate it. If it is embedded in the data section, then it
+        * will be relocated with other data.
+        */
+       if (gd->fdt_blob) {
+               dest_addr -= fdt_size;
+               gd->arch.new_fdt = (void *)dest_addr;
+               dest_addr &= ~15;
+       }
+#endif
        /* U-Boot is below the FDT */
        dest_addr -= uboot_size;
        dest_addr &= ~((1 << 12) - 1);
        /* U-Boot is below the FDT */
        dest_addr -= uboot_size;
        dest_addr &= ~((1 << 12) - 1);
index cca018fa9b06ae174eccb90fea69fb2b4eafa749..19af875c0e0ee4951966615e0ad8ac103f4a7700 100644 (file)
@@ -22,6 +22,7 @@
  */
 #include <common.h>
 #include <environment.h>
  */
 #include <common.h>
 #include <environment.h>
+#include <fdtdec.h>
 #include <serial.h>
 #include <kgdb.h>
 #include <scsi.h>
 #include <serial.h>
 #include <kgdb.h>
 #include <scsi.h>
index 23edca95269f36a7215f040fc1420e009a942541..3a38e52ac9d8f6960dbf87dc601d833277416d8c 100644 (file)
@@ -32,6 +32,7 @@
  */
 
 #include <common.h>
  */
 
 #include <common.h>
+#include <libfdt.h>
 #include <malloc.h>
 #include <asm/u-boot-x86.h>
 #include <asm/relocate.h>
 #include <malloc.h>
 #include <asm/u-boot-x86.h>
 #include <asm/relocate.h>
@@ -46,6 +47,22 @@ int copy_uboot_to_ram(void)
        return 0;
 }
 
        return 0;
 }
 
+int copy_fdt_to_ram(void)
+{
+       if (gd->arch.new_fdt) {
+               ulong fdt_size;
+
+               fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
+
+               memcpy(gd->arch.new_fdt, gd->fdt_blob, fdt_size);
+               debug("Relocated fdt from %p to %p, size %lx\n",
+                      gd->fdt_blob, gd->arch.new_fdt, fdt_size);
+               gd->fdt_blob = gd->arch.new_fdt;
+       }
+
+       return 0;
+}
+
 int clear_bss(void)
 {
        ulong dst_addr = (ulong)&__bss_start + gd->reloc_off;
 int clear_bss(void)
 {
        ulong dst_addr = (ulong)&__bss_start + gd->reloc_off;