Giter Site home page Giter Site logo

Comments (11)

fernandez85 avatar fernandez85 commented on August 19, 2024

Can You provide an example of a file before encode and after decode?

If i understood correctly (from the "fix" code) to have your image written correctly You must put first line at one before last position. I'm guessing that this is a Starting Address record. IntelHex standard doesn't say strictly about position. It can be placed at the beginning, it can be placed at the end (before End of File record). It could be placed between data segments as well. But this is just my theory - honestly I never seen such Hex file. Nevertheless this IntelHex implementation always place Starting Address record at the beginning of the file.

By the way, Your "fix" code can be simplified:

file = open(output_file_name, 'r')
lines = file.readlines()
file.close()
output = open(output_file_name, 'w')
lines.insert(-1, lines[0])
for line in lines[1:]:
    output.write(line)
output.close()

Of course if I clearly read out your intentions. But same is what You get when You run your code.

from intelhex.

fernandez85 avatar fernandez85 commented on August 19, 2024

I looked at the IntelHex standard again, and I realized that Starting Address record types are numbered higher then Data and Extended Adress records. So maybe this implementation isn't that good after all.
But first let us check the root-cause of your problem.

from intelhex.

bialix avatar bialix commented on August 19, 2024

IntelHex startard allows separate records to be freely swapped until they all within one 64K page IIRC. Additional starting records can appear anywhere in the file.
Anyway, in your approach I would not rely on MD5 hashing of binary file. With IntelHex files this is not stable approach.
You can use hexdiff.py utility to actually compare content of 2 files, if you wish.
Or maybe you can provide some minimal example of your files with different MD5 before and after processing. It's possible that starting address record is to blame here. I don't really need your binary files, you can inspect with text editor first and last lines and show first 8 bytes here.
BTW the very last line must be EOF record always. So puting it to the start - sounds very wrong. Without real data it's hard to tell what's wrong actually.

from intelhex.

LukeGary462 avatar LukeGary462 commented on August 19, 2024

Thanks for looking in to this. Our images are over that size boundary (about 100K), unfortunately I cannot share the hex files here, but I have used hex files with swapped lines in the past when merging in bootloaders in the image. The reasoning behind using the MD5 is because my firmware guy wants that to be used (not my choice). When I diff the files I can see exactly the line that gets swapped. I will get together a small snippet of the beginning and the end of the files to show you what is happening.

from intelhex.

LukeGary462 avatar LukeGary462 commented on August 19, 2024

Source File on the Right. Reconstructed on the Left

Beginning of file
Meld_2020-07-09_13-09-33

End of file
Meld_2020-07-09_13-10-19

from intelhex.

fernandez85 avatar fernandez85 commented on August 19, 2024

Yes, that is the Start Linear Address record all right.
As I already wrote. Current implementation always places Starting Address records at beginning. So no matter where it will be placed when importing a file (e.g. using 'loadhex') You will have always Starting Address record at the beginning of the file when exporting to a file (e.g. using 'write_hex_file').

from intelhex.

bialix avatar bialix commented on August 19, 2024

"the data is stored in a database as a JSON record" - why don't you save actual hex file content to database then?

from intelhex.

bialix avatar bialix commented on August 19, 2024

I will change the title of this issue. It can be fixed with another option of write_hex_file, oh my. That's already too complex.

from intelhex.

LukeGary462 avatar LukeGary462 commented on August 19, 2024

"the data is stored in a database as a JSON record" - why don't you save actual hex file content to database then?

I'm starting to think I should just do that... This module is very nice though. There is talk of changing bootloaders, so being able to merge the files with this module without manually creating new releases seems like nice future proofing

from intelhex.

LukeGary462 avatar LukeGary462 commented on August 19, 2024

Yes, that is the Start Linear Address record all right.
As I already wrote. Current implementation always places Starting Address records at beginning. So no matter where it will be placed when importing a file (e.g. using 'loadhex') You will have always Starting Address record at the beginning of the file when exporting to a file (e.g. using 'write_hex_file').

Im not sure why this is happening, this was compiled and linked in IAR EWARM

from intelhex.

fernandez85 avatar fernandez85 commented on August 19, 2024

Why You have in Your Hex file Start Record on the end? Probably by a software design. @bialix already wrote that there isn't only one place to put that record. IntelHex documentation doesn't describe this precisely.

It can be fixed with another option of write_hex_file, oh my. That's already too complex.

Yeah. This function is really evolving very dynamically ;)
I thinking about the solution. I see 2 ways:

  1. We only care about importing and when loading we only check were it's placed, on beginning or at the end. If somewhere else then I suggest to just force 'on beginning' option in this case. And when writing we set it as-is (resolved while loading)
  2. Option 1. + new parameter, that would replace 'write_start_addr' (in 'write_hex_file' function) with for example 'start_addr_mode', which would have 3 options:
    • 'sof' - start of file, old behavior when 'write_start_addr'=True
    • 'eof' - end of file, naturally before EOF record
    • 'none' - old behavior when 'write_start_addr'=False

from intelhex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.