Skip to content

Commit 11f2e4a

Browse files
danieldegrassecfriedt
authored andcommitted
scripts: dmc_reset: make default arguments module variables
Make the default arguments for the script into module variables, so we can reuse this script as a module where desired. Signed-off-by: Daniel DeGrasse <[email protected]>
1 parent e3c900f commit 11f2e4a

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

scripts/dmc_reset.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,24 @@
3232
OPT_DIR = Path("/opt/tenstorrent")
3333
SDK_SYSROOT = Path("/opt/zephyr/zephyr-sdk-0.17.0/sysroots/x86_64-pokysdk-linux")
3434

35+
# Execute CMake to locate SDK sysroot
36+
proc = subprocess.run(
37+
["cmake", "-P", str(Path(__file__).parent / "find_zephyr_sdk.cmake")],
38+
capture_output=True,
39+
)
40+
if "SDK_INSTALL_DIR" in str(proc.stderr):
41+
DEFAULT_SDK_INSTALL_DIR = (
42+
Path(str(proc.stderr).split(":")[1][:-3]) / "sysroots" / "x86_64-pokysdk-linux"
43+
)
44+
else:
45+
DEFAULT_SDK_INSTALL_DIR = SDK_SYSROOT
46+
47+
DEFAULT_OPENOCD = DEFAULT_SDK_INSTALL_DIR / "usr" / "bin" / "openocd"
48+
DEFAULT_SCRIPTS_DIR = DEFAULT_SDK_INSTALL_DIR / "usr" / "share" / "openocd" / "scripts"
49+
DEFAULT_HW_MAP = OPT_DIR / "twister" / "hw-map.yml"
50+
3551

3652
def parse_args():
37-
# Execute CMake to locate SDK sysroot
38-
proc = subprocess.run(
39-
["cmake", "-P", str(Path(__file__).parent / "find_zephyr_sdk.cmake")],
40-
capture_output=True,
41-
)
42-
if "SDK_INSTALL_DIR" in str(proc.stderr):
43-
DEFAULT_SDK_INSTALL_DIR = (
44-
Path(str(proc.stderr).split(":")[1][:-3])
45-
/ "sysroots"
46-
/ "x86_64-pokysdk-linux"
47-
)
48-
else:
49-
DEFAULT_SDK_INSTALL_DIR = SDK_SYSROOT
5053
parser = argparse.ArgumentParser(description="Reset DMC", allow_abbrev=False)
5154
parser.add_argument(
5255
"-c",
@@ -73,23 +76,23 @@ def parse_args():
7376
parser.add_argument(
7477
"-m",
7578
"--hw-map",
76-
default=OPT_DIR / "twister" / "hw-map.yml",
79+
default=DEFAULT_HW_MAP,
7780
help="Use a specific hw-map.yml file",
7881
metavar="MAP",
7982
type=Path,
8083
)
8184
parser.add_argument(
8285
"-o",
8386
"--openocd",
84-
default=DEFAULT_SDK_INSTALL_DIR / "usr" / "bin" / "openocd",
85-
help="Use a specific hw-map.yml file",
87+
default=DEFAULT_OPENOCD,
88+
help="Use a specific openocd executable",
8689
metavar="FILE",
8790
type=Path,
8891
)
8992
parser.add_argument(
9093
"-s",
9194
"--scripts",
92-
default=DEFAULT_SDK_INSTALL_DIR / "usr" / "share" / "openocd" / "scripts",
95+
default=DEFAULT_SCRIPTS_DIR,
9396
help="Path to OpenOCD scripts directory",
9497
metavar="DIR",
9598
type=Path,

0 commit comments

Comments
 (0)