Skip to content

Conversation

@mhei
Copy link
Contributor

@mhei mhei commented Mar 27, 2024

libgpiod in version 2 or above introduced an API change which results in compile error with the current code.

This commit adds some glue magic for the newer versions and tries to detect the used libgpiod version based on the information available in the pkg-config files.

At the moment, this eliminates the possibility to statically link against this library - sorry for this, maybe it is possible to re-add this later again.

To give a big picture: I'm not a user of avrdude and I could only compile test this change so far - run-time testing and review is really appreciated. I'm libgpiod package maintainer for OpenWrt and this package/tool needs be buildable against the newer libgpiod otherwise it would block the libgpiod update or it would be required to disable this function subset. This is something I would like to prevent, so thanks for helping out here with testing and review.

@mcuee mcuee added the enhancement New feature or request label Mar 29, 2024
@mcuee
Copy link
Collaborator

mcuee commented Mar 29, 2024

@mhei
Linux CMake CI build failed, You need to update the CI build script as well.

@mhei
Copy link
Contributor Author

mhei commented Mar 29, 2024

CI is a fine thing 😄 I see that I changed the fallback behavior unintendedly. I'll have a look and rework.

@mhei mhei force-pushed the support-for-libgpiodv2 branch 2 times, most recently from 43196d5 to 7c635e5 Compare March 29, 2024 14:00
@mhei
Copy link
Contributor Author

mhei commented Mar 29, 2024

At the moment, I did not add stuff for autotools based build. I've seen that there is some (larger?) refactoring/improvements ongoing. Should I add the required changes here already now, or should this be added later?

@mhei mhei force-pushed the support-for-libgpiodv2 branch from 7c635e5 to cef77ee Compare March 29, 2024 20:30
@mcuee
Copy link
Collaborator

mcuee commented Mar 31, 2024

At the moment, I did not add stuff for autotools based build. I've seen that there is some (larger?) refactoring/improvements ongoing. Should I add the required changes here already now, or should this be added later?

The basic autotools build is pretty good alrready. So I I tend to think it is good to add the support now.

@mcuee
Copy link
Collaborator

mcuee commented Apr 5, 2024

Thanks for the PR. Let me try this on my Raspberry Pi 400 over the weekend.

@mcuee
Copy link
Collaborator

mcuee commented Apr 6, 2024

I am using a fully up-to-date Raspberry Pi OS with my Raspberry Pi 400 and it still comes with libgpiod v1.

mcuee@raspberrypi400arm64:~/build/avrdude_pr1725 $ sudo apt update
Hit:1 http://deb.debian.org/debian bookworm InRelease
Hit:2 http://deb.debian.org/debian-security bookworm-security InRelease
Hit:3 http://deb.debian.org/debian bookworm-updates InRelease
Hit:4 http://archive.raspberrypi.com/debian bookworm InRelease   
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.

mcuee@raspberrypi400arm64:~/build/avrdude_pr1725 $ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 12 (bookworm)
Release:	12
Codename:	bookworm


