Merge pull request #15520 from Jason2866/safemode

Safemode refactor
This commit is contained in:
Jason2866 2022-05-02 23:33:38 +02:00 committed by GitHub
commit 78d1b0c354
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 44 additions and 33 deletions

View File

@ -31,11 +31,7 @@
"flash_extra_images": [ "flash_extra_images": [
[ [
"0x10000", "0x10000",
"variants/tasmota/tasmota32-minicustom.bin" "variants/tasmota/tasmota32-safemode.bin"
],
[
"0x3B0000",
"variants/tasmota/littlefs.bin"
] ]
] ]
}, },

View File

@ -28,11 +28,7 @@
"flash_extra_images": [ "flash_extra_images": [
[ [
"0x10000", "0x10000",
"variants/tasmota/tasmota32c3-minicustom.bin" "variants/tasmota/tasmota32c3-safemode.bin"
],
[
"0x3B0000",
"variants/tasmota/littlefs.bin"
] ]
] ]
}, },

View File

@ -1,6 +1,6 @@
# Name, Type, SubType, Offset, Size, Flags # Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000, nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000, otadata, data, ota, 0xe000, 0x2000,
factory, app, factory, 0x10000,0xD0000, factory, app, factory, 0x10000, 0xD0000,
app0, app, ota_0, 0xE0000, 0x2D0000, app0, app, ota_0, 0xE0000, 0x2D0000,
spiffs, data, spiffs, 0x3B0000,0x50000, spiffs, data, spiffs, 0x3B0000,0x50000,

1 # Name Type SubType Offset Size Flags
2 nvs data nvs 0x9000 0x5000
3 otadata data ota 0xe000 0x2000
4 factory app factory 0x10000 0xD0000
5 app0 app ota_0 0xE0000 0x2D0000
6 spiffs data spiffs 0x3B0000 0x50000

View File

@ -1,20 +0,0 @@
import os
import shutil
from os.path import join
from SCons.Script import DefaultEnvironment
env = DefaultEnvironment()
platform = env.PioPlatform()
FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32")
safemode_dir = join(env["PROJECT_DIR"], "safemode")
variants_dir = join(FRAMEWORK_DIR, "variants", "tasmota")
if env["PIOPLATFORM"] == "espressif32":
if os.path.exists(safemode_dir):
# print("safemode.bin dir exists")
if os.path.exists(variants_dir):
# print("variants/tasmota exists")
shutil.rmtree(variants_dir)
shutil.copytree(safemode_dir, variants_dir)

View File

