eerimoq / bincopy

Mangling of various file formats that conveys binary information (Motorola S-Record, Intel HEX, TI-TXT, Verilog VMEM, ELF and binary files).
MIT License
109 stars 38 forks source link

intel hex Extended Linear Address #4

Closed awinner-stg closed 8 years ago

awinner-stg commented 8 years ago

There is an issue with outputting type 4 addresses that are > 0xffff, they create address that have 5 digits, and are invalid in the format. i.e. have a segment with address as 0x1000e, and it will be output as two records, one the Extended Linear Address record which is correct, but then the data record has all 5 didgits of the address. example:

read and then write the following text:

:020000040001F9 :04000E00A4CFFFDD9F

you will get an error on the write due to the CRC routine getting an odd number of digits:

:020000040001F9 :041000E00A4CFFFDD9F note address is 0x1000e

the issue is in the as_ihex function:

def as_ihex(self, size=32, address_length=32): """Return string of Intel HEX records of all data.

    """

    data_address = []
    extmaximumed_address = -1

    for address, data in self.segments.iter(size):
        address //= self.word_size_bytes

        if address_length == 32:
            if ((address >> 16) & 0xffff) > extmaximumed_address :
                extmaximumed_address = ((address >> 16) & 0xffff)

I added this fix as a hack for my situation, but would not work for subsequent segments that are in the same address space.

                address = address & 0xffff   

end of hack

                packed = pack_ihex(4,
                                   0,
                                   2,
                                   binascii.unhexlify('%04X'
                                                      % extmaximumed_address))
                data_address.append(packed)
        else:
            raise Error('unsupported address length %d'
                             % address_length)

        data_address.append(pack_ihex(0, address, len(data), data))

But the function also assumes that all address are in sorted order, which I do not believe is the case for all Intel hex files, unless you are sorting them as you insert into the list, I may have missed that.

eerimoq commented 8 years ago

I implemented a fix in c420fb248781f1ed3deb29c510e4e94f397f2a79, created a tag 2.1.2 and uploaded it to PyPi.

The segments are inserted in ascending order, so iterating over the segments assuming ascending address should work. I split the address into the upper and lower 16 bits in as_ihex(), and are using the upper 16 for extended linear address and the lower in the data record.

A test case was added called test_issue_4(). It uses your example data and also another record testing that the segments are inserted by ascending address.

Thanks for the bug report =)

awinner-stg commented 8 years ago

Found another issue, if you read in an Intel hex file, then rewrite it, if there is a Type 0x05 record in it is lost as the program ignores those. Anyway to retain them?

Anthony Winner Senior Software Engineer Software Technology Group 4240 SW 109th Avenue Beaverton, OR 97005 Office Phone: 503.672.9245 Email: anthonyw@softwaretechnology.commailto:mrachelg@softwaretechnology.com Website: http://www.softwaretechnology.comhttp://www.softwaretechnology.com/

Electronic Transmission Confidentiality Notice The information contained in this electronic transmission is private, confidential, the property of the sender, and intended for the use of the recipient(s), only. If you are not the addressee, any disclosure, copying, distribution or use of this information for any purpose is strictly prohibited. If you have received this information in error, please notify the sender, anthonyw@softwaretechnology.commailto:mrachelg@softwaretechnology.com, immediately by e-mail and then delete this message. Thank you. [FE.EN.1]

