Combine blocks of a Motorola S Record file into a single continuous address space and insert CRC

Abhishek Anand
3 min readFeb 6, 2021

The Motorola S Record file generated by the build chain has divided the file into 2 separate blocks with different address spaces. ECU flashing utility needs this file to have a single continuous block with the CRC of the file inserted at the end.

How to combine these blocks and generate a S Record file with a continuous address space ?

The tool that we will be using is HexView. This is available in the standard Vector installation package. Its an amazing tool. Check out its documentation on Vector website.

1. First step is to convert the given S record file into a binary file and completely strip off the address information from the file.

path/to/hexview.exe path/to/source_file/sourceFile.srec /s /XN -o path/to/destination_file/intermediateFile.bin

/s — is for silent operation of HexView tool

/XN — convert the given file to a binary file

* -o — whatever follows this is the output file path name

2. Next step is to convert this binary file back to a S Record file, this file will now have a default continuous linear address and will not be divided into blocks.

path/to/hexview.exe path/to/source_file/intermediateFile.bin /s /XS:32 -o path/to/destination_file/cleanSrecFile.srec

/XS — Convert to S Record file

:32–32 bytes per record line (S3 file)

3. Next step is to remap this S Record file to the desired address space

path/to/hexview.exe path/to/source_file/cleanSrecFile.srec /s /remap:BankStartAddress-BankEndAddress,LinearBaseAddress,BankSize,BankIncrement /XS:32 -o path/to/destination_file/cleanSrecFile_remaped.srec

for our case we use these values

path/to/hexview.exe path/to/source_file/cleanSrecFile.srec /s /remap:0x0–0x3bffff,0x80040000,0x3C0000,0x10000 /XS:32 -o path/to/destination_file/cleanSrecFile_remaped.srec

BankStartAddress — start address of the input file. This was assigned by default by the tool when binary file was converted to S Record. [0x0]

BankEndAddress — end address of the input file. [0x3bffff]

LinearBaseAddress — start address of the output file. This is the start address of the resultant remapped S Record file. [0x80040000]

BankSize — size of bank should be the total size of the data in the source file. This will result in a single block in the remapped file. [0x3C0000]

BankIncrement — this is not relevant for our use, leave it to any default value [0x10000]

4. Inserting CRC at the end of the file.

path/to/hexview.exe path/to/source_file/cleanSrecFile_remaped.srec /s /CS9:@0x803FFFFC;0x80040000–0x803FFFFB /XS:32 -o path/to/destination_file/cleanSrecFile_remaped_CRC.srec

/CS9–9 here refers to the CRC32 algorithm

@0x803FFFFF — is the address where the CRC will be inserted

0x80040000–0x803FFFFB — range of data over which the CRC calculation will be done.

/XS:32 -o — creates a S Record file with the CRC inserted at the end of it

All of this can also be done directly using the HexView GUI. You can experiment with the GUI first and then update your build chain once the kinks are ironed out.

  1. To convert the file to binary : File > Export > Export Binary-Data

2. To convert the file to S Record : File > Export > Export as S-Record

3. To Remap the file : Edit > General Remapping

4. CRC calculation: Edit > Create Checksum

Resultant file should look something like this.

Notice the address space has changed but the length of the file is still the same. This process has not inserted any filler data into the file.