[openfirmware] r1019 - clients/lib cpu/x86/pc/olpc dev/olpc/cafenand dev/olpc/spiflash dev/usb2/device/wlan
svn at openfirmware.info
svn at openfirmware.info
Thu Dec 4 10:18:19 CET 2008
Author: wmb
Date: 2008-12-04 10:18:18 +0100 (Thu, 04 Dec 2008)
New Revision: 1019
Added:
cpu/x86/pc/olpc/wifichannel.fth
Modified:
clients/lib/lib.c
clients/lib/strings.c
cpu/x86/pc/olpc/copynand.fth
cpu/x86/pc/olpc/fsupdate.fth
cpu/x86/pc/olpc/fw.bth
cpu/x86/pc/olpc/mcastnand.bth
cpu/x86/pc/olpc/nandcastui.fth
cpu/x86/pc/olpc/nandstat.fth
dev/olpc/cafenand/badblock.fth
dev/olpc/cafenand/redboot.fth
dev/olpc/spiflash/spiui.fth
dev/usb2/device/wlan/usb8388.fth
Log:
OLPC - bit checkin of multicast NAND updater improvements, including
graphical progress reports, automatic channel chooser, partition support.
Modified: clients/lib/lib.c
===================================================================
--- clients/lib/lib.c 2008-12-04 09:18:10 UTC (rev 1018)
+++ clients/lib/lib.c 2008-12-04 09:18:18 UTC (rev 1019)
@@ -159,6 +159,22 @@
}
int
+kbhit()
+{
+ int count;
+
+ if (stdin->bufc != 0)
+ return 1;
+ count = OFRead(stdin->id, stdin->buf, 1);
+ if (count > 0) {
+ stdin->bufc = count;
+ stdin->inbufp = stdin->buf;
+ return 1;
+ }
+ return 0;
+}
+
+int
fgetc(FILE *fp)
{
int count;
Modified: clients/lib/strings.c
===================================================================
--- clients/lib/strings.c 2008-12-04 09:18:10 UTC (rev 1018)
+++ clients/lib/strings.c 2008-12-04 09:18:18 UTC (rev 1019)
@@ -38,6 +38,16 @@
return((size_t) i);
}
+size_t
+strnlen(const char *s, size_t maxlen)
+{
+ int i;
+
+ for (i = 0; i < maxlen && s[i] != '\0'; ++i)
+ ;
+ return((size_t) i);
+}
+
char *
strcpy(char *to, const char *from)
{
@@ -71,8 +81,9 @@
strcpy(to, from);
return (ret);
}
+
char *
-index(char *s, int c)
+strchr(char *s, int c)
{
while (*s) {
if (*s == c)
@@ -92,7 +103,7 @@
saved_str = s;
if (saved_str == NULL)
return(NULL);
- s = index(saved_str, sep);
+ s = strchr(saved_str, sep);
if (s != NULL) {
*s++ = '\0';
while (*s && (*s == sep))
Modified: cpu/x86/pc/olpc/copynand.fth
===================================================================
--- cpu/x86/pc/olpc/copynand.fth 2008-12-04 09:18:10 UTC (rev 1018)
+++ cpu/x86/pc/olpc/copynand.fth 2008-12-04 09:18:18 UTC (rev 1019)
@@ -26,10 +26,13 @@
: close-image-file ( -- )
fileih ?dup if 0 to fileih close-dev then
;
+: close-nand ( -- )
+ nandih ?dup if 0 to nandih close-dev 0 to #nand-pages then
+;
: close-nand-ihs ( -- )
0 to nanddump-mode?
close-image-file
- nandih ?dup if 0 to nandih close-dev 0 to #nand-pages then
+ close-nand
crc-ih ?dup if 0 to crc-ih close-dev then
#crc-records if
crc-buf #crc-records /l* free-mem
@@ -51,13 +54,16 @@
" Stopped by keystroke" ?nand-abort
;
-: open-nand ( -- )
- " /nandflash" open-dev to nandih
- nandih 0= " Can't open NAND FLASH device" ?nand-abort
+: set-nand-vars ( -- )
" erase-size" $call-nand to /nand-block
" page-size" $call-nand to /nand-page
" size" $call-nand /nand-page um/mod nip to #nand-pages
/nand-block /nand-page / to nand-pages/block
+;
+: open-nand ( -- )
+ " /nandflash" open-dev to nandih
+ nandih 0= " Can't open NAND FLASH device" ?nand-abort
+ set-nand-vars
" start-scan" $call-nand
;
@@ -237,8 +243,6 @@
: xy+ ( x1 y1 x2 y2 -- x3 y3 ) rot + -rot + swap ;
: xy* ( x y w h -- x*w y*h ) rot * >r * r> ;
-0 value nand-block-limit
-
: do-fill ( color x y w h -- ) " fill-rectangle" $call-screen ;
\ States: 0:erased 1:bad 2:waiting for write 3:written
@@ -247,20 +251,28 @@
: show-state ( eblock# state -- ) swap >loc glyph-w glyph-h do-fill ;
+code map-color ( color24 -- color565 )
+ bx pop
+ bx ax mov 3 # ax shr h# 1f # ax and \ Blue in correct place
+ bx cx mov 5 # cx shr h# 7e0 # cx and cx ax or \ Green and blue in place
+ 8 # bx shr h# f800 # bx and bx ax or \ Red, green and blue in place
+ ax push
+c;
+: show-color ( eblock# color32 -- ) map-color show-state ;
+
dev screen : erase-screen erase-screen ; dend
h# 80 h# 80 h# 80 rgb>565 constant bbt-color \ gray
0 0 0 rgb>565 constant erased-color \ black
h# ff 0 0 rgb>565 constant bad-color \ red
0 0 h# ff rgb>565 constant clean-color \ blue
+h# ff 0 h# ff rgb>565 constant partial-color \ magenta
h# ff h# ff 0 rgb>565 constant pending-color \ yellow
0 h# ff 0 rgb>565 constant written-color \ green
0 h# ff h# ff rgb>565 constant strange-color \ cyan
h# ff h# ff h# ff rgb>565 constant starting-color \ white
: gshow-init ( #eblocks -- )
- #nand-pages nand-pages/block / to nand-block-limit
-
cursor-off " erase-screen" $call-screen
" bbt0" $call-nand nand-pages/block / bbt-color show-state
@@ -371,13 +383,15 @@
working-page " read-oob" $call-nand d# 14 + ( adr )
\ .. Cleanmarker
- dup " "(85 19 03 20 08 00 00 00)" comp 0= if drop 4 exit then
+ dup " "(85 19 03 20 08 00 00 00)" comp 0= if drop 4 exit then ( adr )
\ .. Bad block tables
\ These can't happen because the BBT table blocks are marked "bad"
\ so they get filtered out at the top of this routine.
\ dup " Bbt0" comp 0= if drop 7 exit then
\ dup " 1tbB" comp 0= if drop 8 exit then
+
+[ifdef] notdef
drop
\ See if the whole thing is really completely erased
@@ -386,6 +400,9 @@
\ Not completely erased
load-base /nand-block written? if 5 exit then
+[else]
+ ( adr ) h# 40 written? if 5 then
+[then]
\ Erased
6
@@ -426,6 +443,8 @@
to current-block
current-block highlight
;
+
+0 value nand-block-limit
: +block ( offset -- )
current-block + nand-block-limit mod ( new-block )
point-block
@@ -449,6 +468,7 @@
: examine-nand ( -- )
0 status-line 1- at-xy red-letters ." Arrows, fn Arrows to move, Esc to exit" black-letters cr
+ #nand-pages nand-pages/block / to nand-block-limit
0 to current-block
current-block highlight
false to examine-done?
Modified: cpu/x86/pc/olpc/fsupdate.fth
===================================================================
--- cpu/x86/pc/olpc/fsupdate.fth 2008-12-04 09:18:10 UTC (rev 1018)
+++ cpu/x86/pc/olpc/fsupdate.fth 2008-12-04 09:18:18 UTC (rev 1019)
@@ -186,7 +186,12 @@
: update-devices " disk: sd: http:\\172.18.0.1" ;
: try-fs-update ( -- )
." Searching for a NAND file system update image." cr
- update-devices fs-update-from-list
+ " disk: sd:" fs-update-from-list
+ secure? 0= if
+ ." Trying multicast update" cr
+ ['] enand catch 0= if exit then
+ then
+ " http:\\172.18.0.1" fs-update-from-list
;
: $update-nand ( devspec$ -- )
Modified: cpu/x86/pc/olpc/fw.bth
===================================================================
--- cpu/x86/pc/olpc/fw.bth 2008-12-04 09:18:10 UTC (rev 1018)
+++ cpu/x86/pc/olpc/fw.bth 2008-12-04 09:18:18 UTC (rev 1019)
@@ -344,7 +344,6 @@
fload ${BP}/cpu/x86/pc/olpc/setwp.fth
fload ${BP}/cpu/x86/pc/olpc/security.fth
-fload ${BP}/cpu/x86/pc/olpc/fsupdate.fth
fload ${BP}/ofw/gui/ofpong.fth
fload ${BP}/cpu/x86/pc/olpc/life.fth
fload ${BP}/cpu/x86/pc/olpc/sound.fth
@@ -436,6 +435,7 @@
fload ${BP}/ofw/inet/http.fth \ HTTP client
end-support-package
+
fload ${BP}/ofw/wifi/wifi-cfg.fth
support-package: supplicant
fload ${BP}/ofw/wifi/loadpkg.fth
@@ -446,6 +446,10 @@
;
' olpc-ssids to default-ssids
+fload ${BP}/cpu/x86/pc/olpc/nandcastui.fth
+fload ${BP}/cpu/x86/pc/olpc/wifichannel.fth
+fload ${BP}/cpu/x86/pc/olpc/fsupdate.fth
+
fload ${BP}/ofw/inet/sntp.fth
: olpc-ntp-servers ( -- )
" time 172.18.0.1 0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org"
@@ -625,8 +629,6 @@
\ " flash http:\\18.85.46.172\new.rom" eval
;
-fload ${BP}/cpu/x86/pc/olpc/nandcastui.fth
-
\ This helps with TeraTerm, which sends ESC-O as the arrow key prefix
also hidden also keys-forth definitions
warning @ warning off
Modified: cpu/x86/pc/olpc/mcastnand.bth
===================================================================
--- cpu/x86/pc/olpc/mcastnand.bth 2008-12-04 09:18:10 UTC (rev 1018)
+++ cpu/x86/pc/olpc/mcastnand.bth 2008-12-04 09:18:18 UTC (rev 1019)
@@ -7,7 +7,7 @@
" ${MCNAND_VERSION}" expand$ " test" $= [if]
" multicast-nand/Makefile" $file-exists? 0= [if]
- " git clone --depth 1 -q git://dev.laptop.org/users/wmb/multicast-nand" expand$ $sh
+ " git clone -q git://dev.laptop.org/users/wmb/multicast-nand" expand$ $sh
[then]
[else]
" rm -rf multicast-nand" $sh
Modified: cpu/x86/pc/olpc/nandcastui.fth
===================================================================
--- cpu/x86/pc/olpc/nandcastui.fth 2008-12-04 09:18:10 UTC (rev 1018)
+++ cpu/x86/pc/olpc/nandcastui.fth 2008-12-04 09:18:18 UTC (rev 1019)
@@ -12,57 +12,46 @@
then
;
-: ether-clone1
- false to already-go?
- " boot rom:cloner ether: 1 /nandflash" eval
+: #enand ( channel# -- )
+ depth 1 < abort" Usage: channel# enand"
+ " rom:mcastnand ether:%d" sprintf boot-load go
;
-: ether-clone6
- false to already-go?
- " boot rom:cloner ether: 6 /nandflash" eval
+: #ether-clone ( channel# -- )
+ depth 1 < abort" Usage: channel# ether-clone"
+ " rom:cloner ether:%d" sprintf boot-load go
;
-: ether-clone11
- false to already-go?
- " boot rom:cloner ether: 11 /nandflash" eval
-;
+: ether-clone1 ( -- ) 1 #ether-clone ;
+: ether-clone6 ( -- ) 6 #ether-clone ;
+: ether-clone11 ( -- ) d# 11 #ether-clone ;
+: enand1 ( -- ) 1 #enand ;
+: enand6 ( -- ) 6 #enand ;
+: enand11 ( -- ) d# 11 #enand ;
-: enand1
- false to already-go?
- " boot rom:mcastnand ether: 1 /nandflash" eval
-;
-: enand6
- false to already-go?
- " boot rom:mcastnand ether: 6 /nandflash" eval
-;
-: enand11
- false to already-go?
- " boot rom:mcastnand ether: 11 /nandflash" eval
-;
-
: mesh-clone
use-mesh
false to already-go?
- " boot rom:cloner 239.255.1.2 12345 /nandflash" eval
+ " boot rom:cloner 239.255.1.2" eval
;
: meshnand
use-mesh
false to already-go?
- " boot rom:mcastnand 239.255.1.2 12345 /nandflash" eval
+ " boot rom:mcastnand 239.255.1.2" eval
;
: mcastnand
false to already-go?
- " boot rom:mcastnand 239.255.1.2 12345 /nandflash" eval
+ " boot rom:mcastnand 239.255.1.2" eval
;
: ucastnand
false to already-go?
- " boot rom:mcastnand 10.20.0.16,,10.20.0.44 12345 /nandflash" eval
+ " boot rom:mcastnand 10.20.0.16,,10.20.0.44" eval
;
: nmcastnand \ Boot from network, for testing
false to already-go?
- " boot http:\\10.20.0.14\mcastnand 239.255.1.2 12345 /nandflash" eval
+ " boot http:\\10.20.0.14\mcastnand 239.255.1.2" eval
;
: dmcastnand \ Boot from USB disk, for testing
false to already-go?
- " boot disk:\mcnand 239.255.1.2 12345 /nandflash" eval
+ " boot disk:\mcnand 239.255.1.2" eval
;
Modified: cpu/x86/pc/olpc/nandstat.fth
===================================================================
--- cpu/x86/pc/olpc/nandstat.fth 2008-12-04 09:18:10 UTC (rev 1018)
+++ cpu/x86/pc/olpc/nandstat.fth 2008-12-04 09:18:18 UTC (rev 1019)
@@ -199,11 +199,14 @@
;
: lowlight ( block# -- ) background-rgb rgb>565 cell-border ;
: highlight ( block# -- ) 0 cell-border ;
-: +block ( offset -- )
- current-block + nand-block-limit mod ( new-block )
+: highlight-block ( block# -- )
current-block lowlight
to current-block
current-block highlight
+;
+: +block ( offset -- )
+ current-block + nand-block-limit mod ( new-block )
+ highlight-block
current-block show-block-status
;
@@ -231,7 +234,7 @@
current-block lowlight
;
-: scan-nand ( -- )
+: (scan-nand) ( -- )
open-nand
nand-map 0= if
#nand-pages nand-pages/block / alloc-mem to nand-map
@@ -255,9 +258,8 @@
show-done
close-nand-ihs
-
- examine-nand
;
+: scan-nand ( -- ) (scan-nand) examine-nand ;
\ LICENSE_BEGIN
\ Copyright (c) 2007 FirmWorks
Added: cpu/x86/pc/olpc/wifichannel.fth
===================================================================
--- cpu/x86/pc/olpc/wifichannel.fth (rev 0)
+++ cpu/x86/pc/olpc/wifichannel.fth 2008-12-04 09:18:18 UTC (rev 1019)
@@ -0,0 +1,127 @@
+
+
+0 value wlan-ih
+d# 2048 buffer: scan-buf
+
+: open-wlan ( -- )
+ " /wlan:force" open-dev to wlan-ih
+ wlan-ih 0= abort" Can't open wireless LAN"
+ " " " set-ssid" wlan-ih $call-method
+;
+
+: analyze-beacons ( -- total-rssi max-rssi #beacons )
+ 0 0 ( tot-rssi max-rssi )
+
+ \ Byte 2 of the scan result is the number of beacons
+ scan-buf 2 + c@ >r ( tot-rssi max-rssi r: #beacons )
+
+ \ The first AP structure begins at offset 3 within the scan result
+ scan-buf 3 + ( tot-rssi max-rssi 'ap r: #beacons )
+
+ r@ 0 ?do ( tot-rssi max-rssi 'ap r: #beacons )
+
+ \ The RSSI is in byte 8 of the AP structure
+ >r r@ 8 + c@ ( tot-rssi max-rssi rssi r: #beacons 'ap )
+
+ \ Update max-rssi
+ 2dup < if ( tot-rssi max-rssi rssi r: #beacons 'ap )
+ nip dup ( tot-rssi max-rssi' rssi r: #beacons 'ap )
+ then ( tot-rssi max-rssi rssi r: #beacons 'ap )
+
+ \ Update tot-rssi
+ rot + swap ( tot-rssi' max-rssi r: #beacons 'ap )
+
+ \ Skip to the next AP structure
+ r@ le-w@ ( tot-rssi max-rssi len r: #beacons 'ap )
+ r> + wa1+ ( tot-rssi max-rssi 'ap' r: #beacons )
+
+ loop ( tot-rssi max-rssi 'ap r: #beacons )
+ drop r> ( tot-rssi max-rssi #beacons )
+;
+
+: channel-stats ( channel# -- total-rssi max-rssi #beacons )
+ 1 swap lshift " set-channel-mask" wlan-ih $call-method
+ scan-buf d# 2048 " scan" wlan-ih $call-method ( actual )
+ if
+ analyze-beacons
+ else
+ 0 0 0
+ then
+;
+
+d# 15 constant rssi-limit
+
+: scan-mesh-channels ( -- chan# max-rssi )
+ d# 11 channel-stats 0= if ( total-rssi max-rssi )
+ 2drop d# 11 0 exit
+ then ( total-rssi max-rssi )
+ nip d# 11 ( max-rssi chan# )
+
+ d# 6 channel-stats 0= if ( max-rssi11 chan11 total-rssi max-rssi )
+ 4drop 6 0 exit
+ then ( max-rssi11 chan11 total-rssi max-rssi )
+ nip ( max-rssi11 chan11 max-rssi6 )
+ rot over > if ( max-rssi11 chan11 max-rssi6 )
+ nip nip 6 ( max-rssi6 chan6 )
+ else ( max-rssi11 chan11 max-rssi6 )
+ drop ( max-rssi11 chan11 )
+ then ( max-rssiN chan# )
+
+ d# 1 channel-stats 0= if ( max-rssiN chan# total-rssi1 max-rssi1 )
+ 4drop 1 0 exit
+ then ( max-rssiN chan# total-rssi1 max-rssi1 )
+ nip ( max-rssiN chan# max-rssi1 )
+ rot over > if ( max-rssiN chan# max-rssi1 )
+ nip nip 1 ( max-rssi1 chan1 )
+ else ( max-rssiN chan# max-rssi1 )
+ drop ( max-rssiN chan# )
+ then ( max-rssiN chan# )
+ swap ( chan# max-rssi )
+;
+
+: quietest-mesh-channel ( -- chan# max-rssi )
+ open-wlan
+ scan-mesh-channels
+ wlan-ih close-dev
+;
+
+
+: multinand-traffic? ( channel# -- flag )
+ " mesh-start" wlan-ih $call-method drop
+ d# 100 0 " set-beacon" wlan-ih $call-method
+ " "(01 00 5e 7e 01 02)" " set-multicast" wlan-ih $call-method
+ d# 300 0 do
+ scan-buf d# 2048 " read" wlan-ih $call-method ( actual )
+ 0> if ( )
+ scan-buf d# 12 + " XO" comp 0= if ( )
+ " mesh-stop" wlan-ih $call-method drop ( )
+ true unloop exit
+ then
+ then
+ 1 ms
+ loop
+ " mesh-stop" wlan-ih $call-method drop
+ false
+;
+: search-channels ( -- true | chan# false )
+ d# 11 multinand-traffic? if d# 11 false exit then
+ d# 6 multinand-traffic? if d# 6 false exit then
+ d# 1 multinand-traffic? if d# 1 false exit then
+ true
+;
+: find-multinand-server ( -- true | chan# false )
+ open-wlan
+ search-channels
+ wlan-ih close-dev
+;
+: enand ( -- )
+ find-multinand-server abort" No multicast NAND server" ( chan# )
+ #enand
+;
+
+d# 10 constant rssi-threshold
+: ether-clone ( -- )
+ quietest-mesh-channel ( chan# rssi )
+ rssi-threshold > abort" No quiet channels" ( chan# )
+ #ether-clone
+;
Modified: dev/olpc/cafenand/badblock.fth
===================================================================
--- dev/olpc/cafenand/badblock.fth 2008-12-04 09:18:10 UTC (rev 1018)
+++ dev/olpc/cafenand/badblock.fth 2008-12-04 09:18:18 UTC (rev 1019)
@@ -33,6 +33,70 @@
<>
;
+: block#-bad? ( block# -- flag )
+ dup 2 rshift ( block# byte# )
+ bbt + c@ ( block# byte )
+ swap 3 and 2* rshift ( bits )
+ 3 and 3 <>
+;
+
+: next-bad-block ( block# -- block#' )
+ usable-page-limit pages/eblock / swap 1+ ?do
+ i block#-bad? if i unloop exit then
+ loop
+ -1
+;
+
+defer xskipchar
+: abs-block>page ( abs-block# -- rel-page# )
+ pages/eblock * partition-start -
+;
+: page>next-abs-block ( rel-page# -- abs-block# )
+ dup -1 = if
+ drop partition-start
+ else
+ partition-start + pages/eblock / 1+
+ then
+;
+
+\ This is a very fast way to extract the bad block information,
+\ taking advantage of the sparseness of bad blocks.
+\ * To find the first bad block, call it with page# = -1.
+\ * Then call it with the page# that was returned the last time.
+\ * When there are no more bad blocks, it returns page# = -1.
+\ Finding all N bad blocks requires only N+1 calls, whereas
+\ using block-bad? would require total#blocks calls.
+\ The implementation skips long spans of good blocks very rapidly.
+
+: next-bad-block ( page# -- page#' )
+ page>next-abs-block
+ usable-page-limit pages/eblock / swap ( limit block# )
+
+ \ Handle initial fragments the hard way
+ begin dup 3 and while ( limit block# )
+ 2dup <= if 2drop -1 exit then ( limit block# )
+ dup block#-bad? if
+ nip abs-block>page exit
+ then ( limit block# )
+ 1+ ( limit block#' )
+ repeat ( limit block#' )
+
+ \ Rapid scan for a non-ff byte
+ 2dup - 2 rshift ( limit block# #bytes )
+ swap 2 rshift bbt + swap ( limit adr #bytes )
+ h# ff xskipchar drop ( limit adr' )
+ bbt - 2 lshift ( limit block# )
+
+ \ Slow scan (4 iterations max) to find the specific block
+ ?do ( )
+ i block#-bad? if
+ i abs-block>page unloop exit
+ then
+ loop
+ -1
+;
+
+
\ Marks the block containing page# as bad
: mark-bad ( page# -- )
>bbt ( adr mask )
@@ -237,6 +301,7 @@
\ Get the existing bad block table, or make a new one if necessary
: get-bbt ( -- )
+ " skipchar" $find if to xskipchar then
get-existing-bbt
bbt0 bbt1 or 0= if
." No bad block table; making one" cr
Modified: dev/olpc/cafenand/redboot.fth
===================================================================
--- dev/olpc/cafenand/redboot.fth 2008-12-04 09:18:10 UTC (rev 1018)
+++ dev/olpc/cafenand/redboot.fth 2008-12-04 09:18:18 UTC (rev 1019)
@@ -52,6 +52,36 @@
part-buf (#partitions) to #partitions
;
+: cscount ( adr -- adr len )
+ dup begin dup c@ while ca1+ repeat ( adr adr' )
+ over -
+;
+
+\ partition# = 0 means the entire disk, -1 means the partition map
+\ type=0:unspecified -1:partition map
+
+: partition-info ( partition# -- start size granularity name$ type )
+ ?dup 0= if
+ 0 usable-page-limit pages/eblock / /eblock " " 0
+ exit
+ then ( partition# )
+
+ \ Redboot partition entry 0 describes the partition map block
+ \ -1 on input asks for info about the partition map area .
+ dup -1 = if 1+ then ( partition#' )
+
+ dup #partitions > if ( partition# )
+ drop 0 0 0 " " -1 exit
+ then ( partition# )
+
+ /partition-entry * part-buf + >r ( r: adr )
+ r@ d# 16 + l@ /eblock / ( start )
+ r@ d# 24 + l@ /eblock / ( start size )
+ /eblock ( start size granularity )
+ r@ cscount d# 16 min ( start size granularity name$ )
+ r> part-buf = if -1 else 0 then ( start size granularity name$ type )
+;
+
: set-partition-number ( partition# -- error? )
dup 0= if ( partition# )
to partition#
Modified: dev/olpc/spiflash/spiui.fth
===================================================================
--- dev/olpc/spiflash/spiui.fth 2008-12-04 09:18:10 UTC (rev 1018)
+++ dev/olpc/spiflash/spiui.fth 2008-12-04 09:18:18 UTC (rev 1019)
@@ -18,11 +18,21 @@
: write-flash-range ( adr end-offset start-offset -- )
." Writing" cr
?do ( adr )
- i .x (cr ( adr )
- i /flash-block mod 0= if i flash-erase-block then
- dup /chunk i flash-write ( adr )
- /chunk + ( adr' )
- /chunk +loop ( adr )
+ \ Save time - don't write if the data is the same
+ i .x (cr ( adr )
+ flash-base -1 = if ( adr )
+ true ( adr must-write? )
+ else ( adr )
+ dup flash-base i + /flash-block comp ( adr must-write? )
+ then ( adr must-write? )
+
+ if
+\ i /flash-block mod 0= if i flash-erase-block then
+ i flash-erase-block
+ dup /flash-block i flash-write ( adr )
+ then
+ /flash-block + ( adr' )
+ /flash-block +loop ( adr )
cr drop ( )
;
@@ -30,8 +40,8 @@
." Verifying" cr
?do ( adr )
i .x (cr
- dup i + /chunk i flash-verify
- /chunk +loop ( adr )
+ dup i + /flash-block i flash-verify
+ /flash-block +loop ( adr )
cr drop ( )
;
Modified: dev/usb2/device/wlan/usb8388.fth
===================================================================
--- dev/usb2/device/wlan/usb8388.fth 2008-12-04 09:18:10 UTC (rev 1018)
+++ dev/usb2/device/wlan/usb8388.fth 2008-12-04 09:18:18 UTC (rev 1019)
@@ -153,7 +153,7 @@
-1 value fw-seq
-: fw-seq++ ( -- ) fw-seq 1+ to fw-seq ;
+: fw-seq++ ( -- seq ) fw-seq 1+ dup to fw-seq ;
d# 30 constant resp-wait-tiny
d# 1,000 constant resp-wait-short
@@ -310,6 +310,7 @@
: +xw ( n -- ) 'x le-w! /w +x ;
: +xb ( n -- ) 'x c! /c +x ;
: +xbl ( n -- ) 'x be-l! /l +x ;
+: +xerase ( n -- ) 'x over erase +x ;
: outbuf-bulk-out ( dlen -- error? )
/fw-cmd + outbuf swap ( adr len )
@@ -385,14 +386,27 @@
dup .cmd
resp-wait-short to resp-wait
outbuf 2 pick /fw-cmd + erase ( len cmd )
- fw-seq++ ( len cmd )
CMD_TYPE_REQUEST outbuf >fw-req le-l! ( len cmd )
( cmd ) outbuf >fw-cmd le-w! ( len )
( len ) /fw-cmd-hdr + outbuf >fw-len le-w! ( )
- fw-seq outbuf >fw-seq le-w! ( )
+ fw-seq++ outbuf >fw-seq le-w! ( )
0 outbuf >fw-result le-w! ( )
set-fw-data-x ( )
;
+: start-cmd ( cmd -- )
+ dup .cmd
+ resp-wait-short to resp-wait
+ outbuf to x 0 to /x
+ CMD_TYPE_REQUEST +xl ( cmd )
+ ( cmd ) +xw ( )
+ 0 +xw ( ) \ Set len later
+ fw-seq++ +xw ( )
+ 0 +xw ( )
+;
+: finish-cmd ( -- len )
+ /x 4 - outbuf 6 + le-w! \ Set len field
+ /x
+;
true value got-response?
true value got-indicator?
@@ -742,6 +756,9 @@
1 constant #probes
+d# 14 constant #channels
+
+[ifdef] notdef
struct
2 field >type-id
2 field >/payload
@@ -749,8 +766,6 @@
2 field >probes
constant /probes-IE
-d# 14 constant #channels
-
struct
1 field >radio-type
1 field >channel#
@@ -775,6 +790,7 @@
/chan-list-IE field >chan-list-IE
/probes-IE field >probes-IE
constant /cmd_802_11_scan
+[then]
1 constant BSS_INDEPENDENT
2 constant BSS_INFRASTRUCTURE
@@ -790,12 +806,13 @@
h# 0050.f202 constant amoui \ WPA authentication suite
-d# 34 instance buffer: ssid
+d# 34 instance buffer: scan-ssid
0 value scan-type
: active-scan ( -- ) 0 to scan-type ;
: passive-scan ( -- ) 1 to scan-type ;
+[ifdef] notdef
: make-chan-list-param ( adr -- )
#channels 0 do
dup i /chan-list * +
@@ -807,9 +824,9 @@
loop drop
;
-: (scan) ( -- error? | adr len 0 )
- /cmd_802_11_scan ssid c@ if
- /marvel-IE-hdr + ssid c@ +
+: (oldscan) ( -- error? | adr len 0 )
+ /cmd_802_11_scan scan-ssid c@ if
+ /marvel-IE-hdr + scan-ssid c@ +
then
6 ( CMD_802_11_SCAN ) prepare-cmd ( )
resp-wait-long to resp-wait ( )
@@ -825,13 +842,13 @@
2 over >/payload le-w! ( 'fw-data 'probes )
#probes swap >probes le-w! ( 'fw-data )
- ssid c@ if ( 'fw-data )
+ scan-ssid c@ if ( 'fw-data )
\ Attach an SSID TLV to filter the result
/cmd_802_11_scan + ( 'ssid )
h# 000 over >type-id le-w! ( 'ssid )
- ssid c@ over >/payload le-w! ( 'ssid )
- ssid count rot /marvel-IE-hdr + swap move ( )
- /cmd_802_11_scan /marvel-IE-hdr ssid c@ + + ( cmdlen )
+ scan-ssid c@ over >/payload le-w! ( 'ssid )
+ scan-ssid count rot /marvel-IE-hdr + swap move ( )
+ /cmd_802_11_scan /marvel-IE-hdr scan-ssid c@ + + ( cmdlen )
else ( 'fw-data )
drop
/cmd_802_11_scan ( cmdlen )
@@ -842,8 +859,62 @@
respbuf /respbuf /fw-cmd /string rot ( adr len 0 )
then
;
+[then]
+h# 7ffe instance value channel-mask
+
+: +chan-list-tlv ( -- )
+ h# 101 +xw
+ 0 +xw 'x >r ( r: 'payload )
+ #channels 1+ 1 do
+ 1 i lshift channel-mask and if
+ 0 +xb \ Radio type
+ i +xb \ Channel #
+ scan-type +xb \ Scan type - 0:active or 1:passive
+ d# 100 +xw \ Min scan time
+ d# 100 +xw \ Max scan time
+ then
+ loop
+ 'x r@ - r> 2- le-w!
+;
+
+: +probes-tlv ( -- )
+ h# 102 +xw \ Probes TLV
+ 2 +xw \ length
+ #probes +xw \ #probes
+;
+
+: +ssid-tlv ( -- )
+ scan-ssid c@ if
+ 0 +xw \ SSID TLV
+ scan-ssid c@ +xw \ length
+ scan-ssid count +x$
+ then
+;
+
+: (scan) ( -- error? | adr len 0 )
+ 6 ( CMD_802_11_SCAN ) start-cmd
+ resp-wait-long to resp-wait
+
+ BSS_ANY +xb
+ 6 +xerase \ BSS ID
+
+ +chan-list-tlv
+ +probes-tlv
+ +ssid-tlv
+
+ finish-cmd outbuf-wait ( error? )
+ dup 0= if ( error? )
+ respbuf /respbuf /fw-cmd /string rot ( adr len 0 )
+ then
+;
+
+
external
+: set-channel-mask ( n -- )
+ h# 7ffe and to channel-mask
+;
+
\ Ask the device to look for the indicated SSID.
: set-ssid ( adr len -- )
\ This is an optimization for NAND update over the mesh.
@@ -851,7 +922,7 @@
\ from transmitting when they come on-line.
2dup " olpc-mesh" $= if passive-scan then
- h# 32 min ssid pack drop
+ h# 32 min scan-ssid pack drop
;
: scan ( adr len -- actual )
@@ -1073,7 +1144,14 @@
: mesh-start ( channel -- error? )
\ h# 223 (0x100 + 291) is an old value
\ h# 125 (0x100 + 37) is an "official" value that doesn't work
- h# 223 (mesh-start) dup 0= if ( error? )
+ dup h# 223 (mesh-start) if ( channel )
+ \ Retry once
+ h# 223 (mesh-start) ( error? )
+ else
+ drop false ( error? )
+ then
+
+ dup 0= if ( error? )
tx-ctrl TX_WDS or to tx-ctrl ( error? )
ds-associated set-driver-state ( error? )
then ( error? )
More information about the openfirmware
mailing list