optionally dump config to a .uf2 file

this allows for creating a UF2 that writes the user config to the whole
user config section of flash, allowing for easy copying/juggling of
configurations by just maintaining a library of .uf2 files you like to
apply

Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
Brian S. Stephan 2024-03-25 10:00:54 -05:00
parent a3f9f12e74
commit 449812f1df
Signed by: bss
GPG Key ID: 3DE06D3180895FCB
1 changed files with 11 additions and 4 deletions

View File

@ -319,16 +319,23 @@ def serialize_config_with_footer(config: Message) -> bytearray:
def dump_config():
"""Save the GP2040-CE's configuration to a binary file."""
"""Save the GP2040-CE's user configuration to a binary or UF2 file."""
parser = argparse.ArgumentParser(
description="Read the configuration section from a USB device and save it to a binary file.",
parents=[core_parser],
)
parser.add_argument('binary_filename', help=".bin file to save the GP2040-CE board's config section to")
parser.add_argument('filename', help="file to save the GP2040-CE board's config section to --- if the "
"suffix is .uf2, it is saved in UF2 format, else it is a raw binary")
args, _ = parser.parse_known_args()
config, _, _ = get_user_config_from_usb()
with open(args.binary_filename, 'wb') as out_file:
out_file.write(serialize_config_with_footer(config))
binary_config = serialize_config_with_footer(config)
with open(args.filename, 'wb') as out_file:
if args.filename[-4:] == '.uf2':
# we must pad to storage start in order for the UF2 write addresses to make sense
out_file.write(convert_binary_to_uf2(pad_config_to_storage_size(binary_config),
start=USER_CONFIG_BINARY_LOCATION))
else:
out_file.write(binary_config)
def visualize():