Image checksum

Discussion to talk about software related topics only.
Post Reply
SeeCwriter
Posts: 606
Joined: Mon May 12, 2008 10:55 am

Image checksum

Post by SeeCwriter »

Using 3.3.5 tools. Using Eclipse to build my NANO app, there are "Code Checksum" and "Struct Checksum" values displayed in the Console window of Eclipse. I assume one or both of those are made part of the image file. After an image file is transferred to the module, is it possible for my app to get (read) one of those values? Not necessarily during the reprogramming process, maybe after bootup.
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: Image checksum

Post by pbreed »

Yes, you can also have compcode make a SHA1 hash of the result and check that.
On the nano the app is stored at address zero of the SPI flash. (not memory mapped)

So:
#include <SPIFlash.h>

SPIFlash lclSPI_Main(0);
lclSPI_Main.ReadData(destination_buffer,len,0);

Should read the beginning of app image into destination buffer.
SeeCwriter
Posts: 606
Joined: Mon May 12, 2008 10:55 am

Re: Image checksum

Post by SeeCwriter »

I tried this:

Code: Select all

  uint8_t buf2[16];
  SPIFlash lclSPI_Main( 0 );
  lclSPI_Main.ReadData(buf2,8,0);
  iprintf( "ChkSum: 0x%02x 0x%02x 0x%02x 0x%02x \r\n", buf2[0], buf2[1], buf2[2], buf2[3] );
  iprintf( "ChkSum: 0x%02x 0x%02x 0x%02x 0x%02x \r\n", buf2[4], buf2[5], buf2[6], buf2[7] );
Output is:

Code: Select all

ChkSum: 0x00 0x00 0x00 0x94
ChkSum: 0x00 0x00 0x00 0x00
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: Image checksum

Post by pbreed »

uint32_t U32BlockRamStart ;
uint32_t U32ExecutionAddr ;
uint32_t U32BlockSize ;
uint32_t U32SourceBlockSize;
uint32_t U32BlockSum ;
uint32_t U32StructSum ;

So the two checksums start at offsets of 16 and 20 from the beginning of the structure.
(You can find this structure in arch\coldfire\include\platformheader.h)

So I'd do it like this :
#include <platformheader.h>
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: Image checksum

Post by pbreed »

PlatformFlashHeaderStruct phs;
SPIFlash lclSPI_Main( 0 );
lclSPI_Main.ReadData((*puint8_t)&phs,sizeof(phs),0);

printf("Csums[%08X,%08X]",phs.U32BlockSum,phs.U32StructSum);
SeeCwriter
Posts: 606
Joined: Mon May 12, 2008 10:55 am

Re: Image checksum

Post by SeeCwriter »

Still doesn't work:

Code: Select all

  PlatformFlashHeaderStruct phs;
  SPIFlash lclSPI_Main( 0 );
  lclSPI_Main.ReadData((puint8_t)&phs,sizeof(phs),0);
  if ( phs.VerifyCorrect() )  puts( "Correct" );
  else                        puts( "Not Correct" );
  iprintf( "Csums[%08lX,%08lX]\r\n", phs.U32BlockSum, phs.U32StructSum );
Output:

Code: Select all

Not Correct
Csums[00000000,0001C200]
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: Image checksum

Post by pbreed »

The nano stores code a bit differntly, I'll sort it out when I get to the office in about 2 hrs.
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: Image checksum

Post by pbreed »

Had the flash offset wrong.

This works:

PlatformFlashHeaderStruct phs;
SPIFlash lclSPI_Main( 0 );
lclSPI_Main.ReadData((puint8_t)&phs,sizeof(phs),0x4000);//CHANGE offset to 0x4000
if ( phs.VerifyCorrect() ) puts( "Correct" );
else puts( "Not Correct" );
iprintf( "Csums[%08lX,%08lX]\r\n", phs.U32BlockSum, phs.U32StructSum );
SeeCwriter
Posts: 606
Joined: Mon May 12, 2008 10:55 am

Re: Image checksum

Post by SeeCwriter »

That works. Thank you.
Post Reply