xref: /rk3399_ARM-atf/plat/arm/board/fvp/fvp_err.c (revision 37b70031e027c76fdebe3c2d2edb2da173bcf150)
1*37b70031SAmbroise Vincent /*
2*37b70031SAmbroise Vincent  * Copyright (c) 2019, Arm Limited. All rights reserved.
3*37b70031SAmbroise Vincent  *
4*37b70031SAmbroise Vincent  * SPDX-License-Identifier: BSD-3-Clause
5*37b70031SAmbroise Vincent  */
6*37b70031SAmbroise Vincent 
7*37b70031SAmbroise Vincent #include <errno.h>
8*37b70031SAmbroise Vincent 
9*37b70031SAmbroise Vincent #include <common/debug.h>
10*37b70031SAmbroise Vincent #include <drivers/arm/sp805.h>
11*37b70031SAmbroise Vincent #include <drivers/cfi/v2m_flash.h>
12*37b70031SAmbroise Vincent #include <plat/arm/common/plat_arm.h>
13*37b70031SAmbroise Vincent #include <plat/common/platform.h>
14*37b70031SAmbroise Vincent #include <platform_def.h>
15*37b70031SAmbroise Vincent 
16*37b70031SAmbroise Vincent /*
17*37b70031SAmbroise Vincent  * FVP error handler
18*37b70031SAmbroise Vincent  */
19*37b70031SAmbroise Vincent __dead2 void plat_arm_error_handler(int err)
20*37b70031SAmbroise Vincent {
21*37b70031SAmbroise Vincent 	int ret;
22*37b70031SAmbroise Vincent 
23*37b70031SAmbroise Vincent 	switch (err) {
24*37b70031SAmbroise Vincent 	case -ENOENT:
25*37b70031SAmbroise Vincent 	case -EAUTH:
26*37b70031SAmbroise Vincent 		/* Image load or authentication error. Erase the ToC */
27*37b70031SAmbroise Vincent 		INFO("Erasing FIP ToC from flash...\n");
28*37b70031SAmbroise Vincent 		(void)nor_unlock(PLAT_ARM_FIP_BASE);
29*37b70031SAmbroise Vincent 		ret = nor_word_program(PLAT_ARM_FIP_BASE, 0);
30*37b70031SAmbroise Vincent 		if (ret != 0) {
31*37b70031SAmbroise Vincent 			ERROR("Cannot erase ToC\n");
32*37b70031SAmbroise Vincent 		} else {
33*37b70031SAmbroise Vincent 			INFO("Done\n");
34*37b70031SAmbroise Vincent 		}
35*37b70031SAmbroise Vincent 		break;
36*37b70031SAmbroise Vincent 	default:
37*37b70031SAmbroise Vincent 		/* Unexpected error */
38*37b70031SAmbroise Vincent 		break;
39*37b70031SAmbroise Vincent 	}
40*37b70031SAmbroise Vincent 
41*37b70031SAmbroise Vincent 	(void)console_flush();
42*37b70031SAmbroise Vincent 
43*37b70031SAmbroise Vincent 	/* Setup the watchdog to reset the system as soon as possible */
44*37b70031SAmbroise Vincent 	sp805_refresh(ARM_SP805_TWDG_BASE, 1U);
45*37b70031SAmbroise Vincent 
46*37b70031SAmbroise Vincent 	for (;;)
47*37b70031SAmbroise Vincent 		wfi();
48*37b70031SAmbroise Vincent }
49