Get MD5 hash of entire firmware

I have a firmware file on my hard disk for the SAM D21 microcontroller. I've padded the end of the file with zeroes to bring it to 256 kilobytes. I've gotten the MD5 sum of this file.

Next, in my Arduino sketch, I've written a function that calculates the MD5 sum of all the bytes from memory address 0x00000 to 0x40000.

These two MD5 sums don't match.

So next I looked at the first 16 bytes of the firmware file:

0080 0020 398c 0000 218c 0000 218c 0000

But the first 16 bytes at runtime in the microcontroller's Flash are coming back as:

fc7f 0020 0d06 0000 fd05 0000 0106 0000

Are these some sort of configuration bytes or something?

Anyone know what's going on here?

I figured this out.

You need to take the hash of the Flash bytes from 0x2000 to 0x40000. Presumably the bootloader is located at 0x0000 to 0x2000.

And when you're comparing to a firmware file on your hard disk, you need to pad it as follows:

Pad it with 0x00 until the file size is a multiple of 64,
and then pad it with 0xFF until the file size is 0x40000 minus 0x2000.

The Flash page size on SAM D21 is 64 bytes, so to ignore the first 0x2000 bytes is to ignore the first 128 pages.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.