Skip to content

Commit 5ec3ddb

Browse files
committed
Add -D option; python3 fixes
Also don't MSD-deploy bin files
1 parent df9920a commit 5ec3ddb

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

utils/uf2conv.py

100755100644
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,16 @@ def convert_from_hex_to_uf2(buf):
167167
resfile += blocks[i].encode(i, numblocks)
168168
return resfile
169169

170+
def to_str(b):
171+
return b.decode("utf-8")
172+
170173
def get_drives():
171174
drives = []
172175
if sys.platform == "win32":
173176
r = subprocess.check_output(["wmic", "PATH", "Win32_LogicalDisk",
174177
"get", "DeviceID,", "VolumeName,",
175178
"FileSystem,", "DriveType"])
176-
for line in r.split('\n'):
179+
for line in to_str(r).split('\n'):
177180
words = re.split('\s+', line)
178181
if len(words) >= 3 and words[1] == "2" and words[2] == "FAT":
179182
drives.append(words[0])
@@ -234,6 +237,8 @@ def error(msg):
234237
help='list connected devices')
235238
parser.add_argument('-c' , '--convert', action='store_true',
236239
help='do not flash, just convert')
240+
parser.add_argument('-D' , '--deploy', action='store_true',
241+
help='just flash, do not convert')
237242
parser.add_argument('-f' , '--family', dest='family', type=str,
238243
default="0x0",
239244
help='specify familyID - number or name (default: 0x0)')
@@ -259,7 +264,9 @@ def error(msg):
259264
inpbuf = f.read()
260265
from_uf2 = is_uf2(inpbuf)
261266
ext = "uf2"
262-
if from_uf2:
267+
if args.deploy:
268+
outbuf = inpbuf
269+
elif from_uf2:
263270
outbuf = convert_from_uf2(inpbuf)
264271
ext = "bin"
265272
elif is_hex(inpbuf):
@@ -271,7 +278,7 @@ def error(msg):
271278
outbuf = convert_to_uf2(inpbuf)
272279
print("Converting to %s, output size: %d, start address: 0x%x" %
273280
(ext, len(outbuf), appstartaddr))
274-
if args.convert:
281+
if args.convert or ext != "uf2":
275282
drives = []
276283
if args.output == None:
277284
args.output = "flash." + ext

0 commit comments

Comments
 (0)