From: Nick Owens <mischief@offblast.org>
To: 9front@9front.org
Subject: efi loader disk order
Date: Fri, 20 Nov 2020 05:25:06 -0800 [thread overview]
Message-ID: <20201120132506.tfkboyyqr265qylh@wololo.home.arpa> (raw)
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;
next reply other threads:[~2020-11-20 13:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-20 13:25 Nick Owens [this message]
2020-11-21 13:05 ` [9front] " cinap_lenrek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201120132506.tfkboyyqr265qylh@wololo.home.arpa \
--to=mischief@offblast.org \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).