psa_autogen.py: improve management of output files

While at this, fix also Makefile so that "make clean" does not
complain if some of the files to be cancelled do not exist.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
Valerio Setti 2024-05-15 07:29:51 +02:00
parent 87d99fbd6c
commit 1f3c99c774
2 changed files with 38 additions and 31 deletions

View File

@ -58,6 +58,5 @@ clean:
rm -rf libpsaclient libpsaserver rm -rf libpsaclient libpsaserver
rm -rf include/psa_manifest rm -rf include/psa_manifest
rm -f test/psa_service_* test/psa_notify_* rm -f test/psa_service_* test/psa_notify_*
rm -r test/*.log rm -f test/*.log
rm test/seedfile rm -f test/seedfile

View File

@ -19,6 +19,10 @@ SCRIPT_PATH = os.path.dirname(__file__)
GENERATED_H_PATH = os.path.join(SCRIPT_PATH, "..", "include", "psa_manifest") GENERATED_H_PATH = os.path.join(SCRIPT_PATH, "..", "include", "psa_manifest")
GENERATED_C_PATH = os.path.join(SCRIPT_PATH, "..", "src") GENERATED_C_PATH = os.path.join(SCRIPT_PATH, "..", "src")
MANIFEST_FILE = os.path.join(GENERATED_H_PATH, "manifest.h")
PID_FILE = os.path.join(GENERATED_H_PATH, "pid.h")
SID_FILE = os.path.join(GENERATED_H_PATH, "sid.h")
with open(str(FILENAME), "r") as read_file: with open(str(FILENAME), "r") as read_file:
data = json.load(read_file) data = json.load(read_file)
FILENAME = os.path.basename(FILENAME) FILENAME = os.path.basename(FILENAME)
@ -38,11 +42,11 @@ with open(str(FILENAME), "r") as read_file:
os.mkdir(GENERATED_H_PATH) os.mkdir(GENERATED_H_PATH)
print("Generating psa_manifest directory") print("Generating psa_manifest directory")
except OSError: except OSError:
print ("PSA manifest directory already exists") print("PSA manifest directory already exists")
man = open(os.path.join(GENERATED_H_PATH, FILENAME + ".h"), "w") manifest_content = []
pids = open(os.path.join(GENERATED_H_PATH, "pid.h"), "a") pids_content = []
sids = open(os.path.join(GENERATED_H_PATH, "sid.h"), "a") sids_content = []
if len(services) > 28: if len(services) > 28:
print ("Unsupported number of services") print ("Unsupported number of services")
@ -63,8 +67,8 @@ with open(str(FILENAME), "r") as read_file:
# Go through all the services to make sid.h and pid.h # Go through all the services to make sid.h and pid.h
for svc in services: for svc in services:
man.write("#define {}_SIGNAL 0x{:08x}\n".format(svc['signal'], 2**count)) manifest_content.append("#define {}_SIGNAL 0x{:08x}".format(svc['signal'], 2**count))
sids.write("#define {}_SID {}\n".format(svc['name'], svc['sid'])) sids_content.append("#define {}_SID {}".format(svc['name'], svc['sid']))
qcode = qcode + "\"" + queue_path + str(int(svc['sid'], 16)) + "\"," qcode = qcode + "\"" + queue_path + str(int(svc['sid'], 16)) + "\","
ns_clients = svc['non_secure_clients'] ns_clients = svc['non_secure_clients']
print(str(svc)) print(str(svc))
@ -94,7 +98,7 @@ with open(str(FILENAME), "r") as read_file:
handlercode = "void __sig_handler(int signo) {\n" handlercode = "void __sig_handler(int signo) {\n"
irqcount = count irqcount = count
for irq in irqs: for irq in irqs:
man.write("#define {} 0x{:08x}\n".format(irq['signal'], 2**irqcount)) manifest_content.append("#define {} 0x{:08x}".format(irq['signal'], 2**irqcount))
sigcode = sigcode + " signal({}, __sig_handler);\n".format(irq['source']) sigcode = sigcode + " signal({}, __sig_handler);\n".format(irq['source'])
handlercode = handlercode + \ handlercode = handlercode + \
" if (signo == {}) {{ raise_signal(0x{:08x}); }};\n".format(irq['source'], 2**irqcount) " if (signo == {}) {{ raise_signal(0x{:08x}); }};\n".format(irq['source'], 2**irqcount)
@ -114,9 +118,12 @@ with open(str(FILENAME), "r") as read_file:
versions = versions + "};\n" versions = versions + "};\n"
policy = policy + "};\n" policy = policy + "};\n"
pids.close() with open(MANIFEST_FILE, "wt") as output:
sids.close() output.write("\n".join(manifest_content))
man.close() with open(SID_FILE, "wt") as output:
output.write("\n".join(sids_content))
with open(PID_FILE, "wt") as output:
output.write("\n".join(pids_content))
symbols = [] symbols = []
@ -144,23 +151,24 @@ with open(str(FILENAME), "r") as read_file:
print("Duplicate entrypoint symbol detected: " + str(symbols)) print("Duplicate entrypoint symbol detected: " + str(symbols))
sys.exit(2) sys.exit(2)
else: else:
bs = open(os.path.join(GENERATED_C_PATH, "psa_ff_bootstrap_" + partition_name + ".c"), C_FILENAME = os.path.join(GENERATED_C_PATH, "psa_ff_bootstrap_" + partition_name + ".c")
"w") c_content = []
bs.write("#include <init.h>\n") c_content.append("#include <init.h>")
bs.write("#include \"" + symbols[0] + "\"\n") c_content.append("#include \"" + symbols[0] + "\"")
bs.write("#include <signal.h>\n\n") c_content.append("#include <signal.h>")
bs.write(qcode) c_content.append(qcode)
bs.write(nsacl) c_content.append(nsacl)
bs.write(policy) c_content.append(policy)
bs.write(versions) c_content.append(versions)
bs.write("\n") c_content.append(handlercode)
bs.write(handlercode) c_content.append("int main(int argc, char *argv[]) {")
bs.write("\n") c_content.append(" (void) argc;")
bs.write("int main(int argc, char *argv[]) {\n") c_content.append(sigcode)
bs.write(" (void) argc;\n") c_content.append(" __init_psasim(psa_queues, 32, ns_allowed, versions,"
bs.write(sigcode) "strict_policy);")
bs.write(" __init_psasim(psa_queues, 32, ns_allowed, versions, strict_policy);\n") c_content.append(" " + entry_point + "(argc, argv);")
bs.write(" " + entry_point + "(argc, argv);\n}\n") c_content.append("}")
bs.close() with open(C_FILENAME, "wt") as output:
output.write("\n".join(c_content))
print("Success") print("Success")