Pages: 1 [2]
Author Topic: Damos address corrector (Python script)  (Read 30578 times)
Bitshifter
Full Member
***

Karma: +10/-7
Offline Offline

Posts: 94


« Reply #15 on: April 06, 2019, 01:34:36 AM »

copy/paste what you tried to do at the command line.

That was not the Problem. The Problem are missing "" Wink

@ Polo35580

Great tool. Tested with 3 versions (MED9) and all looks fine, save a lot of time.

Thank you for engineering, release and update. I vote: hero member  Smiley
Logged
IamwhoIam
Hero Member
*****

Karma: +52/-114
Offline Offline

Posts: 1070


« Reply #16 on: April 06, 2019, 04:56:35 AM »

If only it worked as decently with continental as it does with Bosch stuff... there's definitely LOADS of room for improvement there, just searching for byte strings isn't enough to make it a proper "corrector"... I've tested it on 2 similar Bosch MED17 files, in one of them LAMFA doesn't exist anymore, in the original one it exists. Guess what? the corrector found LAMFA in my file that doesn't have it Cheesy
Logged

I have no logs because I have a boost gauge (makes things easier)
Gilgamesh
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 8


« Reply #17 on: June 02, 2019, 04:10:56 AM »


Feel free to test it and report if it fit your needs.   Cheesy


Hello Polo! Very good idea and solution. Thanks a lot for your work!
I've test it and it's working good, but sometimes there is strange errors:

Quote

Address 0x04A170 not corrected in 16384 search !!! No matching pattern !!!
Correcting address 0x04A172
Address 0x04A172 not corrected in 16384 search !!! No matching pattern !!!
Correcting address 0x04A174
Bestmatch for address: 0x04A174, searchaddress: 0x04B7D2, offset: 165E, matchbefore: 0, matchafter: 20
Address 0x04A174 not corrected in 16384 search !!! Keeped Best match: 0x04B7D2 - Offset 165E matchbefore: 0 matchafter: 20 !!!
Correcting address 0x04A176
Bestmatch for address: 0x04A176, searchaddress: 0x04B7D4, offset: 165E, matchbefore: 4, matchafter: 16
Address 0x04A176 not corrected in 16384 search !!! Keeped Best match: 0x04B7D4 - Offset 165E matchbefore: 4 matchafter: 16 !!!
Correcting address 0x04A178
Bestmatch for address: 0x04A178, searchaddress: 0x04B7D6, offset: 165E, matchbefore: 8, matchafter: 12
Address 0x04A178 not corrected in 16384 search !!! Keeped Best match: 0x04B7D6 - Offset 165E matchbefore: 8 matchafter: 12 !!!
Correcting address 0x04A17A
Bestmatch for address: 0x04A17A, searchaddress: 0x04B7D8, offset: 165E, matchbefore: 12, matchafter: 8
Address 0x04A17A not corrected in 16384 search !!! Keeped Best match: 0x04B7D8 - Offset 165E matchbefore: 12 matchafter: 8 !!!
Correcting address 0x04A17C
Address 0x04A17C not corrected in 16384 search !!! No matching pattern !!!
Correcting address 0x04A180
Bestmatch for address: 0x04A180, searchaddress: 0x04B7DC, offset: 165C, matchbefore: 2, matchafter: 16
Bestmatch for address: 0x04A180, searchaddress: 0x04A224, offset: A4, matchbefore: 4, matchafter: 8
Bestmatch for address: 0x04A180, searchaddress: 0x049D34, offset: -44C, matchbefore: 2, matchafter: 8
Address 0x04A180 not corrected in 16384 search !!! Rejected Best match: 0x04B7DC - Offset 165C matchbefore: 2 matchafter: 16 !!!
Correcting address 0x04A184
Bestmatch for address: 0x04A184, searchaddress: 0x04B7E0, offset: 165C, matchbefore: 10, matchafter: 8

