USB转串口驱动开发
- [1. Makefile 编译流程分析](#1. Makefile 编译流程分析)
-
- [1.1 外部驱动目录的 Makefile](#1.1 外部驱动目录的 Makefile)
- [1.2 外部驱动目录的 Makefile --- 编译时打印信息](#1.2 外部驱动目录的 Makefile --- 编译时打印信息)
- [1.3 外部驱动目录的 Makefile --- 编译流程](#1.3 外部驱动目录的 Makefile --- 编译流程)
1. Makefile 编译流程分析
1.1 外部驱动目录的 Makefile
cusbserial-y := usb-serial.o generic.o bus.o obj-m = cp210x.o obj-m += usbserial.o obj-m += option.o obj-m += usb_wwan.o obj-m += zte_ev.o KVERSION = $(shell uname -r) KBUILD=/opt/raspberry-pi/linux-rpi-4.1.y ARCH_ROOT=arm CROSS_COMPILER_ROOT=/opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux->gnueabihf-raspbian/bin/arm-linux-gnueabihf- all: make -C $(KBUILD) ARCH=$(ARCH_ROOT) CROSS_COMPILE=$(CROSS_COMPILER_ROOT) M=$(shell pwd) modules V=1 cp ./*.ko ./App/ clean: make -C $(KBUILD) ARCH=$(ARCH_ROOT) CROSS_COMPILE=$(CROSS_COMPILER_ROOT) M=$(shell pwd) clean
-C $(KBUILD):进入内核源码树目录(切换到内核顶层 Makefile),使用其 Kbuild 系统M=$(shell pwd):Kbuild 在 M=$(pwd) 目录下查找 Kbuild 或 Makefile,读取 obj-m 等变量modules:要构建的目标V=1:输出详细的编译命令(verbose),便于调试obj-y:编译进内核(built-in)的目标文件obj-m:编译成可加载模块
1.2 外部驱动目录的 Makefile --- 编译时打印信息
c1 xd@xd:/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer$ make 2 make -C /opt/raspberry-pi/linux-rpi-4.1.y ARCH=arm CROSS_COMPILE=/opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf- M=/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer modules V=1 3 make[1]: 进入目录"/opt/raspberry-pi/linux-rpi-4.1.y" 4 test -e include/generated/autoconf.h -a -e include/config/auto.conf || ( \ 5 echo >&2; \ 6 echo >&2 " ERROR: Kernel configuration is invalid."; \ 7 echo >&2 " include/generated/autoconf.h or include/config/auto.conf are missing.";\ 8 echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \ 9 echo >&2 ; \ 10 /bin/false) 11 mkdir -p /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.tmp_versions ; rm -f /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.tmp_versions/* 12 13 WARNING: Symbol version dump ./Module.symvers 14 is missing; modules will have no dependencies and modversions. 15 16 make -f ./scripts/Makefile.build obj=/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer 17 /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc -Wp,-MD,/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.cp210x.o.d -nostdinc -isystem /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/include -I./arch/arm/include -Iarch/arm/include/generated/uapi -Iarch/arm/include/generated -Iinclude -I./arch/arm/include/uapi -Iarch/arm/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-bcm2709/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-dwarf2-cfi-asm -fno-omit-frame-pointer -mapcs -mno-sched-prolog -fno-ipa-sra -mabi=aapcs-linux -mno-thumb-interwork -mfpu=vfp -funwind-tables -marm -D__LINUX_ARM_ARCH__=7 -march=armv7-a -msoft-float -Uarm -fno-delete-null-pointer-checks -O2 --param=allow-store-data-races=0 -Wframe-larger-than=1024 -fno-stack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -pg -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -DCC_HAVE_ASM_GOTO -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(cp210x)" -D"KBUILD_MODNAME=KBUILD_STR(cp210x)" -c -o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.tmp_cp210x.o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/cp210x.c 18 if [ "-pg" = "-pg" ]; then if [ /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/cp210x.o != "scripts/mod/empty.o" ]; then ./scripts/recordmcount "/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/cp210x.o"; fi; fi; 19 /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc -Wp,-MD,/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.usb-serial.o.d -nostdinc -isystem /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/include -I./arch/arm/include -Iarch/arm/include/generated/uapi -Iarch/arm/include/generated -Iinclude -I./arch/arm/include/uapi -Iarch/arm/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-bcm2709/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-dwarf2-cfi-asm -fno-omit-frame-pointer -mapcs -mno-sched-prolog -fno-ipa-sra -mabi=aapcs-linux -mno-thumb-interwork -mfpu=vfp -funwind-tables -marm -D__LINUX_ARM_ARCH__=7 -march=armv7-a -msoft-float -Uarm -fno-delete-null-pointer-checks -O2 --param=allow-store-data-races=0 -Wframe-larger-than=1024 -fno-stack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -pg -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -DCC_HAVE_ASM_GOTO -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(usb_serial)" -D"KBUILD_MODNAME=KBUILD_STR(usbserial)" -c -o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.tmp_usb-serial.o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/usb-serial.c 20 if [ "-pg" = "-pg" ]; then if [ /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/usb-serial.o != "scripts/mod/empty.o" ]; then ./scripts/recordmcount "/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/usb-serial.o"; fi; fi; 21 /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc -Wp,-MD,/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.generic.o.d -nostdinc -isystem /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/include -I./arch/arm/include -Iarch/arm/include/generated/uapi -Iarch/arm/include/generated -Iinclude -I./arch/arm/include/uapi -Iarch/arm/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-bcm2709/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-dwarf2-cfi-asm -fno-omit-frame-pointer -mapcs -mno-sched-prolog -fno-ipa-sra -mabi=aapcs-linux -mno-thumb-interwork -mfpu=vfp -funwind-tables -marm -D__LINUX_ARM_ARCH__=7 -march=armv7-a -msoft-float -Uarm -fno-delete-null-pointer-checks -O2 --param=allow-store-data-races=0 -Wframe-larger-than=1024 -fno-stack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -pg -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -DCC_HAVE_ASM_GOTO -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(generic)" -D"KBUILD_MODNAME=KBUILD_STR(usbserial)" -c -o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.tmp_generic.o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/generic.c 22 if [ "-pg" = "-pg" ]; then if [ /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/generic.o != "scripts/mod/empty.o" ]; then ./scripts/recordmcount "/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/generic.o"; fi; fi; 23 /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc -Wp,-MD,/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.bus.o.d -nostdinc -isystem /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/include -I./arch/arm/include -Iarch/arm/include/generated/uapi -Iarch/arm/include/generated -Iinclude -I./arch/arm/include/uapi -Iarch/arm/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-bcm2709/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-dwarf2-cfi-asm -fno-omit-frame-pointer -mapcs -mno-sched-prolog -fno-ipa-sra -mabi=aapcs-linux -mno-thumb-interwork -mfpu=vfp -funwind-tables -marm -D__LINUX_ARM_ARCH__=7 -march=armv7-a -msoft-float -Uarm -fno-delete-null-pointer-checks -O2 --param=allow-store-data-races=0 -Wframe-larger-than=1024 -fno-stack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -pg -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -DCC_HAVE_ASM_GOTO -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(bus)" -D"KBUILD_MODNAME=KBUILD_STR(usbserial)" -c -o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.tmp_bus.o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/bus.c 24 if [ "-pg" = "-pg" ]; then if [ /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/bus.o != "scripts/mod/empty.o" ]; then ./scripts/recordmcount "/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/bus.o"; fi; fi; 25 /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ld -EL -r -o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/usbserial.o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/usb-serial.o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/generic.o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/bus.o 26 /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc -Wp,-MD,/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.option.o.d -nostdinc -isystem /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/include -I./arch/arm/include -Iarch/arm/include/generated/uapi -Iarch/arm/include/generated -Iinclude -I./arch/arm/include/uapi -Iarch/arm/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-bcm2709/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-dwarf2-cfi-asm -fno-omit-frame-pointer -mapcs -mno-sched-prolog -fno-ipa-sra -mabi=aapcs-linux -mno-thumb-interwork -mfpu=vfp -funwind-tables -marm -D__LINUX_ARM_ARCH__=7 -march=armv7-a -msoft-float -Uarm -fno-delete-null-pointer-checks -O2 --param=allow-store-data-races=0 -Wframe-larger-than=1024 -fno-stack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -pg -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -DCC_HAVE_ASM_GOTO -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(option)" -D"KBUILD_MODNAME=KBUILD_STR(option)" -c -o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.tmp_option.o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/option.c 27 if [ "-pg" = "-pg" ]; then if [ /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/option.o != "scripts/mod/empty.o" ]; then ./scripts/recordmcount "/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/option.o"; fi; fi; 28 /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc -Wp,-MD,/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.usb_wwan.o.d -nostdinc -isystem /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/include -I./arch/arm/include -Iarch/arm/include/generated/uapi -Iarch/arm/include/generated -Iinclude -I./arch/arm/include/uapi -Iarch/arm/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-bcm2709/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-dwarf2-cfi-asm -fno-omit-frame-pointer -mapcs -mno-sched-prolog -fno-ipa-sra -mabi=aapcs-linux -mno-thumb-interwork -mfpu=vfp -funwind-tables -marm -D__LINUX_ARM_ARCH__=7 -march=armv7-a -msoft-float -Uarm -fno-delete-null-pointer-checks -O2 --param=allow-store-data-races=0 -Wframe-larger-than=1024 -fno-stack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -pg -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -DCC_HAVE_ASM_GOTO -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(usb_wwan)" -D"KBUILD_MODNAME=KBUILD_STR(usb_wwan)" -c -o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.tmp_usb_wwan.o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/usb_wwan.c 29 if [ "-pg" = "-pg" ]; then if [ /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/usb_wwan.o != "scripts/mod/empty.o" ]; then ./scripts/recordmcount "/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/usb_wwan.o"; fi; fi; 30 /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc -Wp,-MD,/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.zte_ev.o.d -nostdinc -isystem /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/include -I./arch/arm/include -Iarch/arm/include/generated/uapi -Iarch/arm/include/generated -Iinclude -I./arch/arm/include/uapi -Iarch/arm/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-bcm2709/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-dwarf2-cfi-asm -fno-omit-frame-pointer -mapcs -mno-sched-prolog -fno-ipa-sra -mabi=aapcs-linux -mno-thumb-interwork -mfpu=vfp -funwind-tables -marm -D__LINUX_ARM_ARCH__=7 -march=armv7-a -msoft-float -Uarm -fno-delete-null-pointer-checks -O2 --param=allow-store-data-races=0 -Wframe-larger-than=1024 -fno-stack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -pg -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -DCC_HAVE_ASM_GOTO -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(zte_ev)" -D"KBUILD_MODNAME=KBUILD_STR(zte_ev)" -c -o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.tmp_zte_ev.o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/zte_ev.c 31 if [ "-pg" = "-pg" ]; then if [ /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/zte_ev.o != "scripts/mod/empty.o" ]; then ./scripts/recordmcount "/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/zte_ev.o"; fi; fi; 32 (cat /dev/null; echo kernel//mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/cp210x.ko; echo kernel//mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/usbserial.ko; echo kernel//mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/option.ko; echo kernel//mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/usb_wwan.ko; echo kernel//mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/zte_ev.ko;) > /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/modules.order 33 make -f ./scripts/Makefile.modpost 34 find /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.tmp_versions -name '*.mod' | xargs -r grep -h '\.ko$' | sort -u | sed 's/\.ko$/.o/' | scripts/mod/modpost -m -a -i ./Module.symvers -I /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/Module.symvers -o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/Module.symvers -S -w -s -T - 35 /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc -Wp,-MD,/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.cp210x.mod.o.d -nostdinc -isystem /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/include -I./arch/arm/include -Iarch/arm/include/generated/uapi -Iarch/arm/include/generated -Iinclude -I./arch/arm/include/uapi -Iarch/arm/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-bcm2709/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-dwarf2-cfi-asm -fno-omit-frame-pointer -mapcs -mno-sched-prolog -fno-ipa-sra -mabi=aapcs-linux -mno-thumb-interwork -mfpu=vfp -funwind-tables -marm -D__LINUX_ARM_ARCH__=7 -march=armv7-a -msoft-float -Uarm -fno-delete-null-pointer-checks -O2 --param=allow-store-data-races=0 -Wframe-larger-than=1024 -fno-stack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -pg -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -DCC_HAVE_ASM_GOTO -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(cp210x.mod)" -D"KBUILD_MODNAME=KBUILD_STR(cp210x)" -DMODULE -c -o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/cp210x.mod.o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/cp210x.mod.c 36 /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ld -EL -r -T ./scripts/module-common.lds --build-id -o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/cp210x.ko /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/cp210x.o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/cp210x.mod.o 37 /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc -Wp,-MD,/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.option.mod.o.d -nostdinc -isystem /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/include -I./arch/arm/include -Iarch/arm/include/generated/uapi -Iarch/arm/include/generated -Iinclude -I./arch/arm/include/uapi -Iarch/arm/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-bcm2709/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-dwarf2-cfi-asm -fno-omit-frame-pointer -mapcs -mno-sched-prolog -fno-ipa-sra -mabi=aapcs-linux -mno-thumb-interwork -mfpu=vfp -funwind-tables -marm -D__LINUX_ARM_ARCH__=7 -march=armv7-a -msoft-float -Uarm -fno-delete-null-pointer-checks -O2 --param=allow-store-data-races=0 -Wframe-larger-than=1024 -fno-stack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -pg -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -DCC_HAVE_ASM_GOTO -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(option.mod)" -D"KBUILD_MODNAME=KBUILD_STR(option)" -DMODULE -c -o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/option.mod.o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/option.mod.c 38 /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ld -EL -r -T ./scripts/module-common.lds --build-id -o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/option.ko /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/option.o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/option.mod.o 39 /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc -Wp,-MD,/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.usb_wwan.mod.o.d -nostdinc -isystem /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/include -I./arch/arm/include -Iarch/arm/include/generated/uapi -Iarch/arm/include/generated -Iinclude -I./arch/arm/include/uapi -Iarch/arm/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-bcm2709/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-dwarf2-cfi-asm -fno-omit-frame-pointer -mapcs -mno-sched-prolog -fno-ipa-sra -mabi=aapcs-linux -mno-thumb-interwork -mfpu=vfp -funwind-tables -marm -D__LINUX_ARM_ARCH__=7 -march=armv7-a -msoft-float -Uarm -fno-delete-null-pointer-checks -O2 --param=allow-store-data-races=0 -Wframe-larger-than=1024 -fno-stack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -pg -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -DCC_HAVE_ASM_GOTO -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(usb_wwan.mod)" -D"KBUILD_MODNAME=KBUILD_STR(usb_wwan)" -DMODULE -c -o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/usb_wwan.mod.o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/usb_wwan.mod.c 40 /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ld -EL -r -T ./scripts/module-common.lds --build-id -o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/usb_wwan.ko /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/usb_wwan.o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/usb_wwan.mod.o 41 /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc -Wp,-MD,/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.usbserial.mod.o.d -nostdinc -isystem /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/include -I./arch/arm/include -Iarch/arm/include/generated/uapi -Iarch/arm/include/generated -Iinclude -I./arch/arm/include/uapi -Iarch/arm/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-bcm2709/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-dwarf2-cfi-asm -fno-omit-frame-pointer -mapcs -mno-sched-prolog -fno-ipa-sra -mabi=aapcs-linux -mno-thumb-interwork -mfpu=vfp -funwind-tables -marm -D__LINUX_ARM_ARCH__=7 -march=armv7-a -msoft-float -Uarm -fno-delete-null-pointer-checks -O2 --param=allow-store-data-races=0 -Wframe-larger-than=1024 -fno-stack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -pg -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -DCC_HAVE_ASM_GOTO -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(usbserial.mod)" -D"KBUILD_MODNAME=KBUILD_STR(usbserial)" -DMODULE -c -o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/usbserial.mod.o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/usbserial.mod.c 42 /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ld -EL -r -T ./scripts/module-common.lds --build-id -o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/usbserial.ko /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/usbserial.o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/usbserial.mod.o 43 /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc -Wp,-MD,/mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/.zte_ev.mod.o.d -nostdinc -isystem /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/include -I./arch/arm/include -Iarch/arm/include/generated/uapi -Iarch/arm/include/generated -Iinclude -I./arch/arm/include/uapi -Iarch/arm/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-bcm2709/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-dwarf2-cfi-asm -fno-omit-frame-pointer -mapcs -mno-sched-prolog -fno-ipa-sra -mabi=aapcs-linux -mno-thumb-interwork -mfpu=vfp -funwind-tables -marm -D__LINUX_ARM_ARCH__=7 -march=armv7-a -msoft-float -Uarm -fno-delete-null-pointer-checks -O2 --param=allow-store-data-races=0 -Wframe-larger-than=1024 -fno-stack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -pg -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -DCC_HAVE_ASM_GOTO -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(zte_ev.mod)" -D"KBUILD_MODNAME=KBUILD_STR(zte_ev)" -DMODULE -c -o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/zte_ev.mod.o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/zte_ev.mod.c 44 /opt/raspberry-pi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-ld -EL -r -T ./scripts/module-common.lds --build-id -o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/zte_ev.ko /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/zte_ev.o /mnt/hgfs/FSU_SMP/CustomDrv-k4.1.18/UsbSer/zte_ev.mod.o 45 make[1]: 离开目录"/opt/raspberry-pi/linux-rpi-4.1.y" 46 cp ./*.ko ./App/
1.3 外部驱动目录的 Makefile --- 编译流程
进入内核源码树目录(切换到内核顶层 Makefile)【第 3 行】
尝试读取
include/config/auto.conf文件,不存在则查找生成它的规则 【第 4-10 行】在外部驱动目录下创建
.tmp_version目录,并清空此目录中的所有内容 【第 11 行】检查
./Module.symvers文件是否存在,不存在则查找生成它的规则 【第 12-15 行】通过
rule_cc_o_c函数编译驱动文件(目标依赖): 【第 16-32 行】创建文件 @、.@.cmd、 (M)modules.order,创建目录 (M)/.tmp_versions
5.1 通过
cmd_crmodverdir函数,创建$(M)/.tmp_versions目录,并清空目录内容5.2 检查是否存在
./Module.symvers(通常在编译完成后才有)【第 12-15 行】5.3 通过
make -f ./scripts/Makefile.build obj=$@ 命令,完成下列任务:
- 将目标 @ 相应的 `*.c` 文件编译成临时目标文件`.tmp_`@ 和
.$@.d- 将临时目标文件
.tmp_@ 重命名为 最终目标文件 @- 调用
scripts/recordmcount工具扫描 $@ 文件中的 ELF 符号表和重定位信息,找到所有函数入口,并将其地址记录到一个专门的节(__mcount_loc)中- 调用
scripts/basic/fixdep工具将临时目标文件.@`.d` 和最终目标文件 @ 的相应信息输出到临时依赖文件.$@.tmp- 删除临时依赖文件
.$@.d- 将临时依赖文件
.@`.tmp`重命名为最终目标文件 `.`@.cmd5.4 生成
$(M)modules.order文件 【第 32 行】
- 编译驱动文件,执行
./scripts/Makefile.modpost(目标): 【第 33-44 行】
创建文件 @、@.cmd、 $(M)modules.order
6.1 收集所有模块的.o文件:通过.tmp_versions/*.mod文件动态获取
6.2 调用modpost工具,每个模块生成对应的.mod.c文件,并且更新外部模块目录下的Module.symvers