Comments on: Chapter 16: Kernel Programming https://www.exploringrpi.com Companion Site for the book Exploring Raspberry Pi Fri, 27 Apr 2018 02:56:25 +0000 hourly 1 https://wordpress.org/?v=5.0.1 By: Alexander Jaworowski https://www.exploringrpi.com/chapter16/#comment-167 Wed, 08 Feb 2017 06:57:18 +0000 https://www.exploringrpi.com/?page_id=525#comment-167 Checkout rpi-source from https://github.com/notro/rpi-source/wiki. It’s makes it super easy to install the linux headers on rpi 1 and 2.

]]>
By: Alexander Jaworowski https://www.exploringrpi.com/chapter16/#comment-151 Thu, 12 Jan 2017 11:58:18 +0000 https://www.exploringrpi.com/?page_id=525#comment-151 Checked with modinfo
pi@raspberrypi ~/exploringrpi/chp16/hello $ modinfo hello.ko
filename: /home/pi/exploringrpi/chp16/hello/hello.ko
version: 0.1
description: A simple Linux LKM for the RPi.
author: Derek Molloy
license: GPL
srcversion: 579146BC11D4158697739F2
depends:
vermagic: 4.1.21 mod_unload modversions ARMv6
parm: name:The name to display in /var/log/kern.log (charp)

Vermagic info is not the same as uname -r (4.1.19+) – can that be the cause for the error message from insmod?

Have tried to build hello.c with other Module.symvers found at https://github.com/raspberrypi/firmware/commits/master/extra/Module.symvers. Tried both 4.1.19 and 4.1.21. However, for both of these, make returns the following error

pi@raspberrypi ~/exploringrpi/chp16/hello $ make
make -C /lib/modules/4.1.19+/build/ M=/home/pi/exploringrpi/chp16/hello modules
make[1]: Entering directory ‘/usr/src/raspberrypi-linux-ff45bc0’
CC [M] /home/pi/exploringrpi/chp16/hello/hello.o
Building modules, stage 2.
MODPOST 1 modules
FATAL: parse error in symbol dump file
scripts/Makefile.modpost:90: recipe for target ‘__modpost’ failed
make[2]: *** [__modpost] Error 1
Makefile:1387: recipe for target ‘modules’ failed
make[1]: *** [modules] Error 2
make[1]: Leaving directory ‘/usr/src/raspberrypi-linux-ff45bc0’
Makefile:4: recipe for target ‘all’ failed
make: *** [all] Error 2

]]>
By: Alexander Jaworowski https://www.exploringrpi.com/chapter16/#comment-149 Thu, 12 Jan 2017 10:33:03 +0000 https://www.exploringrpi.com/?page_id=525#comment-149 Another try. Started with a new wheezy image, then update and upgrade, resulting in (uname -r) 4.1.19+.
Followed the instructions in ch16 for rpi (instead of rpi2/3). Everything went smooth until insmod

root@raspberrypi:/home/pi/exploringrpi/chp16/hello# insmod hello.ko
Error: could not insert module hello.ko: Invalid module format

pi@raspberrypi ~ $ tail /var/log/messages
Jan 12 10:17:28 raspberrypi kernel: [ 2723.011383] hello: disagrees about version of symbol module_layout

Suggestions for how to proceed?

]]>
By: Alexander Jaworowski https://www.exploringrpi.com/chapter16/#comment-147 Thu, 12 Jan 2017 07:59:10 +0000 https://www.exploringrpi.com/?page_id=525#comment-147 Got a segmentation fault when trying to insert the module hello.ko. Any suggestions for how to debug the problem?

root@ba0025A0011:/home/pi/exploringpi# insmod hello.ko

Message from syslogd@ba0025A0011 at Jan 12 07:52:43 …
kernel:[ 163.531914] Internal error: Oops: 5 [#1] ARM

Message from syslogd@ba0025A0011 at Jan 12 07:52:43 …
kernel:[ 163.591118] Process insmod (pid: 2668, stack limit = 0xd847a188)

Message from syslogd@ba0025A0011 at Jan 12 07:52:43 …
kernel:[ 163.594115] Stack: (0xd847be88 to 0xd847c000)

]]>
By: Alexander Jaworowski https://www.exploringrpi.com/chapter16/#comment-145 Thu, 12 Jan 2017 07:44:09 +0000 https://www.exploringrpi.com/?page_id=525#comment-145 First build of on rpi. In the book: “Finally, you can build the LKM with a call to make. Do not use sudo make;…”. Got error when running as pi user:

pi@ba0025A0011 ~/exploringpi $ make
make -C /lib/modules/4.4.41+/build/ M=/home/pi/exploringpi modules
make[1]: *** /lib/modules/4.4.41+/build/: Permission denied. Stop.
Makefile:4: recipe for target ‘all’ failed
make: *** [all] Error 2

Instead, I returned to root (sudo bash) in order to compile the LKM,

pi@ba0025A0011 ~/exploringpi $ sudo bash
root@ba0025A0011:/home/pi/exploringpi# make
make -C /lib/modules/4.4.41+/build/ M=/home/pi/exploringpi modules
make[1]: Entering directory ‘/usr/src/raspberrypi-linux-4897c5c’
CC [M] /home/pi/exploringpi/hello.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/pi/exploringpi/hello.mod.o
LD [M] /home/pi/exploringpi/hello.ko
make[1]: Leaving directory ‘/usr/src/raspberrypi-linux-4897c5c’

]]>