Exemple #1
0
def test_generate_cfpa(data_dir):
    config = json.loads(load_file(data_dir, 'cfpa_test.json'))
    binary = load_file(data_dir, 'CFPA_test.bin', mode='rb')

    cfpa = CFPA('lpc55s6x', user_config=config['settings'])
    data = cfpa.export(add_seal=True, compute_inverses=False)
    assert binary == data
Exemple #2
0
def test_lpc55s3x_load_yml_without_change(data_dir):
    """Test silicon LPC55S3x mandatory computing of antipole values."""
    cfpa = CFPA(user_config=PfrConfiguration(f"{data_dir}/cfpa_no_change.yml"))
    data = cfpa.export()

    assert len(data) == 512
    with open(data_dir + "/lpc55s3x_CFPA_basic.bin", "rb") as binary:
        assert data == binary.read()
Exemple #3
0
def test_seal_cmpa_n4analog():
    cfpa = CFPA('lpc55s3x')

    data = cfpa.export(add_seal=False)
    assert len(data) == 512
    assert data[0x1e0:] == bytes(32)

    data = cfpa.export(add_seal=True)
    assert len(data) == 512
    assert data[0x1ec:0x1f0] == CFPA.MARK
Exemple #4
0
def test_seal_cfpa():
    cfpa = CFPA('lpc55s6x')

    data = cfpa.export(add_seal=False)
    assert len(data) == 512
    assert data[0x1e0:] == bytes(32)

    data = cfpa.export(add_seal=True)
    assert len(data) == 512
    assert data[0x1e0:] == CFPA.MARK * 8
Exemple #5
0
def test_seal_cmpa_lpc55s3x():
    """Test PFR tool - Test CMPA seal on LPC55S3x."""
    cfpa = CFPA("lpc55s3x")

    data = cfpa.export(add_seal=False)
    assert len(data) == 512
    assert data[0x1E0:] == bytes(32)

    data = cfpa.export(add_seal=True)
    assert len(data) == 512
    assert data[0x1EC:0x1F0] == CFPA.MARK
Exemple #6
0
def test_seal_cfpa():
    """Test PFR tool - Test CFPA seal."""
    cfpa = CFPA("lpc55s6x")

    data = cfpa.export(add_seal=False)
    assert len(data) == 512
    assert data[0x1E0:] == bytes(32)

    data = cfpa.export(add_seal=True)
    assert len(data) == 512
    assert data[0x1E0:] == CFPA.MARK * 8
Exemple #7
0
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)
Exemple #8
0
def test_config_cfpa():
    cfpa = CFPA('lpc55s6x')
    config = cfpa.generate_config()
    config2 = cfpa.generate_config(exclude_computed=False)

    assert config != config2

    cfpa2 = CFPA('lpc55s6x', user_config=config2)
    out = cfpa2.parse(bytes(512), exclude_computed=False)

    assert out == config2
Exemple #9
0
def test_generate_cfpa(data_dir):
    """Test PFR tool - Generating CFPA binary."""
    binary = load_file(data_dir, "CFPA_test.bin", mode="rb")

    pfr_cfg_json = PfrConfiguration(os.path.join(data_dir, "cfpa_test.json"))
    cfpa_json = CFPA("lpc55s6x", user_config=pfr_cfg_json)
    assert cfpa_json.export(add_seal=True) == binary

    pfr_cfg_yml = PfrConfiguration(os.path.join(data_dir, "cfpa_test.yml"))
    cfpa_yml = CFPA("lpc55s6x", user_config=pfr_cfg_yml)
    assert cfpa_yml.export(add_seal=True) == binary
Exemple #10
0
def test_supported_devices():
    cfpa_devices = CFPA.devices()
    cmpa_devices = CMPA.devices()

    assert sorted(cmpa_devices) == sorted(cfpa_devices)
Exemple #11
0
def test_supported_devices():
    """Test PFR tool - Getting supported devices."""
    cfpa_devices = CFPA.devices()
    cmpa_devices = CMPA.devices()
    assert sorted(cmpa_devices) == sorted(cfpa_devices)
Exemple #12
0
def test_missing_rotkh():
    """Simple test to check right functionality of missing ROTKH."""
    cfpa = CFPA("lpc55s6x")
    with pytest.raises(SPSDKPfrRotkhIsNotPresent):
        cfpa.export(keys=["Invalid"])
Exemple #13
0
def test_config_cfpa(data_dir):
    """Test PFR tool - Test CFPA configuration."""
    cfpa = CFPA("lpc55s6x")
    config = cfpa.generate_config()
    config2 = cfpa.generate_config(exclude_computed=False)

    assert config != config2

    cfpa2 = CFPA("lpc55s6x", user_config=PfrConfiguration(config2))
    cfpa2.parse(bytes(512))  # Parse 512-bytes of empty CFPA page content
    cfpa2_pfr_cfg = PfrConfiguration(
        data_dir +
        "/cfpa_after_reset.yml")  # Apply known CFPA fields after reset values
    cfpa2.set_config(cfpa2_pfr_cfg)
    out = cfpa2.get_yaml_config(exclude_computed=False)

    assert out == config2