\ OLPC Boot Script for automatically saving OS images \ by Erik Garrison \ with help from Mitch Bradley \ Version number ." syscopy key version: 2008-09-04 19:02Z" cr screen-ih stdout ! \ show output to show process progress no-page \ but don't use the pager, because the keyboard isn't turned on \ (the keyboard is only turned on if we boot holding down a game key) ' . to .error \ suppress fancy abort messages ' noop to load-started \ suppress the load progress spinner ' noop to ?show-device \ suppress the boot progress icons ' false to auto-boot? \ suppress automatic booting after this finishes \needs halt code halt hlt c; : $die ( message$ -- ) red-letters type cr suspend \ Save power while showing message h# 8000 0 acpi-l! \ The WAK_FLAG bit prevents power-off power-off begin halt again \ Just in case power-off fails ; : must-update ( -- ) " Update firmware" $die ; \needs expiration-to-seconds must-update \needs date-bad? must-update \needs current-seconds must-update : ?expire-script ( -- ) date-bad? if " The date on this machine is invalid." $die then " 20080912T000000Z" expiration-to-seconds 0= if ( seconds ) current-seconds <= if " This script has expired." $die then then ; h# 100 buffer: $cmd-buf : save-named-image ( -- ) \ save NAND image to USB storage device ?expire-script " save-nand " $cmd-buf place ( ) make-sn-name $cmd-buf $cat ( ) $cmd-buf count ( adr len ) ." Saving system NAND FLASH" cr ( adr len ) ['] evaluate catch if ( x x ) " Save failed - try another USB key" $die ( x x ) then ( ) green-letters ." Save complete, powering off in three seconds" cr ( ) d# 3000 ms power-off ; save-named-image