9front - general discussion about 9front
 help / color / mirror / Atom feed
* efi loader disk order
@ 2020-11-20 13:25 Nick Owens
  2020-11-21 13:05 ` [9front] " cinap_lenrek
  0 siblings, 1 reply; 2+ messages in thread
From: Nick Owens @ 2020-11-20 13:25 UTC (permalink / raw)
  To: 9front

on my desktop i have multiple disks. one contains a full 9front install
in uefi mode with an esp and 9fat. in my primary disk, i added
bootx64.efi, 9pc64 and a plan9.ini and configured grub to chainload it,
so i could use those to tcpboot to my fileserver.

i was very surprised when bootx64.efi picked the plan9.ini from the
other disk with the full 9front installation! 9boot(8) is somewhat
unspecific on the behavior, but the current code seems to walk all disks
in reverse order looking for plan9.ini in them. i understand the intent
of this ordering was to select the 9fat first (which would usually be
subsequent to the ESP), but i do not understand why 9front doesn't just
forgo a 9fat if an ESP is present.

in any case, here's a patch to load plan9.ini and the kernel from the
same partition that bootx64.efi was loaded from, and if that fails, fall
back to the old behavior of picking whatever.

diff --git a/sys/src/boot/efi/efi.h b/sys/src/boot/efi/efi.h
--- a/sys/src/boot/efi/efi.h
+++ b/sys/src/boot/efi/efi.h
@@ -49,6 +49,22 @@ typedef struct {
 } EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL;
 
 typedef struct {
+	UINT32		Revision;
+	EFI_HANDLE	ParentHandle;
+	void		*SystemTable;
+	EFI_HANDLE	DeviceHandle;
+	void		*FilePath;
+	void		*Reserved;
+	UINT32		LoadOptionsSize;
+	void		*LoadOptions;
+	void		*ImageBase;
+	UINT64		ImageSize;
+	UINT32		ImageCodeType;
+	UINT32		ImageDataType;
+	void		*Unload;
+} EFI_LOADED_IMAGE_PROTOCOL;
+
+typedef struct {
 	UINT32		RedMask;
 	UINT32		GreenMask;
 	UINT32		BlueMask;
diff --git a/sys/src/boot/efi/fs.c b/sys/src/boot/efi/fs.c
--- a/sys/src/boot/efi/fs.c
+++ b/sys/src/boot/efi/fs.c
@@ -32,6 +32,12 @@ EFI_GUID EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
 	0xc9, 0x69, 0x72, 0x3b,
 };
 
+static EFI_GUID EFI_LOADED_IMAGE_PROTOCOL_GUID = {
+	0x5b1b31a1, 0x9562, 0x11d2,
+	0x8e, 0x3f, 0x00, 0xa0,
+	0xc9, 0x69, 0x72, 0x3b,
+};
+
 static
 EFI_FILE_PROTOCOL *fsroot;
 
@@ -87,12 +93,37 @@ int
 fsinit(void **pf)
 {
 	EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs;
+	EFI_LOADED_IMAGE_PROTOCOL *image;
 	EFI_FILE_PROTOCOL *root;
 	EFI_HANDLE *Handles;
 	void *f;
 	UINTN Count;
 	int i;
 
+	image = nil;
+
+	/* locate kernel and plan9.ini by deriving a fs protocol
+	 * from the device the loader was read from.
+	 * if that fails, fall back to old method.
+	 */
+	if(eficall(ST->BootServices->HandleProtocol, IH,
+		&EFI_LOADED_IMAGE_PROTOCOL_GUID, &image) == 0 &&
+		eficall(ST->BootServices->HandleProtocol, image->DeviceHandle,
+		&EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, &fs) == 0 &&
+		eficall(fs->OpenVolume, fs, &root) == 0){
+
+		fsroot = root;
+		f = fsopen("/plan9.ini");
+		if(f != nil){
+			if(pf != nil)
+				*pf = f;
+			else
+				fsclose(f);
+
+			goto gotit;
+		}
+	}
+
 	Count = 0;
 	Handles = nil;
 	if(eficall(ST->BootServices->LocateHandleBuffer,
@@ -126,6 +157,7 @@ fsinit(void **pf)
 	if(fsroot == nil)
 		return -1;
 
+gotit:
 	read = fsread;
 	close = fsclose;
 	open = fsopen;



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [9front] efi loader disk order
  2020-11-20 13:25 efi loader disk order Nick Owens
@ 2020-11-21 13:05 ` cinap_lenrek
  0 siblings, 0 replies; 2+ messages in thread
From: cinap_lenrek @ 2020-11-21 13:05 UTC (permalink / raw)
  To: 9front

yeah, that seems to be a reasonable solution to support
multiple 9front installations per disk in uefi.

the old logic is mainly historical, because in bios,
all we got was the disk number where the boot sector
came from. then we just look for any 9fat.

i'm fine with this modification. could you also
provide a patch to the manpage to document the behavior?

--
cinap


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-11-21 13:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-20 13:25 efi loader disk order Nick Owens
2020-11-21 13:05 ` [9front] " cinap_lenrek

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).