DietPi icon indicating copy to clipboard operation
DietPi copied to clipboard

Regression: GPIO | Latest kernel deprecates sysfs API #5385

Open maartenlangeveld opened this issue 1 year ago • 19 comments

Hi @MichaIng,

As of lately my NanoHatOLED has stopped working

Linux M-DNS 6.6.16-current-sunxi64 #2 SMP Fri Feb 23 08:25:28 UTC 2024 aarch64 GNU/Linux

It seems GPIO devices are missing again in latest kernel.

2024-03-29 21:57:23 root@M-DNS:/# cat /tmp/nanohat-oled.log
open of gpio 0 returned -1: No such file or directory
error opening gpio sysfs entries

Would you be so kind to re-address this issue at Armbian devs since you have some authority, moreover you are knowledgeable whereas I am not? So that they can include GPIO in the kernel again?

Thanks, Maarten

maartenlangeveld avatar Mar 29 '24 21:03 maartenlangeveld

Well our relationship to Armbian devs is not the best. Usually they don't like DietPi and issues addressed from or side.

Joulinar avatar Mar 29 '24 21:03 Joulinar

Well our relationship to Armbian devs is not the best. Usually they don't like DietPi and issues addressed from or side.

Meanwhile I have addressed this issue at Armbian user forum, we leet you know if and when this issue will be resolved.

maartenlangeveld avatar Mar 30 '24 14:03 maartenlangeveld

Maybe you like to share the related form link?

Joulinar avatar Mar 30 '24 14:03 Joulinar

A build is running with this re-enabled: https://github.com/MichaIng/DietPi/actions/runs/8491886407/job/23264312017

You will find the kernel image and dtb packages here once done: https://dietpi.com/downloads/binaries/testing/ Would be great if you could give them a try.

I'll open a PR, if it works as expected. It should do, it was removed accidentally and is still enabled in edge and legacy kernel builds.

MichaIng avatar Mar 30 '24 16:03 MichaIng

Hi @MichaIng,

Eager to help, but do not know how to install the kernel. If you provide guidance, I will give it a try.

maartenlangeveld avatar Mar 30 '24 17:03 maartenlangeveld

cd /tmp
wget https://dietpi.com/downloads/binaries/testing/linux-{image,dtb}-current-sunxi64.deb
dpkg -i linux-{image,dtb}-current-sunxi64.deb
reboot

MichaIng avatar Mar 30 '24 17:03 MichaIng

It boots normal however, NanoHatOLED still dark....

2024-03-30 18:36:35 root@M-DNS:~# uname -a
Linux M-DNS 6.6.23-current-sunxi64 #1 SMP Tue Mar 26 22:22:53 UTC 2024 aarch64 GNU/Linux
2024-03-30 18:38:04 root@M-DNS:~# gpio readall
-bash: gpio: command not found
2024-03-30 18:38:25 root@M-DNS:~# ls -l /sys/class/gpio
ls: cannot access '/sys/class/gpio': No such file or directory

maartenlangeveld avatar Mar 30 '24 17:03 maartenlangeveld

Hmm, the gpio command is WiringPi, which can be installed only on RPi and some Odroids. /sys/class/gpio however should exist. Which SBC are you using?

Can you verify it's using this Linux 6.6.23 build:

uname -a

I'll test on Orange Pi Zero 3 in an hour.

MichaIng avatar Mar 30 '24 17:03 MichaIng

NanoPi NEO2

Have installed NanoPi's software (https://github.com/friendlyarm/NanoHatOLED) which includes https://github.com/friendlyarm/WiringNP. It worked up until latest kernel update.

Will try re-installing soon if necessary.

2024-03-30 18:36:35 root@M-DNS:~# uname -a
Linux M-DNS 6.6.23-current-sunxi64 #1 SMP Tue Mar 26 22:22:53 UTC 2024 aarch64 GNU/Linux

maartenlangeveld avatar Mar 30 '24 18:03 maartenlangeveld

