Howto recompile a single driver?

My final goal is to change a few lines of a kernel driver, recompile it and insert into the running kernel.

However I’m stuck at the simple task of recompiling a kernel driver without modification. The resulting file is not identical to the provided binary.

The steps I’ve done so far:

  • Install kernel-sources, making sure the version matchs the running kernel. GCC also matches the version of /proc/version.
  • make oldconfig or make cloneconfig
  • make path/to/the/driver.ko

Now, if I try to insert the driver, it gives this error:

insmod: error inserting 'driver.ko': -1 Invalid module format.

Looking at the file sizes of the new compiled driver and the current one I can see they differ greatly.
Doing “strip -d” helps to reduce the size of the new one, but now the old is 2KB greater, and still can’t insert the new one.

So, what additional steps do I need to do to compile a driver with unmodified sources and get an identical file than the one installed?

Cymerio wrote:
> My final goal is to change a few lines of a kernel driver, recompile it
> and insert into the running kernel.
>
> However I’m stuck at the simple task of recompiling a kernel driver
> without modification. The resulting file is not identical to the
> provided binary.
>
> The steps I’ve done so far:
>
> - Install kernel-sources, making sure the version matchs the running
> kernel. GCC also matches the version of /proc/version.
> - make oldconfig or make cloneconfig
> - make path/to/the/driver.ko

You need to do a full ‘make’, which has two parts. Your last step only does the
first part.

Larry

So, there’s no short way? :
Ok. I will follow your advice.

Well, I finished doing “make”. It took forever.

Now I don’t get any error at all, but the files I get are still not identical to the ones that OpenSuSE provides, and that worries me.

And besides that, I can’t do this again and again when a new kernel comes out.>:(

There should be a shorter way.

Googling around seems that my initial approach was right:

Rebuilding a single kernel module - LinuxQuestions.org
Build a single native kernel module
Building a single kernel module - FedoraForum.org

Some people do “make path/to/driver.ko” and some others do “make M=path/to/drivers/directory”.

Why none of these solutions work for OpenSuSE? (apparently with other distros they work)

Hi
Not sure what module your trying to compile, but I need to patch the
toshiba_acpi module for bluetooth, here are the commands I run;


make clean
make oldconfig
make prepare
make scripts
cp /usr/src/linux-obj/i386/default/Module.symvers /usr/src/linux/
cd drivers/acpi
make -C /usr/src/linux SUBDIRS=$PWD modules
cp /usr/src/linux/drivers/acpi/toshiba_acpi.ko /lib/modules/`uname
-r`/kernel/drivers/acpi rmmod toshiba_acpi; modprobe toshiba_acpi


Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 11.0 x86 Kernel 2.6.25.18-0.2-default
up 20:59, 2 users, load average: 0.14, 0.14, 0.18
GPU GeForce 6600 TE/6200 TE - Driver Version: 177.82

Thanks! I tried your commands and I can insert the module without errors. That was really fast.

However, the original and new driver’s file sizes are not identical.
After I run “strip -d” on the new file, the old (current) file size is still ~1KB over the new.
I don’t why the file sizes vary, when the sources are identical. Probably I should study the SPEC file of the OpenSuSE kernel to know that.

FYI: The module I’m trying to compile is “rtl8187.ko”, one of the wireless drivers, but all modules should compile the same way, shouldn’t they?

After some investigation I found that adding “CONFIG_DEBUG_INFO=y -k” to all the make commands (including oldconfig, prepare, etc) improves the result.
Additionally I added also “CONFIG_DEBUG_SECTION_MISMATCH=y” to the last make, and run “strip -d” to the resulting module.

Now files are almost identical. They differ a little in the header and a little over the middle.
Probably I can’t get any closer than that.

Hi
Not sure about file size differences, seems a little strange. And yes,
any module should compile ok this way.


Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 11.0 x86 Kernel 2.6.25.18-0.2-default
up 1 day 8:04, 1 user, load average: 0.01, 0.04, 0.00
GPU GeForce 6600 TE/6200 TE - Driver Version: 177.82