Skip to content

Commit

Permalink
rg_tool: Only use shell=True on Windows
Browse files Browse the repository at this point in the history
Apparently when shell=True we can't reliably pass a list to subprocess.run
  • Loading branch information
ducalex committed Jan 30, 2024
1 parent c02aa30 commit 2280e29
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions rg_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,15 @@ def analyze_profile(frames):
debug_print("")


def run(cmd, cwd=None, check=True):
print(f"Running command: {' '.join(cmd)}")
return subprocess.run(cmd, shell=os.name == 'nt', cwd=cwd, check=check)


def build_firmware(apps, device_type, fw_format="odroid-go"):
print("Building firmware with: %s\n" % " ".join(apps))
args = [
sys.executable,
"tools/mkfw.py",
os.path.join("tools", "mkfw.py"),
("%s_%s_%s.fw" % (PROJECT_NAME, PROJECT_VER, device_type)).lower(),
("%s %s" % (PROJECT_NAME, PROJECT_VER)),
PROJECT_ICON
Expand All @@ -132,8 +136,7 @@ def build_firmware(apps, device_type, fw_format="odroid-go"):
part = PROJECT_APPS[app]
args += [str(part[0]), str(part[1]), str(part[2]), app, os.path.join(app, "build", app + ".bin")]

print("Running: %s" % ' '.join(shlex.quote(arg) for arg in args[1:]))
subprocess.run(args, check=True)
run(args)


def build_image(apps, device_type, img_format="esp32"):
Expand All @@ -158,14 +161,13 @@ def build_image(apps, device_type, img_format="esp32"):
print("Generating partition table...")
with open("partitions.csv", "w") as f:
f.write("\n".join(table_csv))
subprocess.run("gen_esp32part.py partitions.csv partitions.bin", shell=True, check=True)
run(["gen_esp32part.py", "partitions.csv", "partitions.bin"])
with open("partitions.bin", "rb") as f:
table_bin = f.read()

print("Building bootloader...")
cwd = os.path.join(os.getcwd(), list(apps)[0])
subprocess.run("idf.py bootloader", shell=True, check=True, cwd=cwd)
with open(os.path.join(cwd, "build", "bootloader", "bootloader.bin"), "rb") as f:
run(["idf.py", "bootloader"], cwd=os.path.join(os.getcwd(), list(apps)[0]))
with open(os.path.join(os.getcwd(), list(apps)[0], "build", "bootloader", "bootloader.bin"), "rb") as f:
bootloader_bin = f.read()

if img_format == "esp32s3":
Expand Down Expand Up @@ -203,8 +205,7 @@ def build_app(app, device_type, with_profiling=False, no_networking=False):
args.append(f"-DRG_BUILD_TARGET={re.sub(r'[^A-Z0-9]', '_', device_type.upper())}")
args.append(f"-DRG_ENABLE_PROFILING={1 if with_profiling else 0}")
args.append(f"-DRG_ENABLE_NETWORKING={0 if no_networking else 1}")
print(f"Running {' '.join(args)}")
subprocess.run(" ".join(args), shell=True, check=True, cwd=os.path.join(os.getcwd(), app))
run(args, cwd=os.path.join(os.getcwd(), app))
print("Done.\n")


Expand All @@ -214,12 +215,11 @@ def flash_app(app, port, baudrate=1152000):
os.putenv("ESPTOOL_PORT", port)
if not os.path.exists("partitions.bin"):
print("Reading device's partition table...")
subprocess.run("esptool.py read_flash 0x8000 0x1000 partitions.bin", check=True, shell=True)
subprocess.run("gen_esp32part.py partitions.bin", shell=True)
run(["esptool.py", "read_flash", "0x8000", "0x1000", "partitions.bin"], check=False)
run(["gen_esp32part.py", "partitions.bin"], check=False)
app_bin = os.path.join(app, "build", app + ".bin")
print(f"Flashing '{app_bin}' to port {port}")
args = ["parttool.py", "--partition-table-file", "partitions.bin", "write_partition", "--partition-name", app, "--input", app_bin]
subprocess.run(args, check=True, shell=True)
run(["parttool.py", "--partition-table-file", "partitions.bin", "write_partition", "--partition-name", app, "--input", app_bin])


def monitor_app(app, port, baudrate=115200):
Expand Down

0 comments on commit 2280e29

Please sign in to comment.