Error uploading bootloader, MegaCoreX, SerialUPDI

We are trying to burn a bootloader to a custom ATMega4809 board over serialUPDI. We are following the .ini template provided by MegaCoreX, with adjustments to fit our board specifications

board_build.f_cpu = 4000000L
board_build.variant = 40pin-standard
upload_port = COM3
board_hardware.uart = uart0

Running code

pio run -e fuses_bootloader -t bootloader -v

Produces the error

avrdude: 1 byte of lock verified
avrdude: leaving NVM programming mode
avrdude serialupdi_close() warning: releasing DTR/RTS handshake lines

avrdude done.  Thank you.

avrdude -p atmega4809 -C C:\Users\rn71\.platformio\packages\tool-avrdude\avrdude.conf -P usb -c serialupdi -xrtsdtr=high -U flash:w:C:\Users\rn71\.platformio\packages\framework-arduino-megaavr-megacorex\bootloaders\optiboot\bootloaders\mega0\115200\Optiboot_mega0_UART0_DEF_115200_A7.hex:i
avrdude error: cannot open port usb: The system cannot find the file specified.


avrdude error: unable to open programmer serialupdi on port usb

avrdude done.  Thank you.

*** [bootloader] Error 1
================================================= [FAILED] Took 3.65 seconds ===========================================

Upload_UPDI       IGNORED
Upload_UART       IGNORED
fuses_bootloader  FAILED    00:00:03.647
============================================ 1 failed, 0 succeeded in 00:00:03.647 ============================================

Does anyone know what we may be doing wrong? Thanks in advance!

I 've been running into this problem too, working on ATmega4808 though.
I have tried this:
set BOOTUPLOADERFLAGS=-P COM3
but did not work (same error).
Perhaps this issue relates to this:
https://github.com/platformio/platform-atmelmegaavr/issues/9

It looks like some python script in the guts of platformio is missing some information.
I am just wondering… the issue was closed more than 3 years ago.

Hello! I opened the issue with MCUdude: https://github.com/MCUdude/MegaCoreX/issues/193. He found and fixed the root cause

To fix the problem, I just needed to replace my local copy of the bootloader.py script (for me, at location: "~\.platformio\platforms\atmelmegaavr\builder\bootloader.py") with the updated version here: https://github.com/MCUdude/platform-atmelmegaavr/blob/b82248d423bd8546b1cac6692303b9473abf86ad/builder/bootloader.py

Hope this solves your problems, too!