Author: wmb
Date: 2007-10-29 23:02:39 +0100 (Mon, 29 Oct 2007)
New Revision: 703
Added:
dev/olpc/cafenand/redboot.fth
Modified:
cpu/x86/pc/olpc/devices.fth
cpu/x86/pc/olpc/fsupdate.fth
cpu/x86/pc/olpc/gui.fth
cpu/x86/pc/olpc/security.fth
dev/olpc/cafenand/badblock.fth
dev/olpc/cafenand/cafenand.bth
dev/olpc/cafenand/cafenand.fth
dev/olpc/cafenand/methods.fth
ofw/fs/jffs2/jffs2.fth
Log:
Fixed a bug in filesystem update via USB key and implemented NAND partition support.
Modified: cpu/x86/pc/olpc/devices.fth
===================================================================
--- cpu/x86/pc/olpc/devices.fth 2007-10-29 16:21:34 UTC (rev 702)
+++ cpu/x86/pc/olpc/devices.fth 2007-10-29 22:02:39 UTC (rev 703)
@@ -165,6 +165,7 @@
\ This alias will work for either the CS5536 NAND FLASH
\ or the CaFe NAND FLASH, whichever is present.
devalias nand /nandflash
+devalias mtd /nandflash
[ifdef] pseudo-nvram
fload ${BP}/cpu/x86/pc/biosload/filenv.fth
Modified: cpu/x86/pc/olpc/fsupdate.fth
===================================================================
--- cpu/x86/pc/olpc/fsupdate.fth 2007-10-29 16:21:34 UTC (rev 702)
+++ cpu/x86/pc/olpc/fsupdate.fth 2007-10-29 22:02:39 UTC (rev 703)
@@ -4,28 +4,85 @@
: get-hex# ( -- n )
safe-parse-word
- push-hex
- $number " Bad number" ?nand-abort
- pop-base
+ push-hex $number pop-base " Bad number" ?nand-abort
;
-\ XXX implement this
-: map-eblock# ( block# -- block#' ) ;
+0 value partition-map-offset
+0 value next-partition-start
+0 value partition#
+d# 256 constant /partition-entry
+: partition-adr ( -- adr ) partition# /partition-entry * load-base + ;
+: max-nand-offset ( -- n ) " usable-page-limit" $call-nand /nand-page * ;
+: add-partition ( name$ #eblocks -- )
+ partition# " max#partitions" $call-nand >= abort" Partition map overflow"
+
+ -rot ( #eblocks name$ )
+ partition-adr /partition-entry erase ( #eblocks name$ )
+ d# 15 min partition-adr swap move ( #eblocks )
+ next-partition-start partition-adr d# 16 + l! ( #eblocks )
+
+ dup -1 = if ( #eblocks )
+ drop max-nand-offset ( last-offset )
+ next-partition-start - ( #bytes )
+ else
+ /nand-block * ( #bytes )
+ then ( #bytes )
+
+ dup partition-adr d# 24 + l! \ size ( #bytes )
+
+ next-partition-start + to next-partition-start ( )
+ next-partition-start max-nand-offset > abort" NAND size overflow"
+
+ partition# 1+ to partition#
+;
+: start-partition-map ( -- )
+ load-base /nand-block h# ff fill
+ 0 to partition#
+\ 0 to next-partition-start
+ " partition-map-page#" $call-nand /nand-page * to partition-map-offset
+
+ partition-map-offset to next-partition-start
+ " FIS directory" 1 add-partition
+;
+: write-partition-map ( -- )
+ partition-map-offset /nand-page / dup " erase-block" $call-nand
+ load-base swap nand-pages/block " write-blocks" $call-nand
+ nand-pages/block <> abort" Can't write partition map"
+;
+
+0 value partition-page-offset
+: map-eblock# ( block# -- block#' ) partition-page-offset + ;
+
+\ XXX need to check for overwriting existing partition map
+
vocabulary nand-commands
also nand-commands definitions
+: set-partition: ( "partition#" -- )
+ safe-parse-word " $set-partition" $call-nand abort" Nonexistent partition#"
+;
+
+: partitions: ( "name" "#eblocks" ... -- )
+ start-partition-map
+ begin parse-word dup while ( name$ )
+ get-hex# add-partition ( )
+ repeat ( null$ )
+ 2drop
+ write-partition-map
+;
+
: data: ( "filename" -- )
safe-parse-word fn-buf place
- bundle-name$ image-name-buf place
+ " ${DN}${PN}\${CN}${FN}" expand$ image-name-buf place
open-img
;
: erase-all ( -- )
#nand-pages >eblock# show-erasing
['] show-bad ['] show-erased ['] show-bbt-block " (wipe)" $call-nand
- #image-eblocks show-writing
+\ #image-eblocks show-writing
;
: eblock: ( "eblock#" "hashname" "hash-of-128KiB" -- )
@@ -80,6 +137,7 @@
tuck load-base h# 100000 + swap move ( len )
load-base h# 100000 + swap
open-nand
+
['] noop to show-progress
#nand-pages >eblock# show-init
@@ -112,6 +170,8 @@
2drop ( )
show-unlock ( )
img$ do-fs-update ( )
+ ." Rebooting in 10 seconds ..." cr
+ d# 10,000 ms bye
exit
then ( rem$ )
show-lock ( rem$ )
@@ -119,6 +179,7 @@
repeat ( rem$ )
2drop
;
+: update-devices " disk: sd: http:\\177.18.16.1" ;
: try-fs-update ( -- )
." Searching for a NAND file system update image." cr
all-devices$ fs-update-from-list
Modified: cpu/x86/pc/olpc/gui.fth
===================================================================
--- cpu/x86/pc/olpc/gui.fth 2007-10-29 16:21:34 UTC (rev 702)
+++ cpu/x86/pc/olpc/gui.fth 2007-10-29 22:02:39 UTC (rev 703)
@@ -360,6 +360,7 @@
h# 32 buffer: icon-name
: show-icon ( basename$ -- )
+ [char] : left-parse-string 2nip ( basename$' )
" rom:" icon-name pack $cat ( )
" .565" icon-name $cat ( )
icon-name count $show ( )
Modified: cpu/x86/pc/olpc/security.fth
===================================================================
--- cpu/x86/pc/olpc/security.fth 2007-10-29 16:21:34 UTC (rev 702)
+++ cpu/x86/pc/olpc/security.fth 2007-10-29 22:02:39 UTC (rev 703)
@@ -121,7 +121,7 @@
\ bundle, piecing it together from the device (DN), path (PN),
\ filename head (CN), and filename body (FN) macros.
-: bundle-name$ ( -- $ ) " ${DN}:${PN}\${CN}${FN}.zip" expand$ ;
+: bundle-name$ ( -- $ ) " ${DN}${PN}\${CN}${FN}.zip" expand$ ;
\ bundle-present? determines the existence (or not) of a signed image
\ bundle whose name is constructed from the current settings of the
@@ -419,7 +419,7 @@
\ a valid lease was found.
: lease-valid? ( -- valid? )
- " ${DN}:\security\lease.sig" expand$ ( name$ )
+ " ${DN}\security\lease.sig" expand$ ( name$ )
" Trying " ?lease-debug 2dup ?lease-debug-cr
r/o open-file if drop false exit then ( ih )
load-started
@@ -584,7 +584,8 @@
\ device given by the DN macro.
: has-developer-key? ( -- flag )
- " ${DN}:\security\develop.sig" expand$ ( name$ )
+ button-x game-key? if false exit then
+ " ${DN}\security\develop.sig" expand$ ( name$ )
" Trying " ?lease-debug 2dup ?lease-debug-cr
r/o open-file if drop false exit then ( ih )
>r
@@ -691,7 +692,7 @@
;
: filesystem-present? ( -- flag )
- " ${DN}:\" expand$ ( name$ )
+ " ${DN}\" expand$ ( name$ )
open-dev dup if dup close-dev then
0<>
;
@@ -740,9 +741,8 @@
: persistent-devkey? ( -- flag ) " dk" find-tag dup if nip nip then ;
-: all-devices$ ( -- list$ ) " disk sd fastnand nand" ;
+: all-devices$ ( -- list$ ) " disk: sd: nand:" ;
-
d# 410 d# 540 2constant progress-xy
: secure-startup ( -- )
['] noop to ?show-device
Modified: dev/olpc/cafenand/badblock.fth
===================================================================
--- dev/olpc/cafenand/badblock.fth 2007-10-29 16:21:34 UTC (rev 702)
+++ dev/olpc/cafenand/badblock.fth 2007-10-29 22:02:39 UTC (rev 703)
@@ -18,6 +18,7 @@
\ Return address of byte containing bad-block info and the mask
\ for the relevant bits.
: >bbt ( page# -- byte-adr mask )
+ partition-start +
pages/eblock / ( eblock# )
4 /mod ( remainder byte# )
bbt + ( remainder adr )
@@ -30,21 +31,7 @@
tuck swap c@ and ( mask masked-byte )
<>
;
-: block-reserved? ( page# -- flag )
- >bbt ( adr mask )
- tuck swap c@ and ( mask masked-byte )
- swap h# aa and =
-;
-
-\ Marks the block containing page# as used for another purpose
-: mark-reserved ( page# -- )
- >bbt ( adr mask )
- dup h# aa and -rot ( set-mask adr mask )
- invert over c@ and ( set-mask adr masked-byte )
- rot or swap c! ( )
-;
-
\ Marks the block containing page# as bad
: mark-bad ( page# -- )
>bbt ( adr mask )
@@ -107,6 +94,7 @@
;
: .page-byte ( page# -- )
+ partition-start +
push-hex
." at 0x" dup /page um* <# #s #> type
." = page 0x" dup . ." = eblock 0x" pages/eblock / u.
@@ -199,26 +187,41 @@
release-bbt
;
-\ Get the existing bad block table, or make a new one if necessary
-: get-bbt ( -- )
- get-existing-bbt
- bbt 0= if
- ." No bad block table; making one" cr
- make-bbt
- then
+0 instance value #bad-blocks
+0 instance value bb-list
+: make-bb-list ( -- )
+ 0 usable-page-limit 0 ?do ( bb# )
+ i block-bad? if 1+ then
+ pages/eblock +loop
+ to #bad-blocks
+
+ #bad-blocks 1+ /n* alloc-mem to bb-list
+
+ bb-list usable-page-limit 0 ?do ( adr )
+ i block-bad? if ( adr )
+ i over ! na+ ( adr' )
+ then ( adr )
+ pages/eblock +loop ( adr )
+ h# 7fffffff swap ! ( ) \ "Stopper" entry
;
-0 instance value resmap
-0 value #reserved-eblocks
-: ?free-resmap ( -- )
- resmap if
- resmap #reserved-eblocks /n* free-mem
- 0 to resmap
+: map-page# ( page# -- page#' )
+ pages/eblock /mod ( offset eblock# )
+ bb-list ( offset eblock# list-adr )
+ begin 2dup @ >= while ( offset eblock# list-adr )
+ swap 1+ swap na1+ ( offset eblock#' list-adr' )
+ repeat ( offset eblock#' list-adr' )
+ pages/eblock * + ( page#' )
+;
+: ?free-bb-list ( -- )
+ bb-list if
+ bb-list #bad-blocks 1+ /n* free-mem
+ 0 to bb-list
then
;
\ The upper limit of pages below the bad block tables
-: usable-page-limit ( -- page# )
+: (usable-page-limit) ( -- page# )
bbt0 if
bbt0
bbt1 if bbt1 min then
@@ -228,20 +231,20 @@
total-pages
;
-: map-resblock ( page# #pages -- page#' #pages )
- swap pages/eblock /mod ( adr #pages offset eblock# )
- resmap swap na+ @ ( adr #pages offset res-eblock# )
- + pages/eblock * swap ( adr page#' #pages )
+\ Get the existing bad block table, or make a new one if necessary
+: get-bbt ( -- )
+ get-existing-bbt
+ bbt 0= if
+ ." No bad block table; making one" cr
+ make-bbt
+ then
+ (usable-page-limit) to usable-page-limit
;
external
\ Assumes that the page range doesn't cross an erase block boundary
: read-blocks ( adr page# #pages -- #read )
- resmap if ( adr page# #pages )
- map-resblock
- else
- over block-bad? if 3drop 0 exit then
- then
+ over block-bad? if 3drop 0 exit then
rot >r 2dup r> -rot ( page# #pages adr page# #pages )
bounds ?do ( page# #pages adr )
@@ -255,11 +258,7 @@
;
: write-blocks ( adr page# #pages -- #written )
- resmap if ( adr page# #pages )
- map-resblock
- else
- over block-bad? if 3drop 0 exit then
- then
+ over block-bad? if 3drop 0 exit then
over >r dup >r ( adr page# #pages r: page# #pages )
bounds ?do ( adr r: page# #pages )
@@ -305,21 +304,23 @@
: .bn ( -- ) (cr . ;
: (wipe) ( 'show-bad 'show-erased 'show-bbt -- )
- get-existing-bbt
- bbt 0= if
- \ If there is no existing bad block table, make one from factory info
- make-bbt
- then ( 'show-bad 'show-erased 'show-bbt )
+ partition# 0= if
+ get-existing-bbt
+ bbt 0= if
+ \ If there is no existing bad block table, make one from factory info
+ make-bbt
+ then ( 'show-bad 'show-erased 'show-bbt )
- bbt0 if bbt0 pages/eblock / over execute then
- bbt1 if bbt1 pages/eblock / over execute then
+ bbt0 if bbt0 pages/eblock / over execute then
+ bbt1 if bbt1 pages/eblock / over execute then
+ then
drop ( 'show-bad 'show-erased )
- usable-page-limit 0 ?do ( 'show-bad 'show-erased )
+ partition-size 0 ?do ( 'show-bad 'show-erased )
i block-bad? if
- i pages/eblock / 2 pick execute
+ i partition-start + pages/eblock / 2 pick execute
else
- i pages/eblock / over execute
+ i partition-start + pages/eblock / over execute
i erase-block
then
pages/eblock +loop ( 'show-bad 'show-erased )
@@ -330,32 +331,13 @@
: wipe ( -- ) ['] drop ['] .bn ['] drop (wipe) ;
: show-bbt ( -- )
- get-bbt
total-pages 0 ?do
- i block-reserved? if ." Reserved " i .page-byte cr else
- i block-bad? if ." Bad block" i .page-byte cr then
- then
+ i block-bad? if ." Bad block" i .page-byte cr then
pages/eblock +loop
bbt1 if ." BBTable 1" bbt1 .page-byte cr then
bbt0 if ." BBTable 0" bbt0 .page-byte cr then
;
-: map-reserved
- 0 usable-page-limit 0 ?do
- i block-reserved? if 1+ then
- pages/eblock +loop
- dup to #reserved-eblocks
-
- /n* alloc-mem to resmap ( adr )
-
- resmap usable-page-limit 0 ?do ( adr )
- i block-reserved? if ( adr )
- i over ! na1+ ( adr' )
- then ( adr )
- pages/eblock +loop ( adr )
- drop
-;
-
headers
\ Copy-to-NAND functions
@@ -367,7 +349,7 @@
headers
: (next-page#) ( -- true | page# false )
- usable-page-limit scan-page# pages/eblock + ?do
+ partition-size scan-page# pages/eblock + ?do
i block-bad? 0= if
i to scan-page#
scan-page# false unloop exit
@@ -416,14 +398,14 @@
: copy-block ( adr -- page# error? )
begin (next-page#) 0= while ( adr page# )
- 2dup copy&check if nip false exit then ( adr page# )
+ 2dup copy&check if nip partition-start + false exit then ( adr page# )
\ Error; retry once
dup erase-block ( adr page# )
- 2dup copy&check if nip false exit then ( adr page# )
+ 2dup copy&check if nip partition-start + false exit then ( adr page# )
mark-bad save-bbt ( adr )
repeat ( adr )
drop ( )
- usable-page-limit pages/eblock - true ( page# error? )
+ partition-size pages/eblock - partition-start + true ( page# error? )
;
: put-cleanmarker ( page# -- )
@@ -437,7 +419,7 @@
: put-cleanmarkers ( show-xt -- )
begin (next-page#) 0= while ( show-xt page# )
dup put-cleanmarker ( show-xt page# )
- pages/eblock / over execute ( show-xt )
+ partition-start + pages/eblock / over execute ( show-xt )
repeat ( show-xt )
drop
;
@@ -481,99 +463,6 @@
true
;
-: block-erased? ( page# -- flag )
- pages/eblock bounds ?do
- test-page i read-page drop
- test-page /page erased? 0= if false unloop exit then
- pages/eblock +loop
- true
-;
-: enough-reserve? ( len -- flag )
- dup 0= if true exit then ( len )
- /eblock 1- + /eblock / ( #eblocks-needed )
- usable-page-limit 0 ?do ( #needed )
- i block-reserved? if 1- else ( #needed' )
- i block-erased? if 1- then ( #needed' )
- then ( #needed )
- dup 0= if drop true unloop exit then ( #needed )
- pages/eblock +loop ( #needed )
- drop false ( flag )
-;
-
-0 value any-marked?
-
-: start-fastcopy ( len -- error? )
- /page dma-alloc to test-page
- enough-reserve? 0= if
- test-page /page dma-free
- true exit
- then
- false to any-marked?
-
- \ Erase existing fastnand area
- usable-page-limit 0 ?do
- i block-reserved? if
- i erase-block
- i mark-good true to any-marked?
- then
- pages/eblock +loop
-
- start-scan
- false
-;
-: next-fastcopy ( adr -- )
- usable-page-limit scan-page# ?do ( adr )
- i block-erased? if ( adr )
- i pages/eblock write-blocks drop ( )
- i mark-reserved true to any-marked? ( )
- i pages/eblock + to scan-page#
- unloop exit
- then ( adr )
- pages/eblock +loop ( adr )
- ." Error: no more NAND fastcopy space" cr
- abort
-;
-: end-fastcopy ( -- )
- test-page /page dma-free
- any-marked? if save-bbt then
-;
-
-0 instance value deblocker
-: $call-deblocker ( ??? adr len -- ??? ) deblocker $call-method ;
-: init-deblocker ( -- okay? )
- " " " deblocker" $open-package to deblocker
- deblocker if
- true
- else
- ." Can't open deblocker package" cr false
- then
-;
-: seek ( d.offset -- status )
- resmap 0= if -1 exit then
- " seek" $call-deblocker
-;
-: position ( -- d.offset )
- resmap 0= if 0. exit then
- " position" $call-deblocker
-;
-: read ( adr len -- actual )
- resmap 0= if 2drop -1 exit then
- " read" $call-deblocker
-;
-: write ( adr len -- actual )
- resmap 0= if 2drop -1 exit then
- " write" $call-deblocker
-;
-: size ( -- d.size )
- resmap 0= if 0. exit then
- #reserved-eblocks /eblock um*
-;
-: load ( adr -- actual )
- resmap 0= if drop 0 exit then
- 0 0 seek drop
- size drop read
-;
-
\ LICENSE_BEGIN
\ Copyright (c) 2006 FirmWorks
\
Modified: dev/olpc/cafenand/cafenand.bth
===================================================================
--- dev/olpc/cafenand/cafenand.bth 2007-10-29 16:21:34 UTC (rev 702)
+++ dev/olpc/cafenand/cafenand.bth 2007-10-29 22:02:39 UTC (rev 703)
@@ -13,6 +13,7 @@
fload ${BP}/dev/olpc/cafenand/cafenand.fth
fload ${BP}/dev/olpc/cafenand/configure.fth
fload ${BP}/dev/olpc/cafenand/badblock.fth
+fload ${BP}/dev/olpc/cafenand/redboot.fth
fload ${BP}/dev/olpc/cafenand/methods.fth
fload ${BP}/dev/olpc/cafenand/selftest.fth
Modified: dev/olpc/cafenand/cafenand.fth
===================================================================
--- dev/olpc/cafenand/cafenand.fth 2007-10-29 16:21:34 UTC (rev 702)
+++ dev/olpc/cafenand/cafenand.fth 2007-10-29 22:02:39 UTC (rev 703)
@@ -68,12 +68,18 @@
\ version of the CaFe chip spec that we have, but Jerry Zheng says
\ that it chooses the chip select - 0 for CS0, 1 for CS1.
+0 instance value partition#
+0 instance value partition-start \ Boundary between chip 0 and chip 1
+0 instance value partition-size \ Boundary between chip 0 and chip 1
+0 instance value usable-page-limit \ #pages excluding bad block tables
+
1 instance value chip-boundary \ Boundary between chip 0 and chip 1
0 instance value cs-mask \ Chip-select bit for command 0 register
: chip0 ( -- ) 0 to cs-mask ;
: chip1 ( -- ) h# 80000 to cs-mask ;
: set-chip ( page# -- page#' )
+ partition-start +
dup chip-boundary >= if chip-boundary - chip1 else chip0 then
;
Modified: dev/olpc/cafenand/methods.fth
===================================================================
--- dev/olpc/cafenand/methods.fth 2007-10-29 16:21:34 UTC (rev 702)
+++ dev/olpc/cafenand/methods.fth 2007-10-29 22:02:39 UTC (rev 703)
@@ -24,7 +24,13 @@
total-pages 0= \ Error if there are no chips
;
-: open-args ( -- arg$ ) my-args ascii : left-parse-string 2swap 2drop ;
+: open-args ( -- arg$ )
+ \ If the argument string starts with :, discard the rest, because
+ \ it is intended for the selftest function.
+ my-args dup 0> if ( arg$ )
+ over c@ ascii : = if drop 0 then
+ then
+;
external
@@ -40,21 +46,28 @@
dma-buf-va dma-buf-pa /dma-buf " dma-map-out" $call-parent
/dma-buf dma-free
then
- ?free-resmap
;
-: size ( -- d )
- resmap if
- #reserved-eblocks /eblock
- else
- total-pages /page
- then
- um*
+: size ( -- d ) partition-size /page um* ;
+
+: $set-partition ( $ -- error? )
+ dup 0= if 2drop false exit then ( $ )
+ over c@ ascii 0 ascii 9 between if ( $ ) \ number
+ base @ >r decimal $number r> base ! if true exit then ( )
+ set-partition-number ( error? )
+ else ( $ ) \ name
+ set-partition-name ( error? )
+ then ( error? )
+ dup if ( error? )
+ ." NAND: No such partition" cr ( error? )
+ then
;
: open ( -- okay? )
map-regs
init
+ 0 to partition#
+ 0 to partition-start
configure-all if false exit then
/dma-buf dma-alloc to dma-buf-va
@@ -63,37 +76,29 @@
" lmove" $find 0= if ['] move then to do-lmove
get-bbt
+ usable-page-limit to partition-size
+ read-partmap
open-args dup if ( arg$ )
ascii , left-parse-string ( arg2$ arg1$ )
- 2dup " zip" $= if ( arg2$ arg1$ )
- 2drop ( arg2$ )
- map-reserved ( arg2$ )
- init-deblocker 0= if 2drop ?free-resmap false exit then ( arg2$ )
- \ If no file is specified, open the raw archive
- dup 0= if 2drop true exit then ( arg2$ )
-
- \ Otherwise interpose the filesystem handler
- " zip-file-system" find-package if ( arg2$ xt )
- interpose true ( true )
- else ( arg2$ )
- ." Can't find zip-file-system package" cr ( arg2$ )
- 2drop deblocker close-package ?free-resmap ( )
- false ( false )
- then
- exit
- then ( arg2$ arg1$ )
-
- \ Accept either "path" or "jffs2,path"
- 2dup " jffs2" $= if ( arg2$ arg1$ )
- 2drop ( arg2$ )
+ \ Handle partitions ( arg2$ arg1$ )
+ 2dup 1 min " \" $= if ( arg2$ arg1$ )
+ 2swap 2drop ( arg1$ )
+ \ If there is no "mtd" specifier and there is a partition map,
+ \ select the boot partition.
+ #partitions 0>= if ( arg1$ )
+ " boot" $set-partition if 2drop false exit then
+ then ( arg2$ arg1$ )
else ( arg2$ arg1$ )
- \ XXX probably should check that arg$2 is empty...
- 2swap 2drop ( arg1$ )
- then ( arg$ )
+ \ The argument is not a file so it must be a partition spec
+ #partitions 0< if 2drop 2drop false exit then ( arg2$ arg1$ )
+ $set-partition if 2drop false exit then ( arg2$ )
+ then ( arg$ )
- " jffs2-file-system" find-package if ( arg$ xt )
+ dup 0= if 2drop true exit then ( arg$ )
+
+ " jffs2-file-system" find-package if ( arg$ xt )
interpose true ( okay? )
else ( arg$ )
." Can't find jffs2-file-system package" cr
Added: dev/olpc/cafenand/redboot.fth
===================================================================
--- dev/olpc/cafenand/redboot.fth (rev 0)
+++ dev/olpc/cafenand/redboot.fth 2007-10-29 22:02:39 UTC (rev 703)
@@ -0,0 +1,111 @@
+purpose: Handler for Redboot FIS FLASH partition maps
+
+[ifdef] notdef
+struct fis_image_desc {
+ unsigned char name[16]; // Null terminated name
+ uint32_t flash_base; // Address within FLASH of image
+ uint32_t mem_base; // Address in memory where it executes
+ uint32_t size; // Length of image
+ uint32_t entry_point; // Execution entry point
+ uint32_t data_length; // Length of actual data
+ unsigned char _pad[256-(16+7*sizeof(uint32_t))];
+ uint32_t desc_cksum; // Checksum over image descriptor
+ uint32_t file_cksum; // Checksum over image data
+};
+[then]
+
+d# 256 constant /partition-entry
+d# 8 constant max#partitions
+
+: partition-map-page# ( -- page# )
+[ifdef] notdef
+ bbt1 if
+ bbt1 bbt0 if bbt0 min then ( bbtn )
+ else ( )
+ bbt0 dup 0= abort" No Bad Block Table" ( bbt0 )
+ then ( last-bbt-page# )
+ begin pages/eblock - dup while ( part-page# )
+ dup block-bad? 0= if exit then ( part-page# )
+ repeat
+[else]
+ h# 10 pages/eblock * 0 do
+ i block-bad? 0= if i unloop exit then
+ pages/eblock +loop
+[then]
+
+ true abort" No place for partition map"
+;
+
+: (#partitions) ( adr -- n )
+ 0 swap ( seen adr )
+ max#partitions 0 ?do ( seen adr )
+ dup i /partition-entry * + ( seen adr padr )
+ dup w@ h# ffff = if ( seen adr padr )
+ 2drop if i else -1 then ( n )
+ unloop exit ( n )
+ then ( seen adr padr )
+ " FIS directory" rot swap comp 0= if ( seen adr )
+ nip true swap ( seen adr )
+ then ( seen adr )
+ loop ( seen adr )
+ drop if max#partitions else -1 then
+;
+
+/page instance buffer: part-buf
+
+0 instance value #partitions
+: read-partmap ( -- )
+ part-buf partition-map-page#
+ partition-start >r 0 to partition-start
+ read-page
+ r> to partition-start
+ if true exit then
+ part-buf (#partitions) to #partitions
+;
+
+: set-partition-number ( partition# -- error? )
+ dup 0= if ( partition# )
+ to partition#
+ 0 to partition-start usable-page-limit to partition-size
+ false exit
+ then ( partition# )
+
+ dup #partitions u> if drop true exit then ( partition# )
+
+ dup to partition# ( partition# )
+
+ \ Partition 1 (the FIS directory entry) begins at offset 0
+ 1- /partition-entry * part-buf + ( adr )
+ dup d# 16 + l@ /page / to partition-start ( adr )
+ d# 24 + l@ /page / to partition-size ( )
+ false
+ start-scan
+;
+
+\ C string length no longer than maxlen
+: ncstr ( adr maxlen -- adr len )
+ 2dup bounds ?do ( adr maxlen )
+ i c@ 0= if drop i over - unloop exit then
+ loop ( adr maxlen )
+;
+
+: $= ( adr1 len1 adr2 len2 -- flag )
+ rot over <> if 3drop false exit then ( adr1 adr2 len2 )
+ comp 0=
+;
+
+: set-partition-name ( name$ -- error? )
+ #partitions dup 0< if 2drop false exit then ( name$ #partitions )
+ /partition-entry * ( name$ len )
+ part-buf swap bounds ?do ( name$ )
+ 2dup i d# 16 ncstr $= if ( name$ )
+ 2drop ( )
+ i d# 16 + l@ /page / to partition-start ( )
+ i d# 24 + l@ /page / to partition-size ( )
+ i part-buf - /partition-entry / 1+ to partition#
+ start-scan
+ false unloop exit
+ then ( name$ )
+ /partition-entry +loop ( name$ )
+ 2drop true
+;
Modified: ofw/fs/jffs2/jffs2.fth
===================================================================
--- ofw/fs/jffs2/jffs2.fth 2007-10-29 16:21:34 UTC (rev 702)
+++ ofw/fs/jffs2/jffs2.fth 2007-10-29 22:02:39 UTC (rev 703)
@@ -85,6 +85,7 @@
: dma-free ( len -- adr ) " dma-free" $call-parent ;
true value first-time?
+-1 value partition#
: allocate-buffers ( -- )
/eblock dma-alloc to block-buf
@@ -823,7 +824,7 @@
;
: scan-occupied ( -- )
- first-time? 0= if exit then
+ " partition#" $call-parent partition# = if exit then
init-curvars
dirents 'next-dirent !
inodes 'next-inode !
@@ -1432,6 +1433,7 @@
scan-occupied ( )
+ " partition#" $call-parent to partition#
false to first-time?
my-args " <NoFile>" $= if true exit then