Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2018, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <firmware_image_package.h> |
| 8 | #include <fwu_nvm.h> |
| 9 | #include <io_storage.h> |
| 10 | #include <platform.h> |
| 11 | #include <psci.h> |
| 12 | #include <smccc.h> |
| 13 | #include <status.h> |
| 14 | #include <tftf_lib.h> |
| 15 | |
| 16 | /* |
| 17 | * @Test_Aim@ Validate the FWU ToC invalid case. |
| 18 | * The Firmware Update feature implemented in Trusted Firmware-A |
| 19 | * code needs to be tested to check if FWU process gets started |
| 20 | * or not when the ToC header value in fip.bin is invalid. |
| 21 | * Test SUCCESS in case ToC is found valid. |
| 22 | * Test FAIL in case ToC is found invalid. |
| 23 | */ |
| 24 | test_result_t test_fwu_toc(void) |
| 25 | { |
| 26 | STATUS status; |
| 27 | unsigned int toc_header; |
| 28 | smc_args args = { SMC_PSCI_SYSTEM_RESET }; |
| 29 | smc_ret_values ret = {0}; |
| 30 | |
| 31 | if (tftf_is_rebooted()) { |
| 32 | /* |
| 33 | * Check whether we successfully resumed from the |
| 34 | * Firmware Update process. If we have, then the |
| 35 | * ToC header value will have been repaired. |
| 36 | */ |
| 37 | status = fwu_nvm_read(0, &toc_header, 4); |
| 38 | if (status != STATUS_SUCCESS) { |
| 39 | tftf_testcase_printf("Failed to read NVM (%d)\n", status); |
| 40 | return TEST_RESULT_FAIL; |
| 41 | } |
| 42 | |
| 43 | if (toc_header != TOC_HEADER_NAME) { |
| 44 | tftf_testcase_printf("ToC is Invalid (%u)\n", toc_header); |
| 45 | return TEST_RESULT_FAIL; |
| 46 | } |
| 47 | |
| 48 | return TEST_RESULT_SUCCESS; |
| 49 | } |
| 50 | |
| 51 | /* Corrupt the TOC in fip.bin. */ |
| 52 | toc_header = 0xdeadbeef; |
| 53 | status = fwu_nvm_write(0, &toc_header, 4); |
| 54 | if (status != STATUS_SUCCESS) { |
| 55 | tftf_testcase_printf("Failed to overwrite the ToC header (%d)\n", |
| 56 | status); |
| 57 | return TEST_RESULT_SKIPPED; |
| 58 | } |
| 59 | |
| 60 | /* Notify that we are rebooting now. */ |
| 61 | tftf_notify_reboot(); |
| 62 | |
| 63 | /* Request PSCI system reset. */ |
| 64 | ret = tftf_smc(&args); |
| 65 | |
| 66 | /* The PSCI SYSTEM_RESET call is not supposed to return */ |
| 67 | tftf_testcase_printf("System didn't reboot properly (%d)\n", |
| 68 | (unsigned int)ret.ret0); |
| 69 | |
| 70 | return TEST_RESULT_FAIL; |
| 71 | } |