xref: /rk3399_ARM-atf/plat/arm/common/arm_err.c (revision c948f77136c42a92d0bb660543a3600c36dcf7f1)
1 /*
2  * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <errno.h>
8 #include <stdint.h>
9 
10 #include <platform_def.h>
11 
12 #include <arch_helpers.h>
13 #include <common/debug.h>
14 #include <drivers/cfi/v2m_flash.h>
15 #include <drivers/console.h>
16 #include <plat/common/platform.h>
17 
18 #include <plat_arm.h>
19 
20 #pragma weak plat_arm_error_handler
21 
22 /*
23  * ARM common implementation for error handler
24  */
25 void __dead2 plat_arm_error_handler(int err)
26 {
27 	int ret;
28 
29 	switch (err) {
30 	case -ENOENT:
31 	case -EAUTH:
32 		/* Image load or authentication error. Erase the ToC */
33 		INFO("Erasing FIP ToC from flash...\n");
34 		(void)nor_unlock(PLAT_ARM_FIP_BASE);
35 		ret = nor_word_program(PLAT_ARM_FIP_BASE, 0);
36 		if (ret != 0) {
37 			ERROR("Cannot erase ToC\n");
38 		} else {
39 			INFO("Done\n");
40 		}
41 		break;
42 	default:
43 		/* Unexpected error */
44 		break;
45 	}
46 
47 	(void)console_flush();
48 
49 	/* Loop until the watchdog resets the system */
50 	for (;;)
51 		wfi();
52 }
53 
54 void __dead2 plat_error_handler(int err)
55 {
56 	plat_arm_error_handler(err);
57 }
58