Skip to content

Commit

Permalink
Fix srec execution start address
Browse files Browse the repository at this point in the history
  • Loading branch information
eerimoq committed Aug 31, 2016
1 parent 663660e commit d8c9150
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
41 changes: 19 additions & 22 deletions bincopy.py
Expand Up @@ -14,7 +14,7 @@
from io import StringIO

__author__ = 'Erik Moqvist'
__version__ = '7.1.2'
__version__ = '7.1.3'

DEFAULT_WORD_SIZE_BITS = 8

Expand Down Expand Up @@ -444,7 +444,7 @@ def add_ihex(self, records, overwrite=False):
elif type_ == 5:
self.execution_start_address = int(binascii.hexlify(data), 16)
else:
raise Error('bad type {}'.format(type_))
raise Error("bad type '{}'".format(type_))

def add_binary(self, data, address=0, overwrite=False):
"""Add given data at given address. Set `overwrite` to True to allow
Expand Down Expand Up @@ -500,6 +500,10 @@ def as_srec(self, number_of_data_bytes=32, address_length_bits=32):
header.append(pack_srec('0', 0, len(self.header), self.header))

type_ = str((address_length_bits // 8) - 1)

if type_ not in ['1', '2', '3']:
raise Error("bad type '{}'".format(type_))

data = [pack_srec(type_,
address // self.word_size_bytes,
len(data),
Expand All @@ -514,23 +518,16 @@ def as_srec(self, number_of_data_bytes=32, address_length_bits=32):
else:
raise Error('too many records: {}'.format(number_of_records))

if ((self.execution_start_address is not None)
and (self.segments.get_minimum_address() == 0)):
# Add the execution start address.
if self.execution_start_address is not None:
if type_ == '1':
footer.append(pack_srec('9',
self.execution_start_address,
0,
None))
record = pack_srec('9', self.execution_start_address, 0, None)
elif type_ == '2':
footer.append(pack_srec('8',
self.execution_start_address,
0,
None))
elif type_ == '3':
footer.append(pack_srec('7',
self.execution_start_address,
0,
None))
record = pack_srec('8', self.execution_start_address, 0, None)
else:
record = pack_srec('7', self.execution_start_address, 0, None)

footer.append(record)

return '\n'.join(header + data + footer) + '\n'

Expand Down Expand Up @@ -576,12 +573,12 @@ def as_ihex(self, number_of_data_bytes=32, address_length_bits=32):

if self.execution_start_address is not None:
if address_length_bits == 16:
address = binascii.unhexlify('%08X'
% self.execution_start_address)
address = binascii.unhexlify(
'%08X' % self.execution_start_address)
footer.append(pack_ihex(3, 0, 4, address))
elif address_length_bits == 32:
address = binascii.unhexlify('%08X'
% self.execution_start_address)
address = binascii.unhexlify(
'%08X' % self.execution_start_address)
footer.append(pack_ihex(5, 0, 4, address))

footer.append(pack_ihex(1, 0, 0, None))
Expand Down Expand Up @@ -641,7 +638,7 @@ def as_array(self, minimum_address=None, padding=b'\xff', separator=', '):
word = 0

for byte in binary_data[offset:offset + self.word_size_bytes]:
word <<= 8;
word <<= 8
word += byte

words.append('0x{:02x}'.format(word))
Expand Down
1 change: 1 addition & 0 deletions tests/files/in_crop_2_4.s19
@@ -1,3 +1,4 @@
S00F000068656C6C6F202020202000003C
S105000202A650
S5030001FB
S9030000FC
1 change: 1 addition & 0 deletions tests/files/in_exclude_0_9.s19
Expand Up @@ -2,3 +2,4 @@ S00F000068656C6C6F202020202000003C
S123000921FFF07C6C1B787C8C23783C600000386300004BFFFFE5398000007D836378802C
S1200029010014382100107C0803A64E80002048656C6C6F20776F726C642E0A00A9
S5030002FA
S9030000FC

0 comments on commit d8c9150

Please sign in to comment.