Address corrected from 0x04A170 to 0x04B7CE - 36% - 105420/286002 - offset 165E 
Address corrected from 0x04A171 to 0x04B7CF - 36% - 105421/286002 - offset 165E     
Address corrected from 0x04A172 to 0x04B7D0 - 36% - 105422/286002 - offset 165E     
Address corrected from 0x04A173 to 0x04B7D1 - 36% - 105423/286002 - offset 165E     
Address corrected from 0x04A174 to 0x04B7D2 - 36% - 105424/286002 - offset 165E     
Address corrected from 0x04A175 to 0x04B7D3 - 36% - 105425/286002 - offset 165E     
Address corrected from 0x04A176 to 0x04B7D4 - 36% - 105426/286002 - offset 165E     
Address corrected from 0x04A177 to 0x04B7D5 - 36% - 105427/286002 - offset 165E     
Address corrected from 0x04A178 to 0x04B7D6 - 36% - 105428/286002 - offset 165E     
Address corrected from 0x04A179 to 0x04B7D7 - 36% - 105429/286002 - offset 165E     
Address corrected from 0x04A17A to 0x04B7D8 - 36% - 105430/286002 - offset 165E     
Address corrected from 0x04A17B to 0x04B7D7 - 36% - 105431/286002 - offset 165C     
Address corrected from 0x04A17C to 0x04B7D8 - 36% - 105432/286002 - offset 165C     
Address corrected from 0x04A17D to 0x04B7D9 - 36% - 105433/286002 - offset 165C     
Address corrected from 0x04A17E to 0x04B7DA - 36% - 105434/286002 - offset 165C
Address corrected from 0x04A17F to 0x04B7DB - 36% - 105435/286002 - offset 165C     
Address corrected from 0x04A180 to 0x04B7DC - 36% - 105436/286002 - offset 165C     
Address corrected from 0x04A181 to 0x04B7DD - 36% - 105437/286002 - offset 165C     

Logged

Passat 1.4tsi Ecofuel Petrol/CNG 150hp Med17.1
Polo35580
Newbie
*

Karma: +9/-0
Offline Offline

Posts: 12


« Reply #18 on: July 15, 2019, 02:59:13 AM »

If only it worked as decently with continental as it does with Bosch stuff... there's definitely LOADS of room for improvement there, just searching for byte strings isn't enough to make it a proper "corrector"... I've tested it on 2 similar Bosch MED17 files, in one of them LAMFA doesn't exist anymore, in the original one it exists. Guess what? the corrector found LAMFA in my file that doesn't have it Cheesy
Hello
I can take a look to Simos support if you provide me some hex + damos couples  Smiley

Yes there is lot of things to improve as reorder the whole code with class and functions or rewrote the address linearization part which cause your LAMFA and Gilgamesh issues or add MEASUREMENT correction support ...
It's a hard work for each improvement and I don't have enough time for now...
Feel free to give help on any part

Best regards

Polo
« Last Edit: July 15, 2019, 06:26:19 AM by Polo35580 » Logged
nabsabs
Newbie
*

Karma: +0/-1
Offline Offline

Posts: 3


« Reply #19 on: October 16, 2019, 02:40:47 AM »

Hello
I am trying this for the first time on an MED9.1 file
I am getting the following errors and it is not being executed

c:\Users\nabih\Desktop\Test>python correct-damos-address.py DamosFile.A2L OriginalDump NewDump
  File "correct-damos-address.py", line 734
    print (('Address 0x%06X skipped because of unreconizable pattern - %d%% - %d/%d              ' % (damosaddress, (100/len(damosaddresslist)*damosaddresscount), damosaddressco
unt, len(damosaddresslist))), end="\r")

                                 ^
SyntaxError: invalid syntax


Image attached below



Can anyone help
Logged
pukacinio
Newbie
*

Karma: +0/-6
Offline Offline

Posts: 18


« Reply #20 on: January 17, 2021, 08:53:18 AM »

Hello
I am trying this for the first time on an MED9.1 file
I am getting the following errors and it is not being executed

c:\Users\nabih\Desktop\Test>python correct-damos-address.py DamosFile.A2L OriginalDump NewDump
  File "correct-damos-address.py", line 734
    print (('Address 0x%06X skipped because of unreconizable pattern - %d%% - %d/%d              ' % (damosaddress, (100/len(damosaddresslist)*damosaddresscount), damosaddressco
unt, len(damosaddresslist))), end="\r")

                                 ^
SyntaxError: invalid syntax


Image attached below



Can anyone help

