def write_key_store(ctx: click.Context, file_and_size: str) -> None: """Send the key store to bootloader.. \b FILE - Binary file containing key store. SIZE - If not specified, the entire <file> will be sent. Otherwise, only send the first <size> bytes. """ file_path, size = parse_file_and_size(file_and_size) with open(file_path, 'rb') as key_file: key_data = key_file.read(size) with McuBoot(ctx.obj['interface']) as mboot: response = mboot.kp_write_key_store(key_data) display_output([], mboot.status_code, ctx.obj['use_json'])
def set_user_key(ctx: click.Context, key_type: int, file_and_size: str) -> None: """Send the user key specified by <type> to bootloader. \b TYPE - Type of user key FILE - Binary file containing user key plaintext SIZE - If not specified, the entire <file> will be sent. Otherwise, only send the first <size> bytes. The valid options of <type> and corresponding <size> are documented in the target's Reference Manual or User Manual. """ file_path, size = parse_file_and_size(file_and_size) with open(file_path, 'rb') as key_file: key_data = key_file.read(size) with McuBoot(ctx.obj['interface']) as mboot: response = mboot.kp_set_user_key(key_type=key_type, key_data=key_data) # type: ignore display_output([], mboot.status_code, ctx.obj['use_json'])
def write_memory(ctx: click.Context, address: int, data_source: str, memory_id: int) -> None: """Write memory. \b ADDRESS - starting address FILE - write content of this file BYTE_COUNT - if specified, load only first BYTE_COUNT number of bytes from file HEX-DATA - string of hex values: {{112233}}, {{11 22 33}} MEMORY_ID - id of memory to read from (default: 0) """ try: data = parse_hex_data(data_source) except SPSDKError: file_path, size = parse_file_and_size(data_source) with open(file_path, 'rb') as f: data = f.read(size) with McuBoot(ctx.obj['interface']) as mboot: response = mboot.write_memory(address, data, memory_id) display_output([len(data)] if response else None, mboot.status_code, ctx.obj['use_json'])
def test_file_size_composite(input_param, exp_path, exp_size): path, size = utils.parse_file_and_size(input_param) assert path == exp_path assert size == exp_size