Avrdude config file not found (because of spaces in path)

just a quick fix, my VSCode based platformIO installation of avrdude can’t find its config file, because my windows username has spaces in it. I’m no scripting master, but i’ve placed quotes around stuff in a bat/python script before, i think i can fix it myself. Should probably be fixed by default in the future through (thank you in advance, maxgerhardt :wink:

Processing nanoatmega328new (platform: atmelavr; board: nanoatmega328new; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/nanoatmega328new.html
PLATFORM: Atmel AVR (4.0.1) > Arduino Nano ATmega328 (New Bootloader)
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 30KB Flash
DEBUG: Current (avr-stub) External (avr-stub, simavr)
PACKAGES:
 - framework-arduino-avr @ 5.1.0
 - toolchain-atmelavr @ 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode

Selected fuses: [lfuse = 0xFF, hfuse = 0xDA, efuse = 0xFD]
Setting fuses
avrdude: can't open config file "C:\Users\Thijs": No such file or directory
avrdude: error reading system wide configuration file "C:\Users\Thijs"
*** [bootloader] Error 1
=========================================================================================== [FAILED] Took 1.30 seconds ===========================================================================================

This is slightly outdated. Does this appear in the latest version?

CLI

pio pkg update -g -p atmelavr

in 4.2.0, yes:

Processing nanoatmega328new (platform: atmelavr; board: nanoatmega328new; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/nanoatmega328new.html
PLATFORM: Atmel AVR (4.2.0) > Arduino Nano ATmega328 (New Bootloader)
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 30KB Flash
DEBUG: Current (avr-stub) External (avr-stub, simavr)
PACKAGES:
 - framework-arduino-avr @ 5.1.0
 - tool-avrdude @ 1.60300.200527 (6.3.0)
 - toolchain-atmelavr @ 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Using bootloader image:
C:\Users\Thijs van Liempd\.platformio\packages\framework-arduino-avr\bootloaders\optiboot/optiboot_atmega328.hex

Selected fuses: [lfuse = 0xFF, hfuse = 0xDA, efuse = 0xFD]
Setting fuses
avrdude: can't open config file "C:\Users\Thijs": No such file or directory
avrdude: error reading system wide configuration file "C:\Users\Thijs"
*** [bootloader] Error 1
=========================================================================================== [FAILED] Took 0.85 seconds ===========================================================================================

edit:
i will admit, just found what i think is the script in question:


env.Replace(
    BOOTUPLOADER="avrdude",
    BOOTUPLOADERFLAGS=[
        "-p",
        "$BOARD_MCU",
        "-C",
        '"%s"'
        % join(env.PioPlatform().get_package_dir("tool-avrdude") or "", "avrdude.conf"),
    ],
    BOOTFLAGS=['-Uflash:w:"%s":i' % bootloader_path, "-Ulock:w:%s:m" % lock_bits],
    UPLOADBOOTCMD="$BOOTUPLOADER $BOOTUPLOADERFLAGS $UPLOAD_FLAGS $BOOTFLAGS",
)

and it looks like the “%s” should have already solve this problem, right?

Then this seems like

to me. Can you comment in that issue that it’s still not resolved?

It’s weird because this explicitly quotes the path to try and avoid that error, but you can try and use just "%s".

i will comment on that original one, (as soon as i’ve made sure that it’s not just my machine though);

i’m starting to think avrdude doesn’t like me:


env.Replace(
    BOOTUPLOADER="avrdude",
    BOOTUPLOADERFLAGS=[
        "-p",
        "$BOARD_MCU",
        "-C",
        '"C:/Users/Thijs van Liempd/.platformio/packages/tool-avrdude/avrdude.conf"'
        # '"%s"'
        # % join(env.PioPlatform().get_package_dir("tool-avrdude") or "", "avrdude.conf"),
    ],
    BOOTFLAGS=['-Uflash:w:"%s":i' % bootloader_path, "-Ulock:w:%s:m" % lock_bits],
    UPLOADBOOTCMD="$BOOTUPLOADER $BOOTUPLOADERFLAGS $UPLOAD_FLAGS $BOOTFLAGS",
)
print("thijs sanity check:", '"%s"' % join(env.PioPlatform().get_package_dir("tool-avrdude") or "", "avrdude.conf")) # just a debug print for my sanity

produces:

Processing nanoatmega328new (platform: atmelavr; board: nanoatmega328new; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/nanoatmega328new.html
PLATFORM: Atmel AVR (4.2.0) > Arduino Nano ATmega328 (New Bootloader)
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 30KB Flash
DEBUG: Current (avr-stub) External (avr-stub, simavr)
PACKAGES:
 - framework-arduino-avr @ 5.1.0
 - tool-avrdude @ 1.60300.200527 (6.3.0)
 - toolchain-atmelavr @ 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Using bootloader image:
C:\Users\Thijs van Liempd\.platformio\packages\framework-arduino-avr\bootloaders\optiboot/optiboot_atmega328.hex

Selected fuses: [lfuse = 0xFF, hfuse = 0xDA, efuse = 0xFD]
thijs sanity check: "C:\Users\Thijs van Liempd\.platformio\packages\tool-avrdude\avrdude.conf"
Setting fuses
avrdude: can't open config file "C:\Users\Thijs": No such file or directory
avrdude: error reading system wide configuration file "C:\Users\Thijs"
*** [bootloader] Error 1
=========================================================================================== [FAILED] Took 0.81 seconds ===========================================================================================

Check what command actually comes out as the command to be executed: CLIpio run -t bootloader -v

There might be a problem with how SCons escapes the given command string.

Also this executes FUSESCMD first not your modified UPLOADBOOTCMD.

you are absolutely right, the error message i saw was coming from the fuses script, not the bootloader script. the fuses script was trying to run:

avrdude -p atmega328p -C ""C:\Users\Thijs van Liempd\.platformio\packages\tool-avrdude\avrdude.conf"" -e -c usbasp -Ulock:w:0x3F:m -Uhfuse:w:0xDA:m -Ulfuse:w:0xFF:m -Uefuse:w:0xFD:m

which has needless doubled quotes. One set of quotes was added manually using %s, then i suspect env.Replace is detecting spaces in the string and adding another set of quotation marks. After removing the %s quotation, the fuses script worked! (so the github page you linked to was absolutely right, and i’ll post a reminder there that it’s unsolved once again)
However, the bootloader script has a similar (but more difficult) issue, it tries to run:

avrdude -p atmega328p -C "C:\Users\Thijs van Liempd\.platformio\packages\tool-avrdude\avrdude.conf" -c usbasp "-Uflash:w:"C:\Users\Thijs van Liempd\.platformio\packages\framework-arduino-avr\bootloaders\optiboot/optiboot_atmega328.hex":i" -Ulock:w:0x0F:m

where "-Uflash:w:"C:\Users\Thijs van Liempd\.platformio\packages\framework-arduino-avr\bootloaders\optiboot/optiboot_atmega328.hex":i" comes from the line: BOOTFLAGS=['-Uflash:w:"%s":i' % bootloader_path, "-Ulock:w:%s:m" % lock_bits],
The bootloader_path variable doesn’t have quotes by default, so adding them with %s makes sense, but because the -Uflash:w: portion is concatenated to a single string, the env.Replace (presumably!) adds another set of quotation marks, which screws it up.
Do you think env.Replace() is adding the excessive quotation marks, and is there a quick way to stop it?

it’s been a while but i’d like to close this thing off.
I have identified the problem and devised a fix;
the issue lies in the fact that BOOTFLAGS is a list:

BOOTFLAGS=[("-Uflash:w:"+('"%s"' % bootloader_path)+":i"), "-Ulock:w:%s:m" % lock_bits],

the fix is just to make it a single string instead (using concatenation):

BOOTFLAGS="-Uflash:w:"+('"%s"' % bootloader_path)+":i" + " " + "-Ulock:w:%s:m" % lock_bits,

here is the PR i made with the 3 fixes (‘“%s”’ in fuses.py and bootloader.py, and this concat’ed string in bootloader.py).

1 Like