happycloud
Posts: 7
Joined: Fri Jul 25, 2014 8:41 am

Compiling drivers RTL8187L for Alfa awus036h

Fri Jul 25, 2014 9:15 am

Hello!
Raspbian comes with a driver for the RTL8187L chipset which is rtl8187

Code: Select all

$  lsmod | grep 8187
rtl8187                51423  0

Code: Select all

$ modinfo rtl8187
filename:       /lib/modules/3.12.22+/kernel/drivers/net/wireless/rtl818x/rtl8187/rtl8187.ko
license:        GPL
description:    RTL8187/RTL8187B USB wireless driver
author:         Larry Finger <Larry.Finger@lwfinger.net>
author:         Hin-Tak Leung <htl10@users.sourceforge.net>
author:         Herton Ronaldo Krzesinski <herton@mandriva.com.br>
author:         Andrea Merello <andrea.merello@gmail.com>
author:         Michael Wu <flamingice@sourmilk.net>
srcversion:     A707FEC6B464A70F7A04C69
It turns out that this driver for RTL8187L works ok but has some bugs, specially when it comes to using the Rpi as a AP. It also fails in monitor mode.

Luckily, the folks at Realtek have also released a more recent version of this driver : rtl8187L_linux_1041.0209.2012. The source is available at on Realtek's site.

Now, I'm trying to compile this source for my raspberryPi and that's where the problem starts. I was hoping I could get some help :)

The first problem I bumped into was this:

Code: Select all

~/rtl8187L_linux_1041.0209.2012 $ make
make: *** /lib/modules/3.12.22+/build: No such file or directory.  Stop.
make: *** [all] Error 2
My solution was to :

Code: Select all

$ sudo apt-get install linux-headers-$(uname -r)
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package linux-headers-3.12.22
E: Couldn't find any package by regex 'linux-headers-3.12.22'
I actually installed

Code: Select all

linux-headers-3.12-1-rpi
instead, and linked the

Code: Select all

build
directory, but I got compilation errors...

Am I on the right track? Am I missing something?
What's the "book way" to compile drivers for Raspberry?

Thanks!

diederik
Posts: 394
Joined: Wed Mar 26, 2014 11:17 pm

Re: Compiling drivers RTL8187L for Alfa awus036h

Sat Jul 26, 2014 10:41 am

You've got a raspberry pi foundation (rpf) kernel and the linux-headers package is for raspbian, so they don't match.
You can get the rpf kernel source here: https://github.com/raspberrypi/linux

happycloud
Posts: 7
Joined: Fri Jul 25, 2014 8:41 am

Re: Compiling drivers RTL8187L for Alfa awus036h

Sun Jul 27, 2014 7:55 pm

Thanks Diederik. What should I do when this is checked out?
Should I compile the whole kernel?

Thanks,

diederik
Posts: 394
Joined: Wed Mar 26, 2014 11:17 pm

Re: Compiling drivers RTL8187L for Alfa awus036h

Mon Jul 28, 2014 9:36 am

Recompiling the whole kernel is overkill and I wouldn't do that if I were you.
I haven't compiled a module myself, so I can't help you with that. But there should be plenty of tutorials etc either on this forum or on the internet.
I just saw that you were running a rpf kernel and installing the raspbian kernel headers, which don't match and hence compiling a module won't work.

The real solution should be that the rpf would supply a linux-headers-<version> debian package ... but I don't know if/when that will happen.
Also keep in mind that if you run rpi-update, that you would probably get a new kernel version and that means that you'd have to compile a module for your card again (... and again ...)

MrEngman
Posts: 4140
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: Compiling drivers RTL8187L for Alfa awus036h

Mon Jul 28, 2014 11:52 am

I use this to compile various modules I use. No need to compile the full linux source, just need to configure it to compile additional modules, takes less than 5 minutes. A full kernel compile can take around 10hrs on a Pi.

Code: Select all

