feat(sptool): populate secure partition number in makefile

Calculate the secure partition number and saves it into the defined
macro NUM_SP.

Signed-off-by: Ben Horgan <ben.horgan@arm.com>
Signed-off-by: Leo Yan <leo.yan@arm.com>
Change-Id: I4175a10d315482b65fd0f3eed4c6fd1e1e2b5e4d
diff --git a/tools/sptool/sp_mk_generator.py b/tools/sptool/sp_mk_generator.py
index 1edb77d..9bf5cd0 100644
--- a/tools/sptool/sp_mk_generator.py
+++ b/tools/sptool/sp_mk_generator.py
@@ -30,6 +30,9 @@
     FIP_ARGS += --blob uuid=XXXXX-XXX...,file=sp1.pkg
     CRT_ARGS += --sp-pkg1 sp1.pkg
 
+It populates the number of SP in the defined macro 'NUM_SP'
+    $(eval $(call add_define_val,NUM_SP,{len(sp_layout.keys())}))
+
 A typical SP_LAYOUT_FILE file will look like
 {
         "SP1" : {
@@ -151,6 +154,12 @@
         raise Exception(f"Too many SPs in SP layout file. Max: {MAX_SP}")
     return args
 
+@SpSetupActions.sp_action(global_action=True)
+def count_sps(sp_layout, _, args :dict):
+    ''' Count number of SP and put in NUM_SP '''
+    write_to_sp_mk_gen(f"$(eval $(call add_define_val,NUM_SP,{len(sp_layout.keys())}))", args)
+    return args
+
 @SpSetupActions.sp_action
 def gen_fdt_sources(sp_layout, sp, args :dict):
     ''' Generate FDT_SOURCES values for a given SP. '''