Ejemplo n.º 1
0
 def binary_hook(t_self, resources, elf, binf):
     from tools.targets.LPC55S69 import lpc55s69_complete
     configured_secure_image_filename = t_self.target.secure_image_filename
     secure_bin = find_secure_image(t_self.notify, resources, binf,
                                    configured_secure_image_filename,
                                    FileType.BIN)
     lpc55s69_complete(t_self, binf, secure_bin)
Ejemplo n.º 2
0
 def binary_hook(t_self, resources, elf, binf):
     from tools.targets.ARM_MUSCA_B1 import musca_tfm_bin
     configured_secure_image_filename = t_self.target.secure_image_filename
     secure_bin = find_secure_image(t_self.notify, resources, binf,
                                    configured_secure_image_filename,
                                    FileType.BIN)
     musca_tfm_bin(t_self, binf, secure_bin)
Ejemplo n.º 3
0
    def merge_secure(t_self, resources, ns_elf, ns_hex):
        t_self.notify.info("Merging non-secure image with secure image")
        configured_secure_image_filename = t_self.target.secure_image_filename
        t_self.notify.info("Non-secure elf image %s" % ns_elf)
        t_self.notify.info("Non-secure hex image %s" % ns_hex)
        t_self.notify.info("Finding secure image %s" % configured_secure_image_filename)
        s_hex = find_secure_image(
            t_self.notify,
            resources,
            ns_hex,
            configured_secure_image_filename,
            FileType.HEX
        )
        t_self.notify.info("Found secure image %s" % s_hex)

        _, ext = os.path.splitext(s_hex)
        if ext != ".hex":
            t_self.notify.debug("Secure image %s must be in Intel HEX format" % s_hex)
            return
        if not os.path.isfile(s_hex):
            t_self.notify.debug("Secure image %s must be regular file" % s_hex)
            return

        ns_main, ext = os.path.splitext(ns_hex)
        if ext != ".hex":
            t_self.notify.debug("Non-secure image %s must be in Intel HEX format" % s_hex)
            return
        if not os.path.isfile(ns_hex):
            t_self.notify.debug("Non-secure image %s must be regular file" % s_hex)
            return

        # Keep original non-secure before merge with secure
        ns_nosecure_hex = ns_main + "_no-secure-merge" + ext
        t_self.notify.info("Keep no-secure-merge image %s" % ns_nosecure_hex)
        shutil.copy2(ns_hex, ns_nosecure_hex)

        # Merge secure and non-secure and save to non-secure (override it)
        from intelhex import IntelHex
        s_ih = IntelHex()
        s_ih.loadhex(s_hex)
        ns_ih = IntelHex()
        ns_ih.loadhex(ns_hex)
        ns_ih.start_addr = None
        s_ih.merge(ns_ih)
        s_ih.tofile(ns_hex, 'hex')
Ejemplo n.º 4
0
def test_find_secure_image():
    mock_notifier = MockNotifier()
    mock_resources = Resources(mock_notifier)
    ns_image_path = os.path.join('BUILD', 'TARGET_NS', 'app.bin')
    ns_test_path = os.path.join('BUILD', 'TARGET_NS', 'test.bin')
    config_s_image_name = 'target_config.bin'
    default_bin = os.path.join('prebuilt', config_s_image_name)
    test_bin = os.path.join('prebuilt', 'test.bin')

    with pytest.raises(
            Exception,
            match='ns_image_path and configured_s_image_path are mandatory'):
        find_secure_image(mock_notifier, mock_resources, None, None,
                          FileType.BIN)
        find_secure_image(mock_notifier, mock_resources, ns_image_path, None,
                          FileType.BIN)
        find_secure_image(mock_notifier, mock_resources, None,
                          config_s_image_name, FileType.BIN)

    with pytest.raises(Exception,
                       match='image_type must be of type BIN or HEX'):
        find_secure_image(mock_notifier, mock_resources, ns_image_path,
                          config_s_image_name, None)
        find_secure_image(mock_notifier, mock_resources, ns_image_path,
                          config_s_image_name, FileType.C_SRC)

    with pytest.raises(Exception,
                       match='No image files found for this target'):
        find_secure_image(mock_notifier, mock_resources, ns_image_path,
                          config_s_image_name, FileType.BIN)

    dummy_bin = os.path.join('path', 'to', 'dummy.bin')
    mock_resources.add_file_ref(FileType.BIN, dummy_bin, dummy_bin)

    with pytest.raises(Exception, match='Required secure image not found'):
        find_secure_image(mock_notifier, mock_resources, ns_image_path,
                          config_s_image_name, FileType.BIN)

    mock_resources.add_file_ref(FileType.BIN, default_bin, default_bin)
    mock_resources.add_file_ref(FileType.BIN, test_bin, test_bin)
    secure_image = find_secure_image(mock_notifier, mock_resources,
                                     ns_image_path, config_s_image_name,
                                     FileType.BIN)
    assert secure_image == default_bin

    secure_image = find_secure_image(mock_notifier, mock_resources,
                                     ns_test_path, config_s_image_name,
                                     FileType.BIN)
    assert secure_image == test_bin