def generate_spm_code(service_files, app_files, output_dir):
    with open(TEMPLATES_DESC, 'r') as fh:
        templates_data = json.load(fh)
        templates_dict = {
            path_join(MBED_OS_ROOT, t['template']):
            path_join(output_dir, t['output'])
            for t in templates_data
        }

    if is_up_to_date(service_files + app_files, list(templates_dict.values())):
        return

    # Construct lists of all the manifests and mmio_regions.
    service_manifests, service_region_list = parse_manifests(service_files)
    test_manifests, test_region_list = parse_manifests(app_files)

    # Validate the correctness of the manifest collection.
    validate_partition_manifests(service_manifests + test_manifests)

    region_list = service_region_list + test_region_list

    render_args = {
        'service_partitions': service_manifests,
        'test_partitions': test_manifests,
        'script_ver': __version__,
        'regions': region_list,
        'region_pair_list': list(itertools.combinations(region_list, 2)),
    }

    generate_source_files(templates_dict, render_args)
Beispiel #2
0
def generate_psa_setup(manifest_files,
                       output_dir,
                       weak_setup,
                       extra_filters=None):
    """
Process all the given manifest files and generate C setup code from them
    :param manifest_files: List of manifest files
    :param output_dir: Output directory for the generated files
    :param weak_setup: Is the functions/data in the setup file weak
            (can be overridden by another setup file)
    :param extra_filters: Dictionary of extra filters to use in the rendering
           process
    :return: path to the setup generated files
    """
    autogen_folder = output_dir
    templates_dict = {
        t: path_join(autogen_folder,
                     os.path.relpath(os.path.splitext(t)[0], TEMPLATES_DIR))
        for t in COMMON_TEMPLATES
    }

    complete_source_list = list(templates_dict.values())

    # Construct lists of all the manifests and mmio_regions.
    region_list = []
    manifests = []
    for manifest_file in manifest_files:
        manifest_obj = Manifest.from_json(manifest_file)
        manifests.append(manifest_obj)
        for region in manifest_obj.mmio_regions:
            region_list.append(region)
        complete_source_list.extend(
            list(
                manifest_obj.templates_to_files(
                    MANIFEST_TEMPLATES, TEMPLATES_DIR,
                    manifest_obj.autogen_folder).values()))

    # Validate the correctness of the manifest collection.
    validate_partition_manifests(manifests)

    render_args = {
        'partitions': manifests,
        'regions': region_list,
        'region_pair_list': list(itertools.combinations(region_list, 2)),
        'weak': weak_setup,
        'script_ver': __version__
    }

    return generate_source_files(templates_dict,
                                 render_args,
                                 autogen_folder,
                                 extra_filters=extra_filters)
def generate_partition_source_files(manifest_files, extra_filters=None):
    """
    Process all the given manifest files and generate C code from them.

    :param manifest_files: List of manifest files
    :param extra_filters: Dictionary of extra filters to use in the rendering
           process
    :return: path to the setup generated files
    """

    # Construct lists of all the manifests and mmio_regions.
    region_list = []
    manifests = []
    for manifest_file in manifest_files:
        manifest_obj = Manifest.from_json(manifest_file, psa_type='TFM')
        manifests.append(manifest_obj)
        for region in manifest_obj.mmio_regions:
            region_list.append(region)

    # Validate the correctness of the manifest collection.
    validate_partition_manifests(manifests)

    render_args = {
        'partitions': manifests,
    }

    # Load templates for the code generation.
    with open(TEMPLATES_LIST_FILE, 'r') as fh:
        templates_data = json.load(fh)

    env = Environment(
        loader=FileSystemLoader(MBED_OS_ROOT),
        lstrip_blocks=True,
        trim_blocks=True,
        undefined=StrictUndefined
    )

    if extra_filters:
        env.filters.update(extra_filters)

    # Generate code for each template
    for tpl in templates_data:
        template = env.get_template(tpl['template'])
        data = template.render(**render_args)
        output_path = os.path.join(MBED_OS_ROOT, tpl['output'])
        output_folder = os.path.dirname(output_path)

        if not os.path.exists(output_folder):
            os.makedirs(output_folder)

        with open(output_path, 'wt') as fh:
            fh.write(data)
def generate_psa_setup(manifest_files,
                       output_dir,
                       weak_setup,
                       extra_filters=None):
    """
Process all the given manifest files and generate C setup code from them
    :param manifest_files: List of manifest files
    :param output_dir: Output directory for the generated files
    :param weak_setup: Is the functions/data in the setup file weak
            (can be overridden by another setup file)
    :param extra_filters: Dictionary of extra filters to use in the rendering
           process
    :return: path to the setup generated files
    """
    with open(MBED_SPM_TEMPLATES_DESC, 'r') as fh:
        template_data = json.load(fh)
        templates_dict = {
            path_join(MBED_OS_ROOT, t['template']):
            path_join(output_dir, t['target'])
            for t in template_data['common']
        }

    # Construct lists of all the manifests and mmio_regions.
    manifests, region_list = parse_manifests(manifest_files, 'MBED_SPM')

    # Validate the correctness of the manifest collection.
    validate_partition_manifests(manifests)

    render_args = {
        'partitions': manifests,
        'regions': region_list,
        'region_pair_list': list(itertools.combinations(region_list, 2)),
        'weak': weak_setup,
        'script_ver': __version__
    }

    return generate_source_files(templates_dict,
                                 render_args,
                                 output_dir,
                                 extra_filters=extra_filters)
def generate_tfm_code(service_files, test_files):
    # Construct lists of all the manifests and mmio_regions.
    service_manifests, service_region_list = parse_manifests(
        service_files, 'TFM')
    test_manifests, test_region_list = parse_manifests(test_files, 'TFM')

    # Validate the correctness of the manifest collection.
    validate_partition_manifests(service_manifests + test_manifests)

    render_args = {
        'service_partitions': service_manifests,
        'test_partitions': test_manifests
    }

    with open(TFM_TEMPLATES_DESC, 'r') as fh:
        templates_data = json.load(fh)
        templates_dict = {
            path_join(MBED_OS_ROOT, t['template']):
            path_join(MBED_OS_ROOT, t['output'])
            for t in templates_data
        }

        generate_source_files(templates_dict, render_args, MBED_OS_ROOT)