博客
关于我
linux内核3.4 led驱动,4.移植驱动到3.4内核-移植总结
阅读量:790 次
发布时间:2023-02-03

本文共 2163 字,大约阅读时间需要 7 分钟。

Linux 内核 3.4 系统移植与适配指南

1. 常用函数改动

1.1 device_create()

作用: 创建设备节点

替代函数: 消除了 2.6 内核中的 class_device_create() 函数
注意事项:

  • 使用前需包含头文件:#include <asm/device.h>
  • 该函数与 2.6 内核下的 mdev_create() 类似

1.2 device_destroy()

作用: 卸载设备节点

替代函数: 消除了 2.6 内核中的 class_device_destroy() 函数
注意事项:

  • 使用前需包含头文件:#include <asm/device.h>
  • device_create() 配合使用

1.3 usb_alloc_coherent()

**作用:**申请 USB 缓冲区,确保内存与硬件缓存一致性

替代函数: 消除了 2.6 内核中的 usb_buffer_alloc() 函数
注意事项:

  • 使用前需包含头文件:#include <asm/usb.h>

1.4 usb_free_coherent()

作用: 释放 USB 缓冲区

替代函数: 消除了 2.6 内核中的 usb_buffer_free() 函数
注意事项:

  • 使用前需包含头文件:#include <asm/usb.h>

1.5 blk_fetch_request()

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

替代函数: 消除了 2.6 内核中的 elv_next_request() 函数
注意事项:

  • 使用时需注意 request 结构体的处理

1.6 __blk_end_request_cur()

作用: 完成当前获取的请求结构体

替代函数: 消除了 2.6 内核中的 end_request() 函数
注意事项:

  • 返回值为 0 表示当前申请已完成
  • error 为 0 表示读写扇区成功,error < 0 表示失败

2. 结构体改动

2.1 struct net_device 结构体

改动方向: 2.6 内核下的 net_device 结构体成员(与操作相关)已移至 net_device_ops 结构体下

示例:

  • 2.6 内核:
    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. 宏改动

3.1 管脚宏改动

替代宏: S3C2410_GPA(0) ~ S3C2410_GPM(0)

注意事项:

  • 使用前需包含头文件:#include <asm/arch/gpio.h>

3.2 互斥信号量改动

替代宏: static DEFINE_SEMAPHORE(name);

注意事项:

  • 替代了 2.6 内核中的 DECLARE_MUTEX(name)
  • 如需初始化信号量值为 0,请自定义:
    struct semaphore name;// 在初始化函数中调用:sema_init(&name, 0)

3.3 移植 LED 为例

3.3.1 Makefile 修改

将内核位置改为:

KERN_DIR = /work/system/linux-3.4.2

3.3.2 编译错误修复

根据错误信息,修改 first_drv.c

  • 删除前两行:
    // #include // #include
  • 替换 class_device_create()device_create()
  • 替换 class_device_unregister()device_unregister()
  • 添加头文件:
    #include 
  • 编译并测试
  • 3.3.3 移植 LCD 为例

  • 编译驱动:
    make uImagemake modules
  • 在设备驱动中:
    • 去除内核自带的 LCD 驱动
    • drivers/video 下的文件添加到 nfs 文件系统中
  • 使用示例:
    insmod cfbcopyarea.koinsmod cfbfillrect.koinsmod cfbimgblt.koinsmod 9th_lcd.ko
  • 3.3.4 使用示例

    echo "Hello, World!" > /dev/lcdcat /dev/lcd

    4. 移植触摸屏

    4.1 安装 tslib

  • 编译 tslib 驱动:
    make cleanmake
  • 安装到板子上:
    make install
  • 4.2 常见问题

    • 如果出现 "selected device is not a touchscreen I understand" 错误,请检查触摸屏设备配置是否正确
    • 注意 3.4 内核与 tslib 的版本兼容性问题,需确保 EV_VERSION 定义一致
      #define EV_VERSION 0x010001

    以上内容可根据实际需求进行扩展和调整,建议在实际操作前进行充分测试。

    转载地址:http://mtzfk.baihongyu.com/

    你可能感兴趣的文章
    Linux 常用网络命令
    查看>>
    Linux 强大的网络命令:nc,网络的瑞士军刀!
    查看>>
    Linux 文件与目录管理/tree命令
    查看>>
    Linux 文件目录管理命令
    查看>>
    Linux 文件系统详解
    查看>>
    Linux 显示磁盘空间使用情况的命令:df
    查看>>
    Linux 普通用户使用 sudo 命令报 xxx is not in the sudoers file 问题解决
    查看>>
    linux 查看 mongodb 连接数
    查看>>
    linux 根目录扩容
    查看>>
    Linux 环境下将 ASM 磁盘映射到物理磁盘的完整指南
    查看>>
    Linux 的性能调优的思路
    查看>>
    Linux 的账号与群组管理
    查看>>
    Linux 硬链接和软链接到底是什么?怎么理解?
    查看>>
    Linux 磁盘分区详解
    查看>>
    Linux 磁盘和文件系统管理1
    查看>>
    Linux 磁盘和文件系统管理2
    查看>>
    linux 禁用磁盘密码,linux 磁盘加密保护
    查看>>
    Linux 系统备份与恢复详解
    查看>>
    linux 系统服务管理
    查看>>
    linux 系统的ssh服务
    查看>>