hello.c檔案:
#include #includemakefile檔案:static
int hello_init(void
)static
void hello_exit(void
)module_init(hello_init);
module_exit(hello_exit);
module_author(
"vedic ");
module_license(
"dual bsd/gpl
");
obj-m +=template.o追加:上面的makefile其實寫得不嚴謹!首先make命令後處理的makefile是kernel下的makefile, 檢視內容得知裡面除了用cc ld ar 還會用其他的template-objs:=hello.o
kdir:=/home/fuzk/project/prolin/firmware_4/build_dir/linux-sc9820_sc9820_pax/linux-3.10.65
compiler=/opt/toolchain/arm-2012.03/bin/arm-none-linux-gnueabi-gcc
ld_path=/opt/toolchain/arm-2012.03/bin/arm-none-linux-gnueabi-ld
ar_path=/opt/toolchain/arm-2012.03/bin/arm-none-linux-gnueabi-ar
arch_type=arm
#ccflags新ggc要求改用ccflags-y, -i標頭檔案必須是絕對路徑 像-i./include壓根找不到 巨集定義用-d緊跟著巨集名字即可不用空格
#ccflags-y += -mfloat-abi=softfp -ixx/xx/include -d***_rrr
#ldflags-y += -l/opt/toolchain/arm-2012.03/lib/gcc/arm-none-linux-gnueabi/4.6.3 -lgcc -static
all:
make cc=$(compiler) ld=$(ld_path) ar=$(ar_path) arch=$(arch_type) -c $(kdir) m=$(pwd) modules
clean:
make cc=$(compiler) ld=$(ld_path) arch=$(arch_type) -c $(kdir) m=$(pwd) clean
所以我們要做的是賦值cross_compile變數才對
obj-m +=template.otemplate-objs:=hello.o
kdir:=/home/fuzk/project/prolin/firmware_4/build_dir/linux-sc9820_sc9820_pax/linux-3.10.65
compile=/opt/toolchain/arm-2012.03/bin/arm-none-linux-gnueabi-arch_type=arm
#ccflags新ggc要求改用ccflags-y, -i標頭檔案必須是絕對路徑 像-i./include壓根找不到 巨集定義用-d緊跟著巨集名字即可不用空格
#ccflags-y += -mfloat-abi=softfp -ixx/xx/include -d***_rrr
#ldflags-y += -l/opt/toolchain/arm-2012.03/lib/gcc/arm-none-linux-gnueabi/4.6.3 -lgcc -static
all:
make cross_compile
=$(compile) arch=$(arch_type) -c $(kdir) m=$(pwd) modules
clean:
make cross_compile
=$(compile) arch=$(arch_type) -c $(kdir) m=$(pwd) clean
編譯Linux驅動模組
xz d linux 5.7.8.tar.xz tar xf linux 5.7.8.tar cd linux 5.7.8 make menuconfig 執行make menuconfig 報錯 error 1 unable to find the ncurses package.install ...
Linux核心驅動 模組編譯技巧
export arch arm export cross compile usr arm arm linux export subdirs dir 有時候我們無法獲取裝置的核心原始碼或者獲得的原始碼與裝置中的核心版本不同,此時如果安裝核心模組會提示exec format error錯誤,同時會在dm...
驅動模組編譯Makefile
驅動模組編譯makefile如下 1 使用不同的開發板核心時,一定要修改kern dir 2 kern dir中的核心要事先配置 編譯,為了能編譯核心,要先設定下列環境變數 2.1 arch,比如 export arch arm64 2.2 cross compile,比如 export cross...