From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f194.google.com ([209.85.215.194]) by ewsd; Fri Nov 20 08:25:17 -0500 2020 Received: by mail-pg1-f194.google.com with SMTP id 81so7307977pgf.0 for <9front@9front.org>; Fri, 20 Nov 2020 05:25:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=offblast-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=gpqvz0e0SBorDp02H0E5LStBZAe1EdeM07DHu2rGSvw=; b=08on3Q5APoxvdX5cc7qmiDxLhJ2bIpQk3+R0k8ugQ73tjVRhCam4r0UjidIz9cTsPJ MeLojncgVJEnZ3G/XAZFs3VMuLXhyJ7Z/mD7s6SwB1F2ut+/1JfYTRuLcEgxFVfIGZH4 0ZwCBxKncmfxoI2euss1QDM9Z8BkQ3IT2BZQzlVk+4i57NspHn0uerRGXRNGO5d/7JF0 Nyzwla3HRuprJjpGNDE6g/uTvFQKBQAaw2xD6SQGIROb7+B+dkr5I4ybtOA9Z1qPgJgM 7F0kZLV2e3/c4x6WEFRlrObZWnXgmzJCtZGKVoWESMUS4zkaIywVYJa2DOk+/44zpoMu 4M0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=gpqvz0e0SBorDp02H0E5LStBZAe1EdeM07DHu2rGSvw=; b=ZXZ0fYZgOc2L+ITR+qgeSE8HTS0osOV8dZABaZaDnhZv3IdZ5lZ3GYucL9Nbq9a1Ca oPIN/GKld6SICk3vubv/bfvgPYWyqsmgELRUGaNEOjcAZ5c79u5wfEmujPIPef4G0eSp 0h0yOyXMeEhnZOEKZH+rc540AomKaFfyQldtRWuEr6wyCQS/zr+MiaXZJqysKrVHMz5Z s+UgBcKvt351Y2m6GzbHd4TjZpaOu71hPzCXoODAPs7Ryqj3cWJeHaOTx5NAdVlPrqR7 q70qFOe9TdcNkAlc06R6ubrGm8vwCPNJmgNfNUJQ1XzS9UEYhZKZRXztxjlulC+z6hnq mL8Q== X-Gm-Message-State: AOAM53053M9rJiGe6hAzgYVjyFSlomOXCx856pkacI8Ooot1mz02JHIM FM8VG0QqV/UFvbWMuTi+Vv7VBgzTlJHswovF X-Google-Smtp-Source: ABdhPJyIAqZOegGuSJippJJgbfbljpo3IpGEq73FrUQyQDkLXjz6s20fqJd6egemzoRv1sXadIPbZA== X-Received: by 2002:a17:90a:f994:: with SMTP id cq20mr9680392pjb.62.1605878709798; Fri, 20 Nov 2020 05:25:09 -0800 (PST) Return-Path: Received: from wololo.home.arpa ([2601:646:100:8cb:2c6d:f3ff:fe32:a632]) by smtp.gmail.com with ESMTPSA id ie21sm4101437pjb.14.2020.11.20.05.25.08 for <9front@9front.org> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2020 05:25:09 -0800 (PST) Date: Fri, 20 Nov 2020 05:25:06 -0800 From: Nick Owens To: 9front@9front.org Subject: efi loader disk order Message-ID: <20201120132506.tfkboyyqr265qylh@wololo.home.arpa> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: NeoMutt/20180716 List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: XML over ActivityPub information singleton dependency dependency-aware framework 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;