3

I try to compile the source code of DHT11 module given in [https://www.endian.se/content/?p=127] . I have followed the step of KERNEL compilation in [[http://bchavez.bitarmory.com/archive/2013/01/16/compiling-kernel-modules-for-raspberry-pi.aspx ] and succeed. whene I try to compile the file dht11km.c I get error :

make arch=ARM CROSS_COMPILE=/home/makhlouf/rpi/tools-master/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi- -C /home/makhlouf/rpi/linux M=/home/makhlouf/temperature modules
make[1]: Entering directory `/home/makhlouf/rpi/linux'
/home/makhlouf/rpi/linux/arch/x86/Makefile:98: stack protector enabled but no compiler support
  CC [M]  /home/makhlouf/temperature/dht11km.o
arm-bcm2708-linux-gnueabi-gcc: error: unrecognized command line option '-m64'
arm-bcm2708-linux-gnueabi-gcc: error: unrecognized command line option '-mno-mmx'
arm-bcm2708-linux-gnueabi-gcc: error: unrecognized command line option '-mno-sse'
arm-bcm2708-linux-gnueabi-gcc: error: unrecognized command line option '-mno-red-zone'
arm-bcm2708-linux-gnueabi-gcc: error: unrecognized command line option '-mcmodel=kernel'
arm-bcm2708-linux-gnueabi-gcc: error: unrecognized command line option '-maccumulate-outgoing-args'
make[2]: *** [/home/makhlouf/temperature/dht11km.o] Error 1
make[1]: *** [_module_/home/makhlouf/temperature] Error 2
make[1]: Leaving directory `/home/makhlouf/rpi/linux'
make: *** [all] Error 2

Makefile :

obj-m += dht11km.o

all:
    make arch=ARM CROSS_COMPILE=${CCPREFIX} -C /home/makhlouf/rpi/linux M=$(PWD) modules

clean:
    make -C /home/makhlouf/rpi/linux M=$(PWD) clean

linux source is in /home/makhlouf/rpi/linux

  • Have you considered a userland solution? There is a method using Python/SPI which seems 100% reliable. I have my own Python DHT22 module which uses any spare gpio and has error rates of roughly one bad read per 40,000. However I have seen the DHT22 become unresponsive with my method. I have never seen unresponsiveness with the SPI method. – joan May 14 '14 at 12:00
  • thanks @joan but it's home work, I should made it with c. and compile the module. – Makhlouf GHARBI May 14 '14 at 12:04
  • Homework was different in my day! I don't know anything about building kernel modules. The line /home/makhlouf/rpi/linux/arch/x86/Makefile looks odd. RPi (ARM) and x86 do not mix. – joan May 14 '14 at 12:11
  • I think you're right, in the directory /home/makhlouf/rpi/linux/arch/ there is arm, x86 ...., I'm sure i had an options error when compiling the kernel, I will review it – Makhlouf GHARBI May 14 '14 at 12:14
  • this like works fine for me [ stackoverflow.com/questions/20167411/… ] – Makhlouf GHARBI May 14 '14 at 19:41
3

Here are the steps required to build a kernel module on Raspbian.

  1. Perform an sudo rpi-update

    See https://github.com/Hexxeh/rpi-update for details on rpi-update. You have to be on the latest firmware and associated kernel to be able to perform the next step.

  2. Install and run rpi-source to install the source code that built the latest kernel that you are running. This will create the correct entry in /lib/modules for the kernel that you are running. Note: you don't need to be root to run this, however the script will perform certain tasks using sudo and the root password will be requested during the script execution.

    Instructions to install rpi-source can be found at https://github.com/notro/rpi-source/wiki

Once those steps are performed you should be able to make your kernel module.

johnma@raspberrypi ~ $ cd dht11km/
johnma@raspberrypi ~/dht11km $ make
make -C /lib/modules/3.12.19+/build M=/home/johnma/dht11km modules
make[1]: Entering directory `/home/johnma/linux-c3db7205bcd8988cf7c185e50c8849542554b1f5'
  CC [M]  /home/johnma/dht11km/dht11km.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/johnma/dht11km/dht11km.mod.o
  LD [M]  /home/johnma/dht11km/dht11km.ko
make[1]: Leaving directory `/home/johnma/linux-c3db7205bcd8988cf7c185e50c8849542554b1f5'


johnma@raspberrypi ~/dht11km $ sudo insmod dht11km.ko gpio_pin=4 format=3
May 14 21:58:58 raspberrypi kernel: [ 2985.291192] dht11: driver registered!
johnma@raspberrypi ~/dht11km $ sudo mknod /dev/dht11 c 80 0
johnma@raspberrypi ~/dht11km $ cat /dev/dht11 
Temperature: 2C
Humidity: 0%
Result:OK
  • rpi-source command not found. sudo apt-get install rpi-source : Unable to locate package rpi-source – Makhlouf GHARBI May 15 '14 at 10:27
  • Added link for instructions on how to install rpi-source – HeatfanJohn May 15 '14 at 12:45
3

I was able to build (make) the module on my Raspberry Pi itself instead of cross compiling it on another machine.

However, I needed to perform the steps listed at the end to avoid the following error:

raspberrypi ~/dht11km $ make
make -C /lib/modules/3.10.25+/build M=/home/johnma/dht11km modules
make: *** /lib/modules/3.10.25+/build: No such file or directory.  Stop.
make: *** [all] Error 2

The following instructions from this article allowed the make to complete without error.

  1. Try to install linux-headers

    sudo apt-get install linux-headers

    You get a message that you try to install a virtual package and you have to install a concrete package. You find a list of concrete packages.

  2. Install the concrete package

    sudo apt-get install linux-headers-3.10-3-rpi

  3. Now the trick. You have to link the new build folder with the missing folder.

    sudo ln -s /lib/modules/3.10-3-rpi/build /lib/modules/3.10.25+/build

Here's what modinfo shows after the make completes:

~/dht11km $ modinfo ./dht11km.ko
filename:       /home/johnma/dht11km/./dht11km.ko
license:        GPL
author:         Nigel Morton
description:    DHT11 temperature/humidity sendor driver for Raspberry Pi GPIO.
depends:
vermagic:       3.10-3-rpi mod_unload modversions ARMv6 p2v8
parm:           format:int
parm:           gpio_pin:Format of output (int)
parm:           driverno:Driver handler major value (int)
  • 1
    the module compile, but cant insert it with insmod, because it has been compiled with 3.10.3 and insered in 3.10.25 kernel version. so I should use 3.10.3 kernel binary – Makhlouf GHARBI May 14 '14 at 19:41
2

the answers of this link [https://stackoverflow.com/questions/20167411/how-to-compile-a-kernel-module-for-raspberry-pi] works fine. You first need kernel headers and the corresponding kernel binary to build the module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.