How to add my driver to kernel source

来自个人维基
2022年4月8日 (五) 16:21free6d1823讨论 | 贡献的版本

(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航搜索

Purpose: add customized driver to Linux source tree, follow the procedures below.
This is verified in Kernel 4.20

1. kernel/arch/arm64/configs/<board>_defconfig
CONFIG_<MY_MODULE_NAME>=y

2. My driver will be the sub-item of the graphic menu,
kernel/drivers/video/Kconfig, add this line
source "drivers/gpu/<my_product>/Kconfig"

3. kernel/drivers/gpu/Makefile
obj-$(CONFIG_<MY_MODULE_NAME>) += <my_product>/

4. kernel/drivers/gpu/<my_product>/
a. Makefile: add

 obj-$(CONFIG_<MY_MODULE_NAME>) += <my_model>/

b. Kconfig: add menu description in Kconfig
c. Move driver source files to here

5. kernel/drivers/gpu/<my_product>/<my_model>
makefile Makefile: add project source files
sample of Makefile:

MODULE_NAME := <my_model>
obj-$(MY_MODULE_NAME) += $(MODULE_NAME).o
ccflags-y       := -I$(src)/ ...
ccflags-$(CONFIG_ARM) += -Iarch/arm/mm
 
COMMON_OBJS := *.o
$(MODULE_NAME)-y := $(COMMON_OBJS)
 
ifeq ($(DEBUG), 1)
ccflags-y   += -DDBG=1 -DDEBUG -D_DEBUG
else
ccflags-y   += -DDBG=0
endif

6. update dts:
kernel/arch/arm64/boot/dts/<company>/<board>_<myproduct>.dtsi