What I want to do is set the serial number for a device as the code is downloaded to the device. I have a nice utility that can download hex file images to my device. I could store the serial number as a constant in a c file which I could modify, compile, link and then download, but it is a bit long winded (and requires SDCC). Another option would be to hack the hex file changing a fixed serial number as required, but this is error prone and not very flexible.
I am considering scanning the map file for my symbol name to get its address. Then scanning the hex file to locate the required address and modify it before downloading the code to the device.
What I want is a simple and supportable solution, which preferably I can build into a single executable without the need for dlls or installing SDCC.
Has anyone tried to do something similar before? Is there an easier way?
I am currently using SDCC 2.8.0 with SiLabs F340 running on Windows XP Pro SP2
Thanks in advance
You know, SDCC can be run from the command line. You could write a batch file or script to compile and link and generate the hex file properly.
Hacking HEX files is doable...we did it in the dark ages. Actually worked with a guy who "hand assembled" and wrote into an S record file. The problem is the checksum field. not only do you have to modify the addresses, you have to recompute the checksum.
Stick the serial number into its own file and link in as a, dare I say, GLOBAL. That will reduce the compilation time and I can't imagine that the link would take very long on any modern computer.
Automate your SDCC compilation process and relink...Easy, Neat, Automatic!
you can also use srecord http://srecord.sf.net
(shortly mentioned in the manual 3.1.2 "Postprocessing the Intel Hex file")
to read both the SDCC generated hex file and f.e. another binary file
and paste them together with offsets.
You'd additionally need a small program for the host that increments the
serial number file. The small program is needed unless someone implements
a similar feature as in the srecord feature request "Input filter for increment" :)
In your source you could specify a variable/array/struct so that address
and memory space match (like "__code __at(0xff00)" (see manual
"3.6 Absolute Addressing"))
Or access the data by a pointer to code memory.
(126.96.36.199 "Pointers to MCS51/DS390 speciﬁc memory spaces")