Author: wmb Date: 2007-07-24 03:21:22 +0200 (Tue, 24 Jul 2007) New Revision: 492
Modified: dev/olpc/cafenand/badblock.fth dev/olpc/cafenand/cafenand.fth dev/olpc/cafenand/ecc.fth Log: OLPC CaFe NAND driver - turned on ECC correction. Trac 738
Modified: dev/olpc/cafenand/badblock.fth =================================================================== --- dev/olpc/cafenand/badblock.fth 2007-07-23 20:24:48 UTC (rev 491) +++ dev/olpc/cafenand/badblock.fth 2007-07-24 01:21:22 UTC (rev 492) @@ -170,7 +170,10 @@ bbt swap /bbt /page / ( adr page# #pages ) \ Can't use read-blocks because of block-bad? dependency bounds ?do ( adr ) - dup i read-page ( adr ) + dup i read-page if ( adr ) + ." BBT has uncorrectable errors" cr + abort + then ( adr ) /page + ( adr' ) loop ( adr ) drop @@ -232,13 +235,15 @@ over block-bad? if 3drop 0 exit then then
- dup >r ( adr page# #pages r: #pages ) - bounds ?do ( adr ) - \ XXX need some error handling - dup i read-page ( adr ) - /page + ( adr' ) - loop ( adr ) - drop r> + rot >r 2dup r> -rot ( page# #pages adr page# #pages ) + bounds ?do ( page# #pages adr ) + dup i read-page if ( page# #pages adr ) + 2drop i swap - ( #read ) + unloop exit + then ( page# #pages adr ) + /page + ( page# #pages adr' ) + loop ( page# #pages adr ) + drop nip ;
: write-blocks ( adr page# #pages -- #written ) @@ -364,7 +369,9 @@ : read-next-block ( adr -- ) find-good-block scan-page# pages/eblock bounds ?do ( adr ) - dup i read-page ( adr ) + dup i read-page if ( adr ) + ." Uncorrectable error in page 0x" i .x cr + then /page + ( adr' ) loop ( adr ) drop ( ) @@ -381,7 +388,7 @@ \ : verify-block ( adr -- false | page# true ) \ find-good-block \ scan-page# pages/eblock bounds ?do ( adr ) -\ test-page i read-page ( adr ) +\ test-page i read-page drop ( adr ) \ dup test-page /page comp if ( adr ) \ drop ( ) \ i true exit ( -- page# true ) @@ -401,7 +408,7 @@
: block-erased? ( page# -- flag ) pages/eblock bounds ?do - test-page i read-page + test-page i read-page drop test-page /page erased? 0= if false unloop exit then pages/eblock +loop true
Modified: dev/olpc/cafenand/cafenand.fth =================================================================== --- dev/olpc/cafenand/cafenand.fth 2007-07-23 20:24:48 UTC (rev 491) +++ dev/olpc/cafenand/cafenand.fth 2007-07-24 01:21:22 UTC (rev 492) @@ -22,6 +22,7 @@
: cl! ( l adr -- ) chip + rl! ; : cl@ ( adr -- l ) chip + rl@ ; +: cw@ ( adr -- w ) chip + rw@ ;
: map-regs ( -- ) 0 0 h# 0200.0010 my-space + /regs " map-in" $call-parent to chip @@ -199,16 +200,27 @@ 0 instance value dma-buf-pa 0 instance value dma-buf-va defer do-lmove +h# 10 buffer: syndrome-buf +: syndrome ( -- adr ) + 8 0 do h# 50 i wa+ cw@ i syndrome-buf array! loop + syndrome-buf +;
-\ XXX should check ECC -: read-page ( adr page# -- ) +: read-page ( adr page# -- error? ) 0 set-page ( adr ) - /page ( /oob + ) h# 18 cl! ( adr ) + /page /ecc + h# 18 cl! ( adr ) dma-buf-pa h# 44 cl! ( adr ) 0 h# 48 cl! ( adr ) /page h# a000.0000 or h# 40 cl! ( adr ) read-cmd h# 0800.0130 cmd wait-dma ( adr ) - dma-buf-va swap /page do-lmove ( ) + + h# 3c cl@ h# 40000 and if ( adr ) \ ECC error + dma-buf-va syndrome correct-ecc ( adr uncorrectable? ) + else ( adr ) + false ( adr error? ) + then ( adr error? ) + + dma-buf-va rot /page do-lmove ( error? ) ;
: dma-write-raw ( adr len page# offset -- ) @@ -231,7 +243,6 @@ write-disable ( ) ;
-\ : read-page ( adr page# -- ) dma-read-page ; : write-page ( adr page# -- ) dma-write-page ; : write-bytes ( adr len page# offset -- ) pio-write-raw ;
Modified: dev/olpc/cafenand/ecc.fth =================================================================== --- dev/olpc/cafenand/ecc.fth 2007-07-23 20:24:48 UTC (rev 491) +++ dev/olpc/cafenand/ecc.fth 2007-07-24 01:21:22 UTC (rev 492) @@ -3,8 +3,8 @@
hex
-: array! ( value index adr -- ) swap wa+ ! ; -: array@ ( index adr -- value ) swap wa+ @ ; +: array! ( value index adr -- ) swap wa+ w! ; +: array@ ( index adr -- value ) swap wa+ w@ ;
\ Split or join a number, size of low half is n bits. : #split ( x n -- x.lo x.hi ) @@ -330,10 +330,10 @@
[ifdef] notdef \ Test vectors -CREATE s1 001 , 6c6 , 291 , d91 , 1ef , e26 , a19 , 8c0 , -CREATE s2 0f8 , de1 , 5e5 , 287 , 566 , 756 , f5f , 253 , -CREATE s3 001 , 001 , 001 , 001 , 001 , 001 , 001 , 001 , -CREATE s4 41e , b7a , 37c , 885 , c32 , a87 , 218 , b08 , +CREATE s1 001 w, 6c6 w, 291 w, d91 w, 1ef w, e26 w, a19 w, 8c0 w, +CREATE s2 0f8 w, de1 w, 5e5 w, 287 w, 566 w, 756 w, f5f w, 253 w, +CREATE s3 001 w, 001 w, 001 w, 001 w, 001 w, 001 w, 001 w, 001 w, +CREATE s4 41e w, b7a w, 37c w, 885 w, c32 w, a87 w, 218 w, b08 w,
: #aligned negate swap negate and negate ;