| Thaddeus Gonzalez-Serna | ba6ef4f | 2025-05-13 14:54:41 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2025, 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 <image_loader.h> |
| 10 | #include <io_storage.h> |
| 11 | #include <platform.h> |
| 12 | #include <platform_def.h> |
| 13 | #include <psci.h> |
| 14 | #include <smccc.h> |
| 15 | #include <status.h> |
| 16 | #include <tftf_lib.h> |
| 17 | #include <uuid.h> |
| 18 | #include <uuid_utils.h> |
| 19 | |
| 20 | /* |
| 21 | * @TEST_AIM@ validate FWU IMAGE SIZE invalid scenario |
| 22 | * TEST SUCCESS if FWU FIP IMAGE SIZE is found invalid and Fails to Proceed |
| 23 | * TEST FAIL in case FWU process is able to reboot |
| 24 | */ |
| 25 | |
| 26 | static fip_toc_entry_t * |
| 27 | find_fiptoc_entry_t(const int fip_base, const uuid_t *uuid) |
| 28 | { |
| 29 | fip_toc_entry_t *current_file = |
| 30 | (fip_toc_entry_t *) (fip_base + sizeof(fip_toc_header_t)); |
| 31 | |
| 32 | while (!is_uuid_null(&(current_file->uuid))) { |
| 33 | if (uuid_equal(&(current_file->uuid), uuid)) |
| 34 | return current_file; |
| 35 | |
| 36 | current_file += 1; |
| 37 | }; |
| 38 | return NULL; |
| 39 | } |
| 40 | |
| 41 | test_result_t test_fwu_image_size(void) |
| 42 | { |
| 43 | STATUS status; |
| 44 | int fip_base = PLAT_ARM_FIP_BASE; |
| 45 | int fwu_fip_base = PLAT_ARM_FWU_FIP_BASE; |
| 46 | |
| 47 | const uuid_t bl2 = UUID_TRUSTED_BOOT_FIRMWARE_BL2; |
| 48 | const uuid_t bl2u = UUID_FIRMWARE_UPDATE_BL2U; |
| 49 | |
| 50 | fip_toc_entry_t *bl2_entry; |
| 51 | fip_toc_entry_t *bl2u_entry; |
| 52 | |
| 53 | uintptr_t bl2_entry_address, bl2u_entry_address; |
| 54 | |
| 55 | int corrupt_size = 0xFFFF; |
| 56 | int offset; |
| 57 | |
| 58 | smc_args args = { SMC_PSCI_SYSTEM_RESET }; |
| 59 | smc_ret_values ret = {0}; |
| 60 | |
| 61 | /* retrieve bl2 and bl2u */ |
| 62 | bl2_entry = find_fiptoc_entry_t(fip_base, &bl2); |
| 63 | bl2_entry_address = (uintptr_t)bl2_entry; |
| 64 | |
| 65 | bl2u_entry = find_fiptoc_entry_t(fwu_fip_base, &bl2u); |
| 66 | bl2u_entry_address = (intptr_t)bl2u_entry; |
| 67 | |
| 68 | /* Reboot has not occurred yet */ |
| 69 | tftf_testcase_printf("not rebooted yet\n"); |
| 70 | |
| 71 | /* Corrupt FWU_FIP_SIZE */ |
| 72 | tftf_testcase_printf("bl2_entry_address value is (%lx)\n", bl2_entry_address); |
| 73 | |
| 74 | /* |
| 75 | * corrupt bl2 in fip |
| 76 | * corrupt toc entry size field of bl2u |
| 77 | */ |
| 78 | |
| 79 | /* corrupt bl2 image */ |
| 80 | offset = bl2_entry_address + sizeof(uuid_t) + sizeof(uint64_t) - FLASH_BASE; |
| 81 | status = fwu_nvm_write(offset, &corrupt_size, sizeof(uint64_t)); |
| 82 | |
| 83 | if (status != STATUS_SUCCESS) { |
| 84 | tftf_testcase_printf("staus not success error %d\n", status); |
| 85 | return TEST_RESULT_FAIL; |
| 86 | } |
| 87 | |
| 88 | /* corrupt toc bl2u entry */ |
| 89 | offset = bl2u_entry_address + sizeof(uuid_t) + sizeof(uint64_t) - FLASH_BASE; |
| 90 | status = fwu_nvm_write(offset, &corrupt_size, sizeof(uint64_t)); |
| 91 | |
| 92 | if (status != STATUS_SUCCESS) { |
| 93 | tftf_testcase_printf("status not success error %d\n", status); |
| 94 | return TEST_RESULT_FAIL; |
| 95 | } |
| 96 | |
| 97 | /* Notify that we are rebooting now. */ |
| 98 | tftf_notify_reboot(); |
| 99 | |
| 100 | /* Request PSCI system reset. */ |
| 101 | ret = tftf_smc(&args); |
| 102 | |
| 103 | /* The PSCI SYSTEM_RESET call is not supposed to return */ |
| 104 | tftf_testcase_printf("System didn't reboot properly (%d)\n", |
| 105 | (unsigned int)ret.ret0); |
| 106 | |
| 107 | return TEST_RESULT_FAIL; |
| 108 | } |