diff --git a/lkm/Makefile b/lkm/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..11c4d8b9bfbf3f4a5e4148313bb05fd6b30fc7fb --- /dev/null +++ b/lkm/Makefile @@ -0,0 +1,13 @@ +KDIR ?= ../kernel/linux-3.xx.y +CROSS ?= arm-linux-gnueabi- # use this if you want to cross-compile the module +PWD := $(shell pwd) + +obj-m += mod.o + +all: + make ARCH=arm CROSS_COMPILE=$(CROSS) -C $(KDIR) M=$(PWD) modules # cross-compilation + #make -C $(KDIR) M=$(PWD) modules # non-cross-compilation + +clean: + make -C $(KDIR) M=$(PWD) clean + diff --git a/lkm/README.md b/lkm/README.md new file mode 100644 index 0000000000000000000000000000000000000000..84cdd2914467e75eaa28db3344e18a160af74ffe --- /dev/null +++ b/lkm/README.md @@ -0,0 +1,19 @@ +Minimal template for loadable kernel module (LKM) compilation. +Change `Makefile` to your needs. + +Usage: + +``` +$ make KDIR=<path_to_kernel_out> +$ make KDIR=<path_to_kernel_out> clean +``` + +Copy `mod.ko` to target system. + +On target: + +``` +$ insmod mod.ko +$ lsmod # should show LKM +``` + diff --git a/lkm/mod.c b/lkm/mod.c new file mode 100644 index 0000000000000000000000000000000000000000..64d2ded77422fe4515f8edef52ecef1a65ee48f7 --- /dev/null +++ b/lkm/mod.c @@ -0,0 +1,15 @@ +#include <linux/module.h> +#include <linux/kernel.h> + +static int __init initmodule(void ){ + printk("Hello Kernel!\n"); + return 0; +} + +static void __exit exitmodule(void ){ + return; +} + +module_init( initmodule ); +module_exit( exitmodule ); +