|
| 1 | +#!/usr/bin/env python3 |
| 2 | +#------------------------------------------------------------------------------- |
| 3 | +# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors |
| 4 | +# |
| 5 | +# SPDX-License-Identifier: BSD-3-Clause |
| 6 | +# |
| 7 | +#------------------------------------------------------------------------------- |
| 8 | + |
| 9 | +import argparse |
| 10 | +import sys |
| 11 | +import os |
| 12 | + |
| 13 | +import arg_utils |
| 14 | + |
| 15 | +import logging |
| 16 | +logger = logging.getLogger("TF-M.{}".format(__name__)) |
| 17 | + |
| 18 | +sys.path.append(os.path.join(sys.path[0], 'modules')) |
| 19 | + |
| 20 | +import routing_tables as rt |
| 21 | +from routing_tables import Routing_tables |
| 22 | + |
| 23 | +C_SOURCE = """/* |
| 24 | + * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors |
| 25 | + * |
| 26 | + * SPDX-License-Identifier: BSD-3-Clause |
| 27 | + * |
| 28 | + */ |
| 29 | +
|
| 30 | +/* This file is autogenerated - DO NOT EDIT! */ |
| 31 | +
|
| 32 | +#include "rse_routing_tables.h" |
| 33 | +
|
| 34 | +const struct rse_whole_system_routing_tables_t rse_system_routing_tables = |
| 35 | + {}; |
| 36 | +""" |
| 37 | + |
| 38 | +def add_arguments(parser : argparse.ArgumentParser, |
| 39 | + prefix : str = "", |
| 40 | + required : bool = True, |
| 41 | + ) -> None: |
| 42 | + rt.add_arguments(parser, prefix, required=True) |
| 43 | + |
| 44 | +def parse_args(args : argparse.Namespace, |
| 45 | + prefix : str = "", |
| 46 | + ) -> dict: |
| 47 | + out = {} |
| 48 | + |
| 49 | + out |= rt.parse_args(args, prefix=prefix) |
| 50 | + |
| 51 | + return out |
| 52 | + |
| 53 | +script_description = """ |
| 54 | +This script takes in the routing tables configuration and uses it to |
| 55 | +generate a C source file with the system wide routing tables definition |
| 56 | +""" |
| 57 | + |
| 58 | +if __name__ == "__main__": |
| 59 | + parser = argparse.ArgumentParser(allow_abbrev=False, |
| 60 | + formatter_class=argparse.ArgumentDefaultsHelpFormatter, |
| 61 | + description=script_description) |
| 62 | + |
| 63 | + add_arguments(parser) |
| 64 | + |
| 65 | + parser.add_argument("--c_source_output_file", help="File to output the generated source file to", required=True) |
| 66 | + parser.add_argument("--log_level", help="log level", required=False, default="ERROR", choices=logging._levelToName.values()) |
| 67 | + |
| 68 | + args = parser.parse_args() |
| 69 | + logging.getLogger("TF-M").setLevel(args.log_level) |
| 70 | + logger.addHandler(logging.StreamHandler()) |
| 71 | + |
| 72 | + kwargs = parse_args(args) |
| 73 | + |
| 74 | + with open(args.c_source_output_file, "w") as f: |
| 75 | + f.write(C_SOURCE.format(kwargs['routing_tables'].get_routing_tables_source())) |
0 commit comments