General Forums >> Interesting Projects and Tutorials

Pages: 1
dfnr2



Reged: Jul 27 2004
Posts: 11
Serial Number embedding (repost)
      #65392 - Tue Jul 15 2008 09:51 PM Attachment (162 downloads)

Since I posted this program several years back, I had lost my original source code and when I came here to try to download a copy, I saw that there is a new board and the post was lost. I did manage to find a copy, and since the program is still useful, I will re-post it here. Hopefully someone else will find it useful, too. Below is the original post:

----

This program for embedding serial numbers in production code has been useful to me. I had previously posted this utility in the HEXMATE thread, but I suspect that it complements the functionality of HEXMATE. Perhaps the functions could evenutally be added in to HEXMATE.

I am re-posting this update adding support for "balancing" the effect of the serial on the checksum by embedding the serial's complement. This is useful because the checksum will remain unchanged by the overlay, allowing proper quality control during the programming process. I also updated the instructions to be more clear (see below)

This is different from HEXMATE, because is generates a different overlay file for each serial number in a specified range of serial numbers, and places each serial number overlay in an appropriately named file which can be loaded separately by the programmer (e.g., xyz_200.hex, xyz_201.hex, ...)

The Problem:

Your program must have a serial number embedded at program time. You don't want to recompile the program for each serial number, since the process is fragile, time-consuming, and cumbersome. Your programmer may also be in a production area, or off-site from your development system.

Programmer software doesn't always adequately support serial numbers as implemented on Harvard architectures. (Data I/O does, but requires preparation of a spreadsheet.) BPWin doesn't support serial numbers embedded in MOVLW or RTLW statements, even if you pay for the serial number extension.

The solution:

Leave space in your program for the serial number, by assigning to a "dummy" serial number, making sure that the number is not optimized away:

Readme file for serno.c (serial number overlay generator).

This program generates serial numbers to be embedded in hex firmware
files. It is written in standard C, and compiles with GCC, and under
DOS with the (free) Borland C 5.5 compiler.

STEP 1) Leaving place for a serial number in your code:

The easiest is to initialize a variable to the serial number value:
Code:


volatile uint16 serno = 0x1234; /* example for a 16-bit serial */


You can also just use a constant:
Code:


SERNO = 0x1234;

...

printf("Serial: %d\n\r",SERNO); /* 16-bit serial example */


The unwanted side effect of the above statements is that the checksum
of your code changes with each serial number. To avoid this, you can
introduce the 1's complement of your serial number into the code:
Code:


volatile uint16 serno;

serno = 0xedcb;

serno = 0x1234;



NOTE: The C code *MUST* be compiled with a serial number that
generates a load/store sequence for EACH byte (not optimized away).
That means, for example, that the dummy embedded value for a 16-bit
serial number cannot be less than 256, and no multiple of 256. That
is why the above examples use the values 0x1234 (and the complement
0xedcb). That is why the "volatile" declaration is suggested.

Of course, there is no restriction on the values of the actual
embedded serial numbers, other than imposed by its size and type.

STEP 2) Find out where the values are stored:

This is the least convenient part of the process, but you only need to
do it once. Compile your code using the assembly-listing option, and
examine it. Determine the address for each byte used to initialize
ther serial number (and its complement).


STEP 3) Using SERNO to generate serial numbers:
Code:


serno -f myapp -a (address) -c (address2) -b (bytes) -g (gap) -n (startno) -e (endno)


This will generate intel hex files myapp_XXXX.hex, where XXXX is from
(startno) to (endno) in decimal. The serial number of size (bytes)
will be placed at (address) in 1-byte pieces with gap of (gap). The
complement of the serial number will be placed at the address
address2, in 1-byte pieces with the same gap as the serial number (use
the same assignment form.)

For example,
Code:


serno -f myapp -a 0x201c -c 0x2024 -b 2 -g 3 -n 500 -e 1000


Will generate 501 overlay files named myapp_0599.hex ->
myapp_1000.hex, each containing an overlay for a 2-byte (16-bit)
serial number from 500 to 1000, embedded with the low byte at 0x201c
and high byte at 0x2020. The complement will be similarly embedded at
0x2024 and 2028.

Default is low-byte to high-byte (little endian). To change that, use
the -r option.


1) generate the intel hex overlay files for each serial number using
the serno.exe program as above.

2) load the firmware myapp.hex file into a cleared data area in BPWIN (or TLWIN
for data i/o, or the firmware for your other programmer).

3) without clearing the data area, load the myapp_XXXX.hex file for
serial number XXXX over the myapp object data

4) program the device

5) repeat steps (3) and (4) for each new device, incrementing the
serial number each time. Record the serial numbers in the log.
Note that the memory checksum will change for each increment of the
serial number, unless you embed the serial number's complement with
the "-c" option (see discussion in STEP 1 on generating the serial
numbers).

6) Verify correct serialization by testing the device in a working
system.


Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 16 anonymous users are browsing this forum.

Moderator:  jtemples, mikerj, Dan Henry, Andrew L 

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is enabled
      UBBCode is enabled

Rating:
Topic views: 3299

Rate this topic

Jump to

Contact Us | Privacy statement HI-TECH Software

Powered by UBB.threads™ 6.5.5