# create directory for source files in my home directory (/home/pi)
mkdir src
# go to source file directory
cd src
# download linux source - --depth will restict the amount downloaded
# as you don't need the whole repository
git clone --depth 500 https://github.com/raspberrypi/linux.git
# download firmware source - restrict the amount downloaded with --depth
git clone --depth 15 https://github.com/raspberrypi/firmware.git
# set up some symbolic links needed by compile
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
cd linux
# 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
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
cd ../firmware
git checkout 5bb0317210
# go back to linux source directory
cd ../linux
# 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
cd ../rtl8717L
# init module source and compile it
make clean && make
# and hopefully it will compile without errors. 
For other versions of linux to find the necessary commit-id's go to https://github.com/raspberrypi/firmware/commits/master and look though the list of firmware commits for one close to your version. Then select browse code (<>) and look at firmware/extra/uname-string to check linux version, 3.12.xx+, and build number, #123. When you find the right version and build look at firmware/extra/git_hash for the linux source commit-id. The full commit-id is a 40 character value but you should only need to use the first 7-10 character to set the right source version.

I've had some problems with modules compiled using the default gcc version (4.6) and have updated mine to gcc-4.7 currently. Also to get a different Realtek driver I use to compile I had to make a few changes.



MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

happycloud
Posts: 7
Joined: Fri Jul 25, 2014 8:41 am

Re: Compiling drivers RTL8187L for Alfa awus036h

Thu Jul 31, 2014 7:34 am

Hum.. I'm struggling to clone the linux directory...:

Code: Select all

fatal: Out of memory, malloc failed (tried to allocate 1519697 bytes)
Not sure what I can do, because the memory on my Pi is obviously limited :/ Any hint?

SteveSpencer
Posts: 432
Joined: Thu Mar 28, 2013 9:19 am
Location: Nottingham, UK

Re: Compiling drivers RTL8187L for Alfa awus036h

Thu Jul 31, 2014 7:58 am

You could use raspi-config to temporarily change the amount of GPU memory...
Steve S
No, I can't think of anything funny that won't offend someone if they want it to...

MrEngman
Posts: 4140
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: Compiling drivers RTL8187L for Alfa awus036h

Thu Jul 31, 2014 10:06 am

SteveSpencer wrote:You could use raspi-config to temporarily change the amount of GPU memory...
Is that message to do with failing while downloading, like a lack of swap space, or just insufficient space on the SD card.

I can git clone on an A and B1 if I add some swap space. With a B2 and B+ I've not seen this type of issue.
happycloud wrote:Hum.. I'm struggling to clone the linux directory...:

Code: Select all

fatal: Out of memory, malloc failed (tried to allocate 1519697 bytes)
Not sure what I can do, because the memory on my Pi is obviously limited :/ Any hint?
What size SD card are you using? Did you expand the partition with raspi-config? What model Pi are you using?

The first line of command df -h (rootfs) will give a general idea of how much free space you have.



MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

SteveSpencer
Posts: 432
Joined: Thu Mar 28, 2013 9:19 am
Location: Nottingham, UK

Re: Compiling drivers RTL8187L for Alfa awus036h

Thu Jul 31, 2014 12:32 pm

malloc specifically relates to RAM, so lack of swap is probably the culprit.
Steve S
No, I can't think of anything funny that won't offend someone if they want it to...

happycloud
Posts: 7
Joined: Fri Jul 25, 2014 8:41 am

Re: Compiling drivers RTL8187L for Alfa awus036h

Thu Jul 31, 2014 3:57 pm

Ok, git was the culprit it seems because I cloned the repo on my laptop and then scp'ed it to the pi and that worked great...

Compiling the Modules worked:

Code: Select all

