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 <fwu_nvm.h> |
| 8 | #include <io_storage.h> |
| 9 | #include <platform.h> |
| 10 | #include <platform_def.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 AUTH failure 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 | * when watchdog resets the system due to Authentication |
| 21 | * failure of an image in BL1/BL2 stage. |
| 22 | * Test SUCCESS in case Firmware Update was done. |
| 23 | * Test FAIL in case Firmware Update was not done. |
| 24 | */ |
| 25 | test_result_t test_fwu_auth(void) |
| 26 | { |
| 27 | STATUS status; |
| 28 | unsigned int flag; |
| 29 | smc_args args = { SMC_PSCI_SYSTEM_RESET }; |
| 30 | smc_ret_values ret = {0}; |
| 31 | |
| 32 | if (tftf_is_rebooted()) { |
| 33 | /* |
| 34 | * Check if the FIP update is done. |
| 35 | */ |
| 36 | status = fwu_nvm_read(FWU_TFTF_TESTCASE_BUFFER_OFFSET, &flag, 4); |
| 37 | if (status != STATUS_SUCCESS) { |
| 38 | tftf_testcase_printf("Failed to read NVM (%d)\n", status); |
| 39 | return TEST_RESULT_FAIL; |
| 40 | } |
| 41 | |
| 42 | if (flag != FIP_IMAGE_UPDATE_DONE_FLAG) { |
| 43 | tftf_testcase_printf("FIP was not updated\n"); |
| 44 | return TEST_RESULT_FAIL; |
| 45 | } |
| 46 | |
| 47 | return TEST_RESULT_SUCCESS; |
| 48 | } |
| 49 | |
| 50 | /* |
| 51 | * Corrupt the flash offset for authentication failure. |
| 52 | */ |
| 53 | flag = 0xdeadbeef; |
| 54 | status = fwu_nvm_write(FIP_CORRUPT_OFFSET, &flag, 4); |
| 55 | if (status != STATUS_SUCCESS) { |
| 56 | tftf_testcase_printf("Failed to corrupt FIP (%d)\n", status); |
| 57 | return TEST_RESULT_SKIPPED; |
| 58 | } |
| 59 | |
| 60 | /* |
| 61 | * Provide the backup FIP address. |
| 62 | */ |
| 63 | flag = FIP_BKP_ADDRESS; |
| 64 | status = fwu_nvm_write(FWU_TFTF_TESTCASE_BUFFER_OFFSET, &flag, 4); |
| 65 | if (status != STATUS_SUCCESS) { |
| 66 | tftf_testcase_printf("Failed to update backup FIP address (%d)\n", |
| 67 | status); |
| 68 | return TEST_RESULT_SKIPPED; |
| 69 | } |
| 70 | |
| 71 | /* Notify that we are rebooting now. */ |
| 72 | tftf_notify_reboot(); |
| 73 | |
| 74 | /* Request PSCI system reset. */ |
| 75 | ret = tftf_smc(&args); |
| 76 | |
| 77 | /* The PSCI SYSTEM_RESET call is not supposed to return */ |
| 78 | tftf_testcase_printf("System didn't reboot properly (%d)\n", |
| 79 | (unsigned int)ret.ret0); |
| 80 | |
| 81 | return TEST_RESULT_FAIL; |
| 82 | } |