bootloader_serial.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:tockloader 作者: helena-project 项目源码 文件源码
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.')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号