$ make mrproper && make bcmrpi_defconfig && make modules_prepare && cp ../firmware/extra/Module.symvers .
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  SHIPPED scripts/kconfig/zconf.tab.c
  SHIPPED scripts/kconfig/zconf.lex.c
  SHIPPED scripts/kconfig/zconf.hash.c
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
#
# configuration written to .config
#
scripts/kconfig/conf --silentoldconfig Kconfig
  CHK     include/config/kernel.release
  UPD     include/config/kernel.release
  WRAP    arch/arm/include/generated/asm/auxvec.h
  WRAP    arch/arm/include/generated/asm/bitsperlong.h
  WRAP    arch/arm/include/generated/asm/cputime.h
  WRAP    arch/arm/include/generated/asm/current.h
  WRAP    arch/arm/include/generated/asm/emergency-restart.h
  WRAP    arch/arm/include/generated/asm/errno.h
  WRAP    arch/arm/include/generated/asm/exec.h
  WRAP    arch/arm/include/generated/asm/ioctl.h
  WRAP    arch/arm/include/generated/asm/ipcbuf.h
  WRAP    arch/arm/include/generated/asm/irq_regs.h
  WRAP    arch/arm/include/generated/asm/kdebug.h
  WRAP    arch/arm/include/generated/asm/local.h
  WRAP    arch/arm/include/generated/asm/local64.h
  WRAP    arch/arm/include/generated/asm/msgbuf.h
  WRAP    arch/arm/include/generated/asm/param.h
  WRAP    arch/arm/include/generated/asm/parport.h
  WRAP    arch/arm/include/generated/asm/poll.h
  WRAP    arch/arm/include/generated/asm/resource.h
  WRAP    arch/arm/include/generated/asm/sections.h
  WRAP    arch/arm/include/generated/asm/segment.h
  WRAP    arch/arm/include/generated/asm/sembuf.h
  WRAP    arch/arm/include/generated/asm/serial.h
  WRAP    arch/arm/include/generated/asm/shmbuf.h
  WRAP    arch/arm/include/generated/asm/siginfo.h
  WRAP    arch/arm/include/generated/asm/sizes.h
  WRAP    arch/arm/include/generated/asm/socket.h
  WRAP    arch/arm/include/generated/asm/sockios.h
  WRAP    arch/arm/include/generated/asm/termbits.h
  WRAP    arch/arm/include/generated/asm/termios.h
  WRAP    arch/arm/include/generated/asm/timex.h
  WRAP    arch/arm/include/generated/asm/trace_clock.h
  WRAP    arch/arm/include/generated/asm/unaligned.h
  CHK     include/generated/uapi/linux/version.h
  UPD     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  UPD     include/generated/utsrelease.h
  Generating include/generated/mach-types.h
  CC      kernel/bounds.s
  GEN     include/generated/bounds.h
  CC      arch/arm/kernel/asm-offsets.s
  GEN     include/generated/asm-offsets.h
  CALL    scripts/checksyscalls.sh
  HOSTCC  scripts/genksyms/genksyms.o
  SHIPPED scripts/genksyms/lex.lex.c
  SHIPPED scripts/genksyms/keywords.hash.c
  SHIPPED scripts/genksyms/parse.tab.h
  HOSTCC  scripts/genksyms/lex.lex.o
  SHIPPED scripts/genksyms/parse.tab.c
  HOSTCC  scripts/genksyms/parse.tab.o
  HOSTLD  scripts/genksyms/genksyms
  CC      scripts/mod/empty.o
  HOSTCC  scripts/mod/mk_elfconfig
  MKELF   scripts/mod/elfconfig.h
  CC      scripts/mod/devicetable-offsets.s
  GEN     scripts/mod/devicetable-offsets.h
  HOSTCC  scripts/mod/file2alias.o
  HOSTCC  scripts/mod/modpost.o
  HOSTCC  scripts/mod/sumversion.o
  HOSTLD  scripts/mod/modpost
  HOSTCC  scripts/kallsyms
  HOSTCC  scripts/pnmtologo
  HOSTCC  scripts/conmakehash
  HOSTCC  scripts/bin2c
  HOSTCC  scripts/sortextable
