Image checksum
-
- Posts: 630
- Joined: Mon May 12, 2008 10:55 am
Image checksum
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.
Re: Image checksum
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.
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.
-
- Posts: 630
- Joined: Mon May 12, 2008 10:55 am
Re: Image checksum
I tried this:
Output is:
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] );
Code: Select all
ChkSum: 0x00 0x00 0x00 0x94
ChkSum: 0x00 0x00 0x00 0x00
Re: Image checksum
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>
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>
Re: Image checksum
PlatformFlashHeaderStruct phs;
SPIFlash lclSPI_Main( 0 );
lclSPI_Main.ReadData((*puint8_t)&phs,sizeof(phs),0);
printf("Csums[%08X,%08X]",phs.U32BlockSum,phs.U32StructSum);
SPIFlash lclSPI_Main( 0 );
lclSPI_Main.ReadData((*puint8_t)&phs,sizeof(phs),0);
printf("Csums[%08X,%08X]",phs.U32BlockSum,phs.U32StructSum);
-
- Posts: 630
- Joined: Mon May 12, 2008 10:55 am
Re: Image checksum
Still doesn't work:
Output:
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 );
Code: Select all
Not Correct
Csums[00000000,0001C200]
Re: Image checksum
The nano stores code a bit differntly, I'll sort it out when I get to the office in about 2 hrs.
Re: Image checksum
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 );
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 );
-
- Posts: 630
- Joined: Mon May 12, 2008 10:55 am
Re: Image checksum
That works. Thank you.