zoukankan      html  css  js  c++  java
  • ubuntu12.04下helloworld驱动从失败到成功过程

    最近在看linux的设备驱动程序,写一个简单的helloworld程序都花了我好久的时间,具体过程如下:

    编写helloworld.c


    编写Makefile


    注意,makefile中的命令那里是一个tab,而不是多个空格,还有源文件的名字不要写错了,然后make,出现了下面这些错误make -C /lib/modules/3.8.0-29-generic/build  M=/home/Linux/helloworld modules
    make[1]: Entering directory `/usr/src/linux-headers-3.8.0-29-generic'
      CC [M]  /home/Linux/helloworld/helloworld.o
    In file included from include/linux/types.h:5:0,
                     from include/linux/init.h:5,
                     from /home/Linux/helloworld/helloworld.c:1:
    include/uapi/linux/types.h:4:23: fatal error: asm/types.h: No such file or directory
    compilation terminated.
    make[2]: *** [/home/Linux/helloworld/helloworld.o] Error 1
    make[1]: *** [_module_/home/Linux/helloworld] Error 2
    make[1]: Leaving directory `/usr/src/linux-headers-3.8.0-29-generic'
    make: *** [default] Error 2


    在pc机的linux下运行helloworld驱动时不需要重新编译内核的,然后上面却提示缺少文件,后面看看确实是缺少文件,于是,我在windows下装了个虚拟机,用的也是ubuntu12.04,关于安装可以看我上传的资源,将这个helloworld.c和Makefile拷贝虚拟机下的ubuntu下,运行make,出现


    ls一下可以看到生成的文件如下:


    可以看到什么都没有改,然而这里就make成功了。看来用wubi安装系统有一定的缺陷。

    insmod ./helloworld.ko加载驱动,没有打印信息,在/var/log/syslog下可以看到打印信息,注意不是在/var/log/messages下的哦。vim /var/log/syslog后按下G,跳到后面,看下图


    这样,ubuntu12.04下pc机的helloworld驱动就正常运行起来了。


  • 相关阅读:
    利用相关的Aware接口
    java 值传递和引用传递。
    权限控制框架Spring Security 和Shiro 的总结
    优秀代码养成
    Servlet 基础知识
    leetcode 501. Find Mode in Binary Search Tree
    leetcode 530. Minimum Absolute Difference in BST
    leetcode 543. Diameter of Binary Tree
    leetcode 551. Student Attendance Record I
    leetcode 563. Binary Tree Tilt
  • 原文地址:https://www.cnblogs.com/james1207/p/3370828.html
Copyright © 2011-2022 走看看