1 /*
2  * Copyright 2018-2020 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include <errno.h>
9 #include <stdbool.h>
10 #include <stdint.h>
11 
12 #include <arch_helpers.h>
13 #include <common/debug.h>
14 
15 #if TRUSTED_BOARD_BOOT
16 #include <dcfg.h>
17 #include <snvs.h>
18 #endif
19 
20 #include "plat_common.h"
21 
22 /*
23  * Error handler
24  */
plat_error_handler(int err)25 void plat_error_handler(int err)
26 {
27 #if TRUSTED_BOARD_BOOT
28 	uint32_t mode;
29 	bool sb = check_boot_mode_secure(&mode);
30 #endif
31 
32 	switch (err) {
33 	case -ENOENT:
34 	case -EAUTH:
35 		printf("Authentication failure\n");
36 #if TRUSTED_BOARD_BOOT
37 		/* For SB production mode i.e ITS = 1 */
38 		if (sb == true) {
39 			if (mode == 1U) {
40 				transition_snvs_soft_fail();
41 			} else {
42 				transition_snvs_non_secure();
43 			}
44 		}
45 #endif
46 		break;
47 	default:
48 		/* Unexpected error */
49 		break;
50 	}
51 
52 	/* Loop until the watchdog resets the system */
53 	for (;;)
54 		wfi();
55 }
56