1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
@ Prepare regs
mov r14, #0x24000000 @ R14 = 0x24000000
orr r13, r14, #0xaa00
orr r13, r13, #0xaa @ R13 = 0x2400aaaa
orr r12, r14, #0x5500
orr r12, r12, #0x54 @ R12 = 0x24005554
mov r11, #0xaa @ R11 = 0xaa
mov r10, #0x55 @ R10 = 0x55
mov r9, #0xa0 @ R9 = 0xa0
mov r8, #0x80 @ R8 = 0x80
mov r7, #0x30 @ R7 = 0x30
ldr r6, addr @ R6 = destination address
ldr r5, size @ R5 = image size
adr r4, data @ R4 = pointer to start of data
loop:
tst r6, #0xff @ If we're not on a sector boundary, don't erase
bne skiperase
strh r11, [r13] @ Write 0xaa to 0x2400aaaa (command phase 1)
strh r10, [r12] @ Write 0x55 to 0x24005554 (command phase 2)
strh r8, [r13] @ Write 0x80 to 0x2400aaaa (erase operation)
strh r11, [r13] @ Write 0xaa to 0x2400aaaa (erase verify 1)
strh r10, [r12] @ Write 0x55 to 0x24005554 (erase verify 2)
strh r7, [r6] @ Write 0x30 to destination address (erase sector)
ldrh r0, [r14] @ Wait for bit 6 to stop toggling
waiterase:
ldrh r1, [r14]
eor r0, r0, r1
tst r0, #0x40
mov r0, r1
bne waiterase
skiperase:
ldrh r3, [r4], #2 @ Load data for the current word
strh r11, [r13] @ Write 0xaa to 0x2400aaaa (command phase 1)
strh r10, [r12] @ Write 0x55 to 0x24005554 (command phase 2)
strh r9, [r13] @ Write 0xa0 to 0x2400aaaa (program word)
strh r3, [r6], #2 @ Write the data word to the destination address
ldrh r0, [r14] @ Wait for bit 6 to stop toggling
waitwrite:
ldrh r1, [r14]
eor r0, r0, r1
tst r0, #0x40
mov r0, r1
bne waitwrite
subs r5, r5, #2 @ Check if there is anything left to be done
bhi loop
hang:
b hang
addr:
.ascii "ADDR" @ Will be replaced by genflasher.py
size:
.ascii "SIZE" @ Will be replaced by genflasher.py
data: @ The data to be flashed will be appended to this file
|