9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] usb booting
@ 2013-04-30 23:06 erik quanstrom
  0 siblings, 0 replies; only message in thread
From: erik quanstrom @ 2013-04-30 23:06 UTC (permalink / raw)
  To: 9fans

this is a follow up to the discussion about root from usb-hdd
on the raspberry pi discussion (http://9fans.net/archive/2013/03/499)
it's a roundabout trip.

on pcs, i'm using cinap's bios-only loader.  it's tiny, and does its job well.
i've added the ability to find bios's first drive and pxe's first card.
information is exported in #ec/drive0 and #ec/ether0.  the latter
is quite useful for making machines with many interfaces "just boot".
the former is very useful for usb.  bios edd services will tell us if
the drive is usb.  (http://www.quanstro.net/magic/man2html/8/pcipl)

i'm also using kernels that have a sd loopback device.  a file
can be turned into a sd device with the ctl message
	config switch on spec $letter type loop/$file

putting the two together in boot/boot.c allows for boot
to depend on usb disks for nvram or file systems with just
20 lines of extra code.

to apply this to the rasberry pi, one would only need to
add the configuration passed into the pi kernel "drive0=usb=y".

unfortunately, sd(3) doesn't make it easy to have a /dev/sdboot
to make it easy to make this configuration mess go away.  ideally,
i think, drives would be renumbered as we do with ethernet devices
already.

- erik

----

; diffy -c /sys/src/nix/boot/boot.c
/n/dump/2013/0430/sys/src/nix/boot/boot.c:262,274 - /sys/src/nix/boot/boot.c:262,304
  }

  static void
+ usbbootdrive(void)
+ {
+ 	int fd, t;
+ 	static char usbsrv[] = "/srv/usb";
+ 	static char usbdrv[] = "/dev/sdU0.0/data";
+
+ 	for(t = 0; t < 10*1000;){
+ 		if(access(usbdrv, OREAD) != -1)
+ 			break;
+ 		sleep(300);
+ 		t += 300;
+ 	}
+
+ 	fd = open("#S/sdctl", OWRITE);
+ 	if(fd == -1){
+ 		fprint(2, "usbbootdrive: open #S/sdctl: %r\n");
+ 		return;
+ 	}
+ 	if(fprint(fd, "config switch on spec u type loop/%s\n", usbdrv) == -1)
+ 		fprint(2, "usbbootdrive: loopback: %r\n");
+ 	close(fd);
+ }
+
+ static void
  usbinit(void)
  {
+ 	char *s;
  	static char usbd[] = "/boot/usbd";

  	if(access("#u/usb/ctl", 0) >= 0 && bind("#u", "/dev", MAFTER) >= 0 &&
- 	    access(usbd, AEXIST) >= 0)
- 		run(usbd, nil);
+ 	    access(usbd, AEXIST) >= 0){
+ 		run(usbd, "-m", "/dev", nil);
+ 		s = getenv("drive0");
+ 		if(s != nil && strstr(s, " usb=") != nil)
+ 			usbbootdrive();
+ 		free(s);
+ 	}
  }

  static void



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-04-30 23:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-30 23:06 [9fans] usb booting erik quanstrom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).