Jump to content

creating an Intel hex or S-Record file


FixedWire

Recommended Posts

Hi everyone,

After searching both forums I've not been able to source a way to easily create either file format. There are examples reading these files but not writing them.

Segger simply gave the Python script below.
Unfortunately we can't simply just install Python as this is in a regulated environment. So we're hoping for a native LabVIEW solution.

Surely someone has done this before. It gets a bit complicated if we need to roll our own down to the bit level & then having to do a full validation on it. I'd really rather not go there.

Thanks in advance!

 

python script (the "intelhex" does the heavy lifting)

from intelhex import IntelHex

h = IntelHex(None)


h[0x1000] = 0x12


h[0x1001] = 0x34


h[0x1002] = 0x56


h[0x1003] = 0x78

h.write_hex_file('patch.hex')

Link to comment

Typically, writing such a beast isn't exactly rocket science. But validating it is, and whoever could send you some code doing this, it would be:

- Just implementing as much as they needed at that point and everything else might be not there or wrong

- Almost certainly not validated: "Look mam it works, without hands!" "Great son, now don't touch it!"

So the major part of the work would still be on you unless someone had a real product that they did some good validation on, and will cost considerable money.

Writing your own will be unsexy: Who the heck is still writing assembly binary files anymore? 😀, but it is most likely unavoidable in this case and the real work is in the validation that you mention and that will have to be done anyhow if your product is in such a regulated industry.

Link to comment

Couple of years ago I was working with SREC files, but I only needed to import them.  Initially I used LabVIEW but switch to C# as it was more suited.  This is only the import part, maybe it can get you started (reverse the process?, idk).  

as Rolf said, my concern was only import and my project requirement and then switched to C# anyways, the only thing I tested was making sure both my LabVIEW and C# were doing the import the same way. 

Parse SREC File.vi

 

  • Thanks 1
Link to comment

Yes I too am only familiar with reading these file types but not writing.  NI has the ECU Measurement and Calibration Toolkit which is a CAN toolkit for performing XCP and CCP functions.  One of which is flashing new software to an ECU over CAN.  In there is the start of some code that reads SREC and HEX files.  Some of the file types were had poor performance and I made an attempt at improving them.  This code can be found in the CAN File IO package here. But I admit that is a whole lot of code to install for some simple file reading stuff so I've attached the important bits here.  This appears to support S0 through S9 types, and some kind of HEX files that start with a ":".  Looking at the code I still see some room for improvement.

Hooovahh SREC and HEX.zip

Link to comment

Many moons ago I wrote a cloner for embedded devices. It basically dumped a device firmware image to an S-Record file which was then used to upload to other devices on the production line.

Like Rolf said. It did enough to do the task for those devices and took a couple of hours to write the basic functionality - S-Records aren't a difficult format. It just started at an address and byte-copied chunks so only S3 was required for that (and the S0/9).

I think you'll find that most people either knock up a quick utility like that or invoke the programmer utility.

10 hours ago, hooovahh said:

some kind of HEX files that start with a ":".

That's the Intel Hex format.

Link to comment
On 11/9/2021 at 8:42 PM, FixedWire said:

We ended up finding a relatively simple solution using command line calls from  http://srecord.sourceforge.net/
At least there is source code if it is ever needed and it's compiled unlike the Python approach.

For what we need the risks can be mitigated.

Thanks everyone. It's just incredible to have such resources available. Kudos to all.

They also support a shared library interface!

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.