|
|
|
|
@@ -1,5 +1,79 @@
|
|
|
|
|
# Copyright (C) 2026 Hector van der Aa <hector@h3cx.dev>
|
|
|
|
|
# Copyright (C) 2026 Association Exergie <association.exergie@gmail.com>
|
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
def run():
|
|
|
|
|
print("Flashing NeoECU...")
|
|
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
import neoecu.common
|
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
def gen_flash_script(jlink_path: Path, core: str, bin_path: Path) -> Path:
|
|
|
|
|
jlink_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
script_path = jlink_path / "flash.jlink"
|
|
|
|
|
script_path.unlink(missing_ok=True)
|
|
|
|
|
new_script: str = ""
|
|
|
|
|
if (core == "M7") or (core == "CM7"):
|
|
|
|
|
new_script += "device STM32H747XI_M7\n"
|
|
|
|
|
elif (core == "M4") or (core == "CM4"):
|
|
|
|
|
new_script += "device STM32H747XI_M4\n"
|
|
|
|
|
else:
|
|
|
|
|
raise RuntimeError(f"Unknown core: {core}")
|
|
|
|
|
|
|
|
|
|
new_script += "si SWD\n"
|
|
|
|
|
new_script += "speed auto\n"
|
|
|
|
|
new_script += "\n"
|
|
|
|
|
new_script += "connect\n"
|
|
|
|
|
new_script += "\n"
|
|
|
|
|
new_script += f'loadfile "{bin_path}"\n'
|
|
|
|
|
new_script += "\n"
|
|
|
|
|
new_script += "r\n"
|
|
|
|
|
new_script += "g\n"
|
|
|
|
|
new_script += "exit"
|
|
|
|
|
|
|
|
|
|
script_path.write_text(new_script);
|
|
|
|
|
return script_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run(root_path: Path):
|
|
|
|
|
|
|
|
|
|
config = neoecu.common.load_config(root_path)
|
|
|
|
|
|
|
|
|
|
m7_root = root_path / config["build"]["m7_dir"]
|
|
|
|
|
m4_root = root_path / config["build"]["m4_dir"]
|
|
|
|
|
|
|
|
|
|
m7_jlink_scripts = m7_root / ".jlink_scripts"
|
|
|
|
|
m4_jlink_scripts = m4_root / ".jlink_scripts"
|
|
|
|
|
|
|
|
|
|
m7_build = m7_root / "CM7" / "build"
|
|
|
|
|
|
|
|
|
|
matches = list(m7_build.glob("*_CM7.elf"))
|
|
|
|
|
|
|
|
|
|
if not matches:
|
|
|
|
|
raise FileNotFoundError("No *_CM7.elf found in build directory")
|
|
|
|
|
|
|
|
|
|
if len(matches) > 1:
|
|
|
|
|
raise RuntimeError(f"Multiple CM7 ELF files found: {matches}")
|
|
|
|
|
|
|
|
|
|
m7_bin = matches[0]
|
|
|
|
|
|
|
|
|
|
m4_build = m4_root / "build" / "zephyr"
|
|
|
|
|
|
|
|
|
|
matches = list(m4_build.glob("zephyr.elf"))
|
|
|
|
|
|
|
|
|
|
if not matches:
|
|
|
|
|
raise FileNotFoundError("No *_CM4.elf found in build directory")
|
|
|
|
|
|
|
|
|
|
if len(matches) > 1:
|
|
|
|
|
raise RuntimeError(f"Multiple CM4 ELF files found: {matches}")
|
|
|
|
|
|
|
|
|
|
m4_bin = matches[0]
|
|
|
|
|
|
|
|
|
|
m7_flash_script = gen_flash_script(m7_jlink_scripts, "CM7", m7_bin)
|
|
|
|
|
m4_flash_script = gen_flash_script(m4_jlink_scripts, "CM4", m4_bin)
|
|
|
|
|
|
|
|
|
|
subprocess.run(["JLinkExe", "-CommanderScript", f"{m4_flash_script}"], cwd=m4_root)
|
|
|
|
|
subprocess.run(["JLinkExe", "-CommanderScript", f"{m7_flash_script}"], cwd=m7_root)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|