I can't load a simple kernel mudule hello.ko with insmod command.
(board: Raspberry Pi Model B 512MB, OS: raspbian)
An Oops message occurs: "Unable to handle kernel NULL pointer dereference at virtual address 00000004".
Can anyone tell me what is the cause and how to solve the problem.
What I tried is as follows:
(1) Download 2013-09-25-wheezy-raspbian.zip from http://downloads.raspberrypi.org/raspbian_latest.
(2) Unzip it and write the image to a SD card with Win32DiskImager.exe.
(3) Insert the SD card into RaspberryPi (only a USB keyboard, HDMI and a LAN cable are connected to that), then power on it.
(4) Select <Finish> raspi-config without setting anything up.
(5) Get kernel source with get-kernel-source.sh:
Code: Select all
pi@raspberrypi ~$ wget https://raw.github.com/gkaindl/ambi-tv/master/misc/get-kernel-source.sh
pi@raspberrypi ~$ chmod a+x get-kernel-source.sh
pi@raspberrypi ~$ sudo -i
root@raspberrypi:~# cd /home/pi/
root@raspberrypi:/home/pi# ./get-kernel-source.sh > get-kernel-source.mylog 2>&1
root@raspberrypi:/home/pi# echo $?
0
Code: Select all
Installing kernel source for revision d4f5315cfac4e...
--2013-11-08 06:28:25-- https://raw.github.com/raspberrypi/firmware/d4f5315cfac4e/extra/git_hash
Resolving raw.github.com (raw.github.com)... 103.245.222.133
Connecting to raw.github.com (raw.github.com)|103.245.222.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 41 [text/plain]
Saving to: `rasp-tmp/git_hash'
0K 100% 60.8K=0.001s
2013-11-08 06:28:31 (60.8 KB/s) - `rasp-tmp/git_hash' saved [41/41]
--2013-11-08 06:28:31-- https://raw.github.com/raspberrypi/firmware/d4f5315cfac4e/extra/Module.symvers
Resolving raw.github.com (raw.github.com)... 103.245.222.133
Connecting to raw.github.com (raw.github.com)|103.245.222.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 450335 (440K) [text/plain]
Saving to: `rasp-tmp/Module.symvers'
0K .......... .......... .......... .......... .......... 11% 1.27M 0s
50K .......... .......... .......... .......... .......... 22% 1.91M 0s
100K .......... .......... .......... .......... .......... 34% 1.55M 0s
150K .......... .......... .......... .......... .......... 45% 3.17M 0s
200K .......... .......... .......... .......... .......... 56% 2.34M 0s
250K .......... .......... .......... .......... .......... 68% 2.88M 0s
300K .......... .......... .......... .......... .......... 79% 3.26M 0s
350K .......... .......... .......... .......... .......... 90% 2.83M 0s
400K .......... .......... .......... ......... 100% 3.84M=0.2s
2013-11-08 06:28:37 (2.25 MB/s) - `rasp-tmp/Module.symvers' saved [450335/450335]
--2013-11-08 06:28:37-- https://github.com/raspberrypi/linux/tarball/1587f775d0a3c437485262ba951afc5e30be69fa
Resolving github.com (github.com)... 192.30.252.129
Connecting to github.com (github.com)|192.30.252.129|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/raspberrypi/linux/legacy.tar.gz/1587f775d0a3c437485262ba951afc5e30be69fa [following]
--2013-11-08 06:28:43-- https://codeload.github.com/raspberrypi/linux/legacy.tar.gz/1587f775d0a3c437485262ba951afc5e30be69fa
Resolving codeload.github.com (codeload.github.com)... 192.30.252.146
Connecting to codeload.github.com (codeload.github.com)|192.30.252.146|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 106487882 (102M) [application/x-gzip]
Saving to: `rasp-tmp/linux.tar.gz'
0K .......... .......... .......... .......... .......... 0% 131K 13m13s
50K .......... .......... .......... .......... .......... 0% 261K 9m55s
100K .......... .......... .......... .......... .......... 0% 263K 8m48s
(...... Omit here ......)
103850K .......... .......... .......... .......... .......... 99% 4.29M 0s
103900K .......... .......... .......... .......... .......... 99% 4.25M 0s
103950K .......... .......... .......... .......... .. 100% 3.68M=53s
2013-11-08 06:29:45 (1.91 MB/s) - `rasp-tmp/linux.tar.gz' saved [106487882/106487882]
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
scripts/kconfig/conf --oldconfig Kconfig
#
# configuration written to .config
#
scripts/kconfig/conf --silentoldconfig Kconfig
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/emergency-restart.h
WRAP arch/arm/include/generated/asm/errno.h
WRAP arch/arm/include/generated/asm/ioctl.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/percpu.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/siginfo.h
WRAP arch/arm/include/generated/asm/sizes.h
CHK include/linux/version.h
UPD include/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
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
Code: Select all
pi@raspberrypi ~/hello$ make V=1 > compile-hello.mylog 2>&1
pi@raspberrypi ~/hello$ echo $?
0
Code: Select all
make -C /lib/modules/3.6.11+/build M=/home/pi/hello modules
make[1]: Entering directory `/usr/src/linux-source-3.6.11+'
test -e include/generated/autoconf.h -a -e include/config/auto.conf || ( \
echo >&2; \
echo >&2 " ERROR: Kernel configuration is invalid."; \
echo >&2 " include/generated/autoconf.h or include/config/auto.conf are missing.";\
echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \
echo >&2 ; \
/bin/false)
mkdir -p /home/pi/hello/.tmp_versions ; rm -f /home/pi/hello/.tmp_versions/*
make -f scripts/Makefile.build obj=/home/pi/hello
make[2]: Warning: File `include/config/auto.conf' has modification time 3.7e+06 s in the future
gcc -Wp,-MD,/home/pi/hello/.hello.o.d -nostdinc -isystem /usr/lib/gcc/arm-linux-gnueabihf/4.6/include -I/usr/src/linux-source-3.6.11+/arch/arm/include -Iarch/arm/include/generated -Iinclude -include /usr/src/linux-source-3.6.11+/include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-bcm2708/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -fno-delete-null-pointer-checks -O2 -marm -fno-dwarf2-cfi-asm -fstack-protector -mabi=aapcs-linux -mno-thumb-interwork -funwind-tables -D__LINUX_ARM_ARCH__=6 -march=armv6 -mtune=arm1136j-s -msoft-float -Uarm -Wframe-larger-than=1024 -Wno-unused-but-set-variable -fomit-frame-pointer -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(hello)" -D"KBUILD_MODNAME=KBUILD_STR(hello)" -c -o /home/pi/hello/.tmp_hello.o /home/pi/hello/hello.c
(cat /dev/null; echo kernel//home/pi/hello/hello.ko;) > /home/pi/hello/modules.order
make[2]: warning: Clock skew detected. Your build may be incomplete.
make -f /usr/src/linux-source-3.6.11+/scripts/Makefile.modpost
make[2]: Warning: File `include/config/auto.conf' has modification time 3.7e+06 s in the future
scripts/mod/modpost -m -a -i /usr/src/linux-source-3.6.11+/Module.symvers -I /home/pi/hello/Module.symvers -o /home/pi/hello/Module.symvers -S -w -s
gcc -Wp,-MD,/home/pi/hello/.hello.mod.o.d -nostdinc -isystem /usr/lib/gcc/arm-linux-gnueabihf/4.6/include -I/usr/src/linux-source-3.6.11+/arch/arm/include -Iarch/arm/include/generated -Iinclude -include /usr/src/linux-source-3.6.11+/include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-bcm2708/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -fno-delete-null-pointer-checks -O2 -marm -fno-dwarf2-cfi-asm -fstack-protector -mabi=aapcs-linux -mno-thumb-interwork -funwind-tables -D__LINUX_ARM_ARCH__=6 -march=armv6 -mtune=arm1136j-s -msoft-float -Uarm -Wframe-larger-than=1024 -Wno-unused-but-set-variable -fomit-frame-pointer -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(hello.mod)" -D"KBUILD_MODNAME=KBUILD_STR(hello)" -DMODULE -c -o /home/pi/hello/hello.mod.o /home/pi/hello/hello.mod.c
ld -EL -r -T /usr/src/linux-source-3.6.11+/scripts/module-common.lds --build-id -o /home/pi/hello/hello.ko /home/pi/hello/hello.o /home/pi/hello/hello.mod.o
make[2]: warning: Clock skew detected. Your build may be incomplete.
make[1]: Leaving directory `/usr/src/linux-source-3.6.11+'
Code: Select all
pi@raspberrypi ~$ sudo -i
root@raspberrypi:~# cd /home/pi/hello/
root@raspberrypi:/home/pi/hello# insmod hello.ko
But /dev/ttyAMA0 (UART) is still working and kdb is running on the serial console via UART cable connected to Connector P1 as below:
Code: Select all
root@raspberrypi:/home/pi/hello# insmod hello.ko
[ 400.954687] [hello]: hello_load()
[ 400.959430] Unable to handle kernel NULL pointer dereference at virtual address 00000004
[ 400.970310] pgd = d9e4c000
[ 400.974421] [00000004] *pgd=00000000
[ 400.979342] Internal error: Oops: 5 [#1] PREEMPT ARM
Entering kdb (current=0xd9e86e40, pid 2685) Oops: (null)
due to oops @ 0xc005ce34
Pid: 2685, comm: insmod
CPU: 0 Tainted: P O (3.6.11+ #538)
PC is at module_put+0x28/0x6c
LR is at sys_init_module+0x428/0x19d0
pc : [<c005ce34>] lr : [<c005e08c>] psr: a0000013
sp : d9ea5ef0 ip : 00000000 fp : 000000ee
r10: 00000024 r9 : bf0700cc r8 : 0000001c
r7 : 00000001 r6 : daae9c40 r5 : bf070084 r4 : d9ea4000
r3 : 00000000 r2 : 00000000 r1 : 00000001 r0 : bf070084
Flags: NzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user
Control: 00c5387d Table: 19e4c008 DAC: 00000015
[<c0013b60>] (unwind_backtrace+0x0/0xf0) from [<c0072fe0>] (kdb_dumpregs+0x28/0x50)
[<c0072fe0>] (kdb_dumpregs+0x28/0x50) from [<c0075364>] (kdb_main_loop+0x3a8/0x6fc)
[<c0075364>] (kdb_main_loop+0x3a8/0x6fc) from [<c0077a48>] (kdb_stub+0x154/0x380)
[<c0077a48>] (kdb_stub+0x154/0x380) from [<c006eb7c>] (kgdb_handle_exception+0x1f8/0x668)
[<c006eb7c>] (kgdb_handle_exception+0x1f8/0x668) from [<c00132e0>] (kgdb_notify+0x24/0x40)
[<c00132e0>] (kgdb_notify+0x24/0x40) from [<c03a32d4>] (notifier_call_chain+0x44/0x84)
[<c03a32d4>] (notifier_call_chain+0x44/0x84) from [<c03a334c>] (__atomic_notifier_call_chain+0x38/0x4c)
[<c03a334c>] (__atomic_notifier_call_chain+0x38/0x4c) from [<c03a3378>] (atomic_notifier_call_chain+0x18/0x20)
[<c03a3378>] (atomic_notifier_call_chain+0x18/0x20) from [<c03a33b8>] (notify_die+0x38/0x44)
[<c03a33b8>] (notify_die+0x38/0x44) from [<c001102c>] (die+0xc4/0x39c)
[<c001102c>] (die+0xc4/0x39c) from [<c039b6b8>] (__do_kernel_fault.part.9+0x54/0x74)
[<c039b6b8>] (__do_kernel_fault.part.9+0x54/0x74) from [<c03a2ff4>] (do_page_fault+0x1d8/0x3cc)
[<c03a2ff4>] (do_page_fault+0x1d8/0x3cc) from [<c000832c>] (do_DataAbort+0x34/0x98)
[<c000832c>] (do_DataAbort+0x34/0x98) from [<c03a17f8>] (__dabt_svc+0x38/0x60)
Exception stack(0xd9ea5ea8 to 0xd9ea5ef0)
5ea0: bf070084 00000001 00000000 00000000 d9ea4000 bf070084
5ec0: daae9c40 00000001 0000001c bf0700cc 00000024 000000ee 00000000 d9ea5ef0
5ee0: c005e08c c005ce34 a0000013 ffffffff
[<c03a17f8>] (__dabt_svc+0x38/0x60) from [<c005ce34>] (module_put+0x28/0x6c)
[<c005ce34>] (module_put+0x28/0x6c) from [<c005e08c>] (sys_init_module+0x428/0x19d0)
[<c005e08c>] (sys_init_module+0x428/0x19d0) from [<c000da60>] (ret_fast_syscall+0x0/0x30)
more>
kdb>
kdb>
kdb>
kdb>
Thanks for any hint.
source code here:
<1> hello.c:
Code: Select all
#include <linux/kernel.h>
#include <linux/module.h>
/* on driver load */
static int __init hello_load(void)
{
printk(KERN_CRIT "[hello]: %s()\n", __func__);
return 0;
}
/* on driver unload */
static void __exit hello_unload(void)
{
printk(KERN_CRIT "[hello]: %s()\n", __func__);
}
module_init(hello_load);
module_exit(hello_unload);
Code: Select all
obj-m := hello.o
KDIR := /lib/modules/$(shell uname -r)/build
default:
$(MAKE) -C $(KDIR) M=$(shell pwd) modules
clean:
$(MAKE) -C $(KDIR) M=$(shell pwd) clean
rm -f TAGS Module.symvers Module.markers modules.order