2 * (C) Copyright 2011-2012
5 * SPDX-License-Identifier: GPL-2.0+
10 relocaddr: /* address of this relocaddr section after coping */
11 .word . /* address of section (calculated at compile time) */
13 startaddr: /* address of u-boot after copying */
14 .word CONFIG_SYS_TEXT_BASE
16 kernaddr: /* address of kernel after copying */
19 kernsize: /* maximal size of kernel image */
22 kernoffs: /* offset of kernel image in loaded u-boot */
25 imagesize: /* maximal size of image */
28 ih_magic: /* IH_MAGIC in big endian from include/image.h */
32 * Routine: save_boot_params (called after reset from start.S)
33 * Description: Copy attached kernel to address KERNEL_ADDRESS
34 * Copy u-boot to address CONFIG_SYS_TEXT_BASE
35 * Return to copied u-boot address
38 .global save_boot_params
42 /* Copy valid attached kernel to address KERNEL_ADDRESS */
45 adr r0, relocaddr /* r0 - address of section relocaddr */
46 ldr r1, relocaddr /* r1 - address of relocaddr after relocation */
49 /* r4 - calculated offset */
53 /* r0 - start of kernel before */
60 /* r3 - start of kernel after */
63 /* r2 - end of kernel after */
67 /* r1 - end of kernel before */
70 /* remove header in target kernel */
74 /* check for valid kernel uImage */
75 ldr r4, [r0] /* r4 - 4 bytes header of kernel */
76 ldr r5, ih_magic /* r5 - IH_MAGIC */
78 bne copy_kernel_end /* skip if invalid image */
88 str r5, [r0] /* remove 4 bytes header of kernel */
94 adr r0, relocaddr /* r0 - address of section relocaddr */
95 ldr r1, relocaddr /* r1 - address of relocaddr after relocation */
98 beq copy_uboot_end /* skip if u-boot is on correct address */
100 /* r5 - calculated offset */
104 /* r6 - maximal u-boot size */
107 /* fix return address */
111 /* r1 - start of u-boot after */
114 /* r0 - start of u-boot before */
118 /* check if we need to move uboot copy code before calling it */
120 bhi copy_uboot_start /* now coping u-boot code directly is safe */
124 /* r0 - start of u-boot before */
125 /* r1 - start of u-boot after */
126 /* r6 - maximal u-boot size */
128 /* r7 - maximal kernel size */
131 /* r4 - end of kernel before */
135 /* r5 - end of u-boot after */
139 /* r2 - start of loop code after */
140 cmp r4, r5 /* higher address (r4 or r5) */
144 /* r3 - end of loop code before */
147 /* r4 - end of loop code after */
148 adr r4, copy_uboot_start
153 ldmdb r3!, {r7 - r10}
154 stmdb r4!, {r7 - r10}
162 /* Copy u-boot to address CONFIG_SYS_TEXT_BASE */
165 /* r0 - start of u-boot before */
166 /* r1 - start of u-boot after */
167 /* r6 - maximal u-boot size */
169 /* r2 - end of u-boot after */
172 /* condition for copying from left to right */
174 addlo r1, r0, r6 /* r1 - end of u-boot before */
175 blo copy_uboot_loop_right
177 copy_uboot_loop_left:
178 ldmia r0!, {r3 - r10}
179 stmia r1!, {r3 - r10}
181 blo copy_uboot_loop_left
184 copy_uboot_loop_right:
185 ldmdb r1!, {r3 - r10}
186 stmdb r2!, {r3 - r10}
188 bhi copy_uboot_loop_right