But building the driver fails:

Code: Select all

$ make clean && make
rm -fr *.mod.c *.mod *.o .*.cmd *.ko *~
rm -fr .tmp_versions
rm -fr Module.symvers
rm -fr modules.order
rm -fr Module.markers
rm -rf tags
make -C /lib/modules/3.12.22+/build M=/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187 CC=gcc modules
make[1]: Entering directory `/home/pi/src/linux'
  CC [M]  /home/pi/rtl8187L_linux_1041.0209.2012/rtl8187/r8187_core.o
gcc: error: -msoft-float and -mhard_float may not be used together
make[2]: *** [/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187/r8187_core.o] Error 1
make[1]: *** [_module_/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187] Error 2
make[1]: Leaving directory `/home/pi/src/linux'
make: *** [modules] Error 2
Now, I'm lost :/

SteveSpencer
Posts: 432
Joined: Thu Mar 28, 2013 9:19 am
Location: Nottingham, UK

Re: Compiling drivers RTL8187L for Alfa awus036h

Fri Aug 01, 2014 4:08 pm

So am I. You shouldn't be specifying soft floating point and hard floating point. You want one or the other, ideally hard fp for Raspian. Something in the driver's makefile isn't configured properly.
Steve S
No, I can't think of anything funny that won't offend someone if they want it to...

happycloud
Posts: 7
Joined: Fri Jul 25, 2014 8:41 am

Re: Compiling drivers RTL8187L for Alfa awus036h

Sat Aug 02, 2014 9:49 am

