Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

mjt_4825471
Level 1
Level 1
10 sign-ins 5 questions asked 5 sign-ins

I changed some flash data in hex,and I fail to download because of the wrong checksum in the end  of hex. How can I calculate the  checksum of the whole flash.

 
1 Solution
lock attach
Attachments are accessible only for community members.
DheerajK_81
Moderator
Moderator
Moderator
First comment on KBA First comment on blog 5 questions asked

Hello @mjt_4825471 ,

Can you please let me know why you require modifying the hex file? 

Let me start by saying this cannot be done. Even if you do calculate the right checksum, it will still not work with PSoC Programmer. 

Here's a long story on why this won't work. You can modify the data in the hex, but you need to take care about two things. Every row in the hex file follows the Intel Hex Format. You can understand more about it in the Appendix section of the Programming Specification

So, firstly each of the rows has a checksum calculated at the end of the record. You need to modify this as well to align with the changes you made. 

Secondly, we calculate the checksum of the entire flash and store it in the location 0x90300000 in the hex. Check the Organization of the Hex File section in the link provided above. So, you will need to modify this as well to align with the changes and also the checksum of the checksum 🙂

DheerajK_81_1-1620833164376.png

But, the metadata section at 0x90500000 contains some proprietary information that is used to guarantee the integrity of the hex file. Hence, you will not be able to program the hex file even though we tried to modify it to make it seem legitimate. 

DheerajK_81_2-1620833750272.png

Just for your knowledge, I can tell you how you can calculate the flash checksum. You can write a simple C program to do this. Parsing the hex is slightly complicated, so it is better to convert the hex to a bin file using hex2bin and then run a simple c program to calculate the checksum for the entire flash. 

Here are the steps to use the C program to calculate the checksum:
1) Please find attached the bat script. Extract the bat script into the Debug directory of your project where the hex file exists. 
2) Right-click on the bat script and edit it to add your project name, flash size of the device. Save it. 
3) Run the bat script by double-clicking it. It will generate the bin file for you.
4) Modify the C Program to add the filename of the bin and run the C program

DheerajK_81_3-1620834482189.png

 

DheerajK_81_0-1620832733698.png

5) It will give you the checksum of the entire flash. 

All the necessary files are attached.

Hope this helps 🙂

Regards,
Dheeraj





View solution in original post

0 Likes
2 Replies
lock attach
Attachments are accessible only for community members.
DheerajK_81
Moderator
Moderator
Moderator
First comment on KBA First comment on blog 5 questions asked

Hello @mjt_4825471 ,

Can you please let me know why you require modifying the hex file? 

Let me start by saying this cannot be done. Even if you do calculate the right checksum, it will still not work with PSoC Programmer. 

Here's a long story on why this won't work. You can modify the data in the hex, but you need to take care about two things. Every row in the hex file follows the Intel Hex Format. You can understand more about it in the Appendix section of the Programming Specification

So, firstly each of the rows has a checksum calculated at the end of the record. You need to modify this as well to align with the changes you made. 

Secondly, we calculate the checksum of the entire flash and store it in the location 0x90300000 in the hex. Check the Organization of the Hex File section in the link provided above. So, you will need to modify this as well to align with the changes and also the checksum of the checksum 🙂

DheerajK_81_1-1620833164376.png

But, the metadata section at 0x90500000 contains some proprietary information that is used to guarantee the integrity of the hex file. Hence, you will not be able to program the hex file even though we tried to modify it to make it seem legitimate. 

DheerajK_81_2-1620833750272.png

Just for your knowledge, I can tell you how you can calculate the flash checksum. You can write a simple C program to do this. Parsing the hex is slightly complicated, so it is better to convert the hex to a bin file using hex2bin and then run a simple c program to calculate the checksum for the entire flash. 

Here are the steps to use the C program to calculate the checksum:
1) Please find attached the bat script. Extract the bat script into the Debug directory of your project where the hex file exists. 
2) Right-click on the bat script and edit it to add your project name, flash size of the device. Save it. 
3) Run the bat script by double-clicking it. It will generate the bin file for you.
4) Modify the C Program to add the filename of the bin and run the C program

DheerajK_81_3-1620834482189.png

 

DheerajK_81_0-1620832733698.png

5) It will give you the checksum of the entire flash. 

All the necessary files are attached.

Hope this helps 🙂

Regards,
Dheeraj





0 Likes

Thankyou for your reply. Yes, metedata will fail.I want store the checksum of whole flash by CRC16 in the end of hex.After power on,my code will check the falsh data and compare the result with the checksum which I put in the hex.  

0 Likes