強烈建議自己重新編譯一次 linux kernel...
詳細步驟請參考 在Raspberr pi2上面編譯 Kernel
做完上面的步驟後.....
接下來寫一個 hello world的程式
hello.c :
#include<linux/module.h>
#include<linux/kernel.h>
int hello_init(void)
{
printk("hello world!\n");
return(0);
}
void hello_exit(void)
{
printk("goodbye world!\n");
}
MODULE_LICENSE("GPL");
module_init(hello_init);
module_exit(hello_exit);
其中init function 裡面只有 print "Hello world"
.....
然後Makefile 的內容如下
obj-m += hello.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
注意.... Makefile 是用 tab 而不是空白鍵.....
make
你就會看到如下的檔案

輸入
sudo insmod ./hello.ko
dmesg
就會看到 "Hello world!"

沒有留言:
張貼留言