mcuee@raspberrypi400arm64:~/build/avrdude_pr1725 $ ./build.sh 
-- The C compiler identification is GNU 12.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found Git: /usr/bin/git (found version "2.39.2") 
-- Found FLEX: /usr/bin/flex (found version "2.6.4") 
-- Found BISON: /usr/bin/bison (found version "3.8.2")
-- Looking for libelf.h
-- Looking for libelf.h - found
-- Looking for libelf/libelf.h
-- Looking for libelf/libelf.h - not found
-- Looking for usb.h
-- Looking for usb.h - found
-- Looking for lusb0_usb.h
-- Looking for lusb0_usb.h - not found
-- Looking for libusb.h
-- Looking for libusb.h - not found
-- Looking for libusb-1.0/libusb.h
-- Looking for libusb-1.0/libusb.h - found
-- Looking for hidapi/hidapi.h
-- Looking for hidapi/hidapi.h - found
-- Looking for ftdi_tcioflush
-- Looking for ftdi_tcioflush - found
-- Found PkgConfig: /usr/bin/pkg-config (found version "1.8.1") 
-- Checking for module 'libgpiod>=2.0'
--   Package dependency requirement 'libgpiod >= 2.0' could not be satisfied.
Package 'libgpiod' has version '1.6.3', required version is '>= 2.0'
-- Checking for module 'libgpiod'
--   Found libgpiod, version 1.6.3
-- Configuration summary:
-- ----------------------
-- DO HAVE    libelf
-- DO HAVE    libusb
-- DO HAVE    libusb_1_0
-- DO HAVE    libhidapi
-- DON'T HAVE libftdi
-- DO HAVE    libftdi1
-- DO HAVE    libreadline
-- DO HAVE    libserialport
-- DISABLED   doc
-- DISABLED   parport
-- ENABLED    linuxgpio
-- DO HAVE    libgpiod
-- ENABLED    linuxspi
-- ----------------------
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mcuee/build/avrdude_pr1725/build_linux
[  1%] Generating avrdude.conf
[  1%] Built target conf
[  2%] [FLEX][Parser] Building scanner with flex 2.6.4
[  3%] [BISON][Parser] Building parser with bison 3.8.2
[  5%] Building C object src/CMakeFiles/libavrdude.dir/arduino.c.o
[  6%] Building C object src/CMakeFiles/libavrdude.dir/avr.c.o
[  7%] Building C object src/CMakeFiles/libavrdude.dir/avr910.c.o
[  9%] Building C object src/CMakeFiles/libavrdude.dir/avrcache.c.o
[ 10%] Building C object src/CMakeFiles/libavrdude.dir/avrftdi.c.o
[ 11%] Building C object src/CMakeFiles/libavrdude.dir/avrftdi_tpi.c.o
[ 13%] Building C object src/CMakeFiles/libavrdude.dir/avrintel.c.o
[ 14%] Building C object src/CMakeFiles/libavrdude.dir/avrpart.c.o
[ 15%] Building C object src/CMakeFiles/libavrdude.dir/bitbang.c.o
[ 17%] Building C object src/CMakeFiles/libavrdude.dir/buspirate.c.o
[ 18%] Building C object src/CMakeFiles/libavrdude.dir/butterfly.c.o
[ 19%] Building C object src/CMakeFiles/libavrdude.dir/ch341a.c.o
[ 21%] Building C object src/CMakeFiles/libavrdude.dir/config.c.o
[ 22%] Building C object src/CMakeFiles/libavrdude.dir/confwin.c.o
[ 23%] Building C object src/CMakeFiles/libavrdude.dir/crc16.c.o
[ 25%] Building C object src/CMakeFiles/libavrdude.dir/dfu.c.o
[ 26%] Building C object src/CMakeFiles/libavrdude.dir/dryrun.c.o
[ 27%] Building C object src/CMakeFiles/libavrdude.dir/fileio.c.o
[ 28%] Building C object src/CMakeFiles/libavrdude.dir/flip1.c.o
[ 30%] Building C object src/CMakeFiles/libavrdude.dir/flip2.c.o
[ 31%] Building C object src/CMakeFiles/libavrdude.dir/ft245r.c.o
[ 32%] Building C object src/CMakeFiles/libavrdude.dir/jtagmkI.c.o
[ 34%] Building C object src/CMakeFiles/libavrdude.dir/jtagmkII.c.o
[ 35%] Building C object src/CMakeFiles/libavrdude.dir/jtag3.c.o
[ 36%] Building C object src/CMakeFiles/libavrdude.dir/leds.c.o
[ 38%] Building C object src/CMakeFiles/libavrdude.dir/linuxgpio.c.o
[ 39%] Building C object src/CMakeFiles/libavrdude.dir/linuxspi.c.o
[ 40%] Building C object src/CMakeFiles/libavrdude.dir/lists.c.o
[ 42%] Building C object src/CMakeFiles/libavrdude.dir/micronucleus.c.o
[ 43%] Building C object src/CMakeFiles/libavrdude.dir/par.c.o
[ 44%] Building C object src/CMakeFiles/libavrdude.dir/pgm.c.o
[ 46%] Building C object src/CMakeFiles/libavrdude.dir/pgm_type.c.o
[ 47%] Building C object src/CMakeFiles/libavrdude.dir/pickit2.c.o
[ 48%] Building C object src/CMakeFiles/libavrdude.dir/pindefs.c.o
[ 50%] Building C object src/CMakeFiles/libavrdude.dir/ppi.c.o
[ 51%] Building C object src/CMakeFiles/libavrdude.dir/ppiwin.c.o
[ 52%] Building C object src/CMakeFiles/libavrdude.dir/serbb_posix.c.o
[ 53%] Building C object src/CMakeFiles/libavrdude.dir/serbb_win32.c.o
[ 55%] Building C object src/CMakeFiles/libavrdude.dir/ser_avrdoper.c.o
[ 56%] Building C object src/CMakeFiles/libavrdude.dir/ser_posix.c.o
[ 57%] Building C object src/CMakeFiles/libavrdude.dir/ser_win32.c.o
[ 59%] Building C object src/CMakeFiles/libavrdude.dir/serialadapter.c.o
[ 60%] Building C object src/CMakeFiles/libavrdude.dir/serialupdi.c.o
[ 61%] Building C object src/CMakeFiles/libavrdude.dir/stk500.c.o
[ 63%] Building C object src/CMakeFiles/libavrdude.dir/stk500v2.c.o
[ 64%] Building C object src/CMakeFiles/libavrdude.dir/stk500generic.c.o
[ 65%] Building C object src/CMakeFiles/libavrdude.dir/strutil.c.o
[ 67%] Building C object src/CMakeFiles/libavrdude.dir/teensy.c.o
[ 68%] Building C object src/CMakeFiles/libavrdude.dir/term.c.o
[ 69%] Building C object src/CMakeFiles/libavrdude.dir/updi_link.c.o
[ 71%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm.c.o
[ 72%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm_v0.c.o
[ 73%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm_v2.c.o
[ 75%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm_v3.c.o
[ 76%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm_v4.c.o
[ 77%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm_v5.c.o
[ 78%] Building C object src/CMakeFiles/libavrdude.dir/updi_readwrite.c.o
[ 80%] Building C object src/CMakeFiles/libavrdude.dir/updi_state.c.o
[ 81%] Building C object src/CMakeFiles/libavrdude.dir/urclock.c.o
[ 82%] Building C object src/CMakeFiles/libavrdude.dir/usbasp.c.o
[ 84%] Building C object src/CMakeFiles/libavrdude.dir/usb_hidapi.c.o
[ 85%] Building C object src/CMakeFiles/libavrdude.dir/usb_libusb.c.o
[ 86%] Building C object src/CMakeFiles/libavrdude.dir/usbtiny.c.o
[ 88%] Building C object src/CMakeFiles/libavrdude.dir/update.c.o
[ 89%] Building C object src/CMakeFiles/libavrdude.dir/wiring.c.o
[ 90%] Building C object src/CMakeFiles/libavrdude.dir/xbee.c.o
[ 92%] Building C object src/CMakeFiles/libavrdude.dir/__/lexer.c.o
[ 93%] Building C object src/CMakeFiles/libavrdude.dir/__/config_gram.c.o
[ 94%] Linking C static library libavrdude.a
[ 94%] Built target libavrdude
[ 96%] Building C object src/CMakeFiles/avrdude.dir/main.c.o
[ 97%] Building C object src/CMakeFiles/avrdude.dir/developer_opts.c.o
[ 98%] Building C object src/CMakeFiles/avrdude.dir/whereami.c.o
[100%] Linking C executable avrdude
[100%] Built target avrdude

Build succeeded.

Run

sudo cmake --build build_linux --target install

to install.

@mcuee
Copy link
Collaborator

mcuee commented Apr 6, 2024

But the package name is confusing.

mcuee@raspberrypi400arm64:~/build/avrdude_pr1725 $ sudo apt search libgpiod
Sorting... Done
Full Text Search... Done
gpiod/stable,now 1.6.3-1+b3 arm64 [installed]
  Tools for interacting with Linux GPIO character device - binary

libgpiod-dev/stable,now 1.6.3-1+b3 arm64 [installed]
  C library for interacting with Linux GPIO device - static libraries and headers

libgpiod-doc/stable,stable 1.6.3-1 all
  C library for interacting with Linux GPIO device - library documentation

libgpiod2/stable,now 1.6.3-1+b3 arm64 [installed,automatic]
  C library for interacting with Linux GPIO device - shared libraries

python3-libgpiod/stable,now 1.6.3-1+b3 arm64 [installed]
  Python bindings for libgpiod (Python 3)

mcuee@raspberrypi400arm64:~/build $ pkg-config --version libgpiod
1.8.1
mcuee@raspberrypi400arm64:~/build $ pkg-config --cflags libgpiod

mcuee@raspberrypi400arm64:~/build $ pkg-config --libs libgpiod
-lgpiod 

@mcuee
Copy link
Collaborator

mcuee commented Apr 6, 2024

So I just build the latest libgpiod from its git repo.
https://github.com/brgl/libgpiod

It is not compatible with git main.

(py311venv) mcuee@raspberrypi400arm64:~/build/avrdude_git $ ./build.sh 
-- The C compiler identification is GNU 12.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found Git: /usr/bin/git (found version "2.39.2") 
-- Found FLEX: /usr/bin/flex (found version "2.6.4") 
-- Found BISON: /usr/bin/bison (found version "3.8.2")
-- Looking for libelf.h
-- Looking for libelf.h - found
-- Looking for libelf/libelf.h
-- Looking for libelf/libelf.h - not found
-- Looking for usb.h
-- Looking for usb.h - found
-- Looking for lusb0_usb.h
-- Looking for lusb0_usb.h - not found
-- Looking for libusb.h
-- Looking for libusb.h - not found
-- Looking for libusb-1.0/libusb.h
-- Looking for libusb-1.0/libusb.h - found
-- Looking for hidapi/hidapi.h
-- Looking for hidapi/hidapi.h - found
-- Looking for ftdi_tcioflush
-- Looking for ftdi_tcioflush - found
-- Configuration summary:
-- ----------------------
-- DO HAVE    libelf
-- DO HAVE    libusb
-- DO HAVE    libusb_1_0
-- DO HAVE    libhidapi
-- DON'T HAVE libftdi
-- DO HAVE    libftdi1
-- DO HAVE    libreadline
-- DO HAVE    libserialport
-- DISABLED   doc
-- DISABLED   parport
-- ENABLED    linuxgpio
-- DO HAVE    libgpiod
-- ENABLED    linuxspi
-- ----------------------
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mcuee/build/avrdude_git/build_linux
[  1%] Generating avrdude.conf
[  1%] Built target conf
[  2%] [FLEX][Parser] Building scanner with flex 2.6.4
[  3%] [BISON][Parser] Building parser with bison 3.8.2
[  5%] Building C object src/CMakeFiles/libavrdude.dir/arduino.c.o
[  6%] Building C object src/CMakeFiles/libavrdude.dir/avr.c.o
[  7%] Building C object src/CMakeFiles/libavrdude.dir/avr910.c.o
[  9%] Building C object src/CMakeFiles/libavrdude.dir/avrcache.c.o
[ 10%] Building C object src/CMakeFiles/libavrdude.dir/avrftdi.c.o
[ 11%] Building C object src/CMakeFiles/libavrdude.dir/avrftdi_tpi.c.o
[ 13%] Building C object src/CMakeFiles/libavrdude.dir/avrintel.c.o
[ 14%] Building C object src/CMakeFiles/libavrdude.dir/avrpart.c.o
[ 15%] Building C object src/CMakeFiles/libavrdude.dir/bitbang.c.o
[ 17%] Building C object src/CMakeFiles/libavrdude.dir/buspirate.c.o
[ 18%] Building C object src/CMakeFiles/libavrdude.dir/butterfly.c.o
[ 19%] Building C object src/CMakeFiles/libavrdude.dir/ch341a.c.o
[ 21%] Building C object src/CMakeFiles/libavrdude.dir/config.c.o
[ 22%] Building C object src/CMakeFiles/libavrdude.dir/confwin.c.o
[ 23%] Building C object src/CMakeFiles/libavrdude.dir/crc16.c.o
[ 25%] Building C object src/CMakeFiles/libavrdude.dir/dfu.c.o
[ 26%] Building C object src/CMakeFiles/libavrdude.dir/dryrun.c.o
[ 27%] Building C object src/CMakeFiles/libavrdude.dir/fileio.c.o
[ 28%] Building C object src/CMakeFiles/libavrdude.dir/flip1.c.o
[ 30%] Building C object src/CMakeFiles/libavrdude.dir/flip2.c.o
[ 31%] Building C object src/CMakeFiles/libavrdude.dir/ft245r.c.o
[ 32%] Building C object src/CMakeFiles/libavrdude.dir/jtagmkI.c.o
[ 34%] Building C object src/CMakeFiles/libavrdude.dir/jtagmkII.c.o
[ 35%] Building C object src/CMakeFiles/libavrdude.dir/jtag3.c.o
[ 36%] Building C object src/CMakeFiles/libavrdude.dir/leds.c.o
[ 38%] Building C object src/CMakeFiles/libavrdude.dir/linuxgpio.c.o
/home/mcuee/build/avrdude_git/src/linuxgpio.c: In function ‘linuxgpio_libgpiod_open’:
/home/mcuee/build/avrdude_git/src/linuxgpio.c:385:35: warning: implicit declaration of function ‘gpiod_line_get’ [-Wimplicit-function-declaration]
  385 |     linuxgpio_libgpiod_lines[i] = gpiod_line_get(port, gpio_num);
      |                                   ^~~~~~~~~~~~~~
/home/mcuee/build/avrdude_git/src/linuxgpio.c:385:33: warning: assignment to ‘struct gpiod_line *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
  385 |     linuxgpio_libgpiod_lines[i] = gpiod_line_get(port, gpio_num);
      |                                 ^
/home/mcuee/build/avrdude_git/src/linuxgpio.c:393:13: warning: implicit declaration of function ‘gpiod_line_request_input’; did you mean ‘gpiod_line_request_get_fd’? [-Wimplicit-function-declaration]
  393 |         r = gpiod_line_request_input(linuxgpio_libgpiod_lines[i], "avrdude");
      |             ^~~~~~~~~~~~~~~~~~~~~~~~
      |             gpiod_line_request_get_fd
/home/mcuee/build/avrdude_git/src/linuxgpio.c:395:13: warning: implicit declaration of function ‘gpiod_line_request_output’; did you mean ‘gpiod_line_request_get_fd’? [-Wimplicit-function-declaration]
  395 |         r = gpiod_line_request_output(linuxgpio_libgpiod_lines[i], "avrdude", 0);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~
      |             gpiod_line_request_get_fd
/home/mcuee/build/avrdude_git/src/linuxgpio.c: In function ‘linuxgpio_libgpiod_close’:
/home/mcuee/build/avrdude_git/src/linuxgpio.c:415:15: warning: implicit declaration of function ‘gpiod_line_set_direction_input’ [-Wimplicit-function-declaration]
  415 |       int r = gpiod_line_set_direction_input(linuxgpio_libgpiod_lines[i]);
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/mcuee/build/avrdude_git/src/linuxgpio.c:37:
/home/mcuee/build/avrdude_git/src/linuxgpio.c:417:58: warning: implicit declaration of function ‘gpiod_line_name’ [-Wimplicit-function-declaration]
  417 |         msg_error("failed to set pin %s to input: %s\n", gpiod_line_name(linuxgpio_libgpiod_lines[i]), strerror(errno));
      |                                                          ^~~~~~~~~~~~~~~
/home/mcuee/build/avrdude_git/src/avrdude.h:66:98: note: in definition of macro ‘msg_error’
   66 | #define msg_error(...)      avrdude_message2(stderr, __LINE__, __FILE__, __func__, 0, MSG_ERROR, __VA_ARGS__)
      |                                                                                                  ^~~~~~~~~~~
/home/mcuee/build/avrdude_git/src/linuxgpio.c:419:7: warning: implicit declaration of function ‘gpiod_line_release’; did you mean ‘gpiod_line_request_release’? [-Wimplicit-function-declaration]
  419 |       gpiod_line_release(linuxgpio_libgpiod_lines[i]);
      |       ^~~~~~~~~~~~~~~~~~
      |       gpiod_line_request_release
/home/mcuee/build/avrdude_git/src/linuxgpio.c: In function ‘linuxgpio_libgpiod_setpin’:
/home/mcuee/build/avrdude_git/src/linuxgpio.c:451:11: warning: implicit declaration of function ‘gpiod_line_set_value’; did you mean ‘pin_set_value’? [-Wimplicit-function-declaration]
  451 |   int r = gpiod_line_set_value(linuxgpio_libgpiod_lines[pinfunc], value);
      |           ^~~~~~~~~~~~~~~~~~~~
      |           pin_set_value
/home/mcuee/build/avrdude_git/src/linuxgpio.c: In function ‘linuxgpio_libgpiod_getpin’:
/home/mcuee/build/avrdude_git/src/linuxgpio.c:477:11: warning: implicit declaration of function ‘gpiod_line_get_value’ [-Wimplicit-function-declaration]
  477 |   int r = gpiod_line_get_value(linuxgpio_libgpiod_lines[pinfunc]);
      |           ^~~~~~~~~~~~~~~~~~~~
[ 39%] Building C object src/CMakeFiles/libavrdude.dir/linuxspi.c.o
[ 40%] Building C object src/CMakeFiles/libavrdude.dir/lists.c.o
[ 42%] Building C object src/CMakeFiles/libavrdude.dir/micronucleus.c.o
[ 43%] Building C object src/CMakeFiles/libavrdude.dir/par.c.o
[ 44%] Building C object src/CMakeFiles/libavrdude.dir/pgm.c.o
[ 46%] Building C object src/CMakeFiles/libavrdude.dir/pgm_type.c.o
[ 47%] Building C object src/CMakeFiles/libavrdude.dir/pickit2.c.o
[ 48%] Building C object src/CMakeFiles/libavrdude.dir/pindefs.c.o
[ 50%] Building C object src/CMakeFiles/libavrdude.dir/ppi.c.o
[ 51%] Building C object src/CMakeFiles/libavrdude.dir/ppiwin.c.o
[ 52%] Building C object src/CMakeFiles/libavrdude.dir/serbb_posix.c.o
[ 53%] Building C object src/CMakeFiles/libavrdude.dir/serbb_win32.c.o
[ 55%] Building C object src/CMakeFiles/libavrdude.dir/ser_avrdoper.c.o
[ 56%] Building C object src/CMakeFiles/libavrdude.dir/ser_posix.c.o
[ 57%] Building C object src/CMakeFiles/libavrdude.dir/ser_win32.c.o
[ 59%] Building C object src/CMakeFiles/libavrdude.dir/serialadapter.c.o
[ 60%] Building C object src/CMakeFiles/libavrdude.dir/serialupdi.c.o
[ 61%] Building C object src/CMakeFiles/libavrdude.dir/stk500.c.o
[ 63%] Building C object src/CMakeFiles/libavrdude.dir/stk500v2.c.o
[ 64%] Building C object src/CMakeFiles/libavrdude.dir/stk500generic.c.o
[ 65%] Building C object src/CMakeFiles/libavrdude.dir/strutil.c.o
[ 67%] Building C object src/CMakeFiles/libavrdude.dir/teensy.c.o
[ 68%] Building C object src/CMakeFiles/libavrdude.dir/term.c.o
[ 69%] Building C object src/CMakeFiles/libavrdude.dir/updi_link.c.o
[ 71%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm.c.o
[ 72%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm_v0.c.o
[ 73%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm_v2.c.o
[ 75%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm_v3.c.o
[ 76%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm_v4.c.o
[ 77%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm_v5.c.o
[ 78%] Building C object src/CMakeFiles/libavrdude.dir/updi_readwrite.c.o
[ 80%] Building C object src/CMakeFiles/libavrdude.dir/updi_state.c.o
[ 81%] Building C object src/CMakeFiles/libavrdude.dir/urclock.c.o
[ 82%] Building C object src/CMakeFiles/libavrdude.dir/usbasp.c.o
[ 84%] Building C object src/CMakeFiles/libavrdude.dir/usb_hidapi.c.o
[ 85%] Building C object src/CMakeFiles/libavrdude.dir/usb_libusb.c.o
[ 86%] Building C object src/CMakeFiles/libavrdude.dir/usbtiny.c.o
[ 88%] Building C object src/CMakeFiles/libavrdude.dir/update.c.o
[ 89%] Building C object src/CMakeFiles/libavrdude.dir/wiring.c.o
[ 90%] Building C object src/CMakeFiles/libavrdude.dir/xbee.c.o
[ 92%] Building C object src/CMakeFiles/libavrdude.dir/__/lexer.c.o
[ 93%] Building C object src/CMakeFiles/libavrdude.dir/__/config_gram.c.o
[ 94%] Linking C static library libavrdude.a
[ 94%] Built target libavrdude
[ 96%] Building C object src/CMakeFiles/avrdude.dir/main.c.o
[ 97%] Building C object src/CMakeFiles/avrdude.dir/developer_opts.c.o
[ 98%] Building C object src/CMakeFiles/avrdude.dir/whereami.c.o
[100%] Linking C executable avrdude
/usr/bin/ld: libavrdude.a(linuxgpio.c.o): in function `linuxgpio_libgpiod_highpulsepin':
/home/mcuee/build/avrdude_git/src/linuxgpio.c:498: undefined reference to `gpiod_line_set_value'
/usr/bin/ld: /home/mcuee/build/avrdude_git/src/linuxgpio.c:504: undefined reference to `gpiod_line_set_value'
/usr/bin/ld: libavrdude.a(linuxgpio.c.o): in function `linuxgpio_libgpiod_getpin':
/home/mcuee/build/avrdude_git/src/linuxgpio.c:477: undefined reference to `gpiod_line_get_value'
/usr/bin/ld: /home/mcuee/build/avrdude_git/src/linuxgpio.c:479: undefined reference to `gpiod_line_name'
/usr/bin/ld: libavrdude.a(linuxgpio.c.o): in function `linuxgpio_libgpiod_setpin':
/home/mcuee/build/avrdude_git/src/linuxgpio.c:451: undefined reference to `gpiod_line_set_value'
/usr/bin/ld: /home/mcuee/build/avrdude_git/src/linuxgpio.c:453: undefined reference to `gpiod_line_name'
/usr/bin/ld: libavrdude.a(linuxgpio.c.o): in function `linuxgpio_libgpiod_close':
/home/mcuee/build/avrdude_git/src/linuxgpio.c:415: undefined reference to `gpiod_line_set_direction_input'
/usr/bin/ld: /home/mcuee/build/avrdude_git/src/linuxgpio.c:419: undefined reference to `gpiod_line_release'
/usr/bin/ld: /home/mcuee/build/avrdude_git/src/linuxgpio.c:426: undefined reference to `gpiod_line_set_direction_input'
/usr/bin/ld: /home/mcuee/build/avrdude_git/src/linuxgpio.c:430: undefined reference to `gpiod_line_release'
/usr/bin/ld: /home/mcuee/build/avrdude_git/src/linuxgpio.c:417: undefined reference to `gpiod_line_name'
/usr/bin/ld: /home/mcuee/build/avrdude_git/src/linuxgpio.c:428: undefined reference to `gpiod_line_name'
/usr/bin/ld: libavrdude.a(linuxgpio.c.o): in function `linuxgpio_libgpiod_open':
/home/mcuee/build/avrdude_git/src/linuxgpio.c:385: undefined reference to `gpiod_line_get'
/usr/bin/ld: /home/mcuee/build/avrdude_git/src/linuxgpio.c:395: undefined reference to `gpiod_line_request_output'
/usr/bin/ld: /home/mcuee/build/avrdude_git/src/linuxgpio.c:393: undefined reference to `gpiod_line_request_input'
collect2: error: ld returned 1 exit status
gmake[2]: *** [src/CMakeFiles/avrdude.dir/build.make:139: src/avrdude] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:154: src/CMakeFiles/avrdude.dir/all] Error 2
gmake: *** [Makefile:136: all] Error 2
Build failed.

@mcuee
Copy link
Collaborator

mcuee commented Apr 6, 2024

But this PR is good.

mcuee@raspberrypi400arm64:~/build/avrdude_pr1725 $ ./build.sh 
-- The C compiler identification is GNU 12.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found Git: /usr/bin/git (found version "2.39.2") 
-- Found FLEX: /usr/bin/flex (found version "2.6.4") 
-- Found BISON: /usr/bin/bison (found version "3.8.2")
-- Looking for libelf.h
-- Looking for libelf.h - found
-- Looking for libelf/libelf.h
-- Looking for libelf/libelf.h - not found
-- Looking for usb.h
-- Looking for usb.h - found
-- Looking for lusb0_usb.h
-- Looking for lusb0_usb.h - not found
-- Looking for libusb.h
-- Looking for libusb.h - not found
-- Looking for libusb-1.0/libusb.h
-- Looking for libusb-1.0/libusb.h - found
-- Looking for hidapi/hidapi.h
-- Looking for hidapi/hidapi.h - found
-- Looking for ftdi_tcioflush
-- Looking for ftdi_tcioflush - found
-- Found PkgConfig: /usr/bin/pkg-config (found version "1.8.1") 
-- Checking for module 'libgpiod>=2.0'
--   Found libgpiod, version 2.2
-- Configuration summary:
-- ----------------------
-- DO HAVE    libelf
-- DO HAVE    libusb
-- DO HAVE    libusb_1_0
-- DO HAVE    libhidapi
-- DON'T HAVE libftdi
-- DO HAVE    libftdi1
-- DO HAVE    libreadline
-- DO HAVE    libserialport
-- DISABLED   doc
-- DISABLED   parport
-- ENABLED    linuxgpio
-- DO HAVE    libgpiod (v2.x)
-- ENABLED    linuxspi
-- ----------------------
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mcuee/build/avrdude_pr1725/build_linux
[  1%] Generating avrdude.conf
[  1%] Built target conf
[  2%] [FLEX][Parser] Building scanner with flex 2.6.4
[  3%] [BISON][Parser] Building parser with bison 3.8.2
[  5%] Building C object src/CMakeFiles/libavrdude.dir/arduino.c.o
[  6%] Building C object src/CMakeFiles/libavrdude.dir/avr.c.o
[  7%] Building C object src/CMakeFiles/libavrdude.dir/avr910.c.o
[  9%] Building C object src/CMakeFiles/libavrdude.dir/avrcache.c.o
[ 10%] Building C object src/CMakeFiles/libavrdude.dir/avrftdi.c.o
[ 11%] Building C object src/CMakeFiles/libavrdude.dir/avrftdi_tpi.c.o
[ 13%] Building C object src/CMakeFiles/libavrdude.dir/avrintel.c.o
[ 14%] Building C object src/CMakeFiles/libavrdude.dir/avrpart.c.o
[ 15%] Building C object src/CMakeFiles/libavrdude.dir/bitbang.c.o
[ 17%] Building C object src/CMakeFiles/libavrdude.dir/buspirate.c.o
[ 18%] Building C object src/CMakeFiles/libavrdude.dir/butterfly.c.o
[ 19%] Building C object src/CMakeFiles/libavrdude.dir/ch341a.c.o
[ 21%] Building C object src/CMakeFiles/libavrdude.dir/config.c.o
[ 22%] Building C object src/CMakeFiles/libavrdude.dir/confwin.c.o
[ 23%] Building C object src/CMakeFiles/libavrdude.dir/crc16.c.o
[ 25%] Building C object src/CMakeFiles/libavrdude.dir/dfu.c.o
[ 26%] Building C object src/CMakeFiles/libavrdude.dir/dryrun.c.o
[ 27%] Building C object src/CMakeFiles/libavrdude.dir/fileio.c.o
[ 28%] Building C object src/CMakeFiles/libavrdude.dir/flip1.c.o
[ 30%] Building C object src/CMakeFiles/libavrdude.dir/flip2.c.o
[ 31%] Building C object src/CMakeFiles/libavrdude.dir/ft245r.c.o
[ 32%] Building C object src/CMakeFiles/libavrdude.dir/jtagmkI.c.o
[ 34%] Building C object src/CMakeFiles/libavrdude.dir/jtagmkII.c.o
[ 35%] Building C object src/CMakeFiles/libavrdude.dir/jtag3.c.o
[ 36%] Building C object src/CMakeFiles/libavrdude.dir/leds.c.o
[ 38%] Building C object src/CMakeFiles/libavrdude.dir/linuxgpio.c.o
[ 39%] Building C object src/CMakeFiles/libavrdude.dir/linuxspi.c.o
[ 40%] Building C object src/CMakeFiles/libavrdude.dir/lists.c.o
[ 42%] Building C object src/CMakeFiles/libavrdude.dir/micronucleus.c.o
[ 43%] Building C object src/CMakeFiles/libavrdude.dir/par.c.o
[ 44%] Building C object src/CMakeFiles/libavrdude.dir/pgm.c.o
[ 46%] Building C object src/CMakeFiles/libavrdude.dir/pgm_type.c.o
[ 47%] Building C object src/CMakeFiles/libavrdude.dir/pickit2.c.o
[ 48%] Building C object src/CMakeFiles/libavrdude.dir/pindefs.c.o
[ 50%] Building C object src/CMakeFiles/libavrdude.dir/ppi.c.o
[ 51%] Building C object src/CMakeFiles/libavrdude.dir/ppiwin.c.o
[ 52%] Building C object src/CMakeFiles/libavrdude.dir/serbb_posix.c.o
[ 53%] Building C object src/CMakeFiles/libavrdude.dir/serbb_win32.c.o
[ 55%] Building C object src/CMakeFiles/libavrdude.dir/ser_avrdoper.c.o
[ 56%] Building C object src/CMakeFiles/libavrdude.dir/ser_posix.c.o
[ 57%] Building C object src/CMakeFiles/libavrdude.dir/ser_win32.c.o
[ 59%] Building C object src/CMakeFiles/libavrdude.dir/serialadapter.c.o
[ 60%] Building C object src/CMakeFiles/libavrdude.dir/serialupdi.c.o
[ 61%] Building C object src/CMakeFiles/libavrdude.dir/stk500.c.o
[ 63%] Building C object src/CMakeFiles/libavrdude.dir/stk500v2.c.o
[ 64%] Building C object src/CMakeFiles/libavrdude.dir/stk500generic.c.o
[ 65%] Building C object src/CMakeFiles/libavrdude.dir/strutil.c.o
[ 67%] Building C object src/CMakeFiles/libavrdude.dir/teensy.c.o
[ 68%] Building C object src/CMakeFiles/libavrdude.dir/term.c.o
[ 69%] Building C object src/CMakeFiles/libavrdude.dir/updi_link.c.o
[ 71%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm.c.o
[ 72%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm_v0.c.o
[ 73%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm_v2.c.o
[ 75%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm_v3.c.o
[ 76%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm_v4.c.o
[ 77%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm_v5.c.o
[ 78%] Building C object src/CMakeFiles/libavrdude.dir/updi_readwrite.c.o
[ 80%] Building C object src/CMakeFiles/libavrdude.dir/updi_state.c.o
[ 81%] Building C object src/CMakeFiles/libavrdude.dir/urclock.c.o
[ 82%] Building C object src/CMakeFiles/libavrdude.dir/usbasp.c.o
[ 84%] Building C object src/CMakeFiles/libavrdude.dir/usb_hidapi.c.o
[ 85%] Building C object src/CMakeFiles/libavrdude.dir/usb_libusb.c.o
[ 86%] Building C object src/CMakeFiles/libavrdude.dir/usbtiny.c.o
[ 88%] Building C object src/CMakeFiles/libavrdude.dir/update.c.o
[ 89%] Building C object src/CMakeFiles/libavrdude.dir/wiring.c.o
[ 90%] Building C object src/CMakeFiles/libavrdude.dir/xbee.c.o
[ 92%] Building C object src/CMakeFiles/libavrdude.dir/__/lexer.c.o
[ 93%] Building C object src/CMakeFiles/libavrdude.dir/__/config_gram.c.o
[ 94%] Linking C static library libavrdude.a
[ 94%] Built target libavrdude
[ 96%] Building C object src/CMakeFiles/avrdude.dir/main.c.o
[ 97%] Building C object src/CMakeFiles/avrdude.dir/developer_opts.c.o
[ 98%] Building C object src/CMakeFiles/avrdude.dir/whereami.c.o
[100%] Linking C executable avrdude
[100%] Built target avrdude

Build succeeded.

Run

sudo cmake --build build_linux --target install

to install.

@mcuee
Copy link
Collaborator

mcuee commented Apr 6, 2024

@mhei

However, this PR does not seem to work. I will check later.

mcuee@raspberrypi400arm64:~/build/avrdude_pr1725/build_linux/src $ ./avrdude -c linuxgpio -P gpiochip0 -p m328p
using libgpiod for linuxgpio
failed to open gpiochip0 line 25: No such file or directory
avrdude error: unable to open port gpiochip0 for programmer linuxgpio

avrdude done.  Thank you.

I am testing PR #1714 and it works.

mcuee@raspberrypi400arm64:~/build/avrdude_jw/build_linux/src $ ./avrdude -c linuxgpio -P gpiochip0 -p m328p
using libgpiod for linuxgpio
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e950f (probably m328p)

avrdude done.  Thank you.

@mcuee
Copy link
Collaborator

mcuee commented Apr 7, 2024

@SebKuzminsky

Just wondering if you can review this PR as well. Thanks.

As of now, it does not seem to work with my Raspberry Pi 400.

On the other hand, the current git main does not seem to be compatible with the libgpiod v2+ API. So we may need to improve this PR to get it working,

@mhei mhei force-pushed the support-for-libgpiodv2 branch from 4722745 to f2df416 Compare April 7, 2024 19:56
@mhei
Copy link
Contributor Author

mhei commented Apr 7, 2024

failed to open gpiochip0 line 25: No such file or directory

Stupid error on my side, sorry for this. This should be fixed now.
Meanwhile, I now have access to a AVR based device but need to build some level shifting so that I can also test with Raspi...

@mcuee
Copy link
Collaborator

mcuee commented Apr 8, 2024

Somehow it is still not working.

mcuee@raspberrypi400arm64:~/build/avrdude_pr1725/build_linux/src $ ldd ./avrdude
	linux-vdso.so.1 (0x0000007f9b1dc000)
	libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000007f9ac30000)
	libelf.so.1 => /lib/aarch64-linux-gnu/libelf.so.1 (0x0000007f9abf0000)
	libusb-0.1.so.4 => /usr/local/lib/libusb-0.1.so.4 (0x0000007f9abc0000)
	libusb-1.0.so.0 => /usr/local/lib/libusb-1.0.so.0 (0x0000007f9ab80000)
	libhidapi-libusb.so.0 => /usr/local/lib/libhidapi-libusb.so.0 (0x0000007f9ab50000)
	libftdi1.so.2 => /usr/local/lib/libftdi1.so.2 (0x0000007f9ab20000)
	libreadline.so.8 => /lib/aarch64-linux-gnu/libreadline.so.8 (0x0000007f9aaa0000)
	libserialport.so.0 => /lib/aarch64-linux-gnu/libserialport.so.0 (0x0000007f9aa70000)
	libgpiod.so.3 => /usr/local/lib/libgpiod.so.3 (0x0000007f9aa40000)
	libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000007f9a890000)
	/lib/ld-linux-aarch64.so.1 (0x0000007f9b19f000)
	libz.so.1 => /lib/aarch64-linux-gnu/libz.so.1 (0x0000007f9a850000)
	libudev.so.1 => /lib/aarch64-linux-gnu/libudev.so.1 (0x0000007f9a800000)
	libtinfo.so.6 => /lib/aarch64-linux-gnu/libtinfo.so.6 (0x0000007f9a7b0000)

mcuee@raspberrypi400arm64:~/build/avrdude_pr1725/build_linux/src $ gpiodetect 
gpiochip0 [pinctrl-bcm2711] (58 lines)
gpiochip1 [raspberrypi-exp-gpio] (8 lines)

mcuee@raspberrypi400arm64:~/build/avrdude_pr1725/build_linux/src $ ./avrdude -c linuxgpio -P gpiochip0 -p m328p -v

avrdude: Version 7.3-20240407 (f2df4169)
         Copyright the AVRDUDE authors;
         see https://github.com/avrdudes/avrdude/blob/main/AUTHORS

         System wide configuration file is /home/mcuee/build/avrdude_pr1725/build_linux/src/avrdude.conf
         User configuration file is /home/mcuee/.avrduderc
         User configuration file does not exist or is not a regular file, skipping

using libgpiod for linuxgpio
         Using port            : gpiochip0
         Using programmer      : linuxgpio
failed to open gpiochip0 line 25: No such file or directory
avrdude main() error: unable to open port gpiochip0 for programmer linuxgpio

avrdude done.  Thank you.

mcuee@raspberrypi400arm64:~/build/avrdude_pr1725/build_linux/src $ gpioinfo
gpiochip0 - 58 lines:
	line   0:	"ID_SDA"        	input
	line   1:	"ID_SCL"        	input
	line   2:	"GPIO2"         	input
	line   3:	"GPIO3"         	input
	line   4:	"GPIO4"         	input
	line   5:	"GPIO5"         	input
	line   6:	"GPIO6"         	input
	line   7:	"GPIO7"         	output active-low consumer="spi0 CS1"
	line   8:	"GPIO8"         	output active-low consumer="spi0 CS0"
	line   9:	"GPIO9"         	input
	line  10:	"GPIO10"        	input
	line  11:	"GPIO11"        	input
	line  12:	"GPIO12"        	input
	line  13:	"GPIO13"        	input
	line  14:	"GPIO14"        	input
	line  15:	"GPIO15"        	input
	line  16:	"GPIO16"        	input
	line  17:	"GPIO17"        	input
	line  18:	"GPIO18"        	input
	line  19:	"GPIO19"        	input
	line  20:	"GPIO20"        	input
	line  21:	"GPIO21"        	input
	line  22:	"GPIO22"        	input
	line  23:	"GPIO23"        	input
	line  24:	"GPIO24"        	input
	line  25:	"GPIO25"        	input
	line  26:	"GPIO26"        	input
	line  27:	"GPIO27"        	input
	line  28:	"RGMII_MDIO"    	input
	line  29:	"RGMIO_MDC"     	input
	line  30:	"CTS0"          	input
	line  31:	"RTS0"          	input
	line  32:	"TXD0"          	input
	line  33:	"RXD0"          	input
	line  34:	"SD1_CLK"       	input
	line  35:	"SD1_CMD"       	input
	line  36:	"SD1_DATA0"     	input
	line  37:	"SD1_DATA1"     	input
	line  38:	"SD1_DATA2"     	input
	line  39:	"SD1_DATA3"     	input
	line  40:	"PWM0_MISO"     	input
	line  41:	"PWM1_MOSI"     	input
	line  42:	"STATUS_LED_G_CLK"	output consumer="PWR"
	line  43:	"SPIFLASH_CE_N" 	input
	line  44:	"SDA0"          	input
	line  45:	"SCL0"          	input
	line  46:	"RGMII_RXCLK"   	input
	line  47:	"RGMII_RXCTL"   	input
	line  48:	"RGMII_RXD0"    	input
	line  49:	"RGMII_RXD1"    	input
	line  50:	"RGMII_RXD2"    	input
	line  51:	"RGMII_RXD3"    	input
	line  52:	"RGMII_TXCLK"   	input
	line  53:	"RGMII_TXCTL"   	input
	line  54:	"RGMII_TXD0"    	input
	line  55:	"RGMII_TXD1"    	input
	line  56:	"RGMII_TXD2"    	input
	line  57:	"RGMII_TXD3"    	input
gpiochip1 - 8 lines:
	line   0:	"BT_ON"         	output consumer="shutdown"
	line   1:	"WL_ON"         	output
	line   2:	"PWR_LED_OFF"   	output
	line   3:	"GLOBAL_RESET"  	output
	line   4:	"VDD_SD_IO_SEL" 	output consumer="vdd-sd-io"
	line   5:	"GLOBAL_SHUTDOWN"	output consumer="gpio-poweroff"
	line   6:	"SD_PWR_ON"     	output consumer="regulator-sd-vcc"
	line   7:	"SHUTDOWN_REQUEST"	input

@mhei
Copy link
Contributor Author

mhei commented Apr 11, 2024

Thanks again, I'll have a look next weekend.

@mhei mhei force-pushed the support-for-libgpiodv2 branch from f2df416 to ddcc52b Compare April 11, 2024 18:14
@mhei
Copy link
Contributor Author

mhei commented Apr 11, 2024

It gave me no peace before weekend.
I installed latest master of libgpiod.

root@raspberrypi:~/avrdude.git# git log --abbrev-commit --oneline HEAD^..HEAD
ddcc52bb (HEAD -> support-for-libgpiodv2, github/support-for-libgpiodv2) Add support for libgpiod v2+ API


root@raspberrypi:~/avrdude.git# ldd build_linux/src/avrdude
        linux-vdso.so.1 (0x0000007fbd198000)
        libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000007fbcc20000)
        libgpiod.so.3 => /usr/local/lib/libgpiod.so.3 (0x0000007fbcbf0000)
        libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000007fbca40000)
        /lib/ld-linux-aarch64.so.1 (0x0000007fbd15b000)

        
root@raspberrypi:~/avrdude.git# build_linux/src/avrdude -C build_linux/src/avrdude.conf -c raspberry_pi_gpio  -p m32 -B 1kHz -U flash:r:/tmp/usbprog.hex
using libgpiod for linuxgpio
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9502 (probably m32)

avrdude: processing -U flash:r:/tmp/usbprog.hex:r
avrdude: reading flash memory ...
Reading | ################################################## | 100% 3.88 s 
avrdude: writing output file /tmp/usbprog.hex

avrdude done.  Thank you.

root@raspberrypi:~/avrdude.git# hexdump -C /tmp/usbprog.hex
...
00007ee0  0f be 01 96 08 95 f8 94  ff cf 00 55 53 42 70 72  |...........USBpr|
00007ef0  6f 67 20 45 6d 62 65 64  64 65 64 50 72 6f 6a 65  |og EmbeddedProje|
00007f00  63 74 73 00 75 73 62 70  72 6f 67 42 61 73 65 20  |cts.usbprogBase |
00007f10  4d 6f 64 65 00 12 01 10  01 00 00 00 08 81 17 62  |Mode...........b|
...

So at least reading the flash looks good to me.

Then I switched over to the libgpiod-dev which comes as Debian package for Raspberry Pi OS. It could read the flash as well, compared the two files with sha256sum showed same hash.
I'm struggling with sysfs fallback, though:

avrdude OS error: cannot export GPIO 22, already exported/busy?: Invalid argument
avrdude error: unable to open port gpiochip0 for programmer raspberry_pi_gpio

But I also cannot export the GPIO manually, I've to check later.

@mcuee
Copy link
Collaborator

mcuee commented Apr 13, 2024

Then I switched over to the libgpiod-dev which comes as Debian package for Raspberry Pi OS. It could read the flash as well, compared the two files with sha256sum showed same hash.

Nice, that is a good progress.

I'm struggling with sysfs fallback, though:

avrdude OS error: cannot export GPIO 22, already exported/busy?: Invalid argument
avrdude error: unable to open port gpiochip0 for programmer raspberry_pi_gpio

But I also cannot export the GPIO manually, I've to check later.

It may be an existing problem. You may have to reboot the Raspberry Pi and see if the fall-back is working or not.

The following PR makes the sysfs interface a bit better but not sorted out all the issue. libgpiod is the way to go.

So PR #1299 was merged and it makes the situation much better.

Now with libgpiod v2+ API change, I think your PR will be a good improvement.

@stefanrueger
Copy link
Collaborator

@mhei Thanks for the PR; @mcuee What is the status of this PR? Ready to be merged?

@mcuee
Copy link
Collaborator

mcuee commented Apr 13, 2024

@mhei Thanks for the PR; @mcuee What is the status of this PR? Ready to be merged?

Not yet. I will carry out some tests tomorrow to see if it is already good or not. I'd like to hear from @mhei on his testing results as well.

@mhei
Copy link
Contributor Author

mhei commented Apr 13, 2024

I found the reason, why the original/example configuration file does not work anymore. I'm using a Raspberry Pi 4 with latest image and the GPIO numbers changed. After a quick search I stumbled over e.g. raspberrypi/linux#5668 where a reason for renumbering is given.
When we look at the following output:

root@raspberrypi:~# ls -la /sys/class/gpio
total 0
drwxrwxr-x  2 root gpio    0 Apr 13 13:32 .
drwxr-xr-x 65 root root    0 Jan  1  1970 ..
--w--w----  1 root gpio 4096 Apr 13 13:29 export
lrwxrwxrwx  1 root gpio    0 Apr 11 19:17 gpiochip512 -> ../../devices/platform/soc/fe200000.gpio/gpio/gpiochip512
lrwxrwxrwx  1 root gpio    0 Apr 11 19:17 gpiochip570 -> ../../devices/platform/soc/soc:firmware/soc:firmware:gpio/gpio/gpiochip570
--w--w----  1 root gpio 4096 Apr 13 13:29 unexport

we see that the first gpiochip is now with offset 512. That means, that we need to add 512 to all GPIO numbers in the config file when using sysfs. When using libgpiod, then the GPIO numbers to use are just the offsets within the relevant gpiochip, so we can stay with the current numbers.
A quick solution could be to provide two configuration file sections and/or mention this in documentation.

Thanks so far for all your patience and testing, really appreciated.

@mcuee
Copy link
Collaborator

mcuee commented Apr 13, 2024

A quick solution could be to provide two configuration file sections and/or mention this in documentation.

Good finding. Thanks for the updates. I think this is a sensible solution.

@stefanrueger
Copy link
Collaborator

stefanrueger commented Apr 13, 2024

A quick solution could be to provide two configuration file sections and/or mention this in documentation.

Better to figure out from the kernel what the base number is. How would a user otherwise know which configuration to use?

@mhei
Copy link
Contributor Author

mhei commented Apr 13, 2024

Better to figure out from the kernel what the base number is.

For the sysfs case, figuring out means that you have to look in the directory /sys/class/gpio to see what gpiochipXYZ devices are available. The default "port" (compiled in) is "gpiochip0". The simplest way for the user would be to just override the default by giving "gpiochip512". Then it would be possible to use the value from the port string as offset while opening the pins.

But this is not 1:1 compatible with the libgpiod path: since /sys/class/gpio/gpiochip512 is registered as /dev/gpiochip0 character device, the valid configuration when using libgpiod would still be using port "gpiochip0", because libgpiod does not bother with /sys/class/gpio stuff at all.

So what should be the goal here? Same config works with both ways?

@stefanrueger
Copy link
Collaborator

So what should be the goal here?

That it just works™. Assuming that AVRDUDE can write some code to figure out what the GPIO offset is with each kernel version, old or new, it would be much better to let AVRDUDE figure out how to get to the pins rather than each and every user having to know what the kernel does and which config entry to use as a consequence. It's linuxgpio, so I am assuming we don't need to worry too much about many differet platforms.

Same config works with both ways?

Yes, that would be great.

I am not in a position to write that code, but it looks like it must be possible. Would you like to give it a go, @mhei?

@mcuee
Copy link
Collaborator

mcuee commented Apr 14, 2024

@stefanrueger
The sysfs change is actutally another thing, not really related to this PR (libgpiod API change).

In fact I am favoring to remove the sysfs support since it has been deprecated for quite a while and will become a maintenance nightmare for a small project like avrdude.

Reference:
WiringPi/WiringPi#186

@mcuee
Copy link
Collaborator

mcuee commented Apr 14, 2024

@stefanrueger and @mhei

Removing sysfs support is my recommendation. But if it is not too troublesome, then I am fine with keeping the sysfs support as well.

The problem is that there are many Single Board Computers out there and I am not so sure if we can support them well, since they may use a modified kernel. As of now, we mainly support Raspberry Pi series and we rely on the users of other boards (eg: Orange Pi) to report the issue and even fix the issue.

BTW, probably the following issue is also related to sysfs change. But once the user switches to libgpio, the problem got resolved.

I am not so sure if the following issue is also related to sysfs. I have posted the question back to the issue reporter.

@mcuee
Copy link
Collaborator

mcuee commented Apr 14, 2024

@stefanrueger and @mhei

Yet another option is to keep sysfs code as it is (only working with older kernel version). New kernel version users will be required to use libgpiod.

I tend to think this is probably a good compromise. How do you like the idea?

@mcuee
Copy link
Collaborator

mcuee commented Apr 14, 2024

@mhei

Now this PR works well for libgpiod v2+ API change.

mcuee@raspberrypi400arm64:~/build/avrdude_pr1725 $ ./build.sh 
-- The C compiler identification is GNU 12.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found Git: /usr/bin/git (found version "2.39.2") 
-- Found FLEX: /usr/bin/flex (found version "2.6.4") 
-- Found BISON: /usr/bin/bison (found version "3.8.2")
-- Looking for libelf.h
-- Looking for libelf.h - found
-- Looking for libelf/libelf.h
-- Looking for libelf/libelf.h - not found
-- Looking for usb.h
-- Looking for usb.h - found
-- Looking for lusb0_usb.h
-- Looking for lusb0_usb.h - not found
-- Looking for libusb.h
-- Looking for libusb.h - not found
-- Looking for libusb-1.0/libusb.h
-- Looking for libusb-1.0/libusb.h - found
-- Looking for hidapi/hidapi.h
-- Looking for hidapi/hidapi.h - found
-- Looking for ftdi_tcioflush
-- Looking for ftdi_tcioflush - found
-- Found PkgConfig: /usr/bin/pkg-config (found version "1.8.1") 
-- Checking for module 'libgpiod>=2.0'
--   Found libgpiod, version 2.2
-- Configuration summary:
-- ----------------------
-- DO HAVE    libelf
-- DO HAVE    libusb
-- DO HAVE    libusb_1_0
-- DO HAVE    libhidapi
-- DON'T HAVE libftdi
-- DO HAVE    libftdi1
-- DO HAVE    libreadline
-- DO HAVE    libserialport
-- DISABLED   doc
-- DISABLED   parport
-- ENABLED    linuxgpio
-- DO HAVE    libgpiod (v2.x)
-- ENABLED    linuxspi
-- ----------------------
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mcuee/build/avrdude_pr1725/build_linux
[  1%] Generating avrdude.conf
[  1%] Built target conf
[  2%] [FLEX][Parser] Building scanner with flex 2.6.4
[  3%] [BISON][Parser] Building parser with bison 3.8.2
[  5%] Building C object src/CMakeFiles/libavrdude.dir/arduino.c.o
[  6%] Building C object src/CMakeFiles/libavrdude.dir/avr.c.o
[  7%] Building C object src/CMakeFiles/libavrdude.dir/avr910.c.o
[  9%] Building C object src/CMakeFiles/libavrdude.dir/avrcache.c.o
[ 10%] Building C object src/CMakeFiles/libavrdude.dir/avrftdi.c.o
[ 11%] Building C object src/CMakeFiles/libavrdude.dir/avrftdi_tpi.c.o
[ 13%] Building C object src/CMakeFiles/libavrdude.dir/avrintel.c.o
[ 14%] Building C object src/CMakeFiles/libavrdude.dir/avrpart.c.o
[ 15%] Building C object src/CMakeFiles/libavrdude.dir/bitbang.c.o
[ 17%] Building C object src/CMakeFiles/libavrdude.dir/buspirate.c.o
[ 18%] Building C object src/CMakeFiles/libavrdude.dir/butterfly.c.o
[ 19%] Building C object src/CMakeFiles/libavrdude.dir/ch341a.c.o
[ 21%] Building C object src/CMakeFiles/libavrdude.dir/config.c.o
[ 22%] Building C object src/CMakeFiles/libavrdude.dir/confwin.c.o
[ 23%] Building C object src/CMakeFiles/libavrdude.dir/crc16.c.o
[ 25%] Building C object src/CMakeFiles/libavrdude.dir/dfu.c.o
[ 26%] Building C object src/CMakeFiles/libavrdude.dir/dryrun.c.o
[ 27%] Building C object src/CMakeFiles/libavrdude.dir/fileio.c.o
[ 28%] Building C object src/CMakeFiles/libavrdude.dir/flip1.c.o
[ 30%] Building C object src/CMakeFiles/libavrdude.dir/flip2.c.o
/[ 31%] Building C object src/CMakeFiles/libavrdude.dir/ft245r.c.o
[ 32%] Building C object src/CMakeFiles/libavrdude.dir/jtagmkI.c.o
[ 34%] Building C object src/CMakeFiles/libavrdude.dir/jtagmkII.c.o
[ 35%] Building C object src/CMakeFiles/libavrdude.dir/jtag3.c.o
[ 36%] Building C object src/CMakeFiles/libavrdude.dir/leds.c.o
[ 38%] Building C object src/CMakeFiles/libavrdude.dir/linuxgpio.c.o
[ 39%] Building C object src/CMakeFiles/libavrdude.dir/linuxspi.c.o
[ 40%] Building C object src/CMakeFiles/libavrdude.dir/lists.c.o
[ 42%] Building C object src/CMakeFiles/libavrdude.dir/micronucleus.c.o
[ 43%] Building C object src/CMakeFiles/libavrdude.dir/par.c.o
[ 44%] Building C object src/CMakeFiles/libavrdude.dir/pgm.c.o
[ 46%] Building C object src/CMakeFiles/libavrdude.dir/pgm_type.c.o
[ 47%] Building C object src/CMakeFiles/libavrdude.dir/pickit2.c.o
[ 48%] Building C object src/CMakeFiles/libavrdude.dir/pindefs.c.o
[ 50%] Building C object src/CMakeFiles/libavrdude.dir/ppi.c.o
[ 51%] Building C object src/CMakeFiles/libavrdude.dir/ppiwin.c.o
[ 52%] Building C object src/CMakeFiles/libavrdude.dir/serbb_posix.c.o
[ 53%] Building C object src/CMakeFiles/libavrdude.dir/serbb_win32.c.o
[ 55%] Building C object src/CMakeFiles/libavrdude.dir/ser_avrdoper.c.o
[ 56%] Building C object src/CMakeFiles/libavrdude.dir/ser_posix.c.o
[ 57%] Building C object src/CMakeFiles/libavrdude.dir/ser_win32.c.o
[ 59%] Building C object src/CMakeFiles/libavrdude.dir/serialadapter.c.o
[ 60%] Building C object src/CMakeFiles/libavrdude.dir/serialupdi.c.o
[ 61%] Building C object src/CMakeFiles/libavrdude.dir/stk500.c.o
[ 63%] Building C object src/CMakeFiles/libavrdude.dir/stk500v2.c.o
[ 64%] Building C object src/CMakeFiles/libavrdude.dir/stk500generic.c.o
[ 65%] Building C object src/CMakeFiles/libavrdude.dir/strutil.c.o
[ 67%] Building C object src/CMakeFiles/libavrdude.dir/teensy.c.o
[ 68%] Building C object src/CMakeFiles/libavrdude.dir/term.c.o
[ 69%] Building C object src/CMakeFiles/libavrdude.dir/updi_link.c.o
[ 71%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm.c.o
[ 72%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm_v0.c.o
[ 73%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm_v2.c.o
[ 75%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm_v3.c.o
[ 76%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm_v4.c.o
[ 77%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm_v5.c.o
[ 78%] Building C object src/CMakeFiles/libavrdude.dir/updi_readwrite.c.o
[ 80%] Building C object src/CMakeFiles/libavrdude.dir/updi_state.c.o
[ 81%] Building C object src/CMakeFiles/libavrdude.dir/urclock.c.o
[ 82%] Building C object src/CMakeFiles/libavrdude.dir/usbasp.c.o
[ 84%] Building C object src/CMakeFiles/libavrdude.dir/usb_hidapi.c.o
[ 85%] Building C object src/CMakeFiles/libavrdude.dir/usb_libusb.c.o
[ 86%] Building C object src/CMakeFiles/libavrdude.dir/usbtiny.c.o
[ 88%] Building C object src/CMakeFiles/libavrdude.dir/update.c.o
[ 89%] Building C object src/CMakeFiles/libavrdude.dir/wiring.c.o
[ 90%] Building C object src/CMakeFiles/libavrdude.dir/xbee.c.o
[ 92%] Building C object src/CMakeFiles/libavrdude.dir/__/lexer.c.o
[ 93%] Building C object src/CMakeFiles/libavrdude.dir/__/config_gram.c.o
[ 94%] Linking C static library libavrdude.a
[ 94%] Built target libavrdude
[ 96%] Building C object src/CMakeFiles/avrdude.dir/main.c.o
[ 97%] Building C object src/CMakeFiles/avrdude.dir/developer_opts.c.o
[ 98%] Building C object src/CMakeFiles/avrdude.dir/whereami.c.o
[100%] Linking C executable avrdude
[100%] Built target avrdude

Build succeeded.

Run

sudo cmake --build build_linux --target install

to install.

mcuee@raspberrypi400arm64:~/build/avrdude_pr1725 $ cd build_linux/src/

mcuee@raspberrypi400arm64:~/build/avrdude_pr1725/build_linux/src $ ldd ./avrdude
	linux-vdso.so.1 (0x0000007fa9183000)
	libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000007fa8be0000)
	libelf.so.1 => /lib/aarch64-linux-gnu/libelf.so.1 (0x0000007fa8ba0000)
	libusb-0.1.so.4 => /usr/local/lib/libusb-0.1.so.4 (0x0000007fa8b70000)
	libusb-1.0.so.0 => /usr/local/lib/libusb-1.0.so.0 (0x0000007fa8b30000)
	libhidapi-libusb.so.0 => /usr/local/lib/libhidapi-libusb.so.0 (0x0000007fa8b00000)
	libftdi1.so.2 => /usr/local/lib/libftdi1.so.2 (0x0000007fa8ad0000)
	libreadline.so.8 => /lib/aarch64-linux-gnu/libreadline.so.8 (0x0000007fa8a50000)
	libserialport.so.0 => /lib/aarch64-linux-gnu/libserialport.so.0 (0x0000007fa8a20000)
	libgpiod.so.3 => /usr/local/lib/libgpiod.so.3 (0x0000007fa89f0000)
	libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000007fa8840000)
	/lib/ld-linux-aarch64.so.1 (0x0000007fa9146000)
	libz.so.1 => /lib/aarch64-linux-gnu/libz.so.1 (0x0000007fa8800000)
	libudev.so.1 => /lib/aarch64-linux-gnu/libudev.so.1 (0x0000007fa87b0000)
	libtinfo.so.6 => /lib/aarch64-linux-gnu/libtinfo.so.6 (0x0000007fa8760000)

mcuee@raspberrypi400arm64:~/build/avrdude_pr1725/build_linux/src $ ./avrdude -c linuxgpio -P gpiochip0 -p m328p -v

avrdude: Version 7.3-20240411 (ddcc52bb)
         Copyright the AVRDUDE authors;
         see https://github.com/avrdudes/avrdude/blob/main/AUTHORS

         System wide configuration file is /home/mcuee/build/avrdude_pr1725/build_linux/src/avrdude.conf
         User configuration file is /home/mcuee/.avrduderc
         User configuration file does not exist or is not a regular file, skipping

using libgpiod for linuxgpio
         Using port            : gpiochip0
         Using programmer      : linuxgpio
         AVR Part              : ATmega328P
         Programming modes     : ISP, HVPP, debugWIRE, SPM
         Programmer Type       : linuxgpio
         Description           : Use the Linux sysfs interface to bitbang GPIO lines
         Pin assignment        : libgpiod
           RESET   =  25
           SCK     =  11
           SDO     =  10
           SDI     =  9
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e950f (probably m328p)

avrdude done.  Thank you.

mcuee@raspberrypi400arm64:~/build/avrdude_pr1725/build_linux/src $ ./avrdude -c linuxgpio -P gpiochip0 -p m328p -U the_quick_brown_fox_256B.hex 
using libgpiod for linuxgpio
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e950f (probably m328p)
avrdude: Note: flash memory has been specified, an erase cycle will be performed.
         To disable this feature, specify the -D option.
avrdude: erasing chip

avrdude: processing -U flash:w:the_quick_brown_fox_256B.hex:i
avrdude: reading input file the_quick_brown_fox_256B.hex for flash
         with 256 bytes in 1 section within [0, 0xff]
         using 2 pages and 0 pad bytes
avrdude: writing 256 bytes flash ...
Writing | ################################################## | 100% 0.04 s 
avrdude: 256 bytes of flash written
avrdude: verifying flash memory against the_quick_brown_fox_256B.hex
Reading | ################################################## | 100% 0.03 s 
avrdude: 256 bytes of flash verified

avrdude done.  Thank you.

mcuee@raspberrypi400arm64:~/build/avrdude_pr1725/build_linux/src $ ./avrdude -c linuxgpio -P gpiochip0 -p m328p -U eeprom:w:the_quick_brown_fox_256B.hex:i
using libgpiod for linuxgpio
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e950f (probably m328p)

avrdude: processing -U eeprom:w:the_quick_brown_fox_256B.hex:i
avrdude: reading input file the_quick_brown_fox_256B.hex for eeprom
         with 256 bytes in 1 section within [0, 0xff]
         using 64 pages and 0 pad bytes
avrdude: writing 256 bytes eeprom ...
Writing | ################################################## | 100% 0.94 s 
avrdude: 256 bytes of eeprom written
avrdude: verifying eeprom memory against the_quick_brown_fox_256B.hex
Reading | ################################################## | 100% 0.03 s 
avrdude: 256 bytes of eeprom verified

avrdude done.  Thank you.

@mcuee
Copy link
Collaborator

mcuee commented Apr 14, 2024

@stefanrueger

I will suggest we merge this PR first to address the issue of libgpiod v2+ API change. The reason is that git main no longer works (linking errors) if the user's system has the upgraded libgpiod.

Then we can have another issue to address the sysfs change for new kernel version. How do you like this idea?

@mcuee
Copy link
Collaborator

mcuee commented Apr 14, 2024

we see that the first gpiochip is now with offset 512. That means, that we need to add 512 to all GPIO numbers in the config file when using sysfs. When using libgpiod, then the GPIO numbers to use are just the offsets within the relevant gpiochip, so we can stay with the current numbers.

Same here with a fully up-to-date Raspberry Pi OS installation with my Raspberry Pi 400.

mcuee@raspberrypi400arm64:~/build $ uname -a
Linux raspberrypi400arm64 6.6.20+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.20-1+rpt1 (2024-03-07) aarch64 GNU/Linux
mcuee@raspberrypi400arm64:~/build $ ls -la /sys/class/gpio
total 0
drwxrwxr-x  2 root gpio    0 Apr  8 20:06 .
drwxr-xr-x 67 root root    0 Jan  1  1970 ..
--w--w----  1 root gpio 4096 Apr  8 20:06 export
lrwxrwxrwx  1 root gpio    0 Apr  8 20:06 gpiochip512 -> ../../devices/platform/soc/fe200000.gpio/gpio/gpiochip512
lrwxrwxrwx  1 root gpio    0 Apr  8 20:06 gpiochip570 -> ../../devices/platform/soc/soc:firmware/soc:firmware:gpio/gpio/gpiochip570
--w--w----  1 root gpio 4096 Apr  8 20:06 unexport

@stefanrueger
Copy link
Collaborator

suggest we merge this PR first

OK, happy to merge during the next mergefest if

  • The older libgpiod is still supported; I guess it is as the code still uses v1 API but in case of v2 emulates the v1 calls
  • Tabs in the new code get replaced by two spaces (new code shouldn't use tabs); leave existsing tabs, though

@mhei please confirm once done

Then we can have another issue to address the sysfs change for new kernel version

@mcuee Thanks for explaining; I have looked at the code and now see that sysfs is a fallback when libgpiod is not available. According to https://www.thegoodpenguin.co.uk/blog/stop-using-sys-class-gpio-its-deprecated/ it has been deprecated since 2015, but it's OK AVRDUDE still uses /sys/class/gpio as fallback if someone compiles it on an old system without libgpiod.

src/linuxgpio.c Outdated
#ifdef HAVE_LIBGPIOD_V2

struct gpiod_line {
struct gpiod_chip *chip;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use two spaces instead of one tab

@mcuee
Copy link
Collaborator

mcuee commented Apr 14, 2024

The older libgpiod is still supported; I guess it is as the code still uses v1 API but in case of v2 emulates the v1 calls

If the user has not upgraded to the new libgpiod v2 API and still use the older v1 API, git main and this PR both work fine. Please refer to earlier comment. As of now Raspberry Pi OS still ships with older version of libgpiod library with older v1 API. And I tested this PR with the stock v1 version of libgpiod inside Rasberry Pi OS and it worked well.

If the user has upgraded to new libgpiod version, then git main will fail to link due to API change. This PR now works in this situation.

libgpiod in version 2 or above introduced an API change which results
in compile error with the current code.

This commit adds some glue magic for the newer versions and
tries to detect the used libgpiod version based on the information
available in the pkg-config files.

At the moment, this eliminates the possibility to statically link
against this library.

Signed-off-by: Michael Heimpold <[email protected]>
@mhei mhei force-pushed the support-for-libgpiodv2 branch from ddcc52b to ea701bc Compare April 14, 2024 21:49
@mhei
Copy link
Contributor Author

mhei commented Apr 14, 2024

That it just works™.

I understand the idea, but this will not work. This is a conceptual problem.
The original sysfs linux gpio API does not have the concept of gpiochips. You only have gpio numbers - you don't know how the individual gpio pins are grouped in hardware.
But ok, meanwhile we actually have the gpiochip stuff available. AVRDUDE uses the "port" mechanics to map a port name in the case of linuxgpio to a desired gpiochip, here usually gpiochip0.
Adding code to figure things out means that you ignore the configuration.
Would this be confusing for users?

As already mentioned by @mcuee, I'm unsure how the whole gpio stuff looks on other platforms (SBCs).

I think we have the following options:

  • keep current code as is: the user can switch on older OSes transparently between sysfs and libgpiod. On newer OSes the same offset must be added manually 4-times (4 pins) to the configuration file when sysfs should be used.
  • if we add logic to extract the offset from the port: since the port differs between sysfs (entry point is /sys/class/gpio) and libgpiod (entry point is /dev), the user has to provide the correct port

I would keep the current sysfs code as is. The reason is that it still gives the highest flexibility.
Consider an SBC on which a user want to use pins which are not all part of a single gpiochip.
At the moment, the configuration file format of AVRDUDE is not capable of handling this case since it would require to specify the gpiochip for every pin individually.

I'd do an AVRDUDE release with support for both libgpiod v1 and v2 support ASAP.
It is important since distros want to get rid of the libgpiod v1 stuff.
Once all relevant distros ship with libgpiod v2, support for v1 can easily be removed in AVRDUDE, sooner is better.

@stefanrueger: using two spaces instead of tabs now, thanks.

@stefanrueger
Copy link
Collaborator

stefanrueger commented Apr 14, 2024

@mhei Thanks for the update

The AVRDUDE project likes to be backward compatible, and as such is unlikely to remove support for libgpiod v1 or sysfs for that matter. I understand your point of view.

I think(!) I have read up sufficiently on sysfs and gpiod to hazard a guess that it ought to be possible to try a workaround once AVRDUDE realises that the current config doesn't work with the current kernel. Knowing that some kernes shifted the GPIO numbering from one version to the next, AVRDUDE could try to undo that shift by carefully looking at the config GPIO numbers and the GPIO numbers offered by the kernel.

@mcuee
Copy link
Collaborator

mcuee commented Apr 15, 2024

@stefanrueger stefanrueger linked an issue Apr 16, 2024 that may be closed by this pull request
@stefanrueger stefanrueger merged commit 4761a70 into avrdudes:main Apr 16, 2024
@mhei mhei deleted the support-for-libgpiodv2 branch April 17, 2024 03:54
@mcuee mcuee added this to the AVRDUDE 8.0 milestone Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for libgpiod v2+ API

3 participants