summaryrefslogtreecommitdiff
path: root/rbutil/mkamsboot/dualboot
diff options
context:
space:
mode:
authorRafaël Carré <rafael.carre@gmail.com>2010-02-19 14:10:26 +0000
committerRafaël Carré <rafael.carre@gmail.com>2010-02-19 14:10:26 +0000
commitb6c20c17e462d29192ea579ee061af8437457bac (patch)
tree8a4320a326623264a7424db75444b190850d1168 /rbutil/mkamsboot/dualboot
parent5bae969a3e7d2bbc3119d913335fc325402f2700 (diff)
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
Diffstat (limited to 'rbutil/mkamsboot/dualboot')
-rw-r--r--rbutil/mkamsboot/dualboot/dualboot.S24
1 files changed, 10 insertions, 14 deletions
diff --git a/rbutil/mkamsboot/dualboot/dualboot.S b/rbutil/mkamsboot/dualboot/dualboot.S
index cf11b66cfa..a27ab34d85 100644
--- a/rbutil/mkamsboot/dualboot/dualboot.S
+++ b/rbutil/mkamsboot/dualboot/dualboot.S
@@ -21,13 +21,6 @@
.text
-#if defined(SANSA_CLIPV2)
-.set RAM_SIZE, 0x100000 /* Use 1MB of SDRAM (bigger firmware do not fit in
- * 0x50000 bytes) */
-#else
-.set RAM_SIZE, 0x50000 /* Use full IRAM (or part of SDRAM on as3525v2) */
-#endif
-
/* AS3525 hardware registers */
.set GPIOA, 0xC80B0000
.set GPIOB, 0xC80C0000
@@ -59,6 +52,7 @@ 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 */
+ucl_dest: .word 0 /* End of our destination buffer (end of memory) */
start:
/* First copy the UCL unpack function to the end of RAM */
@@ -66,7 +60,7 @@ start:
ldr r1, uclunpack_size /* Source length */
sub r2, r0, r1 /* Source start - 1*/
- ldr r3, =(RAM_SIZE-1) /* Destination end */
+ ldr r3, ucl_dest /* Destination end */
uclcopy:
ldrb r4, [r0], #-1
@@ -74,8 +68,8 @@ uclcopy:
cmp r2, r0
bne uclcopy
- add r5, r3, #2 /* r5 is entry point of copy of uclunpack */
- /* function, plus one (for thumb mode */
+ /* store the new destination buffer */
+ str r3, ucl_dest
/* enable gpio clock */
ldr r0, =CGU_PERI
@@ -84,9 +78,9 @@ uclcopy:
str r1, [r0]
-/* TODO : M200V4 */
+/* TODO : M200V4 ? */
#if defined(SANSA_C200V2)
-#define USB_PIN 1
+#define USB_PIN 1 /* FIXME: not correct on some c200v2s */
#elif defined(SANSA_CLIP) || defined(SANSA_CLIPV2)
#define USB_PIN 6
#elif defined(SANSA_FUZE) || defined(SANSA_E200V2)
@@ -210,11 +204,13 @@ boot_of:
decompress:
/* At this point: */
- /* r5 = entry point (plus one for thumb) of uclunpack function */
- /* r3 = destination_end for copy of UCL image */
/* r0 = source_end for UCL image to copy */
/* r1 = size of UCL image to copy */
+ ldr r3, ucl_dest
+ add r5, r3, #2 /* r5 is entry point of copy of uclunpack */
+ /* function, plus one (for thumb mode */
+
sub r4, r3, r1 /* r4 := destination_start - 1 */
fw_copy: