Skip to content

Commit f4d3a2c

Browse files
committed
toolkit: Support a custom global-cfg.db.
Signed-off-by: Damien George <[email protected]>
1 parent 46347f9 commit f4d3a2c

File tree

5 files changed

+51
-15
lines changed

5 files changed

+51
-15
lines changed

toolkit/app-gen-toc.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ def main():
687687
parser.add_argument(
688688
"--config-dir",
689689
type=str,
690-
default=Path(os.path.dirname(__file__)) / "build/config",
690+
default=None,
691691
help="directory with configuration files",
692692
)
693693
parser.add_argument(
@@ -706,11 +706,7 @@ def main():
706706
args = parser.parse_args()
707707

708708
# Set paths given on command line.
709-
paths.TOOLKIT_DIR = Path(os.path.dirname(__file__))
710-
paths.CERT_INPUT_DIR = paths.TOOLKIT_DIR / "cert"
711-
paths.CONFIG_INPUT_DIR = Path(args.config_dir)
712-
paths.FIRMWARE_INPUT_DIR = Path(args.firmware_dir)
713-
paths.OUTPUT_DIR = Path(args.output_dir)
709+
paths.configure(args.config_dir, args.firmware_dir, args.output_dir)
714710

715711
if args.version:
716712
print(TOOL_VERSION)

toolkit/app-write-mram.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from isp.serialport import serialPort
2424
from isp.serialport import COM_BAUD_RATE_MAXIMUM
2525
from utils.toc_common import globalToLocalAddress
26+
from utils import paths
2627

2728
# import ispcommands
2829
from isp.isp_core import (
@@ -195,8 +196,18 @@ def main():
195196
"-V", "--version", help="Display Version Number", action="store_true"
196197
)
197198
parser.add_argument("-v", "--verbose", help="verbosity mode", action="store_true")
199+
parser.add_argument(
200+
"--config-dir",
201+
type=str,
202+
default=None,
203+
help="directory with configuration files",
204+
)
198205

199206
args = parser.parse_args()
207+
208+
# Set paths given on command line.
209+
paths.configure(args.config_dir)
210+
200211
if args.version:
201212
print(TOOL_VERSION)
202213
sys.exit()
File renamed without changes.

toolkit/utils/config.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
import sys
33
import json
44
from json.decoder import JSONDecodeError
5+
from utils import paths
56

67
# Define Version constant for each separate tool
78
# 0.06.000 added package and offset params
89
TOOL_VERSION = "0.07.000"
910

1011
# DB files
1112
config_file_dir = os.path.dirname(__file__)
12-
CONFIG_FILE = os.path.join(config_file_dir, "global-cfg.db")
13+
CONFIG_FILE = "global-cfg.db"
1314
DEVICE_DB_FILE = os.path.join(config_file_dir, "devicesDB.db")
1415
FEATURES_DB_FILE = os.path.join(config_file_dir, "featuresDB.db")
1516
HASHES_DB_FILE = os.path.join(config_file_dir, "hashesDB.db")
@@ -80,10 +81,10 @@ def read_global_config(file):
8081

8182

8283
def save_global_config(devDescription, devRevision):
83-
with open(CONFIG_FILE, "r", encoding="utf-8") as f:
84+
with open(paths.CONFIG_INPUT_DIR / CONFIG_FILE, "r", encoding="utf-8") as f:
8485
cfg = json.load(f)
8586

86-
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
87+
with open(paths.CONFIG_INPUT_DIR / CONFIG_FILE, "w", encoding="utf-8") as f:
8788
cfg["DEVICE"]["Part#"] = devDescription
8889
cfg["DEVICE"]["Revision"] = devRevision
8990
json.dump(cfg, f, ensure_ascii=False, indent=4)
@@ -184,7 +185,7 @@ def load_global_config():
184185
global JTAG_ADAPTER
185186
global HASHES_DB
186187

187-
cfg = read_global_config(CONFIG_FILE)
188+
cfg = read_global_config(paths.CONFIG_INPUT_DIR / CONFIG_FILE)
188189

189190
# validate configuration parameters
190191
# check parameter is configured...

toolkit/utils/paths.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
11
# Global control of input and output paths.
22

3-
TOOLKIT_DIR = ""
4-
CERT_INPUT_DIR = ""
5-
CONFIG_INPUT_DIR = ""
6-
FIRMWARE_INPUT_DIR = ""
7-
OUTPUT_DIR = ""
3+
import os.path
4+
from pathlib import Path
5+
6+
TOOLKIT_DIR = None
7+
CERT_INPUT_DIR = None
8+
CONFIG_INPUT_DIR = None
9+
FIRMWARE_INPUT_DIR = None
10+
OUTPUT_DIR = None
11+
12+
13+
def configure(config_dir=None, firmware_dir=None, output_dir=None):
14+
global TOOLKIT_DIR
15+
global CERT_INPUT_DIR
16+
global CONFIG_INPUT_DIR
17+
global FIRMWARE_INPUT_DIR
18+
global OUTPUT_DIR
19+
20+
TOOLKIT_DIR = Path(os.path.dirname(os.path.dirname(__file__)))
21+
CERT_INPUT_DIR = TOOLKIT_DIR / "cert"
22+
23+
if config_dir is None:
24+
# Use Toolkit directory as the default.
25+
CONFIG_INPUT_DIR = TOOLKIT_DIR / "build/config"
26+
else:
27+
CONFIG_INPUT_DIR = Path(config_dir)
28+
29+
# If no directory specified, FIRMWARE_INPUT_DIR should not be used.
30+
if firmware_dir is not None:
31+
FIRMWARE_INPUT_DIR = Path(firmware_dir)
32+
33+
# If no directory specified, OUTPUT_DIR should not be used.
34+
if output_dir is not None:
35+
OUTPUT_DIR = Path(output_dir)

0 commit comments

Comments
 (0)