Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flash firmware without run build #18233

Merged
merged 2 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -30,11 +40,6 @@
}
]
},
{
"text": "$(arrow-right)",
"tooltip": "PlatformIO: Upload and Monitor",
"commands": "platformio-ide.uploadAndMonitor"
},
{
"text": "$(error)",
"tooltip": "PlatformIO: Erase Flash",
Expand All @@ -45,6 +50,11 @@
}
]
},
{
"text": "$(arrow-right)",
"tooltip": "PlatformIO: Upload and Monitor",
"commands": "platformio-ide.uploadAndMonitor"
},
{
"text": "$(device-desktop)",
"tooltip": "PlatformIO: Serial Monitor",
Expand Down
38 changes: 38 additions & 0 deletions pio-tools/download_fs.py → pio-tools/custom_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand All @@ -327,3 +355,13 @@ def command_download_fs(*args, **kwargs):
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"
)
2 changes: 1 addition & 1 deletion pio-tools/name-firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
15 changes: 15 additions & 0 deletions pio-tools/set_partition_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down