mardyk01 | 817d860 | 2024-01-17 16:02:49 -0600 | [diff] [blame^] | 1 | # !/usr/bin/env python |
| 2 | # |
| 3 | # Copyright (c) 2024, Arm Limited. All rights reserved. |
| 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | |
| 8 | # Script to generate the header file compiled into fuzzer for creating |
| 9 | # the various enum values used to identify the specific fuzzer function called. |
| 10 | # This is intended to replace the orignal string output of the fuzzer. |
| 11 | # There are two arguments... one to specify the device tree file input to the fuzzer |
| 12 | # and the other to give the name and path of the header file. |
| 13 | |
| 14 | import re |
| 15 | import argparse |
| 16 | |
| 17 | parser = argparse.ArgumentParser( |
| 18 | prog='gen_smc_fuzz_setup', |
| 19 | description='Creates a header file to assign enum values to fuzzing function names', |
| 20 | epilog='Two argument input') |
| 21 | |
| 22 | parser.add_argument('-dts', '--devtree',help="Device tree file to analyze .") |
| 23 | parser.add_argument('-hdf', '--headfile',help="Header file to create .") |
| 24 | |
| 25 | args = parser.parse_args() |
| 26 | |
| 27 | addresses = {} |
| 28 | numl = 1 |
| 29 | dt_file = open(args.devtree, "r") |
| 30 | hdr_file = open(args.headfile, "w") |
| 31 | dt_lines = dt_file.readlines() |
| 32 | dt_file.close() |
| 33 | for line in dt_lines: |
| 34 | if "functionname" in line: |
| 35 | grp = re.search(r'functionname\s*=\s*\"(\w+)\"',line) |
| 36 | fnme = grp.group(1) |
| 37 | if fnme not in addresses: |
| 38 | addresses[fnme] = 1; |
| 39 | print("#define", fnme, numl,file=hdr_file) |
| 40 | numl = numl + 1 |
| 41 | hdr_file.close() |