How To Disassemble & Reassemble Evo ECU Code
How To Disassemble & Reassemble Evo ECU Code
ECU Disassembly
This section explains how to disassemble an Evo ROM binary file, downloaded from your ECU
using EcuFlash, into a GNU assembly text file using a Windows PC. It assumes you know how
to dump your ROM to a hex file using ECUFlash.
1. Get a copy of IDA Pro 6.1 and the IDA Pro Book 2nd edition from the internetz.
Spend many days reading about how to install and use this powerful disassembly
tool.
2. Download a copy of the Hitachi Renesas SH-2 Software Manual to get familiar with
the assembly language used in the Evo ROMs.
4. Download a copy of the Hitachi Renesas SH7055SF-Hardware Manual for the Evo 9
ECU.
5. Open IDA Pro 6.1 and click Go! (Work on your own).
Page |1
HOW TO DISASSEMBLE & REASSEMBLE EVO ECU CODE
6. Use File > Open to select the ROM hex file you want to disassemble.
Change the processor type in the drop down list from "Intel 80x86 processors: metapc"
to "Renesas: SH4B" and press the Set button.
2
HOW TO DISASSEMBLE & REASSEMBLE EVO ECU CODE
Uncheck the “Create ascii string if data xref exisits” and “Convert 32 bit instruction
operand to offset” options and then click OK.
3
HOW TO DISASSEMBLE & REASSEMBLE EVO ECU CODE
Uncheck the “Check for unicode strings” option and hit OK.
Remove the check mark from “Convert immediate loads” and hit OK, then OK again.
4
HOW TO DISASSEMBLE & REASSEMBLE EVO ECU CODE
11. A new window will appear called "Disassembly memory organization”.
Check the Renesas SH7058 (SH4B) processor is selected and press OK to continue.
5
HOW TO DISASSEMBLE & REASSEMBLE EVO ECU CODE
13. The disassembled hex file will be shown on your IDA pro window:
14. Use keyboard shortcut "G" to jump to the beginning of the code.
Press "G", insert 0000 and press OK.
***Now you are at the beginning of the code***
6
HOW TO DISASSEMBLE & REASSEMBLE EVO ECU CODE
15. Press keyboard "D" 3 times and that reference will transform into another number
16. Double-click on the “unk_XXXX” reference to jump to the start of the main
routine.
7
HOW TO DISASSEMBLE & REASSEMBLE EVO ECU CODE
17. Now you need to press keyboard "C" and wait. This will convert the code from
binary into assembly. It will change to something like this:
***This is actually Renesas SHASM assembly code and is no good for the GNU assembler
that we will use later to build the ROM after modification.
18. To fix this, select Options > General, and on the Analysis tab change the Target
assembler to “GNU Assembler” from the drop down list. Click the Reanalyze
program button, then hit OK.
19. Next run logic’s SH7052.idc script to fix the IDA file to a format that can be used to
produce an .ASM file that the KPIT GNU assembler can use.
Get the script from http://dev.logic.net/hg/esm/file/tip/evo/IDA/sh7052.idc and
save it to your ..\IDA PRO 61\idc folder.
8
HOW TO DISASSEMBLE & REASSEMBLE EVO ECU CODE
20. Run the script in IDA using File > Script file, to select and run the SH7052.idc script
in the ..\IDA PRO 61\idc folder.
The reason it restricts the definition is because when IDA encounters a longword, it
tries to treat it as a reference to a memory address if it falls within one of the existing
segments. This helps to filter out obviously bogus references to things like
"0xFFFFFFFF" or "0xFFFF0000" as there are quite a few instances of the latter used as
bitmasks.
21. Export your ASM text file from IDA using File > Produce file > Create ASM file, and
save it to your favorite project folder.
9
HOW TO DISASSEMBLE & REASSEMBLE EVO ECU CODE
ECU Assembly
This section describes how to build a ROM binary from a GNU format assembly text file.
1. Download the pcrel-filter.sh script from
http://dev.logic.net/hg/esm/file/tip/evo/IDA/pcrel_filter.sh
Save it to your project folder.
2. Download and install the Cygwin 64bit bash shell terminal for Windows using the
instructions at https://cygwin.com/install.html
4. Download the KPIT GNU Toolchain v09.02 installer executable from the Renasas
GNU Tools website. The name of the installer executable has the form
―GNUSH<version>-ELF.exe‖, where <version> is toolchain version. For example if
toolchain version is ―v0902‖ then its installer will have the name ―GNUSHv0902-
ELF.exe
5. Run the KPIT GNU Toolchain installer and integrate it with HEW. Installation
instructions are in C:\Program Files (x86)\Renesas\Hew\Tools\KPIT
Cummins\GNUSH-ELF\v0902\Doc\ GNUSH_UserManual.pdf
6. Prepare the ASM text file for the KPIT GNU assembler by running the pcrel_filter.sh
bash script on your assembly text file. This script corrects PC-Relative MOV
instructions to a format that is recognized by the KPIT GNU assembler.
a. Start a Cygwin64 bash shell by clicking on the Cygwin64 Terminal option on the
Start menu.
10
HOW TO DISASSEMBLE & REASSEMBLE EVO ECU CODE
b. Change to the project directory containing your assembly text file and the
pcrel_filter.sh script.
Type cd <drive:/path to project directory> and hit enter.
11
HOW TO DISASSEMBLE & REASSEMBLE EVO ECU CODE
c. The line above the $ prompt changes to show the relative path to the project
directory.
12
HOW TO DISASSEMBLE & REASSEMBLE EVO ECU CODE
13
HOW TO DISASSEMBLE & REASSEMBLE EVO ECU CODE
14
HOW TO DISASSEMBLE & REASSEMBLE EVO ECU CODE
9. Assemble the code by running this command:
11. Finally, you'll need to trim the header junk created by the GNU assembler and linker,
using a Cygwin64 Terminal command:
This will extract the ROM image into a hex file that you can flash to your ECU.
15