avrdudes / avrdude

AVRDUDE is a utility to program AVR microcontrollers
GNU General Public License v2.0
747 stars 138 forks source link

avrdude git main crash with hidapi #1222

Closed mcuee closed 1 year ago

mcuee commented 1 year ago

I will need to debug further why this happened. It may have something to do with my paticular system and not avrdude.

From here:

mcuee@mcuees-Mac-mini avrdude_bin % ./avrdude_git -c pickit4_updi -p m4808 -v

avrdude_git: Version 7.0-20221214 (159d126)
             Copyright the AVRDUDE authors;
             see https://github.com/avrdudes/avrdude/blob/main/AUTHORS

             System wide configuration file is /Users/mcuee/build/avr/avrdude_test/avrdude_bin/avrdude.conf
             User configuration file is /Users/mcuee/.avrduderc
             User configuration file does not exist or is not a regular file, skipping

             Using Port                    : usb
             Using Programmer              : pickit4_updi
zsh: segmentation fault  ./avrdude_git -c pickit4_updi -p m4808 -v

But github action git main binary is okay. Strange.


mcuee@mcuees-Mac-mini avrdude_test % cd avrdude-macos-x86_64
mcuee@mcuees-Mac-mini avrdude-macos-x86_64 % ls
avrdude     avrdude.conf
mcuee@mcuees-Mac-mini avrdude-macos-x86_64 % ./avrdude -c pickit4_updi -p m4808 -v 

avrdude: Version 7.0-20221214 (159d126)
         Copyright the AVRDUDE authors;
         see https://github.com/avrdudes/avrdude/blob/main/AUTHORS

         System wide configuration file is /Users/mcuee/build/avr/avrdude_test/avrdude-macos-x86_64/avrdude.conf
         User configuration file is /Users/mcuee/.avrduderc
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : pickit4_updi
avrdude: found CMSIS-DAP compliant device, using EDBG protocol
         AVR Part                      : ATmega4808
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         Serial program mode           : yes
         Parallel program mode         : yes
         Memory Detail                 :

                                           Block Poll               Page                       Polled
           Memory Type Alias    Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           fuse0       wdtcfg      0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse1       bodcfg      0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse2       osccfg      0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse4       tcd0cfg     0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse5       syscfg0     0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse6       syscfg1     0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse7       append      0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse8       bootend     0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuses                   0     0     0    0 no          9   10      0     0     0 0x00 0x00
           lock                    0     0     0    0 no          1    1      0     0     0 0x00 0x00
           tempsense               0     0     0    0 no          2    1      0     0     0 0x00 0x00
           signature               0     0     0    0 no          3    1      0     0     0 0x00 0x00
           prodsig                 0     0     0    0 no         61   61      0     0     0 0x00 0x00
           sernum                  0     0     0    0 no         10    1      0     0     0 0x00 0x00
           osccal16                0     0     0    0 no          2    1      0     0     0 0x00 0x00
           osccal20                0     0     0    0 no          2    1      0     0     0 0x00 0x00
           osc16err                0     0     0    0 no          2    1      0     0     0 0x00 0x00
           osc20err                0     0     0    0 no          2    1      0     0     0 0x00 0x00
           data                    0     0     0    0 no          0    1      0     0     0 0x00 0x00
           userrow     usersig     0     0     0    0 no         64   64      0     0     0 0x00 0x00
           eeprom                  0     0     0    0 no        256   64      0     0     0 0x00 0x00
           flash                   0     0     0    0 no      49152  128      0     0     0 0x00 0x00

         Programmer Type : JTAGICE3_UPDI
         Description     : MPLAB(R) PICkit 4 in UPDI mode
         ICE HW version  : 4
         ICE FW version  : 1.14 (rel. 268)
         Serial number   : 
         Vtarget         : 4.87 V
         JTAG clock megaAVR/program   : 1000 kHz
         JTAG clock megaAVR/debug     : 100 kHz
         PDI/UPDI clock Xmega/megaAVR : 100 kHz
avrdude: partial Family_ID returned: "mega"
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9650 (probably m4808)

avrdude done.  Thank you.
mcuee commented 1 year ago

Similar problem for other programmers using hidapi.

mcuee@mcuees-Mac-mini avrdude_bin % ./avrdude_git -c xplainedpro_updi -p t817 -t                 
zsh: segmentation fault  ./avrdude_git -c xplainedpro_updi -p t817 -t

mcuee@mcuees-Mac-mini avrdude_bin % lldb ./avrdude_git
(lldb) target create "./avrdude_git"
Current executable set to '/Users/mcuee/build/avr/avrdude_test/avrdude_bin/avrdude_git' (arm64).
(lldb) run -c xplainedpro_updi -p t817 -t
Process 7576 launched: '/Users/mcuee/build/avr/avrdude_test/avrdude_bin/avrdude_git' (arm64)
Process 7576 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x16)
    frame #0: 0x00000001001b7200 libhidapi.0.dylib`set_report + 28
