Author: wmb Date: 2008-12-04 10:18:29 +0100 (Thu, 04 Dec 2008) New Revision: 1021
Modified: clients/lib/lib.c clients/lib/printf.c cpu/x86/pc/olpc/fsupdate.fth cpu/x86/pc/olpc/mcastnand.bth cpu/x86/pc/olpc/nandcastui.fth cpu/x86/pc/olpc/olpc.bth cpu/x86/pc/olpc/versions.fth cpu/x86/pc/olpc/wifichannel.fth Log: OLPC - secure NANDblaster support.
Modified: clients/lib/lib.c =================================================================== --- clients/lib/lib.c 2008-12-04 09:18:23 UTC (rev 1020) +++ clients/lib/lib.c 2008-12-04 09:18:29 UTC (rev 1021) @@ -69,7 +69,7 @@ int ofw_setup() { - static char *argv[8]; + static char *argv[10]; phandle ph; char *argstr; int i; @@ -82,7 +82,7 @@ argv[0] = get_str_prop(ph, "bootpath", ALLOC); argstr = get_str_prop(ph, "bootargs", ALLOC);
- for (i = 1; i < 8;) { + for (i = 1; i < 10;) { if (*argstr == '\0') break; argv[i++] = argstr;
Modified: clients/lib/printf.c =================================================================== --- clients/lib/printf.c 2008-12-04 09:18:23 UTC (rev 1020) +++ clients/lib/printf.c 2008-12-04 09:18:29 UTC (rev 1021) @@ -5,9 +5,10 @@ #include "1275.h"
#include <stdarg.h> +#include "stdio.h"
int -atoi(char *s) +atoi(const char *s) { int temp = 0, base = 10;
@@ -175,6 +176,7 @@ va_start(args, fmt); i = _printf(fmt, args); va_end(args); + fflush(stdout); return (i); }
Modified: cpu/x86/pc/olpc/fsupdate.fth =================================================================== --- cpu/x86/pc/olpc/fsupdate.fth 2008-12-04 09:18:23 UTC (rev 1020) +++ cpu/x86/pc/olpc/fsupdate.fth 2008-12-04 09:18:29 UTC (rev 1021) @@ -196,10 +196,13 @@
: $update-nand ( devspec$ -- ) load-crypto abort" Can't load the crypto functions" - null$ cn-buf place null$ pn-buf place ( devspec$ ) - 2dup [char] \ split-string 2drop dn-buf place ( devspec$ ) - boot-read - loaded do-fs-update + null$ cn-buf place ( devspec$ ) + 2dup ( devspec$ devspec$ ) + [char] : right-split-string dn-buf place ( devspec$ path+file$ ) + [char] \ right-split-string ( devspec$ file$ path$ ) + dup if 1- then pn-buf place ( devspec$ file$ ) + 2drop ( devspec$ ) + boot-read loaded do-fs-update ( ) ; : update-nand ( "devspec" -- ) safe-parse-word $update-nand ;
Modified: cpu/x86/pc/olpc/mcastnand.bth =================================================================== --- cpu/x86/pc/olpc/mcastnand.bth 2008-12-04 09:18:23 UTC (rev 1020) +++ cpu/x86/pc/olpc/mcastnand.bth 2008-12-04 09:18:29 UTC (rev 1021) @@ -19,7 +19,7 @@ " rm multicast-nand.tar.gz" $sh [then]
-" (cd multicast-nand; make BPDIR=../../../../../.. mcastnand.bin blaster.bin cloner.bin; cp mcastnand.bin blaster.bin cloner.bin ..)" expand$ $sh +" (cd multicast-nand; make BPDIR=../../../../../.. nandblaster_rx.bin nandblaster_tx.bin; cp nandblaster_rx.bin nandblaster_tx.bin ..)" expand$ $sh
\ This forces the creation of a .log file, so we don't re-fetch writing mcastnand.version
Modified: cpu/x86/pc/olpc/nandcastui.fth =================================================================== --- cpu/x86/pc/olpc/nandcastui.fth 2008-12-04 09:18:23 UTC (rev 1020) +++ cpu/x86/pc/olpc/nandcastui.fth 2008-12-04 09:18:29 UTC (rev 1021) @@ -11,47 +11,72 @@ " olpc-mesh" $essid then ; +: $file-to-mem ( filename$ -- adr len ) + $read-open + ifd @ fsize dup alloc-mem swap ( adr len ) + 2dup ifd @ fgets ( adr len actual ) + ifd @ fclose ( adr len actual ) + over <> abort" Can't read file" cr ( adr len ) +; +: load-read ( filename$ -- ) + open-dev dup 0= abort" Can't open file" >r ( r: ih ) + load-base " load" r@ $call-method !load-size + r> close-dev +;
-: #enand ( channel# -- ) - depth 1 < abort" Usage: channel# enand" - " rom:mcastnand ether:%d" sprintf boot-load go +d# 20 value redundancy + +: #nb ( channel# -- ) + depth 1 < abort" Usage: channel# #nb" + " rom:nb_rx ether:%d" sprintf boot-load go ; -: #ether-clone ( channel# -- ) - depth 1 < abort" Usage: channel# ether-clone" - " rom:cloner ether:%d" sprintf boot-load go +: #nb-clone ( channel# -- ) + depth 1 < abort" Usage: channel# #nb-clone" + redundancy swap + " rom:nb_tx ether:%d nand: %d" sprintf boot-load go ; -: 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 ; +: #nb-update ( placement-filename$ image-filename$ channel# -- ) + depth 5 < abort" #nb-update - too few arguments" + >r 2>r ( placement-filename$ r: channel# image-filename$ ) + $file-to-mem ( spec$ r: channel# image-filename$ ) + swap redundancy 2r> r> ( speclen specadr redundancy image-filename$ channel# ) + " rom:nb_tx ether:%d %s 131072 %d %d %d" sprintf boot-load go +; +: #nb-secure ( zip-filename$ image-filename$ channel# -- ) + depth 5 < abort" #nb-secure-update - too few arguments" + >r 2>r ( placement-filename$ r: channel# image-filename$ ) + load-read sig$ ?save-string swap ( siglen sigadr r: channel# image-filename$ ) + img$ ?save-string swap ( siglen sigadr speclen specadr r: channel# image-filename$ ) + redundancy 2r> r> ( siglen sigadr speclen specadr redundancy image-filename$ channel# ) + " rom:nb_tx ether:%d %s 131072 %d %d %d %d %d" sprintf boot-load go +; +: t1 " u:\os767.plc" " u:\os767.img" d# 11 #nb-update ; +: t2 " u:\fs.zip" " u:\os767.img" d# 11 #nb-secure ;
+: nb-clone1 ( -- ) 1 #nb-clone ; +: nb-clone6 ( -- ) 6 #nb-clone ; +: nb-clone11 ( -- ) d# 11 #nb-clone ; +: nb1 ( -- ) 1 #nb ; +: nb6 ( -- ) 6 #nb ; +: nb11 ( -- ) d# 11 #nb ; + : mesh-clone use-mesh false to already-go? - " boot rom:cloner 239.255.1.2" eval + redundancy " boot rom:nb_tx udp:239.255.1.2 nand: %d" sprintf eval ;
: meshnand use-mesh false to already-go? - " boot rom:mcastnand 239.255.1.2" eval + " boot rom:nb_rx 239.255.1.2" eval ;
-: mcastnand +: nb_rx false to already-go? - " boot rom:mcastnand 239.255.1.2" eval + " boot rom:nb_rx 239.255.1.2" eval ; : ucastnand false to already-go? - " boot rom:mcastnand 10.20.0.16,,10.20.0.44" eval + " boot rom:nb_rx 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" eval -; -: dmcastnand \ Boot from USB disk, for testing - false to already-go? - " boot disk:\mcnand 239.255.1.2" eval -;
Modified: cpu/x86/pc/olpc/olpc.bth =================================================================== --- cpu/x86/pc/olpc/olpc.bth 2008-12-04 09:18:23 UTC (rev 1020) +++ cpu/x86/pc/olpc/olpc.bth 2008-12-04 09:18:29 UTC (rev 1021) @@ -74,9 +74,11 @@ " ${BP}/cpu/x86/pc/olpc/build/dsdt.aml" " dsdt" $add-deflated-dropin \ " ${BP}/cpu/x86/pc/olpc/build/ssdt.aml" " ssdt" $add-deflated-dropin
- " ${BP}/cpu/x86/pc/olpc/build/mcastnand.bin" " mcastnand" $add-deflated-dropin - " ${BP}/cpu/x86/pc/olpc/build/blaster.bin" " blaster" $add-deflated-dropin - " ${BP}/cpu/x86/pc/olpc/build/cloner.bin" " cloner" $add-deflated-dropin + " ${BP}/cpu/x86/pc/olpc/build/nandblaster_rx.bin" " nb_rx" $add-deflated-dropin + " ${BP}/cpu/x86/pc/olpc/build/nandblaster_tx.bin" " nb_tx" $add-deflated-dropin +\ " ${BP}/cpu/x86/pc/olpc/build/multicast-nand/mcastnand.elf" " mcastnand" $add-deflated-dropin +\ " ${BP}/cpu/x86/pc/olpc/build/blaster.bin" " blaster" $add-deflated-dropin +\ " ${BP}/cpu/x86/pc/olpc/build/cloner.bin" " cloner" $add-deflated-dropin
/rom h# 400 - pad-file \ rmstart image must start 0x400 from end " rmstart.img" $add-file
Modified: cpu/x86/pc/olpc/versions.fth =================================================================== --- cpu/x86/pc/olpc/versions.fth 2008-12-04 09:18:23 UTC (rev 1020) +++ cpu/x86/pc/olpc/versions.fth 2008-12-04 09:18:29 UTC (rev 1021) @@ -2,7 +2,7 @@
\ The overall firmware revision macro: FW_MAJOR E -macro: FW_MINOR 22b +macro: FW_MINOR 22h
\ The EC microcode macro: EC_VERSION e21 @@ -26,5 +26,6 @@ \ With a specific ID, mcastnand.bth will download a tarball without .git stuff. \ With "test", mcastnand.bth will clone the git head if build/multicast-nand/ \ is not already present, then you can modify the git subtree as needed. -macro: MCNAND_VERSION 5f202b05147826ad69fcb849b92290681a56c70c +\ macro: MCNAND_VERSION 5f202b05147826ad69fcb849b92290681a56c70c \ macro: MCNAND_VERSION test +macro: MCNAND_VERSION HEAD
Modified: cpu/x86/pc/olpc/wifichannel.fth =================================================================== --- cpu/x86/pc/olpc/wifichannel.fth 2008-12-04 09:18:23 UTC (rev 1020) +++ cpu/x86/pc/olpc/wifichannel.fth 2008-12-04 09:18:29 UTC (rev 1021) @@ -51,41 +51,35 @@
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# ) +\ Keep the rssi,chan pair with the lowest max-rssi value +: lowest-rssi ( max-rssiN chanN max-rssiM chanM -- max-rssiP P ) + 3 pick 2 pick ( max-rssiN chanN max-rssiM chanM max-rssiN max-rssiM ) + u> if 2nip else 2drop then ( max-rssiP chanP ) +;
- 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# ) +: try-channel ( max-rssiN N chan# -- max-rssiN' N' no-beacons? ) + >r r@ channel-stats 0= if ( max-rssiN N total-rssi max-rssi r: chan# ) + \ No beacons - this one is an automatic winner + 4drop 0 r> true ( max-rssiN' N' no-beacons? ) + else ( max-rssiN N total-rssi max-rssi r: chan# ) + \ Some activity on this channel - keep it if it's the quietest so far + nip r> lowest-rssi false ( max-rssiN' N' no-beacons? ) + then ( max-rssiN' N' no-beacons? ) +;
- 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 ) +: scan-mesh-channels ( -- max-rssi chan# ) + h# ffffffff 0 ( max-rssi0 0 ) \ This high rssi always loses + d# 11 try-channel if exit then ( max-rssiN chanN ) + d# 6 try-channel if exit then ( max-rssiN chanN ) + d# 1 try-channel drop ( max-rssi chan# ) ;
-: quietest-mesh-channel ( -- chan# max-rssi ) +: quietest-mesh-channel ( -- max-rssi chan# ) 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 @@ -116,12 +110,12 @@ ; : enand ( -- ) find-multinand-server abort" No multicast NAND server" ( chan# ) - #enand + #nb ;
d# 10 constant rssi-threshold : ether-clone ( -- ) - quietest-mesh-channel ( chan# rssi ) - rssi-threshold > abort" No quiet channels" ( chan# ) - #ether-clone + quietest-mesh-channel ( rssi chan# ) + swap rssi-threshold > abort" No quiet channels" ( chan# ) + #nb-clone ;
openfirmware@openfirmware.info