cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

Contributor II

Hi there,

I have a question regarding the code checksum on a PSoC5LP part (specifically CY8C5667AXI-LP040).

I have a request on a project to provide the checksum of code over a serial interface.  Is there a known good way during runtime to either read or calculate the checksum of the entire codespace of the PSoC?  Perhaps even an API function I'm not aware of?

Thanks for the help!

0 Likes
Reply
1 Solution
Contributor II

Hello KyTr.

If 5LP uses a bootloader, the bootloader validates the bootloadable via a checksum (CRC), AN73854 shows this in a flow chart.  If checksum's don't match, bootloader will not jump to bootloadable.  The checksum (or its 2's compliment) is stored in 5LP FLASH memory in the top row, see AN73854 section 6.4 Recovering from Failures.

The bootloader (see Bootloader Component datasheet) has an API for validating the checksum:
cystatus Bootloader_ValidateBootloadable (uint8 appId)
You might be able to clone this function (or call it from within bootloadable).

If target 5LP doesn't have a bootloader, clone the API or develop your own checksum calculator and compare against FLASH checksum.

From the API, it should be possible to figure out exactly where in FLASH the checksum is stored.

Hope this helps.

edit: bootloader has an API for getting the checksum from Metadata area of FLASH.
uint32 Bootloader_GetMetadata (uint8 field, uint8 appId)
So, you could experiment by adding a bootloader and display the checksum.  Then use Debugger to look at FLASH to find the matching checksum address.  You could try to interpret the 'memory map' from the build and find the address for the checksum.

Lots of good info in Bootloader Component datasheet.

edit: Lots of checksum utilities can be found in bootloader utility folder:
...\PSoC Creator\cybootloaderutils
cybtldr_command, cybtldr_api, cybtldr_parse, search for the word 'checksum'.

View solution in original post

0 Likes
Reply
8 Replies
Contributor II

Hello KyTr.

I can't answer your question directly, but here's a place to start investigation.

https://community.cypress.com/t5/Knowledge-Base-Articles/Format-of-cyacd-File-for-PSoC-3-or-PSoC-5LP...

Looks like cyacd file can store checksum as either simple sum, or as CCITT calculation.  So, you'd need to know this in advance (if using cyacd file).

There's also a utility, cyacd2bin convertor.
https://community.cypress.com/t5/Resource-Library/CYACD-to-BIN-Tool/ta-p/250784
which you might find useful as it strips off certain fields (I believe).

The parser in \PSoC Creator\cybootloaderutils\cybtldr_parse.c  might also shed some light.

Good luck with your project.

0 Likes
Reply
Contributor II

BiBi,

Both of these look to be methods of calculating checksum for a cyacd, and if I recall correctly, that checksum in the cyacd is never actually is written to the flash of the target PSoC (do correct me if I am wrong about this, of course).  I'm looking for a method during runtime to verify that the checksum of all code matches a known value.

 

0 Likes
Reply
Honored Contributor

KyTr,

Are you inquiring about a checksum or CRC?

Are you trying to calculate the checksum pre-FLASH load or runtime after the FLASH has already been loaded?

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
Reply
Contributor II

Hi Len,

Looking for a checksum specifically, not a CRC (although I suppose either would serve the same purpose).  It needs to be runtime after the flash has been loaded.  This is part of a Built-In-Test on bootup where I need to provide a "Code Checksum OK" bit

0 Likes
Reply
Honored Contributor

KyTr,

 

Checksums are easier than CRCs.    You can create your own checksum adding routine. 

You just need to use the start and end addresses of the  contiguous FLASH you need to sum into the Compute_FLASH_checksum(uint32_t  *start_addr, uint32_t  *start_addr); 

Recommendation:   Use unit32_t as the size of the checksum and the size of the FLASH memory read.

Len

 

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
Reply
Contributor II

Len,

It is simple enough to calculate a checksum, but where I hit a snag is I don't need to return the checksum itself for the BIT, I need to return a boolean true/false for if the checksum matches an expected value. 

Unless the checksum is programmed onto the PSoC by the programmer I have nothing to verify against, and if I manually put the checksum into the program memory in my code, that will change the checksum.  As I mentioned above in response to BiBi, I don't think the checksum that's included in the compiled intel hex file (or cyacd) is written to PSoC flash by the programmer.  Am I correct on this?  If not, and the checksum resides somewhere in flash from programming, I would just need to know the location so I can read it and compare it to the calculated value.

Thanks again

0 Likes
Reply
Contributor II

Hello KyTr.

If 5LP uses a bootloader, the bootloader validates the bootloadable via a checksum (CRC), AN73854 shows this in a flow chart.  If checksum's don't match, bootloader will not jump to bootloadable.  The checksum (or its 2's compliment) is stored in 5LP FLASH memory in the top row, see AN73854 section 6.4 Recovering from Failures.

The bootloader (see Bootloader Component datasheet) has an API for validating the checksum:
cystatus Bootloader_ValidateBootloadable (uint8 appId)
You might be able to clone this function (or call it from within bootloadable).

If target 5LP doesn't have a bootloader, clone the API or develop your own checksum calculator and compare against FLASH checksum.

From the API, it should be possible to figure out exactly where in FLASH the checksum is stored.

Hope this helps.

edit: bootloader has an API for getting the checksum from Metadata area of FLASH.
uint32 Bootloader_GetMetadata (uint8 field, uint8 appId)
So, you could experiment by adding a bootloader and display the checksum.  Then use Debugger to look at FLASH to find the matching checksum address.  You could try to interpret the 'memory map' from the build and find the address for the checksum.

Lots of good info in Bootloader Component datasheet.

edit: Lots of checksum utilities can be found in bootloader utility folder:
...\PSoC Creator\cybootloaderutils
cybtldr_command, cybtldr_api, cybtldr_parse, search for the word 'checksum'.

View solution in original post

0 Likes
Reply
Contributor II

@BiBi_1928986 wrote:

 

If 5LP uses a bootloader, the bootloader validates the bootloadable via a checksum (CRC), AN73854 shows this in a flow chart.  If checksum's don't match, bootloader will not jump to bootloadable.  The checksum (or its 2's compliment) is stored in 5LP FLASH memory in the top row, see AN73854 section 6.4 Recovering from Failures.

This was the info I needed.  I came across an old thread where it was stated that the flash checksum/CRC from the intel hex file was not stored on the PSoC.  See this thread.  But this was also for PSoC4, so perhaps there are different rules on the 5LP.

The system in question is going to have a bootloader, so performing the BIT entirely inside the bootloader, and using Bootloader_ValidateBootloadable() for the flash verification might actually be the easiest option.

I also found: AN78175 , which actually looks to have multiple features for me to make use of in this required BIT (such as RAM verification as well as Flash checksum verification). 

Appreciate the tips

0 Likes
Reply