Ubuntu 21.10 makes libgpiod unusable

Created On:

Linux provides two APIs for user space programs to interact with GPIO lines, a legacy sysfs based API and a newer character device based API using ioctl. The legacy sysfs API is documented to be removed soon:

This ABI is deprecated and will be removed after 2020. It is replaced with the GPIO character device.

The newer character device is controlled with ioctl calls and has a complementary library called libgpiod. It provides C library with C++ and Python bindings to manipulate GPIO via the newer API. The library also ships with a few utility command line tools like gpioinfo, gpiofind and gpiodetect which expose basic functionality of libgpiod over the CLI.

Unfortunately on Ubuntu 21.10 (Impish) libgpiod is not usable at all. For example the gpioinfo tool fails with the following error when trying to look up the details for a GPIO line.

$ gpioinfo gpiochip1
gpioinfo: error creating line iterator: Invalid argument

Similarly gpiofind will fail as well with the same error.

$ gpiofind gpiochip0
gpiofind: error performing the line lookup: Invalid argument

The root cause of this is that there are two ioctl based APIs. The first one was introduced in Linux v4.6 and the second was introduced in Linux v5.10. The first one is behind a configuration flag which is called CONFIG_GPIO_CDEV_V1.

Unfortunately Ubuntu 21.10 ships with libpgiod 1.6.2 which uses the v1 ioctl API. The V1 API is disabled in the Ubuntu 21.10 generic arm64 kernel.

$ grep GPIO_CDEV /boot/config-5.13.0-19-generic 
# CONFIG_GPIO_CDEV_V1 is not set

As a consequence all of the ioctl calls that libgpiod makes will result in an “Invalid Argument” error, because the ioctl is not available.

There are two possible solutions: