Build and Upload. Raspberry PI - Arduino Mega

Hi.
I have some code for the Arduino Mega which is connected to the Raspberry PI, and I want to compile and download the code to the Arduino Mega using the command . platformio run --target upload
But I get an error:

Building in release mode
Compiling .pio/build/megaatmega2560/src/CommandAnalogRead.cpp.o
avr-g++: error: device-specs/specs-atmega2560: No such file or directory
Compiling .pio/build/megaatmega2560/src/CommandAnalogWrite.cpp.o
avr-g++: error: device-specs/specs-atmega2560: No such file or directory
Compiling .pio/build/megaatmega2560/src/CommandDeviceTemplate.cpp.o
avr-g++: error: device-specs/specs-atmega2560: No such file or directory
*** [.pio/build/megaatmega2560/src/CommandAnalogRead.cpp.o] Error 1
Compiling .pio/build/megaatmega2560/src/CommandDigitalRead.cpp.o
*** [.pio/build/megaatmega2560/src/CommandAnalogWrite.cpp.o] Error 1
*** [.pio/build/megaatmega2560/src/CommandDeviceTemplate.cpp.o] Error 1
avr-g++: error: device-specs/specs-atmega2560: No such file or directory
*** [.pio/build/megaatmega2560/src/CommandDigitalRead.cpp.o] Error 1

This seems like a broken toolchain. Can yoo SSH into the Pi, do rm -rf ~/.platformio/packages/toolchain-atmelavr and retry?