esptool.py 文件源码

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

项目:phatsniffer 作者: larsjuhljensen 项目源码 文件源码
def write_flash(esp, args):
    flash_params = _get_flash_params(esp, args)
    flasher = CesantaFlasher(esp, args.baud)

    for address, argfile in args.addr_filename:
        image = argfile.read()
        argfile.seek(0)  # rewind in case we need it again
        if address + len(image) > int(args.flash_size.split('m')[0]) * (1 << 17):
            print('WARNING: Unlikely to work as data goes beyond end of flash. Hint: Use --flash_size')
        image = _update_image_flash_params(address, flash_params, image)
        # Pad to sector size, which is the minimum unit of writing (erasing really).
        if len(image) % esp.ESP_FLASH_SECTOR != 0:
            image += b'\xff' * (esp.ESP_FLASH_SECTOR - (len(image) % esp.ESP_FLASH_SECTOR))
        t = time.time()
        flasher.flash_write(address, image, not args.no_progress)
        t = time.time() - t
        print('\rWrote %d bytes at 0x%x in %.1f seconds (%.1f kbit/s)...'
              % (len(image), address, t, len(image) / t * 8 / 1000))
    print('Leaving...')
    if args.verify:
        print('Verifying just-written flash...')
        _verify_flash(esp, args, flasher)
    flasher.boot_fw()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号