]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
ARM: implement relocation for ARM926
authorHeiko Schocher <hs@denx.de>
Fri, 17 Sep 2010 11:10:42 +0000 (13:10 +0200)
committerWolfgang Denk <wd@denx.de>
Sun, 19 Sep 2010 17:29:54 +0000 (19:29 +0200)
Change the implementation for arm926 to relocate the code to
an arbitrary address in RAM.

Adapt the TX25 (i.MX25), magnesium board to test the changes.

On the tx25 board TEXT_BASE is set to the final relocation
address to prevent one more copying of u-boot code
when relocating. More info see:
doc/README.arm-relocation

da850 board:
Tested-by: Ben Gardiner <bengardiner@nanometrics.ca>
Portions of this work were supported by funding from
the CE Linux Forum.

Signed-off-by: Heiko Schocher <hs@denx.de>
Cc: Ben Gardiner <bengardiner@nanometrics.ca>
14 files changed:
arch/arm/cpu/arm926ejs/orion5x/dram.c
arch/arm/cpu/arm926ejs/start.S
arch/arm/cpu/arm926ejs/u-boot.lds
board/karo/tx25/config.mk
board/karo/tx25/tx25.c
board/keymile/km_arm/km_arm.c
board/logicpd/imx27lite/config.mk
board/logicpd/imx27lite/imx27lite.c
doc/README.arm-relocation
include/configs/da850evm.h
include/configs/imx27lite-common.h
include/configs/km_arm.h
include/configs/tx25.h
nand_spl/board/karo/tx25/u-boot.lds

index c719798a6608d8f7d08c5f7942ec3cc71088fe3c..c5c8ab7e4d88f74e677f0eeb3d5d82c9016920fc 100644 (file)
@@ -49,7 +49,7 @@ u32 orion5x_sdram_bar(enum memory_bank bank)
        result = winregs[bank].base;
        return result;
 }
-
+#if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
 int dram_init(void)
 {
        int i;
@@ -62,3 +62,25 @@ int dram_init(void)
        }
        return 0;
 }
+#else
+int dram_init (void)
+{
+       /* dram_init must store complete ramsize in gd->ram_size */
+       gd->ram_size = get_ram_size(
+                       (volatile long *) orion5x_sdram_bar(0),
+                       CONFIG_MAX_RAM_BANK_SIZE);
+       return 0;
+}
+
+void dram_init_banksize (void)
+{
+       int i;
+
+       for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
+               gd->bd->bi_dram[i].start = orion5x_sdram_bar(i);
+               gd->bd->bi_dram[i].size = get_ram_size(
+                       (volatile long *) (gd->bd->bi_dram[i].start),
+                       CONFIG_MAX_RAM_BANK_SIZE);
+       }
+}
+#endif
index cf40ce12928359c5238d02a32ed361ccc153c101..16ee972f2b9aca1339bbb4f5c6c21836a091b029 100644 (file)
@@ -114,12 +114,15 @@ _fiq:
  *************************************************************************
  */
 
+.globl _TEXT_BASE
 _TEXT_BASE:
        .word   TEXT_BASE
 
+#if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
 .globl _armboot_start
 _armboot_start:
        .word _start
