Skip to main content

IAR Embedded Workbench for RL78 5.20

Troubleshooting checksum calculation

In this section:

If the two checksums do not match, there are several possible causes. These are some troubleshooting hints:

  • If possible, start with a small example when trying to get the checksums to match.

  • Verify that the exact same memory range or ranges are used in both checksum calculations.

    To help you do this, ielftool lists the ranges for which the checksum is calculated on stdout about the exact addresses that were used and the order in which they were accessed.

  • Make sure that all checksum symbols are excluded from all checksum calculations.

    Compare the checksum placement with the checksum range and make sure they do not overlap. You can find information in the Build message window after ielftool has generated a checksum.

  • Because pointers declared __near implicitly have some of the most significant bits set, make sure that the checksum calculated by your application uses a __far pointer instead of a __near pointer.

  • Verify that the checksum calculations use the same polynomial.

  • Verify that the bits in the bytes are processed in the same order in both checksum calculations, from the least to the most significant bit or the other way around. You control this with the Bit order option (or from the command line, the -m parameter of the ‑‑checksum option).

  • If you are using the small variant of CRC, check whether you need to feed additional bytes into the algorithm.

    The number of zeros to add at the end of the byte sequence must match the size of the checksum, in other words, one zero for a 1-byte checksum, two zeros for a 2-byte checksum, four zeros for a 4-byte checksum, and eight zeros for an 8-byte checksum.

  • Carefully consider the number of bits in pointers when crossing 64-Kbyte boundaries.

    For example, if the pointer 0xFFFF is incremented by one, this typically results in the pointer 0x0 (and not 0x10000) if the pointer is 16 bits.

  • Any breakpoints in flash memory change the content of the flash. This means that the checksum which is calculated by your application will no longer match the initial checksum calculated by ielftool. To make the two checksums match again, you must disable all your breakpoints in flash and any breakpoints set in flash by C-SPY internally. The stack plugin and the debugger option Run to both require C-SPY to set breakpoints. Read more about possible breakpoint consumers in Breakpoint consumers.

  • By default, a symbol that you have allocated in memory by using the linker option ‑‑place_holder is considered by C-SPY to be of the type int. If the size of the checksum is different than the size of an int, you can change the display format of the checksum symbol to match its size.

    In the C-SPY Watch window, select the symbol and choose Show As from the context menu. Choose the display format that matches the size of the checksum symbol.

  • If your application is linked with address translation (see logical directive), make sure that any checksums are calculated using explicit physical checksum ranges, see Checksums of address-translated ranges.