Example #1
0
def generate_partitions_sources(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: List of paths to the generated files
    """

    # Construct a list of all the manifests and sids.
    manifests = []
    for manifest_file in manifest_files:
        manifest = Manifest.from_json(manifest_file)
        manifests.append(manifest)

    generated_folders = set()
    for manifest in manifests:
        manifest_output_folder = manifest.autogen_folder

        render_args = {
            'partition': manifest,
            'dependent_partitions': manifest.find_dependencies(manifests),
            'script_ver': __version__
        }
        manifest_output_folder = generate_source_files(
            manifest.templates_to_files(MANIFEST_TEMPLATES, TEMPLATES_DIR,
                                        manifest_output_folder),
            render_args,
            manifest_output_folder,
            extra_filters=extra_filters)
        generated_folders.add(manifest_output_folder)

    return list(generated_folders)
Example #2
0
def parse_manifests(manifests_files):
    region_list = []
    manifests = []
    for manifest_file in manifests_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)

    return manifests, region_list
Example #3
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)