Skip to content

Commit 8e81a8b

Browse files
committed
Enhance CLI argument handling for parallel flashing by allowing multiple programmer serial numbers
1 parent 9bc4f94 commit 8e81a8b

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/bmlab_toolkit/flashing.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ def main():
4949
parser.add_argument(
5050
"--serial", "-s",
5151
type=int,
52+
nargs='+',
5253
default=None,
53-
help="Programmer serial number (optional, will use first available if not specified)"
54+
help="Programmer serial number(s) (can specify multiple for parallel flashing, or leave empty for auto-detect)"
5455
)
5556

5657
parser.add_argument(
@@ -90,23 +91,24 @@ def main():
9091
if args.serial and args.ip:
9192
print("Error: Cannot specify both --serial and --ip")
9293
sys.exit(1)
93-
94+
9495
# Check firmware file exists
9596
fw_file = os.path.abspath(args.firmware_file)
9697
if not os.path.exists(fw_file):
9798
print(f"Error: Firmware file not found: {fw_file}")
9899
print(f"To list connected devices, run: bmlab-scan")
99100
sys.exit(1)
100-
101+
101102
try:
102103
# Convert log level string to logging constant
103104
log_level = getattr(logging, args.log_level.upper())
104-
105-
# Handle IP addresses (convert to list for uniform processing)
105+
106+
# Handle IP addresses and serials (convert to list for uniform processing)
106107
ip_list = args.ip if args.ip else None
107-
108-
flash_devices(args.serial, ip_list, fw_file, args.mcu, args.programmer, log_level)
109-
108+
serial_list = args.serial if args.serial else None
109+
110+
flash_devices(serial_list, ip_list, fw_file, args.mcu, args.programmer, log_level)
111+
110112
except Exception as e:
111113
print(f"Error: {e}")
112114
sys.exit(1)
@@ -141,6 +143,8 @@ def flash_devices(serial, ip_list, fw_file, mcu, programmer_type, log_level):
141143
devices = []
142144
if ip_list:
143145
devices = [{'serial': None, 'ip': ip} for ip in ip_list]
146+
elif serial and isinstance(serial, list):
147+
devices = [{'serial': s, 'ip': None} for s in serial]
144148
else:
145149
devices = [{'serial': serial, 'ip': None}]
146150

0 commit comments

Comments
 (0)