framework-laptop-kmod icon indicating copy to clipboard operation
framework-laptop-kmod copied to clipboard

Cannot build kernel module on Fedora Workstation 41

Open MasinAD opened this issue 1 year ago • 3 comments

When trying to build the module on Fedora Workstation 41 I get:

masin.wiedner@wmde-103180:~/Projekte/framework-laptop-kmod$ LANG=C make
make -C /lib/modules/`uname -r`/build M=$PWD modules
make[1]: Entering directory '/home/masin.wiedner/Projekte/framework-laptop-kmod'
make[1]: *** /lib/modules/6.11.8-300.fc41.x86_64/build: No such file or directory.  Stop.
make[1]: Leaving directory '/home/masin.wiedner/Projekte/framework-laptop-kmod'
make: *** [Makefile:12: modules] Error 2

I guess that's because although I run Linux version 6.11.8-300.fc41.x86_64 when installing kernel-devel I get installed version 6.11.10-300.fc41.x86_64. Last system update was only 4 days ago but of course they might have released 6.11.9 and 6.11.10 in the meantime. But there aren't any kernel-devel packages for 6.11.8 available.

I'm new to Fedora, coming from Debian and Arch, so I might do stuff the wrong way. Or there's a fundamentally different approach in Fedora for providing kernel headers I haven't grasped fully. Either way it does not work for me. Any hints?

MasinAD avatar Dec 03 '24 15:12 MasinAD

FYI you should be able to update your kernel:

sudo dnf update kernel

This will make sure you're running the latest kernel, which should match the latest kernel-devel. However, you'll probably need to do a few more things to install the kernel module:

Install by hand (TBH not recommended, scroll down to DKMS install to save yourself trouble in the long run):

For default, out-of-the-box Fedora you'll need to generate signing keys and add them to the right places:

# In this repo
mkdir -p certs

# Generate the signing keys
openssl req -new -x509 -newkey rsa:2048 -keyout certs/signing_key.pem -outform DER -out certs/signing_key.x509 -nodes -days 36500 -subj "/CN=Local Module Signing Key/"

# Copy them into the kernel build system
sudo mkdir -p /lib/modules/$(uname -r)/build/certs
sudo cp certs/signing_key.* /lib/modules/$(uname -r)/build/certs/

# Add them to the kernel's trusted keys
sudo mokutil --import /lib/modules/$(uname -r)/build/certs/signing_key.x509

The last line will prompt you to create a password: remember it. Then, reboot, and you should be prompted to enter UEFI/MOK management. Select "Enroll MOK" and follow the prompts to enter the password you created.

Finally, you should be able to build, install, and run the kernel module:

make
sudo make modules_install
sudo modprobe framework_laptop

DKMS installation to automate rebuilding the kernel module

You may also just want to automate all of this with DKMS so that the kernel module gets rebuilt automatically whenever you update your kernel. DKMS will also handle some of the key signing stuff for you. Here's how to do it with DKMS:

sudo dnf install dkms
sudo mkdir -p /usr/src/framework_laptop-1.0
# Inside this repo directory:
sudo cp -r * /usr/src/framework_laptop-1.0/

Then you'll need to create a DKMS conf file:

# Or use whatever editor you prefer, I use vi
sudo nano /usr/src/framework_laptop-1.0/dkms.conf

Copy this in:

PACKAGE_NAME="framework_laptop"
PACKAGE_VERSION="1.0"
MAKE="make -C ${kernel_source_dir} M=${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build && make -C ${kernel_source_dir} M=${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build modules_install"
CLEAN="make -C ${kernel_source_dir} M=${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build clean"
BUILT_MODULE_NAME[0]="framework_laptop"
DEST_MODULE_LOCATION[0]="/updates"
AUTOINSTALL="yes"

If you previously hand-installed the kernel module, make sure to remove it:

sudo rm /lib/modules/6.11.11-300.fc41.x86_64/updates/framework_laptop.ko

Then run:

sudo dkms add -m framework_laptop -v 1.0
sudo dkms build -m framework_laptop -v 1.0
sudo dkms install -m framework_laptop -v 1.0

If the last line fails, you need to reboot your system to get the DKMS key enrolled. Follow the prompts to enroll the DKMS MOK key in the boot menu.

If for some reason you aren't prompted to install the key, you can run the following to force being prompted on reboot:

sudo mokutil --import /var/lib/dkms/mok.pub

Finally, you can load the module:

sudo modprobe framework_laptop

Autoload on boot

Note that neither installation mechanism will make the module auto-load on boot, so if you reboot, you'd need to reload the module. To make it autoload on boot, you'll need to write a config file:

sudo nano /etc/modules-load.d/framework.conf

Add these lines to the file:

cros_ec
cros_ec_lpcs
framework_laptop

Save and exit the editor, and you should be good! I just did this myself on Fedora 41, and it all worked.

reissbaker avatar Dec 13 '24 15:12 reissbaker

Also FYI since I just ran into this: if your BIOS gets updated, it'll probably wipe out your MOK settings with it: without the MOK key enrolled, you won't be able to load the kernel module even if it built successfully. To fix after a BIOS update, just run:

sudo mokutil --import /var/lib/dkms/mok.pub

To re-enroll the DKMS key, and then reboot and you'll be prompted to enroll the key. Or if you manually built the kernel module, just re-enroll the key you generated with the same command.

For the Framework 13, you'll also want to go into your BIOS settings and re-enable "Gaming" mode for the iGPU after a BIOS update as well, since something about Gnome/Wayland/who knows tends tends to lock up on the 13 otherwise.

reissbaker avatar Dec 18 '24 08:12 reissbaker

for my own personal use I've made an akmod package for fedora https://copr.fedorainfracloud.org/coprs/sentry/framework-laptop-kmod/

Jan200101 avatar Jul 30 '25 06:07 Jan200101