【linux】驱动学习问题及解决方法
1.前言
笔者自己学习linux 驱动遇见的问题,及相关解决方法记录
环境:Ubuntu 20,IM6U,uboot-imx-2016.03-2.1.0-g0ae7e33-v1.7.tar
2.问题及解决方法
2.1cc1: error: code model kernel does not support PIC mode
KBUILD_CFLAGS := -fno-pie
Makefile:9: *** missing separator. Stop.
解决方法
在Makefile文件中,命令必须以Tab键开始。
./arch/x86/include/asm/arch_hweight.h:53:42: error: expected ‘:’ or ‘)’ before ‘POPCNT64’
内核makefile中添加ARM 路径和编译器路径,因此在内核源码的主Makefile中指定ARCH和CROSS_COMPILE 即可
2.2 ./arch/arm/include/asm/spinlock.h:5:2: error: #error SMP not supported on pre-ARMv6 CPUs
# ARCH ?= arm
# CROSS_COMPILE ?= arm-linux-gnueabihf-
# # Architecture as present in compile.h
# UTS_MACHINE := $(ARCH)
# SRCARCH := $(ARCH)# KBUILD_CFLAGS := -fno-pie
# # ENV:=ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-# KERNELDIR := /home/zx/zx/linux/uboot-stu/linux-imx-rel_imx_4.1.15_2.1.0_ga
# CURRENT_PATH := $(shell pwd)
# obj-m := chrdevbase.o# build: kernel_modules# kernel_modules:
# $(MAKE) -C $(KERNELDIR) M=$(CURRENT_PATH) modules# clean:
# $(MAKE) -C $(KERNELDIR) M=$(CURRENT_PATH) cleanKERNELDIR := /home/zx/zx/linux/uboot-stu/linux-imx-rel_imx_4.1.15_2.1.0_ga
CURRENT_PATH := $(shell pwd)
obj-m := chrdevbase.obuild: kernel_moduleskernel_modules:$(MAKE) -C $(KERNELDIR) M=$(CURRENT_PATH) modules
clean:$(MAKE) -C $(KERNELDIR) M=$(CURRENT_PATH) clean
注释的makefile 编译有问题
2.3 文件系统有depmod 但是depmod: can’t change directory to ‘lib/modules/4.1.15’: No such file or directory
解决方法
创建’lib/modules/4.1.15目录解决问题
参考文献 Modprobe加载驱动问题
2.4 Segmentation fault
多了个括号,编译通过了
/lib/modules/4.1.15 # modprobe newchrled.ko
modprobe: module newchrled.ko not found in modules.dep
//需要用depmod命令将驱动加载到modules.dep文件中,系统从该文件调用
/lib/modules/4.1.15 # depmod
/lib/modules/4.1.15 # modprobe newchrled.ko
2.4 FATAL ERROR: Unable to parse input tree
Error: arch/arm/boot/dts/myfirst.dts:54.5-11 syntax error
解决方法
找到对应的设备树文件的相应行附近寻找错误 比如54行附近
ERROR (duplicate_label): Duplicate label ‘ecspi1’ on /soc/aips-bus@02000000/ecspi@02008000 and /soc/aips-bus@02000000/spba-bus@02000000/ecspi@02008000
设备树下修改led驱动,试验达不到理想效果(灯不亮)
2.5 用格式化工具格式后Ubuntu 报错
默认格式化是FAT32
解决方法:
sudo fsck /dev/sdb1
发现报错
sudo mkfs.ext3 /dev/sdb1
重新在Ubuntu 环境下格式化,解决问题
大佬链接,笔者在正点原子im6ux mini 开发板上实验有些SD卡能正常使用但是不能用来烧录系统和用作启动
格式成FAT32也不行
FAT32 也不行,WIN11环境下能使用(32G 的和64G都是)
好使的是SanDisk 的8G SD卡
2.6 uboot 编译报错问题
In file included from ./tools/…/common/env_embedded.c:14,
from tools/common/env_embedded.c:1:
include/environment.h:161:21: error: ‘CONFIG_ENV_SIZE’ undeclared here (not in a function)
161 | unsigned char data[ENV_SIZE]; /* Environment data */
| ^~~~~~~~
make[1]: *** [scripts/Makefile.host:111: tools/common/env_embedded.o] Error 1
make[1]: *** Waiting for unfinished jobs…
make: *** [Makefile:1194: tools] Error 2
解决方法
修改config为当前目录下,结果不行
查百度
cd /
sudo find -name "config.h"
sudo mv /usr/local/include/config.h /usr/local/include/config.h.bak