zoukankan      html  css  js  c++  java
  • linux设备驱动开发详解 笔记

     

    在目录的 Makefile 中关于 RTC_DRV_S3C 的编译脚本为:
    obj -$(CONFIG_RTC_DRV_S3C) += rtc-s3c.o
    上述脚本意味着如果 RTC_DRV_S3C 配置选项被选择为“Y” 或“M”,即 obj-$(CONFIG_RTC_
    DRV_S3C)等同于 obj-y 或 obj-m 时,则编译 rtc-s3c.c,选“ Y” 的情况直接会将生成的目标代码
    直接连接到内核,为“ M” 的情况则会生成模块 rtc-s3c.ko;如果 RTC_DRV_S3C 配置选项被选择
    为“ N”,即 obj-$(CONFIG_RTC_DRV_S3C)等同于 obj-n 时,则不编译 rtc-s3c.c。
    一般而言,驱动工程师只会在内核源代码的 drivers 目录的相应子目录中增加新设备驱动的源
    代码,并增加或修改 Kconfig 配置脚本和 Makefile 脚本,完全仿照上述过程执行即可

    多文件模块Makefile:

    obj -m := modulename.o
    modulename-objs := file1.o file2.o

     

    不加MODULE_LICENSE 会警告

    MODULE_LICENSE("Dual BSD/GPL");

    第6章

    insmod: error inserting 'globalmem.ko': -1 Device or resource busy

    设备号冲突, cat /proc/devices 可以看到已经使用的设备号。 换个设备号,或者alloc_chrdev_region 动态分配

     

    error: implicit declaration of function ‘kmalloc’

    #include <linux/slab.h>

     

    手动建立设备文件

    mknod /dev/globalmem c 248 0

     

    第7章

    error: implicit declaration of function ‘init_MUTEX’

    2.6.25及以后的linux内核版本废除了init_MUTEX函数

    新版本使用sema_init函数

    将原来使用 init_MUTEX(sem)的地方统统替换为sema_init(sem, 1); 即可

    /**
    * down_interruptible - acquire the semaphore unless interrupted
    * @sem: the semaphore to be acquired
    *
    * Attempts to acquire the semaphore. If no more tasks are allowed to
    * acquire the semaphore, calling this function will put the task to sleep.
    * If the sleep is interrupted by a signal, this function will return -EINTR.
    * If the semaphore is successfully acquired, this function returns 0.
    */

    得不到信号量,就会进入睡眠。 可被信号中断(如ctrl+c)

     

     

    第23章

    可以通过LINUX_VERSION_CODE判断linux版本, 同时支持多个 Linux 版本.入2.6.36后面, ioctl函数名称和签名都改变了:

    /*文件操作结构体*/
    static const struct file_operations globalfifo_fops =
    {
      .owner = THIS_MODULE,
      .read = globalfifo_read,
      .write = globalfifo_write,
    #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,36)
      .unlocked_ioctl = globalmem_ioctl,
    #else
      .ioctl = globalmem_ioctl,
    #endif
      .poll = globalfifo_poll,
      .open = globalfifo_open,
      .release = globalfifo_release,
    };

    #include <linux/version.h>
      #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,36)
      /* ioctl设备控制函数 */
      static long globalmem_ioctl(struct file *filp, unsigned
       int cmd, unsigned long arg)
      #else
      static int globalmem_ioctl(struct inode *inodep, struct file *filp, unsigned
        int cmd, unsigned long arg)
      #endif

     

    Linux 内核的移植主要含义是将 Linux 内核运行于一块新的 SoC 芯片或一块新的电路板之上,
    其实质含义就是建立 Linux 的板级支持包( BSP)。 BSP 的本质作用有二:为内核的运行提供底层
    支撑;屏蔽与板相关的硬件细节。对于 ARM 而言, BSP 代码位于 arch/arm/的各个 plat 和 mach
    目录下,

    板文件都位于 arch/arm/mach-

    BSP 公用的部分又被提炼到 arch/arm/plat-

  • 相关阅读:
    用jmeter进行多用户并发压力测试 [转]
    jmeter 压力测试 参数
    web测试 结果存储类型为“Database”,但尚未指定结果储存库连接字符串
    apache配置多站点
    seajs + easyui [转]
    js,this,constrct ,prototype
    js call apply
    js this [转]
    [leetcode] Longest Common Prefix @ Python
    [leetcode] path sum @ Python [recursion]
  • 原文地址:https://www.cnblogs.com/cute/p/4643351.html
Copyright © 2011-2022 走看看