Flash firmware without `run build` (#18233)

* Flash without build
* Use firmwares from `build_output`
* simulate build with firmware from `build_output`
* rm debug code
This commit is contained in:
Jason2866 2023-03-21 14:56:24 +01:00 committed by GitHub
parent a68bc49cab
commit 11645705e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 7 deletions

20
.vscode/settings.json vendored
View File

@ -15,6 +15,16 @@
"tooltip": "PlatformIO: Build",
"commands": "platformio-ide.build"
},
{
"text": "Upload",
"tooltip": "PlatformIO: Flash firmware (NO build run)",
"commands": [
{
"id": "platformio-ide.runPIOCoreCommand",
"args": "pio run -t nobuild -t factory_flash"
}
]
},
{
"text": "$(zap)",
"tooltip": "PlatformIO: Build and Upload",
@ -30,11 +40,6 @@
}
]
},
{
"text": "$(arrow-right)",
"tooltip": "PlatformIO: Upload and Monitor",
"commands": "platformio-ide.uploadAndMonitor"
},
{
"text": "$(error)",
"tooltip": "PlatformIO: Erase Flash",
@ -45,6 +50,11 @@
}
]
},
{
"text": "$(arrow-right)",
"tooltip": "PlatformIO: Upload and Monitor",
"commands": "platformio-ide.uploadAndMonitor"
},
{
"text": "$(device-desktop)",
"tooltip": "PlatformIO: Serial Monitor",

View File

@ -256,9 +256,14 @@ def get_fs_type_start_and_length():
def download_fs(fs_info: FSInfo):
esptoolpy = join(platform.get_package_dir("tool-esptoolpy") or "", "esptool.py")
upload_port = join(env.get("UPLOAD_PORT", "none"))
if "none" in upload_port:
env.AutodetectUploadPort()
upload_port = join(env.get("UPLOAD_PORT", "none"))
fs_file = join(env["PROJECT_DIR"], f"downloaded_fs_{hex(fs_info.start)}_{hex(fs_info.length)}.bin")
esptoolpy_flags = [
"--chip", mcu,
"--port", upload_port,
"--baud", env.subst("$UPLOAD_SPEED"),
"--before", "default_reset",
"--after", "hard_reset",
@ -318,6 +323,29 @@ def command_download_fs(*args, **kwargs):
if unpack_ok is True:
display_fs(unpacked_dir)
def upload_factory(*args, **kwargs):
esptoolpy = join(platform.get_package_dir("tool-esptoolpy") or "", "esptool.py")
upload_speed = join(str(board.get("upload.speed", "115200")))
upload_port = join(env.get("UPLOAD_PORT", "none"))
cur_env = (env["PIOENV"])
firm_name = cur_env + "%s" % (".bin" if mcu == "esp8266" else (".factory.bin"))
target_firm = join(env.subst("$PROJECT_DIR"), "build_output","firmware",firm_name)
if "none" in upload_port:
env.AutodetectUploadPort()
upload_port = join(env.get("UPLOAD_PORT", "none"))
if "tasmota" in cur_env:
esptoolpy_flags = [
"--chip", mcu,
"--port", upload_port,
"--baud", upload_speed,
"write_flash",
"0x0",
target_firm
]
esptoolpy_cmd = [env["PYTHONEXE"], esptoolpy] + esptoolpy_flags
print("Flash firmware at address 0x0")
subprocess.call(esptoolpy_cmd, shell=False)
env.AddCustomTarget(
name="downloadfs",
dependencies=None,
@ -327,3 +355,13 @@ env.AddCustomTarget(
title="Download Filesystem",
description="Downloads and displays files stored in the target ESP32/ESP8266"
)
env.AddCustomTarget(
name="factory_flash",
dependencies=None,
actions=[
upload_factory
],
title="Flash factory",
description="Flash factory firmware"
)

View File

@ -29,4 +29,4 @@ def bin_map_copy(source, target, env):
if env["PIOPLATFORM"] == "espressif32":
shutil.copy(factory, one_bin_file)
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", bin_map_copy)
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", bin_map_copy)

View File

@ -9,11 +9,26 @@
Import("env")
import os
from os.path import isfile, join
import shutil
from SCons.Script import COMMAND_LINE_TARGETS
board_config = env.BoardConfig()
if "nobuild" in COMMAND_LINE_TARGETS:
if not os.path.isfile(join(env.subst("$BUILD_DIR"),"firmware.bin")):
#print ("No firmware in path:",join(env.subst("$BUILD_DIR")))
env.CleanProject()
cur_env = (env["PIOENV"])
firm_name = cur_env + ".bin"
source_firm = join(env.subst("$PROJECT_DIR"), "build_output","firmware",firm_name)
if not os.path.exists(join(env.subst("$BUILD_DIR"))):
os.makedirs(join(env.subst("$BUILD_DIR")))
shutil.copy(source_firm, join(env.subst("$BUILD_DIR")))
target_ren = join(env.subst("$BUILD_DIR"), firm_name)
renamed = join(env.subst("$BUILD_DIR"), "firmware.bin")
os.rename(target_ren, renamed)
if env["PIOPLATFORM"] != "espressif32":
framework_dir = env.PioPlatform().get_package_dir("framework-arduinoespressif8266")
assert os.path.isdir(framework_dir)

View File

@ -72,7 +72,7 @@ extra_scripts = pre:pio-tools/pre_source_dir.py
[esp_defaults]
extra_scripts = post:pio-tools/name-firmware.py
post:pio-tools/gzip-firmware.py
post:pio-tools/download_fs.py
post:pio-tools/custom_target.py
; post:pio-tools/obj-dump.py
${scripts_defaults.extra_scripts}
; *** remove undesired all warnings