#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright 2020 Espressif Systems (Shanghai) CO LTD # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from __future__ import unicode_literals import filecmp import hashlib import os import random import struct import sys import tempfile import time import unittest from functools import partial from io import open from itertools import chain import pexpect try: from itertools import izip as zip except ImportError: # Python 3 pass current_dir = os.path.dirname(os.path.realpath(__file__)) mkuf2_dir = os.path.abspath(os.path.join(current_dir, '..')) mkuf2_path = os.path.join(mkuf2_dir, 'mkuf2.py') try: import mkuf2 except ImportError: sys.path.append(mkuf2_dir) import mkuf2 class UF2Block(object): def __init__(self, bs): self.length = len(bs) # See https://github.com/microsoft/uf2 for the format first_part = '<' + 'I' * 8 # payload is between last_part = '