Well, I guess the driver I got from the Realtek website has never be tested on a rpi :(

happycloud
Posts: 7
Joined: Fri Jul 25, 2014 8:41 am

Re: Compiling drivers RTL8187L for Alfa awus036h

Mon Aug 04, 2014 7:54 pm

I'm now trying to fix the Makefile. This is my very first time tinkering with a driver Makefile, but I'm hopeful.
The makefile has a line like this:

Code: Select all

EXTRA_CFLAGS += -mhard-float -DCONFIG_FORCE_HARD_FLOAT=y
but not line that indicates soft-float . Any idea where this could come from or how to find it?

happycloud
Posts: 7
Joined: Fri Jul 25, 2014 8:41 am

Re: Compiling drivers RTL8187L for Alfa awus036h

Mon Aug 04, 2014 8:19 pm

Based on what I could gather online, it'll be hard to remove the *soft-float* handle... so I commented the *hard-float* in the driver Makefile and tried to compile:

Code: Select all

$ make
make -C /lib/modules/3.12.22+/build M=/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187 CC=gcc modules
make[1]: Entering directory `/home/pi/src/linux'
  CC [M]  /home/pi/rtl8187L_linux_1041.0209.2012/rtl8187/r8187_core.o
/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187/r8187_core.c:153:22: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'rtl8187_usb_probe'
/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187/r8187_core.c:155:23: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'rtl8187_usb_disconnect'
/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187/r8187_core.c:168:12: error: 'rtl8187_usb_probe' undeclared here (not in a function)
/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187/r8187_core.c:169:16: error: 'rtl8187_usb_disconnect' undeclared here (not in a function)
/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187/r8187_core.c: In function 'rtl8180_proc_module_init':
/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187/r8187_core.c:427:2: error: implicit declaration of function 'create_proc_entry' [-Werror=implicit-function-declaration]
/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187/r8187_core.c:427:14: warning: assignment makes pointer from integer without a cast [enabled by default]
/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187/r8187_core.c: In function 'rtl8180_proc_init_one':
/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187/r8187_core.c:461:16: warning: assignment makes pointer from integer without a cast [enabled by default]
/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187/r8187_core.c:479:2: error: implicit declaration of function 'create_proc_read_entry' [-Werror=implicit-function-declaration]
/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187/r8187_core.c:479:4: warning: assignment makes pointer from integer without a cast [enabled by default]
/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187/r8187_core.c:489:4: warning: assignment makes pointer from integer without a cast [enabled by default]
/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187/r8187_core.c:518:4: warning: assignment makes pointer from integer without a cast [enabled by default]
/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187/r8187_core.c: At top level:
/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187/r8187_core.c:3762:22: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'rtl8187_usb_probe'
/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187/r8187_core.c:3862:23: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'rtl8187_usb_disconnect'
cc1: some warnings being treated as errors
make[2]: *** [/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187/r8187_core.o] Error 1
make[1]: *** [_module_/home/pi/rtl8187L_linux_1041.0209.2012/rtl8187] Error 2
make[1]: Leaving directory `/home/pi/src/linux'
make: *** [modules] Error 2
Yikes.

shallyverma
Posts: 4
Joined: Mon Mar 23, 2015 11:32 am

Re: Compiling drivers RTL8187L for Alfa awus036h

Tue Mar 24, 2015 10:21 am

MrEngman wrote:I use this to compile various modules I use. No need to compile the full linux source, just need to configure it to compile additional modules, takes less than 5 minutes. A full kernel compile can take around 10hrs on a Pi.

Code: Select all

# create directory for source files in my home directory (/home/pi)
mkdir src
# go to source file directory
cd src
# download linux source - --depth will restict the amount downloaded
# as you don't need the whole repository
git clone --depth 500 https://github.com/raspberrypi/linux.git
# download firmware source - restrict the amount downloaded with --depth
git clone --depth 15 https://github.com/raspberrypi/firmware.git
# set up some symbolic links needed by compile
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
cd linux
# 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
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
cd ../firmware
git checkout 5bb0317210
# go back to linux source directory
cd ../linux
# 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
cd ../rtl8717L
# init module source and compile it
make clean && make
# and hopefully it will compile without errors. 
For other versions of linux to find the necessary commit-id's go to https://github.com/raspberrypi/firmware/commits/master and look though the list of firmware commits for one close to your version. Then select browse code (<>) and look at firmware/extra/uname-string to check linux version, 3.12.xx+, and build number, #123. When you find the right version and build look at firmware/extra/git_hash for the linux source commit-id. The full commit-id is a 40 character value but you should only need to use the first 7-10 character to set the right source version.

I've had some problems with modules compiled using the default gcc version (4.6) and have updated mine to gcc-4.7 currently. Also to get a different Realtek driver I use to compile I had to make a few changes.



MrEngman
HI MrEngman
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 - */) :
mkdir src
# go to source file directory
cd src
# 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
cd linux
# 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
cd ../firmware
git checkout 5bb0317210
# go back to linux source directory
cd ../linux
# 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 */
cd ../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.

MrEngman
Posts: 4140
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: Compiling drivers RTL8187L for Alfa awus036h

Tue Mar 24, 2015 5:12 pm

shallyverma wrote:HI MrEngman
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 - */) :
mkdir src
# go to source file directory
cd src
# 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
cd linux
# 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
cd ../firmware
git checkout 5bb0317210
# go back to linux source directory
cd ../linux
# 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 */
cd ../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 commands.

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 shows

Code: Select all

Linux version 3.18.7+ (dc4@dc4-XPS13-9333) (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
cd ~/src/linux
git checkout 0be82f7
# go to firmware directory and select version for kernel 3.18.7+ #755
cd ~/src/firmware
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, 89efbd4 and 8aca576 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 commands again.

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, System7.map and uname_string7. 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.


MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

shallyverma
Posts: 4
Joined: Mon Mar 23, 2015 11:32 am

Re: Compiling drivers RTL8187L for Alfa awus036h

Wed Mar 25, 2015 4:25 am

MrEngman wrote:
shallyverma wrote:HI MrEngman
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 - */) :
mkdir src
# go to source file directory
cd src
# 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
cd linux
# 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
cd ../firmware
git checkout 5bb0317210
# go back to linux source directory
cd ../linux
# 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 */
cd ../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 commands.

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 shows

