From b261a0c31b3d2e134b3c6cc07020e83c593a29db Mon Sep 17 00:00:00 2001 From: iru Date: Sun, 17 Apr 2011 17:25:55 -0300 Subject: [PATCH] Add /sys/src/9/boot/tread, a tool to read a line with a timeout. While here, remove boot(8) references to pcload. --- sys/src/9/boot/bootmkfile | 4 ++ sys/src/9/boot/bootrc | 20 ++-------- sys/src/9/boot/conf.rc | 3 +- sys/src/9/boot/local.rc | 7 ---- sys/src/9/boot/tread.c | 73 +++++++++++++++++++++++++++++++++++++ sys/src/9/port/bootfs.proto | 1 + sys/src/9/port/mkbootfs | 5 +++ 7 files changed, 88 insertions(+), 25 deletions(-) mode change 100755 => 100644 sys/src/9/boot/local.rc create mode 100644 sys/src/9/boot/tread.c diff --git a/sys/src/9/boot/bootmkfile b/sys/src/9/boot/bootmkfile index 0b873ae7a..af1fcb3f6 100644 --- a/sys/src/9/boot/bootmkfile +++ b/sys/src/9/boot/bootmkfile @@ -16,3 +16,7 @@ $BOOTFILES: $BOOTDIR/boot.h %.$O: $BOOTDIR/%.c $CC -I$BOOTDIR $CFLAGS $BOOTDIR/$stem.c + +tread: tread.c + $CC tread.c + $LD -o tread tread.8 diff --git a/sys/src/9/boot/bootrc b/sys/src/9/boot/bootrc index 2e2355a63..ac07aa42d 100644 --- a/sys/src/9/boot/bootrc +++ b/sys/src/9/boot/bootrc @@ -67,22 +67,17 @@ fn readmethod{ timeo=5 resp=() while(~ $#resp 0){ - if(~ $#pcload 0) - echo -n 'root is from: ' - if not - echo -n 'kernel is at: ' - resp=`{read} + echo -n 'root is from: ' + resp=`{tread $timeo} if(! ~ $status ''){ bootconf # set configuration from file if(! ~ $#nobootprompt 0) bootargs=$nobootprompt resp=$bootargs } - if(~ $resp !rc){ + if(~ $resp !rc) rc -i - resp=() - } - timo=0 + timeo=0 } method=`{echo $resp | awk -F! '{print $1}'} @@ -103,9 +98,6 @@ fn readmethod{ fn authentication{ if(! test -f /srv/factotum){ - # in pcload we only need to read the kernel - if(~ $pcload 1) - user=none x=(auth/factotum -sfactotum) if(~ $cpuflag 1) x=($x -kS) @@ -142,10 +134,6 @@ fn main{ $mp($connect) must mount -c /srv/boot /root - if(~ $pcload 1){ - echo reboot /root/$kern >/dev/reboot - fatal kernel load failed: $kern - } swapproc diff --git a/sys/src/9/boot/conf.rc b/sys/src/9/boot/conf.rc index dd217c6c0..a82594d8d 100755 --- a/sys/src/9/boot/conf.rc +++ b/sys/src/9/boot/conf.rc @@ -28,8 +28,7 @@ fn confmount{ } fn findconf{ - # search cd/dvd drives first - for(d in $cddevs /dev/sd* /dev/fd*disk) + for(d in /dev/sd*) for(p in `{ls $d}){ if(~ $found 0){ confmount $p diff --git a/sys/src/9/boot/local.rc b/sys/src/9/boot/local.rc old mode 100755 new mode 100644 index dd35a2f33..7b5c85cdb --- a/sys/src/9/boot/local.rc +++ b/sys/src/9/boot/local.rc @@ -5,13 +5,6 @@ fn configlocal{ fstype=`{echo $disk | sed 's,.*/(.*)$,\1,g'} disk=`{echo $disk | sed 's,(.*)/.*$,\1,'} - if(~ $pcload 1){ - kern=`{echo $methodarg | sed 's,.*!(.*)$,\1,g'} - - # for now we only allow kernels in the same dev/part of $methodargs - if(~ $#kern 0 || ! ~ $#bootfile 0) - kern=`{echo $bootfile | sed 's,.*!(.*)$,\1,g'} - } diskparts } diff --git a/sys/src/9/boot/tread.c b/sys/src/9/boot/tread.c new file mode 100644 index 000000000..068bcbfca --- /dev/null +++ b/sys/src/9/boot/tread.c @@ -0,0 +1,73 @@ +#include +#include + +int c; + +int +alarmed(void *a, char *msg) +{ + USED(a); + USED(msg); + if(!c) + exits("timedout"); + noted(NCONT); + return 1; +} + +void +readline(int fd, char *buf, int nbuf) +{ + int i, n; + + i = 0; + while(i < nbuf-1){ + n = read(fd, &c, sizeof c); + alarm(0); + c &= 0xff; + write(fd, &c, 1); + if(n != 1 || c == '\04' || c == '\177'){ + i = 0; + break; + } else if(c == '\n') + break; + else if(c == '\b' && i > 0) + --i; + else if(c == ('u' & 037)){ + c = '\b'; + for(n=0; n <= i; n++) + write(fd, &c, 1); + i = 0; + } else + buf[i++] = c; + } + buf[i] = 0; +} + +void +main(int argc, char *argv[]) +{ + int fd, ctl, i; + char buf[256]; + long n; + + if(argc < 2) + sysfatal("usage: tread timeout"); + + atnotify(alarmed, 1); + + fd = open("/dev/cons", ORDWR); + if(fd < 0) + sysfatal("open cons: %r"); + ctl = open("/dev/consctl", OWRITE); + if(ctl < 0) + sysfatal("open consctl: %r"); + + write(ctl, "rawon", 5); + alarm(atoi(argv[1])*1000); + + readline(fd, buf, sizeof(buf)); + close(ctl); + close(fd); + print("%s", buf); + exits(nil); +} diff --git a/sys/src/9/port/bootfs.proto b/sys/src/9/port/bootfs.proto index ea8d4942c..9046a8e51 100644 --- a/sys/src/9/port/bootfs.proto +++ b/sys/src/9/port/bootfs.proto @@ -30,6 +30,7 @@ $cputype seq srv test + tread 555 sys sys ../boot/tread unmount usb usbd diff --git a/sys/src/9/port/mkbootfs b/sys/src/9/port/mkbootfs index d8867c5ad..949284f45 100755 --- a/sys/src/9/port/mkbootfs +++ b/sys/src/9/port/mkbootfs @@ -33,6 +33,11 @@ fn rootbz2 { rm boot.bz2 } +@{cd ../boot + . /$cputype/mkfile + mk -f bootmkfile tread +} + bootraw bootbz2 rootbz2