Skip to content

Commit 7972751

Browse files
committed
rg_tool: cleanup
1 parent 370532e commit 7972751

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

rg_tool.py

+18-16
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,20 @@ def build_app(app, device_type, with_profiling=False, no_networking=False):
206206
print("Done.\n")
207207

208208

209+
def flash_app(app, port, baudrate=1152000):
210+
os.putenv("ESPTOOL_CHIP", os.getenv("IDF_TARGET", "auto"))
211+
os.putenv("ESPTOOL_BAUD", baudrate)
212+
os.putenv("ESPTOOL_PORT", port)
213+
if not os.path.exists("partitions.bin"):
214+
print("Reading device's partition table...")
215+
subprocess.run("esptool.py read_flash 0x8000 0x1000 partitions.bin", check=True, shell=True)
216+
subprocess.run("gen_esp32part.py partitions.bin", shell=True)
217+
app_bin = os.path.join(app, "build", app + ".bin")
218+
print(f"Flashing '{app_bin}' to port {port}")
219+
args = ["parttool.py", "--partition-table-file", "partitions.bin", "write_partition", "--partition-name", app, "--input", app_bin]
220+
subprocess.run(args, check=True, shell=True)
221+
222+
209223
def monitor_app(app, port, baudrate=115200):
210224
print(f"Starting monitor for app {app} on port {port}")
211225
try:
@@ -334,26 +348,14 @@ def monitor_app(app, port, baudrate=115200):
334348

335349
if command in ["flash", "run", "profile"]:
336350
print("=== Step: Flashing ===\n")
337-
os.putenv("ESPTOOL_CHIP", os.getenv("IDF_TARGET", "auto"))
338-
os.putenv("ESPTOOL_BAUD", args.baud)
339-
os.putenv("ESPTOOL_PORT", args.port)
340-
print("Reading device's partition table...")
341-
subprocess.run("esptool.py read_flash 0x8000 0x1000 partitions.bin", check=True, shell=True)
342-
subprocess.run("gen_esp32part.py partitions.bin", shell=True)
351+
try: os.unlink("partitions.bin")
352+
except: pass
343353
for app in apps:
344-
print("Flashing app '%s'" % app)
345-
subprocess.run([
346-
"parttool.py",
347-
"--partition-table-file", "partitions.bin",
348-
"write_partition", "--partition-name", app, "--input", os.path.join(app, "build", app + ".bin")
349-
], check=True, shell=True)
354+
flash_app(app, args.port, args.baud)
350355

351356
if command in ["monitor", "run", "profile"]:
352357
print("=== Step: Monitoring ===\n")
353-
if len(apps) == 1:
354-
monitor_app(apps[0], args.port)
355-
else:
356-
monitor_app("dummy", args.port)
358+
monitor_app(apps[0] if len(apps) else "dummy", args.port)
357359

358360
print("All done!")
359361

0 commit comments

Comments
 (0)