I’m also learning about this stuff too but I can relate some of my experience with building kernel modules on the TX1. I found that I could build and install kernel modules on the TX1 itself (no need for a cross compiler). Here is how I did it, perhaps someone more experienced then me can help refine this.
Disclaimer: I am using the 24.1 version of L4T so I don’t know if there are differences with the 23.2 and 24.1
I wrote a kernel driver template for myself (I’m sure there are a lot more out there that are much better than this) but I’ll use it for this demo.
https://github.com/CospanDesign/kernel-module
Do the following steps inside a terminal on the TX1
- Run ‘make modules_prepare’ in the kernel headers directory. I think this is important to prepare the build system to link your module with the currently running kernel.
cd /usr/src/linux-headers-3.10.96-tegra
sudo make modules_prepare
- Clone, build and install module
mkdir Projects
cd Projects
git clone https://github.com/CospanDesign/kernel-module.git
cd kernel-module
make
sudo make install
Here is what the entire process looks like
buntu@tegra-ubuntu:~$ cd /usr/src/linux-headers-3.10.96-tegra/
ubuntu@tegra-ubuntu:/usr/src/linux-headers-3.10.96-tegra$ sudo make modules_prepare
[sudo] password for ubuntu:
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
make[1]: `include/generated/mach-types.h' is up to date.
CC scripts/mod/devicetable-offsets.s
GEN scripts/mod/devicetable-offsets.h
HOSTCC scripts/mod/file2alias.o
HOSTLD scripts/mod/modpost
ubuntu@tegra-ubuntu:/usr/src/linux-headers-3.10.96-tegra$ cd ~/
ubuntu@tegra-ubuntu:~$ git clone https://github.com/CospanDesign/kernel-module.git
Cloning into 'kernel-module'...
remote: Counting objects: 77, done.
remote: Total 77 (delta 0), reused 0 (delta 0), pack-reused 77
Unpacking objects: 100% (77/77), done.
Checking connectivity... done.
ubuntu@tegra-ubuntu:~$ cd kernel-module/
ubuntu@tegra-ubuntu:~/kernel-module$ make
make -C /home/ubuntu/kernel-module/src
make[1]: Entering directory `/home/ubuntu/kernel-module/src'
make -C /lib/modules/3.10.96-tegra/build M=/home/ubuntu/kernel-module/src modules
make[2]: Entering directory `/usr/src/linux-headers-3.10.96-tegra'
CC [M] /home/ubuntu/kernel-module/src/mymodule.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/ubuntu/kernel-module/src/mymodule.mod.o
LD [M] /home/ubuntu/kernel-module/src/mymodule.ko
make[2]: Leaving directory `/usr/src/linux-headers-3.10.96-tegra'
make[1]: Leaving directory `/home/ubuntu/kernel-module/src'
ubuntu@tegra-ubuntu:~/kernel-module$ sudo make install
sudo cp rules/61-mymodule.rules /etc/udev/rules.d/
Installing Drivermake -C /home/ubuntu/kernel-module/src install
make[1]: Entering directory `/home/ubuntu/kernel-module/src'
sudo insmod ./mymodule.ko
make[1]: Leaving directory `/home/ubuntu/kernel-module/src'
ubuntu@tegra-ubuntu:~/kernel-module$ lsmod
Module Size Used by
mymodule 2232 0
rfcomm 66118 0
bnep 14864 2
bcmdhd 7453607 0
cfg80211 452766 1 bcmdhd
bluedroid_pm 11452 0
ubuntu@tegra-ubuntu:~/kernel-module$ echo "Removing Module..."
Removing Module...
ubuntu@tegra-ubuntu:~/kernel-module$ sudo make remove
sudo rm /etc/udev/rules.d/61-mymodule.rules
make -C /home/ubuntu/Projects/kernel-module/src remove
make[1]: Entering directory `/home/ubuntu/Projects/kernel-module/src'
sudo rmmod mymodule
make[1]: Leaving directory `/home/ubuntu/Projects/kernel-module/src'
To modify this code to build your own file you should be able to replace the ‘mymodule.c’ file with the source file you received from the manufacturer and then go into the ‘Makefile’ within the ‘src’ directory and change it so that ‘TARGET’ and ‘obj-m’ is pointing to your filename.
As an example if I were to change the module to point to a new file called ‘my_new_module’ the process would look like this:
cd <kernel-module-base>/src
mv mymodule.c my_new_module.c
sed -i 's/mymodule/my_new_module/g' Makefile
cd ..
make clean
make
sudo make install
lsmod
WARNING: Your module might be intended for a future version of the kernel
I originally wrote my driver for the 4.6 version of the kernel and needed to modify it a bit to make it work on the 3.10 currently used by the TX1.
Experienced kernel driver writers will have preprocessor conditional statements to adjust various aspects of the driver depending on what version is available. If the driver is written with this in mind then it should compile cleanly otherwise you can use the link below to help you modify the driver.
http://lxr.free-electrons.com/
It’s very helpful because it will let you isolate a specific version of the kernel. For the TX1 you will need to select the ‘3.10’
I hope you will have an easier time writing a kernel module than I did.
Dave