diff --git a/toolkit/app-gen-toc.py b/toolkit/app-gen-toc.py index 4117854..c2a5054 100755 --- a/toolkit/app-gen-toc.py +++ b/toolkit/app-gen-toc.py @@ -687,7 +687,7 @@ def main(): parser.add_argument( "--config-dir", type=str, - default=Path(os.path.dirname(__file__)) / "build/config", + default=None, help="directory with configuration files", ) parser.add_argument( @@ -706,11 +706,7 @@ def main(): args = parser.parse_args() # Set paths given on command line. - paths.TOOLKIT_DIR = Path(os.path.dirname(__file__)) - paths.CERT_INPUT_DIR = paths.TOOLKIT_DIR / "cert" - paths.CONFIG_INPUT_DIR = Path(args.config_dir) - paths.FIRMWARE_INPUT_DIR = Path(args.firmware_dir) - paths.OUTPUT_DIR = Path(args.output_dir) + paths.configure(args.config_dir, args.firmware_dir, args.output_dir) if args.version: print(TOOL_VERSION) diff --git a/toolkit/app-write-mram.py b/toolkit/app-write-mram.py index 423e455..6f287ed 100755 --- a/toolkit/app-write-mram.py +++ b/toolkit/app-write-mram.py @@ -23,6 +23,7 @@ from isp.serialport import serialPort from isp.serialport import COM_BAUD_RATE_MAXIMUM from utils.toc_common import globalToLocalAddress +from utils import paths # import ispcommands from isp.isp_core import ( @@ -195,8 +196,18 @@ def main(): "-V", "--version", help="Display Version Number", action="store_true" ) parser.add_argument("-v", "--verbose", help="verbosity mode", action="store_true") + parser.add_argument( + "--config-dir", + type=str, + default=None, + help="directory with configuration files", + ) args = parser.parse_args() + + # Set paths given on command line. + paths.configure(args.config_dir) + if args.version: print(TOOL_VERSION) sys.exit() diff --git a/toolkit/utils/global-cfg.db b/toolkit/build/config/global-cfg.db similarity index 100% rename from toolkit/utils/global-cfg.db rename to toolkit/build/config/global-cfg.db diff --git a/toolkit/utils/config.py b/toolkit/utils/config.py index 7b3f4c8..209f17b 100644 --- a/toolkit/utils/config.py +++ b/toolkit/utils/config.py @@ -2,6 +2,7 @@ import sys import json from json.decoder import JSONDecodeError +from utils import paths # Define Version constant for each separate tool # 0.06.000 added package and offset params @@ -9,7 +10,7 @@ # DB files config_file_dir = os.path.dirname(__file__) -CONFIG_FILE = os.path.join(config_file_dir, "global-cfg.db") +CONFIG_FILE = "global-cfg.db" DEVICE_DB_FILE = os.path.join(config_file_dir, "devicesDB.db") FEATURES_DB_FILE = os.path.join(config_file_dir, "featuresDB.db") HASHES_DB_FILE = os.path.join(config_file_dir, "hashesDB.db") @@ -80,10 +81,10 @@ def read_global_config(file): def save_global_config(devDescription, devRevision): - with open(CONFIG_FILE, "r", encoding="utf-8") as f: + with open(paths.CONFIG_INPUT_DIR / CONFIG_FILE, "r", encoding="utf-8") as f: cfg = json.load(f) - with open(CONFIG_FILE, "w", encoding="utf-8") as f: + with open(paths.CONFIG_INPUT_DIR / CONFIG_FILE, "w", encoding="utf-8") as f: cfg["DEVICE"]["Part#"] = devDescription cfg["DEVICE"]["Revision"] = devRevision json.dump(cfg, f, ensure_ascii=False, indent=4) @@ -184,7 +185,7 @@ def load_global_config(): global JTAG_ADAPTER global HASHES_DB - cfg = read_global_config(CONFIG_FILE) + cfg = read_global_config(paths.CONFIG_INPUT_DIR / CONFIG_FILE) # validate configuration parameters # check parameter is configured... diff --git a/toolkit/utils/paths.py b/toolkit/utils/paths.py index 2d0aa5c..f798430 100644 --- a/toolkit/utils/paths.py +++ b/toolkit/utils/paths.py @@ -1,7 +1,35 @@ # Global control of input and output paths. -TOOLKIT_DIR = "" -CERT_INPUT_DIR = "" -CONFIG_INPUT_DIR = "" -FIRMWARE_INPUT_DIR = "" -OUTPUT_DIR = "" +import os.path +from pathlib import Path + +TOOLKIT_DIR = None +CERT_INPUT_DIR = None +CONFIG_INPUT_DIR = None +FIRMWARE_INPUT_DIR = None +OUTPUT_DIR = None + + +def configure(config_dir=None, firmware_dir=None, output_dir=None): + global TOOLKIT_DIR + global CERT_INPUT_DIR + global CONFIG_INPUT_DIR + global FIRMWARE_INPUT_DIR + global OUTPUT_DIR + + TOOLKIT_DIR = Path(os.path.dirname(os.path.dirname(__file__))) + CERT_INPUT_DIR = TOOLKIT_DIR / "cert" + + if config_dir is None: + # Use Toolkit directory as the default. + CONFIG_INPUT_DIR = TOOLKIT_DIR / "build/config" + else: + CONFIG_INPUT_DIR = Path(config_dir) + + # If no directory specified, FIRMWARE_INPUT_DIR should not be used. + if firmware_dir is not None: + FIRMWARE_INPUT_DIR = Path(firmware_dir) + + # If no directory specified, OUTPUT_DIR should not be used. + if output_dir is not None: + OUTPUT_DIR = Path(output_dir)