c - 如何在设备驱动程序编程中添加用户空间头?

标签 c linux-kernel linux-device-driver embedded-linux kernel-module

我正在尝试通过可加载内核模块执行一些 GPIO 操作。为此,我尝试使用 open() 和 write() 系统调用访问文件“/sys/class/leds/led1/brightness”,因此我包含了以下头文件。

#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>

但是在交叉编译项目时,我收到以下警告和错误。

guru@guru-G40-80:~/OFC/lnx/projects/V4/source_codes/git/Device-Driver/char_dev_gsm$ make
pwd : /home/guru/OFC/lnx/projects/V4/source_codes/git/Device-Driver/char_dev_gsm 
make -C /home/guru/OFC/lnx/projects/V4/source_codes/git/linux-at91/ M=/home/guru/OFC/lnx/projects/V4/source_codes/git/Device-Driver/char_dev_gsm modules
make[1]: Entering directory '/home/guru/OFC/lnx/projects/V4/source_codes/git/linux-at91'

  WARNING: Symbol version dump ./Module.symvers
           is missing; modules will have no dependencies and modversions.

    pwd : /home/guru/OFC/lnx/projects/V4/source_codes/git/Device-Driver/char_dev_gsm 
      CC [M]  /home/guru/OFC/lnx/projects/V4/source_codes/git/Device-Driver/char_dev_gsm/src/pwr_hndl/pwr_hndl.o
    /home/guru/OFC/lnx/projects/V4/source_codes/git/Device-Driver/char_dev_gsm/src/pwr_hndl/pwr_hndl.c:5:10: fatal error: sys/stat.h: No such file or directory
     #include <sys/stat.h>
              ^~~~~~~~~~~~
    compilation terminated.

这里是 git-hub 的链接:https://github.com/guruprasad-92/Device-Driver.git 你能帮我解决这个问题吗?

最佳答案

抱歉,您做错了 - 不要尝试从内核访问 GPIO 用户空间接口(interface)。相反,请使用内核内 GPIO 接口(interface)。

更多信息请点击:https://lwn.net/Articles/532714/

关于c - 如何在设备驱动程序编程中添加用户空间头?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58898607/

相关文章:

c - 为什么不推荐使用带有单个参数(没有转换说明符)的 printf?

linux - linux新手关于嵌入式linux设备驱动的问题

Linux initramfs switch_root 无法找到内核使用的控制台

c - 了解 LINUX_VERSION_CODE

linux - 将多个内核缓冲区映射到连续的用户空间缓冲区?

linux - 如何从内核空间检查/验证用户空间中 .so 或 exe 的可用性

c - 如何将这些字符沿字母表向下移动 3 个空格,而不进入字母表之外的其他字符?

c - 端口扫描时的随机端口连接

c - 为什么使用 NDEBUG 而不是 RELEASE?

linux - 在 linux 中是否可以从任何用户空间程序注册中断处理程序?