I quickly loaded it into ghidra, (arm 32 8thumb little endian ) used svd-loader to setup memory and peripherals ( i just used a svd file from the cmis svd collection online)
it would be easy to patch this file to dump the entire flash to uart, just edit the jump vector at the start to jump to super basic code that reads flash=0x0 and puts into uart, counts to 100 then add 1 to flash address and repeat until past 0x20000 , if you capture fia serial port using something like Realterm you can save as a bin and then import into ghidra
by the time this app code is run the uart and clocks are setup so you wont need to do that.
attached is a file i made to do that for the gd32f103 clones,
this is how it it works , in folder is the file stm32.ld and in that is the boot address where this code would start from,
Code:
[Select]rom (rx) : ORIGIN = 0x08006000, LENGTH = 242K
and if we look at the compiled rom at 0x6000 we see the stack address & reset entry vector of 0x8006231
now say if your device app boots at 0x02000 (yours actually boots at 0x20000 )
what we would do is goto the firmware file , add 0x02000 to the address and find the real 0x6000 we then delete the code after that and paste our new uart bin file there(we need to remove the blank data from 0x0 to 0x5FFF from the uart.bin) , we then go to the start of out new firmware patch file and set the new stack and entry to match our bin file (the first 8 bytes, stack and reset)
so effectively we are telling the patched firmware to jump to our new code and dump the whole flash to the serial port.
there are issues with this,
if the bootloader is activated by the application only you might not get back into it unless it one that see's the usb flash+file and just flashes, this leads onto issue two that if there is a crc check of any sorts it may fail to update with the patch or the original file.
if you attempt to dump via the SWD pins a word of caution, some Openocd tcl files will unlock you mcu when it connects, if the protection level is on 0 then it will erase the mcu for good. Stm32 cube programmer does not do this but warns you it's locked and wont read.
there is a list of ways the protections on gigadevices can be broken, look for the pdf gigivulnerability at offzone.moscow
a example is on the f405 model you can dump flash to uart via setting up dma to read flash, another trick is to load your dump code into sram then using a pi-pico to control reset and boot0/boot1 you can trick the system into running code from sram even at rdp 2
darkspr1te