WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Compiled driver failing with: insmod: can't insert '..': invalid module format  (Read 11137 times)

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 182
Hi!

  I've been trying to compile a driver for a WiFi USB adapter with the MT7601U chipset.
On piCore 6.0rc1 I succeeded in compiling the driver using the modules and .config that Béla put available for download.
I now wanted to do the same on final release 6.0.
I can get the kernel compiled and all the modules. And the driver compiles too, but the insmod keeps failing with:

Code: [Select]
$ sudo insmod /home/tc/mt7601/src/os/linux/mt7601Usta.ko
insmod: can't insert '/home/tc/mt7601/src/os/linux/mt7601Usta.ko': invalid module format


Because I think I am doing something wrong, I want to show you the steps I am taking to compile the driver.
If anybody sees something wrong, please tell me.
Here it goes..

I've formatted a USB stick with the linux filesystem (first I didn't do that and had all kinds of case-sensitive problems), and put the kernel on it this way:

Code: [Select]
sudo mount /dev/sda1 /mnt/sda1
cd /mnt/sda1
sudo wget https://github.com/raspberrypi/linux/archive/rpi-3.12.y.tar.gz
sudo tar xvfz /home/pi/kernel/rpi-3.12.y.tar.gz
Next I installed the essential things for compiling:

Code: [Select]
tce-load -wi compile-essentials.tcz
tce-load -wi linux-3.12.y_api_headers.tcz
tce-load -wi git.tcz

Create a symbolic link to the usb stick called "build" in the modules directory:

Code: [Select]
cd /lib/modules/3.12.36-piCore+
sudo ln -s /mnt/sda1/linux-rpi-3.12.y build

And now I can start building the kernel:
Code: [Select]
cd /lib/modules/3.12.36-piCore+/build
make mrproper

Now retrieve the .config from the current running piCore:

Code: [Select]
cd /mnt/sda1/linux-rpi-3.12.y
sudo rm -r .config
sudo zcat /proc/config.gz > /home/tc/running.config
sudo mv /home/tc/running.config .config

Now prepare it for compiling:

Code: [Select]
sudo make prepare
sudo make modules_prepare

And then compile all modules to retreive Module.symvers. This takes long! About half a day on the pi.
I know that this goes faster when using cross-compiling. But I don't own a powerfull linux machine.
Anyway, compiling the modules:

Code: [Select]
sudo make modules
When this is done, the driver can be compiled. First get the sources (from: https://github.com/porjo/mt7601):

Code: [Select]
cd /home/tc
git clone https://github.com/porjo/mt7601.git

And start compilation:

Code: [Select]
cd mt7601/src
make

These sources don't compile at the moment, one source (rt_linux.c) has to be changed. I won't go into details about it now, it will complicate this post.
After the modification it will compile.

Then I have to place a .dat file in the right directory:

Code: [Select]
sudo mkdir -p /etc/Wireless/RT2870STA/
sudo cp RT2870STA.dat /etc/Wireless/RT2870STA

And I can try to insmod the module:

Code: [Select]
sudo insmod /home/tc/mt7601/src/os/linux/mt7601Usta.ko
But this will result in this error:
Code: [Select]
insmod: can't insert '/home/tc/mt7601/src/os/linux/mt7601Usta.ko': invalid module format
And this is the message in dmesg:
Code: [Select]
[ 5206.098159] mt7601Usta: no symbol version for module_layout
I've researched all over the internet, and everything points to something with the Module.symvers. But I don't know how to check what's wrong with it..

Greetings,
    Gerrelt.


 
« Last Edit: February 03, 2015, 11:24:18 AM by Gerrelt »
my Raspberry Pi page: http://raspberry.gerrelt.nl

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1086
It means that the modules doesn't match the kernel.   It is probably a difference in the compiler that you are using versus the one that Bela is using.    I've struggled with this before, the only solution is for you to compile the full kernel and modules and remaster the 
system.    Or see if Bela can compile it for you into a tcz.

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
I will upload the 'dirty' kernel source used, I mean the full 3.18.y from GitHub.

I'm using crosstool-NG to build on x86 machine (CentOS 7 but it's not important). I can provide its config, you can install the same environment, mean same toolchain.

