LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices

Reply
 
LinkBack Search this Thread
Old 10-10-2007, 09:47 AM   #1
AndrewShanks
LQ Newbie
 
Registered: Oct 2007
Posts: 7

Rep: Reputation: 0
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 2.6.16.28-arcom1-2-zeus. 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-2.6.16.18-arcom1 source tree under /opt/arcom/src/ using tarball supplied by Arcom
3: in root directory of linux-source-2.6.16.18-arcom1 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-2.6.16.18-arcom1/drivers/helloworld

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

MODULE_LICENSE("GPL") ;

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/2.6.16.28-arcom1-2-zeus/kernel/drivers/helloworld 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.

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

Last edited by AndrewShanks; 10-10-2007 at 10:00 AM. Reason: New information
 
Old 10-11-2007, 06:52 AM   #2
kennithwang
Member
 
Registered: Aug 2007
Location: shanghai
Distribution: LDD
Posts: 32

Rep: Reputation: 15
make modules

after then you

XXX-strip XXX.ko

Have you done that?
 
Old 10-11-2007, 07:17 AM   #3
AndrewShanks
LQ Newbie
 
Registered: Oct 2007
Posts: 7

Original Poster
Rep: Reputation: 0
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.6.16.27-arcom1
2) mkdir /opt/arcom/src/build-zeus
3) cp /opt/arcom/src/linux-source-2.6.16.27-arcom1/arch/arm/configs/zeus_defconfig /opt/arcom/src/build-zeus/.config
4) cd opt/arcom/src/linux-source-2.6.16.27-arcom1
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:

CC=/opt/arcom/bin/arm-linux-gcc
#location of cross-compiler

ifneq ($(KERNELRELEASE),)
#standard test for whether or not makefile is being called from within kernel build tree
obj-m := hello.o
else

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

PWD := $(shell pwd)

CFLAGS = -O2 -D__KERNEL__ -DLINUX -Dlinux -DMODULE -DEXPORT_SYMTAB -O3 -Wall -I$(KERNELDIR) -O

default:
$(MAKE) ARCH=arm CROSS-COMPILE=$(CC) -C $(KERNELDIR) M=$(PWD) modules
endif

8) from the linux-source-2.6.16.28-arcom1 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.

Last edited by AndrewShanks; 10-11-2007 at 07:18 AM. Reason: Clean up info. on what I did
 
Old 10-13-2007, 09:41 PM   #4
kennithwang
Member
 
Registered: Aug 2007
Location: shanghai
Distribution: LDD
Posts: 32

Rep: Reputation: 15
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?

Kennith
 
Old 10-15-2007, 03:50 AM   #5
AndrewShanks
LQ Newbie
 
Registered: Oct 2007
Posts: 7

Original Poster
Rep: Reputation: 0
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.
 
  


Reply

Tags
kernel, modules


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
insmod: error inserting 'usbip.ko': -1 Invalid module format barunparichha Linux - Software 1 01-13-2007 08:51 PM
insmod: error inserting 'module.o': -1 Invalid module format ksrinivas Linux - Newbie 5 10-11-2006 07:29 AM
insmod: error inserting 'new.ko': -1 Invalid module format hemk76 Programming 2 01-26-2005 10:52 AM
insmod invalid module format csfalcon Linux - Hardware 6 01-24-2005 11:03 AM
insmod: error inserting 'new.ko': -1 Invalid module format hemk76 Programming 2 01-24-2005 10:42 AM


All times are GMT -5. The time now is 03:00 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration