0

I am trying to perform some GPIO operations through a lodable kernel module. for which, I am trying to access the file "/sys/class/leds/led1/brightness" using open() and write() system-calls, therefore I have included the following header files.

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

but while cross compiling the project, I got the following warning and error.

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.

Here is a link to git-hub : https://github.com/guruprasad-92/Device-Driver.git Can you please help me with this ?

red0ct
  • 4,840
  • 3
  • 17
  • 44
  • You have to figure out what you are doing. If it's user space application, why you do need kernel to be involved in the compilation like this? Otherwise, why are you trying to use user space headers and ABI to work with it from kernel? Kernel has its own **internal** API for GPIO and / or LED devices. For now I see the XY mess in your Q. – 0andriy Nov 17 '19 at 10:11
  • Does this answer your question? [Read/write files within a Linux kernel module](https://stackoverflow.com/questions/1184274/read-write-files-within-a-linux-kernel-module) – Tsyvarev Nov 17 '19 at 11:08

1 Answers1

1

Sorry but you are doing it wrong - don't try to access the GPIO user space interface from the kernel. Instead, use the in-kernel GPIO interface.

More info on that here: https://lwn.net/Articles/532714/

gby
  • 14,900
  • 40
  • 57