Jimmy Brisson | 16de810 | 2023-08-18 08:50:30 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2024, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include "tbb_test_infra.h" |
| 8 | |
| 9 | #include <fwu_nvm.h> |
| 10 | #include <io_storage.h> |
| 11 | #include <platform.h> |
| 12 | #include <status.h> |
| 13 | #include <test_helpers.h> |
| 14 | #include <tftf_lib.h> |
| 15 | |
| 16 | test_result_t test_corrupt_boot_fip(unsigned int offset) |
| 17 | { |
| 18 | unsigned int flag = 0xDEADBEEF; |
| 19 | size_t written = 0; |
| 20 | uintptr_t dev_handle; |
| 21 | int result; |
| 22 | |
| 23 | if (tftf_is_rebooted()) { |
| 24 | /* FIP successfully repaired */ |
| 25 | return TEST_RESULT_SUCCESS; |
| 26 | } |
| 27 | |
| 28 | /* Corrupt the FIP at the provided offset */ |
| 29 | plat_get_nvm_handle(&dev_handle); |
| 30 | result = io_seek(dev_handle, IO_SEEK_SET, offset); |
| 31 | TEST_ASSERT(result == IO_SUCCESS); |
| 32 | result = io_write(dev_handle, (uintptr_t) &flag, sizeof(flag), &written); |
| 33 | TEST_ASSERT(result == IO_SUCCESS); |
| 34 | TEST_ASSERT(written == sizeof(flag)); |
| 35 | |
| 36 | /* |
| 37 | * Now reboot the system. |
| 38 | * On the next boot, EL3 firmware should notice and repair the corruption |
| 39 | * before re-entering TFTF |
| 40 | */ |
| 41 | |
| 42 | tftf_notify_reboot(); |
| 43 | psci_system_reset(); |
| 44 | return TEST_RESULT_FAIL; |
| 45 | } |