def _get_crc_internal_flash (self, address, length):
'''
Get the bootloader to compute a CRC.
'''
message = struct.pack('<II', address, length)
success, crc = self._issue_command(self.COMMAND_CRC_INTERNAL_FLASH, message, True, 4, self.RESPONSE_CRC_INTERNAL_FLASH)
# There is a bug in a version of the bootloader where the CRC returns 6
# bytes and not just 4. Need to read just in case to grab those extra
# bytes.
self.sp.read(2)
if not success:
if crc[1] == self.RESPONSE_BADADDR:
raise TockLoaderException('Error: RESPONSE_BADADDR: Invalid address for CRC (address: 0x{:X})'.format(address))
elif crc[1] == self.RESPONSE_BADARGS:
raise TockLoaderException('Error: RESPONSE_BADARGS: Invalid length for CRC check')
else:
raise TockLoaderException('Error: 0x{:X}'.format(crc[1]))
return crc
评论列表
文章目录