My situation:
I have a prebuilt kernel running fedora already installed and running. Now, I want to install the mcp251x and mcp25xfd driver modules, which depends on the can-dev driver module, so I need to install that one too. Apparently, the source code for these modules existed in the kernel source for this version, but my guess is that they were not "enabled" via the .config file during the kernel compilation. So this is an after-the-fact driver module installation attempt.
I've never done this, so please guide me if there is an easier way.
What I've tried:
I first went into the /lib/modules directory and looked to see if my 3 modules already existed, ready to be installed. I found one of them: can-dev.ko.xz
So I install it:
$ sudo insmod can-dev.ko.xz
This completes, no error message. For the other 2 modules, I see the source code for them and a makefile, but calling "make" just says "No targets" and fails to build.
I then looked at the version using uname -a:
Linux fedora 5.11.3-300.fc34.x86_64
So I go and download the source code for 5.11.3 from: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/refs/tags
I check my current compiler version:
$ gcc --version
$ gcc (GCC) 11.0.0 20210210 (Red Hat 11.0.0-0)
I verify that this is the same gcc version used to build the kernel:
$ cat /proc/version
$ gcc (GCC) 11.0.0 20210210 (Red Hat 11.0.0-0)
So apparently I can't just go into the driver folder and call "make", even though it has a makefile. The driver makefile is all tangled together with the kernel makefile, so I go into the kernel source code root directory and modify the Makefile:
EXTRAVERSION = -300.fc34.x86_64
This ensures the "vermagic" string in the module is compatible with the currently installed OS version.
Then, in the kernel source code root directory, I call:
$ make oldconfig
This generates a .config file. I manually edit the .config file to add these lines:
CONFIG_CAN_MCP251X=m
CONFIG_CAN_MCP251XFD=m
This tells the kernel to build MCP251x and MCP251xfd as modules (they were defaulted to not build at all).
I then call
$ make prepare
Then, I cd into the specific driver directory I am trying to build (which contains c code and a Makefile), and call:
$ make -C ~/linux-5.11.3 M=`pwd` modules
Which calls the kernel-source-root Makefile with some special arguments instructing to only build the kernel modules in the current directory. This works, and it generates the files mcp251xfd.ko and mcp251x.ko.
I try to install these modules:
$ sudo insmod mcp251x.ko
$ sudo insmod mcp251xfd.ko
But both return the following error message:
insmod: ERROR: could not insert module mcp251xfd.ko: Invalid module format
and a call to
$ dmesg
Returns:
module: x86/modules: Skipping invalid relocation target, existing value is nonzero for type 1, loc 00000000abe7d4fb, val ffffffffc10b3a77
The only thing I know left to check is that the magic number matches to uname -r number:
$ uname -r
5.11.3-300.fc34.x86_64
Check against module:
$ modinfo mcp251xfd.ko
vermagic: 5.11.3-300.fc34.x86_64
So I'm out of ideas on what to do or try to get these drivers installed.