Though this is older post but i am struggling with an issue where any externally built kernel module insmod command returning with an Error:Invalid format. I stumbled down to this post through http://www.raspberrypi.org/forums/viewt ... 9&t=101920
. I am just learning a way to compile , load and run a module on rpi. I followed steps as you mentioned above but with few exceptions (my comments are under /* shally - */) :
# go to source file directory
# download linux source - --depth will restict the amount downloaded
# as you don't need the whole repository
/* shally - instead of git clone -depth 500 and 15 for linux and firmware checkout, i used this command */
git clone --depth 1 https://github.com/raspberrypi/linux.git
# download firmware source - restrict the amount downloaded with --depth
git clone --depth 1 https://github.com/raspberrypi/firmware.git
# set up some symbolic links needed by compile
/* shally - here uname -r shows 3.18.7+ where as seems cloned git linux source has 3.18.9+ version
thus seems symbolic link of 3.18.7 pointing to 3.18.9+ sources */
sudo ln -s /home/pi/src/linux /lib/modules/$(uname -r)/build
sudo ln -s /home/pi/src/linux/arch/arm /home/pi/src/linux/arch/armv6l
# enter linux directory
# set up linux source to 3.12.22+ #690 (git checkout commit-id)
# for a different version change the commit-id
# for 3.12.22+ #691 use commit-id 1981ddebd4
/* shally - i skipped these two step for linux and firmware as i did not understand where to get this and what it is doing
we already have source code for linux and firmware cloned */
git checkout 99df631ec3
# enter firmware directory and set for 3.12.22+ #690 (git checkout commit-id)
# for 3.12.22+ #691 use commit-id 462f3e3f47
git checkout 5bb0317210
# go back to linux source directory
# set up linux to compile your module - make mrproper: init sourc
# - make bcmrpi_defconfig: set up .config file
# - make modules_prepare: compile to set up for module
# - cp ../firmware/extra/Module.symvers . - copy file Module.symvers from firmware to linux directory
# - NOTE: period (full stop) after Module.symvers
make mrproper && make bcmrpi_defconfig && make modules_prepare && cp ../firmware/extra/Module.symvers .
# now go to your rtl8717L source directory wherever it is
/* shally i goto rtl8812au */
# init module source and compile it
make clean && make
# and hopefully it will compile without errors.
So it compiles fine . Insmod still returns me error "invalid module format".
Any help, pointers , suggestion will be greatly appreciated.
Generally things look good but the problem you are seeing is because you are compiling the module using the wrong linux and firmware versions. You are compiling with the very latest versions of the kernel and firmware.
Using command git clone --depth 1 ...
to select the linux source and firmware will only load the very latest code which is for kernel version 3.18.9+ #772 or even newer if the repositories have been updated.
I would suggest you need to use --depth 200
for the linux and --depth 25
for the firmware in the git clone commands. You will then need to select the correct linux and firmware versions to match the kernel you are compiling your module for by using the command git checkout commit-id
in each of the linux and firmware directories. The commit-id is a hex number selecting the commit you need from the repository to select the right kernel and firmware versions. The full commit-id is a 40 character hex number but it is possible to only need to use the first 7-10 characters in the git checkout
To find the right commit-id's for the kernel and firmware you need look at the raspberry pi firmware repository https://github.com/raspberrypi/firmware/commits/master
. You will see a long list of different commits. To find the correct one you need use command uname -a
on your Pi and this will show the kernel version and build number for your kernel and a build date. e.g.
Code: Select all
Linux Pi-B-Plus 3.18.7+ #755 PREEMPT Thu Feb 12 17:14:31 GMT 2015 armv6l GNU/Linux
Now look through the list of commits for one matching the date in the output from uname -a
. If you cannot find a date to match the one in your uname -a
output look for the next date after that.
In the example uname -a
output above the date is Feb 12 and this matches firmware commit 47bd0f0
. Select the button "<>
" to browse the code and look at file extra/uname_string
and this will show the kernel version and build and these should match what you see in your uname -a
command. Using my example extra/uname_string
Code: Select all
Linux version 3.18.7+ ([email protected]) (gcc version 4.8.3 20140303 (prerelease) (crosstool-NG linaro-1.13.1+bzr2650 - Linaro GCC 2014.03) ) #755 PREEMPT Thu Feb 12 17:14:31 GMT 2015
Now look at the file extra/git_hash
and this will show the commit-id for the kernel version.
So for my example to select the correct kernel version and firmware version I could use the commands
Code: Select all
# go to linux directory and select version 3.18.7+ #755
git checkout 0be82f7
# go to firmware directory and select version for kernel 3.18.7+ #755
git checkout 47bd0f0
Sometimes you may find different commits in the firmware repository show the same kernel version and build. Using my example commits 47bd0f0
all show the same kernel version, build number and date in file extra/uname_string
so any one of those commits can be used to select the firmware to use. If I was compiling a module for this version of the kernel I would usually select the newest commit-id, in this case 8aca576
If you update your Pi to a newer version of code you will probably need to re-compile your module. You can update your linux and firmware directories to add newer code using the command git pull
in the linux and firmware directories. If you see a message like "You are not currently on a branch" when you use the git pull
command in the linux directory use the command git checkout rpi-3.18.y
and in the firmware directory the command git checkout master
to reset them then run the git pull
And an update for the new Pi B 2. When you look at the firmware repository and browse the code in the directory extra
you will see several files including the number "7
". e.g. Module7.symvers
. These are files for the new version PI, the Pi B 2. If you want to compile modules for the Pi B 2 instead of using the command make bcmrpi_defconfig
to generate the .config
file you will need to use the command make bcm2709_defconfig
and instead of copying file Module.symvers
to the linux directory you will need to copy the file Module7.symvers
to file Module.symvers
in the linux directory.
Hope this helps you select the correct kernel and firmware version to compile your module and it now works.
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra
Please post ALL technical questions on the forum. Please Do Not send private messages.