+#endif
 
 /*
  * These are defined in the board-specific linker script.
@@ -144,6 +147,35 @@ FIQ_STACK_START:
        .word 0x0badc0de
 #endif
 
+#if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
+/* IRQ stack memory (calculated at run-time) + 8 bytes */
+.globl IRQ_STACK_START_IN
+IRQ_STACK_START_IN:
+       .word   0x0badc0de
+
+.globl _datarel_start
+_datarel_start:
+       .word __datarel_start
+
+.globl _datarelrolocal_start
+_datarelrolocal_start:
+       .word __datarelrolocal_start
+
+.globl _datarellocal_start
+_datarellocal_start:
+       .word __datarellocal_start
+
+.globl _datarelro_start
+_datarelro_start:
+       .word __datarelro_start
+
+.globl _got_start
+_got_start:
+       .word __got_start
+
+.globl _got_end
+_got_end:
+       .word __got_end
 
 /*
  * the actual reset code
@@ -166,6 +198,135 @@ reset:
        bl      cpu_init_crit
 #endif
 
+/* Set stackpointer in internal RAM to call board_init_f */
+call_board_init_f:
+       ldr     sp, =(CONFIG_SYS_INIT_SP_ADDR)
+       ldr     r0,=0x00000000
+       bl      board_init_f
+
+/*------------------------------------------------------------------------------*/
+
+/*
+ * void relocate_code (addr_sp, gd, addr_moni)
+ *
+ * This "function" does not return, instead it continues in RAM
+ * after relocating the monitor code.
+ *
+ */
+       .globl  relocate_code
+relocate_code:
+       mov     r4, r0  /* save addr_sp */
+       mov     r5, r1  /* save addr of gd */
+       mov     r6, r2  /* save addr of destination */
+       mov     r7, r2  /* save addr of destination */
+
+       /* Set up the stack                                                 */
+stack_setup:
+       mov     sp, r4
+
+       adr     r0, _start
+       ldr     r2, _TEXT_BASE
+       ldr     r3, _bss_start
+       sub     r2, r3, r2              /* r2 <- size of armboot            */
+       add     r2, r0, r2              /* r2 <- source end address         */
+       cmp     r0, r6
+       beq     clear_bss
+
+#ifndef CONFIG_SKIP_RELOCATE_UBOOT
+copy_loop:
+       ldmia   r0!, {r9-r10}           /* copy from source address [r0]    */
+       stmia   r6!, {r9-r10}           /* copy to   target address [r1]    */
+       cmp     r0, r2                  /* until source end addreee [r2]    */
+       ble     copy_loop
+
+#ifndef CONFIG_PRELOADER
+       /* fix got entries */
+       ldr     r1, _TEXT_BASE          /* Text base */
+       mov     r0, r7                  /* reloc addr */
+       ldr     r2, _got_start          /* addr in Flash */
+       ldr     r3, _got_end            /* addr in Flash */
+       sub     r3, r3, r1
+       add     r3, r3, r0
+       sub     r2, r2, r1
+       add     r2, r2, r0
+
+fixloop:
+       ldr     r4, [r2]
+       sub     r4, r4, r1
+       add     r4, r4, r0
+       str     r4, [r2]
+       add     r2, r2, #4
+       cmp     r2, r3
+       bne     fixloop
+#endif
+#endif /* #ifndef CONFIG_SKIP_RELOCATE_UBOOT */
+
+clear_bss:
+#ifndef CONFIG_PRELOADER
+       ldr     r0, _bss_start
+       ldr     r1, _bss_end
+       ldr     r3, _TEXT_BASE          /* Text base */
+       mov     r4, r7                  /* reloc addr */
+       sub     r0, r0, r3
+       add     r0, r0, r4
+       sub     r1, r1, r3
+       add     r1, r1, r4
+       mov     r2, #0x00000000         /* clear                            */
+
+clbss_l:str    r2, [r0]                /* clear loop...                    */
+       add     r0, r0, #4
+       cmp     r0, r1
+       bne     clbss_l
+
+       bl coloured_LED_init
+       bl red_LED_on
+#endif
+
+/*
+ * We are done. Do not return, instead branch to second part of board
+ * initialization, now running from RAM.
+ */
+#ifdef CONFIG_NAND_SPL
+       ldr     pc, _nand_boot
+
+_nand_boot: .word nand_boot
+#else
+       ldr     r0, _TEXT_BASE
+       ldr     r2, _board_init_r
+       sub     r2, r2, r0
+       add     r2, r2, r7      /* position from board_init_r in RAM */
+       /* setup parameters for board_init_r */
+       mov     r0, r5          /* gd_t */
+       mov     r1, r7          /* dest_addr */
+       /* jump to it ... */
+       mov     lr, r2
+       mov     pc, lr
+
+_board_init_r: .word board_init_r
+#endif
+
+#else /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
+/*
+ * the actual reset code
+ */
+
+reset:
+       /*
+        * set the cpu to SVC32 mode
+        */
+       mrs     r0,cpsr
+       bic     r0,r0,#0x1f
+       orr     r0,r0,#0xd3
+       msr     cpsr,r0
+
+       /*
+        * we do sys-critical inits only at reboot,
+        * not when booting from ram!
+        */
+#ifndef CONFIG_SKIP_LOWLEVEL_INIT
+       bl      cpu_init_crit
+#endif
+
 #ifndef CONFIG_SKIP_RELOCATE_UBOOT
 relocate:                              /* relocate U-Boot to RAM           */
        adr     r0, _start              /* r0 <- current position of code   */
@@ -221,7 +382,7 @@ _start_armboot:
 #else
        .word start_armboot
 #endif /* CONFIG_NAND_SPL */
