feat(arm): makefile invoke CoT dt2c

Change the makefile to call the cot-dt2c tool
during the build for Arm platform

Change-Id: Idb7c02cca6b9ddd87f575a42c88e7b2660b896e0
Signed-off-by: Xialin Liu <Xialin.Liu@ARM.com>
diff --git a/Makefile b/Makefile
index baf8431..2fc856a 100644
--- a/Makefile
+++ b/Makefile
@@ -121,6 +121,9 @@
 SP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
 SP_DTS_LIST_FRAGMENT	?=	${BUILD_PLAT}/sp_list_fragment.dts
 
+# Variables for use with Certificate Conversion (cot-dt2c) Tool
+CERTCONVPATH	?= tools/cot_dt2c
+
 # Variables for use with ROMLIB
 ROMLIBPATH		?=	lib/romlib
 
@@ -1582,6 +1585,7 @@
 clean:
 	$(s)echo "  CLEAN"
 	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
+	$(q)${MAKE} -C ${CERTCONVPATH} clean
 ifdef UNIX_MK
 	$(q)${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
 else
@@ -1597,6 +1601,7 @@
 	$(s)echo "  REALCLEAN"
 	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
 	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
+	$(q)${MAKE} -C ${CERTCONVPATH} clean
 ifdef UNIX_MK
 	$(q)${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
 else
diff --git a/plat/arm/common/arm_common.mk b/plat/arm/common/arm_common.mk
index 0b6b526..cff7771 100644
--- a/plat/arm/common/arm_common.mk
+++ b/plat/arm/common/arm_common.mk
@@ -387,20 +387,25 @@
         BL1_SOURCES	+=	drivers/auth/dualroot/bl1_cot.c
         ifneq (${COT_DESC_IN_DTB},0)
             BL2_SOURCES	+=	lib/fconf/fconf_cot_getter.c
-        else
-            BL2_SOURCES	+=	drivers/auth/dualroot/bl2_cot.c
         endif
     else ifeq (${COT},cca)
         BL1_SOURCES	+=	drivers/auth/cca/bl1_cot.c
         ifneq (${COT_DESC_IN_DTB},0)
             BL2_SOURCES	+=	lib/fconf/fconf_cot_getter.c
-        else
-            BL2_SOURCES	+=	drivers/auth/cca/bl2_cot.c
         endif
     else
         $(error Unknown chain of trust ${COT})
     endif
 
+    ifeq (${COT_DESC_IN_DTB},0)
+      ifeq (${COT},dualroot)
+        COTDTPATH := fdts/dualroot_cot_descriptors.dtsi
+      else ifeq (${COT},cca)
+        COTDTPATH := fdts/cca_cot_descriptors.dtsi
+      endif
+      bl2: cot-dt2c
+    endif
+
     BL1_SOURCES		+=	${AUTH_SOURCES}					\
 				bl1/tbbr/tbbr_img_desc.c			\
 				plat/arm/common/arm_bl1_fwu.c			\
@@ -471,4 +476,18 @@
   ifeq (${RESET_TO_BL31}, 1)
     bl31: tl
   endif
+endif
+
+cot-dt2c:
+ifneq ($(COTDTPATH),)
+  $(info COT CONVERSION FOR ${COTDTPATH})
+  toolpath := $(shell which cot-dt2c)
+  ifeq (${toolpath},)
+    output := $(shell make -C ./${CERTCONVPATH} install)
+    $(info install output ${output})
+    toolpath := $(shell which cot-dt2c)
+  endif
+  output := $(shell ${toolpath} convert-to-c ${COTDTPATH} ${BUILD_PLAT}/bl2_cot.c)
+  $(info ${output})
+  BL2_SOURCES += ${BUILD_PLAT}/bl2_cot.c
 endif