MCMrARM / mbp2018-bridge-drv

A driver for MacBook models 2018 and newer, which makes the keyboard, mouse and audio output work.
131 stars 54 forks source link

Loading the module in initramfs for cryptsetup use #24

Open a1aw opened 3 years ago

a1aw commented 3 years ago

Hi,

I am trying to use LUKS encryption on my MacBook Pro (16,2). Cryptsetup will show the password prompt in initramfs before boot to decrypt the root filesystem first.

However, I was unable to type anything using the internal keyboard as the Apple BCE, HID kernel modules are not loaded yet. I can only enter the encryption key with an external keyboard connected.

I am wondering is there a (correct) way to copy and load those modules into initramfs.

a1aw commented 3 years ago

I have tried doing the following:

  1. Adding the module names into /etc/initramfs/modules or /usr/share/initramfs/modules

  2. Adding modprobe commands to init “hid-apple”, “snd-seq”, “apple-bce” into the unlock script of cryptosetup

  3. Booting into recovery mode and specifically running those modprobe commands. Dmesg shows the following:

networkException commented 3 years ago

This guide might get you further https://github.com/DimitriDokuchaev/GrubLuksUnlock

a1aw commented 3 years ago

Thanks for the link and I might use it as the last resort if I can’t port the driver into initramfs. Here’s what I have found from my research:

  1. From cat /proc/modules, apple-bce actually got loaded already as the default /etc/initramfs/modules config already contains the BCE modules. The snq errors from the last dmesg is actually just because the ALSA modules not got loaded, specifically loading a snq-dummy doesn’t work too.
  2. apple-bce module only runs its apple_bce_probe() when the system root get loaded. Therefore the bce_vhci won’t generate and enable the touchpad and keyboard for initramfs. It makes the default config in /etc/initramfs/modules actually meaningless.

I am wondering if an another kernel module can be specifically implemented for support in initramfs.

LukeShortCloud commented 2 years ago

In my winesapOS project, we fully support Mac hardware and LUKS encryption. On Arch Linux distributions, these are the relevant lines of our code used to enable such support. The most important part is to add apple-bce to the modules that the initramfs will use. Then rebuild the initramfs. The actual commands and files to change will be very different on Debian and Fedora distributions but the concept is the same.

sed -i s'/MODULES=(/MODULES=(applespi spi_pxa2xx_platform intel_lpss_pci apple_ibridge apple_ib_tb apple_ib_als /'g ${WINESAPOS_INSTALL_DIR}/etc/mkinitcpio.conf

https://github.com/LukeShortCloud/winesapOS/blob/3.0.0-beta.1/scripts/winesapos-install.sh#L651

sed -i s'/MODULES=(/MODULES=(apple-bce /'g ${WINESAPOS_INSTALL_DIR}/etc/mkinitcpio.conf

https://github.com/LukeShortCloud/winesapOS/blob/3.0.0-beta.1/scripts/winesapos-install.sh#L671

    sed -i s'/HOOKS=.*/HOOKS=(base udev block keyboard keymap autodetect modconf encrypt filesystems fsck)/'g ${WINESAPOS_INSTALL_DIR}/etc/mkinitcpio.conf

https://github.com/LukeShortCloud/winesapOS/blob/3.0.0-beta.1/scripts/winesapos-install.sh#L682

arch-chroot ${WINESAPOS_INSTALL_DIR} mkinitcpio -p linux510 -p linux515

https://github.com/LukeShortCloud/winesapOS/blob/3.0.0-beta.1/scripts/winesapos-install.sh#L690

a1aw commented 2 years ago

I have successfully made the keyboard working in initramfs. Now I can type the password directly in a nicely looking Ubuntu LUKS prompt instead of GRUB's text-mode prompt.

I have changed /etc/initramfs-tools/modules to include these modules:

snd_sof_pci_intel_icl
snd_sof_intel_hda_common
snd_sof_intel_hda
snd_sof_pci
snd_sof_xtensa_dsp
snd_sof
snd_soc_hdac_hda
snd_hda_ext_core
snd_soc_acpi_intel_match
snd_soc_acpi
snd_hda_codec_hdmi
snd_soc_core
snd_compress
snd_pcm_dmaengine
snd_hda_intel
snd_intel_dspcfg
snd_intel_sdw_acpi
snd_hda_codec
snd_hda_core
snd_hwdep
snd_seq_midi
snd_seq_midi_event
snd_rawmidi
snd_seq
snd_pcm
snd_seq_device
snd_timer
snd
apple_bce

and updated the initrd with update-initramfs -k all -u

a1aw commented 2 years ago

apple_bce will report unknown symbol: snd_* errors if the snd modules are not loaded/included in the initrd. Including them in the initramfs makes the apple_bce works properly and exposes the keyboard device.