Improve safeboot binary fetching logic (#25107)

Enhanced error handling for safeboot binary download and validation.
This commit is contained in:
Jason2866 authored and GitHub committed 2026-10-06 12:53:46 +02:00
1 parent 33bfcf4578
commit 5f3f8c97df
1 file changed
+24 -11
+24 -11
View File
@@ -223,22 +223,35 @@ def esp32_fetch_safeboot_bin(tasmota_platform):
safeboot_fw_url = "http://ota.tasmota.com/tasmota32/release/" + tasmota_platform + "-safeboot.bin"
safeboot_fw_name = os.path.normpath(join(variants_dir, tasmota_platform + "-safeboot.bin"))
if(exists(safeboot_fw_name)):
print(Fore.GREEN + "Safeboot binary already in place")
return True
try:
with open(safeboot_fw_name, "rb") as safeboot_file:
if safeboot_file.read(1) == b"\xE9":
print(Fore.GREEN + "Safeboot binary already in place")
return True
except OSError:
pass
print(Fore.YELLOW + "Existing safeboot file is not a valid ESP firmware image; downloading a replacement")
print()
print(Fore.GREEN + "Will download safeboot binary from URL:")
print(Fore.BLUE + safeboot_fw_url)
try:
response = requests.get(safeboot_fw_url)
open(safeboot_fw_name, "wb").write(response.content)
print(Fore.GREEN + "Safeboot binary written to variants path:")
print(Fore.BLUE + safeboot_fw_name)
return True
except:
print(Fore.RED + "Download of safeboot binary failed. Please check your Internet connection.")
print(Fore.RED + "Creation of " + tasmota_platform + "-factory.bin not possible")
print(Fore.YELLOW + "Without Internet " + Fore.GREEN + tasmota_platform + "-safeboot.bin" + Fore.YELLOW + " needs to be compiled before " + Fore.GREEN + tasmota_platform)
return False
if not response.ok:
print(Fore.RED + "Safeboot download failed with HTTP status", response.status_code)
elif not response.content.startswith(b"\xE9"):
print(Fore.RED + "Downloaded file is not a valid ESP firmware image")
else:
with open(safeboot_fw_name, "wb") as safeboot_file:
safeboot_file.write(response.content)
print(Fore.GREEN + "Safeboot binary written to variants path:")
print(Fore.BLUE + safeboot_fw_name)
return True
except Exception:
pass
print(Fore.RED + "Download of safeboot binary failed. Please check your Internet connection.")
print(Fore.RED + "Creation of " + tasmota_platform + "-factory.bin not possible")
print(Fore.YELLOW + "Without download from Internet " + Fore.GREEN + tasmota_platform + "-safeboot.bin" + Fore.YELLOW + " needs to be compiled before " + Fore.GREEN + tasmota_platform)
return False
def esp32_copy_new_safeboot_bin(tasmota_platform,new_local_safeboot_fw):
print("Copy new local safeboot firmware to variants dir -> using it for further flashing operations")