LibGPIOd control on newer kernels and Ubuntu Core

Hello there. Not sure where this fits in, but had to post it somewhere.

Since the gpio-sysfs interface has been deprecated since somewhere around 2020-ish, (meaning that some newer 5.15 kernels does not have the /sys/class/gpio interface anymore by default) how would one go to control the gpios, without having access to the /sys/class/gpio interface?

Apparently, there’s a few commands one can use to read/set the gpiochip device’s inputs/outputs, with library access as well. (gpioset, gpioinfo and gpioget)

While one could still enable the legacy gpio-sysfs stuff, but since I need to monitor/control quite a few inputs/outputs (32 inputs/outputs on top off my head) without hogging the system with read/write requests to /sys/class/gpio/gpioX devices, would it be better to somehow grant access the libgpiod library (no idea what it accesses and where) through the gadget snap?

@ogra This might fire-off some debates, so not sure who to involve in this, that Ubuntu Core can support the gpio-char devices? Usually, they are available through /dev/gpiochipX…

AFAIK the new libgpio stuff was reverted upstream … and i also think we never actually disabled the old stuff until a final decision happens upstream … so gpio-sysfs should still work as is …

Understood.

But have anyone tested this? It appears that the libgpio binary looks at the following (apparmor log):

[   97.062618] audit: type=1400 audit(1685003005.581:333): apparmor="STATUS" operation="profile_load" profile="unconfined" name="snap-update-ns.libgpiod-snap" pid=1785 comm="apparmor_parser"
[   97.579454] audit: type=1400 audit(1685003006.098:334): apparmor="STATUS" operation="profile_load" profile="unconfined" name="snap.libgpiod-snap.gpioget" pid=1788 comm="apparmor_parser"
[   97.582479] audit: type=1400 audit(1685003006.102:335): apparmor="STATUS" operation="profile_load" profile="unconfined" name="snap.libgpiod-snap.gpiodetect" pid=1786 comm="apparmor_parser"
[   97.588568] audit: type=1400 audit(1685003006.110:336): apparmor="STATUS" operation="profile_load" profile="unconfined" name="snap.libgpiod-snap.gpiofind" pid=1787 comm="apparmor_parser"
[   97.640379] audit: type=1400 audit(1685003006.158:337): apparmor="STATUS" operation="profile_load" profile="unconfined" name="snap.libgpiod-snap.gpioinfo" pid=1789 comm="apparmor_parser"
[   98.117321] audit: type=1400 audit(1685003006.634:338): apparmor="STATUS" operation="profile_load" profile="unconfined" name="snap.libgpiod-snap.gpioset" pid=1791 comm="apparmor_parser"
[   98.117344] audit: type=1400 audit(1685003006.634:339): apparmor="STATUS" operation="profile_load" profile="unconfined" name="snap.libgpiod-snap.gpiomon" pid=1790 comm="apparmor_parser"
[  126.171021] audit: type=1400 audit(1685003034.697:340): apparmor="ALLOWED" operation="open" profile="snap.libgpiod-snap.gpioinfo" name="/dev/gpiochip0" pid=1821 comm="gpioinfo" requested_mask="wr" denied_mask="wr" fsuid=0 ouid=0
[  126.171098] audit: type=1400 audit(1685003034.697:341): apparmor="ALLOWED" operation="open" profile="snap.libgpiod-snap.gpioinfo" name="/sys/devices/platform/soc@0/30000000.bus/30200000.gpio/gpiochip0/dev" pid=1821 comm="gpioinfo" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
[  126.171150] audit: type=1400 audit(1685003034.697:342): apparmor="ALLOWED" operation="open" profile="snap.libgpiod-snap.gpioinfo" name="/dev/gpiochip1" pid=1821 comm="gpioinfo" requested_mask="wr" denied_mask="wr" fsuid=0 ouid=0
[  126.171230] audit: type=1400 audit(1685003034.697:343): apparmor="ALLOWED" operation="open" profile="snap.libgpiod-snap.gpioinfo" name="/sys/devices/platform/soc@0/30000000.bus/30210000.gpio/gpiochip1/dev" pid=1821 comm="gpioinfo" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
[  126.171266] audit: type=1400 audit(1685003034.697:344): apparmor="ALLOWED" operation="open" profile="snap.libgpiod-snap.gpioinfo" name="/dev/gpiochip2" pid=1821 comm="gpioinfo" requested_mask="wr" denied_mask="wr" fsuid=0 ouid=0
[  126.171336] audit: type=1400 audit(1685003034.697:345): apparmor="ALLOWED" operation="open" profile="snap.libgpiod-snap.gpioinfo" name="/sys/devices/platform/soc@0/30000000.bus/30220000.gpio/gpiochip2/dev" pid=1821 comm="gpioinfo" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
[  126.171370] audit: type=1400 audit(1685003034.697:346): apparmor="ALLOWED" operation="open" profile="snap.libgpiod-snap.gpioinfo" name="/dev/gpiochip3" pid=1821 comm="gpioinfo" requested_mask="wr" denied_mask="wr" fsuid=0 ouid=0
[  126.171442] audit: type=1400 audit(1685003034.697:347): apparmor="ALLOWED" operation="open" profile="snap.libgpiod-snap.gpioinfo" name="/sys/devices/platform/soc@0/30000000.bus/30230000.gpio/gpiochip3/dev" pid=1821 comm="gpioinfo" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
[  126.171478] audit: type=1400 audit(1685003034.697:348): apparmor="ALLOWED" operation="open" profile="snap.libgpiod-snap.gpioinfo" name="/dev/gpiochip4" pid=1821 comm="gpioinfo" requested_mask="wr" denied_mask="wr" fsuid=0 ouid=0
[  126.171545] audit: type=1400 audit(1685003034.697:349): apparmor="ALLOWED" operation="open" profile="snap.libgpiod-snap.gpioinfo" name="/sys/devices/platform/soc@0/30000000.bus/30240000.gpio/gpiochip4/dev" pid=1821 comm="gpioinfo" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

This is my custom development board, but should the decision be made upsteam to add support for the libgpio stuff, this could then probably assist in this matter…