efabless / caravel_board

31 stars 41 forks source link

fix typo in binary reversal of project id #96

Closed htfab closed 8 months ago

htfab commented 8 months ago

The formatting code left-pads with spaces instead of zeros, which gives the wrong results for even project IDs (i.e. those that start with a 0 when read in reverse from caravel).

E.g. data == b'\x24\x36\xe0\x00' int.from_bytes(data, byteorder='big') == 607576064 '{0:32b}'.format(int.from_bytes(data, byteorder='big')) == ' 100100001101101110000000000000' '{0:32b}'.format(int.from_bytes(data, byteorder='big'))[::-1] == '000000000000011101101100001001 ' "{:08x}".format(int('{0:32b}'.format(int.from_bytes(data, byteorder='big'))[::-1], 2)) == '0001db09'

Corrected version: '{:032b}'.format(int.from_bytes(data, byteorder='big')) == '00100100001101101110000000000000' '{:032b}'.format(int.from_bytes(data, byteorder='big'))[::-1] == '00000000000001110110110000100100' "{:08x}".format(int('{:032b}'.format(int.from_bytes(data, byteorder='big'))[::-1], 2)) == '00076c24'

RTimothyEdwards commented 8 months ago

@htfab : This needs to be considered carefully. There was a bit order reversal in the code itself at one point. But I think this fix is correct and has been missed previously because the chipIgnite project IDs do not have the leading zeros that the MPWs do, so there is no shifting when the bits are reversed.

RTimothyEdwards commented 8 months ago

@jeffdi : Please merge this pull request ASAP.