/* * Copyright (c) 2015-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. */ #include #include #include #include #include #include #include #include /* * @Test_Aim@ Validate the FWU ToC invalid case. * The Firmware Update feature implemented in Trusted Firmware * code needs to be tested to check if FWU process gets started * or not when the ToC header value in fip.bin is invalid. * Test SUCCESS in case ToC is found valid. * Test FAIL in case ToC is found invalid. */ test_result_t test_fwu_toc(void) { STATUS status; unsigned int toc_header; smc_args args = { SMC_PSCI_SYSTEM_RESET }; smc_ret_values ret = {0}; if (tftf_is_rebooted()) { /* * Check whether we successfully resumed from the * Firmware Update process. If we have, then the * ToC header value will have been repaired. */ status = fwu_nvm_read(0, &toc_header, 4); if (status != STATUS_SUCCESS) { tftf_testcase_printf("Failed to read NVM (%d)\n", status); return TEST_RESULT_FAIL; } if (toc_header != TOC_HEADER_NAME) { tftf_testcase_printf("ToC is Invalid (%u)\n", toc_header); return TEST_RESULT_FAIL; } return TEST_RESULT_SUCCESS; } /* Corrupt the TOC in fip.bin. */ toc_header = 0xdeadbeef; status = fwu_nvm_write(0, &toc_header, 4); if (status != STATUS_SUCCESS) { tftf_testcase_printf("Failed to overwrite the ToC header (%d)\n", status); return TEST_RESULT_SKIPPED; } /* Notify that we are rebooting now. */ tftf_notify_reboot(); /* Request PSCI system reset. */ ret = tftf_smc(&args); /* The PSCI SYSTEM_RESET call is not supposed to return */ tftf_testcase_printf("System didn't reboot properly (%d)\n", (unsigned int)ret.ret0); return TEST_RESULT_FAIL; }