我有很多很多问号【DH-H Tina】
-
(我很菜,别骂 )
大佬们指点下(如果可以的话,发俩demo参考学习下也好,尤其是带IO操作以及IIC设备的 ):1.在SDK目录下 make kernel_menuconfig 里的选项如何保存并应用,直接选择save一路回车? (百度上搜了一堆,什么cp xxxx,还有make save 都没反应)
2.想要编写驱动程序生成.KO文件,Makefile 文件如何编写(SDK目录下执行过mkernel,看了些论坛上和百度上的Makefile,尝试了未果)。
3.写的网上学来的基本驱动框架没有在 /dev/下生成节点(放在/opt/d1/tina_d1_open_v2/lichee/linux-5.4/drivers/char/下 并修改 Kconfig 追加hello_drv default y 然后SDK 下make时,就会在该目录下生成相应的ko文件,insmod后也没见节点, make kernel_menuconfig勾选后 再make,烧录img 也没有节点 )(相关代码在页面最底下)
4.比如/opt/d1/tina_d1_open_v2/lichee/linux-5.4/drivers/ 里的i2c-dev-basexxx一类的c文件,里面的函数(如i2c_transfer();), 编写APP时如何调用?还是说只能写的驱动才能调用?
5.关于linux设备数上添加节点,SDK文档介绍说最好是在board.dts中添加,配置pin是这样嘛(也是到处参照写的)? &pio { ........ dth_11_pin:dht_11_pin{ pins = "PC1"; function = "gpio_out"; allwinner,pull = <1>; bias-pull-up; }; ........ } 不需要再 上面dht_11_pin 后面家@0x.....(地址)嘛?上下的差异很不解 sun20iw1p1.dtsi中 pio: pinctrl@2000000 { ..... ledc: ledc@2008000 { #address-cells = <1>; #size-cells = <0>; compatible = "allwinner,sunxi-leds"; reg = <0x0 0x02008000 0x0 0x400>; interrupts-extended = <&plic0 36 IRQ_TYPE_LEVEL_HIGH>; interrupt-names = "ledcirq"; clocks = <&ccu CLK_LEDC>, <&ccu CLK_BUS_LEDC>; clock-names = "clk_ledc", "clk_cpuapb"; dmas = <&dma 42>, <&dma 42>; dma-names = "rx", "tx"; resets = <&ccu RST_BUS_LEDC>; reset-names = "ledc_reset"; status = "disable"; }; ...... }
6.哪吒板子上的iio接口在哪(看到iio下有DHT11驱动想直接用)
下面是参照官方的APP的Makefile CTOOL := riscv64-unknown-linux-gnu- CCL := /opt/d1/tina_d1_open_v2/prebuilt/gcc/linux-x86/riscv/toolchain-thead-glibc/riscv64-glibc-gcc-thead_20200702 CC := ${CCL}/bin/${CTOOL}gcc myproject : *.c ${CC} -o myproject $^ clean : rm myproject
相关路径给大佬参上:
whycan@ubuntu:/opt/d1/tina_d1_open_v2$ pwd /opt/d1/tina_d1_open_v2 whycan@ubuntu:/opt/d1/tina_d1_open_v2$ find -name "linux-5*" ./out/d1-h-nezha/compile_dir/target/linux-d1-h-nezha/linux-5.4.61 ./.repo/project-objects/lichee/linux-5.4.git ./.repo/projects/lichee/linux-5.4.git ./lichee/linux-5.4 ./device/config/chips/d1-h/configs/nezha_min/linux-5.4 ./device/config/chips/d1-h/configs/nezha/linux-5.4 ./device/config/chips/d1s/configs/nezha/linux-5.4 whycan@ubuntu:/opt/d1/tina_d1_open_v2$
漫长无聊的代码以及错误信息参上:
whycan@ubuntu:/mnt/hgfs/vmout/project/hellodev$ ls hello_drv.c Makefile whycan@ubuntu:/mnt/hgfs/vmout/project/hellodev$ cat Makefile KDIR =/opt/d1/tina_d1_open_v2/out/d1-h-nezha/compile_dir/target/linux-d1-h-nezha/linux-5.4.61 CTOOL := riscv64-unknown-linux-gnu- CCL := /opt/d1/tina_d1_open_v2/prebuilt/gcc/linux-x86/riscv/toolchain-thead-glibc/riscv64-glibc-gcc-thead_20200702 CC := ${CCL}/bin/${CTOOL}gcc CURRENT_PATH:=$(shell pwd) LINUX_KERNEL:=$(shell uname -r) KVERSION:=5.4 PWD:=$(shell pwd) all: make -C $(KDIR) M=$(PWD) modules CROSS_COMPILE=riscv64-unknown-linux-gnu- ARCH=riscv #myproject : *.c # ${CC} -o myproject $^ clean : rm myproject obj-m += hello_drv.o whycan@ubuntu:/mnt/hgfs/vmout/project/hellodev$ make make -C /opt/d1/tina_d1_open_v2/out/d1-h-nezha/compile_dir/target/linux-d1-h-nezha/linux-5.4.61 M=/mnt/hgfs/vmout/project/hellodev modules CROSS_COMPILE=riscv64-unknown-linux-gnu- ARCH=riscv make[1]: Entering directory '/opt/d1/tina_d1_open_v2/lichee/linux-5.4' make[1]: riscv64-unknown-linux-gnu-gcc: Command not found CC [M] /mnt/hgfs/vmout/project/hellodev/hello_drv.o In file included from ./include/linux/list.h:9, from ./include/linux/module.h:9, from /mnt/hgfs/vmout/project/hellodev/hello_drv.c:1: ./include/linux/kernel.h:6:10: fatal error: stdarg.h: No such file or directory #include <stdarg.h> ^~~~~~~~~~ compilation terminated. scripts/Makefile.build:286: recipe for target '/mnt/hgfs/vmout/project/hellodev/hello_drv.o' failed make[2]: *** [/mnt/hgfs/vmout/project/hellodev/hello_drv.o] Error 1 Makefile:1810: recipe for target '/mnt/hgfs/vmout/project/hellodev' failed make[1]: *** [/mnt/hgfs/vmout/project/hellodev] Error 2 make[1]: Leaving directory '/opt/d1/tina_d1_open_v2/lichee/linux-5.4' Makefile:15: recipe for target 'all' failed make: *** [all] Error 2 whycan@ubuntu:/mnt/hgfs/vmout/project/hellodev$ cat hello_drv.c //============================================== #include <linux/module.h> #include <linux/fs.h> #include <linux/errno.h> #include <linux/miscdevice.h> #include <linux/kernel.h> #include <linux/major.h> #include <linux/mutex.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> #include <linux/stat.h> #include <linux/init.h> #include <linux/device.h> #include <linux/tty.h> #include <linux/kmod.h> #include <linux/gfp.h> static int major =0; static int err; static char kernel_buf [1024]; static struct class * hello_class; #define MIN(a,b)(a < b ? a : b) static ssize_t hello_drv_read(struct file *file, char __user *user, size_t bytesize, loff_t *this_loff_t){ int err0; printk("%s %s line %d \n ",__FILE__,__FUNCTION__,__LINE__); err0 = copy_to_user(user,kernel_buf,MIN(1024,bytesize)); return err0; } static ssize_t hello_drv_write(struct file *file, const char __user *user, size_t bytesize, loff_t *this_loff_t){ int err0; printk("%s %s line %d \n ",__FILE__,__FUNCTION__,__LINE__); err0 = copy_from_user(kernel_buf,user,MIN(1024,bytesize)); return err0; } static int hello_drv_open(struct inode *inode, struct file *file){ int err0; err0 = printk("%s %s line %d \n ",__FILE__,__FUNCTION__,__LINE__); return err0; } static int hello_drv_close(struct inode *inode, struct file *file){ int err0; err0 = printk("%s %s line %d \n ",__FILE__,__FUNCTION__,__LINE__); return err0; } static struct file_operations hello_drv ={ .owner = THIS_MODULE, .open = hello_drv_open, .read = hello_drv_read, .write = hello_drv_write, .release = hello_drv_close }; static int __init hello_init(void){ printk("%s %s line %d \n ",__FILE__,__FUNCTION__,__LINE__); register_chrdev(0,"hello",&hello_drv); hello_class = class_create(THIS_MODULE ,"hello_class"); err = PTR_ERR(hello_class); if(IS_ERR (hello_class)){ unregister_chrdev(major,"hello"); return -1; } device_create(hello_class,NULL ,MKDEV(major ,0),NULL,"hello"); return 0; } static void __exit hello_exit(void){ printk("%s %s line %d \n ",__FILE__,__FUNCTION__,__LINE__); unregister_chrdev(major,"hello"); device_destroy(hello_class,MKDEV(major,0)); class_destroy(hello_class); } module_init(hello_init); module_exit(hello_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("XD"); //==============================================
-
1.在Tina SDK make kernel_menuconfig 点击save后保存应用均为自动操作,save了就可以了
2.生成ko文件makefile里吧obj-y改为obj-m。
3.驱动编写教程参考:https://v853.docs.aw-ol.com/soft/dev_gpio/#led
4.APP不能调用kernel层的操作,需要Port一些操作,可以是用户层接口,也可以是VFS
5.设备树相关:https://v853.docs.aw-ol.com/soft/dev_gpio/#pinctrl
6.iio接口的驱动应该是其他平台使用的,哪吒板子没有IIO接口针对哪吒板子,PerfXLab 提供了多个demo可供使用,可以参照:https://github.com/rvboards/d1_demo
Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号