fix bad loading of .uf2 files in summarize-gp2040ce
the UF2 file wasn't converted to binary format before searching for the board/user config sections, so it was reading the middle of the UF2 file instead of the end of the binary file and returning that there were no configs Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
parent
90a5f879df
commit
ea4d4be709
|
@ -352,8 +352,7 @@ def summarize_gp2040ce():
|
|||
content, endpoint, _ = get_gp2040ce_from_usb()
|
||||
print(f"USB device {hex(endpoint.device.idVendor)}:{hex(endpoint.device.idProduct)}:\n")
|
||||
else:
|
||||
with open(args.filename, 'rb') as file_:
|
||||
content = file_.read()
|
||||
content = storage.get_binary_from_file(args.filename)
|
||||
print(f"File {args.filename}:\n")
|
||||
|
||||
gp2040ce_version = find_version_string_in_binary(content)
|
||||
|
|
|
@ -202,6 +202,25 @@ def get_config_footer(content: bytes) -> tuple[int, int, str]:
|
|||
return config_size, config_crc, config_magic
|
||||
|
||||
|
||||
def get_binary_from_file(filename: str) -> bytes:
|
||||
"""Read the specified file (.bin or .uf2) and get back its raw binary contents.
|
||||
|
||||
Args:
|
||||
filename: the filename of the file to open and read
|
||||
Returns:
|
||||
the file's content, in raw binary format
|
||||
Raises:
|
||||
FileNotFoundError: if the file was not found
|
||||
"""
|
||||
with open(filename, 'rb') as dump:
|
||||
if filename[-4:] == '.uf2':
|
||||
content = bytes(convert_uf2_to_binary(bytearray(dump.read())))
|
||||
else:
|
||||
content = dump.read()
|
||||
|
||||
return content
|
||||
|
||||
|
||||
def get_config_from_file(filename: str, whole_board: bool = False, allow_no_file: bool = False,
|
||||
board_config: bool = False) -> Message:
|
||||
"""Read the specified file (memory dump or whole board dump) and get back its config section.
|
||||
|
@ -215,11 +234,7 @@ def get_config_from_file(filename: str, whole_board: bool = False, allow_no_file
|
|||
the parsed configuration
|
||||
"""
|
||||
try:
|
||||
with open(filename, 'rb') as dump:
|
||||
if filename[-4:] == '.uf2':
|
||||
content = bytes(convert_uf2_to_binary(bytearray(dump.read())))
|
||||
else:
|
||||
content = dump.read()
|
||||
content = get_binary_from_file(filename)
|
||||
except FileNotFoundError:
|
||||
if not allow_no_file:
|
||||
raise
|
||||
|
|
Loading…
Reference in New Issue