kopia lustrzana https://github.com/micropython/micropython
Merge 296a774e72
into 49ce7a6075
commit
65143f1918
|
@ -422,6 +422,20 @@ def read_dfu_file(filename):
|
||||||
return elements
|
return elements
|
||||||
|
|
||||||
|
|
||||||
|
def read_bin_file(filename, address):
|
||||||
|
"""Reads binary file(.bin) and stores it as single
|
||||||
|
element in element array just like read_dfu_file() would.
|
||||||
|
"""
|
||||||
|
element = {}
|
||||||
|
print("File: {}".format(filename))
|
||||||
|
with open(filename, "rb") as fin:
|
||||||
|
element["data"] = fin.read()
|
||||||
|
element["size"] = len(element["data"])
|
||||||
|
element["num"] = 0
|
||||||
|
element["addr"] = address
|
||||||
|
return [element]
|
||||||
|
|
||||||
|
|
||||||
class FilterDFU(object):
|
class FilterDFU(object):
|
||||||
"""Class for filtering USB devices to identify devices which are in DFU
|
"""Class for filtering USB devices to identify devices which are in DFU
|
||||||
mode.
|
mode.
|
||||||
|
@ -573,6 +587,13 @@ def main():
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-u", "--upload", help="read file from DFU device", dest="path", default=False
|
"-u", "--upload", help="read file from DFU device", dest="path", default=False
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-a",
|
||||||
|
"--address",
|
||||||
|
help="specify target memory address(hex or dec) when uploading .bin files",
|
||||||
|
dest="address",
|
||||||
|
default=False,
|
||||||
|
)
|
||||||
parser.add_argument("-x", "--exit", help="Exit DFU", action="store_true", default=False)
|
parser.add_argument("-x", "--exit", help="Exit DFU", action="store_true", default=False)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-v", "--verbose", help="increase output verbosity", action="store_true", default=False
|
"-v", "--verbose", help="increase output verbosity", action="store_true", default=False
|
||||||
|
@ -601,7 +622,18 @@ def main():
|
||||||
command_run = True
|
command_run = True
|
||||||
|
|
||||||
if args.path:
|
if args.path:
|
||||||
elements = read_dfu_file(args.path)
|
if str(args.path).endswith(".bin"):
|
||||||
|
if not args.address:
|
||||||
|
raise ValueError("Address must be specified using -a when uploading binary")
|
||||||
|
addr = str(args.address)
|
||||||
|
if addr.startswith("0x") or addr.startswith("0X"):
|
||||||
|
addr = int(addr, 16)
|
||||||
|
else:
|
||||||
|
addr = int(addr)
|
||||||
|
elements = read_bin_file(args.path, addr)
|
||||||
|
else:
|
||||||
|
elements = read_dfu_file(args.path)
|
||||||
|
|
||||||
if not elements:
|
if not elements:
|
||||||
print("No data in dfu file")
|
print("No data in dfu file")
|
||||||
return
|
return
|
||||||
|
|
Ładowanie…
Reference in New Issue