fix another keymap (FS#10237 by Tomer Shalev)
[kugel-rb.git] / rbutil / mkamsboot / dualboot.S
bloba4d046906066a94c3480fae9a30912074c83f9b5
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 .set IRAM_SIZE, 0x50000
26 .set GPIOA,     0xC80B0000
27 .set GPIOB,     0xC80C0000
28 .set GPIOC,     0xC80D0000
29 .set GPIOD,     0xC80E0000
30 .set CGU_PERI,  0xC80F0014
33 /* Vectors */
34         ldr   pc, =start
35 .word   0
36 .word   0
37 .word   0
38 .word   0
39 .word   0
40 .word   0
41 .word   0
43 /* These values are filled in by mkamsboot - don't move them from offset 0x20 */
44 uclunpack_end:   .word   0 /* End of the ucl_unpack function */
45 uclunpack_size:  .word   0 /* Size in bytes of the ucl_unpack function */
47 ucl_of_end:      .word   0 /* End of the ucl-compressed OF image */
48 ucl_of_size:     .word   0 /* Size in bytes of the compressed OF image */
50 ucl_rb_end:      .word   0 /* End of the ucl-compressed RB image */
51 ucl_rb_size:     .word   0 /* Size in bytes of the compressed RB image */
54 start:
55         /* First copy the UCL unpack function to the end of RAM */
56         ldr   r0, uclunpack_end     /* Source */
57         ldr   r1, uclunpack_size    /* Source length */
58         sub   r2, r0, r1            /* Source start - 1*/
60         ldr   r3, =(IRAM_SIZE-1)    /* Destination end */
62 uclcopy:
63         ldrb  r4, [r0], #-1
64         strb  r4, [r3], #-1
65         cmp   r2, r0
66         bne   uclcopy
68         add   r5, r3, #2            /* r5 is entry point of copy of uclunpack */
69                                     /* function, plus one (for thumb mode */
71         /* enable gpio clock */
72         ldr   r0, =CGU_PERI
73         ldr   r1, [r0]
74         orr   r1, r1, #(1<<16)
75         str   r1, [r0]
77         
78 #ifndef SANSA_M200V4  /* this doesnt work for m200 */         
79         /* we check A3 unconditionally of the model because it seems to be */
80         /* either hold, either usb on every model */
81         /* TODO: make it USB on all AMS Sansas for consistency, USB is safer too */
83         ldr   r0, =GPIOA
84         mov   r1, #0
85         str   r1, [r0, #0x400]
86 #ifdef SANSA_C200V2
87         ldr   r1, [r0, #0x8]    /* USB is A1 on C200 */
88 #elif defined(SANSA_CLIP)
89         ldr   r1, [r0, #0x100]    /* USB is A6 on Clip */
90 #else
91         ldr   r1, [r0, #0x20]    /* read pin A3 */
92 #endif
93         cmp   r1, #0
94         bne   boot_of
95 #endif
97         /* here are model specific tests, for dual boot without a computer */
99 #ifdef SANSA_CLIP
100         /* LEFT button */
101 .set row, (1<<5) /* enable output on C5 */
102         ldr   r0, =GPIOC
103         mov   r1, #row
104         str   r1, [r0, #0x400]
105         str   r1, [r0, #(4*row)]
107 .set col, (1<<0) /* read keyscan column B0 */
108         ldr   r0, =GPIOB
109         mov   r1, #0
110         str   r1, [r0, #0x400]
111         ldr   r1, [r0, #(4*col)]
113         cmp   r1, #0
114         bne   boot_of
115 #elif defined(SANSA_E200V2) || defined(SANSA_FUZE)
116         /* LEFT button */
117         ldr   r0, =GPIOC
118         mov   r1, #0
119         str   r1, [r0, #0x400]
120         ldr   r1, [r0, #0x20]    /* read pin C3 */
122         cmp   r1, #0             /* C3 = #0 means button pressed */
123         beq   boot_of
124 #elif defined(SANSA_C200V2)
125         /* check for RIGHT on C6, should maybe changed to LEFT as soon as it
126          * known in which pin that is in order for consistency  */
127         ldr   r0, =GPIOC
128         mov   r1, #0
129         str   r1, [r0, #0x400]      /* set pin to output */
131         ldr   r1, [r0, #256]        /* 1<<(6+2) */
132         cmp   r1, #0                /* C6 low means button pressed */
133         beq   boot_of
134 #elif defined(SANSA_M200V4)
135         /* LEFT button */
136 .set row, (1<<5) /* enable output on A5 */
137         ldr   r0, =GPIOA
138         mov   r1, #row
139         str   r1, [r0, #0x400]
140         str   r1, [r0, #(4*row)]
142 .set col, (1<<0) /* read keyscan column A0 */
143         ldr   r2, [r0, #(4*col)]
145         /* check value read (1 means button pressed) */
146         cmp   r2, #0
147         bne   boot_of
148 #else
149         #error No target-specific key check defined!
150 #endif
152         /* No button was held, so we boot rockbox */
153         ldr   r0, ucl_rb_end   /* Address of compressed image */
154         ldr   r1, ucl_rb_size    /* Compressed size */
155         b     decompress
157 boot_of:
158         ldr   r0, ucl_of_end     /* Address of compressed image */
159         ldr   r1, ucl_of_size    /* Compressed size */
162 decompress:
163         /* At this point:                                              */
164         /* r5 = entry point (plus one for thumb) of uclunpack function */
165         /* r3 = destination_end for copy of UCL image                  */
166         /* r0 = source_end for UCL image to copy                       */
167         /* r1 = size of UCL image to copy                              */
169         sub   r4, r3, r1      /* r4 := destination_start - 1 */
170         
171 fw_copy:
172         ldrb  r2, [r0], #-1
173         strb  r2, [r3], #-1
174         cmp   r3, r4          /* Stop when we reached dest_start-1 */
175         bne   fw_copy
177         /* Call the ucl decompress function, which will branch to 0x0 */
178         /* on completion */
179         add   r0, r3, #1      /* r0 := Start of compressed image */
180                               /* r1 already contains compressed size */
181         mov   r2, #0          /* r2 := Destination for unpacking */
182         bx    r5              /* Branch to uclunpack, switching to thumb */
184         /* never reached */