ARM Technical Support Knowledge Articles

GENERATING A ROM CHECKSUM

Applies to: General Topics

Answer


Information in this article applies to:


QUESTION

I need to validate the ROM in a DS80C320 based system at boot time. Is there any way to automatically generate a checksum of any kind in the code image that I could compare the actual code to?

ANSWER

Yes. You can easily add a ROM checksum to your program.

  1. Download the following utility programs from the Keil web site:
  2. Compile and link your program as normal.
  3. In µVision, check the Create HEX File checkbox on the Options for Target — Output dialog or from the command prompt, run OH51 to get an Intel HEX file.
  4. Run HEX2BIN on your HEX file to get a 32K binary file (or whatever your EPROM size is).
  5. Run CHECK8 to insert an 8-bit checksum into your BINARY file.
  6. Run BIN2HEX to get a new Intel HEX file from your BINARY file (if you need that).
  7. Include a checksum calculating function that calculates a checksum over your WHOLE EPROM. The following is an example:
    unsigned char calc_checksum (
      unsigned char *start_addr,
      unsigned int len)
    {
    unsigned char checksum = 0;
    for (; len > 0; len--, start_addr++) { checksum += *start_addr; }
    return (checksum); }

    The checksum should equate to 0x00 or 0xFF typically. CHECK8 lets you force the checksum to be anything that you want.

ADDITIONAL INFORMATION

The Check8 program takes the following parameters:

USAGE:        CHECK8 [/options] filename
/Sstart set starting offset of checksum calculation /Eend set ending offset of checksum calculation /Pposition set position to write checksum byte /Vvalue set checksum adjustment value /H Display additional help text
filename name of binary file for checksum calculation
Example: check8 project.bin /s0x0000 /e0x3FFE /p0x3FFF /v0x80
Generate a checksum for the range 0x0000-0x3FFE, of the binary "project.bin", add 0x80 to the result, and store the checksum at address 0x3FFF.

Refer to this Checksum Example Program found in the Download Area on the Keil web site.

This example creates a program that checks the ROM checksum from 0x0000 to 0x3FFF and prints a message if the checksum is valid or not.

Pay special attention to the GENCSUM.BAT file as well as the DEBUG.INI file.

When you create a ROM checksummed file using the above technique, you cannot simply debug the absolute object module. You must debug the cooked Intel HEX file. To do this, in Options for Target/Debug turn off Load Application at Startup for the emulator. Start the debugger and in the Command window, type the command:

LOAD CHECKA.HEX NORESET

This loads your cooked file into the device. After it loads, type the command:

LOAD CHECK NORESET

This loads the OMF-51 file for the debugger to use.

Then, start the program

G, MAIN

and debug normally.

Article last edited on: 2007-03-27 11:18:33

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential