diff options
author | Sandrine Bailleux <sandrine.bailleux@arm.com> | 2016-11-22 13:29:42 +0000 |
---|---|---|
committer | Sandrine Bailleux <sandrine.bailleux@arm.com> | 2017-05-17 16:48:01 +0100 |
commit | 618341a828145d0aaa84d80afb6b12bb4eeaea79 (patch) | |
tree | bc70c56c39d8ba16f9e4c374fd088baa96cb587e | |
parent | 834ea4ab334344d47967c97ee73e16754e3b9de4 (diff) |
NS_BL1U: Reorganize FWU tests
Move most of the FWU tests code in a separate file. The aim is
to better isolate the tests from the rest of the normal operations
carried by NS_BL1U (i.e. loading and authenticating subsequent
images involved in the FWU process). There are still a couple
of test SMCs interleaved in ns_bl1u_main() so this could be
further improved.
The test code in NS_BL1U has also been regorganized to improve
its readability.
Change-Id: If9d86852e59e2d3a40d8e148b9ae707c2b046e22
Signed-off-by: Sandrine Bailleux <sandrine.bailleux@arm.com>
-rw-r--r-- | fwu/ns_bl1u/ns_bl1u.mk | 4 | ||||
-rw-r--r-- | fwu/ns_bl1u/ns_bl1u_main.c | 172 | ||||
-rw-r--r-- | fwu/ns_bl1u/ns_bl1u_tests.c | 269 |
3 files changed, 277 insertions, 168 deletions
diff --git a/fwu/ns_bl1u/ns_bl1u.mk b/fwu/ns_bl1u/ns_bl1u.mk index 8272992..13b57da 100644 --- a/fwu/ns_bl1u/ns_bl1u.mk +++ b/fwu/ns_bl1u/ns_bl1u.mk @@ -52,6 +52,10 @@ NS_BL1U_SOURCES := drivers/io/io_fip.c \ plat/common/image_loader.c \ plat/common/plat_common.c +ifeq (${FWU_BL_TEST},1) + NS_BL1U_SOURCES += fwu/ns_bl1u/ns_bl1u_tests.c +endif + NS_BL1U_LINKERFILE := fwu/ns_bl1u/ns_bl1u.ld.S diff --git a/fwu/ns_bl1u/ns_bl1u_main.c b/fwu/ns_bl1u/ns_bl1u_main.c index 4b2d3c6..956f9df 100644 --- a/fwu/ns_bl1u/ns_bl1u_main.c +++ b/fwu/ns_bl1u/ns_bl1u_main.c @@ -51,12 +51,6 @@ #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) @@ -64,6 +58,8 @@ extern const char version_string[]; typedef void (*ns_bl2u_entrypoint_t)(unsigned long); +void ns_bl1u_fwu_test_main(void); + /* * This structure will be used for: * 1. Assigning unique image identifier. @@ -103,7 +99,7 @@ static const fwu_image_load_desc_t ns_bl1u_desc[] = { } }; -unsigned long smc_result; +static unsigned long smc_result; #define CHECK_SMC_RESULT(_r) do { \ if (smc_result != _r) { \ @@ -112,7 +108,7 @@ unsigned long smc_result; } \ } while (0); -void ns_bl1u_fwu_smc_call(unsigned int smc_id, +static void ns_bl1u_fwu_smc_call(unsigned int smc_id, unsigned long x1, unsigned long x2, unsigned long x3, @@ -124,166 +120,6 @@ 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: diff --git a/fwu/ns_bl1u/ns_bl1u_tests.c b/fwu/ns_bl1u/ns_bl1u_tests.c new file mode 100644 index 0000000..36b56a3 --- /dev/null +++ b/fwu/ns_bl1u/ns_bl1u_tests.c @@ -0,0 +1,269 @@ +/* + * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of ARM nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/******************************************************************************* + * Test the FWU SMC interface in Trusted Firmware, which is implemented in BL1. + ******************************************************************************/ + +#include <debug.h> +#include <errno.h> +#include <io_fip.h> +#include <platform_def.h> +#include <smc.h> +#include <status.h> +#include <tftf.h> +#include <tftf_lib.h> + +/* 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 + +typedef struct { + /* Description to print before sending the SMC */ + const char *description; + /* The arguments to pass to the SMC */ + const smc_args args; + /* The expected SMC return value */ + u_register_t expect; +} ns_bl1u_test_t; + +/* + * The tests consist in sending a succession of SMCs to trigger FWU operations + * in BL1. The order of the SMCs is important because they internally change the + * FWU state machine in Trusted Firmware. + */ +static const ns_bl1u_test_t tests[] = { + /* Basic FWU SMC handler test cases. */ + { + .description = "BL1_SMC_CALL_COUNT", + .args = { BL1_SMC_CALL_COUNT, 0, 0, 0, 0 }, + .expect = BL1_NUM_SMC_CALLS, + }, + + { + .description = "BL1_SMC_VERSION", + .args = { BL1_SMC_VERSION, 0, 0, 0, 0 }, + .expect = BL1_SMC_VER_VALUE, + }, + + { + .description = "Invalid SMC", + .args = { 0xdeadbeef, 0, 0, 0, 0 }, + .expect = SMC_UNKNOWN, + }, + + /* FWU_SMC_IMAGE_COPY test cases. */ + { + .description = "IMAGE_COPY with invalid image_id", + .args = { FWU_SMC_IMAGE_COPY, 0xdeadbeef, 0, 0, 0 }, + .expect = -EPERM, + }, + + { + .description = "IMAGE_COPY with non-secure image_id", + .args = { FWU_SMC_IMAGE_COPY, NS_BL2U_IMAGE_ID, 0, 0, 0 }, + .expect = -EPERM, + }, + + { + .description = "IMAGE_COPY with valid args", + .args = { FWU_SMC_IMAGE_COPY, FWU_CERT_ID, PLAT_ARM_FWU_FIP_BASE, 0x20, 0x20 }, + .expect = STATUS_SUCCESS, + }, + + { + .description = "IMAGE_COPY to copy an image_id again", + .args = { FWU_SMC_IMAGE_COPY, FWU_CERT_ID, PLAT_ARM_FWU_FIP_BASE, 0x20, 0x20 }, + .expect = -EPERM, + }, + + { + .description = "IMAGE_COPY with source address not mapped", + .args = { FWU_SMC_IMAGE_COPY, BL2U_IMAGE_ID, 0, 0, 0 }, + .expect = -ENOMEM, + }, + + { + .description = "IMAGE_COPY with source size not mapped", + .args = { FWU_SMC_IMAGE_COPY, BL2U_IMAGE_ID, PLAT_ARM_FWU_FIP_BASE, 0xdeadbeef, 0xdeadbeef }, + .expect = -ENOMEM, + }, + + { + .description = "IMAGE_COPY with image size more than secure mem", + .args = { FWU_SMC_IMAGE_COPY, BL2U_IMAGE_ID, PLAT_ARM_FWU_FIP_BASE, 0x40000, 0x40000 }, + .expect = -ENOMEM, + }, + + { + .description = "IMAGE_COPY with image size 0", + .args = { FWU_SMC_IMAGE_COPY, BL2U_IMAGE_ID, PLAT_ARM_FWU_FIP_BASE, 0, 0 }, + .expect = -ENOMEM, + }, + + { + .description = "IMAGE_COPY with 1st block size in partial copy", + .args = { FWU_SMC_IMAGE_COPY, BL2U_IMAGE_ID, PLAT_ARM_FWU_FIP_BASE, 0x20, 0x40 }, + .expect = STATUS_SUCCESS, + }, + + { + .description = "IMAGE_AUTH while copying the image", + .args = { FWU_SMC_IMAGE_AUTH, BL2U_IMAGE_ID, PLAT_ARM_FWU_FIP_BASE, 0x40, 0 }, + .expect = -EPERM, + }, + + { + .description = "IMAGE_COPY with last block with invalid source in partial copy", + .args = { FWU_SMC_IMAGE_COPY, BL2U_IMAGE_ID, 0, 0x21, 0x40 }, + .expect = -ENOMEM, + }, + + { + .description = "IMAGE_COPY with last block size > total size in partial copy", + .args = { FWU_SMC_IMAGE_COPY, BL2U_IMAGE_ID, PLAT_ARM_FWU_FIP_BASE, 0x21, 0x40 }, + .expect = STATUS_SUCCESS, + }, + + { + .description = "IMAGE_AUTH to RESET the image state", + .args = { FWU_SMC_IMAGE_AUTH, BL2U_IMAGE_ID, PLAT_ARM_FWU_FIP_BASE, 0x40, 0 }, + .expect = -EAUTH, + }, + + { + .description = "IMAGE_COPY with block size > total size", + .args = { FWU_SMC_IMAGE_COPY, BL2U_IMAGE_ID, PLAT_ARM_FWU_FIP_BASE, 0x21, 0x20 }, + .expect = STATUS_SUCCESS, + }, + + { + .description = "IMAGE_AUTH to RESET the image state", + .args = { FWU_SMC_IMAGE_AUTH, BL2U_IMAGE_ID, PLAT_ARM_FWU_FIP_BASE, 0x40, 0 }, + .expect = -EAUTH, + }, + + + /* FWU_SMC_IMAGE_AUTH test cases. */ + { + .description = "IMAGE_AUTH with invalid image_id", + .args = { FWU_SMC_IMAGE_AUTH, 0, 0, 0, 0 }, + .expect = -EPERM, + }, + + { + .description = "IMAGE_AUTH with secure image not copied", + .args = { FWU_SMC_IMAGE_AUTH, BL2U_IMAGE_ID, 0, 0, 0 }, + .expect = -EPERM, + }, + + { + .description = "IMAGE_AUTH with source address not mapped", + .args = { FWU_SMC_IMAGE_AUTH, NS_BL2U_IMAGE_ID, 0, 0, 0 }, + .expect = -ENOMEM, + }, + + { + .description = "IMAGE_AUTH with source size not mapped", + .args = { FWU_SMC_IMAGE_AUTH, NS_BL2U_IMAGE_ID, PLAT_ARM_FWU_FIP_BASE, 0xdeadbeef, 0 }, + .expect = -ENOMEM, + }, + + { + .description = "IMAGE_AUTH with valid args for copied image", + .args = { FWU_SMC_IMAGE_AUTH, FWU_CERT_ID, 0, 0, 0 }, + .expect = -EAUTH, + }, + + { + .description = "IMAGE_COPY to copy after auth failure", + .args = { FWU_SMC_IMAGE_COPY, FWU_CERT_ID, PLAT_ARM_FWU_FIP_BASE, 0x40, 0x40 }, + .expect = STATUS_SUCCESS, + }, + + { + .description = "IMAGE_AUTH with valid args for copied image", + .args = { FWU_SMC_IMAGE_AUTH, FWU_CERT_ID, 0, 0, 0 }, + .expect = -EAUTH, + }, + + /* FWU_SMC_IMAGE_EXECUTE test cases. */ + { + .description = "IMAGE_EXECUTE with invalid image_id", + .args = { FWU_SMC_IMAGE_EXECUTE, 0, 0, 0, 0 }, + .expect = -EPERM, + }, + + { + .description = "IMAGE_EXECUTE with non-executable image_id", + .args = { FWU_SMC_IMAGE_EXECUTE, FWU_CERT_ID, 0, 0, 0 }, + .expect = -EPERM, + }, + + { + .description = "IMAGE_EXECUTE with un-authenticated image_id", + .args = { FWU_SMC_IMAGE_EXECUTE, BL2U_IMAGE_ID, 0, 0, 0 }, + .expect = -EPERM, + }, + + + /* FWU_SMC_IMAGE_RESUME test case. */ + { + .description = "IMAGE_RESUME with invalid args", + .args = { FWU_SMC_IMAGE_RESUME, 0, 0, 0, 0 }, + .expect = -EPERM, + }, +}; + + +void ns_bl1u_fwu_test_main(void) +{ + NOTICE("NS_BL1U: ***** Starting NS_BL1U FWU test *****\n"); + + for (int i = 0 ; i < ARRAY_SIZE(tests); ++i) { + u_register_t result; + + INFO("NS_BL1U: %s\n", tests[i].description); + + smc_ret_values smc_ret; + smc_ret = tftf_smc(&tests[i].args); + result = smc_ret.ret0; + + if (result != tests[i].expect) { + ERROR("NS_BL1U: Unexpected SMC return value %lu, " + "expected %lu\n", result, tests[i].expect); + panic(); + } + } + + NOTICE("NS_BL1U: ***** All FWU test passed *****\n\n"); +} |