1 \ *****************************************************************************
2 \ * Copyright (c) 2004, 2008 IBM Corporation
3 \ * All rights reserved.
4 \ * This program and the accompanying materials
5 \ * are made available under the terms of the BSD License
6 \ * which accompanies this distribution, and is available at
7 \ * http://www.opensource.org/licenses/bsd-license.php
10 \ * IBM Corporation - initial implementation
11 \ ****************************************************************************/
14 \ we do all flash accesses as 8-bit
16 ff000000 CONSTANT flash-addr
18 : >flash flash-addr + ;
21 : wait-for-flash-ready BEGIN 0 flash@ 80 and UNTIL ;
22 : erase-flash-block ( offset -- )
23 cr dup 8 .r ." Erasing..."
24 20 over flash! d0 swap flash! wait-for-flash-ready ;
25 : write-flash ( data offset -- )
26 40 over flash! flash! wait-for-flash-ready ;
27 : write-flash-buffer ( addr offset -- )
28 e8 over flash! wait-for-flash-ready 1f over flash!
29 20 0 DO over i + c@ over i + flash! LOOP
30 d0 over flash! wait-for-flash-ready 2drop ;
31 : write-flash-block ( addr offset -- ) \ always writes 128kB!
33 20000 0 DO over i + over i + write-flash-buffer 20 +LOOP 2drop
35 : flash ( addr offset size -- )
36 BEGIN dup 0 > WHILE >r dup erase-flash-block 2dup write-flash-block
37 >r 20000 + r> 20000 + r> 20000 - REPEAT drop 2drop -1 0 flash! ;
39 : flash-it get-load-base 0 e0000 flash ;
40 : flash4 get-load-base 0 400000 flash ;
43 : flash-image-size ( addr -- size ) 30 + rx@ ;