Author: wmb Date: 2009-10-01 10:38:31 +0200 (Thu, 01 Oct 2009) New Revision: 1383
Modified: cpu/x86/pc/olpc/via/fsupdate.fth cpu/x86/pc/olpc/via/padlock.fth dev/mmc/sdhci/sdhci.fth Log: Via - fixed several issues with fs-update 1) Now handles large chunk sizes correctly 2) "dir int:" immediately after fs-update now works 3) Better error checking for truncated .zd files 4) Check the hash by default, using the hardware SHA256 engine for speed 5) Display the CPU temperature to verify that the thermal monitor works (prevents overheating)
Modified: cpu/x86/pc/olpc/via/fsupdate.fth =================================================================== --- cpu/x86/pc/olpc/via/fsupdate.fth 2009-10-01 08:30:21 UTC (rev 1382) +++ cpu/x86/pc/olpc/via/fsupdate.fth 2009-10-01 08:38:31 UTC (rev 1383) @@ -3,6 +3,9 @@
\ Depends on words from security.fth and copynand.fth
+: cpu-temperature ( -- degrees-C ) h# 1169 msr@ drop ; +: show-temperature ( -- ) space cpu-temperature .d ; + : get-hex# ( -- n ) safe-parse-word push-hex $number pop-base " Bad number" ?nand-abort @@ -63,9 +66,20 @@
0 value last-eblock# : erase-eblock ( eblock# -- ) - drop \ XXX + \ XXX + to last-eblock# ;
+: ?all-written ( -- ) + last-eblock# 1+ #image-eblocks <> if + cr + red-letters + ." WARNING: The file specified " #image-eblocks .d + ." chunks but wrote only " last-eblock# 1+ .d ." chunks" cr + black-letters + then +; + 0 value secure-fsupdate? d# 128 constant /spec-maxline
@@ -77,6 +91,15 @@ then ;
+\ We simultaneously DMA one data buffer onto NAND while unpacking the +\ next block of data into another. The buffers exchange roles after +\ each block. + +0 value dma-buffer +0 value data-buffer + +: swap-buffers ( -- ) data-buffer dma-buffer to data-buffer to dma-buffer ; + vocabulary nand-commands also nand-commands definitions
@@ -101,6 +124,9 @@ open-nand #image-eblocks show-init get-inflater + load-base to dma-buffer + load-base /nand-block + to data-buffer + /nand-block /nand-page / to nand-pages/block ;
: zblocks-end: ( -- ) @@ -121,14 +147,6 @@ #image-eblocks show-writing ;
-\ We simultaneously DMA one data buffer onto NAND while unpacking the -\ next block of data into another. The buffers exchange roles after -\ each block. -load-base value dma-buffer -load-base /nand-block 4 * + value data-buffer - -: swap-buffers ( -- ) data-buffer dma-buffer to data-buffer to dma-buffer ; - : get-zdata ( comprlen -- ) secure-fsupdate? if data-buffer /spec-maxline fileih read-line ( len end? error? ) @@ -153,12 +171,16 @@ /nand-block <> " Wrong expanded data length" ?nand-abort ( ) ;
-false value check-hash? +true value check-hash?
: check-hash ( -- ) 2>r ( eblock# hashname$ r: hash$ ) data-buffer /nand-block 2swap ( eblock# data$ hashname$ r: hash$ ) - crypto-hash ( eblock# calc-hash$ r: hash$ ) + 2dup " sha256" $= if ( eblock# hashname$ r: hash$ ) + 2drop sha-256 ( eblock# calc-hash$ r: hash$ ) + else + crypto-hash ( eblock# calc-hash$ r: hash$ ) + then 2r> $= 0= if ( eblock# ) ." Bad hash for eblock# " .x cr cr ." Your USB key may be bad. Please try a different one." cr @@ -167,14 +189,37 @@ then ( eblock# ) ;
+0 value have-crc? +0 value my-crc + +: ?get-crc ( -- ) + parse-word dup if ( eblock# hashname$ crc$ r: comprlen ) + push-hex $number pop-base if ( eblock# hashname$ crc$ r: comprlen ) + false to have-crc? ( eblock# hashname$ r: comprlen ) + else ( eblock# hashname$ crc r: comprlen ) + to my-crc ( eblock# hashname$ r: comprlen ) + true to have-crc? ( eblock# hashname$ r: comprlen ) + then ( eblock# hashname$ r: comprlen ) + else ( eblock# hashname$ empty$ r: comprlen ) + 2drop ( eblock# hashname$ r: comprlen ) + false to have-crc? ( eblock# hashname$ r: comprlen ) + then ( eblock# hashname$ r: comprlen ) +; +: ?check-crc ( -- ) + have-crc? if + then +; + : zblock: ( "eblock#" "comprlen" "hashname" "hash-of-128KiB" -- ) get-hex# ( eblock# ) get-hex# >r ( eblock# r: comprlen ) safe-parse-word ( eblock# hashname$ r: comprlen ) safe-parse-word hex-decode ( eblock# hashname$ [ hash$ ] err? r: comprlen ) " Malformed hash string" ?nand-abort ( eblock# hashname$ hash$ r: comprlen ) - + + ?get-crc ( eblock# hashname$ hash$ r: comprlen ) r> get-zdata ( eblock# hashname$ hash$ ) + ?check-crc ( eblock# hashname$ hash$ )
check-hash? if ( eblock# hashname$ hash$ ) check-hash ( eblock# ) @@ -190,6 +235,7 @@
dup to last-eblock# ( eblock# ) show-written ( ) + show-temperature ;
previous definitions @@ -205,13 +251,14 @@ over file ! linefeed line-delimiter c! ( fd fd' ) file ! ( fd )
- t( - also nand-commands - ['] include-file catch dup if + t( ( fd ) + also nand-commands ( fd ) + ['] include-file catch ?dup if ( x error ) nip .error - then + then ( ) previous show-done + ?all-written close-nand-ihs )t-hms ;
Modified: cpu/x86/pc/olpc/via/padlock.fth =================================================================== --- cpu/x86/pc/olpc/via/padlock.fth 2009-10-01 08:30:21 UTC (rev 1382) +++ cpu/x86/pc/olpc/via/padlock.fth 2009-10-01 08:38:31 UTC (rev 1383) @@ -51,7 +51,7 @@ enable-padlock init-sha sha-buf do-sha - sha-buf h# 20 + sha-buf h# 20 2dup lbflips ;
\ LICENSE_BEGIN
Modified: dev/mmc/sdhci/sdhci.fth =================================================================== --- dev/mmc/sdhci/sdhci.fth 2009-10-01 08:30:21 UTC (rev 1382) +++ dev/mmc/sdhci/sdhci.fth 2009-10-01 08:38:31 UTC (rev 1383) @@ -716,6 +716,21 @@
external
+ +: dma-alloc ( size -- vadr ) " dma-alloc" $call-parent ; +: dma-free ( vadr size -- ) " dma-free" $call-parent ; + +0 instance value dma? + +: wait-dma-done ( -- ) + dma? if + 2 wait + dma-release + intstat-off + false to dma? + then +; + : attach-card ( -- okay? ) setup-host power-up-card if ( retry? ) @@ -756,9 +771,8 @@ ;
: detach-card ( -- ) - intstat-on - wait-write-done - intstat-off + wait-dma-done + intstat-on wait-write-done intstat-off card-clock-off card-power-off unmap-regs @@ -795,20 +809,6 @@ : detach-sdio-card ( -- ) ;
-: dma-alloc ( size -- vadr ) " dma-alloc" $call-parent ; -: dma-free ( vadr size -- ) " dma-free" $call-parent ; - -0 instance value dma? - -: wait-dma-done ( -- ) - dma? if - 2 wait - dma-release - intstat-off - false to dma? - then -; - : r/w-blocks-finish ( -- actual ) wait-dma-done dma-len /block / @@ -862,7 +862,6 @@ ;
: close ( -- ) - wait-dma-done open-count 1 = if scratch-buf d# 64 " dma-free" $call-parent then
openfirmware@openfirmware.info