mirror of https://github.com/arendst/Tasmota.git
fix esp8266 fs download and extract (#20554)
This commit is contained in:
parent
de91133414
commit
4a4fe27cee
|
@ -27,7 +27,6 @@ mcu = board.get("build.mcu", "esp32")
|
||||||
|
|
||||||
|
|
||||||
class FSType(Enum):
|
class FSType(Enum):
|
||||||
SPIFFS="spiffs"
|
|
||||||
LITTLEFS="littlefs"
|
LITTLEFS="littlefs"
|
||||||
FATFS="fatfs"
|
FATFS="fatfs"
|
||||||
|
|
||||||
|
@ -44,26 +43,15 @@ class FSInfo:
|
||||||
def get_extract_cmd(self, input_file, output_dir):
|
def get_extract_cmd(self, input_file, output_dir):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
class LittleFSInfo(FSInfo):
|
class FS_Info(FSInfo):
|
||||||
def __init__(self, start, length, page_size, block_size):
|
def __init__(self, start, length, page_size, block_size):
|
||||||
self.tool = env["MKFSTOOL"]
|
self.tool = env["MKFSTOOL"]
|
||||||
self.tool = join(platform.get_package_dir("tool-mklittlefs"), self.tool)
|
self.tool = join(platform.get_package_dir("tool-mklittlefs"), self.tool)
|
||||||
super().__init__(FSType.LITTLEFS, start, length, page_size, block_size)
|
super().__init__(FSType.LITTLEFS, start, length, page_size, block_size)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"{self.fs_type} Start {hex(self.start)} Len {self.length} Page size {self.page_size} Block size {self.block_size}"
|
return f"{self.fs_type} Start {hex(self.start)} Len {hex(self.length)} Page size {hex(self.page_size)} Block size {hex(self.block_size)}"
|
||||||
def get_extract_cmd(self, input_file, output_dir):
|
def get_extract_cmd(self, input_file, output_dir):
|
||||||
return [self.tool, "-b", str(self.block_size), "-s", str(self.length), "-p", str(self.page_size), "--unpack", output_dir, input_file]
|
return f'"{self.tool}" -b {self.block_size} -s {self.length} -p {self.page_size} --unpack "{output_dir}" "{input_file}"'
|
||||||
|
|
||||||
|
|
||||||
class SPIFFSInfo(FSInfo):
|
|
||||||
def __init__(self, start, length, page_size, block_size):
|
|
||||||
self.tool = env["MKFSTOOL"]
|
|
||||||
self.tool = join(platform.get_package_dir("tool-mklittlefs"), self.tool)
|
|
||||||
super().__init__(FSType.SPIFFS, start, length, page_size, block_size)
|
|
||||||
def __repr__(self):
|
|
||||||
return f"{self.fs_type} Start {hex(self.start)} Len {self.length} Page size {self.page_size} Block size {self.block_size}"
|
|
||||||
def get_extract_cmd(self, input_file, output_dir):
|
|
||||||
return f'"{self.tool}" -b {self.block_size} -p {self.page_size} --unpack "{output_dir}" "{input_file}"'
|
|
||||||
|
|
||||||
# SPIFFS helpers copied from ESP32, https://github.com/platformio/platform-espressif32/blob/develop/builder/main.py
|
# SPIFFS helpers copied from ESP32, https://github.com/platformio/platform-espressif32/blob/develop/builder/main.py
|
||||||
# Copyright 2014-present PlatformIO <contact@platformio.org>
|
# Copyright 2014-present PlatformIO <contact@platformio.org>
|
||||||
|
@ -89,8 +77,6 @@ def _parse_size(value):
|
||||||
def _parse_ld_sizes(ldscript_path):
|
def _parse_ld_sizes(ldscript_path):
|
||||||
assert ldscript_path
|
assert ldscript_path
|
||||||
result = {}
|
result = {}
|
||||||
# get flash size from board's manifest
|
|
||||||
result['flash_size'] = int(env.BoardConfig().get("upload.maximum_size", 0))
|
|
||||||
# get flash size from LD script path
|
# get flash size from LD script path
|
||||||
match = re.search(r"\.flash\.(\d+[mk]).*\.ld", ldscript_path)
|
match = re.search(r"\.flash\.(\d+[mk]).*\.ld", ldscript_path)
|
||||||
if match:
|
if match:
|
||||||
|
@ -144,18 +130,6 @@ def esp8266_fetch_fs_size(env):
|
||||||
|
|
||||||
env[k] = _value
|
env[k] = _value
|
||||||
|
|
||||||
def esp8266_get_esptoolpy_reset_flags(resetmethod):
|
|
||||||
# no dtr, no_sync
|
|
||||||
resets = ("no_reset_no_sync", "soft_reset")
|
|
||||||
if resetmethod == "nodemcu":
|
|
||||||
# dtr
|
|
||||||
resets = ("default_reset", "hard_reset")
|
|
||||||
elif resetmethod == "ck":
|
|
||||||
# no dtr
|
|
||||||
resets = ("no_reset", "soft_reset")
|
|
||||||
|
|
||||||
return ["--before", resets[0], "--after", resets[1]]
|
|
||||||
|
|
||||||
## Script interface functions
|
## Script interface functions
|
||||||
def parse_partition_table(content):
|
def parse_partition_table(content):
|
||||||
entries = [e for e in content.split(b'\xaaP') if len(e) > 0]
|
entries = [e for e in content.split(b'\xaaP') if len(e) > 0]
|
||||||
|
@ -168,10 +142,10 @@ def parse_partition_table(content):
|
||||||
#print("type:",hex(type))
|
#print("type:",hex(type))
|
||||||
#print("address:",hex(offset))
|
#print("address:",hex(offset))
|
||||||
#print("size:",hex(size))
|
#print("size:",hex(size))
|
||||||
env["SPIFFS_START"] = offset
|
env["FS_START"] = offset
|
||||||
env["SPIFFS_SIZE"] = size
|
env["FS_SIZE"] = size
|
||||||
env["SPIFFS_PAGE"] = int("0x100", 16)
|
env["FS_PAGE"] = int("0x100", 16)
|
||||||
env["SPIFFS_BLOCK"] = int("0x1000", 16)
|
env["FS_BLOCK"] = int("0x1000", 16)
|
||||||
|
|
||||||
def get_partition_table():
|
def get_partition_table():
|
||||||
esptoolpy = join(platform.get_package_dir("tool-esptoolpy") or "", "esptool.py")
|
esptoolpy = join(platform.get_package_dir("tool-esptoolpy") or "", "esptool.py")
|
||||||
|
@ -193,8 +167,6 @@ def get_partition_table():
|
||||||
fs_file
|
fs_file
|
||||||
]
|
]
|
||||||
esptoolpy_cmd = [env["PYTHONEXE"], esptoolpy] + esptoolpy_flags
|
esptoolpy_cmd = [env["PYTHONEXE"], esptoolpy] + esptoolpy_flags
|
||||||
#print("Executing flash download command to read partition table.")
|
|
||||||
#print(esptoolpy_cmd)
|
|
||||||
try:
|
try:
|
||||||
returncode = subprocess.call(esptoolpy_cmd, shell=False)
|
returncode = subprocess.call(esptoolpy_cmd, shell=False)
|
||||||
except subprocess.CalledProcessError as exc:
|
except subprocess.CalledProcessError as exc:
|
||||||
|
@ -207,10 +179,8 @@ def get_fs_type_start_and_length():
|
||||||
platform = env["PIOPLATFORM"]
|
platform = env["PIOPLATFORM"]
|
||||||
if platform == "espressif32":
|
if platform == "espressif32":
|
||||||
print(f"Retrieving filesystem info for {mcu}.")
|
print(f"Retrieving filesystem info for {mcu}.")
|
||||||
#print("Partition file: " + str(env.subst("$PARTITIONS_TABLE_CSV")))
|
|
||||||
# esp32_fetch_spiffs_size(env)
|
|
||||||
get_partition_table()
|
get_partition_table()
|
||||||
return SPIFFSInfo(env["SPIFFS_START"], env["SPIFFS_SIZE"], env["SPIFFS_PAGE"], env["SPIFFS_BLOCK"])
|
return FS_Info(env["FS_START"], env["FS_SIZE"], env["FS_PAGE"], env["FS_BLOCK"])
|
||||||
elif platform == "espressif8266":
|
elif platform == "espressif8266":
|
||||||
print("Retrieving filesystem info for ESP8266.")
|
print("Retrieving filesystem info for ESP8266.")
|
||||||
filesystem = board.get("build.filesystem", "littlefs")
|
filesystem = board.get("build.filesystem", "littlefs")
|
||||||
|
@ -219,13 +189,13 @@ def get_fs_type_start_and_length():
|
||||||
env.Exit(1)
|
env.Exit(1)
|
||||||
# fetching sizes is the same for all filesystems
|
# fetching sizes is the same for all filesystems
|
||||||
esp8266_fetch_fs_size(env)
|
esp8266_fetch_fs_size(env)
|
||||||
print("FS_START: " + hex(env["FS_START"]))
|
#print("FS_START: " + hex(env["FS_START"]))
|
||||||
print("FS_END: " + hex(env["FS_END"]))
|
#print("FS_SIZE: " + hex(env["FS_END"] - env["FS_START"]))
|
||||||
print("FS_PAGE: " + hex(env["FS_PAGE"]))
|
#print("FS_PAGE: " + hex(env["FS_PAGE"]))
|
||||||
print("FS_BLOCK: " + hex(env["FS_BLOCK"]))
|
#print("FS_BLOCK: " + hex(env["FS_BLOCK"]))
|
||||||
if filesystem == "littlefs":
|
if filesystem == "littlefs":
|
||||||
print("Recognized LittleFS filesystem.")
|
print("Recognized LittleFS filesystem.")
|
||||||
return LittleFSInfo(env["FS_START"], env["FS_END"] - env["FS_START"], env["FS_PAGE"], env["FS_BLOCK"])
|
return FS_Info(env["FS_START"], env["FS_END"] - env["FS_START"], env["FS_PAGE"], env["FS_BLOCK"])
|
||||||
else:
|
else:
|
||||||
print("Unrecongized configuration.")
|
print("Unrecongized configuration.")
|
||||||
pass
|
pass
|
||||||
|
@ -252,10 +222,8 @@ def download_fs(fs_info: FSInfo):
|
||||||
]
|
]
|
||||||
esptoolpy_cmd = [env["PYTHONEXE"], esptoolpy] + esptoolpy_flags
|
esptoolpy_cmd = [env["PYTHONEXE"], esptoolpy] + esptoolpy_flags
|
||||||
print("Download filesystem image")
|
print("Download filesystem image")
|
||||||
#print(esptoolpy_cmd)
|
|
||||||
try:
|
try:
|
||||||
returncode = subprocess.call(esptoolpy_cmd, shell=False)
|
returncode = subprocess.call(esptoolpy_cmd, shell=False)
|
||||||
# print("Launched download of filesystem binary.")
|
|
||||||
return (True, fs_file)
|
return (True, fs_file)
|
||||||
except subprocess.CalledProcessError as exc:
|
except subprocess.CalledProcessError as exc:
|
||||||
print("Downloading failed with " + str(exc))
|
print("Downloading failed with " + str(exc))
|
||||||
|
@ -265,7 +233,6 @@ def unpack_fs(fs_info: FSInfo, downloaded_file: str):
|
||||||
# by writing custom_unpack_dir = some_dir in the platformio.ini, one can
|
# by writing custom_unpack_dir = some_dir in the platformio.ini, one can
|
||||||
# control the unpack directory
|
# control the unpack directory
|
||||||
unpack_dir = env.GetProjectOption("custom_unpack_dir", "unpacked_fs")
|
unpack_dir = env.GetProjectOption("custom_unpack_dir", "unpacked_fs")
|
||||||
#unpack_dir = "unpacked_fs"
|
|
||||||
if not os.path.exists(downloaded_file):
|
if not os.path.exists(downloaded_file):
|
||||||
print(f"ERROR: {downloaded_file} with filesystem not found, maybe download failed due to download_speed setting being too high.")
|
print(f"ERROR: {downloaded_file} with filesystem not found, maybe download failed due to download_speed setting being too high.")
|
||||||
assert(0)
|
assert(0)
|
||||||
|
@ -279,7 +246,6 @@ def unpack_fs(fs_info: FSInfo, downloaded_file: str):
|
||||||
|
|
||||||
cmd = fs_info.get_extract_cmd(downloaded_file, unpack_dir)
|
cmd = fs_info.get_extract_cmd(downloaded_file, unpack_dir)
|
||||||
print("Unpack files from filesystem image")
|
print("Unpack files from filesystem image")
|
||||||
#print("Extraction command: " + str(cmd))
|
|
||||||
try:
|
try:
|
||||||
returncode = subprocess.call(cmd, shell=True)
|
returncode = subprocess.call(cmd, shell=True)
|
||||||
return (True, unpack_dir)
|
return (True, unpack_dir)
|
||||||
|
@ -294,10 +260,8 @@ def display_fs(extracted_dir):
|
||||||
print("Extracted " + str(file_count) + " file(s) from filesystem.")
|
print("Extracted " + str(file_count) + " file(s) from filesystem.")
|
||||||
|
|
||||||
def command_download_fs(*args, **kwargs):
|
def command_download_fs(*args, **kwargs):
|
||||||
get_partition_table()
|
|
||||||
info = get_fs_type_start_and_length()
|
info = get_fs_type_start_and_length()
|
||||||
download_ok, downloaded_file = download_fs(info)
|
download_ok, downloaded_file = download_fs(info)
|
||||||
# print("Download was okay: " + str(download_ok) + ". File at: "+ str(downloaded_file)) # this is wrong
|
|
||||||
unpack_ok, unpacked_dir = unpack_fs(info, downloaded_file)
|
unpack_ok, unpacked_dir = unpack_fs(info, downloaded_file)
|
||||||
if unpack_ok is True:
|
if unpack_ok is True:
|
||||||
display_fs(unpacked_dir)
|
display_fs(unpacked_dir)
|
||||||
|
|
Loading…
Reference in New Issue