Hello World of linux kernel module. Print a message to kernel's message buffer on the module loaded/unloaded, open()/close(), write()/read().
Kernel Timer Template. Timer handler using kernel timer is periodically executed, and it increments counter every 100ms.
High-resolution Timer Template. Timer handler using high-resolution timer is periodically executed, and it increments counter every 100ms.
I2C Client Driver Template. Example of L3GD20 3-axis gyro sensor.
SPI Client Driver Template. Example of L3GD20 3-axis gyro sensor.
I/O memory remap/unmap Template. Monitor memory of specified physical address and display these values.
Download linux-headers:
$ sudo apt-get install linux-headers-`uname -r`
Make a kernel module:
$ make
Build cross compilation environment (refer to the official documentation for details).
On 32bit Linux:
$ git clone --depth=1 https://github.com/raspberrypi/linux
$ git clone --depth=1 https://github.com/raspberrypi/tools
$ cd linux
$ KERNEL=kernel7
$ make ARCH=arm CROSS_COMPILE=../tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf- bcm2709_defconfig
$ make ARCH=arm CROSS_COMPILE=../tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf- zImage modules dtbs
On 64bit Linux:
$ git clone --depth=1 https://github.com/raspberrypi/linux
$ git clone --depth=1 https://github.com/raspberrypi/tools
$ cd linux
$ KERNEL=kernel7
$ make ARCH=arm CROSS_COMPILE=../tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf- bcm2709_defconfig
$ make ARCH=arm CROSS_COMPILE=../tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf- zImage modules dtbs
Change first and second lines of Makefile.raspberrypi (KPATH, TPATH) according to download path on the previous step.
Make a kernel module:
$ make -f Makefile.raspberrypi
Download and Install Vivado Design Suite HLx Edition.
Add bellow line to your .bashrc
in order to add cross-compiler path (change version according to your Vivado):
export PATH=$PATH:/opt/Xilinx/SDK/2017.1/gnu/arm/lin/bin
Build cross compilation environment.
$ git clone -b master-next https://github.com/DigilentInc/Linux-Digilent-Dev.git
$ cd Linux-Digilent-Dev
$ make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi- xilinx_zynq_defconfig
$ make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi-
Change first line of Makefile.digilent (KPATH) according to download path on the previous step.
Make a kernel module:
$ make -f Makefile.digilent
Load the kernel module:
$ sudo insmod hello.ko
Can see the loaded kernel module:
$ lsmod | grep hello
Can see exported valiable:
$ cat /sys/module/hello/parameters/g_dev_major
$ cat /sys/module/hello/parameters/g_dev_minor
Unload the kernel module:
$ sudo rmmod hello
Load the kernel module:
$ sudo insmod ktimer.ko
Can see the loaded kernel module:
$ lsmod | grep ktimer
Can see exported valiable:
$ cat /sys/module/ktimer/parameters/g_counter
Unload the kernel module:
$ sudo rmmod ktimer
Load the kernel module:
$ sudo insmod hrtimer.ko
Can see the loaded kernel module:
$ lsmod | grep hrtimer
Can see exported valiable:
$ cat /sys/module/hrtimer/parameters/g_counter
Unload the kernel module:
$ sudo rmmod hrtimer
Move the kernel module into kernel directory, and update module information:
$ sudo make install
Connect I2C/SPI device and notify it to I2C/SPI core driver:
$ sudo make connect
Can read raw values of 3-axis gyro sensor:
$ sudo make read
(comma-delimited, X-axis, Y-axis, and Z-axis)
Disconnect I2C/SPI device:
$ sudo make disconnect
Remove the kernel module from the kernel directory, and update module information:
$ sudo make uninstall
Load the kernel module:
$ sudo insmod iomemmap.ko
Specify monitoring physical address and size with HEX-format (addr=0x41200000, size=0x8):
$ sudo echo 41200000,8 > /dev/05.iomemmap0
Can monitor these values:
$ sudo cat /dev/05.iomemmap0
Unload the kernel module:
$ sudo rmmod iomemmap