2009-05-28 18:27:08 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Rafaël Carré
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
.text
|
|
|
|
|
|
|
|
/* AS3525 hardware registers */
|
|
|
|
.set GPIOA, 0xC80B0000
|
|
|
|
.set GPIOB, 0xC80C0000
|
|
|
|
.set GPIOC, 0xC80D0000
|
|
|
|
.set GPIOD, 0xC80E0000
|
|
|
|
.set CGU_PERI, 0xC80F0014
|
|
|
|
|
|
|
|
|
|
|
|
/* Vectors */
|
|
|
|
|
|
|
|
ldr pc, =start /* reset vector */
|
2010-03-04 00:08:53 +00:00
|
|
|
/* next vectors are unused, halt cpu */
|
|
|
|
1: b 1b
|
|
|
|
1: b 1b
|
|
|
|
1: b 1b
|
|
|
|
1: b 1b
|
|
|
|
1: b 1b
|
|
|
|
1: b 1b
|
|
|
|
1: b 1b
|
|
|
|
|
2009-05-28 18:27:08 +00:00
|
|
|
|
|
|
|
/* These values are filled in by mkamsboot - don't move them from offset 0x20 */
|
|
|
|
|
|
|
|
uclunpack_end: .word 0 /* End of the ucl_unpack function */
|
|
|
|
uclunpack_size: .word 0 /* Size in bytes of the ucl_unpack function */
|
|
|
|
|
|
|
|
ucl_of_end: .word 0 /* End of the ucl-compressed OF image */
|
|
|
|
ucl_of_size: .word 0 /* Size in bytes of the compressed OF image */
|
|
|
|
|
|
|
|
ucl_rb_end: .word 0 /* End of the ucl-compressed RB image */
|
|
|
|
ucl_rb_size: .word 0 /* Size in bytes of the compressed RB image */
|
|
|
|
|
mkamsboot: prevents 2 potential problems
We checked if the new firmware block (bootloader+ucl function+packed
bootloader & OF) fit in the OF file, but not if it would run properly.
For example the Clipv2 OF is bigger than 0x50000 bytes uncompressed, but
it fitted in this space when packed and concatenated to a packed
bootloader + ucl function and dualboot code (but we use 1MB of RAM and
not 0x50000 anyway).
Now we check that both bootloader and OF are small enough to be unpacked
at runtime: the unpacked data must be smaller than available memory and
not overlap with ucl function and packed data (although the unpacked and
packed data could probably overlap a bit, I don't know how to calculate
this and this could be quite complex).
total_size() is replaced by check_sizes() which will perform all the
checks and set an error string if the firmware can't be patched.
(both mkamsboot and rbutilqt modified accordingly)
The second problem is that dualboot.S assumed r3 and r5 were left
untouched in the device specific checks. This was undocumented and very
error prone when modifying these checks.
r3 is the last byte of packed copy (bootloader or OF)
r5 is the entry point of uclunpack function derived from r3, so move r5
calculation after the device specific code.
Even if r3 is currently unused in the device specific code, we store it
in memory after copying the ucl function, when it points to the last byte
of packed data (not yet copied at this point since we didn't chose if we
boot the OF or the bootloader), and restore it just before using it so no
restriction is placed on registers usage in device specific code.
Add a new variable ucl_dest in dualboot.S set by mkamsboot.c, which
represents the last bound of buffer where we copy the ucl function, and
then the packed data (bootloader or OF).
RAM_SIZE definition is moved from dualboot.S to mkamsboot.c new
model_memory_size(), where it is a bit better documented.
Tested on e200v2 and Clip+
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24772 a1c6a512-1295-4272-9138-f99709370657
2010-02-19 14:10:26 +00:00
|
|
|
ucl_dest: .word 0 /* End of our destination buffer (end of memory) */
|
2009-05-28 18:27:08 +00:00
|
|
|
|
|
|
|
start:
|
|
|
|
/* First copy the UCL unpack function to the end of RAM */
|
|
|
|
ldr r0, uclunpack_end /* Source */
|
|
|
|
ldr r1, uclunpack_size /* Source length */
|
|
|
|
sub r2, r0, r1 /* Source start - 1*/
|
|
|
|
|
mkamsboot: prevents 2 potential problems
We checked if the new firmware block (bootloader+ucl function+packed
bootloader & OF) fit in the OF file, but not if it would run properly.
For example the Clipv2 OF is bigger than 0x50000 bytes uncompressed, but
it fitted in this space when packed and concatenated to a packed
bootloader + ucl function and dualboot code (but we use 1MB of RAM and
not 0x50000 anyway).
Now we check that both bootloader and OF are small enough to be unpacked
at runtime: the unpacked data must be smaller than available memory and
not overlap with ucl function and packed data (although the unpacked and
packed data could probably overlap a bit, I don't know how to calculate
this and this could be quite complex).
total_size() is replaced by check_sizes() which will perform all the
checks and set an error string if the firmware can't be patched.
(both mkamsboot and rbutilqt modified accordingly)
The second problem is that dualboot.S assumed r3 and r5 were left
untouched in the device specific checks. This was undocumented and very
error prone when modifying these checks.
r3 is the last byte of packed copy (bootloader or OF)
r5 is the entry point of uclunpack function derived from r3, so move r5
calculation after the device specific code.
Even if r3 is currently unused in the device specific code, we store it
in memory after copying the ucl function, when it points to the last byte
of packed data (not yet copied at this point since we didn't chose if we
boot the OF or the bootloader), and restore it just before using it so no
restriction is placed on registers usage in device specific code.
Add a new variable ucl_dest in dualboot.S set by mkamsboot.c, which
represents the last bound of buffer where we copy the ucl function, and
then the packed data (bootloader or OF).
RAM_SIZE definition is moved from dualboot.S to mkamsboot.c new
model_memory_size(), where it is a bit better documented.
Tested on e200v2 and Clip+
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24772 a1c6a512-1295-4272-9138-f99709370657
2010-02-19 14:10:26 +00:00
|
|
|
ldr r3, ucl_dest /* Destination end */
|
2009-05-28 18:27:08 +00:00
|
|
|
|
|
|
|
uclcopy:
|
|
|
|
ldrb r4, [r0], #-1
|
|
|
|
strb r4, [r3], #-1
|
|
|
|
cmp r2, r0
|
|
|
|
bne uclcopy
|
|
|
|
|
mkamsboot: prevents 2 potential problems
We checked if the new firmware block (bootloader+ucl function+packed
bootloader & OF) fit in the OF file, but not if it would run properly.
For example the Clipv2 OF is bigger than 0x50000 bytes uncompressed, but
it fitted in this space when packed and concatenated to a packed
bootloader + ucl function and dualboot code (but we use 1MB of RAM and
not 0x50000 anyway).
Now we check that both bootloader and OF are small enough to be unpacked
at runtime: the unpacked data must be smaller than available memory and
not overlap with ucl function and packed data (although the unpacked and
packed data could probably overlap a bit, I don't know how to calculate
this and this could be quite complex).
total_size() is replaced by check_sizes() which will perform all the
checks and set an error string if the firmware can't be patched.
(both mkamsboot and rbutilqt modified accordingly)
The second problem is that dualboot.S assumed r3 and r5 were left
untouched in the device specific checks. This was undocumented and very
error prone when modifying these checks.
r3 is the last byte of packed copy (bootloader or OF)
r5 is the entry point of uclunpack function derived from r3, so move r5
calculation after the device specific code.
Even if r3 is currently unused in the device specific code, we store it
in memory after copying the ucl function, when it points to the last byte
of packed data (not yet copied at this point since we didn't chose if we
boot the OF or the bootloader), and restore it just before using it so no
restriction is placed on registers usage in device specific code.
Add a new variable ucl_dest in dualboot.S set by mkamsboot.c, which
represents the last bound of buffer where we copy the ucl function, and
then the packed data (bootloader or OF).
RAM_SIZE definition is moved from dualboot.S to mkamsboot.c new
model_memory_size(), where it is a bit better documented.
Tested on e200v2 and Clip+
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24772 a1c6a512-1295-4272-9138-f99709370657
2010-02-19 14:10:26 +00:00
|
|
|
/* store the new destination buffer */
|
|
|
|
str r3, ucl_dest
|
2009-05-28 18:27:08 +00:00
|
|
|
|
|
|
|
/* enable gpio clock */
|
|
|
|
ldr r0, =CGU_PERI
|
|
|
|
ldr r1, [r0]
|
|
|
|
orr r1, r1, #(1<<16)
|
|
|
|
str r1, [r0]
|
|
|
|
|
|
|
|
|
mkamsboot: prevents 2 potential problems
We checked if the new firmware block (bootloader+ucl function+packed
bootloader & OF) fit in the OF file, but not if it would run properly.
For example the Clipv2 OF is bigger than 0x50000 bytes uncompressed, but
it fitted in this space when packed and concatenated to a packed
bootloader + ucl function and dualboot code (but we use 1MB of RAM and
not 0x50000 anyway).
Now we check that both bootloader and OF are small enough to be unpacked
at runtime: the unpacked data must be smaller than available memory and
not overlap with ucl function and packed data (although the unpacked and
packed data could probably overlap a bit, I don't know how to calculate
this and this could be quite complex).
total_size() is replaced by check_sizes() which will perform all the
checks and set an error string if the firmware can't be patched.
(both mkamsboot and rbutilqt modified accordingly)
The second problem is that dualboot.S assumed r3 and r5 were left
untouched in the device specific checks. This was undocumented and very
error prone when modifying these checks.
r3 is the last byte of packed copy (bootloader or OF)
r5 is the entry point of uclunpack function derived from r3, so move r5
calculation after the device specific code.
Even if r3 is currently unused in the device specific code, we store it
in memory after copying the ucl function, when it points to the last byte
of packed data (not yet copied at this point since we didn't chose if we
boot the OF or the bootloader), and restore it just before using it so no
restriction is placed on registers usage in device specific code.
Add a new variable ucl_dest in dualboot.S set by mkamsboot.c, which
represents the last bound of buffer where we copy the ucl function, and
then the packed data (bootloader or OF).
RAM_SIZE definition is moved from dualboot.S to mkamsboot.c new
model_memory_size(), where it is a bit better documented.
Tested on e200v2 and Clip+
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24772 a1c6a512-1295-4272-9138-f99709370657
2010-02-19 14:10:26 +00:00
|
|
|
/* TODO : M200V4 ? */
|
2009-05-28 18:27:08 +00:00
|
|
|
#if defined(SANSA_C200V2)
|
mkamsboot: prevents 2 potential problems
We checked if the new firmware block (bootloader+ucl function+packed
bootloader & OF) fit in the OF file, but not if it would run properly.
For example the Clipv2 OF is bigger than 0x50000 bytes uncompressed, but
it fitted in this space when packed and concatenated to a packed
bootloader + ucl function and dualboot code (but we use 1MB of RAM and
not 0x50000 anyway).
Now we check that both bootloader and OF are small enough to be unpacked
at runtime: the unpacked data must be smaller than available memory and
not overlap with ucl function and packed data (although the unpacked and
packed data could probably overlap a bit, I don't know how to calculate
this and this could be quite complex).
total_size() is replaced by check_sizes() which will perform all the
checks and set an error string if the firmware can't be patched.
(both mkamsboot and rbutilqt modified accordingly)
The second problem is that dualboot.S assumed r3 and r5 were left
untouched in the device specific checks. This was undocumented and very
error prone when modifying these checks.
r3 is the last byte of packed copy (bootloader or OF)
r5 is the entry point of uclunpack function derived from r3, so move r5
calculation after the device specific code.
Even if r3 is currently unused in the device specific code, we store it
in memory after copying the ucl function, when it points to the last byte
of packed data (not yet copied at this point since we didn't chose if we
boot the OF or the bootloader), and restore it just before using it so no
restriction is placed on registers usage in device specific code.
Add a new variable ucl_dest in dualboot.S set by mkamsboot.c, which
represents the last bound of buffer where we copy the ucl function, and
then the packed data (bootloader or OF).
RAM_SIZE definition is moved from dualboot.S to mkamsboot.c new
model_memory_size(), where it is a bit better documented.
Tested on e200v2 and Clip+
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24772 a1c6a512-1295-4272-9138-f99709370657
2010-02-19 14:10:26 +00:00
|
|
|
#define USB_PIN 1 /* FIXME: not correct on some c200v2s */
|
2009-05-28 18:27:08 +00:00
|
|
|
#elif defined(SANSA_CLIP) || defined(SANSA_CLIPV2)
|
|
|
|
#define USB_PIN 6
|
2010-02-26 13:55:17 +00:00
|
|
|
#elif defined(SANSA_FUZE) || defined(SANSA_E200V2) || defined(SANSA_FUZEV2)
|
2009-05-28 18:27:08 +00:00
|
|
|
#define USB_PIN 3
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USB_PIN /* TODO : remove this check when we'll have an USB driver */
|
|
|
|
ldr r0, =GPIOA
|
|
|
|
mov r1, #0
|
|
|
|
str r1, [r0, #0x400]
|
|
|
|
ldr r1, [r0, #(4*(1<<USB_PIN))]
|
|
|
|
cmp r1, #0
|
|
|
|
bne boot_of
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Here are model specific tests, for dual boot without a computer */
|
|
|
|
/* All models use left button */
|
|
|
|
/* /!\ Right button for c200v2 (left button is unkwown) */
|
|
|
|
|
|
|
|
#ifdef SANSA_CLIP
|
|
|
|
.set row, (1<<5) /* enable output on C5 */
|
|
|
|
.set col, (1<<0) /* read keyscan column B0 */
|
|
|
|
|
|
|
|
ldr r0, =GPIOC
|
|
|
|
mov r1, #row
|
|
|
|
str r1, [r0, #0x400]
|
|
|
|
str r1, [r0, #(4*row)]
|
|
|
|
|
|
|
|
ldr r0, =GPIOB
|
|
|
|
mov r1, #0
|
|
|
|
str r1, [r0, #0x400]
|
|
|
|
ldr r1, [r0, #(4*col)]
|
|
|
|
|
|
|
|
cmp r1, #0
|
|
|
|
bne boot_of
|
|
|
|
#elif defined(SANSA_CLIPV2)
|
|
|
|
.set row, (1<<4) /* enable output on D4 */
|
|
|
|
.set col, (1<<0) /* read keyscan column D0 */
|
|
|
|
|
|
|
|
ldr r0, =GPIOD
|
|
|
|
mov r1, #((1<<5)|(1<<4)|(1<<3)) /* all rows as output */
|
|
|
|
str r1, [r0, #0x400]
|
|
|
|
|
|
|
|
/* all rows high */
|
|
|
|
mov r1, #(1<<3)
|
|
|
|
str r1, [r0, #(4*(1<<3))]
|
|
|
|
mov r1, #(1<<4)
|
|
|
|
str r1, [r0, #(4*(1<<4))]
|
|
|
|
mov r1, #(1<<5)
|
|
|
|
str r1, [r0, #(4*(1<<5))]
|
|
|
|
|
|
|
|
mov r1, #0 /* button row low */
|
|
|
|
str r1, [r0, #(4*row)]
|
|
|
|
|
|
|
|
mov r1, #5 /* small delay */
|
|
|
|
1: subs r1, r1, #1
|
|
|
|
bne 1b
|
|
|
|
|
|
|
|
ldr r1, [r0, #(4*col)]
|
|
|
|
|
|
|
|
cmp r1, #0
|
|
|
|
beq boot_of
|
2010-02-26 13:55:17 +00:00
|
|
|
#elif defined(SANSA_E200V2) || defined(SANSA_FUZE) || defined(SANSA_FUZEV2)
|
2009-05-28 18:27:08 +00:00
|
|
|
ldr r0, =GPIOC
|
|
|
|
mov r1, #0
|
|
|
|
str r1, [r0, #0x400]
|
|
|
|
ldr r1, [r0, #0x20] /* read pin C3 */
|
|
|
|
|
|
|
|
cmp r1, #0 /* C3 = #0 means button pressed */
|
2010-02-26 13:55:17 +00:00
|
|
|
#ifdef SANSA_FUZEV2
|
|
|
|
/* the logic is reversed on the fuzev2 */
|
|
|
|
bne boot_of
|
|
|
|
#else
|
2009-05-28 18:27:08 +00:00
|
|
|
beq boot_of
|
2010-02-26 13:55:17 +00:00
|
|
|
#endif /* SANSA_FUZEV2 */
|
|
|
|
|
2010-01-13 03:05:29 +00:00
|
|
|
#elif defined(SANSA_CLIPPLUS)
|
2010-02-08 06:43:47 +00:00
|
|
|
@ read pins
|
|
|
|
ldr r0, =GPIOC
|
|
|
|
ldr r1, [r0, #4*(1<<3)] @ read pin C3 "|<<"
|
|
|
|
|
|
|
|
ldr r0, =GPIOA
|
|
|
|
ldr r2, [r0, #4*(1<<1)] @ read pin A1 "Home"
|
|
|
|
|
|
|
|
orr r2, r2, r1 @ c3 || A1
|
|
|
|
|
|
|
|
cmp r2, #0 @ test input from pins
|
|
|
|
bne boot_of @ branch directly to OF if either pin high
|
2009-05-28 18:27:08 +00:00
|
|
|
#elif defined(SANSA_C200V2)
|
|
|
|
/* check for RIGHT on C6, should changed to LEFT as soon as it
|
|
|
|
* known in which pin that is in order for consistency */
|
|
|
|
ldr r0, =GPIOC
|
|
|
|
mov r1, #0
|
|
|
|
str r1, [r0, #0x400] /* set pin to output */
|
|
|
|
|
|
|
|
ldr r1, [r0, #256] /* 1<<(6+2) */
|
|
|
|
cmp r1, #0 /* C6 low means button pressed */
|
|
|
|
beq boot_of
|
|
|
|
#elif defined(SANSA_M200V4)
|
|
|
|
.set row, (1<<5) /* enable output on A5 */
|
|
|
|
.set col, (1<<0) /* read keyscan column A0 */
|
|
|
|
|
|
|
|
ldr r0, =GPIOA
|
|
|
|
mov r1, #row
|
|
|
|
str r1, [r0, #0x400]
|
|
|
|
str r1, [r0, #(4*row)]
|
|
|
|
|
|
|
|
ldr r2, [r0, #(4*col)]
|
|
|
|
|
|
|
|
/* check value read (1 means button pressed) */
|
|
|
|
cmp r2, #0
|
|
|
|
bne boot_of
|
|
|
|
#else
|
|
|
|
#error No target-specific key check defined!
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* The dualboot button was not held, so we boot rockbox */
|
|
|
|
ldr r0, ucl_rb_end /* Address of compressed image */
|
|
|
|
ldr r1, ucl_rb_size /* Compressed size */
|
|
|
|
b decompress
|
|
|
|
|
|
|
|
boot_of:
|
|
|
|
ldr r0, ucl_of_end /* Address of compressed image */
|
|
|
|
ldr r1, ucl_of_size /* Compressed size */
|
|
|
|
|
|
|
|
|
|
|
|
decompress:
|
|
|
|
/* At this point: */
|
|
|
|
/* r0 = source_end for UCL image to copy */
|
|
|
|
/* r1 = size of UCL image to copy */
|
|
|
|
|
mkamsboot: prevents 2 potential problems
We checked if the new firmware block (bootloader+ucl function+packed
bootloader & OF) fit in the OF file, but not if it would run properly.
For example the Clipv2 OF is bigger than 0x50000 bytes uncompressed, but
it fitted in this space when packed and concatenated to a packed
bootloader + ucl function and dualboot code (but we use 1MB of RAM and
not 0x50000 anyway).
Now we check that both bootloader and OF are small enough to be unpacked
at runtime: the unpacked data must be smaller than available memory and
not overlap with ucl function and packed data (although the unpacked and
packed data could probably overlap a bit, I don't know how to calculate
this and this could be quite complex).
total_size() is replaced by check_sizes() which will perform all the
checks and set an error string if the firmware can't be patched.
(both mkamsboot and rbutilqt modified accordingly)
The second problem is that dualboot.S assumed r3 and r5 were left
untouched in the device specific checks. This was undocumented and very
error prone when modifying these checks.
r3 is the last byte of packed copy (bootloader or OF)
r5 is the entry point of uclunpack function derived from r3, so move r5
calculation after the device specific code.
Even if r3 is currently unused in the device specific code, we store it
in memory after copying the ucl function, when it points to the last byte
of packed data (not yet copied at this point since we didn't chose if we
boot the OF or the bootloader), and restore it just before using it so no
restriction is placed on registers usage in device specific code.
Add a new variable ucl_dest in dualboot.S set by mkamsboot.c, which
represents the last bound of buffer where we copy the ucl function, and
then the packed data (bootloader or OF).
RAM_SIZE definition is moved from dualboot.S to mkamsboot.c new
model_memory_size(), where it is a bit better documented.
Tested on e200v2 and Clip+
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24772 a1c6a512-1295-4272-9138-f99709370657
2010-02-19 14:10:26 +00:00
|
|
|
ldr r3, ucl_dest
|
|
|
|
add r5, r3, #2 /* r5 is entry point of copy of uclunpack */
|
|
|
|
/* function, plus one (for thumb mode */
|
|
|
|
|
2009-05-28 18:27:08 +00:00
|
|
|
sub r4, r3, r1 /* r4 := destination_start - 1 */
|
|
|
|
|
|
|
|
fw_copy:
|
|
|
|
ldrb r2, [r0], #-1
|
|
|
|
strb r2, [r3], #-1
|
|
|
|
cmp r3, r4 /* Stop when we reached dest_start-1 */
|
|
|
|
bne fw_copy
|
|
|
|
|
|
|
|
/* Call the ucl decompress function, which will branch to 0x0 */
|
|
|
|
/* on completion */
|
|
|
|
add r0, r3, #1 /* r0 := Start of compressed image */
|
|
|
|
/* r1 already contains compressed size */
|
|
|
|
mov r2, #0 /* r2 := Destination for unpacking */
|
|
|
|
bx r5 /* Branch to uclunpack, switching to thumb */
|
|
|
|
|
|
|
|
/* never reached : uclunpack will branch to the reset vector (0x0) */
|