Compile the makefile of the linux driver

Makefile for cross-compilation driver

There are two situations for compiling the driver, one is to compile the driver into a .ko file, and then install insmod on the board, which uses obj-m, and the other is to compile the driver into the kernel and use obj-y

#obj-m表示编译成ko文件,obj-y编译到内核中
obj-m := ch36x.o
#交叉编译需要指定内核在ubuntu的位置,内核源代码路径
KERNELDIR= /home/ht/rk3588/nvr_v1.3/kernel_rk_demo

#交叉编译器路径
CROSS_PATH = /opt/rk_linux/rv1126_1109/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-

#驱动模块源代码路径,这里驱动源代码和makefile放在了一起
PWD	:= $(shell pwd)

#交叉编译,ARCH=arm64就是指定要编译的系统是arm64架构上的,modules代表要编译内核驱动模块
modules:
	$(MAKE) ARCH=arm64 $(CFLAGS) LOCALVERSION="sun50iw6" CROSS_COMPILE=$(CROSS_PATH) -C $(KERNELDIR) M=$(PWD) modules
clean:
	rm -rf *.o *~ core .depend .*.cmd *.mod *.mod.c .tmp_versions modules.order Module.symvers Module.markers built-in.o ch36x.ko *.ko.*

Compile your own driver on this system

# Copyright (C) WCH 2019
# Makefile for linux 2.6.25 and above

ifneq ($(KERNELRELEASE), )
#call from kernel build system
obj-m := ch36x.o
else
KERNELDIR := /lib/modules/$(shell uname -r)/build
PWD	:= $(shell pwd)
modules:
	$(MAKE) -C $(KERNELDIR) M=$(PWD)
clean:
	rm -rf *.o *~ core .depend .*.cmd *.mod.c .tmp_versions modules.order Module.symvers Module.markers built-in.o ch36x.ko *.ko.*
endif

Guess you like

Origin blog.csdn.net/qq_40170041/article/details/132202009