Will take a look. Is that md5 for uploaded files/spiffs files?
For uploaded scketch for OTA, but you could use it for hash every file you upload.
Ah ok. I've got all that sorted. I'm trying to hash the actual sketch. The running one.
Well I've done it. And it works.
That way u can compare an incoming binary to the running one without having to specify versions and defines, and commit hashes and all sorts that gets complicated.
I just need to verify and change on thing. And check this sketch size issue. As the sketch size needs to return the same size as the binary on the computer. Not the aligned one. As the hash function needs this same size.
If that makes sense.
So far from all the sketches I've tested they are either 0,4,8,12 bytes larger than the current getsketchsize()
Me No Dev
what is common in the sizes (look at them in hex)
it is surely rounding up the size to some common denominator (like 16 bytes or 0xF)
so if the hex of the incomming size in bytes always ends on 0, the formula above should give you the size you are looking for
pos being equal to getsketchsize()
Actually, just rounding the size is not what he needs.
The correct formula is result=(pos+16)&15
Because there is a checksum byte added at the end
Just rounding the sketch size up to 16 bytes will not give a correct result when pos is already 16 bytes aligned, I.e. you need to take checksum byte into account.
P.s. I can send you a sketch which is 16 bytes larger than get sketch size 😉
BTW, I don't know about all underlying stuff, but if getsketchsize() isn't able to keep track of the real size, why not padding empty words with some signature such 0xAAAAAAAA that getsketchsize() will be able adjust itself to real value ?
It's not that it can't track the real size... it's just a bug and the fix is basically one extra line which i have posted above.
A checksum now it makes sense. Thanks. I'll adjust, test accordingly and amend the pull request.
I'm on it already :)
wait a bit please...
actually, if you don't want to be bothered with flashRead and getting all alignments right, you can simply use memcpy_P to copy stuff from flash to RAM
it will be a bit slower (around 35% slower), but not a deal breaker.
turned out, writing a test case for getSketchSize and getSketchMD5 is not exactly trivial...