SPM: Add support for using watermarks to determine stack usage

New config option CONFIG_TFM_STACK_WATERMARKS (defaulted to OFF).
If set, when SPM initialises a partition, it sets every dword of its
stack to a fixed value. As the stack is used, these values will get
overwritten.
Add a new SPM function dump_used_stacks() that examines every
partition's stack looking for the watermark, deduces how much stack
has been used, and prints the stack usages (note that this will be an
underestimate if the partition happens to write the watermark value
to the stack). Ideally this should be called after TF-M has been
thoroughly exercised.

Currently disabled for isolation level 3, which needs more
investigation.

Change-Id: I1592a383790da9d49fddac00407d7bceaf312d47
Signed-off-by: Chris Brand <chris.brand@cypress.com>
diff --git a/secure_fw/spm/ffm/backend_ipc.c b/secure_fw/spm/ffm/backend_ipc.c
index b5b99b6..597016d 100644
--- a/secure_fw/spm/ffm/backend_ipc.c
+++ b/secure_fw/spm/ffm/backend_ipc.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
- * Copyright (c) 2021, Cypress Semiconductor Corporation. All rights reserved.
+ * Copyright (c) 2021-2022, Cypress Semiconductor Corporation. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -10,6 +10,7 @@
 #include "critical_section.h"
 #include "compiler_ext_defs.h"
 #include "runtime_defs.h"
+#include "ffm/stack_watermark.h"
 #include "spm_ipc.h"
 #include "tfm_hal_isolation.h"
 #include "tfm_hal_platform.h"
@@ -166,6 +167,8 @@
                       LOAD_ALLOCED_STACK_ADDR(p_pldi),
                       p_pldi->stack_size);
 
+    watermark_stack(p_pt);
+
     prv_process_metadata(p_pt);
 
     THRD_INIT(&p_pt->thrd, &p_pt->ctx_ctrl,