def _check_crc (self, address, binary):
'''
Compares the CRC of the local binary to the one calculated by the
bootloader.
'''
# Check the CRC
crc_data = self._get_crc_internal_flash(address, len(binary))
# Now interpret the returned bytes as the CRC
crc_bootloader = struct.unpack('<I', crc_data[0:4])[0]
# Calculate the CRC locally
crc_function = crcmod.mkCrcFun(0x104c11db7, initCrc=0, xorOut=0xFFFFFFFF)
crc_loader = crc_function(binary, 0)
if crc_bootloader != crc_loader:
raise TockLoaderException('Error: CRC check failed. Expected: 0x{:04x}, Got: 0x{:04x}'.format(crc_loader, crc_bootloader))
else:
print('CRC check passed. Binaries successfully loaded.')
评论列表
文章目录