Even after doing that, I am still missing header files in order to build modules:
beaglebone:~/projects/modules/hello-world# make
gcc -O2 -DMODULE -D__KERNEL__ -W -Wall -Wstrict-prototypes -Wmissing-prototypes -isystem /lib/modules/uname -r/build/include -c -o hello-1.o hello-1.c
hello-1.c:9:0: warning: “MODULE” redefined
:0:0: note: this is the location of the previous definition
hello-1.c:11:0: warning: “KERNEL” redefined
:0:0: note: this is the location of the previous definition
hello-1.c:13:55: fatal error: linux/module.h: No such file or directory
compilation terminated.
make: *** [hello-1.o] Error 1
beaglebone:~/projects/modules/hello-world#
I know that when I build the Angstrom kernel the missing header files are generated, but they seem to be generated in the wrong places. Here’s the folder that I copy:
So, I’m assuming that I’m just copying the header to the wrong locations on the BeagleBone, but the question is:
“What are the CORRECT mapping from the Angstrom build folder to the BeagleBone file system that I need to have a correctly configured build environment?”
Am I even asking the right question, or am I way off base here?
Try with '-I' (capital 'i') instead of '-i' and add each path with its
own '-I' option:
gcc [...] -Isystem -I/lib/modules/`uname -r`/build/include [...]
I am also trying to build simple hello.c kernel module. I am new this environment and have no past experience working on Device Drivers
Below are logs and Makefile.
arm-angstrom-linux-gnueabi-gcc -O2 -DMODULE -D__KERNEL__ -W -Wall -Wstrict-prototypes -Wmissing-prototypes -isystem /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include -isystem /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/arch/arm/include -isystem /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/arch/arm/mach-omap2/include -isystem /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/arch/arm/plat-omap/include -c -o hello-1.o hello-1.c
hello-1.c:9:1: warning: “MODULE” redefined
: warning: this is the location of the previous definition
hello-1.c:11:1: warning: “KERNEL” redefined
: warning: this is the location of the previous definition
In file included from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/arch/arm/include/asm/system.h:165,
from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/arch/arm/include/asm/bitops.h:27,
from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/bitops.h:22,
from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/kernel.h:17,
from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/cache.h:4,
from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/time.h:7,
from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/stat.h:60,
from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/module.h:10,
from hello-1.c:13:
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/arch/arm/include/asm/memory.h: In function ‘virt_to_phys’:
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/arch/arm/include/asm/memory.h:236: error: ‘CONFIG_DRAM_BASEUL’ undeclared (first use in this function)
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/arch/arm/include/asm/memory.h:236: error: (Each undeclared identifier is reported only once
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/arch/arm/include/asm/memory.h:236: error: for each function it appears in.)
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/arch/arm/include/asm/memory.h: In function ‘phys_to_virt’:
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/arch/arm/include/asm/memory.h:241: error: ‘CONFIG_DRAM_BASEUL’ undeclared (first use in this function)
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/arch/arm/include/asm/memory.h: In function ‘virt_to_bus’:
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/arch/arm/include/asm/memory.h:266: error: ‘CONFIG_DRAM_BASEUL’ undeclared (first use in this function)
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/arch/arm/include/asm/memory.h: In function ‘bus_to_virt’:
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/arch/arm/include/asm/memory.h:271: error: ‘CONFIG_DRAM_BASEUL’ undeclared (first use in this function)
In file included from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/time.h:9,
from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/stat.h:60,
from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/module.h:10,
from hello-1.c:13:
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/math64.h: In function ‘div_u64_rem’:
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/math64.h:51: error: ‘LINUX_ARM_ARCH’ undeclared (first use in this function)
In file included from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/notifier.h:14,
from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/memory_hotplug.h:6,
from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/mmzone.h:657,
from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/gfp.h:4,
from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/kmod.h:22,
from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/module.h:13,
from hello-1.c:13:
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/rwsem.h:41:23: error: asm/rwsem.h: No such file or directory
In file included from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/ktime.h:25,
from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/timer.h:5,
from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/workqueue.h:8,
from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/kmod.h:26,
from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/module.h:13,
from hello-1.c:13:
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:39:3: error: #error Invalid value of HZ.
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/jiffies.h:257:31: error: division by zero in #if
In file included from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/sysctl.h:933,
from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/kmod.h:27,
from /home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/module.h:13,
from hello-1.c:13:
/home/ashishd/work_beaglebone/tools/setup-scripts.bkp/setup-scripts.bkp/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/include/linux/rcupdate.h:160:2: error: #error “Unknown RCU implementation specified to kernel configuration”
make: *** [hello-1.o] Error 1
NOTE: You’ll need to create the following symlink to the destination folder for the build to complete:
/lib/modules/3.2.13/build
I was able to compile the following on the BeagleBone after running the following in the kernel source folder to build the required executables (i.e. modpost)
and in both image contains debug folder in /usr/src/ but there is no linux folder. Does it mean that my SD card is not programmed properly?
My BeagleBone boots properly and I can access it from terminal.
The “reset by peer” issue sounds like a server problem to me. I haven’t run into it personally. I’m doing a new build presently and it seems to be running smoothly.
You should add the the following to your list of items to “bitbake” as well.
The BeagleBone images don’t include the kernel source folder at all. You can get some of the headers (and that missing folder) by runnning the following:
opkg install kernel-headers
Then copy the files from the full kernel source tree you built on your machine over those.
You still may have to create that build symlink if your driver or module make file needs it. My wlan module driver did.
Thanks for reply.
After installing kernel-headers I see include directory at /usr/src/linux-3.2.14. But when I linux/modules.h file is missing in that include dir. This is same error which you mentioned in your first post.
Then I copied kernel tree setup-scripts/build/tmp-angstrom_2010_x-eglibc/sysroots/beagleboard/kernel/ to beaglebone and I also got a long list of nonsensical errors ==> How did you fix this? Am I missing anything?
Even this kernel tree doesn’t contain modules.h.
I realized that there are a lot of hello world kernel modules on the web that just don’t work as written. When I was getting the nonsensical errors I think I just had used a bad example source file. I’ve posted the final working module I used a couple of posts back. Are these the files you used?
I’m kind of jumping in midstream here, but this looks a little suspect. If you are building on a host machine and cross compiling for the beagle, the call to ‘uname’ will use the kernel directory of your host, not the kernel directory of your beagle kernel source.
I make my Beagle kernel source directory an environmental variable and reference it in my module Makefile.
Here’s a makefile I wrote. It compiles, but I haven’t installed the module on the target yet.
I’m trying to follow your setup and right now I’m getting an error of:
make[1]: *** No rule to make target kernel/bounds.c', needed by kernel/bounds.s’. Stop.
make: *** [prepare0] Error 2
when I try to “make modules”
I’ve copied the setup-scripts/build/tmp-angstrom_2010_x-eglibc/sysroots/beaglebone/kernel/ to the directory /usr/src/linux-3.2.13 and I’ve created a symlink though I’m not sure if I created it correctly. I don’t think the symlink is the error though. Any ideas?
~Wesley
I’m not sure about the error since I didn’t get the error myself. Just to clarify, you are copying the source from the host machine at:
Ah, so I think I’ve solved my problem. I hadn’t done the bitbake systemd-image that you had said to do in a later post and I also did a MACHINE=beaglebone bitbake virtual/kernel -c compile -f. After that I found a new kernel source that contained the bounds.c file but it was in a different location.
It was at ./build/tmp-angstrom_vYYYY_MM-eglibc/work/beaglebone-angstrom-linux-gnueabi/linux-ti33x-psp-X.X-rXXX-gitreNNN…NN/git/ as mentioned on this site http://www.cemetech.net/forum/viewtopic.php?t=7814.
I’m running the make modules now and it seems to running smoothly!
NOTE: You'll need to create the following symlink to the destination folder
for the build to complete:
/lib/modules/3.2.13/build
I was able to compile the following on the BeagleBone after running the
following in the kernel source folder to build the required executables
(i.e. modpost)
hello.c
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include <linux/module.h> /* Needed by all modules */ #include <linux/kernel.h> /* Needed for KERN_INFO */ #include <linux/init.h> /* Needed for the macros */
I think the idea of building natively could indeed simplify
development for many users, but I will try to document some steps for
this a bit more spelled out, since this has clearly become a
frequently asked question.
There are some obvious potential issues that need to be addressed. For
one, if you are using the default Angstrom image that comes with the
board, my instructions point you to a different toolchain. While I am
not aware of any incompatibilities, there is some potential (that
seems highly unlikely to me). The split between kernel and userspace
makes toolchain incompatibilities seem even less likely to me. I'll
look for experts to weigh in on how much of an issue this could be.
So in case anyone is interested or still having problems I’ve done a little documentation on how I set up the kernel module and also some code on user ioctl interaction with the kernel module here: