Hisi3559编译驱动 问题(字符设备驱动) Werror问题 版本linux4.9.37 ARM架构

项目需要,自行编写Hi3559 Pcie驱动程序;

因为组内,字符设备驱动中 file_operations中  ioctl函数定义与原型有区别(因为有时候需要在第三个参数中传入结构体,因此将其设置为(void *) arg)

long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);  //内核内定义

long (*unlocked_ioctl) (struct file *, unsigned int, (void *)arg);  /组内定义
 

file_operations 定义在源码  include/linux/fs.h

 

// include/linux/fs.h
struct
file_operations { struct module *owner; loff_t (*llseek) (struct file *, loff_t, int); ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); ssize_t (*read_iter) (struct kiocb *, struct iov_iter *); ssize_t (*write_iter) (struct kiocb *, struct iov_iter *); int (*iterate) (struct file *, struct dir_context *); int (*iterate_shared) (struct file *, struct dir_context *); unsigned int (*poll) (struct file *, struct poll_table_struct *); long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); long (*compat_ioctl) (struct file *, unsigned int, unsigned long); int (*mmap) (struct file *, struct vm_area_struct *); int (*open) (struct inode *, struct file *); int (*flush) (struct file *, fl_owner_t id); int (*release) (struct inode *, struct file *); int (*fsync) (struct file *, loff_t, loff_t, int datasync); int (*fasync) (int, struct file *, int); int (*lock) (struct file *, int, struct file_lock *); ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int); unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); int (*check_flags)(int); int (*flock) (struct file *, int, struct file_lock *); ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int); ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int); int (*setlease)(struct file *, long, struct file_lock **, void **); long (*fallocate)(struct file *file, int mode, loff_t offset, loff_t len); void (*show_fdinfo)(struct seq_file *m, struct file *f); #ifndef CONFIG_MMU unsigned (*mmap_capabilities)(struct file *); #endif ssize_t (*copy_file_range)(struct file *, loff_t, struct file *, loff_t, size_t, unsigned int); int (*clone_file_range)(struct file *, loff_t, struct file *, loff_t, u64); ssize_t (*dedupe_file_range)(struct file *, u64, u64, struct file *, u64); };

 

so  这个时候 ,编译时出现Werror错误(也就是说将warning 视为 errors), gcc编译时  -Werror打开该选项  

 it treats all compiler warnings as errors.

mipse架构和x86中,之前一直没有发现这个问题, 所以纠结了好几个小时;

 

********** https://unix.stackexchange.com/questions/280838/arch-all-warnings-treated-as-errors 中查到相关方法 (明天试一试)***********

Warnings as errors are usually result of -Werror passed somewhere to the compiler. It can be intentional enforcement from developer to see how much mistakes are still there and being left only because it's still in development, or intentional enforcement in mission critical software.

Anyway, you need to find out where -Werror is. grep is a nice tool for that: just recursively grep for whole word (leading dash does not matter): grep -lr Werror ., while residing in drivers source code directory.

Then you can remove the switch from each file with simple sed -i 's@-Werror@@g' file.

Looking in https://github.com/endlessm/xf86-video-armsoc/blob/master/src/Makefile.am I see an explicit -Werror set in ERROR_CFLAGS, so developer decided to catch some non fatal warnings too.

Unfortunately -Werror is useless and annoying when building release software, because compilers widely vary. Simple things like implicit function declarations and incompatible pointers / storage size mismatches do require attention, but it's a developer task to make their code match to common and accepted standards.

 

 

家中电脑用4.9.37版本测试了一下, 查到内核中如下文件中包含Werror   (之前组内的版本是2.8 和 3.10.1版本, 3.10.1版本中也有Werror选项(所以,或许是架构的关系吧))

*********************************************************************************

tools/build/feature/Makefile
tools/usb/usbip/configure.ac
tools/perf/jvmti/Makefile
tools/perf/Makefile.config
tools/perf/Makefile.perf
tools/lib/subcmd/Makefile
tools/lib/api/Makefile
tools/lib/bpf/libbpf.h
tools/lib/bpf/Makefile
tools/testing/selftests/powerpc/Makefile
tools/testing/selftests/nsfs/Makefile
tools/virtio/Makefile
tools/objtool/Makefile
arch/mips/Kbuild
arch/metag/oprofile/Makefile
arch/alpha/mm/Makefile
arch/alpha/oprofile/Makefile
arch/alpha/lib/Makefile
arch/powerpc/kernel/Makefile
arch/powerpc/mm/Makefile
arch/powerpc/perf/Makefile
arch/powerpc/xmon/Makefile
arch/powerpc/Kconfig.debug
arch/powerpc/kvm/Makefile
arch/powerpc/oprofile/Makefile
arch/powerpc/lib/Makefile
arch/powerpc/sysdev/Makefile
arch/powerpc/sysdev/xics/Makefile
arch/powerpc/platforms/Makefile
arch/sh/kernel/Makefile
arch/sh/mm/Makefile
arch/sh/cchips/hd6446x/Makefile
arch/sh/lib/Makefile
arch/sparc/kernel/Makefile
arch/sparc/mm/Makefile
arch/sparc/lib/Makefile
arch/sparc/prom/Makefile
Makefile
scripts/Makefile.kasan
drivers/misc/cxl/Makefile
drivers/gpu/drm/tilcdc/Makefile
drivers/gpu/drm/i915/Kconfig.debug
drivers/gpu/drm/i915/Makefile
drivers/scsi/lpfc/Makefile
drivers/scsi/aic7xxx/Makefile
Documentation/kbuild/makefiles.txt

*********************************************************************************

 

 

!!!!!!!!!!!!!!!验证结果!!!!!!!!!!!!!!!!!!!!

上述处理方式存在一些问题,要捋清楚内核驱动编译的调用过程,针对性的禁止-Weror ;

所以,我将ioctl 第三那个参数改成内核中的unsigned long!  放弃了,最近没时间。追这个问题了,先留下以后去想办法。

 

posted @ 2020-07-30 22:57  semieZX  阅读(455)  评论(0编辑  收藏  举报