AsahiLinux / asahi-scripts

Miscellaneous admin scripts for the Asahi Linux reference distro
MIT License
46 stars 31 forks source link

Add dracut module #9

Closed Conan-Kudo closed 2 years ago

Conan-Kudo commented 2 years ago

This pull request introduces a dracut module for loading Apple system firmware into Linux. Additionally, the Makefile has been reworked to make installing initramfs generator scripts distinct tasks.

davide125 commented 2 years ago

I tested this and it works, but there's errors during early boot about missing the dirname and cut commands (which come from coreutils).

davide125 commented 2 years ago

I'm also seeing https://forums.fedoraforum.org/showthread.php?328901-sbin-sysctl-No-such-file-or-directory&p=1861130 but it's unrelated to this change (as I see it on a stock f37 beta system on x86_64 as well).

marcan commented 2 years ago

Does the systemd unit to copy the firmware run after the initramfs has pivoted to the root filesystem? If so, that's racy, since the kernel can decide to request some firmware before it runs.

At this point I'd wait until the next-revamp of the vendorfw idea is in, which will hopefully simplify this a lot and work with the /run scheme (I want to add /lib/firmware/vendor as a load path to the kernel, then you could just symlink that to /run/whatever from the get-go and not have to copy anything).

chadmed commented 2 years ago

I've written a small module to handle firmware the new way, mirroring what happens in mkinitcpio as closely as possible. It is available at https://github.com/chadmed/asahi-gentoosupport/commit/4cdce8a. Comments welcome of course :)

ericcurtin commented 2 years ago

https://github.com/chadmed/asahi-gentoosupport/commit/4cdce8a

It's like a poor mans udev:

for i in $(seq 0 50); do
    [ -e /sys/bus/platform/drivers/nvme-apple/*.nvme/nvme/nvme*/nvme*n1/ ] && break
    sleep 0.1
done

but it sounds like that's what we need. It gets my vote if it's tested and works. I dunno about gentoo but in the fedora case you can use a systemd unit file, even at the initrd stage.

chadmed commented 2 years ago

copy-firmware.sh is basically 1:1 copied from mkinitcipo/hooks/asahi. Depending on how early we actually need the firmware, we can of course just wait for udev to do its thing and run update-vendor-firmware which should find the ESP once NVMe is up and we can avoid having to do this.

Avoiding systemd-specific stuff is probably best long-term IMHO, since then any distro can take it regardless of how they handle init.

chadmed commented 2 years ago

Fixed version of the above, removing the dependency on update-vendor-firmware. Again, comments welcome.

https://github.com/chadmed/asahi-gentoosupport/commit/9949ff7e3b62

Conan-Kudo commented 2 years ago

I've reworked it to hopefully match up with what is needed for the new mechanism now.

marcan commented 2 years ago

I think this is still missing something to add a /lib/firmware/vendor -> /vendorfw symlink in the initramfs, or did I miss something?

Also, what is in charge of ensuring that /lib/firmware/vendor exists in the root filesystem? I imagine the packaging?

davide125 commented 2 years ago

I think this is still missing something to add a /lib/firmware/vendor -> /vendorfw symlink in the initramfs, or did I miss something?

You're right, this is missing and needs to be added.

Also, what is in charge of ensuring that /lib/firmware/vendor exists in the root filesystem? I imagine the packaging?

Yeah, we can do this on the packaging side of things.

Conan-Kudo commented 2 years ago

I think this is still missing something to add a /lib/firmware/vendor -> /vendorfw symlink in the initramfs, or did I miss something?

You're right, this is missing and needs to be added.

This is now handled. Thanks for spotting that!

Also, what is in charge of ensuring that /lib/firmware/vendor exists in the root filesystem? I imagine the packaging?

Yeah, we can do this on the packaging side of things.

Yup: https://src.fedoraproject.org/rpms/asahi-scripts/pull-request/5

Conan-Kudo commented 2 years ago

This PR should be all set to merge now!