Installing a newer version of python solved this problem for me.  Wink


Polo35580 it works for me, you're my hero  Grin
« Last Edit: January 17, 2021, 10:54:10 AM by pukacinio » Logged
gt-innovation
Sr. Member
****

Karma: +60/-91
Offline Offline

Posts: 449


« Reply #21 on: February 25, 2021, 09:24:54 AM »

There is a bug for binaries that are loading the module table in a different offset in ram.That means the reference point will be shifted so the parsing of the a2l will not match the actual binary file.

for example in Med17.1.62 you will need 0x809 instead of 0x803.

For those who do not know how to edit the code a quick workaround will be to replace all 0x809 occurrences with 0x803 and then feed the a2l to the script.
Remember to change back the offset in the generated a2l before usage in ols.

Other editors with direct address reference will work just fine without changing the offset.

Great work polo35580.

Logged
nyet
Administrator
Hero Member
*****

Karma: +607/-168
Offline Offline

Posts: 12268


WWW
« Reply #22 on: March 01, 2021, 01:12:39 AM »

for example in Med17.1.62 you will need 0x809 instead of 0x803.

For those who do not know how to edit the code a quick workaround will be to replace all 0x809 occurrences with 0x803 and then feed the a2l to the script.

If only there was a way for multiple people to work on a common set of source code
Logged

ME7.1 tuning guide
ECUx Plot
ME7Sum checksum
Trim heatmap tool

Please do not ask me for tunes. I'm here to help people make their own.

Do not PM me technical questions! Please, ask all questions on the forums! Doing so will ensure the next person with the same issue gets the opportunity to learn from your ex
OzzydaveO
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 1


« Reply #23 on: July 02, 2021, 06:09:23 PM »

Installing a newer version of python solved this problem for me.  Wink


Polo35580 it works for me, you're my hero  Grin


Perhaps a check to make sure the running version of python is ver 3.x  (preferably 3.7 or later)


Some thing like this:

import sys
if sys.version_info < (3, 7):
    print('Please upgrade your Python version to 3.7.0 or higher')
    sys.exit()




Logged
kirukisu
Jr. Member
**

Karma: +1/-4
Offline Offline

Posts: 26


« Reply #24 on: December 10, 2021, 05:46:18 PM »

What size should have .hex file? It doesnt like any of my ME7.5 .hex & .a2l pair . Will .dam be supported?

Code:
PS C:\Users\lukas\Desktop\test> python correct-damos-address-v1.4.py a24c203g.a2l a24c203g.hex NewDump.bin
Correcting Damos file: a24c203g.a2l
Output file: NewDump.A2L
Original Dump file: a24c203g.hex
New Dump file: NewDump.bin
Parsing the Damos file ...
Found S80166 Cpu type
Found ME7.5 Ecu type
Found 4760 address to correct
Done in 0.2122 seconds
Reading original dump of 2464kb in Intel hex format
Error !!! Original dump file of unsupported size !!! 18874368 0x1200000
PS C:\Users\lukas\Desktop\test>
Logged
xmifeng6
Newbie
*

Karma: +0/-2
Offline Offline

Posts: 4



« Reply #25 on: March 19, 2022, 06:47:58 PM »

NICE WORK bro ! thanks for share !
Logged
Fang
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 1


« Reply #26 on: February 09, 2024, 01:45:38 PM »

I wonder where is the script? Sorry I found them .  Grin
« Last Edit: February 09, 2024, 01:48:13 PM by Fang » Logged
Albertoak
Full Member
***

Karma: +6/-16
Offline Offline

Posts: 76


Well done is better than well said....


« Reply #27 on: May 16, 2024, 11:18:48 PM »

Hello


I'd like to share a python script I wrote to convert a damos (A2L) to fit a new dump.
I wrote it in python to allow everybody to improve it. (and check there is no worm in it) Wink


You can imagine that the damos need to be as close as possible of the new dump.
I mean same hardware but different software is ok but it's not applicable with different hardware.

The script use a valid damos/dump couple in entry and a new dump to produce a new damos file.

Supported ecus: ME7.5, MED91, EDC16U34, MED17 and SID208.
The format of the dumps can be Intel Hex, Motorola S19 or Binary.
The size must be 1024kb, 1504kb, 2048kb or 4096kb.