But I can try to compile it too. However better to teach you fising than to give a fish :)
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1086
But I can try to compile it too. However better to teach you fishing than to give a fish :)

That is why I suggested remastering.  You haven't had fun unless you built a complete kernel and replaced the entire kernel and modules.

Offline andyj

  • Hero Member
  • *****
  • Posts: 1022
I used Crosstool-NG on Slackware64 and I built a working kernel. I didn't have to replace any modules in the initrd, but I did have to kludge the module path because of the plus sign issue. It sure would be nice however to have the same CTNG build so we working from the same page when we have questions.

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1086
I used Crosstool-NG on Slackware64 and I built a working kernel. I didn't have to replace any modules in the initrd, but I did have to kludge the module path because of the plus sign issue. It sure would be nice however to have the same CTNG build so we working from the same page when we have questions.

Here is a link describing where the plus sign comes from.    http://stackoverflow.com/questions/19333918/dont-add-to-linux-kernel-version

Offline andyj

  • Hero Member
  • *****
  • Posts: 1022
Maybe when I have to rebuild my kernel for the quad-core Pi or Pi clone I hope to get soon I can give it a try.

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Kernel source used to build 3.12.36-piCore+ is available at

http://www.tinycorelinux.net/6.x/armv6/releases/src/kernel/
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 182
Quote from: bmarkus
But I can try to compile it too. However better to teach you fising than to give a fish :)

I totally agree!  :)

Kernel source used to build 3.12.36-piCore+ is available at

http://www.tinycorelinux.net/6.x/armv6/releases/src/kernel/

Thanks, I will give it go. 8)
my Raspberry Pi page: http://raspberry.gerrelt.nl

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 182

After downloading and compiling the kernel soures, I compiled the driver again (after a clean). But I still got the same result.  :-\
So strange, I had it working on the 6.0 rc without much problems.

Béla, could you provide the Module.symvers and the .config for 6.0 too?
my Raspberry Pi page: http://raspberry.gerrelt.nl

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 182
Owh, wait, I might have found it. I used the linux-3.12.y_api_headers.tcz, but these headers are from version 3.12.35. And the current kernel version is  3.12.36.

So, I did a fresh 6.0 install, and didn't install that .tcz this time. I've copied the headers from the kernel source as provided by Béla.
I did this:
Code: [Select]
cd /mnt/sda1/3.12.36/include/uapi
sudo cp -r * /usr/include
cd /usr/include
sudo ln -s asm-generic asm
(the last "asm" symbolic link was necessary to get "make oldconfig" working)

I am compiling the modules "as we speak", tomorrow we will know if this indeed was the solution.

my Raspberry Pi page: http://raspberry.gerrelt.nl

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 182
 :'(  I am getting the exact same eror..
I've checked everything, and it all looks good, but it still doesn't work.
When I do a dry-run with make I can see it uses the right Module.symvers (the one in the kernel directory). But it still doesn't work.
my Raspberry Pi page: http://raspberry.gerrelt.nl

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 182

After replacing my .config and Module.symvers with the ones that Béla used for creating 6.0, everything worked!

I think it is abxolutely necessary that the Module.symvers is exactly the same as when the kernel modules were compiled.
Apparently compiling my own kernel modules resulted in a different Module.symvers.

Anyway, now I've got a working Wifi adapter again.

Thanks everybody for the help, expecially Béla.

@Béla: do you want the new RT2870STA.dat and mt7601Usta.ko for a tce?
my Raspberry Pi page: http://raspberry.gerrelt.nl

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
@Béla: do you want the new RT2870STA.dat and mt7601Usta.ko for a tce?

Sure :)

Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 182
This file should be placed in directory "/etc/Wireless/RT2870STA":

http://www.gerrelt.nl/RaspberryPi/tinycore/piCore_6.0_3.12.36_mt7601_driver/RT2870STA.dat

And you will probably know the best place for this one  :) :

http://www.gerrelt.nl/RaspberryPi/tinycore/piCore_6.0_3.12.36_mt7601_driver/mt7601Usta.ko

And I had to place an "insmod" command in the bootlocal.sh to the mt7601Usta.ko file.


my Raspberry Pi page: http://raspberry.gerrelt.nl