How to change a serial number in frimware..Automatically

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My firmware contains a serial number 3 bytes long.
I want to be able to change serial number before programming chip, without having to change it in source code and recompiling. Is there an utility for that? Any recommendations?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The srecord tools.

Why not store it in EEPROM, and program that one separately?

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've had eeprom corruption in the past. Rather use flash. Maybe that's a subject for another thread.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have the same requirement. Want to store the serial number in bootloader flash region before setting the fuses to protect the bootloader.
It would be nice if the STK500 command line tools would provide a function like this.
I am using the provided function to store the calibration value (or better, two for low and high supply voltage) before setting the fuses. This works very nicely. Why not provide a function to write arbitrary values (possibly self-incrementing) to flash?

EEPROM can always be changed/get corrupted and this would destroy the unique serial number.

Jörg.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, you can always "reserve" your location in flash, and leave it erased to 0xff or init it to 0xff. Then after programming the bootloader, have a utility create the "mini" .HEX file with your serial number and program it over the top with no erase.

I've also "forced" my compiler to put the serial number (or similar customization) information into an otherwise unused memory area so it ends up in its own .HEX record. My program then makes a copy of the entire .HEX file looking for the magic record and then re-creates the magic record with the info. Then there is just one ISP pass and it will verify.

If you use a linker I suppose one could create an object file on the fly, or pre-create an infinite number of them and then link to the needed one.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I had done a similar thing, and it was easy to 'reserve' a location in flash for the serial number, and change it with an small program that flashes the 'temporary.hex' through SKT500 and AVRISP.

But in my case, I should also generate a new CRC over the whole program (including the serial number), and store also at a different location. This part was a little bit more difficult.

Guillem.
"Common sense is the least common of the senses" Anonymous.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lee, I like your idea of the mini.hex file
Would it look like this
serial_number[] = {0xff,0xff,0xff,0xff};
Then over write it with the mini.hex file

How do I figure out the address to create the mini.hex file, I use Codevision C compiler.
Then I could write a small utility to generate the mini.hex
2)Does it use the intel HEX standard?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

2) Look at your current .HEX files. Yes.

1) Search the Yahoo support board for "oldpc" for prior discussions. IIRC the upcoming new version will allow it directly with the @ syntax. No, I wouldn't actually have a source program, but rather just build the Intel Hex line from scratch.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is also a hardware solution (if you have a spare I/O pin and the extra cost does not matter). Many of the MAXIM iButton one wire devices (like the DS2401) supply a unique 48 bit serial number. It does have the advantage of being permanent, but a possible disadvantage is you must use all 48 bits to guarantee each serial number remains unique. It is programming with a soldering iron, my second most favorite embedded activity :).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Although it is a good idea, sometimes specs (laws in my case), force to put the serial number within the program space, and protect it against intentional changes (thus there should be some kind of crc or checksum).

Guillem.
"Common sense is the least common of the senses" Anonymous.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

someone at Atmel gave me a file long ago called hexinc.exe.
it is a command line program that modifies a single byte in a .hex file and recomputes the numbers to make it a valid .hex again.
It could easily do what we are talking about here. I don't know if it is free to give out. Google might turn something up. Or someone at Atmel might post it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ponyprog has a build in serialnumber generator.
http://www.lancos.com/prog.html

Edit: The idea with ponyprog is that it will program the serial number in free flash space, outside the "used by program" space, most of the time the highest address just before the bootload section, but you can choose this. In your prog you peek then at these locations to obtain you serial number.
The advange is that you don't need to change or edit the hexfile or recalculate the checksum.