Linux 内核变更导致驱动经常出现的错误记录

1: error: CFLAGS was changed in xxx. Fix it to use ccflags-y。

解决方法: export KBUILD_NOPEDANTIC=1

解决方法: 修改Makefile中的 CFLAGS 为 EXTRA_CFLAGS 或 ccflags-y


2: linux/config.h no found file or folder

解决方法: #include <linux/config.h> 头文件貌似在2.6.19的内核版本后就没有了, 有此错误的话, 则删除此文件.


3: error: unknown field ‘ioctl’ specified in initializer

解决方法: 所有file_operations结构体中的ioctl函数指针。改为unlocked_ioctl


4: error: implicit declaration of function ‘init_MUTEX’

解决方法: 2.6.25以后就已经不再使用这个宏了。可以自己手动添加此宏.

#define init_MUTEX(sem) sema_init(sem, 1)

#define init_MUTEX_LOCKED(sem) sema_init(sem, 0)

5: error: ‘TASK_INTERRUPTIBLE’ undeclared

解决方法: 添加 #include <linux/sched.h>


6: error: current->uid

解决方法: 变更为 current->cred->uid.val;

typedef struct {

uid_t val;

} kuid_t;

kuid_t uid;

struct cred {

.......................

kuid_t uid; /* real UID of the task */

kgid_t gid; /* real GID of the task */

kuid_t suid; /* saved UID of the task */

kgid_t sgid; /* saved GID of the task */

kuid_t euid; /* effective UID of the task */

kgid_t egid; /* effective GID of the task */

kuid_t fsuid; /* UID for VFS ops */

kgid_t fsgid; /* GID for VFS ops */

.......................

};

struct task_struct {

...........................

...........................

/* process credentials */

const struct cred __rcu *real_cred; /* objective and real subjective task

* credentials (COW) */

const struct cred __rcu *cred; /* effective (overridable) subjective task

* credentials (COW) */

...........................

.................

};

7: error: ‘create_proc_read_entry’or’create_proc_entry’ [-Werror=implicit-function-declaration]

解决方法: 此函数在新内核中已经被 proc_create 或者 proc_create_data 取代。函数在头文件 #include <linux/proc_fs.h> 中。


8: error: #include <asm/semaphore.h> 没有文件或目录

解决方法: 删除此行.


9: error: implicit declaration of function ‘usb_buffer_free’

解决方法: 用usb_free_coherent()替代,

说明:

USB: rename usb_buffer_alloc() and usb_buffer_free()

For more clearance what the functions actually do,

usb_buffer_alloc() is renamed to usb_alloc_coherent()

usb_buffer_free() is renamed to usb_free_coherent()


10: error: implicit declaration of function ‘lock_kernel’

解决方法: 删除或者根据代码进行对应的替换, 在内核锁已经从新版本中移除.


11: error : struct tty_struct has no member named ‘flip’, flip.count错误;

解决方法: 删除 flip, 直接引用count。在<linux/tty.h> 中,struct tty_struct直接包含了 count, flip被删除.


12: error: tty->termios->c_cflag;

解决方法: 将tty->termios->c_cflag; 变更为 tty->termios.c_cflag;


13: error: ‘struct tty_driver’ has no member named ‘devfs_name’

解决方法: 删除此行, devfs_name成员在新内核版本中被删除.


14: error: ‘TTY_DRIVER_NO_DEVFS’ undeclared (first use in this function)

解决方法: 删除, 新版本中此标志被移除

15:fatal error: asm/system.h : No file or directory #include<asm/system.h>:

解决方法:

在linux中3.3以后的内核用switch_to.h 替代了 system.h,修改代码为:
解决方法:删除 #include <asm/system.h>改用 
#include <linux/version.h>
为了保证Code的可移植性,可以使用下面的Code:
#include <linux/version.h>
#if LINUX_VERSION_CODE > KERNEL_VERSION(3, 3, 0)
           #include <asm/switch_to.h> //版本大于3.3
#else
           #include <asm/system.h> //版本小于3.3
#endif

16、关于linux内核中找不到asm文件夹:

源代码中没有asm这个文件夹,asm是一个符号连接,只有在你的主makefile的ARCH 变量赋值,编译内核的时候根据ARCH 的配置,

临时的生成asm文件夹及其下的文件,然后指向对应的体系结构的文件,如/include/asm-arm/ ,/include/asm-x86/

猜你喜欢

转载自blog.csdn.net/shenjin_s/article/details/79811757
今日推荐