1

First of all, about this system:

I didn't build it, but it was tailored and customized with a lot of functions removed. The kernel version appears to be v4.x. It's running on an embedded system.

When I call in my program

 echo 0 > /sys/class/gpio/gpioX/value

where "X" is my desired pin, I got an error message in the bash, produced not by my printf calls in the program but by system:

sh: write error: Device or resource busy

I can see all the pins that I want to use under:

/sys/class/gpio

and not:

/sys/kernel/debug/gpio

in fact, "/sys/kernel/" doesn't even have a debug folder to begin with, which I believe is sufficient to draw the conclusion that no system process is occupying the port.

Furthermore, using lsof produced a long list but no GPIO could be found.

Usually if you saw the titular error message you just locate the process and kill it right? But in this case I couldn't even find the process. What should I do?

halfer
  • 19,824
  • 17
  • 99
  • 186
user44055
  • 21
  • 1
  • 2
  • 1
    From [this question](https://stackoverflow.com/q/16033748/10971581): `mount -t debugfs debugfs /sys/kernel/debug` ? Try `gpioinfo`? From [this question](https://unix.stackexchange.com/a/636417/333919): is your pin mapping what you think? – jhnc Jul 29 '22 at 06:47
  • 1
    Are you sure that this GPIO pin is free to use in userspace? It can be used for any other purposes by the kernel for some other functions like controlling some devices and perhaps that is why you get "busy" state? – user2699113 Jul 29 '22 at 06:52
  • @jhnc Hi, no such directory error on attempt mount. The kernel doesn't have gpioinfo. Also no pigpio . – user44055 Jul 29 '22 at 11:07
  • @user2699113 not entirely sure but fairly sure. – user44055 Jul 29 '22 at 11:07
  • `mkdir /sys/kernel/debug` first? Or just use some other directory. `gpioinfo` is an application. On ubuntu it's part of the `gpiod` package, shouldn't be too hard to cross-compile if you can't find one prebuilt – jhnc Jul 29 '22 at 11:09
  • @jhnc Hi, I found the github repo for gpiod but it doesn't have a "conventional" make file and I don't know how to build it?? Also isn't it kind of missing the point if I made that directory? – user44055 Jul 29 '22 at 12:58
  • Is the kernel configured with `CONFIG_DEBUG_FS=y`? – Ian Abbott Jul 29 '22 at 13:08
  • @IanAbbott can't even located the config file. Tried proc, nothing. No boot directory either. – user44055 Jul 29 '22 at 13:21
  • `mount` needs a mountpoint; any directory you aren't using will do. I thought the point was to solve your problem? You said you wanted to use the /sys/kernel/debug (ie debugfs) interface. It could be it's configured but just not mounted. Attempting to mount seems the obvious test. – jhnc Jul 29 '22 at 13:36
  • @jhnc Hi I have no intention to use /sys/kernel/debug unless it's necessary. If that clears things up. My whole point is to be able to flip certain GPIO pins. I don't think I'll be able to create a folder as my file system on "system block" is read-only. – user44055 Jul 29 '22 at 14:35
  • Are you able to read data from this GPIO? Have you configured GPIO direction properly? Have you read this: https://linuxlink.timesys.com/docs/wiki/engineering/HOWTO_Use_gpiolib ? – user2699113 Jul 30 '22 at 16:05
  • @user2699113 Hi it appears that there's something messed up with the system. I can operate all the pins just fine but the message won't go away. Truly strange. – user44055 Jul 31 '22 at 10:50
  • If you have some kernel debugging experience I suggest to debug the GPIO driver - in what circumstances it returns EBUSY status. – user2699113 Aug 02 '22 at 07:39

1 Answers1

2

Your problem sounds like the GPIO pin has been assigned to a hardware device driver in your kernel device tree. If that is the case, you will not be able to control the pin from user-space as it will forever be "busy". Your only solution in this case would be to alter the device tree (likely disabling the HW driver) as to leave the pin unassigned by DTS.