Weird. Indeed I do not see the libgpio-sysfs driver being compiled in the logs, and the final kernel config does not contain CONFIG_GPIO_SYSFS, as if some dependency was missing. But all dependencies/selects are explicitly enabled: https://www.kernelconfig.io/config_gpio_sysfs?q=&kernelversion=6.6.23&arch=arm64

CONFIG_GPIOLIB=y
CONFIG_GPIO_SYSFS=y
CONFIG_GPIO_CDEV=y
CONFIG_SYSFS=y

Also the build log says:

[🐳|🌿] No misconfigurations or missing kernel option dependencies detected

I need to check other families configs.

MichaIng avatar Mar 30 '24 19:03 MichaIng

Ah, found the old PR which re-enabled this for 64-bit Allwinner chips: https://github.com/armbian/build/pull/3635 There is another flag missing indeed, respectively a patch to make the sysfs API independent of this other flag.

MichaIng avatar Mar 30 '24 19:03 MichaIng

Next try, now with the patch added: https://github.com/MichaIng/DietPi/actions/runs/8491886407/job/23267118549 If I am not mistaken, while CONFIG_GPIO_SYSFS=y was set for e.g. 32-bit Allwinner and Rockchip boards already, it is not effective anymore since Linux 6.6, as the patch to make it independent of CONFIG_EXPERT=y was not ported. And it is still needed: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/gpio/Kconfig#n61

MichaIng avatar Mar 30 '24 20:03 MichaIng

Hi @MichaIng,

Next try did not help either unfortunately

2024-03-30 22:44:08 root@M-DNS:~# uname -a
Linux M-DNS 6.6.23-current-sunxi64 #1 SMP Tue Mar 26 22:22:53 UTC 2024 aarch64 GNU/Linux
2024-03-30 22:43:42 root@M-DNS:~# ls -l /sys/class/gpio
ls: cannot access '/sys/class/gpio': No such file or directory

maartenlangeveld avatar Mar 30 '24 21:03 maartenlangeveld

I need to learn how the patch system works. Looks like they need to be added in two config files: https://github.com/MichaIng/build/commit/52f6b19 Comparing with another added patch, now it should be applied: https://github.com/armbian/build/commit/cf392c1

Next attempt: https://github.com/MichaIng/DietPi/actions/runs/8491886407/job/23268009107

MichaIng avatar Mar 30 '24 22:03 MichaIng

Now it works:

root@OrangePiZero3:~# ls -l /sys/class/gpio
total 0
--w------- 1 root root 4096 Mar 31 00:18 export
lrwxrwxrwx 1 root root    0 Mar 31 00:17 gpiochip0 -> ../../devices/platform/soc/300b000.pinctrl/gpio/gpiochip0
lrwxrwxrwx 1 root root    0 Mar 31 00:17 gpiochip352 -> ../../devices/platform/soc/7022000.pinctrl/gpio/gpiochip352
--w------- 1 root root 4096 Mar 31 00:18 unexport

MichaIng avatar Mar 30 '24 23:03 MichaIng

Yes, I can confirm. THANKS !!!

maartenlangeveld avatar Mar 30 '24 23:03 maartenlangeveld

For some reason I cannot open a PR at Armbian. Will try to check back tomorrow at Discord.

MichaIng avatar Mar 30 '24 23:03 MichaIng

Thanks again, @MichaIng. It's very kind of you to provide this tremendous support !!

maartenlangeveld avatar Mar 30 '24 23:03 maartenlangeveld

@Joulinar

Maybe you like to share the related form link?

https://forum.armbian.com/topic/36901-armbian-6616-sunxi64-kernel-breaks-gpio-on-nanopi-neo2/#comment-186330

maartenlangeveld avatar Apr 02 '24 19:04 maartenlangeveld

Our own kernel build with GPIO sysfs re-implemented, should have been installed with DietPi v9.4. In the meantime, also Armbian re-enabled it for all their builds, but by adding CONFIG_EXPERT=y for all of them, instead of decoupling CONFIG_GPIO_SYSFS=y from it: https://github.com/armbian/build/commit/fb17a2a The upside is, that I can drop our patch then, keeping the diff with upstream as small as possible.

MichaIng avatar May 13 '24 19:05 MichaIng