I'm currently trying to format a disk to exFAT using a micro controller. My issue is that I need to calculate a checksum that uses the bytes from sector 1 to 11 of the VBR (Volume Boot Region) to store it into sector 12 but my result is incorrect. When the checksum isn't correct, the disk cannot be used by Windows or any other OS that recognizes exFAT since the checksum is verified and a fatal error occures if it's incorrect.
Here's the function that calculates the 32-bit checksum:
uint32_t BootChecksum(char * data, long bytes){
uint32_t checksum = 0;
for (uint32_t i = 0 ; i < bytes ; i++){
if (i == 106 || i == 107 || i == 112)
continue;
checksum = ((checksum << 31) | (checksum >> 1)) + (uint32_t) data[i];
if(checksum == 0xF1924082){
printf("%02X | i = %d", checksum, i);
}
}
return checksum;
}
From what I've been able to read, the function is correct so my guess is that the data that I use are incorrect. I'm simply taking the 11 sectors needed so with 512 bytes per sector it results in an array of 5632 bytes.
I've used a similar function to calculate the checksum of the entry set (a 16 bit checksum) and the result is correct, it really has to be the data but I don't understand what I'm missing there!
Anyone who knows about exFAT can help me out? Thanks!