@ -18,21 +18,47 @@
Import("env") Import("env")
env = DefaultEnvironment()
platform = env.PioPlatform() platform = env.PioPlatform()
from genericpath import exists
import os
import sys import sys
from os.path import join from os.path import join
import csv import csv
import requests
import shutil
sys.path.append(join(platform.get_package_dir("tool-esptoolpy"))) sys.path.append(join(platform.get_package_dir("tool-esptoolpy")))
import esptool import esptool
FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32")
safemode_dir = join(env["PROJECT_DIR"], "safemode")
variants_dir = join(FRAMEWORK_DIR, "variants", "tasmota")
def esp32_fetch_safemode_bin(chip):
safemode_fw_url = "https://github.com/Jason2866/Tasmota-specials/raw/firmware/firmware/tasmota32/other/tasmota" + chip[3:] + "-safemode.bin"
safemode_fw_name = safemode_dir + "/tasmota" + chip[3:] + "-safemode.bin"
if(exists(safemode_fw_name)):
print("Safemode binary already downloaded.")
return safemode_fw_name
print("Will download safemode binary from URL:")
print(safemode_fw_url)
response = requests.get(safemode_fw_url)
open(safemode_fw_name, "wb").write(response.content)
print("Safemode binary written to safemode dir.")
return safemode_fw_name
def esp32_create_combined_bin(source, target, env): def esp32_create_combined_bin(source, target, env):
#print("Generating combined binary for serial flashing") #print("Generating combined binary for serial flashing")
# The offset from begin of the file where the app0 partition starts # The offset from begin of the file where the app0 partition starts
# This is defined in the partition .csv file # This is defined in the partition .csv file
app_offset = 0x10000 # default value factory_offset = -1 # error code value
app_offset = 0x10000 # default value for "old" scheme
spiffs_offset = -1 # error code value
with open(env.BoardConfig().get("build.partitions")) as csv_file: with open(env.BoardConfig().get("build.partitions")) as csv_file:
print("Read partitions from ",env.BoardConfig().get("build.partitions")) print("Read partitions from ",env.BoardConfig().get("build.partitions"))
csv_reader = csv.reader(csv_file, delimiter=',') csv_reader = csv.reader(csv_file, delimiter=',')
@ -46,12 +72,17 @@ def esp32_create_combined_bin(source, target, env):
line_count += 1 line_count += 1
if(row[0] == 'app0'): if(row[0] == 'app0'):
app_offset = int(row[3],base=16) app_offset = int(row[3],base=16)
elif(row[0] == 'factory'):
factory_offset = int(row[3],base=16)
elif(row[0] == 'spiffs'):
spiffs_offset = int(row[3],base=16)
# print("Got app_offset from .csv:", row[3]) # print("Got app_offset from .csv:", row[3])
new_file_name = env.subst("$BUILD_DIR/${PROGNAME}.factory.bin") new_file_name = env.subst("$BUILD_DIR/${PROGNAME}.factory.bin")
sections = env.subst(env.get("FLASH_EXTRA_IMAGES")) sections = env.subst(env.get("FLASH_EXTRA_IMAGES"))
firmware_name = env.subst("$BUILD_DIR/${PROGNAME}.bin") firmware_name = env.subst("$BUILD_DIR/${PROGNAME}.bin")
chip = env.get("BOARD_MCU") chip = env.get("BOARD_MCU")
esp32_fetch_safemode_bin(chip)
flash_size = env.BoardConfig().get("upload.flash_size") flash_size = env.BoardConfig().get("upload.flash_size")
cmd = [ cmd = [
"--chip", "--chip",
@ -69,6 +100,14 @@ def esp32_create_combined_bin(source, target, env):
print(f" - {sect_adr} | {sect_file}") print(f" - {sect_adr} | {sect_file}")
cmd += [sect_adr, sect_file] cmd += [sect_adr, sect_file]
if os.path.exists(safemode_dir):
#print("safemode.bin dir exists")
if os.path.exists(variants_dir):
#print("variants/tasmota exists")
shutil.rmtree(variants_dir)
shutil.copytree(safemode_dir, variants_dir)
# "main" firmware to app0 - mandatory
print(f" - {hex(app_offset)} | {firmware_name}") print(f" - {hex(app_offset)} | {firmware_name}")
cmd += [hex(app_offset), firmware_name] cmd += [hex(app_offset), firmware_name]

View File

@ -34,7 +34,6 @@ build_flags = ${esp_defaults.build_flags}
-Wl,--wrap=panicHandler -Wl,--wrap=xt_unhandled_exception -Wl,--wrap=panicHandler -Wl,--wrap=xt_unhandled_exception
-Wl,--wrap=_Z11analogWritehi ; `analogWrite(unsigned char, int)` use the Tasmota version of analogWrite for deeper integration and phase control -Wl,--wrap=_Z11analogWritehi ; `analogWrite(unsigned char, int)` use the Tasmota version of analogWrite for deeper integration and phase control
extra_scripts = pre:pio-tools/add_c_flags.py extra_scripts = pre:pio-tools/add_c_flags.py
pre:pio-tools/copy_safemode.py
post:pio-tools/post_esp32.py post:pio-tools/post_esp32.py
${esp_defaults.extra_scripts} ${esp_defaults.extra_scripts}

Binary file not shown.

1
safemode/placeholder Normal file
View File

@ -0,0 +1 @@

Binary file not shown.

Binary file not shown.