文章目录
- 一、先了解编译驱动需要什么?
- 二、配置makefile
- 1、在Android系统编译LOG上找到编译器信息(一般都会打印出来)
- 2、基于源MK构造 可独立运行的makefile
- 3)进入docker,在此makefile目录下敲make
- 4)最后根据项目不同 动态调整!
- 三、源MK
一、先了解编译驱动需要什么?
1、完整编译kernel的环境,驱动编译需要依赖kernel的生成物;
2、编译器及编译选项;
3、将所需环境变量配置在当前mk里;
注意只适用于ko模块编译
二、配置makefile
1、在Android系统编译LOG上找到编译器信息(一般都会打印出来)
如下
[2025-03-06T15:17:09.378Z] make -C /home/code/android/kernel/5.15_14 ARCH=arm CROSS_COMPILE=/home/code/android/prebuilts/mtk_toolchain/gcc-arm-linux-gnu-5.5.0-ubuntu/x86_64/bin/arm-linux-gnueabi- LOADADDR=0x20008000 NM=/home/code/android/kernel/build-master/prebuilts/clang/host/linux-x86/clang-r487747c/bin/llvm-nm AR=/home/code/android/kernel/build-master/prebuilts/clang/host/linux-x86/clang-r487747c/bin/llvm-ar LD=/home/code/android/kernel/build-master/prebuilts/clang/host/linux-x86/clang-r487747c/bin/ld.lld OBJDUMP=/home/code/android/kernel/build-master/prebuilts/clang/host/linux-x86/clang-r487747c/bin/llvm-objdump OBJCOPY=/home/code/android/kernel/build-master/prebuilts/clang/host/linux-x86/clang-r487747c/bin/llvm-objcopy LLVM=1 LLVM_IAS=1 CC=/home/code/android/kernel/build-master/prebuilts/clang/host/linux-x86/clang-r487747c/bin/clang O=/home/code/android/out/target/product/mt9633/obj/KERNEL_OBJ/5.15_14 BUILD_NUMBER= mtk_dtv_platform=mt5873 olddefconfig
[2025-03-06T15:17:09.378Z] make[2]: Entering directory ‘/home/code/android/kernel/5.15_14’
[2025-03-06T15:17:09.378Z] make[3]: Entering directory ‘/home/code/android/out/target/product/mt9633/obj/KERNEL_OBJ/5.15_14’
2、基于源MK构造 可独立运行的makefile
ccflags-y += -DANDROID_PLATFORM
KDIR ?= /home/builder/code/android/out/target/product/mt9633/obj/KERNEL_OBJ/5.15_14
ARCH ?= arm
CROSS_COMPILE ?= /home/code/android/prebuilts/mtk_toolchain/gcc-arm-linux-gnu-5.5.0-ubuntu/x86_64/bin/arm-linux-gnueabi-
OTHER_PARAMS ?= LOADADDR=0x20008000 NM=/home/code/android/kernel/build-master/prebuilts/clang/host/linux-x86/clang-r487747c/bin/llvm-nm AR=/home/code/android/kernel/build-master/prebuilts/clang/host/linux-x86/clang-r487747c/bin/llvm-ar LD=/home/code/android/kernel/build-master/prebuilts/clang/host/linux-x86/clang-r487747c/bin/ld.lld OBJDUMP=/home/code/android/kernel/build-master/prebuilts/clang/host/linux-x86/clang-r487747c/bin/llvm-objdump OBJCOPY=/home/code/android/kernel/build-master/prebuilts/clang/host/linux-x86/clang-r487747c/bin/llvm-objcopy LLVM=1 LLVM_IAS=1 CC=/home/code/android/kernel/build-master/prebuilts/clang/host/linux-x86/clang-r487747c/bin/clang
all: modules
modules:
make -C ( K D I R ) M = (KDIR) M= (KDIR)M=(PWD) ARCH= ( A R C H ) C R O S S C O M P I L E = (ARCH) CROSS_COMPILE= (ARCH)CROSSCOMPILE=(CROSS_COMPILE) $(OTHER_PARAMS) modules
$(CROSS_COMPILE)strip --strip-debug aic8800_fdrv/aic8800_fdrv.ko
$(CROSS_COMPILE)strip --strip-unneeded aic8800_fdrv/aic8800_fdrv.ko
$(CROSS_COMPILE)strip --strip-debug aic_load_fw/aic_load_fw.ko
$(CROSS_COMPILE)strip --strip-unneeded aic_load_fw/aic_load_fw.ko
//$(CROSS_COMPILE)strip --strip-debug 裁剪ko,去掉冗余信息,由于Android系统会统一后处理,不会体现在单个模块的mk里,需要加上
3)进入docker,在此makefile目录下敲make
4)最后根据项目不同 动态调整!
三、源MK
CONFIG_AIC_LOADFW_SUPPORT := m
CONFIG_AIC8800_WLAN_SUPPORT := mobj-$(CONFIG_LOADFW_SUPPORT) += load_fw/
obj-$(CONFIG_WLAN_SUPPORT) += fdrv/# Platform support list
CONFIG_PLATFORM_ROCKCHIP ?= n
CONFIG_PLATFORM_ALLWINNER ?= n
CONFIG_PLATFORM_AMLOGIC ?= y
CONFIG_PLATFORM_UBUNTU ?= nifeq ($(CONFIG_PLATFORM_ROCKCHIP), y)
#KDIR := /home/yaya/E/Rockchip/3229/Android7/RK3229_ANDROID7.1_v1.01_20170914/rk3229_Android7.1_v1.01_xml0914/kernel
#ARCH ?= arm
#CROSS_COMPILE ?= /home/yaya/E/Rockchip/3229/Android7/RK3229_ANDROID7.1_v1.01_20170914/rk3229_Android7.1_v1.01_xml0914/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-
KDIR := /home/yaya/E/Rockchip/3229/Android9/rk3229_android9.0_box/kernel
ARCH ?= arm
CROSS_COMPILE ?= /home/yaya/E/Rockchip/3229/Android9/rk3229_android9.0_box/prebuilts/gcc/linux-x86/arm/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
#KDIR := /home/yaya/E/Rockchip/3399/rk3399-android-10/kernel
#ARCH ?= arm64
#CROSS_COMPILE ?= /home/yaya/E/Rockchip/3399/rk3399-android-10/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
ccflags-y += -DANDROID_PLATFORM
endififeq ($(CONFIG_PLATFORM_ALLWINNER), y)
KDIR := /home/yaya/E/Allwinner/R818/R818/AndroidQ/lichee/kernel/linux-4.9
ARCH ?= arm64
CROSS_COMPILE ?= /home/yaya/E/Allwinner/R818/R818/AndroidQ/lichee/out/gcc-linaro-5.3.1-2016.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
ccflags-y += -DANDROID_PLATFORM
endififeq ($(CONFIG_PLATFORM_AMLOGIC), y)
ccflags-y += -DANDROID_PLATFORM
ARCH := arm
CROSS_COMPILE := /home/yaya/D/Workspace/CyberQuantum/JinHaoYue/amls905x3/SDK/20191101-0tt-asop/android9.0/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/arm-linux-androidkernel-
KDIR := /home/yaya/D/Workspace/CyberQuantum/JinHaoYue/amls905x3/SDK/20191101-0tt-asop/android9.0/out/target/product/u202/obj/KERNEL_OBJ/endififeq ($(CONFIG_PLATFORM_UBUNTU), y)
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
KVER := $(shell uname -r)
MODDESTDIR := /lib/modules/$(KVER)/kernel/drivers/net/wireless/
ARCH ?= x86_64
CROSS_COMPILE ?=
endifall: modules
modules:make -C $(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modulesinstall:mkdir -p $(MODDESTDIR)install -p -m 644 load_fw/fw.ko $(MODDESTDIR)/install -p -m 644 fdrv/fdrv.ko $(MODDESTDIR)//sbin/depmod -a ${KVER}uninstall:rm -rfv $(MODDESTDIR)/fw.korm -rfv $(MODDESTDIR)/fdrv.ko/sbin/depmod -a ${KVER}clean:cd aic_load_fw/;make clean;cd ..cd aic8800_fdrv/;make clean;cd ..rm -rf modules.order Module.symvers .tmp_versions/