This is a simple example of a kernel driver.
You can compile using:
make ARCH=arm CROSS_COMPILE=<compiler_path>/arm-linux-gnueabihf- -C <linux_path> M=$PWD modulesor using the custom Makefile, you can also compile for your host machine using:
make hostNote you could need to install kernel-devel package for your host machine, i.e:
sudo dnf install kernel-devel.x86_64You can see some information of compiled driver using:
modinfo main.ko<compiler_path>/arm-linux-gnueabihf-objdump -h main.ko- Create a folder inside linux repository, in drivers/char/<your_name>, for exaple drivers/char/foo.
- Copy main.c inside this folder.
- Copy Kconfig inside this folder.
- Create a Makefile with the following line:
obj-$(CONFIG_CUSTOM_HELLOWORLD) += main.o - Add the local Kconfig entry to upper level Kconfig:
source "drivers/char/foo/Kconfig" - Modify the upper Makefile (in drivers/char/) adding:
obj-y +=.my_c_dev/
Then you can access to this kernel module executing:
make ARCH=arm menuconfigThe new module will be in Device Drivers ---> Character devices ---> maherme custom modules.