Author Topic: Newbie ARM Console disassemble questions  (Read 383 times)

cheshirecat

  • New to the forum
  • *
  • Posts: 3
Newbie ARM Console disassemble questions
« on: July 17, 2017, 08:16:38 PM »
My setup;
I have a working ML Development environment in Ubuntu on a VirtualBox.
I have ARM Console working.

From ARM Console I have outputted a disassembly of ROM1.BIN from a 5d4
I did that by following the instructions at
http://magiclantern.wikia.com/wiki/GPL_Tools/ARM_console
Quote
Prepare a working directory where you will put the input files. You will need:
    Some dumps, with the .bin extension. Include the load address in the dump name.
    Some databases, in IDC or Stubs (*.S) format. Try to give them names similar to the dumps, to help the autodetection.

Question: What should I use as the load address ?
Question: I presume that there is currently no IDC I could use for this dump ?
Question: I presume that there is currently no Stub I could use for this dump, since the stubs have not yet been found ?


a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 10061
  • 5D Mark Free
Re: Newbie ARM Console disassemble questions
« Reply #1 on: July 17, 2017, 09:51:51 PM »
First of all, 5D4 has mostly Thumb code, and ARM-console won't help with that (it's ancient stuff I wrote before getting an IDA license, ARM only). Look on CHDK forum for suggestions (from there, I've tried capdis, but only for double-checking small snippets of code where I didn't trust the output from IDA).

Many stubs are easily identified from strings; chris_overseas found some (look up his repo). Running the firmware in QEMU will save an IDC with what functions got called during that session. Currently the emulation works for the bootloader (which is ARM code) and it also runs a tiny part of the main firmware.

Memory layout is similar to other D6 models (look up my notes on e.g. 7D2 or 80D threads). Or just read it from QEMU logs.

First puzzle to solve: how to jump to main firmware from autoexec.bin? Note the 5D4 has two cores, and I believe we have to do something about it somehow.

Next step (which is easy, will probably work in QEMU, but not on the real hardware) would be to adapt the 7D2/80D startup code (which... works in QEMU, but not on the real hardware).

Third step would be making the startup code work on the real hardware (likely as easy as copying a routine from CHDK, discussed on 80D thread). Since I don't have a D6 model yet, I didn't feel any rush to try it.

After that, porting ML should be more or less straightforward (I don't expect major issues, other than some special handling for Thumb stubs).

For the first puzzle (which was solved for single-digic D6 models, and was a non-issue on earlier single-digic models), I've made some limited progress understanding the IPC protocol (communication between the two cores); if you (or anyone else) is interested in continuing this investigation, I can publish them in the current state.

cheshirecat

  • New to the forum
  • *
  • Posts: 3
Re: Newbie ARM Console disassemble questions
« Reply #2 on: July 19, 2017, 05:48:43 PM »
First of all, 5D4 has mostly Thumb code, and ARM-console won't help with that (it's ancient stuff I wrote before getting an IDA license, ARM only). Look on CHDK forum for suggestions (from there, I've tried capdis, but only for double-checking small snippets of code where
I didn't trust the output from IDA).
Thanks a1ex.  Ah, I knew about the Thumb code but didn't realise ARM-console was not the way to go with it.
Thanks for the advice. I tried capdis and it worked but disassembled without text strings when I tried it.
I had better luck with the GPL Disassembling advice at CHDK and the disassemblev7.pl from there produced a disassembly with text strings. I now have disassembled code which agrees with the stubs found by chris_overseas. I have found a few more stubs and have registered at bitbucket. I will fork the ML repo once I have figured out the bitbucket workflow ( chris_overseas has given me his ideas for what to do at bitbucket ).

Many stubs are easily identified from strings; chris_overseas found some (look up his repo). Running the firmware in QEMU will save an IDC with what functions got called during that session. Currently the emulation works for the bootloader (which is ARM code) and it also runs a tiny part of the main firmware.
Yes, I had seen the initial stubs work from chris_overseas and it was that which inspired me to have a go to see what I might be able to do. I have been in contact with Chris and he has been very helpful.
I am yet to get QEMU up and running but that is my next step.

First puzzle to solve: how to jump to main firmware from autoexec.bin? Note the 5D4 has two cores, and I believe we have to do something about it somehow.

Next step (which is easy, will probably work in QEMU, but not on the real hardware) would be to adapt the 7D2/80D startup code (which... works in QEMU, but not on the real hardware).

Third step would be making the startup code work on the real hardware (likely as easy as copying a routine from CHDK, discussed on 80D thread). Since I don't have a D6 model yet, I didn't feel any rush to try it.

After that, porting ML should be more or less straightforward (I don't expect major issues, other than some special handling for Thumb stubs).

For the first puzzle (which was solved for single-digic D6 models, and was a non-issue on earlier single-digic models), I've made some limited progress understanding the IPC protocol (communication between the two cores); if you (or anyone else) is interested in continuing this investigation, I can publish them in the current state.

I would be happy to look at the jump to main firmware from autoexec.bin problem to see if there is anything I can figure out. So if you can publish your work on the IPC protocol, please do.

cheshirecat

  • New to the forum
  • *
  • Posts: 3
Re: Newbie ARM Console disassemble questions
« Reply #3 on: July 23, 2017, 06:07:24 PM »
Thanks for the advice. I tried capdis and it worked but disassembled without text strings when I tried it.

CORRECTION: I had the wrong start address in my capdis command.
Start address should be 0xfe000001 NOT 0xfe000000. The lowest bit tells capdis whether or not to disassemble thumb.
My capdis disassembled code now looks very similar to my disassemblev7.pl disassembled code.