Author: wmb
Date: 2007-09-18 01:34:55 +0200 (Tue, 18 Sep 2007)
New Revision: 612
Modified:
cpu/x86/pc/olpc/devices.fth
dev/geode/acpi.fth
dev/olpc/kb3700/battery.fth
dev/olpc/kb3700/ecio.fth
dev/olpc/spiflash/spiui.fth
Log:
OLPC "flash" command - guard against common failure modes like
power loss and premature power button pushes.
Modified: cpu/x86/pc/olpc/devices.fth
===================================================================
--- cpu/x86/pc/olpc/devices.fth 2007-09-17 23:32:59 UTC (rev 611)
+++ cpu/x86/pc/olpc/devices.fth 2007-09-17 23:34:55 UTC (rev 612)
@@ -124,6 +124,27 @@
[then]
device-end
+dev /8042/keyboard
+0 value waiting-up?
+: olpc-check-abort ( scan-code -- abort? ) \ Square pressed?
+ last-scan over to last-scan ( scan-code old-scan-code )
+ h# e0 <> if drop false exit then ( scan-code )
+
+ check-abort? 0= if drop false exit then ( scan-code )
+
+ dup h# 7f and h# 5d <> if drop false exit then ( scan-code )
+
+ h# 80 and if \ Up
+ false to waiting-up?
+ false ( abort? )
+ else
+ waiting-up? 0= ( abort? )
+ true to waiting-up?
+ then
+;
+patch olpc-check-abort check-abort get-scan
+dend
+
0 0 " i70" " /isa" begin-package \ Real-time clock node
fload ${BP}/dev/ds1385r.fth
8 encode-int 0 encode-int encode+ " interrupts" property
@@ -233,6 +254,8 @@
\needs md5init fload ${BP}/ofw/ppp/md5.fth \ MD5 hash
+fload ${BP}/dev/geode/acpi.fth \ Power management
+
fload ${BP}/dev/olpc/kb3700/ecspi.fth \ EC chip SPI FLASH access
warning @ warning off
@@ -275,6 +298,8 @@
fload ${BP}/cpu/x86/pc/olpc/mfgtree.fth \ Manufacturing data in device tree
fload ${BP}/cpu/x86/pc/olpc/kbdtype.fth \ Export keyboard type
+fload ${BP}/dev/olpc/kb3700/battery.fth \ Battery status reports
+
fload ${BP}/dev/olpc/spiflash/spiflash.fth \ SPI FLASH programming
fload ${BP}/dev/olpc/spiflash/spiui.fth \ User interface for SPI FLASH programming
fload ${BP}/dev/olpc/spiflash/recover.fth \ XO-to-XO SPI FLASH recovery
@@ -304,8 +329,6 @@
devalias screen /display
also hidden d# 34 to display-height previous \ For editing
-fload ${BP}/dev/geode/acpi.fth \ Power management
-
fload ${BP}/cpu/x86/adpcm.fth \ ADPCM decoding
[ifdef] rom-loaded
Modified: dev/geode/acpi.fth
===================================================================
--- dev/geode/acpi.fth 2007-09-17 23:32:59 UTC (rev 611)
+++ dev/geode/acpi.fth 2007-09-17 23:34:55 UTC (rev 612)
@@ -12,15 +12,11 @@
: pm@ ( offset -- n ) pm-base + pl@ ;
: pm! ( n offset -- ) pm-base + pl! ;
-: enable-power-button ( -- ) h# 100 2 acpi-w! ;
+: enable-power-button ( -- ) 2 acpi-w@ h# 100 or 2 acpi-w! ;
+: disable-power-button ( -- ) 2 acpi-w@ h# 100 invert and 2 acpi-w! ;
h# 4000.0000 constant pm-enable
: gx-power-off ( -- )
- \ If the keyboard controller is off (after "flash"), power off doesn't work.
- \ I suspect that is because the EC doesn't notice the deassertion
- \ of main_on and sus_on from the 5536.
- ec-power-off
-
\ The rest of this will succeed in turning off the CPU, but the EC will
\ stay on. The ec-power-off above turns off both the EC and CPU, so the
\ rest of this is for historical interest only.
Modified: dev/olpc/kb3700/battery.fth
===================================================================
--- dev/olpc/kb3700/battery.fth 2007-09-17 23:32:59 UTC (rev 611)
+++ dev/olpc/kb3700/battery.fth 2007-09-17 23:34:55 UTC (rev 612)
@@ -77,7 +77,7 @@
dup abs d# 10,000 / <# u# u# [char] . hold u#s swap sign u#> type
pop-base
;
-: 2.d ( n -- ) push-decimal <# u# u#s u#> type pop-base ;
+\needs 2.d : 2.d ( n -- ) push-decimal <# u# u#s u#> type pop-base ;
: .% ( n -- ) 2.d ." %" ;
: .bat ( -- )
bat-status@ ( stat )
@@ -101,11 +101,17 @@
then
drop
;
+
+: ?enough-power ( )
+ bat-status@ ( stat )
+ dup h# 10 and 0= abort" AC not present" ( stat )
+ dup 1 and 0= abort" Battery not present" ( stat )
+ 4 and abort" Battery low"
+;
+
: watch-battery ( -- )
- cursor-off
begin (cr .bat kill-line d# 1000 ms key? until
key drop
- cursor-on
;
\ send questions to andrew at gold peak
Modified: dev/olpc/kb3700/ecio.fth
===================================================================
--- dev/olpc/kb3700/ecio.fth 2007-09-17 23:32:59 UTC (rev 611)
+++ dev/olpc/kb3700/ecio.fth 2007-09-17 23:34:55 UTC (rev 612)
@@ -267,6 +267,7 @@
7 to spi-us \ Measured time for "1 fea9 ec!" is 7.9 uS
kbc-off
+ disable-power-button \ Guard against the user panicing
;
: use-local-ec ( -- ) ['] io-spi-start to spi-start ;
use-local-ec
Modified: dev/olpc/spiflash/spiui.fth
===================================================================
--- dev/olpc/spiflash/spiui.fth 2007-09-17 23:32:59 UTC (rev 611)
+++ dev/olpc/spiflash/spiui.fth 2007-09-17 23:34:55 UTC (rev 612)
@@ -241,7 +241,8 @@
$get-file
;
-: flash ( ["filename"] -- ) get-file reflash ;
+: flash ( ["filename"] -- ) get-file ?enough-power reflash ;
+: flash! ( ["filename"] -- ) get-file reflash ;
\ This is a slower version of "rom-va flash-buf /flash lmove"
\ It works around the problem that continuous CPU access to the