Hello,
can somebody share alg for "upgrade" image crc calculation created by xflash --upgrade?
according to http://www.xcore.com/forum/viewtopic.php?t=5041
there are page and entire image crc-s.
have found http://www.xcore.com/forum/viewtopic.php?t=663 but does not work for me...
suppose it outdated or does it still work the same way as described in topic 663?
thanks in advance.
wbr
malo
flash image crc calculation Topic is solved
-
- Active Member
- Posts: 33
- Joined: Fri Sep 16, 2016 9:03 pm
-
Verified
- Respected Member
- Posts: 347
- Joined: Wed Jan 27, 2016 5:21 pm
663 should still be correct - you are using the built-in CRC instruction?
In case you are stuck and what to move on without error check - 0x0D15AB1E is a CRC that is generally accepted.
In case you are stuck and what to move on without error check - 0x0D15AB1E is a CRC that is generally accepted.
-
- Active Member
- Posts: 33
- Joined: Fri Sep 16, 2016 9:03 pm
Hello,
thanks for the quick answer.
yes, using xmos functions, trying for one page with code similar to this:
fw_buffer points to offset 3 (3x4B) into the image produced by xflash.
fw_buffer dump first 32B (update 12, size 0x11A4), starting to calc crc from the value 0x04 (offset 12B):
wbr
malo
thanks for the quick answer.
yes, using xmos functions, trying for one page with code similar to this:
Code: Select all
unsigned char fw_buffer [BUFFER_SIZE];
unsigned int crc = 0xFFFFFFFF;
const unsigned int poly = 0xEDB88320;
// One page - word count 256 / 4 = 64
crc32 (crc, 64, poly);
// Add one page.
for (unsigned int i = 0; i < 256; i++)
{
crc8shr (crc, fw_buffer [i], poly);
}
// Add 32 zeros.
crc32 (crc, 0, poly);
crc ^= 0xffffffff;
fw_buffer dump first 32B (update 12, size 0x11A4), starting to calc crc from the value 0x04 (offset 12B):
Code: Select all
0xED 0x15 0xFF 0x00 0xB5 0xB3 0xF4 0x6B
0xCA 0xB4 0xCD 0x1E 0x04 0x00 0x00 0x00
0x4A 0x11 0x00 0x00 0xC0 0x00 0x00 0x00
0x4A 0x11 0x00 0x00 0x20 0x00 0x00 0x00
malo
-
Verified
- Respected Member
- Posts: 347
- Joined: Wed Jan 27, 2016 5:21 pm
Hi,
You will have to do it for the whole image I presume.
Also - I would use CRC32 on a word - not CRC8SHR; it will go faster, and use the right byte order.
Cheers,
Henk
You will have to do it for the whole image I presume.
Also - I would use CRC32 on a word - not CRC8SHR; it will go faster, and use the right byte order.
Cheers,
Henk
-
- Experienced Member
- Posts: 74
- Joined: Mon Dec 16, 2013 12:14 pm
Hi Malo,
I use this function below...
Note that to crc the first page of an image, you want to use the first 64words from the very start of the image (offset 0), but skip over the first 3 words. So you are CRC'ing 61words in total. The same also goes for the whole image crc but make sure you use the image length field not the image size field from the image header otherwise you might not get the right crc if xflash used the size option on the image. The other thing to note is that if you are using libflash or libquadflash to read the data from flash then you will need to bitrev for spi and nibblerev for QSPI.
Colin
I use this function below...
Code: Select all
unsigned int CalcCRC(unsigned int * data, unsigned int num_words, unsigned int expected_crc)
{
unsigned int crc = 0xFFFFFFFF;
unsigned int polynom = 0xedb88320;
for(unsigned int i = 0; i < num_words; i++)
{
asm volatile("crc32 %0, %2, %3" : "=r" (crc) : "0" (crc), "r" (data[i]), "r" (polynom));
}
asm volatile("crc32 %0, %2, %3" : "=r" (crc) : "0" (crc), "r" (expected_crc), "r" (polynom));
return ~crc;
}
Colin
-
- Active Member
- Posts: 33
- Joined: Fri Sep 16, 2016 9:03 pm
Colin,
thanks for the valuable info, got it working.
the trick is to swap the data nibbles for QSPI and do the crc from image len - 3 words.
wbr
malo
thanks for the valuable info, got it working.
the trick is to swap the data nibbles for QSPI and do the crc from image len - 3 words.
wbr
malo