From 0087d42a6809902c10abf699d0bea50af64af436 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Mon, 18 Apr 2011 05:58:04 +0000 Subject: [PATCH] boot(8): add cwfs support to, restart if mount fails, usbd. cwfs: exit code --- sys/src/9/boot/bootrc | 156 +++++++++++++++++------------------- sys/src/9/boot/local.rc | 25 +----- sys/src/9/pc/pccd | 2 - sys/src/9/port/bootfs.proto | 7 +- sys/src/cmd/cwfs/main.c | 3 + 5 files changed, 85 insertions(+), 108 deletions(-) diff --git a/sys/src/9/boot/bootrc b/sys/src/9/boot/bootrc index 0ae023aa0..dabc77aca 100644 --- a/sys/src/9/boot/bootrc +++ b/sys/src/9/boot/bootrc @@ -33,10 +33,9 @@ fn must { fn usbinit{ - if(test -f '#u'){ + if(test -e '#u'){ bind -a '#u' /dev - # TODO: check access to /dev/usb - must usbd + must usb/usbd } } @@ -48,10 +47,6 @@ fn kbmap{ } fn readmethod{ - resp=() - timeo=5 - found=0 - echo echo Storage devices for(i in /dev/sd??){ @@ -60,13 +55,15 @@ fn readmethod{ partitions: `{cat $i/ctl | grep part | awk '{print $2}'} } + found=0 while(~ $found 0){ - if(~ $#pcload 0) - echo -n 'root is from: ' - if not - echo -n 'kernel is at: ' - + timeo=5 + resp=() while(~ $#resp 0){ + if(~ $#pcload 0) + echo -n 'root is from: ' + if not + echo -n 'kernel is at: ' resp=`{read} if(! ~ $status ''){ bootconf # set configuration from file @@ -74,9 +71,11 @@ fn readmethod{ bootargs=$nobootprompt resp=$bootargs } - if(~ $resp !rc) - rc - timeo=0 + if(~ $resp !rc){ + rc -i + resp=() + } + timo=0 } method=`{echo $resp | awk -F! '{print $1}'} @@ -86,10 +85,8 @@ fn readmethod{ if(~ $mtab($i) m^$method) found = $i } - if(~ $found 0){ echo method $method not found - resp=() } } @@ -98,25 +95,19 @@ fn readmethod{ } fn authentication{ - # in pcload we only need to read the kernel - if(~ $pcload 1) - user=none - - if(! test -x /boot/factotum){ - if(~ $#user 0) - user=glenda - echo -n $user > '#c'/hostowner - } - - if not{ - x=(/boot/factotum -u -sfactotum) + 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 -S) + x=($x -kS) + if not + x=($x -u) if(! ~ $#authaddr 0) x=($x -a $authaddr) if(! ~ $#debugfactotum 0) x=($x -p) - must $x } } @@ -126,58 +117,59 @@ fn swapproc{ echo -n start > '#c'/swap } +fn main{ + readmethod + $mp($config) + + switch($method){ + case local + islocal=1 + case hybrid + ishybrid=1 + } + + # authentication agent + authentication + + # connect to the root file system + $mp($connect) + + mount -c /srv/boot /root + if(~ $pcload 1) + echo reboot /root/$kern >/dev/reboot + + swapproc + + # remove part of our temporary root + unmount /$cputype/bin /bin + /mnt/broot/$cputype/bin/unmount /rc/bin /bin + /mnt/broot/$cputype/bin/unmount /boot /bin + /mnt/broot/$cputype/bin/unmount / + + # create the name space, mount the root fs + /mnt/broot/$cputype/bin/bind / / + /mnt/broot/$cputype/bin/mount -ac '#s/boot' / + + # remove the remaining temporary root + /mnt/broot/$cputype/bin/unmount /mnt/broot + + rootdir=/root + + if(~ $#init 0){ + init=/$cputype/init + if(~ $cpuflag 1) + init=($init -c) + if not + init=($init -t) + # TODO handle mflag + } + exec $init +} + usbinit # set up usb keyboard, mouse, and disk, if any +configlocal # add partitions and binds kbmap -configlocal # add partitions and binds - -readmethod -$mp($config) - -switch($method){ -case local - islocal=1 -case hybrid - ishybrid=1 +while(){ + @{rfork n; main} } - -# authentication agent -authentication - -# connect to the root file system -$mp($connect) - -swapproc - -mount -c '#s/boot' /root - -# remove part of our temporary root -unmount /$cputype/bin /bin -/mnt/broot/$cputype/bin/unmount /rc/bin /bin -/mnt/broot/$cputype/bin/unmount /boot /bin -/mnt/broot/$cputype/bin/unmount / - -if(~ $pcload 1) - /boot/echo reboot /root/$kern >/dev/reboot - -# create the name space, mount the root fs -/mnt/broot/$cputype/bin/bind / / -/mnt/broot/$cputype/bin/mount -ac '#s/boot' / - -# remove the remaining temporary root -/mnt/broot/$cputype/bin/unmount /mnt/broot - -rootdir=/root - -if(~ $#init 0){ - init=/$cputype/init - if(~ $cpuflag 1) - init=($init -c) - if not - init=($init -t) - # TODO handle mflag -} - -$init - - diff --git a/sys/src/9/boot/local.rc b/sys/src/9/boot/local.rc index 8e696f6fa..5ba6378c0 100755 --- a/sys/src/9/boot/local.rc +++ b/sys/src/9/boot/local.rc @@ -36,11 +36,12 @@ fn configlocal{ } fn connectlocal{ + rm -f /srv/boot switch($fstype){ - case fossil - connectlocalfossil case fs connectlocalkfs + case fscache fsworm + must cwfs64x -n boot -f $disk^/$fstype case data # test for cd/dvd x=`{sed '/([Cc][Dd]|[Dd][Vv][Dd])/!d' $disk^/ctl} @@ -50,23 +51,3 @@ fn connectlocal{ fatal unknown partition $fstype } } - -fn connectlocalfossil{ - if(! test -x /bin/fossil/fossil){ - echo no fossil - exit nofossil - } - - partition=$disk^/$fstype - - # settime(1, -1, nil) - - # make venti available - - # start fossil - echo 'fossil('$partition')...' - must fossil/fossil -f $partition -c 'srv -A boot' -c 'srv -p fscons' -} - - - diff --git a/sys/src/9/pc/pccd b/sys/src/9/pc/pccd index 76dc6afe9..619eda64a 100644 --- a/sys/src/9/pc/pccd +++ b/sys/src/9/pc/pccd @@ -125,8 +125,6 @@ boot boot #S/sdD0/data bootdir bootpccd.out boot - /386/bin/auth/factotum /386/bin/bzfs - /386/bin/echo /386/bin/mntgen rootfs.bz2 diff --git a/sys/src/9/port/bootfs.proto b/sys/src/9/port/bootfs.proto index 7c050fe08..ea8d4942c 100644 --- a/sys/src/9/port/bootfs.proto +++ b/sys/src/9/port/bootfs.proto @@ -1,6 +1,8 @@ $cputype bin 9660srv + auth + factotum awk bind bzfs @@ -12,8 +14,7 @@ $cputype prep dossrv echo - fossil - fossil + cwfs64x grep gunzip hoc @@ -30,6 +31,8 @@ $cputype srv test unmount + usb + usbd xd rc lib diff --git a/sys/src/cmd/cwfs/main.c b/sys/src/cmd/cwfs/main.c index bd8265c0c..f1942e1fc 100644 --- a/sys/src/cmd/cwfs/main.c +++ b/sys/src/cmd/cwfs/main.c @@ -410,6 +410,9 @@ main(int argc, char **argv) * processes to read the console */ consserve(); + + /* success */ + exits(nil); } /*