From: Erik Moqvist [mailto:notifications@github.com] Sent: Wednesday, June 01, 2016 11:58 AM To: eerimoq/bincopy Cc: Anthony Winner; Author Subject: Re: [eerimoq/bincopy] intel hex Extended Linear Address (#4)

Closed #4https://github.com/eerimoq/bincopy/issues/4.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/eerimoq/bincopy/issues/4#event-678863676, or mute the threadhttps://github.com/notifications/unsubscribe/ASdG333BkLqeoixAy0EAJmr3ijzqqFP-ks5qHdYkgaJpZM4Irnh2.

awinner-stg commented 8 years ago

Will also need that info on read to jump to that vector, so need some solution……

Anthony Winner Senior Software Engineer Software Technology Group 4240 SW 109th Avenue Beaverton, OR 97005 Office Phone: 503.672.9245 Email: anthonyw@softwaretechnology.commailto:mrachelg@softwaretechnology.com Website: http://www.softwaretechnology.comhttp://www.softwaretechnology.com/

Electronic Transmission Confidentiality Notice The information contained in this electronic transmission is private, confidential, the property of the sender, and intended for the use of the recipient(s), only. If you are not the addressee, any disclosure, copying, distribution or use of this information for any purpose is strictly prohibited. If you have received this information in error, please notify the sender, anthonyw@softwaretechnology.commailto:mrachelg@softwaretechnology.com, immediately by e-mail and then delete this message. Thank you. [FE.EN.1]

From: Anthony Winner Sent: Wednesday, June 22, 2016 8:06 AM To: 'eerimoq/bincopy' Subject: RE: [eerimoq/bincopy] intel hex Extended Linear Address (#4)

Found another issue, if you read in an Intel hex file, then rewrite it, if there is a Type 0x05 record in it is lost as the program ignores those. Anyway to retain them?

Anthony Winner Senior Software Engineer Software Technology Group 4240 SW 109th Avenue Beaverton, OR 97005 Office Phone: 503.672.9245 Email: anthonyw@softwaretechnology.commailto:mrachelg@softwaretechnology.com Website: http://www.softwaretechnology.comhttp://www.softwaretechnology.com/

Electronic Transmission Confidentiality Notice The information contained in this electronic transmission is private, confidential, the property of the sender, and intended for the use of the recipient(s), only. If you are not the addressee, any disclosure, copying, distribution or use of this information for any purpose is strictly prohibited. If you have received this information in error, please notify the sender, anthonyw@softwaretechnology.commailto:mrachelg@softwaretechnology.com, immediately by e-mail and then delete this message. Thank you. [FE.EN.1]

From: Erik Moqvist [mailto:notifications@github.com] Sent: Wednesday, June 01, 2016 11:58 AM To: eerimoq/bincopy Cc: Anthony Winner; Author Subject: Re: [eerimoq/bincopy] intel hex Extended Linear Address (#4)

Closed #4https://github.com/eerimoq/bincopy/issues/4.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/eerimoq/bincopy/issues/4#event-678863676, or mute the threadhttps://github.com/notifications/unsubscribe/ASdG333BkLqeoixAy0EAJmr3ijzqqFP-ks5qHdYkgaJpZM4Irnh2.

eerimoq commented 8 years ago

I'll have a look at it tonight. As you have already understood Indel Hex is not fully implemented yet. I'll do my best keeping up implementing the improvment requests. =)

Erik

awinner-stg commented 8 years ago

Found a simple fix, replace the ignore print with ‘ self.execution_start_address = (int(binascii.hexlify(data), 16))’

Rest of the logic is already there. Once I added that, my in / out files match perfectly. Will assume that the get / set functions for execution_start_address will work for my other script….

Thanks for the support….

Anthony Winner Senior Software Engineer Software Technology Group 4240 SW 109th Avenue Beaverton, OR 97005 Office Phone: 503.672.9245 Email: anthonyw@softwaretechnology.commailto:mrachelg@softwaretechnology.com Website: http://www.softwaretechnology.comhttp://www.softwaretechnology.com/

Electronic Transmission Confidentiality Notice The information contained in this electronic transmission is private, confidential, the property of the sender, and intended for the use of the recipient(s), only. If you are not the addressee, any disclosure, copying, distribution or use of this information for any purpose is strictly prohibited. If you have received this information in error, please notify the sender, anthonyw@softwaretechnology.commailto:mrachelg@softwaretechnology.com, immediately by e-mail and then delete this message. Thank you. [FE.EN.1]

From: Erik Moqvist [mailto:notifications@github.com] Sent: Wednesday, June 22, 2016 8:15 AM To: eerimoq/bincopy Cc: Anthony Winner; Author Subject: Re: [eerimoq/bincopy] intel hex Extended Linear Address (#4)

I'll have a look at it tonight. As you have already understood Index Hex is not fully implemented yet. I'll do my best keeping up implementing the improvment requests. =)

Erik

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/eerimoq/bincopy/issues/4#issuecomment-227776700, or mute the threadhttps://github.com/notifications/unsubscribe/ASdG36qspao-eFeTKz9BBnh8-6Jb_q-Xks5qOVF8gaJpZM4Irnh2.

eerimoq commented 8 years ago

Pushed the fix in version 2.1.4. Tried to upload the new version to pypi but failed. The login just hangs and nothing happens.

eerimoq commented 8 years ago

At last, uploaded to pypi.