-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathS08flash-host.mu4
106 lines (84 loc) · 3.17 KB
/
S08flash-host.mu4
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
| This file is part of muforth: https://muforth.dev/
|
| Copyright 2002-2025 David Frech. (Read the LICENSE for details.)
loading S08 Flash programming (host)
hex
| S08 Flash memory layout.
|
| ffac my FTRIM - trims to 9.216M
| ffad my TRIM - ditto
| ffae FTRIM bit - factory trim for 8M
| ffaf TRIM byte - ditto
|
| ffb0 - ffbf is all about _security_
| ffb0 - b7 comparison key
| ffb8 - bc available
| ffbd NVPROT; copied to FPROT at reset
| ffbe available
| ffbf NVOPT; copied to FOPT at reset
|
| ffc0 - ffff Interrupt and reset vectors
forth
| XXX These are ugly.
05 constant mBlankCheck
20 constant mByteProgram
25 constant mBurstProgram
40 constant mPageErase
41 constant mMassErase
#512 constant /page ( S08 has 512 byte Flash pages - this is erase size)
: check-flash-status ( status)
." FSTAT=" dup u.
30 and if error" flash access or protection violation" then ;
| Fake "interact-level" code to do the flashing in a way that's compatible
| with the common flash code.
: t.flash-begin ;
: t.flash-end ;
: t.program ( buf a u)
mByteProgram t.flash check-flash-status ;
: t.erase ( a)
1 over image+ -rot
mPageErase t.flash check-flash-status ;
ld target/common/flash.mu4
| The last page of the flash contains the vectors.
@flash #flash + 1 Ki 2/ - constant @vector-page
| Check to see if we're going to clobber the bootloader and complain if
| we're not executing from RAM.
: ?clobbering-loader
@vector-page \m here u< not if ^ then ( not touching bootloader - Ok)
in-ram? @ if ^ then ( running in RAM - Ok)
error" You need to be running a RAM-based version of the chat code in
order to re-flash it. Consult a local guru. ;-)" ;
| Prepare to do a comparison or computation between data read from the
| target into a buffer, and data in our memory image. Read a chunk from the
| target into buf, and set m to point to the beginning of buf.
|
| Be careful about setting m. Some chunked read implementations use it, so
| set it *after* doing the read.
: setup-comparison ( buf a u - a u)
push 2dup r@ t.read pop rot m ! ;
| On the S08, erasing the vectors means erasing the TRIM bytes, the secure
| bits, and the bootloader. So be careful about re-programming things, esp
| the TRIMs and the secure bits. Copy from ffac to ffaf.
|
| If we've put trims into the image, don't overwrite these with the values
| from the chip. Use bitwise AND to merge the chip and the image!
: save-trims ( save them from the wrecking ball)
| cr ." save-trims"
pad 0ffac 4 setup-comparison
for dup image-c@ m* and over image-c! 1+ next drop ;
-: save-trims ( before erasing anything!)
flash flash-region
commit flash-region
boot ?clobbering-loader
flash-region
trims flash-region
vectors flash-region ; is flash-regions
-: verify-1 save-trims
flash verify-region report
commit verify-region report drop | we expect commit to differ!
boot verify-region report or
trims verify-region report or
vectors verify-region report or ; is verify-regions
-: 0= if ( everything verified)
cr ." Everything looks good!"
then ; is after-flashing ( diff)