About storing initialization information on HCS08 device

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

About storing initialization information on HCS08 device

Jump to solution
2,768 Views
Giox79
Contributor I

Good morning,

I'm developing an application on a HCS08QE device and I need some help.

My problem is the following one:

my application need a set of initialization information that depends on the serial number of the installed device, and that therefore I cannot select at compile time. 

 

In order to solve my problem I thought about using srecord (srecord.sourceforge.net), creating (with a C++ desktop application) a binary file that contains a struct with the desired data, and then inserting it at the desired address through srecord.

 

However I found no reference to this platform in this forum so I have 2 question:

 

  1. is there an easier way to accomplish the desired task, and therefore I don't need it on HCS08?
  2. is there some "tutorial" that explain how to perform these operations?
I searched the web for Flash srecord modification, and similar words, but very often I get link to forum question (I will be one of them :-D) and no tutorial.
Is there someone that can help me?
Many thanks
Giovanni
Labels (1)
0 Kudos
Reply
1 Solution
1,608 Views
tonyp
Senior Contributor II

The S19 file format is very simple, and it should be rather easy to write a routine to get any binary data into S19.

 

Wikipedia has good description for it.

 

Or, get a simple binary to S19 conversion utility like this one.

From the command line, type BINEX KEY.BIN KEY.S19 $F000

where KEY.BIN is your binary data file, KEY.S19 is the output file, and $F000 is whatever starting address you want to place the data at.

 

View solution in original post

0 Kudos
Reply
14 Replies
1,608 Views
Lundin
Senior Contributor IV

Production programmers, such as PE Cyclone Pro, typically have a serial number feature implemented. I would check that out before starting to re-invent the wheel.

 

http://www.pemicro.com/products/product_viewDetails.cfm?product_id=1&CFID=1127929&CFTOKEN=18794447

0 Kudos
Reply
1,608 Views
Giox79
Contributor I

Hi Lundin,

thanks a lot for your help.

In effect I need something more than a serial number.

 

The value that should be stored are about 300 bytes of data, and they dependens on the device (something like a crypto key).

I will check if this kind of data are supported by the P&E device.

Thanks a lot

Giovanni

0 Kudos
Reply
1,610 Views
Lundin
Senior Contributor IV

In that case it might be best to do as you suggested in your first post: reserve memory for the data in the flash by allocating a "dummy struct", then edit the s-record externally before programming it.

.

0 Kudos
Reply
1,610 Views
Giox79
Contributor I

Hi

thanks for your help. And do you have any experience about the tools than could be useful to accomplish the desired task?

Any suggestion will be really appreciated (link to tool, C/C++ class able to parse and modify srecord etc).

 

Thanks a lot for your help

Giovanni

 

 

0 Kudos
Reply
1,610 Views
tonyp
Senior Contributor II

You may find it easier to create a separate S19 file with only the 'unique-per-device' data block, and then simply combine the two S19 files into one.  You may have to remove the S9 record from one of the two (normally you'd want to do that for the firmware S19 because it's the one that will be built once per version), or simply sort the final S19 so that both S9 records end up at the end.

 

Another idea: If your 'key' is somehow mathematically derived solely from the S/N (and assuming the key generation code isn't too demanding in terms of code size), why not have the firmware generate it on very first power up (normally done in-house before testing), and save the generated key to Flash.  Following resets will see the data is already there and not mess with it, or re-calculate it.

 

0 Kudos
Reply
1,610 Views
Giox79
Contributor I

Hi thanks for your help.

The second idea is quite difficult: in effect I don't have enough memory to allocate both the data and the algorithm (the .text section is already almost full).

 

About the first idea: do you have some suggestion on how to create a valid s19 file?

I'm able to write a binary file with the interesting data, how do I convert it to S19 file? Any C++ library (that I can integrate in my application) is available?

Any help will be very useful.

Thanks for your support

 

Gio

0 Kudos
Reply
1,609 Views
tonyp
Senior Contributor II

The S19 file format is very simple, and it should be rather easy to write a routine to get any binary data into S19.

 

Wikipedia has good description for it.

 

Or, get a simple binary to S19 conversion utility like this one.

From the command line, type BINEX KEY.BIN KEY.S19 $F000

where KEY.BIN is your binary data file, KEY.S19 is the output file, and $F000 is whatever starting address you want to place the data at.

 

0 Kudos
Reply
1,608 Views
Giox79
Contributor I

Here it is :-D

Thanks a lot.

I know, may be it was a quite stupid question, but I wasn't able to solve it.

Now I have to understand how to merge the files (but I think this is possible through srecord utility, or may be through P&E tools)

Thanks again

Giovanni

0 Kudos
Reply
1,608 Views
tonyp
Senior Contributor II

Merging the files is just a simply copy (or cat, if in Linux) operation.

 

You can have the whole process run from a single batch or MAKE file, something like this:

 

generate_key mykey.bin

binex mykey.bin mykey.s19 $F000

copy firmware.s19+mykey.s19 final.s19

 

then load final.s19 into your device.  (I'm assuming you have edited out the S9 record from the firmware.s19 file using any ASCII text editor, like NotePad.)

 

0 Kudos
Reply
1,608 Views
Giox79
Contributor I

Hi, thanks again.

I'm sorry for the late replay but I was out of my office.

 

I didn't understand the line "I'm assuming you have edited out the S9 record from the firmware.s19 file using any ASCII text editor, like NotePad."

 

However I will try the suggested approach next weekend.

Thanks again

Giovanni

0 Kudos
Reply
1,608 Views
kef
Specialist I

It was meant that you can concatenate two S-records files like this:

 

copy file1.s19 + file2.s19  file1_plus_file2.s19

 

But S9 records are usually found at the end of S-records file and some bootloaders or flash burners may assume S9-record is the sign of the end of your S-records file, and will ignore S-records from 2nd file, because they come after S9-record. To solve this you should remove S9 record from the end of file1 or from the middle of concatenated file.

0 Kudos
Reply
1,608 Views
Giox79
Contributor I

Well, finally I understood.

Thank you for your help.

May be it was a stupid question, but this is my first project.

Thanks again for this very useful forum.

Giovanni

0 Kudos
Reply
1,608 Views
admin
Specialist II

I'm looking in my s19/mot file (also tried the raw), and can't find where my data is located. What am I missing? If I initialize a static int array with some pattern of bytes, why can't I find that data somewhere in the flash file? I "read back" the contents of the entire chip with j-flash, and can't tell where anything is located. Many thanks!

0 Kudos
Reply
1,608 Views
bigmac
Specialist III

Hello,

If you are initializing a static array within your code, the data will actually be located in RAM, starting at a specific address.  If you are using CW, the location of the data may be identified from the .MAP file generated by the CW compile/link process.  I suspect there may be some misunderstanding about the use of the 'static' modifier.

If you require that the data array should be located within flash, you would initialize a constant array, using the 'const' modifier.  You should then observe, within the .MAP file, the flash address at which the array commences.

Regards,

Mac

0 Kudos
Reply