-   Linux - Embedded & Single-board computer (
-   -   error: -1 Invalid module format when using insmod with module cross-compiled for arm (

AndrewShanks 10-10-2007 09:47 AM

error: -1 Invalid module format when using insmod with module cross-compiled for arm
I am trying to build a kernel module for an Arcom zeus board with a PXA270 processor running arcom embedded linux with kernel I followed the steps described below:
1: Installed development environment (arm-linux- cross compiler etc.) on host pc (x86 processor running Centos 4 with kernel 2.6.9-55.0.9.EL)
2: Created linux-source- source tree under /opt/arcom/src/ using tarball supplied by Arcom
3: in root directory of linux-source- tree, entered command cp /arch/arm/configs/zeus_defconfig ./.config
4: ran make ARCH=arm CROSS_COMPILE=arm-linux- xconfig
5: changed nothing in xconfig
6: ran make ARCH=arm CROSS_COMPILE=arm-linux-
7: wrote module in /linux-source-

#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>


static int hello_init(void){
printk("<1> Hello World!\n") ;
return 0 ;

static void hello_exit(void) {
printk("<1> Goodbye cruel world!\n") ;
return ;

module_init(hello_init) ;
module_exit(hello_exit) ;

8: Created Makefile in helloworld directory

obj-m := hello.o

9:At this point, running
$make -C ../../ M=`pwd` ARCH=arm CROSS_COMPILE=arm_linux- modules
causes built-in.o, hello.ko, hello.mod.c hello.mod.o and hello.o to be created within the helloworld directory.

10: ftp hello.ko to the Zeus board.
11: put hello.ko in /lib/modules/ on the Zeus board
12: from that directory, run /sbin/insmod hello.ko

When I try to do the insmod command, my computer returns the error message
"insmod: error inserting 'hello.ko': -1 Invalid module format"

If I try to use modprobe by running /sbin/modprobe hello.ko, I get the error
"FATAL: Module hello.ko not found."

I have previously been able to cross compile applications for the zeus board using arm-linux-gcc, but this is my first driver.

I have also been able to use insmod with modules that have been provided on the zeus board, such as pxa2xx_spi.ko, but /sbin/modprobe pxa2xx_spi.ko also causes the message "FATAL: module pxa2xx_spi.ko not found."

Any help you can offer would be gratefully recieved.

After doing some more searches I found out about dmesg, which gives me the message
"hello: version magic ' ARMv5 gcc-3.4' should be ' ARMv5 gcc-3.4"

kennithwang 10-11-2007 06:52 AM

make modules

after then you

XXX-strip XXX.ko

Have you done that?

AndrewShanks 10-11-2007 07:17 AM

I've not done that - I got some advice from my vendor about how to build my development kernel so that the magics match, and that seemed to work when I tried it. What does the strip command do?

In case anyone else has the same problem, or is curious, I'm including a description of what I did following the vendor's advice:

===What I did following vendor's advice====

For my system (Arcom Zeus running Arcom embedded linux), the vendor supplies a board specific script "ael-kmake" that provides the appropriate parameters to the makefiles if called with ael-kmake -b zeus. Provided I used the vendor's script to ensure that my build was the same as their's, I could get away with changing the magic by hand. On my system, the extension for the magic "-arcom1" or "-arcom1-2-zeus" is defined in a file called localversion00-arcomn, although my reading indicates that in some versions you can get the same effect by changing the line of the top-level Makefile that reads "EXTRAVERSION = (whatever)".

In summary, the steps I took to get a working module were
1) unpack linux kernel to /opt/arcom/src/linux-source-
2) mkdir /opt/arcom/src/build-zeus
3) cp /opt/arcom/src/linux-source- /opt/arcom/src/build-zeus/.config
4) cd opt/arcom/src/linux-source-
5) open localversion00-arcomn in text editor and change "arcom1" to "arcom1-2-zeus"
6) eal-kmake -b zeus

At this stage the development kernel should be built. The folowing steps are to compile the modules against it.

7)change Makefile associated with module so that it fits better with the script - mainly defining parameters and testing how the makefile is being run:

#location of cross-compiler

#standard test for whether or not makefile is being called from within kernel build tree
obj-m := hello.o

KERNELDIR ?= /*Put the path of your include file here*/

PWD := $(shell pwd)



8) from the linux-source- directory, issue the command (eg)
ael-kmake -b zeus -m drivers/helloworld
9) ftp the resulting hello.ko file from the hello world directory to the Zeuz board
10) ssh or telnet to the zeus board and run /sbin/insmod hello.ko

I don't know how well this exact sequence will work for non-zeus boards, but hopefully there are some bits that will be useful.

kennithwang 10-13-2007 09:41 PM

Have you experienced embedded linux OS development?
You can download arm cross-compilation-toolchain directly?

And you can make changes to other linux device driver in original source code, other than rewite a new device drviers, such as "hello" driver, so as to test your cross toolhain.

Sorry for my poor english?


AndrewShanks 10-15-2007 03:50 AM

This is my first experience with embedded Linux, as you might have guessed from the fact that I'm doing a "hello world" module. I don't really know what makes up a toolchain. Is that preprocessor->compiler->linker, or is it something different? the supplier of my board provided a cd with a script for building what they call a "development environment", including cross-compilers and Linux source. I think there's some support for autoconf and other tools, but I don't really know how to use them.

I've been able to compile applications with the development environment, and I managed to get the hello world module to work after following the instructions from the supplier, and changing the version number in the makefile.

All times are GMT -5. The time now is 02:46 PM.