tockloader.py 文件源码

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

项目:tockloader 作者: helena-project 项目源码 文件源码
def dump_flash_page (self, page_num):
        '''
        Print one page of flash contents.
        '''
        with self._start_communication_with_board():
            address = 512 * page_num
            print('Page number: {} ({:#08x})'.format(page_num, address))

            flash = self.channel.read_range(address, 512)

            def chunks(l, n):
                for i in range(0, len(l), n):
                    yield l[i:i + n]

            def dump_line (addr, bytes):
                k = binascii.hexlify(bytes).decode('utf-8')
                b = ' '.join(list(chunks(k, 2)))
                if len(b) >= 26:
                    # add middle space
                    b = '{} {}'.format(b[0:24], b[24:])
                printable = string.ascii_letters + string.digits + string.punctuation + ' '
                t = ''.join([chr(i) if chr(i) in printable else '.' for i in bytes])
                print('{:08x}  {}  |{}|'.format(addr, b, t))

            for i,chunk in enumerate(chunks(flash, 16)):
                dump_line(address+(i*16), chunk)

    ############################################################################
    ## Internal Helper Functions for Communicating with Boards
    ############################################################################
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号