libhidapi.0.dylib`set_report:
->  0x1001b7200 <+28>: ldr    w8, [x0, #0x14]
    0x1001b7204 <+32>: cbz    w8, 0x1001b7210           ; <+44>
    0x1001b7208 <+36>: mov    w8, #-0x1
    0x1001b720c <+40>: b      0x1001b7238               ; <+84>
Target 0: (avrdude_git) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x16)
  * frame #0: 0x00000001001b7200 libhidapi.0.dylib`set_report + 28
    frame #1: 0x000000010006f164 avrdude_git`usbhid_open(port=<unavailable>, pinfo=<unavailable>, fd=<unavailable>) at usb_hidapi.c:168:5 [opt]
    frame #2: 0x0000000100043040 avrdude_git`jtag3_open_common(pgm=0x000000010082b000, port="usb") at jtag3.c:1472:10 [opt]
    frame #3: 0x0000000100047ddc avrdude_git`jtag3_open_updi(pgm=0x000000010082b000, port="usb") at jtag3.c:1594:7 [opt]
    frame #4: 0x0000000100006a4c avrdude_git`main(argc=<unavailable>, argv=<unavailable>) at main.c:1121:8 [opt]
    frame #5: 0x000000018f787e50 dyld`start + 2544
(lldb) quit
Quitting LLDB will kill one or more processes. Do you really want to proceed: [Y/n] Y
mcuee commented 1 year ago

The output from otool looks suspcicious because of libhid.

mcuee@mcuees-Mac-mini avrdude_bin % otool -L ../avrdude-macos-x86_64/avrdude
../avrdude-macos-x86_64/avrdude:
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.100.3)
    /usr/local/opt/libusb/lib/libusb-1.0.0.dylib (compatibility version 4.0.0, current version 4.0.0)
    /usr/local/opt/hidapi/lib/libhidapi.0.dylib (compatibility version 0.0.0, current version 0.12.0)
    /usr/local/opt/libftdi/lib/libftdi1.2.dylib (compatibility version 2.0.0, current version 2.5.0)
    /usr/lib/libedit.3.dylib (compatibility version 2.0.0, current version 3.0.0)

mcuee@mcuees-Mac-mini avrdude_bin % otool -L ./avrdude_git                  
./avrdude_git:
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
    /opt/homebrew/opt/libusb-compat/lib/libusb-0.1.4.dylib (compatibility version 9.0.0, current version 9.4.0)
    /opt/homebrew/opt/libusb/lib/libusb-1.0.0.dylib (compatibility version 4.0.0, current version 4.0.0)
    /opt/homebrew/opt/libhid/lib/libhid.0.dylib (compatibility version 1.0.0, current version 1.0.0)
    /opt/homebrew/opt/hidapi/lib/libhidapi.0.dylib (compatibility version 0.0.0, current version 0.12.0)
    /opt/homebrew/opt/libftdi0/lib/libftdi.1.dylib (compatibility version 22.0.0, current version 22.0.0)
    /opt/homebrew/opt/libftdi/lib/libftdi1.2.dylib (compatibility version 2.0.0, current version 2.5.0)
    /usr/lib/libedit.3.dylib (compatibility version 2.0.0, current version 3.0.0)
mcuee commented 1 year ago

Looks like a lingering old homebrew avrdude formular problem.

mcuee@mcuees-Mac-mini avrdude_bin % brew info libhid
==> libhid: stable 0.2.16 (bottled)
Library to access and interact with USB HID devices
https://directory.fsf.org/wiki/Libhid
Deprecated because it is not maintained upstream!
/opt/homebrew/Cellar/libhid/0.2.16 (18 files, 305.5KB) *
  Poured from bottle on 2021-03-27 at 12:35:31
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/libhid.rb
License: GPL-2.0
==> Dependencies
Build: autoconf ✔, automake ✔, libtool ✔
Required: libusb ✔, libusb-compat ✔
==> Analytics
install: 40 (30 days), 148 (90 days), 8,312 (365 days)
install-on-request: 35 (30 days), 111 (90 days), 386 (365 days)
build-error: 0 (30 days)
mcuee@mcuees-Mac-mini avrdude_bin % brew remove libhid
Error: Refusing to uninstall /opt/homebrew/Cellar/libhid/0.2.16
because it is required by avrdude, which is currently installed.
You can override this and force removal with:
  brew uninstall --ignore-dependencies libhid
mcuee@mcuees-Mac-mini avrdude_bin % brew uninstall --ignore-dependencies libhid
Uninstalling /opt/homebrew/Cellar/libhid/0.2.16... (18 files, 305.5KB)
mcuee@mcuees-Mac-mini avrdude_bin % brew remove avrdude
Uninstalling /opt/homebrew/Cellar/avrdude/HEAD-159d126_2... (13 files, 2MB)
avrdude 7.0_2 is still installed.
To remove all versions, run:
  brew uninstall --force avrdude

