zoukankan      html  css  js  c++  java
  • 4.移植驱动到3.4内核-移植总结

     1.常用函数改动

    1)device_create()

    作用: 创建设备节点

    头文件: #include <linux/device.h>

    替代了2.6内核里的class_device_create()函数

    2)device_destroy()

    作用:卸载设备节点

    头文件:#include <linux/device.h>

    替代了2.6内核里的class_device_destroy()函数

    3)usb_alloc_coherent()

    作用:申请usb缓冲区,并保持内存和硬件cache一致性

    替代了2.6内核里的usb_buffer_alloc ()函数

    4)usb_free_coherent()

    作用:释放usb缓冲区

    替代了2.6内核里的usb_buffer_free ()函数

    5) blk_fetch_request()

    作用:获取块设备里的一个申请(申请:主要用来读写块读设备的扇区)

    替代了2.6内核里的elv_next_request()函数

    6) bool __blk_end_request_cur(struct request *rq, int error)

    作用:用来完成当前获取的request结构体(具体使用参考:do_z2_request()函数)

    当返回值为0则表示已完成了当前申请(若为真,则需要继续处理当前申请,直到完成为止)

    当error为0表示读写扇区成功,error<0表示失败

    替代了2.6内核里的end_request()函数

     

    2.结构体改动

    1) struct net_device结构体

    改动方向: 2.6内核下的net_device结构体成员(与操作相关的),都放在3.4内核的net_device->net_device_ops结构体下

    比如2.6内核下的net_device结构体成员:

    net_device->hard_start_xmit();     //发包函数
    net_device->tx_timeout();         //发包超时处理函数

     对应3.4内核下:

    net_device->net_device_ops->ndo_start_xmit();   //发包函数
    net_device->net_device_ops->ndo_tx_timeout();  //发包超时处理函数

    3.宏改动

    1)管脚宏改动

    S3C2410_GPA(0)~ S3C2410_GPM(0)

    头文件: #include <mach/regs-gpio.h>

    替代了2.6内核里的S3C2410_GPA0~ S3C2410_GPM0

    2)互斥信号量改动

    static DEFINE_SEMAPHORE(name);  //定义name变量为互斥信号量

    替代了2.6内核里的DECLARE_MUTEX(name)定义宏.

    该宏定义如下图所示:

    若想定义信号量初始值为0时,可以直接定义:

    struct semaphore name    //定义一个name全局结构体变量
    //... ...

    sema_init(name,0)      //在init函数里初始化

    而获取信号量down()函数和释放信号量up()函数保持不变

    (2.6内核下的信号量使用请参考:http://www.cnblogs.com/lifexy/p/7515488.html)

     

    4.以移植LED为例

    4.1首先直接修改Makefile

    将以前的内核位置改为KERN_DIR = /work/system/linux-3.4.2

    4.2然后直接make,根据以下错误信息来修改

    first_drv.c:7:32: error: asm/arch/regs-gpio.h: No such file or directory
    
    first_drv.c:8:26: error: asm/hardware.h: No such file or directory
    
    first_drv.c: In function 'first_drv_write':
    
    first_drv.c:65: warning: ignoring return value of 'copy_from_user', declared with attribute warn_unused_result
    
    first_drv.c: In function 'first_drv_init':
    
    first_drv.c:152: error: implicit declaration of function 'class_create'
    
    first_drv.c:152: warning: assignment makes pointer from integer without a cast
    
    first_drv.c:155: error: implicit declaration of function 'class_device_create'
    
    first_drv.c:155: warning: assignment makes pointer from integer without a cast
    
    first_drv.c:160: warning: assignment makes pointer from integer without a cast
    
    first_drv.c: In function 'first_drv_exit':
    
    first_drv.c:170: error: implicit declaration of function 'class_destroy'
    
    first_drv.c:172: error: implicit declaration of function 'class_device_unregister'

     根据上面错误信息,来修改led文件first_drv.c

    1)去掉第7~8行:

    //#include <asm/arch/regs-gpio.h>
    //#include <asm/hardware.h>

    2)将class_device_create()函数改为device_create()

    3)将class_device_unregister()函数改为device_create()

    4)添加头文件

     #include <linux/device.h> 

    5)然后再次编译测试程序,移植到板子上测试即可

    5.移植LCD

    1)编译驱动

    2)去掉内核自带的lcd驱动

    进入Device Drivers -> Graphics support -> Support for frame buffer devices 

    <M>   S3C2410 LCD framebuffer support         //设为模块化
    
    <M>   Silicon Motion SM501 framebuffer support  //设为模块化

    make uImage 编译内核

    make modules 编译模块

    然后将drivers/video下面的3个文件放入nfs文件系统里,如下图所示:

    (LCD驱动里的成员fb_fillrect(), fb_copyarea(), fb_imageblit()需要用到) 

     3)装载试验

     insmod cfbcopyarea.ko

     insmod cfbfillrect.ko 

     insmod cfbimgblt.ko 

     insmod 9th_lcd.ko 

    使用echo和cat命令试验

    5.1 安装tslib,试验

    1)首先编译触摸屏驱动

    2)然后安装tslib,参考: http://www.cnblogs.com/lifexy/p/7628780.html

    测试时,打印"selected device is not a touchscreen I understand",指配置的触摸屏环境里的设备不正确

    这是因为 3.4内核的input系统和tslib的input输入系统版本号不匹配.

    3.4内核自带了版本号,为0x010001:

    include/linux/input.h:37:#define EV_VERSION             0x010001

    而tslib没有自带版本号,用的是编译器的版本号,所以进入/usr/local/arm/4.3.2/搜索,找到为0x10000:

    arm-none-linux-gnueabi/libc/usr/include/linux/input.h:32:#define EV_VERSION       0x010000

    所以接下来修改编译器的EV_VERSION,将:

    #define EV_VERSION       0x010000

    改为:

    #define EV_VERSION       0x010001

    然后进入tslib目录,然后make clean,再重新安装到板子上试验

  • 相关阅读:
    021.day21 反射 Class类 反射常用操作
    020.day20 线程概述 多线程优缺点 线程的创建 线程常用方法 生命周期 多线程同步
    019.day19 缓冲流 对象流 标准输入输出流
    018.day18 map集合如何实现排序 File类 IO流 字节流 字符流 编码
    017.day17 Map接口 克隆 treeSet集合排重缺陷
    016.day16 HashSet TreeSet 比较器Comparable Comparator
    015.day15
    014.day14
    013.day13
    线程
  • 原文地址:https://www.cnblogs.com/lifexy/p/8431012.html
Copyright © 2011-2022 走看看