blob: d5afe0a5d13487d5e53093bf3aa66eb2e9dc3b09 [file] [log] [blame]
Raef Coles8cbeed52024-03-11 16:24:57 +00001#!/usr/bin/python3
2# -----------------------------------------------------------------------------
Jackson Cooper-Driver2d736062025-03-05 12:37:09 +00003# Copyright (c) 2024-2025, Arm Limited. All rights reserved.
Raef Coles8cbeed52024-03-11 16:24:57 +00004#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7# -----------------------------------------------------------------------------
8
9import argparse
10import logging
11import json
12from os import listdir
13from os.path import join, isfile, relpath
14import subprocess
15
16class Source:
17 def __init__(self, location : str):
18 self.type = "git"
19 self.location = location
20 self.refspec = ""
21
22 with open(join(location, ".git", "config"), "rt") as git_config_file:
23 url_line = [x for x in git_config_file.readlines() if "url" in x][0]
24 self.url = url_line.rstrip().replace("\turl = ", "").rstrip()
25
26 with open(join(location, ".git", "HEAD"), "rt") as git_HEAD_file:
27 self.commit = git_HEAD_file.read().rstrip()
28
29 self.location = relpath(location, args.source_dir)
30
31def get_tfm_dependencies(build_dir : str) -> [Source]:
32 dependencies = []
33
34 with open(join(build_dir, "CMakeCache.txt"), "rt") as cmakecache_file:
35 cmakecache = cmakecache_file.readlines()
36 variables = [x.rstrip().split("=") for x in cmakecache if "=" in x]
37 path_variables = [x for x in variables if "PATH" in x[0]]
38
39 for _,p in path_variables:
40 try:
41 dependencies.append(Source(p))
42 except (FileNotFoundError, NotADirectoryError):
43 continue
44
45 return dependencies
46
47parser = argparse.ArgumentParser()
48parser.add_argument("--build_dir", help="TF-M build directory", required=True)
49parser.add_argument("--source_dir", help="TF-M source directory", required=True)
50parser.add_argument("--tools_binary_dir", help="Binary dir in which objdump etc reside", required=False)
51parser.add_argument("--log_level", help="Log level", choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], default="ERROR")
52parser.add_argument("--output_config_file", help="output JSON file", required=True)
53parser.add_argument("--output_intermediate_file", help="output intermediate file", required=True)
54parser.add_argument("trace_file", nargs="+", help="input trace log files")
Jackson Cooper-Driver2d736062025-03-05 12:37:09 +000055parser.add_argument("--filter_elfs", help="comma-separated list of ELF files to generate report for", required=False)
Raef Coles8cbeed52024-03-11 16:24:57 +000056args = parser.parse_args()
57
58# logging setup
59logging.basicConfig(level=args.log_level)
60
61configuration = {
62 "remove_workspace": True,
63 "include_assembly": True,
64}
65
66if (args.tools_binary_dir):
67 tools_prefix = args.tools_binary_dir
68else:
69 tools_prefix = ""
70
71tfm_source = Source(args.source_dir)
72dependencies = get_tfm_dependencies(args.build_dir)
73
74parameters = {
75 "objdump" : join(tools_prefix, "arm-none-eabi-objdump"),
76 "readelf" : join(tools_prefix, "arm-none-eabi-readelf"),
77 "sources" : [
78 {
79 "type" : x.type,
80 "URL": x.url,
81 "COMMIT" : x.commit,
82 "REFSPEC" : x.refspec,
83 "LOCATION" : x.location,
84 } for x in [tfm_source] + dependencies],
85 "workspace": args.source_dir,
86 "output_file": args.output_intermediate_file,
87}
88
89bin_dir = join(args.build_dir, "bin")
90elf_files = [join(bin_dir, x) for x in listdir(bin_dir) if isfile(join(bin_dir, x)) and "elf" in x]
91
Jackson Cooper-Driver2d736062025-03-05 12:37:09 +000092if args.filter_elfs:
93 elf_files = [x for x in elf_files for f in args.filter_elfs.split(",") if f in x]
94
Raef Coles8cbeed52024-03-11 16:24:57 +000095elfs = [
96 {
97 "name": x,
98 "traces": args.trace_file,
99 } for x in elf_files]
100
101output = {
102 "configuration": configuration,
103 "parameters": parameters,
104 "elfs": elfs,
105}
106
107with open(args.output_config_file, "w+") as output_file:
108 json.dump(output, output_file)