diff options
author | Rafaël Carré <rafael.carre@gmail.com> | 2009-05-28 18:27:08 +0000 |
---|---|---|
committer | Rafaël Carré <rafael.carre@gmail.com> | 2009-05-28 18:27:08 +0000 |
commit | 96165abec2da60c466659fa0e68e06d97587d51a (patch) | |
tree | 5445bddea2ac0e706546ce972d61dacc8d0f81e2 /rbutil/mkamsboot/dualboot/dualboot.S | |
parent | bebc8587cfa7896684278d824ed5b28b2e9f9df1 (diff) | |
download | rockbox-96165abec2da60c466659fa0e68e06d97587d51a.tar.gz rockbox-96165abec2da60c466659fa0e68e06d97587d51a.zip |
FS#10253 : mkamsboot v1.0mkamsboot_1.0
- Bump version to 1.0
- Add Clipv2 target
- Make mkamsboot work as a library (work by domonoky : FS#10185, with a few modifications by me)
. Use a macro with variadic arguments for error cases in functions which might error.
. Add detailed descriptions to functions exported by the library (in the header file)
- modify bin2c.c to produce only one pair of .c/.h files with several files embedded in it
- move files needing to be built by an ARM cross compiler into dualboot/
- commit produced .c/.h files (containing nrv2e_d8.S and dualboot.S built for Clip, Fuze, e200v2, c200v2, m200v4, Clipv2)
- Write a real README file
- cosmetics: indent dualboot.S properly, remove trailing spaces, limit lines to 80 characters
- comments: add/correct comments in dualboot.S and mkamsboot.c
- move back extract_fw.c to utils/AMS/hacking
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21118 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil/mkamsboot/dualboot/dualboot.S')
-rw-r--r-- | rbutil/mkamsboot/dualboot/dualboot.S | 220 |
1 files changed, 220 insertions, 0 deletions
diff --git a/rbutil/mkamsboot/dualboot/dualboot.S b/rbutil/mkamsboot/dualboot/dualboot.S new file mode 100644 index 0000000000..5210ba5160 --- /dev/null +++ b/rbutil/mkamsboot/dualboot/dualboot.S | |||
@@ -0,0 +1,220 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2008 Rafaël Carré | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | .text | ||
23 | |||
24 | #if defined(SANSA_CLIPV2) | ||
25 | .set RAM_SIZE, 0x100000 /* Use 1MB of SDRAM on v2 firmwares (bigger firmware) */ | ||
26 | #else | ||
27 | .set RAM_SIZE, 0x50000 /* Use full IRAM on v1 firmwares */ | ||
28 | #endif | ||
29 | |||
30 | /* AS3525 hardware registers */ | ||
31 | .set GPIOA, 0xC80B0000 | ||
32 | .set GPIOB, 0xC80C0000 | ||
33 | .set GPIOC, 0xC80D0000 | ||
34 | .set GPIOD, 0xC80E0000 | ||
35 | .set CGU_PERI, 0xC80F0014 | ||
36 | |||
37 | |||
38 | /* Vectors */ | ||
39 | |||
40 | ldr pc, =start /* reset vector */ | ||
41 | /* next vectors are unused */ | ||
42 | .word 0 | ||
43 | .word 0 | ||
44 | .word 0 | ||
45 | .word 0 | ||
46 | .word 0 | ||
47 | .word 0 | ||
48 | .word 0 | ||
49 | |||
50 | /* These values are filled in by mkamsboot - don't move them from offset 0x20 */ | ||
51 | |||
52 | uclunpack_end: .word 0 /* End of the ucl_unpack function */ | ||
53 | uclunpack_size: .word 0 /* Size in bytes of the ucl_unpack function */ | ||
54 | |||
55 | ucl_of_end: .word 0 /* End of the ucl-compressed OF image */ | ||
56 | ucl_of_size: .word 0 /* Size in bytes of the compressed OF image */ | ||
57 | |||
58 | ucl_rb_end: .word 0 /* End of the ucl-compressed RB image */ | ||
59 | ucl_rb_size: .word 0 /* Size in bytes of the compressed RB image */ | ||
60 | |||
61 | |||
62 | start: | ||
63 | /* First copy the UCL unpack function to the end of RAM */ | ||
64 | ldr r0, uclunpack_end /* Source */ | ||
65 | ldr r1, uclunpack_size /* Source length */ | ||
66 | sub r2, r0, r1 /* Source start - 1*/ | ||
67 | |||
68 | ldr r3, =(RAM_SIZE-1) /* Destination end */ | ||
69 | |||
70 | uclcopy: | ||
71 | ldrb r4, [r0], #-1 | ||
72 | strb r4, [r3], #-1 | ||
73 | cmp r2, r0 | ||
74 | bne uclcopy | ||
75 | |||
76 | add r5, r3, #2 /* r5 is entry point of copy of uclunpack */ | ||
77 | /* function, plus one (for thumb mode */ | ||
78 | |||
79 | /* enable gpio clock */ | ||
80 | ldr r0, =CGU_PERI | ||
81 | ldr r1, [r0] | ||
82 | orr r1, r1, #(1<<16) | ||
83 | str r1, [r0] | ||
84 | |||
85 | |||
86 | /* TODO : M200V4 */ | ||
87 | #if defined(SANSA_C200V2) | ||
88 | #define USB_PIN 1 | ||
89 | #elif defined(SANSA_CLIP) || defined(SANSA_CLIPV2) | ||
90 | #define USB_PIN 6 | ||
91 | #elif defined(SANSA_FUZE) || defined(SANSA_E200V2) | ||
92 | #define USB_PIN 3 | ||
93 | #endif | ||
94 | |||
95 | #ifdef USB_PIN /* TODO : remove this check when we'll have an USB driver */ | ||
96 | ldr r0, =GPIOA | ||
97 | mov r1, #0 | ||
98 | str r1, [r0, #0x400] | ||
99 | ldr r1, [r0, #(4*(1<<USB_PIN))] | ||
100 | cmp r1, #0 | ||
101 | bne boot_of | ||
102 | #endif | ||
103 | |||
104 | /* Here are model specific tests, for dual boot without a computer */ | ||
105 | /* All models use left button */ | ||
106 | /* /!\ Right button for c200v2 (left button is unkwown) */ | ||
107 | |||
108 | #ifdef SANSA_CLIP | ||
109 | .set row, (1<<5) /* enable output on C5 */ | ||
110 | .set col, (1<<0) /* read keyscan column B0 */ | ||
111 | |||
112 | ldr r0, =GPIOC | ||
113 | mov r1, #row | ||
114 | str r1, [r0, #0x400] | ||
115 | str r1, [r0, #(4*row)] | ||
116 | |||
117 | ldr r0, =GPIOB | ||
118 | mov r1, #0 | ||
119 | str r1, [r0, #0x400] | ||
120 | ldr r1, [r0, #(4*col)] | ||
121 | |||
122 | cmp r1, #0 | ||
123 | bne boot_of | ||
124 | #elif defined(SANSA_CLIPV2) | ||
125 | .set row, (1<<4) /* enable output on D4 */ | ||
126 | .set col, (1<<0) /* read keyscan column D0 */ | ||
127 | |||
128 | ldr r0, =GPIOD | ||
129 | mov r1, #((1<<5)|(1<<4)|(1<<3)) /* all rows as output */ | ||
130 | str r1, [r0, #0x400] | ||
131 | |||
132 | /* all rows high */ | ||
133 | mov r1, #(1<<3) | ||
134 | str r1, [r0, #(4*(1<<3))] | ||
135 | mov r1, #(1<<4) | ||
136 | str r1, [r0, #(4*(1<<4))] | ||
137 | mov r1, #(1<<5) | ||
138 | str r1, [r0, #(4*(1<<5))] | ||
139 | |||
140 | mov r1, #0 /* button row low */ | ||
141 | str r1, [r0, #(4*row)] | ||
142 | |||
143 | mov r1, #5 /* small delay */ | ||
144 | 1: subs r1, r1, #1 | ||
145 | bne 1b | ||
146 | |||
147 | ldr r1, [r0, #(4*col)] | ||
148 | |||
149 | cmp r1, #0 | ||
150 | beq boot_of | ||
151 | #elif defined(SANSA_E200V2) || defined(SANSA_FUZE) | ||
152 | ldr r0, =GPIOC | ||
153 | mov r1, #0 | ||
154 | str r1, [r0, #0x400] | ||
155 | ldr r1, [r0, #0x20] /* read pin C3 */ | ||
156 | |||
157 | cmp r1, #0 /* C3 = #0 means button pressed */ | ||
158 | beq boot_of | ||
159 | #elif defined(SANSA_C200V2) | ||
160 | /* check for RIGHT on C6, should changed to LEFT as soon as it | ||
161 | * known in which pin that is in order for consistency */ | ||
162 | ldr r0, =GPIOC | ||
163 | mov r1, #0 | ||
164 | str r1, [r0, #0x400] /* set pin to output */ | ||
165 | |||
166 | ldr r1, [r0, #256] /* 1<<(6+2) */ | ||
167 | cmp r1, #0 /* C6 low means button pressed */ | ||
168 | beq boot_of | ||
169 | #elif defined(SANSA_M200V4) | ||
170 | .set row, (1<<5) /* enable output on A5 */ | ||
171 | .set col, (1<<0) /* read keyscan column A0 */ | ||
172 | |||
173 | ldr r0, =GPIOA | ||
174 | mov r1, #row | ||
175 | str r1, [r0, #0x400] | ||
176 | str r1, [r0, #(4*row)] | ||
177 | |||
178 | ldr r2, [r0, #(4*col)] | ||
179 | |||
180 | /* check value read (1 means button pressed) */ | ||
181 | cmp r2, #0 | ||
182 | bne boot_of | ||
183 | #else | ||
184 | #error No target-specific key check defined! | ||
185 | #endif | ||
186 | |||
187 | |||
188 | /* The dualboot button was not held, so we boot rockbox */ | ||
189 | ldr r0, ucl_rb_end /* Address of compressed image */ | ||
190 | ldr r1, ucl_rb_size /* Compressed size */ | ||
191 | b decompress | ||
192 | |||
193 | boot_of: | ||
194 | ldr r0, ucl_of_end /* Address of compressed image */ | ||
195 | ldr r1, ucl_of_size /* Compressed size */ | ||
196 | |||
197 | |||
198 | decompress: | ||
199 | /* At this point: */ | ||
200 | /* r5 = entry point (plus one for thumb) of uclunpack function */ | ||
201 | /* r3 = destination_end for copy of UCL image */ | ||
202 | /* r0 = source_end for UCL image to copy */ | ||
203 | /* r1 = size of UCL image to copy */ | ||
204 | |||
205 | sub r4, r3, r1 /* r4 := destination_start - 1 */ | ||
206 | |||
207 | fw_copy: | ||
208 | ldrb r2, [r0], #-1 | ||
209 | strb r2, [r3], #-1 | ||
210 | cmp r3, r4 /* Stop when we reached dest_start-1 */ | ||
211 | bne fw_copy | ||
212 | |||
213 | /* Call the ucl decompress function, which will branch to 0x0 */ | ||
214 | /* on completion */ | ||
215 | add r0, r3, #1 /* r0 := Start of compressed image */ | ||
216 | /* r1 already contains compressed size */ | ||
217 | mov r2, #0 /* r2 := Destination for unpacking */ | ||
218 | bx r5 /* Branch to uclunpack, switching to thumb */ | ||
219 | |||
220 | /* never reached : uclunpack will branch to the reset vector (0x0) */ | ||