-
+#endif /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
 
 /*
  *************************************************************************
@@ -307,10 +468,13 @@ cpu_init_crit:
        @ carve out a frame on current user stack
        sub     sp, sp, #S_FRAME_SIZE
        stmia   sp, {r0 - r12}  @ Save user registers (now in svc mode) r0-r12
-
+#if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
        ldr     r2, _armboot_start
        sub     r2, r2, #(CONFIG_STACKSIZE+CONFIG_SYS_MALLOC_LEN)
        sub     r2, r2, #(CONFIG_SYS_GBL_DATA_SIZE+8)  @ set base 2 words into abort stack
+#else
+       ldr     r2, IRQ_STACK_START_IN
+#endif
        @ get values for "aborted" pc and cpsr (into parm regs)
        ldmia   r2, {r2 - r3}
        add     r0, sp, #S_FRAME_SIZE           @ grab pointer to old stack
@@ -342,9 +506,13 @@ cpu_init_crit:
        .endm
 
        .macro get_bad_stack
+#if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
        ldr     r13, _armboot_start             @ setup our mode stack
        sub     r13, r13, #(CONFIG_STACKSIZE+CONFIG_SYS_MALLOC_LEN)
        sub     r13, r13, #(CONFIG_SYS_GBL_DATA_SIZE+8) @ reserved a couple spots in abort stack
+#else
+       ldr     r13, IRQ_STACK_START_IN         @ setup our mode stack
+#endif
 
        str     lr, [r13]       @ save caller lr in position 0 of saved stack
        mrs     lr, spsr        @ get the spsr
index ecbc58c7c24fa83f23c9a9a83649457087a73e82..02eb8ca6072809a9de96ac055a832dc6c56baae2 100644 (file)
@@ -39,11 +39,23 @@ SECTIONS
        .rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) }
 
        . = ALIGN(4);
-       .data : { *(.data) }
+       .data : {
+               *(.data)
+       __datarel_start = .;
+               *(.data.rel)
+       __datarelrolocal_start = .;
+               *(.data.rel.ro.local)
+       __datarellocal_start = .;
+               *(.data.rel.local)
+       __datarelro_start = .;
+               *(.data.rel.ro)
+       }
 
+       __got_start = .;
        . = ALIGN(4);
        .got : { *(.got) }
 
+       __got_end = .;
        . = .;
        __u_boot_cmd_start = .;
        .u_boot_cmd : { *(.u_boot_cmd) }
index 732a14a6d1e3a7263df4a5f886e0b516b8dbedac..51ca1ab0f0d0d14495596e18f990f386ae9c3660 100644 (file)
@@ -1,5 +1,5 @@
 ifdef CONFIG_NAND_SPL
-TEXT_BASE = 0x81ec0000
+TEXT_BASE = 0x810c0000
 else
-TEXT_BASE = 0x81f00000
+TEXT_BASE = 0x81fc0000
 endif
index 2608698e2905edebc39a954e908070b0b00c9e50..dc57d5c48506ea33eb128290e2f3a7984dcb1ad3 100644 (file)
@@ -159,7 +159,14 @@ int board_late_init(void)
 
 int dram_init (void)
 {
+       /* dram_init must store complete ramsize in gd->ram_size */
+       gd->ram_size = get_ram_size((volatile void *)PHYS_SDRAM_1,
+                               PHYS_SDRAM_1_SIZE);
+       return 0;
+}
 
+void dram_init_banksize(void)
+{
        gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
        gd->bd->bi_dram[0].size = get_ram_size((volatile void *)PHYS_SDRAM_1,
                        PHYS_SDRAM_1_SIZE);
@@ -167,9 +174,9 @@ int dram_init (void)
        gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
        gd->bd->bi_dram[1].size = get_ram_size((volatile void *)PHYS_SDRAM_2,
                        PHYS_SDRAM_2_SIZE);
-#endif
+#else
 
-       return 0;
+#endif
 }
 
 int checkboard(void)
index d7cbd7a2a99099db1d411145679da3ec1e300255..7c0b858887397bbe979f060fc3054bb093802167 100644 (file)
@@ -225,6 +225,7 @@ U_BOOT_CMD(
        );
 #endif
 
+#if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
 int dram_init(void)
 {
        int i;
@@ -234,9 +235,32 @@ int dram_init(void)
                gd->bd->bi_dram[i].size = get_ram_size((long *)kw_sdram_bar(i),
                                                       kw_sdram_bs(i));
        }
+
+       return 0;
+}
+#else
+int dram_init(void)
+{
+       /* dram_init must store complete ramsize in gd->ram_size */
+       /* Fix this */
+       gd->ram_size = get_ram_size((volatile void *)kw_sdram_bar(0),
+                               kw_sdram_bs(0));
        return 0;
 }
 
