Revert r26008. Fonts in the font pack should at least be able to display English...
[kugel-rb.git] / rbutil / mkamsboot / dualboot / dualboot.S
blob8bb2059d789253ea1d0fb32ce0b0fd4dc89e0d58
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  ****************************************************************************/
22 .text
24 /* AS3525 hardware registers */
25 .set GPIOA,     0xC80B0000
26 .set GPIOB,     0xC80C0000
27 .set GPIOC,     0xC80D0000
28 .set GPIOD,     0xC80E0000
29 .set CGU_PERI,  0xC80F0014
30 .set I2C_BASE,  0xC8070000
31 .set I2C_DATA,  0x00
32 .set I2C_SLAD0, 0x04
33 .set I2C_CNTRL, 0x0c
34 .set I2C_DACNT, 0x10
35 .set I2C_CPSR0, 0x1c
36 .set I2C_CPSR1, 0x20
37 .set I2C_IMR,   0x24
38 .set I2C_SR,    0x30
39 .set I2C_SADDR, 0x44
40 .set AS3514_I2C_ADDR, 0x46
41 .set AS3514_IRQ_ENRD0, 0x25
42 .set PCLK, 24000000
43 .set I2C_CLK, 400000
44 .set I2C_PRESCALER, ((PCLK + I2C_CLK -1) / I2C_CLK)
45 .set I2C_PRESCALER_LOW, (I2C_PRESCALER & 0xff)
46 .set I2C_PRESCALER_HIGH, (I2C_PRESCALER >> 8)
47 #if I2C_PRESCALER_HIGH > 3
48 #error i2c prescaler too big!
49 #endif
51 /* Vectors */
53         ldr   pc, =start    /* reset vector */
54         /* next vectors are unused, halt cpu */
55 1:      b 1b
56 1:      b 1b
57 1:      b 1b
58 1:      b 1b
59 1:      b 1b
60 1:      b 1b
61 1:      b 1b
64 /* These values are filled in by mkamsboot - don't move them from offset 0x20 */
66 uclunpack_end:   .word   0 /* End of the ucl_unpack function */
67 uclunpack_size:  .word   0 /* Size in bytes of the ucl_unpack function */
69 ucl_of_end:      .word   0 /* End of the ucl-compressed OF image */
70 ucl_of_size:     .word   0 /* Size in bytes of the compressed OF image */
72 ucl_rb_end:      .word   0 /* End of the ucl-compressed RB image */
73 ucl_rb_size:     .word   0 /* Size in bytes of the compressed RB image */
75 ucl_dest:        .word   0 /* End of our destination buffer (end of memory) */
77 start:
78         /* First copy the UCL unpack function to the end of RAM */
79         ldr     r0, uclunpack_end   /* Source */
80         ldr     r1, uclunpack_size  /* Source length */
81         sub     r2, r0, r1          /* Source start - 1*/
83         ldr     r3, ucl_dest        /* Destination end */
85 uclcopy:
86         ldrb    r4, [r0], #-1
87         strb    r4, [r3], #-1
88         cmp     r2, r0
89         bne     uclcopy
91         /* store the new destination buffer */
92         str     r3, ucl_dest
94         /* enable gpio clock */
95         ldr     r0, =CGU_PERI
96         ldr     r1, [r0]
97         orr     r1, r1, #(1<<16)
98         str     r1, [r0]
101 /* TODO : M200V4 ? */
102 #if defined(SANSA_CLIP) || defined(SANSA_CLIPV2)
103 #define USB_PIN 6
104 #elif defined(SANSA_FUZE) || defined(SANSA_E200V2) || defined(SANSA_FUZEV2)
105 #define USB_PIN 3
106 #endif
108 #ifdef USB_PIN  /* TODO : remove this check when we'll have an USB driver */
109         ldr     r0, =GPIOA
110         mov     r1, #0
111         str     r1, [r0, #0x400]
112         ldr     r1, [r0, #(4*(1<<USB_PIN))]
113         cmp     r1, #0
114         bne     boot_of
115 #endif
116 #if defined(SANSA_C200V2)
117         /* Instead of checking the GPIO, check the audio master IRQ_ENRD0
118          * USB_STATUS bit on C200V2 */
120         ldr     r0, =CGU_PERI
121         ldr     r1, [r0]
122         /* enable i2c audio master clock */
123         orr     r1, r1, #(1<<17)
124         /* make sure 24MHz clk_main is selected */
125         bic     r1, r1, #0x7f
126         str     r1, [r0]
128         ldr     r0, =I2C_BASE
129         /* disable i2c interrupts */
130         mov     r1, #0
131         str     r1, [r0, #I2C_IMR]
132         /* setup prescaler */
133         mov     r1, #I2C_PRESCALER_LOW
134         str     r1, [r0, #I2C_CPSR0]
135         mov     r1, #I2C_PRESCALER_HIGH
136         str     r1, [r0, #I2C_CPSR1]
137         /* setup i2c slave address */
138         mov     r1, #(AS3514_I2C_ADDR << 1)
139         str     r1, [r0, #I2C_SLAD0]
140         mov     r2, #0x51
141         str     r2, [r0, #I2C_CNTRL]
143         /* wait for not busy */
145         ldr     r1, [r0, #I2C_SR]
146         tst     r1, #1
147         bne 1b
149         /* start read of irq_enrd0 */
150         mov     r1, #AS3514_IRQ_ENRD0
151         str     r1, [r0, #I2C_SADDR]
152         orr     r2, r2, #(1 << 1)
153         str     r2, [r0, #I2C_CNTRL]
154         mov     r1, #1
155         str     r1, [r0, #I2C_DACNT]
157         /* wait for transfer to finish */
159         ldr     r1, [r0, #I2C_DACNT]
160         cmp     r1, #0
161         bne     1b
163         /* load result and test USB_STATUS bit */
164         ldr     r1, [r0, #I2C_DATA]
165         tst     r1, #(1 << 3)
166         bne     boot_of
167 #endif
169         /* Here are model specific tests, for dual boot without a computer */
170         /* All models use left button */
171         /* /!\ Right button for c200v2 (left button is unkwown) */
173 #ifdef SANSA_CLIP
174 .set row, (1<<5) /* enable output on C5 */
175 .set col, (1<<0) /* read keyscan column B0 */
177         ldr     r0, =GPIOC
178         mov     r1, #row
179         str     r1, [r0, #0x400]
180         str     r1, [r0, #(4*row)]
182         ldr     r0, =GPIOB
183         mov     r1, #0
184         str     r1, [r0, #0x400]
185         ldr     r1, [r0, #(4*col)]
187         cmp     r1, #0
188         bne     boot_of
189 #elif defined(SANSA_CLIPV2)
190 .set row, (1<<4) /* enable output on D4 */
191 .set col, (1<<0) /* read keyscan column D0 */
193         ldr     r0, =GPIOD
194         mov     r1, #((1<<5)|(1<<4)|(1<<3)) /* all rows as output */
195         str     r1, [r0, #0x400]
197         /* all rows high */
198         mov     r1, #(1<<3)
199         str     r1, [r0, #(4*(1<<3))]
200         mov     r1, #(1<<4)
201         str     r1, [r0, #(4*(1<<4))]
202         mov     r1, #(1<<5)
203         str     r1, [r0, #(4*(1<<5))]
205         mov     r1, #0                      /* button row low */
206         str     r1, [r0, #(4*row)]
208         mov     r1, #5                      /* small delay */
209 1:      subs    r1, r1, #1
210         bne     1b
212         ldr     r1, [r0, #(4*col)]
214         cmp     r1, #0
215         beq     boot_of
216 #elif defined(SANSA_E200V2) || defined(SANSA_FUZE) || defined(SANSA_FUZEV2)
217         ldr     r0, =GPIOC
218         mov     r1, #0
219         str     r1, [r0, #0x400]
220         ldr     r1, [r0, #0x20]    /* read pin C3 */
222         cmp     r1, #0             /* C3 = #0 means button pressed */
223 #ifdef SANSA_FUZEV2
224         /* the logic is reversed on the fuzev2 */
225         bne     boot_of
226 #else
227         beq     boot_of
228 #endif /* SANSA_FUZEV2 */
230 #elif defined(SANSA_CLIPPLUS)
231         @ read pins
232         ldr     r0, =GPIOC
233         ldr     r1, [r0, #4*(1<<3)] @ read pin C3 "|<<"
235         ldr     r0, =GPIOA
236         ldr     r2, [r0, #4*(1<<1)] @ read pin A1 "Home"
238         orr     r2, r2, r1          @ c3 || A1
240         cmp     r2, #0              @ test input from pins
241         bne     boot_of             @ branch directly to OF if either pin high
242 #elif defined(SANSA_C200V2)
243         /* check for RIGHT on C6, should changed to LEFT as soon as it
244          * known in which pin that is in order for consistency  */
245         ldr     r0, =GPIOC
246         mov     r1, #0
247         str     r1, [r0, #0x400]      /* set pin to output */
249         ldr     r1, [r0, #256]        /* 1<<(6+2) */
250         cmp     r1, #0                /* C6 low means button pressed */
251         beq     boot_of
252 #elif defined(SANSA_M200V4)
253 .set row, (1<<5) /* enable output on A5 */
254 .set col, (1<<0) /* read keyscan column A0 */
256         ldr     r0, =GPIOA
257         mov     r1, #row
258         str     r1, [r0, #0x400]
259         str     r1, [r0, #(4*row)]
261         ldr     r2, [r0, #(4*col)]
263         /* check value read (1 means button pressed) */
264         cmp     r2, #0
265         bne     boot_of
266 #else
267         #error No target-specific key check defined!
268 #endif
271         /* The dualboot button was not held, so we boot rockbox */
272         ldr     r0, ucl_rb_end      /* Address of compressed image */
273         ldr     r1, ucl_rb_size     /* Compressed size */
274         b       decompress
276 boot_of:
277         ldr     r0, ucl_of_end      /* Address of compressed image */
278         ldr     r1, ucl_of_size     /* Compressed size */
281 decompress:
282         /* At this point:                                              */
283         /* r0 = source_end for UCL image to copy                       */
284         /* r1 = size of UCL image to copy                              */
286         ldr     r3, ucl_dest
287         add     r5, r3, #2      /* r5 is entry point of copy of uclunpack */
288                                 /* function, plus one (for thumb mode */
290         sub     r4, r3, r1      /* r4 := destination_start - 1 */
292 fw_copy:
293         ldrb    r2, [r0], #-1
294         strb    r2, [r3], #-1
295         cmp     r3, r4          /* Stop when we reached dest_start-1 */
296         bne     fw_copy
298         /* Call the ucl decompress function, which will branch to 0x0 */
299         /* on completion */
300         add     r0, r3, #1      /* r0 := Start of compressed image */
301                                 /* r1 already contains compressed size */
302         mov     r2, #0          /* r2 := Destination for unpacking */
303         bx      r5              /* Branch to uclunpack, switching to thumb */
305         /* never reached : uclunpack will branch to the reset vector (0x0) */