summaryrefslogtreecommitdiff
path: root/fwu
diff options
context:
space:
mode:
authorYatharth Kochar <yatharth.kochar@arm.com>2015-08-17 18:00:37 +0100
committerYatharth Kochar <yatharth.kochar@arm.com>2015-12-09 14:53:01 +0000
commitd300bffb2b7d08b1718042a74cc5671254471acf (patch)
tree08c84972cba19745131eafe3c337a350a11635f5 /fwu
parentfd2c95e3357e96535dfca52becccc737c6eef202 (diff)
FWU: Add FWU SMC related test cases in NS_BL1U
The Firmware Update feature implemented in Trusted Firmware code needs to be tested for the SMC interface to make sure it is working as designed/expected. The main reasons why TFTF test framework cannot be used for this particular test scenario is that it executes totally out of NS-DDR memory and has huge memory requirements. Due to which, in its present implementation, it is not possible to execute it out of NS ROM/RAM memories. This patch adds, new function `ns_bl1u_fwu_smc_test()`, in NS_BL1U, which carries out FWU SMC interface test cases implemented in TF code. It also adds new flag `FWU_BL_TEST` in the Makefile to keep this under conditional compilation. Change-Id: Ide45b49a3d3fd3dc18450ed59f770907085874c4
Diffstat (limited to 'fwu')
-rw-r--r--fwu/ns_bl1u/ns_bl1u_main.c188
1 files changed, 187 insertions, 1 deletions
diff --git a/fwu/ns_bl1u/ns_bl1u_main.c b/fwu/ns_bl1u/ns_bl1u_main.c
index 42609bc..488faf6 100644
--- a/fwu/ns_bl1u/ns_bl1u_main.c
+++ b/fwu/ns_bl1u/ns_bl1u_main.c
@@ -38,6 +38,8 @@
#include <nvm.h>
#include <platform.h>
#include <platform_def.h>
+#include <smc.h>
+#include <status.h>
#include <string.h>
#include <tftf.h>
#include <tftf_lib.h>
@@ -48,6 +50,12 @@
#define FWU_NON_EXEC (0x0)
#define FWU_EXEC (0x1)
+/* Expected number of SMC calls supported in BL1 */
+#define BL1_NUM_SMC_CALLS (10)
+
+/* Expected version of BL1 SMC implementation */
+#define BL1_SMC_VER_VALUE (1)
+
/* This size is used to exercise partial copy */
#define FWU_COPY_PARTIAL_SIZE (0x10)
@@ -115,6 +123,167 @@ void ns_bl1u_fwu_smc_call(unsigned int smc_id,
smc_result = fwu_result.ret0;
}
+#if FWU_BL_TEST
+/*******************************************************************************
+ * Test the TF FWU SMC interface.
+ ******************************************************************************/
+static void ns_bl1u_fwu_test_main(void)
+{
+ unsigned int smc_fid;
+
+ NOTICE("NS_BL1U: *****Starting NS_BL1U FWU test*****\n");
+
+ /* Basic FWU SMC handler test cases. */
+ INFO("NS_BL1U: Calling BL1_SMC_CALL_COUNT\n");
+ ns_bl1u_fwu_smc_call(BL1_SMC_CALL_COUNT, 0, 0, 0, 0);
+ CHECK_SMC_RESULT(BL1_NUM_SMC_CALLS);
+
+ INFO("NS_BL1U: Calling BL1_SMC_VERSION\n");
+ ns_bl1u_fwu_smc_call(BL1_SMC_VERSION, 0, 0, 0, 0);
+ CHECK_SMC_RESULT(BL1_SMC_VER_VALUE);
+
+ INFO("NS_BL1U: Calling invalid SMC\n");
+ ns_bl1u_fwu_smc_call(0xdeadbeef, 0, 0, 0, 0);
+ CHECK_SMC_RESULT(SMC_UNKNOWN);
+
+ /* FWU_SMC_IMAGE_COPY test cases. */
+ INFO("NS_BL1U: Doing FWU_SMC_IMAGE_COPY test\n");
+ smc_fid = FWU_SMC_IMAGE_COPY;
+
+ INFO("NS_BL1U: Calling with invalid image_id\n");
+ ns_bl1u_fwu_smc_call(smc_fid, 0xdeadbeef, 0, 0, 0);
+ CHECK_SMC_RESULT(-EPERM);
+
+ INFO("NS_BL1U: Calling with non-secure image_id\n");
+ ns_bl1u_fwu_smc_call(smc_fid, NS_BL2U_IMAGE_ID, 0, 0, 0);
+ CHECK_SMC_RESULT(-EPERM);
+
+ INFO("NS_BL1U: Calling with valid args\n");
+ ns_bl1u_fwu_smc_call(smc_fid, FWU_CERT_ID,
+ PLAT_ARM_FWU_FIP_BASE, 0x20, 0x20);
+ CHECK_SMC_RESULT(STATUS_SUCCESS);
+
+ INFO("NS_BL1U: Calling to copy an image_id again\n");
+ ns_bl1u_fwu_smc_call(smc_fid, FWU_CERT_ID,
+ PLAT_ARM_FWU_FIP_BASE, 0x20, 0x20);
+ CHECK_SMC_RESULT(-EPERM);
+
+ INFO("NS_BL1U: Calling with source address not mapped\n");
+ ns_bl1u_fwu_smc_call(smc_fid, BL2U_IMAGE_ID, 0, 0, 0);
+ CHECK_SMC_RESULT(-ENOMEM);
+
+ INFO("NS_BL1U: Calling with source size not mapped\n");
+ ns_bl1u_fwu_smc_call(smc_fid, BL2U_IMAGE_ID,
+ PLAT_ARM_FWU_FIP_BASE, 0xdeadbeef, 0xdeadbeef);
+ CHECK_SMC_RESULT(-ENOMEM);
+
+ INFO("NS_BL1U: Calling with image size more than secure mem\n");
+ ns_bl1u_fwu_smc_call(smc_fid, BL2U_IMAGE_ID,
+ PLAT_ARM_FWU_FIP_BASE, 0x40000, 0x40000);
+ CHECK_SMC_RESULT(-ENOMEM);
+
+ INFO("NS_BL1U: Calling with image size 0\n");
+ ns_bl1u_fwu_smc_call(smc_fid, BL2U_IMAGE_ID,
+ PLAT_ARM_FWU_FIP_BASE, 0, 0);
+ CHECK_SMC_RESULT(-ENOMEM);
+
+ INFO("NS_BL1U: Calling with 1st block size in partial copy\n");
+ ns_bl1u_fwu_smc_call(smc_fid, BL2U_IMAGE_ID,
+ PLAT_ARM_FWU_FIP_BASE, 0x20, 0x40);
+ CHECK_SMC_RESULT(STATUS_SUCCESS);
+
+ INFO("NS_BL1U: Calling FWU_SMC_IMAGE_AUTH while copying the image\n");
+ ns_bl1u_fwu_smc_call(FWU_SMC_IMAGE_AUTH, BL2U_IMAGE_ID,
+ PLAT_ARM_FWU_FIP_BASE, 0x40, 0);
+ CHECK_SMC_RESULT(-EPERM);
+
+ INFO("NS_BL1U: Calling with last block with invalid source"
+ " in partial copy\n");
+ ns_bl1u_fwu_smc_call(smc_fid, BL2U_IMAGE_ID, 0, 0x21, 0x40);
+ CHECK_SMC_RESULT(-ENOMEM);
+
+ INFO("NS_BL1U: Calling with last block size > total size"
+ " in partial copy\n");
+ ns_bl1u_fwu_smc_call(smc_fid, BL2U_IMAGE_ID,
+ PLAT_ARM_FWU_FIP_BASE, 0x21, 0x40);
+ CHECK_SMC_RESULT(STATUS_SUCCESS);
+
+ INFO("NS_BL1U: Calling FWU_SMC_IMAGE_AUTH to RESET the image state\n");
+ ns_bl1u_fwu_smc_call(FWU_SMC_IMAGE_AUTH, BL2U_IMAGE_ID,
+ PLAT_ARM_FWU_FIP_BASE, 0x40, 0);
+ CHECK_SMC_RESULT(-EAUTH);
+
+ INFO("NS_BL1U: Calling with block size > total size\n");
+ ns_bl1u_fwu_smc_call(smc_fid, BL2U_IMAGE_ID,
+ PLAT_ARM_FWU_FIP_BASE, 0x21, 0x20);
+ CHECK_SMC_RESULT(STATUS_SUCCESS);
+
+ INFO("NS_BL1U: Calling FWU_SMC_IMAGE_AUTH to RESET the image state\n");
+ ns_bl1u_fwu_smc_call(FWU_SMC_IMAGE_AUTH, BL2U_IMAGE_ID,
+ PLAT_ARM_FWU_FIP_BASE, 0x40, 0);
+ CHECK_SMC_RESULT(-EAUTH);
+
+
+ /* FWU_SMC_IMAGE_AUTH test cases. */
+ INFO("NS_BL1U: Doing FWU_SMC_IMAGE_AUTH test\n");
+ smc_fid = FWU_SMC_IMAGE_AUTH;
+
+ INFO("NS_BL1U: Calling with invalid image_id\n");
+ ns_bl1u_fwu_smc_call(smc_fid, 0, 0, 0, 0);
+ CHECK_SMC_RESULT(-EPERM);
+
+ INFO("NS_BL1U: Calling with secure image not copied\n");
+ ns_bl1u_fwu_smc_call(smc_fid, BL2U_IMAGE_ID, 0, 0, 0);
+ CHECK_SMC_RESULT(-EPERM);
+
+ INFO("NS_BL1U: Calling with source address not mapped\n");
+ ns_bl1u_fwu_smc_call(smc_fid, NS_BL2U_IMAGE_ID, 0, 0, 0);
+ CHECK_SMC_RESULT(-ENOMEM);
+
+ INFO("NS_BL1U: Calling with source size not mapped\n");
+ ns_bl1u_fwu_smc_call(smc_fid, NS_BL2U_IMAGE_ID,
+ PLAT_ARM_FWU_FIP_BASE, 0xdeadbeef, 0);
+ CHECK_SMC_RESULT(-ENOMEM);
+
+ INFO("NS_BL1U: Calling with valid args for copied image\n");
+ ns_bl1u_fwu_smc_call(smc_fid, FWU_CERT_ID, 0, 0, 0);
+ CHECK_SMC_RESULT(-EAUTH);
+
+ INFO("NS_BL1U: Calling FWU_SMC_IMAGE_COPY to copy after auth failure\n");
+ ns_bl1u_fwu_smc_call(FWU_SMC_IMAGE_COPY, FWU_CERT_ID,
+ PLAT_ARM_FWU_FIP_BASE, 0x40, 0x40);
+ CHECK_SMC_RESULT(STATUS_SUCCESS);
+
+ INFO("NS_BL1U: Calling with valid args for copied image\n");
+ ns_bl1u_fwu_smc_call(smc_fid, FWU_CERT_ID, 0, 0, 0);
+ CHECK_SMC_RESULT(-EAUTH);
+
+ /* FWU_SMC_IMAGE_EXECUTE test cases. */
+ INFO("NS_BL1U: Doing FWU_SMC_IMAGE_EXECUTE test\n");
+ smc_fid = FWU_SMC_IMAGE_EXECUTE;
+
+ INFO("NS_BL1U: Calling with invalid image_id\n");
+ ns_bl1u_fwu_smc_call(smc_fid, 0, 0, 0, 0);
+ CHECK_SMC_RESULT(-EPERM);
+
+ INFO("NS_BL1U: Calling with non-executable image_id\n");
+ ns_bl1u_fwu_smc_call(smc_fid, FWU_CERT_ID, 0, 0, 0);
+ CHECK_SMC_RESULT(-EPERM);
+
+ INFO("NS_BL1U: Calling with un-authenticated image_id\n");
+ ns_bl1u_fwu_smc_call(smc_fid, BL2U_IMAGE_ID, 0, 0, 0);
+ CHECK_SMC_RESULT(-EPERM);
+
+
+ /* FWU_SMC_IMAGE_RESUME test case. */
+ INFO("NS_BL1U: Calling FWU_SMC_IMAGE_RESUME with invalid args\n");
+ ns_bl1u_fwu_smc_call(FWU_SMC_IMAGE_RESUME, 0, 0, 0, 0);
+ CHECK_SMC_RESULT(-EPERM);
+
+ NOTICE("NS_BL1U: *****All FWU test passed*****\n");
+}
+#endif /* FWU_BL_TEST */
+
/*******************************************************************************
* Following are the responsibilities of NS_BL1U image:
* Load FWU images from external NVM memory to NS RAM.
@@ -138,6 +307,10 @@ void ns_bl1u_main(void)
plat_arm_io_setup();
+#if FWU_BL_TEST
+ ns_bl1u_fwu_test_main();
+#endif
+
for (index = 0; index < ARRAY_SIZE(ns_bl1u_desc); index++) {
image_desc = &ns_bl1u_desc[index];
@@ -182,12 +355,25 @@ void ns_bl1u_main(void)
ns_bl1u_fwu_smc_call(FWU_SMC_IMAGE_AUTH, image_desc->image_id,
offset, img_size, 0);
CHECK_SMC_RESULT(0);
-
+#if FWU_BL_TEST
+ /* Check if authenticating again the same image returns error. */
+ INFO("NS_BL1U: TEST Calling SMC to auth again\n");
+ ns_bl1u_fwu_smc_call(FWU_SMC_IMAGE_AUTH, ns_bl1u_desc[index].image_id,
+ offset, img_size, 0);
+ CHECK_SMC_RESULT(-EPERM);
+#endif
if (image_desc->execute == FWU_EXEC) {
INFO("NS_BL1U: Calling EXECUTE SMC\n");
ns_bl1u_fwu_smc_call(FWU_SMC_IMAGE_EXECUTE, image_desc->image_id,
0, 0, 0);
CHECK_SMC_RESULT(0);
+#if FWU_BL_TEST
+ /* Check if executing again the same image returns error. */
+ INFO("NS_BL1U: TEST Calling SMC to execute again\n");
+ ns_bl1u_fwu_smc_call(FWU_SMC_IMAGE_EXECUTE,
+ ns_bl1u_desc[index].image_id, 0, 0, 0);
+ CHECK_SMC_RESULT(-EPERM);
+#endif
}
}