Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add boot.efi #138

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft

Add boot.efi #138

wants to merge 17 commits into from

Conversation

wjk
Copy link
Contributor

@wjk wjk commented Jan 8, 2024

This PR will add a simple implementation of boot.efi using the xnu-loading code from Apple’s boot-132, modified to function as 64-bit and under EFI.

Note that I currently have no way to test this, because PureDarwin image creation has not yet been implemented.

@ninjadev64
Copy link

ninjadev64 commented Jan 8, 2024

Note that I currently have no way to test this, because PureDarwin image creation has not yet been implemented.

Naive question: what's wrong with

  • Copying all the files from build/src/Kernel/xnu/xnu/ to a volume
  • Placing the kexts from build/src/Kernel/Extensions/*/*.kext in System/Library/Extensions/ on the volume
  • Of course there'll need to be lots more binaries for libraries and commands we want to have on the system, but that should be enough to test
  • Including the bootloader we want to test
  • Using dd to create a raw image file of the volume and launching it with an OpenCore image as the first drive

@wjk
Copy link
Contributor Author

wjk commented Jan 8, 2024

Naive question: what's wrong with

The problem is that I would be installing into a DMG file, and there is no way (that I know of) to set the GUID of a partition in a mounted DMG to the required one so it can be considered as a boot partition. I’ve tried gpt(8) but it seems Apple has censored the utility; all it does when I run it is say operation not permitted.

@ninjadev64
Copy link

Ah, I'm not using a DMG file - I added an extra harddisk to my macOS VM and am using that. Would it be possible to set the desired flags on a "physical" volume?

@wjk
Copy link
Contributor Author

wjk commented Jan 9, 2024

I’m sorry, I should have been more clear. I am using a raw image as my “DMG file”. macOS doesn’t support loopback mount, but can mount a raw byte-for-byte filesystem image as a DMG. Disk Utility is the best way to create these images, and it outputs files using the .dmg extension. Since this is a raw image, I can easily have QEMU use that as its hard drive when booting the VM.

I would never think of ever letting this code anywhere near a physical hard drive due to the risk of corruption. (Theoretically, wouldn’t you be able to point a command manipulating GPT at a device file and have it perform the same I/O to that device it does when run on an image file?)

@ninjadev64
Copy link

What I meant was create the image on a "physical" hard drive, which isn't really physical since I use macOS in a VM, then create an image of that using dd to use with QEMU inside the macOS VM.

@RandomDSdevel
Copy link

RandomDSdevel commented May 11, 2024

(Replying belatedly:)

…macOS doesn’t support loopback mount, …

  1. macOS actually did have a loop(back) device 'driver' as recently as 10.14.6, if you weren't aware, if I'm understanding the correlation between macOS and XNU version numbers correctly (though maybe only in development kernel builds.) Refer to 'bsd/dev/vn' in XNU's 8020.140.41 sources for its implementation as it last appeared before getting removed. (You'll want to make special note of note 2 at the top of 'bad/dev/vn/vn.c',' however.)
         You could maybe start with that and port it forward. That only helps once PureDarwin can be booted, though, of course. Or perhaps/maybe if one were really lucky, unlikely as that might be, that implementation hadn't diverged too far from FreeBSD's at the time and the current upstream implementation can just get merged back in again. (Though it might well be rather surprising if that ended up being the case.)
  2. macFUSE has a loop(back) filesystem implementation in LoopbackFS, but it's currently un-maintained. That also only helps from the macOS side.

@wjk wjk force-pushed the boot.efi branch 2 times, most recently from 74f3214 to 3bec36a Compare May 11, 2024 21:09
@hideout
Copy link
Member

hideout commented May 12, 2024 via email

@wjk
Copy link
Contributor Author

wjk commented Jun 11, 2024

If anyone can help me out here, I am stumped on something.

I am trying to locate the EFI_FILE_PROTOCOL for the root of the volume on which the running boot.efi is located, so I can locate and load com.apple.Boot.plist and the boot kexts. I’ve read the UEFI spec, as well as the source code for the GRUB and rEFIt bootloaders, and I can’t come up with anything similar. However, the only parameter I have to work with is the ImageHandle parameter passed to the EFI entry point. Does anyone have any pointers?

@ninjadev64
Copy link

I don't know about that myself, but your question has been forwarded on to the Discord server by csekel so you might get a response soon (just to let you know your question has been noticed).

@wjk wjk force-pushed the boot.efi branch 2 times, most recently from 436769d to f9f5cd9 Compare June 11, 2024 23:55
@wjk
Copy link
Contributor Author

wjk commented Jun 11, 2024

@ninjadev64 Small update for you. Unfortunately, it doesn’t look like EFI is able to parse HFS+ filesystems natively, so EFI_FILE_PROTOCOL won’t work. As a result, I need to obtain the device that boot.efi is located on instead, so I can use the EFI volume I/O protocols. Thanks!

wjk added 9 commits June 13, 2024 11:47
This header contains a definition for NULL, as well as
a copy of the strcmp() and strncmp() functions. It will
be extended to contain an EFI-compatible malloc()
implementation later.
These functions come from the boot-132 file i386/libsaio/xml.c.
Symbols have been renamed and moved around to better clean up
the source code.
wjk added 4 commits June 13, 2024 11:47
These functions come from bopt-132 i386/libsaio/device_tree.c.
Some symbols have been renamed for cleanup purposes.
@RandomDSdevel
Copy link

(Continuing on from my earlier comment in earlier discussion of loop(back) mounts/filesystems:)

     Also, the FSKit user-space/user-mode filesystem API framework will be made available for public use as of macOS Sequoia (v15) (and its accompanying backup XNU kernel version) this fall.

@csekel
Copy link
Member

csekel commented Jun 16, 2024

(Continuing on from my earlier comment in earlier discussion of loop(back) mounts/filesystems:)

     Also, the FSKit user-space/user-mode filesystem API framework will be made available for public use as of macOS Sequoia (v15) (and its accompanying backup XNU kernel version) this fall.

Let’s hope that they open source it

@AS5410-developer
Copy link

AS5410-developer commented Jul 28, 2024

@ninjadev64 Small update for you. Unfortunately, it doesn’t look like EFI is able to parse HFS+ filesystems natively, so EFI_FILE_PROTOCOL won’t work. As a result, I need to obtain the device that boot.efi is located on instead, so I can use the EFI volume I/O protocols. Thanks!

Have you solved this problem? If not, it may come in handy: https://github.com/acidanthera/OpenCorePkg/tree/master/Staging/OpenHfsPlus.

@wjk
Copy link
Contributor Author

wjk commented Jul 28, 2024

@AS5410-developer Looks useful, but it still doesn’t fix my main problem: how to determine which EFI volume the currently executing copy of boot.efi lives on. It will take quite a bit of time to separate that code from the rest of OpenCore and convert it to gnu-efi, however.

@AS5410-developer
Copy link

how to determine which EFI volume the currently executing copy of boot.efi lives on.

Doesn't the boot argument "rd" tell the root device?

@AS5410-developer
Copy link

It will take quite a bit of time to separate that code from the rest of OpenCore and convert it to gnu-efi, however.

Doesn't it stay loaded as a UEFI driver after running another efi program?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants