def test_generate_cfpa(data_dir): config = json.loads(read_file(data_dir, 'cfpa_test.json')) binary = read_file(data_dir, 'CFPA_test.bin', 'rb') cfpa = CFPA('lpc55xx', user_config=config) data = cfpa.export(add_hash=True, compute_inverses=False) assert binary == data
def test_hash_cmpa(): cfpa = CFPA('lpc55xx') data = cfpa.export(add_hash=False) assert len(data) == 512 assert data[0x1e0:] == bytes(32) data = cfpa.export(add_hash=True) assert len(data) == 512 sha = hexlify(data[0x1e0:]) assert sha == b'4b48f21a4b7a02bfbec19ef880a967a02334a3cdcef8ae83de2ef327ba8bc5dd'
def generate_pfr() -> None: """Generate CFPA data. Alternatively, to generate data you may use the `pfr` commandline utility After generating the data, you can upload them to the device using McuBoot.write_memory !!! Caution !!! Incorrectly configured data may lock the device from further use """ with open(os.path.join(DATA_DIR, "cfpa_test.json")) as config_file: config_data = json.load(config_file) cfpa = CFPA("lpc55xx", user_config=config_data) cfpa_data = cfpa.export() with open(os.path.join(THIS_DIR, "cfpa.bin"), "wb") as binary_file: binary_file.write(cfpa_data)
def test_config_cfpa(): cfpa = CFPA('lpc55xx') config = cfpa.generate_config() config2 = cfpa.generate_config(exclude_computed=False) assert config != config2 cfpa2 = CFPA('lpc55xx', user_config=config2) out = cfpa2.parse(bytes(512), exclude_computed=False) assert out == config2
def test_supported_devices(): cfpa_devices = CFPA.devices() cmpa_devices = CMPA.devices() assert sorted(cmpa_devices) == sorted(cfpa_devices)