v0l / radio_tool

Radio firmware tool
https://discord.gg/V596cyatmv
GNU General Public License v3.0
82 stars 16 forks source link

Binary image is truncated when written inside MD-380 flash memory #4

Closed silseva closed 3 years ago

silseva commented 3 years ago

Hi @v0l, we found a nasty bug in radio_tool: for some reasons, when uploading a binary image to an MD-380/MD-UV380 not all the content is transferred into the flash, resulting in a truncated content inside the MCU flash. Comparing the content of the flash, the binary image is truncated starting from an offset of 0x1D000 from the beginning of the image, while the output of radio_tool is the following:

Erasing: 0x0800c000 [Size=0x4000]
-- FlashSector[Index=3, Start=0x0800c000, End=0x08010000]
Erasing: 0x08010000 [Size=0x10000]
-- FlashSector[Index=4, Start=0x08010000, End=0x08020000]
Erasing: 0x08020000 [Size=0x9208]
-- FlashSector[Index=5, Start=0x08020000, End=0x08040000]
Writing: 0x0800c000 [Size=0x4000]
Writing: 0x08010000 [Size=0x10000]
Writing: 0x08020000 [Size=0x9208]
Done

My hypothesis is that radio_tool does not correctly handle partial writing to a page. Do you have any ideas? I'm attaching here both the original binary image and the dump from flash, for reference.

original_bin_dump.txt flash_dump.txt

v0l commented 3 years ago

Can you attach the output of --fw-info command also?

silseva commented 3 years ago

Yep! Here you are:

== TYT Firmware == 
Radio: JST51 (MD380)
Size:  116.51 KiB
Data Segments: 
  0: Start=0x0800c000, Length=0x0001d208
v0l commented 3 years ago

Yea looks like its not including the padding

https://github.com/v0l/radio_tool/blob/master/src/tyt_radio.cpp#L77

Pretty simple fix will try to get it done today

v0l commented 3 years ago

I think it might have just been a rounding issue, can you try the latest build?

https://github.com/v0l/radio_tool/commit/e60aad100f35fbf3ff24e6c359e4c5f03e67a45b

f-izzo commented 3 years ago

Hi @v0l, I have tried commit 8601ac2883f6d67a99f6ac047045d04155f582d6 of radio_tool by flashing OpenRTX on an UV380 and it works correctly, compared to the previous version I was using.

I'm working with @silseva to double check the fix with a flash dump

silseva commented 3 years ago

Hi! After updating radio_tool the binary image stored in radio's flash matches the one produced by the compiler, so I think we can consider the bug solved. In a couple of weeks I'll do more rigorous testing, but I'm quite sure that there will be no surprises.

Thanks and 73 de Silvano IU2KWO