It's possible to add support to new ecus by adding a new ecu definition in the script.
For that the script contains a supportedeculist variable which hold ecu definition dictionaries.
Ex:
# MED17 - 0x80045320
  "ecu"              : "MED17",
  "cpu"              : "TriCore",
  "addresslen"     : 10,
  "addressstart"  : '0x80',
  "addressformat": '0x80%06X\n'
Meanings:
#  "ecu"              : Ecu string found in A2L MOD_PAR entry                                                                        (Ex: ECU "MED17")
#  "cpu"              : Cpu type string found in A2L MOD_PAR entry                                                                 (Ex: CPU_TYPE "TriCore")
#  "addresslen"     : Length of address string in A2L CHARACTERISTIC records                                                (Ex: 0x800574D8 -> 10)
#  "addressstart"  : Sub string to remove to obtain an hex address where data can be found in dump file            (Ex: 0x800574D8 -> '0x80')
#  "addressformat": Format use to rebuild an address line where 6 is the len of hex address without addressstart (Ex: 0x800574D8 -> '0x80%06X\n')

The script will ask for an ecu and cpu type if there is no MOD_PAR entry in the A2L.


Here is how the script process:
- Read the damos file and create an address table
- Read the original dump
- Read the new dump
- Correct the address table by searching best match pattern from original dump in new dump using dycothomic search method from original address
- Linearize the address table
- Create a new damos using the address table

And here the command line to execute it:
Code:
python correct-damos-address.py DamosFile.A2L OriginalDump NewDump

It take less than 10 minutes to correct most damos on my computer.
There may be some mistakes due to linearization but it work pretty well in most case.

Feel free to test it and report if it fit your needs.   Cheesy


Edit:

Update script to version 1.1.
# ChangeLog  : v1.0 - Original release
#                          - Add MED17 Ecus support
#                          - Add Intel Hex dump support

Edit2:

Update script to version 1.2.
# ChangeLog  : v1.2 - Add ME7.5 Ecus support

Edit3:

# ChangeLog  : v1.3 - Add MED9.1 Ecus support
#                          - Add EDC16U34 Ecus support
#                          - Add Motorola S19 dump support
#                          - Add supported ecu list to allow adding ecu type (See "Supported Ecu List")

Edit4:

# ChangeLog  : v1.4 - Rewrite Intel Hex and Motorola S19 support to handle address bases
#                          - Add SID208 Ecus support


Best regards

Polo

Hello mate.

I have modified the script to be able to make corrections in Ford's ME 9.0 ECU. in case you want to update the first post. I upload said script. greetings!!!

 # ME7.5 - 0x8574D8
  "ecu"          : "ME7.5",
  "cpu"          : "S80166",
  "addresslen"   : 8,
  "addressstart" : '0x8',
  "addressformat": '0x8%05X\n'
}, {
  # ME9.1 - 0x1C9A02
  "ecu"          : "MED91",
  "cpu"          : "GoldenOak",
  "addresslen"   : 8,
  "addressstart" : '0x',
  "addressformat": '0x%06X\n'
}, {
  # ME9.0 - 0x1C9A02
  "ecu"          : "ME90C",
  "cpu"          : "GoldenOak",
  "addresslen"   : 8,
  "addressstart" : '0x',
  "addressformat": '0x%06X\n'
}, {
  # MED17 - 0x80045320
  "ecu"          : "MED17",
  "cpu"          : "TriCore",
  "addresslen"   : 10,
  "addressstart" : '0x80',
  "addressformat": '0x80%06X\n'
}, {
  # EDC16U34 SIO - 0x1C2030
  "ecu"          : "SIO",
  "cpu"          : "SilverOak",
  "addresslen"   : 8,
  "addressstart" : '0x1',
  "addressformat": '0x1%05X\n'
}, {
  # SID208 - 0xA0200AD4
  "ecu"          : "SID208",
  "cpu"          : "TriCore",
  "addresslen"   : 10,
  "addressstart" : '0xA0',
  "addressformat": '0xA0%06X\n'
Logged
Pages: 1 [2]
  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Page created in 0.032 seconds with 17 queries. (Pretty URLs adds 0s, 0q)