Warning: The following may be avrdude configuration files and have not been removed!
If desired, remove them manually with `rm -rf`:
  /opt/homebrew/etc/avrdude.conf
  /opt/homebrew/etc/avrdude.conf.default
mcuee@mcuees-Mac-mini avrdude_bin % rm /opt/homebrew/etc/avrdude.conf 
mcuee@mcuees-Mac-mini avrdude_bin % rm /opt/homebrew/etc/avrdude.conf.default 
mcuee@mcuees-Mac-mini avrdude_bin % brew uninstall avrdude
Uninstalling /opt/homebrew/Cellar/avrdude/7.0_2... (9 files, 2.4MB)

mcuee@mcuees-Mac-mini avrdude_bin % brew install avrdude
==> Fetching avrdude
==> Downloading https://ghcr.io/v2/homebrew/core/avrdude/manifests/7.0_2
Already downloaded: /Users/mcuee/Library/Caches/Homebrew/downloads/78e02371cdcf49288c566045a40106818630bc2b0dece52d714fcde190b75788--avrdude-7.0_2.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/avrdude/blobs/sha256:50c20fe810d534c1c4cea3209ca812d35167c4b51e140f7154d96
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:50c20fe810d534c1c4cea3209ca812d35167c4
######################################################################## 100.0%
==> Pouring avrdude--7.0_2.arm64_ventura.bottle.tar.gz
🍺  /opt/homebrew/Cellar/avrdude/7.0_2: 9 files, 2.4MB
==> Running `brew cleanup avrdude`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

mcuee@mcuees-Mac-mini avrdude_bin % brew unlink avrdude
Unlinking /opt/homebrew/Cellar/avrdude/7.0_2... 6 symlinks removed.

mcuee@mcuees-Mac-mini avrdude_bin % brew install avrdude --HEAD
==> Fetching avrdude
==> Cloning https://github.com/avrdudes/avrdude.git
Updating /Users/mcuee/Library/Caches/Homebrew/avrdude--git
==> Checking out branch main
Already on 'main'
Your branch is up to date with 'origin/main'.
HEAD is now at 159d126 Update NEWS
==> cmake -S . -B build/shared -DCMAKE_INSTALL_SYSCONFDIR=/opt/homebrew/etc -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_RPATH=@l
==> cmake --build build/shared
==> cmake --install build/shared
==> cmake -S . -B build/static -DCMAKE_INSTALL_SYSCONFDIR=/opt/homebrew/etc
==> cmake --build build/static
🍺  /opt/homebrew/Cellar/avrdude/HEAD-159d126_2: 13 files, 2MB, built in 7 seconds
==> Running `brew cleanup avrdude`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
Removing: /Users/mcuee/Library/Caches/Homebrew/avrdude--7.0_2... (776.7KB)

mcuee@mcuees-Mac-mini avrdude_bin % brew info libhid
==> libhid: stable 0.2.16 (bottled)
Library to access and interact with USB HID devices
https://directory.fsf.org/wiki/Libhid
Deprecated because it is not maintained upstream!
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/libhid.rb
License: GPL-2.0
==> Dependencies
Build: autoconf ✔, automake ✔, libtool ✔
Required: libusb ✔, libusb-compat ✔
==> Analytics
install: 40 (30 days), 148 (90 days), 8,312 (365 days)
install-on-request: 35 (30 days), 111 (90 days), 386 (365 days)
build-error: 0 (30 days)
mcuee commented 1 year ago

After the clean-up and rebuild, everything is fine now.


mcuee@mcuees-Mac-mini avrdude_bin % otool -L ./avrdude_git
./avrdude_git:
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
    /opt/homebrew/opt/libusb-compat/lib/libusb-0.1.4.dylib (compatibility version 9.0.0, current version 9.4.0)
    /opt/homebrew/opt/libusb/lib/libusb-1.0.0.dylib (compatibility version 4.0.0, current version 4.0.0)
    /opt/homebrew/opt/hidapi/lib/libhidapi.0.dylib (compatibility version 0.0.0, current version 0.12.0)
    /opt/homebrew/opt/libftdi0/lib/libftdi.1.dylib (compatibility version 22.0.0, current version 22.0.0)
    /opt/homebrew/opt/libftdi/lib/libftdi1.2.dylib (compatibility version 2.0.0, current version 2.5.0)
    /usr/lib/libedit.3.dylib (compatibility version 2.0.0, current version 3.0.0)
mcuee@mcuees-Mac-mini avrdude_bin % ./avrdude_git -c xplainedpro_updi -p t817 -qqt
avrdude> dump fuses
0000  00 00 02 ff 00 c4 04 00  02                       |.........       |

avrdude> quit
avrdude> %