tools: Validate client ID range in manifest

Validate the NS Agent Secure Partition client ID range in their manifest
files, during manifest file parse stage.

Although TF-M has implemented client ID range validation in runtime
Secure Partition initialization, it is inconvenient for developers to
debug SPM when TF-M runtime reports validation failures.
Furthermore, the runtime validation can only dump limited information
about the validation failures.

Define 2 client ID range validation functions in a Python file
manifest_client_id_validate.py. It is more flexible to implement those
validation in Python functions than in Jinja2.

partition_load_info.template calls those 2 functions to validate client
ID settings.
 - ns_agent_client_id_validate() validates the client ID range of the NS
   Agent Secure Partition.
 - irq_client_id_validate() validates the client ID range of a IRQ
   source.

Change-Id: Ib792e23093a35b3bfddf5d24288031e69d63379d
Signed-off-by: David Hu <david.hu2@arm.com>
diff --git a/tools/tfm_parse_manifest_list.py b/tools/tfm_parse_manifest_list.py
index 4548ec0..35ba2a79 100644
--- a/tools/tfm_parse_manifest_list.py
+++ b/tools/tfm_parse_manifest_list.py
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2018-2024, Arm Limited. All rights reserved.
+# Copyright (c) 2018-2025, Arm Limited. All rights reserved.
 # Copyright (c) 2022 Cypress Semiconductor Corporation (an Infineon company)
 # or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
 #
@@ -14,6 +14,7 @@
 import argparse
 import logging
 from jinja2 import Environment, BaseLoader, select_autoescape, TemplateNotFound
+from manifest_helpers import manifest_client_id_validate
 
 try:
     import yaml
@@ -764,6 +765,14 @@
 
     return args
 
+def register_helpers():
+    """
+    Register helper functions to enable templates to call those helpers.
+    """
+
+    ENV.globals["manifest_ns_agent_client_id_validate"] = manifest_client_id_validate.ns_agent_client_id_validate
+    ENV.globals["manifest_irq_client_id_validate"] = manifest_client_id_validate.irq_client_id_validate
+
 ENV = Environment(
         loader = TemplateLoader(),
         autoescape = select_autoescape(['html', 'xml']),
@@ -788,6 +797,8 @@
 
     OUT_DIR = os.path.abspath(args.outdir)
 
+    register_helpers()
+
     manifest_lists = [os.path.abspath(x) for x in args.manifest_lists]
     gen_file_lists = [os.path.abspath(x) for x in args.gen_file_args]