Browse Source

Plan 9 from Bell Labs 2011-07-22

David du Colombier 12 years ago
parent
commit
7dfdee01e2

+ 16 - 134
sys/src/9/boot/boot.c

@@ -23,143 +23,10 @@ int	debugboot;
 char	*bargv[Nbarg];
 int	bargc;
 
-static char usbdisk0[] = "/dev/sdU0.0";
-static char sdxxctl[]  = "/dev/sdXX/ctl";
-
 static void	swapproc(void);
 static Method	*rootserver(char*);
 static void	kbmap(void);
 
-/*
- * run argv[0] (short name is name) and wait awhile for file to appear.
- * file must be generated by running argv[0]; if it already exists, we're done.
- */
-static int
-start(char *name, char **argv, char *file)
-{
-	int cnt;
-
-	if(access(file, AEXIST) >= 0)
-		return 0;
-	if(access(argv[0], AEXIST) < 0) {
-		fprint(2, "no %s...", argv[0]);
-		return -1;
-	}
-
-	if(debugboot)
-		fprint(2, "%s...", name);
-	runv(argv);
-	for(cnt = 10; cnt > 0 && access(file, AEXIST) < 0; cnt--)
-		sleep(100);
-	if (cnt <= 0) {
-		fprint(2, "no %s...", name);
-		return -1;
-	}
-	return 0;
-}
-
-static int
-chmod(char *file, int mode)
-{
-	Dir *dir;
-
-	dir = dirstat(file);
-	if (dir == nil) {
-		if(debugboot)
-			fprint(2, "can't stat %s: %r\n", file);
-		return -1;
-	}
-	dir->mode &= ~0777;
-	dir->mode |= mode & 0777;
-	dirwstat("/srv/" PARTSRV, dir);
-	free(dir);
-	return 0;
-}
-
-/* start partfs on first usb disk, if any */
-static int
-startpartfs(int post)
-{
-	int r, i;
-	char *parts;
-	char *partfsv[32];
-
-	if(access(usbdisk0, AEXIST) < 0)
-		return -1;	/* can't run partfs until usbd is mounted */
-
-	if (post)
-		remove("/srv/" PARTSRV);
-
-	i = 0;
-	partfsv[i++] = "/boot/partfs";
-	/*
-	 * hack for booting from usb: if /env/sdB0part (from 9load) exists,
-	 * pass it to partfs for sdXX.
-	 */
-	parts = getenv("sdB0part");
-	if (parts != nil) {
-		partfsv[i++] = "-p";
-		partfsv[i++] = parts;
-	}
-	if (post) {
-		partfsv[i++] = "-s";
-		partfsv[i++] = PARTSRV;
-	}
-	partfsv[i++] = usbdisk0;
-	partfsv[i] = nil;
-	r = start("partfs", partfsv, sdxxctl);
-
-	if (post)
-		chmod("/srv/" PARTSRV, 0666);
-	return r;
-}
-
-static int
-mountusb(void)
-{
-	int fd;
-
-	if(debugboot)
-		fprint(2, "mount usbd...");
-	fd = open("/srv/usb", ORDWR);
-	if(fd < 0)
-		warning("can't open /srv/usb");
-	else if(mount(fd, -1, "/dev", MBEFORE, "") < 0) {
-		warning("mount -a /srv/usb /dev");
-		close(fd);
-	} else
-		return 0;		/* mount closed fd */
-	return -1;
-}
-
-int
-mountusbparts(void)
-{
-	mountusb();
-	return startpartfs(Post);
-}
-
-static void
-usbinit(int post)
-{
-	int cnt;
-	static char *usbdv[] = { "/boot/usbd", nil };
-
-	if(access("#u/usb/ctl", 0) < 0 || bind("#u", "/dev", MAFTER) < 0)
-		return;
-	if(debugboot)
-		fprint(2, "usbinit...");
-	start("usbd", usbdv, "/srv/usb");
-
-	/* allow a little time for usbd's device discovery */
-	for(cnt = 20; cnt > 0 && access(usbdisk0, AEXIST) < 0; cnt--)
-		sleep(100);
-	if(cnt > 0)
-		startpartfs(post);
-	else if(debugboot)
-		fprint(2, "no usb disk...");
-}
-
 void
 boot(int argc, char *argv[])
 {
@@ -168,7 +35,7 @@ boot(int argc, char *argv[])
 	char *cmd, cmdbuf[64], *iargv[16];
 	char rootbuf[64];
 	int islocal, ishybrid;
-	char *rp, *rsp;
+	char *rp, *rsp, *rdparts;
 	int iargc, n;
 	char buf[32];
 	AuthInfo *ai;
@@ -238,6 +105,21 @@ boot(int argc, char *argv[])
 	 */
 	kbmap();
 
+	/* don't trigger aoe until the network has been configured */
+	bind("#æ", "/dev", MAFTER);	/* nvram could be here */
+	bind("#S", "/dev", MAFTER);	/* nvram could be here */
+
+	/*
+	 * read disk partition tables here so that readnvram via factotum
+	 * can see them.  ideally we would have this information in
+	 * environment variables before attaching #S, which would then
+	 * parse them and create partitions.
+	 */
+	rdparts = getenv("readparts");
+//	if(rdparts)
+//		readparts();
+	free(rdparts);
+
 	/*
  	 *  authentication agent
 	 *  sets hostowner, creating an auth discontinuity

+ 4 - 0
sys/src/9/boot/boot.h

@@ -17,6 +17,7 @@ extern char*	rootdir;
 extern int	(*cfs)(int);
 extern int	cpuflag;
 extern char	cputype[];
+extern int	debugboot;
 extern int	fflag;
 extern int	kflag;
 extern Method	method[];		/* defined in ../$arch/boot$CONF.c */
@@ -32,6 +33,7 @@ extern int	pcload;
 extern void	authentication(int);
 extern int	cache(int);
 extern char*	checkkey(Method*, char*, char*);
+extern int	chmod(char *file, int mode);
 extern void	fatal(char*);
 extern void	getpasswd(char*, int);
 extern void	key(int, Method*);
@@ -39,6 +41,7 @@ extern int	mountusbparts(void);
 extern int	outin(char*, char*, int);
 extern int	plumb(char*, char*, int*, char*);
 extern int	readfile(char*, char*, int);
+extern int	readparts(void);
 extern long	readn(int, void*, long);
 extern void	run(char *file, ...);
 extern void	runv(char **argv);
@@ -46,6 +49,7 @@ extern int	sendmsg(int, char*);
 extern void	setenv(char*, char*);
 extern void	settime(int, int, char*);
 extern void	srvcreate(char*, int);
+extern void	usbinit(int post);
 extern void	warning(char*);
 extern int	writefile(char*, char*, int);
 extern void	boot(int, char **);

+ 4 - 0
sys/src/9/boot/bootip.c

@@ -73,6 +73,8 @@ configip(int bargc, char **bargv, int needfs)
 	}
 
 	/* wait for ipconfig to finish */