Code: Select all

Linux version 3.18.7+ (dc4@dc4-XPS13-9333) (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
cd ~/src/linux
git checkout 0be82f7
# go to firmware directory and select version for kernel 3.18.7+ #755
cd ~/src/firmware
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, 89efbd4 and 8aca576 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.

[Shally] Now, i am successful in doing this. Now i could retrieve Kernel source code matching version 3.18.7+ on Pi and now can both build and load module by compiling on Pi itself and also through cross compiler. Only key point is both cross compiler and pi must have same kernel source code.


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 commands again.

[Shally] Next i wanted to understand this. I tried to boot Pi through newer kernel code 3.18.9+. As per instructions on this page http://www.raspberrypi.org/documentatio ... uilding.md, I built kernel , copy /linux/arch/arm/boot/Image /boot/kernel.img and replug the SD card on board. On console messages, it shows linux version 3.18.9+ but keyboard and mouse weren't working. Then i tried to build and install modules on ext4 partition on SDCard. However command
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=/mnt/ext4 modules works. But
sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=/mnt/ext4 modules_install fails with error message "arm-linux-gnueabihf-gcc :Command not found. Could not install modules on /mnt/ext4:Operation not permitted".
I tried to reset PATH variable to point to raspbian tools directory but that did not help.
In nutshell, i wanted to understand what steps do i need to follow if i want to boot new kernel on Pi

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, System7.map and uname_string7. 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.


MrEngman
HI MrEngman

Thanks a ton for your detailed reply. it explained lot more things to me. However, i have few questions regarding booting Pi with newer kernel version.Could you please see my comment embed against your reply marked as [Shally]

MrEngman
Posts: 4140
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: Compiling drivers RTL8187L for Alfa awus036h

Wed Mar 25, 2015 9:41 am

shallyverma wrote:
[Shally] Now, i am successful in doing this. Now i could retrieve Kernel source code matching version 3.18.7+ on Pi and now can both build and load module by compiling on Pi itself and also through cross compiler. Only key point is both cross compiler and pi must have same kernel source code.


[Shally] Next i wanted to understand this. I tried to boot Pi through newer kernel code 3.18.9+. As per instructions on this page http://www.raspberrypi.org/documentatio ... uilding.md, I built kernel , copy /linux/arch/arm/boot/Image /boot/kernel.img and replug the SD card on board. On console messages, it shows linux version 3.18.9+ but keyboard and mouse weren't working. Then i tried to build and install modules on ext4 partition on SDCard. However command
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=/mnt/ext4 modules works. But
sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=/mnt/ext4 modules_install fails with error message "arm-linux-gnueabihf-gcc :Command not found. Could not install modules on /mnt/ext4:Operation not permitted".
I tried to reset PATH variable to point to raspbian tools directory but that did not help.
In nutshell, i wanted to understand what steps do i need to follow if i want to boot new kernel on Pi


HI MrEngman

Thanks a ton for your detailed reply. it explained lot more things to me. However, i have few questions regarding booting Pi with newer kernel version.Could you please see my comment embed against your reply marked as [Shally]
Good to hear you have a working module.

Personally I have never tried building and creating a new SD card that way so I have no idea what your problem now is. I would think there must be plenty of info in the forum somewhere so a google search of the forum may help you find some help, something like this - "site:raspberrypi.org compiling new kernel".

I always update my kernel using command

Code: Select all

sudo rpi-update
which will load the latest kernel build or command

Code: Select all

sudo rpi-update commit-id
using a commit-id from https://github.com/Hexxeh/rpi-firmware/commits/master to load a specific version. Using sudo rpi-update commit-id you can even go back to an older version.


MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

Return to “Raspberry Pi OS”