gemini: Add copy-kernel utility package
[openwrt/openwrt.git] / target / linux / gemini / image / copy-kernel / copy-kernel.S
1 // Arm assembly to copy the Gemini kernel on Storlink reference
2 // designs and derived devices with the same flash layout and
3 // boot loader.
4 //
5 // This will execute at 0x01600000
6 //
7 // Copies the kernel from two fragments (originally zImage
8 // and initramdisk) to 0x00400000 making space for a kernel
9 // image of up to 8 MB except for these 512 bytes used for
10 // this bootstrap.
11 //
12 // 0x01600200 .. 0x017fffff -> 0x00400000 .. 0x005ffdff
13 // 0x00800000 .. 0x00dfffff -> 0x005ffe00 .. 0x00bffdff
14
15 // Memory used for this bootstrap
16 .equ BOOT_HEADROOM, 0x200
17
18 .global _start // Stand-alone assembly code
19 _start:
20 mov r1, #0x01600000
21 mov r2, #0x00400000
22 mov r3, #0x00200000
23 add r1, r1, #BOOT_HEADROOM
24 sub r3, r3, #BOOT_HEADROOM
25 copyloop1:
26 ldr r0, [r1]
27 str r0, [r2]
28 add r1, r1, #4
29 add r2, r2, #4
30 sub r3, r3, #4
31 cmp r3, #0
32 bne copyloop1
33 mov r1, #0x00800000
34 mov r3, #0x00600000
35 copyloop2:
36 ldr r0, [r1]
37 str r0, [r2]
38 add r1, r1, #4
39 add r2, r2, #4
40 sub r3, r3, #4
41 cmp r3, #0
42 bne copyloop2
43 mov r0, #0x00400000
44 // Let's go
45 mov pc, r0