kernel 4.4.12 外部模組Makefile 指令碼編寫

weixin_34119545發表於2016-12-26

kernel 4.4.12 最簡單module的編譯


上一篇部落格上面有一個最簡單的模組原始碼,今天就上一個Makefile,執行make 就可以編譯一個外部的模組.

vim Makefile
這個是我寫好的Makefile
CHEN_KERNEL 指向的是我kernel4.4.12的目錄。                                                                        
obj-m += chen_test.o                                                            
                                                                            
export ARCH=arm                                                                 
export CROSS_COMPILE=arm-linux-gnueabihf-                                       
                                                                            
                                                                            
all :                                                                           
    make -C     $(CHEN_KERNEL)    modules  M=`pwd` modules                      
clean:                                                                          
    make -C     $(CHEN_KERNEL)    modules  M=`pwd` clean                        
    rm -rf modules.*                               


這裡要注意的是要指定ARCH 以及交叉編譯工具,M=pwd 也要注意。
插入模組就用insmod 就行了。
insmod chen_test.ko
刪除模組rmmod chen_test.ko

相關文章