+	if(debugboot)
+		fprint(2, "waiting for dhcp...");
 	for(;;){
 		w = wait();
 		if(w != nil && w->pid == pid){
@@ -84,6 +86,8 @@ configip(int bargc, char **bargv, int needfs)
 			fatal("configuring ip");
 		free(w);
 	}
+	if(debugboot)
+		fprint(2, "\n");
 
 	if(!needfs)
 		return;

+ 2 - 0
sys/src/9/boot/bootmkfile

@@ -12,7 +12,9 @@ BOOTFILES=\
 	settime.$O\
 	sac.$O\
 	paq.$O\
+#	parts.$O\
 	printstub.$O\
+	usb.$O\
 
 $BOOTLIB(%.$O):N:	%.$O
 

+ 149 - 0
sys/src/9/boot/usb.c

@@ -0,0 +1,149 @@
+/* usb support */
+
+#include <u.h>
+#include <libc.h>
+#include <auth.h>
+#include <fcall.h>
+#include "../boot/boot.h"
+
+#define PARTSRV "partfs.sdXX"
+
+enum {
+	Dontpost,
+	Post,
+};
+
+int	debugboot;
+
+static char usbdisk0[] = "/dev/sdU0.0";
+static char sdxxctl[]  = "/dev/sdXX/ctl";
+
+/*
+ * run argv[0] (short name is name) and wait awhile for file to appear.
+ * file must be generated by running argv[0]; if it already exists, we're done.
+ */
+static int
+start(char *name, char **argv, char *file)
+{
+	int cnt;
+
+	if(access(file, AEXIST) >= 0)
+		return 0;
+	if(access(argv[0], AEXIST) < 0) {
+		fprint(2, "no %s...", argv[0]);
+		return -1;
+	}
+
+	if(debugboot)
+		fprint(2, "%s...", name);
+	runv(argv);
+	for(cnt = 10; cnt > 0 && access(file, AEXIST) < 0; cnt--)
+		sleep(100);
+	if (cnt <= 0) {
+		fprint(2, "no %s...", name);
+		return -1;
+	}
+	return 0;
+}
+
+int
+chmod(char *file, int mode)
+{
+	Dir *dir;
+
+	dir = dirstat(file);
+	if (dir == nil) {
+		if(debugboot)
+			fprint(2, "can't stat %s: %r\n", file);
+		return -1;
+	}
+	dir->mode &= ~0777;
+	dir->mode |= mode & 0777;
+	dirwstat("/srv/" PARTSRV, dir);
+	free(dir);
+	return 0;
+}
+
+/* start partfs on first usb disk, if any */
+static int
+startpartfs(int post)
+{
+	int r, i;
+	char *parts;
+	char *partfsv[32];
+
+	if(access(usbdisk0, AEXIST) < 0)
+		return -1;	/* can't run partfs until usbd is mounted */
+
+	if (post)
+		remove("/srv/" PARTSRV);
+
+	i = 0;
+	partfsv[i++] = "/boot/partfs";
+	/*
+	 * hack for booting from usb: if /env/sdB0part (from 9load) exists,
+	 * pass it to partfs for sdXX.
+	 */
+	parts = getenv("sdB0part");
+	if (parts != nil) {
+		partfsv[i++] = "-p";
+		partfsv[i++] = parts;
+	}
+	if (post) {
+		partfsv[i++] = "-s";
+		partfsv[i++] = PARTSRV;
+	}
+	partfsv[i++] = usbdisk0;
+	partfsv[i] = nil;
+	r = start("partfs", partfsv, sdxxctl);
+
+	if (post)
+		chmod("/srv/" PARTSRV, 0666);
+	return r;
+}
+
+static int
+mountusb(void)
+{
+	int fd;
+
+	if(debugboot)
+		fprint(2, "mount usbd...");
+	fd = open("/srv/usb", ORDWR);
+	if(fd < 0)
+		warning("can't open /srv/usb");
+	else if(mount(fd, -1, "/dev", MBEFORE, "") < 0) {
+		warning("mount -a /srv/usb /dev");
+		close(fd);
+	} else
+		return 0;		/* mount closed fd */
+	return -1;
+}
+
+int
+mountusbparts(void)
+{
+	mountusb();
+	return startpartfs(Post);
+}
+
+void
+usbinit(int post)
+{
+	int cnt;
+	static char *usbdv[] = { "/boot/usbd", nil };
+
+	if(access("#u/usb/ctl", 0) < 0 || bind("#u", "/dev", MAFTER) < 0)
+		return;
+	if(debugboot)
+		fprint(2, "usbinit...");
+	start("usbd", usbdv, "/srv/usb");
+
+	/* allow a little time for usbd's device discovery */
+	for(cnt = 20; cnt > 0 && access(usbdisk0, AEXIST) < 0; cnt--)
+		sleep(100);
+	if(cnt > 0)
+		startpartfs(post);
+	else if(debugboot)
+		fprint(2, "no usb disk...");
+}

+ 1 - 1
sys/src/9/kw/main.c

@@ -610,7 +610,7 @@ Confmem sheevamem[nelem(conf.mem)] = {
 	 * Memory available to Plan 9:
 	 * the 8K is reserved for ethernet dma access violations to scribble on.
 	 */
-	{ .base = PHYSDRAM, .limit = PHYSDRAM + Minmem - 8*1024, },
+	{ .base = PHYSDRAM, .limit = PHYSDRAM + Maxmem - 8*1024, },
 };
 ulong memsize = Maxmem;
 

+ 5 - 4
sys/src/9/kw/mkfile

@@ -1,5 +1,6 @@
 CONF=plug
-CONFLIST=plug
+CONFLIST=plug plugnv
+EXTRACOPIES=
 
 # allegedly u-boot uses the bottom 8MB (up to 0x800000)
 # so avoid that
@@ -99,9 +100,9 @@ install-in-flash:V: /$objtype/$p$CONF paqdisk
 	cp paqdisk /dev/flash/plan9
 
 /$objtype/$p$CONF:D: $p$CONF s$p$CONF
-	cp -x $p$CONF s$p$CONF /$objtype &
-	{ 9fs lookout &&  cp -x $p$CONF s$p$CONF /n/lookout/$objtype } &
-#	{ 9fs piestand && cp -x $p$CONF s$p$CONF /n/piestand/$objtype } &
+	cp -x $p$CONF s$p$CONF /$objtype/ &
+	for(i in $EXTRACOPIES)
+		{ echo $i: && 9fs $i && cp $p$CONF s$p$CONF /n/$i/$objtype } &
 	wait
 	touch $target
 

+ 6 - 7
sys/src/9/kw/plug

@@ -1,5 +1,5 @@
-# sheeva plug, openrd-client, guruplug and others
-#	based on marvell's kirkwood soc
+# plug - sheeva plug, openrd-client, guruplug, dreamplug and others based on
+#	marvell's kirkwood soc
 dev
 	root
 	cons
@@ -38,7 +38,8 @@ link
 	ether1116	ethermii
 	archkw
 	ethermedium
-# no flash yet for guruplug
+# no flash yet for guruplug nor dreamplug; it keeps changing, and
+# on the dreamplug, flash is spi instead of nand.
 	flashkw		ecc
 	loopbackmedium
 	netdevmedium
@@ -74,8 +75,6 @@ bootdir
 	boot$CONF.out boot
 	/arm/bin/ip/ipconfig
 	/arm/bin/auth/factotum
-#	/arm/bin/paqfs
 	/arm/bin/usb/usbd
-# nvram not needed any longer, it's in flash.
-# but on the dreamplug, flash is spi instead of nand, so we do need it.
-	nvram
+	/arm/bin/disk/partfs
+#	/arm/bin/paqfs

+ 83 - 0
sys/src/9/kw/plugnv

@@ -0,0 +1,83 @@
+# plugnv - sheeva plug, openrd-client, guruplug, dreamplug and others based on
+#	marvell's kirkwood soc.  includes compiled-in nvram.
+dev
+	root
+	cons
+	env
+	pipe
+	proc
+	mnt
+	srv
+	dup
+	rtc
+	arch
+	ssl
+	tls
+	cap
+	kprof
+	aoe
+	sd
+	fs
+	flash
+	twsi
+#	pnp		pci
+
+	ether		netif
+	ip		arp chandial ip ipv6 ipaux iproute netlog nullmedium pktmedium ptclbsum inferno
+
+##	draw		screen vga vgax
+##	mouse		mouse
+##	vga
+#	kbmap
+##	kbin
+
+	uart
+	usb
+
+link
+	ether1116	ethermii
+	archkw
+	ethermedium
+# no flash yet for guruplug nor dreamplug; it keeps changing, and
+# on the dreamplug, flash is spi instead of nand.
+	flashkw		ecc
+	loopbackmedium
+	netdevmedium
+	usbehci		usbehcikw
+
+ip
+	tcp
+	udp
+	ipifc
+	icmp
+	icmp6
+	ipmux
+
+misc
+	rdb
+	coproc
+	sdaoe		sdscsi
+	softfpu
+	syscall
+	uartkw
+	ucalloc
+##	vgavesa
+
+port
+	int cpuserver = 1;
+	int i8250freq = 3686000;
+
+boot cpu
+	tcp
+#	paq
+
+bootdir
+	boot$CONF.out boot
+	/arm/bin/ip/ipconfig
+	/arm/bin/auth/factotum
+#	/arm/bin/paqfs
+	/arm/bin/usb/usbd
+# compiled-in nvram is a hack and only needed if flash is inaccessible,
+# usb won't work, and we don't have coraid access.  it should not be used
+# on outside machines.
+	nvram