carlosperate / ubittool

Utility to extract the contents of flash from a micro:bit, including MicroPython user code.
https://carlosperate.github.io/ubittool/
MIT License
16 stars 4 forks source link

Microbit HEX file is not importing to the MakeCode Editor #19

Open iogameplayer opened 1 year ago

iogameplayer commented 1 year ago

Wiped my chromebook a while back, including all my Microbit hexes, which was not very smart. Anyways, tried to recover one hex I had on my microbit, but the hex can't be accessed via the Makecode editor. iogameplayer github issue.txt Github does not support .hex files, so just rename it to [something].hex. Thanks for reading :D!

aragocz commented 1 year ago

I'm getting the same issue, whenever I try to use the read-flash function it says: Board ID 9904 is not recognized; you will be able to use pyOCD but not program flash

Here is the entire console log from the GUI application:

Board ID 9904 is not recognized; you will be able to use pyOCD but not program flash.
Target type is cortex_m
DP IDR = 0x2ba01477
AP#0 IDR = 0x24770011
AP#1 IDR = 0x02880000
AP#0 ROM table #0 @ 0xe00ff000 (designer=244 part=00d)
[0]<e000e000:SCS-M4 class=14 designer=43b part=00c>
[1]<e0001000:DWT class=14 designer=43b part=002>
[2]<e0002000:FPB class=14 designer=43b part=003>
[3]<e0000000:ITM class=14 designer=43b part=001>
[4]<e0040000:TPIU-M4 class=9 designer=43b part=9a1 devtype=11 archid=0000 devid=0:0:ca1>
[5]<e0041000:ETM-M4 class=9 designer=43b part=925 devtype=13 archid=0000 devid=0:0:0>
CPU core #0 is Cortex-M4 r0p1
FPU present: FPv4-SP
4 hardware watchpoints
6 hardware breakpoints, 4 literal comparators
carlosperate commented 1 year ago

Unfortunately the MakeCode programme data is inside the hex file downloaded from MakeCode, but the data is not transferred to the micro:bit when it is flashed, as it would consume space that should otherwise be reserve for the user programme.

Because of this, reading a hex out of a micro:bit only contains the compiled binary programme, not the rest of the metadata normally inserted inside a MakeCode hex file, and the code cannot be retrieved this way.

LiamG2 commented 1 year ago

Same issue here . . .

So, if the extracted hex can't be used with MakeCode, is there some other program that can convert it back to either Javascript or MicroPython?

Thanks

carlosperate commented 1 year ago

Unfortunately there is no thing that can be done at that point. Once a MakeCode hex file is flashed into the micro:bit, only the compiled output is stored in the device. The user code (javascript/typescript or python) are not transfered, so they cannot be recovered when reading data back from the micro:bit.

The hex files downloaded from the MakeCode editor do contain the source code inside the hex file, which is why dropping a hex file into the MakeCode editor reopens the project. However, that user data is stored in a special format inside the hex file, which is not meant to be transfered to the micro:bit itself.

So when extracting a hex file back from the micro:bit with this tool, the file only contains the compiled programme, not the user code.

Tehcnically speaking, there are techniquest to "reverse" a compiled programme into a higher level language, but a tool to do that for the micro:bit does not currently exists, as far as I know.