+void dram_init_banksize(void)
+{
+       int i;
+
+       for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
+               gd->bd->bi_dram[i].start = kw_sdram_bar(i);
+               gd->bd->bi_dram[i].size = kw_sdram_bs(i);
+               gd->bd->bi_dram[i].size = get_ram_size((long *)kw_sdram_bar(i),
+                                                      kw_sdram_bs(i));
+       }
+}
+#endif
+
 /* Configure and enable MV88E1118 PHY */
 void reset_phy(void)
 {
index a2e7768dd8639cdead529d14ffe04b386fff0267..2f9c4e629cef5eee53e9ad1368236ad10e9ba4b8 100644 (file)
@@ -1 +1 @@
-TEXT_BASE = 0xA7F00000
+TEXT_BASE = 0xc0000000
index 442741547bcce3c5e8a787ce4e02d647dfa213dc..6eb5cc2dd6c1d2b74c2d9c9c9a948a7aaa26fc26 100644 (file)
@@ -66,19 +66,22 @@ int board_init (void)
 
 int dram_init (void)
 {
+       /* dram_init must store complete ramsize in gd->ram_size */
+       gd->ram_size = get_ram_size((volatile void *)CONFIG_SYS_SDRAM_BASE,
+                               PHYS_SDRAM_1_SIZE);
+       return 0;
+}
 
-#if CONFIG_NR_DRAM_BANKS > 0
-       gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
-       gd->bd->bi_dram[0].size = get_ram_size((volatile void *)PHYS_SDRAM_1,
+void dram_init_banksize(void)
+{
+       gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
+       gd->bd->bi_dram[0].size = get_ram_size((volatile void *)CONFIG_SYS_SDRAM_BASE,
                        PHYS_SDRAM_1_SIZE);
-#endif
 #if CONFIG_NR_DRAM_BANKS > 1
        gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
        gd->bd->bi_dram[1].size = get_ram_size((volatile void *)PHYS_SDRAM_2,
                        PHYS_SDRAM_2_SIZE);
 #endif
-
-       return 0;
 }
 
 int checkboard(void)
index 6be1a12923acde7c350c7d1ed24186d28aaf0d69..e3ed60ecdcfea4e072612b3efe569e6040c20f6a 100644 (file)
@@ -43,6 +43,29 @@ CONFIG_SYS_ARM_WITHOUT_RELOC defined!!!
 
 -------------------------------------------------------------------------------------
 
+For boards which boot from nand_spl, it is possible to save a copy
+if TEXT_BASE == relocation address! This prevents that uboot code
+is copied again in relocate_code().
+
+example for the tx25 board:
+
+a) cpu starts
+b) it copies the first page in nand to internal ram
+   (nand_spl_code)
+c) end executes this code
+d) this initialize CPU, RAM, ... and copy itself to RAM
+   (this bin must fit in one page, so board_init_f()
+    don;t fit in it ... )
+e) there it copy u-boot to CONFIG_SYS_NAND_U_BOOT_DST and
+   starts this image @ CONFIG_SYS_NAND_U_BOOT_START
+f) u-boot code steps through board_init_f() and calculates
+   the relocation address and copy itself to it
+
+If TEXT_BASE == relocation address, the copying of u-boot
+in f) could be saved.
+
+-------------------------------------------------------------------------------------
+
 ToDo:
 
 - fill in bd_t infos (check)
index 357715d660c021e696bcceb2205237410c57fa5b..016a21e9d0bdb62ae7df20e4a8c5a3756899b706 100644 (file)
@@ -39,7 +39,6 @@
 #define CONFIG_SYS_HZ_CLOCK            clk_get(DAVINCI_AUXCLK_CLKID)
 #define CONFIG_SYS_HZ                  1000
 #define CONFIG_SKIP_LOWLEVEL_INIT
-#define CONFIG_SKIP_RELOCATE_UBOOT     /* to a proper address, init done */
 
 /*
  * Memory Info
 #undef CONFIG_CMD_ENV
 #endif
 
+/* additions for new relocation code, must added to all boards */
+#undef CONFIG_SYS_ARM_WITHOUT_RELOC /* This board is tested with relocation support */
+#define CONFIG_SYS_SDRAM_BASE          0xc0000000
+#define CONFIG_SYS_INIT_SP_ADDR                (CONFIG_SYS_SDRAM_BASE + 0x1000 - /* Fix this */ \
+                                       CONFIG_SYS_GBL_DATA_SIZE)
 #endif /* __CONFIG_H */
