提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


一、报错

在编译驱动程序过程中,经常碰到的一个小问题:

make -C /home/lubancat/LubanCat_SDK/kernel M=/home/lubancat/lubancat_rk_code_storage/linux_driver/device_tree modules
make[1]: Entering directory '/home/lubancat/LubanCat_SDK/kernel'
  ERROR: Kernel configuration is invalid.
         include/generated/autoconf.h or include/config/auto.conf are missing.
         Run 'make oldconfig && make prepare' on kernel src to fix it.
Makefile:630: include/config/auto.conf: No such file or directory
make[1]: *** [Makefile:691: include/config/auto.conf] Error 1
make[1]: Leaving directory '/home/lubancat/LubanCat_SDK/kernel'
make: *** [Makefile:10: all] Error 2

二、解决方法

1.先编译linux内核源码

步骤1如下:

lubancat@lubancat-vm:~/LubanCat_SDK/kernel$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- lubancat2_defconfig
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  YACC    scripts/kconfig/zconf.tab.c
  LEX     scripts/kconfig/zconf.lex.c
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
#
# configuration written to .config
#

步骤2如下:

lubancat@lubancat-vm:~/LubanCat_SDK/kernel$ make ARCH=arm64 -j4 CROSS_COMPILE=aarch64-linux-gnu- dtbs
.....等待编译完成,这里省略中间的编译过程,最后的输出结果如下即可
Image Name:   
Created:      Tue Jul 29 14:27:08 2025
Image Type:   AArch64 Linux Script (uncompressed)
Data Size:    1258 Bytes = 1.23 KiB = 0.00 MiB
Load Address: 00000000
Entry Point:  00000000
Contents:
   Image 0: 1250 Bytes = 1.22 KiB = 0.00 MiB

2.再重新编译驱动程序

Makefile文件内容如下

#指定linux内核源码的路径
KERNEL_DIR=/home/lubancat/LubanCat_SDK/kernel

ARCH=arm64
CROSS_COMPILE=aarch64-linux-gnu-
export  ARCH  CROSS_COMPILE

obj-m := get_dts_info.o
all:
	$(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules

.PHONE:clean

clean:
	$(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean	

直接make,即可编译成功

更多推荐