summaryrefslogtreecommitdiff
path: root/tests/fwu_tests/test_fwu_auth.c
blob: 09502ad59fc81aaa20e38c1b2455820d3398e30e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * 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 <fwu_nvm.h>
#include <io_storage.h>
#include <platform.h>
#include <platform_def.h>
#include <psci.h>
#include <status.h>
#include <smc.h>
#include <tftf_lib.h>

/*
 * @Test_Aim@ Validate the FWU AUTH failure case.
 * The Firmware Update feature implemented in Trusted Firmware
 * code needs to be tested to check if FWU process gets started
 * when watchdog resets the system due to Authentication
 * failure of an image in BL1/BL2 stage.
 * Test SUCCESS in case Firmware Update was done.
 * Test FAIL in case Firmware Update was not done.
 */
test_result_t test_fwu_auth(void)
{
	STATUS status;
	unsigned int flag;
	smc_args args = { SMC_PSCI_SYSTEM_RESET };
	smc_ret_values ret = {0};

	if (tftf_is_rebooted()) {
		/*
		 * Check if the FIP update is done.
		 */
		status = fwu_nvm_read(FWU_TFTF_TESTCASE_BUFFER_OFFSET,	&flag, 4);
		if (status != STATUS_SUCCESS) {
			tftf_testcase_printf("Failed to read NVM (%d)\n", status);
			return TEST_RESULT_FAIL;
		}

		if (flag != FIP_IMAGE_UPDATE_DONE_FLAG) {
			tftf_testcase_printf("FIP was not updated\n");
			return TEST_RESULT_FAIL;
		}

		return TEST_RESULT_SUCCESS;
	}

	/*
	 * Corrupt the flash offset for authentication failure.
	 */
	flag = 0xdeadbeef;
	status = fwu_nvm_write(FIP_CORRUPT_OFFSET, &flag, 4);
	if (status != STATUS_SUCCESS) {
		tftf_testcase_printf("Failed to corrupt FIP (%d)\n", status);
		return TEST_RESULT_SKIPPED;
	}

	/*
	 * Provide the backup FIP address.
	 */
	flag = FIP_BKP_ADDRESS;
	status = fwu_nvm_write(FWU_TFTF_TESTCASE_BUFFER_OFFSET, &flag, 4);
	if (status != STATUS_SUCCESS) {
		tftf_testcase_printf("Failed to update backup FIP address (%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;
}