#! /usr/bin/env python3 from dotenv import load_dotenv load_dotenv() import os import struct import zipfile import oss2 import json import requests from requests.exceptions import RequestException # 切换到项目根目录 os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) def get_chip_id_string(chip_id): return { 0x0000: "esp32", 0x0002: "esp32s2", 0x0005: "esp32c3", 0x0009: "esp32s3", 0x000C: "esp32c2", 0x000D: "esp32c6", 0x0010: "esp32h2", 0x0011: "esp32c5", 0x0012: "esp32p4", 0x0017: "esp32c5", }[chip_id] def get_flash_size(flash_size): MB = 1024 * 1024 return { 0x00: 1 * MB, 0x01: 2 * MB, 0x02: 4 * MB, 0x03: 8 * MB, 0x04: 16 * MB, 0x05: 32 * MB, 0x06: 64 * MB, 0x07: 128 * MB, }[flash_size] def get_app_desc(data): magic = struct.unpack("> 4) chip_id = get_chip_id_string(data[0xC]) # get segments segment_count = data[0x1] segments = [] offset = 0x18 for i in range(segment_count): segment_size = struct.unpack("