Cannot upload PX4 firmware on customized pixhawk2


I have a pixhawk 2 cube from Hex that have been flashed with a custom software lately.
I would like to upload a fresh PX4 firmware on it through QGC but can’t manage to do it.
I have first flashed the bootloader with JTAG on both FMU and IO MCUs (respectively px4fmuv3_bl and px4iov3_bl targets) and QGC tells me that the bl connection is correct (also, the amber led blinks rapidly, indicating the pixhawk is on bl mode).

It fails trying to erase the previous program (that does not exists obviously) with a 0x13 (PROTO_INVALID) error, as on trace shown below:

QGroundControl can upgrade the firmware on Pixhawk devices, SiK Radios and PX4         
Flow Smart Cameras.
Plug in your device via USB to start firmware upgrade.
Found device: PX4 FMU V2
Connected to bootloader:
Version: 5
Board ID: 255
Flash size: 2080768
Downloading firmware...
Download complete
Successfully decompressed parameter_xml
Successfully decompressed airframe_xml
Successfully decompressed image
Erasing previous program...
Error: Board erase failed: Send Command: Command failed: 0x13 (PROTO_INVALID)
Upgrade cancelled
Upgrade complete

Am I missing something? Is it possible to upload something from QGC when another program is already installed?

Any help would be much appreciated!

No one here can help with this issue?
It must be possible to re-upload a pixhawk from scratch in some way…