index 33550ba66147f25c19ca1797c90224046b65c975..812e5f2e7180f65270ba12eda372aff96f1f86b6 100644 (file)
        "mtdids=" MTDIDS_DEFAULT "\0"                                   \
        "mtdparts=" MTDPARTS_DEFAULT "\0"                               \
 
+/* additions for new relocation code, must added to all boards */
+#undef CONFIG_SYS_ARM_WITHOUT_RELOC /* This board is tested with relocation support */
+#define CONFIG_SYS_SDRAM_BASE          PHYS_SDRAM_1
+#define CONFIG_SYS_INIT_SP_ADDR                (CONFIG_SYS_SDRAM_BASE + 0x1000 - /* Fix this */ \
+                                       CONFIG_SYS_GBL_DATA_SIZE)
 #endif /* __IMX27LITE_COMMON_CONFIG_H */
index 1617e697deb6abacf2dba1d699fe39b4bb71218f..8673e6ff64dbce957de46b4f9c88dfee7d468950 100644 (file)
@@ -180,4 +180,8 @@ int get_scl (void);
 #undef CONFIG_JFFS2_CMDLINE
 #endif
 
+/* additions for new relocation code, must added to all boards */
+#define CONFIG_SYS_SDRAM_BASE          0x00000000
+#define CONFIG_SYS_INIT_SP_ADDR                (0x00000000 + 0x1000 - /* Fix this */ \
+                                       CONFIG_SYS_GBL_DATA_SIZE)
 #endif /* _CONFIG_KM_ARM_H */
index 013aa3541c842b231df967e51b16fdf1fd6acb18..c798570aec97f511ac12c2be0c0bb5bbf0c10f38 100644 (file)
@@ -40,9 +40,9 @@
 /* Start copying real U-boot from the second page */
 #define CONFIG_SYS_NAND_U_BOOT_OFFS    0x800
 #define CONFIG_SYS_NAND_U_BOOT_SIZE    0x30000
-/* Load U-Boot to this address */
-#define CONFIG_SYS_NAND_U_BOOT_DST     0x81f00000
-#define CONFIG_SYS_NAND_U_BOOT_START   CONFIG_SYS_NAND_U_BOOT_DST
+
+#define CONFIG_SYS_NAND_U_BOOT_DST      (0x81fc0000)
+#define CONFIG_SYS_NAND_U_BOOT_START    CONFIG_SYS_NAND_U_BOOT_DST
 
 #define CONFIG_SYS_NAND_PAGE_SIZE      2048
 #define CONFIG_SYS_NAND_SPARE_SIZE     64
@@ -52,7 +52,6 @@
 #define CONFIG_SYS_NAND_BAD_BLOCK_POS  0
 #else
 #define CONFIG_SKIP_LOWLEVEL_INIT
-#define CONFIG_SKIP_RELOCATE_UBOOT
 #endif
 
 #define CONFIG_DISPLAY_CPUINFO
        "update=nand erase 0 40000;nand write ${loadaddr} 0 40000\0"    \
        "upd=run load update\0"                                         \
 
+/* additions for new relocation code, must added to all boards */
+#undef CONFIG_SYS_ARM_WITHOUT_RELOC /* This board is tested with relocation support */
+#define CONFIG_SYS_SDRAM_BASE          PHYS_SDRAM_1
+#define CONFIG_SYS_INIT_SP_ADDR                (CONFIG_SYS_SDRAM_BASE + 0x1000 - /* Fix this */ \
+                                       CONFIG_SYS_GBL_DATA_SIZE)
+
 #endif /* __CONFIG_H */
index 423bed386c4b22adb53cfebc04f6723cc788b866..c57255753555f48609d38921b6963445fd948cdd 100644 (file)
@@ -41,11 +41,23 @@ SECTIONS
        .rodata : { *(.rodata) }
 
        . = ALIGN(4);
-       .data : { *(.data) }
+       .data : {
+               *(.data)
+       __datarel_start = .;
+               *(.data.rel)
+       __datarelrolocal_start = .;
+               *(.data.rel.ro.local)
+       __datarellocal_start = .;
+               *(.data.rel.local)
+       __datarelro_start = .;
+               *(.data.rel.ro)
+       }
 
+       __got_start = .;
        . = ALIGN(4);
        .got : { *(.got) }
 
+       __got_end = .;
        . = .;
        __u_boot_cmd_start = .;
        .u_boot_cmd : { *(.u_boot_cmd) }