SNIU028D February 2016 – September 2020 UCD3138 , UCD3138064 , UCD3138064A , UCD3138128 , UCD3138A , UCD3138A64
On the UCD3138 and UCD3138064, the checksum for an area of program flash is calculated as the sum of bytes over the program flash area.
For example, to calculate the checksum from start_address to end_address, the Boot ROM program on the UCD3138 and UCD3138064 executes something like the following code:
Uint32 calculate_checksum(register Uint32 start_address, register Uint32 end_address)
{
Uint32 checksum = 0;
Uint8 *addr;
for(addr=(Uint8 *)start_address; (Uint32)addr < end_address; addr++)
{
checksum = checksum + (*addr); // read byte data from flash
}
return checksum;
}
For the UCD3138A64 and UCD3138128 (and A versions), the checksum is calculated as the sum of 32-bit words in the program flash area covered by the checksum, rather than the sum of 8-bit bytes. This makes the checksum calculation approximately 4 times faster. It means that the Boot ROM program can verify the checksum for 64kB in around 5ms, while the UCD3138 Boot ROM program takes 10ms to verify 32kB of program flash. Here is the code for calculating the checksum.
void calculate_checksum(register Uint32 *start_address, register Uint32 *end_address)
{
//use local register variable for speed.
register unsigned long long lcs = long_checksum;
while(start_address < end_address)
{
lcs = lcs + *start_address ;
lcs = lcs + (Uint32)*(start_address + 1) ;
start_address = start_address + 2;
}
long_checksum = lcs;
}
Two words are added each pass through the loop to increase the execution speed even further.
The checksums for the UCD3138A64 and UCD3138128 are now 8 bytes in length (versus 4 bytes for the UCD3138 and UCD3138064).
The checksums and their locations are shown in Table 13-5.
Checksum Location | Purpose |
---|---|
0x07F8 | Checksum for 2kB boot in program flash 0 |
0x7FF8 | Checksum for 32kB program in program flash 0 |
0xFFF8 | Checksum for 64kB program in program flash 0 and 1 |
Figure 13-4 is a flowchart showing the order in which the ROM verifies the integrity of the program flash contents using the different checksums.
The branch instruction check at the beginning prevents the checksum program from trying to verify the integrity of an empty block of memory. Otherwise a block filled with zeroes would pass the checksum test.
The UCD3138A64 doesn’t have ROM support for putting 2 separate programs into flash, one in each flash block. This can still be done, however, using a boot flash program. Or the program in block 0 can be a fixed program, which checks the program in block 1 and jumps to it if appropriate.