whitequark / prjbureau

Documenting the Microchip (Atmel) ATF15xx CPLD fuse maps and programming algorithms
https://whitequark.github.io/prjbureau
Other
50 stars 8 forks source link

Issues with transmission checksum of JED files when using jesd3.py #12

Open peterzieba opened 1 year ago

peterzieba commented 1 year ago

Hi,

I think the transmission checksum calculation of JED files is incorrect within jesd3.py

I am using a file which was generated by CUPL and am following the spec verbatim wherein it says: The transmission checksum is the 16-bit sum (i.e., modulo 65,535) of all ASCII characters transmitted between and including the STX and ETX...

I've included a file as a testcase where the sum I calculate to be is 0x7F8A, which matches what is within the file.

jesd3.py calculates the actual sum to be 7B05, which I believe to be incorrect.

testcase.jed.txt

The more important bit (the fusemap checksum) I believe is working as expected.

peterzieba commented 1 year ago

The issue appears to be that the file is opened as "text" mode. It looks like the CRLF from a Windows/DOS .JED file ends up as just LF in the buffer.

This ultimately looks like what is breaking the transmission checksum.

Unfortunately, opening the file as binary breaks a bunch of the regular expression searches...

whitequark commented 1 year ago

Ah that would make sense.

whitequark commented 1 year ago

This actually affects things on Linux just as it affects them on Windows.

whitequark commented 1 year ago

This is now fixed in Glasgow (once https://github.com/GlasgowEmbedded/glasgow/pull/450 is merged). @peterzieba Could you please copy the file out of the Glasgow source tree (https://github.com/GlasgowEmbedded/glasgow/blob/main/software/glasgow/protocol/jesd3.py), put it in this project, update the file open mode (r to rb) and test the resulting changes?