Contiki-NG
Loading...
Searching...
No Matches
tz-fault.c
1/*
2 * Copyright (c) 2023, RISE Research Institutes of Sweden
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * 3. Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 * OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/*
35 * \file
36 * ARMv8-M fault handling.
37 * \author
38 * Nicolas Tsiftes <nicolas.tsiftes@ri.se>
39 * Niclas Finne <niclas.finne@ri.se>
40 */
41
42#include "contiki.h"
43#include "dev/watchdog.h"
44
45#include <arm_cmse.h>
46
47/*---------------------------------------------------------------------------*/
48#include "sys/log.h"
49#define LOG_MODULE "SecureFault"
50#define LOG_LEVEL LOG_LEVEL_INFO
51/*---------------------------------------------------------------------------*/
52/* Magic value to check for initialization */
53#define FAULT_MAGIC 0x12345678
54struct fault_info {
55 uint32_t magic;
56 uint32_t sfsr;
57 uint32_t sfar;
58};
59__attribute__((section(".noinit"))) volatile struct fault_info fault_info;
60/*---------------------------------------------------------------------------*/
61static void
62print_sfsr(uint32_t sfsr)
63{
64 if(sfsr & SAU_SFSR_LSERR_Msk) {
65 LOG_WARN_(" LSERR");
66 }
67 if(sfsr & SAU_SFSR_SFARVALID_Msk) {
68 LOG_WARN_(" SFARVALID");
69 }
70 if(sfsr & SAU_SFSR_LSPERR_Msk) {
71 LOG_WARN_(" LSPERR");
72 }
73 if(sfsr & SAU_SFSR_INVTRAN_Msk) {
74 LOG_WARN_(" INVTRAN");
75 }
76 if(sfsr & SAU_SFSR_AUVIOL_Msk) {
77 LOG_WARN_(" AUVIOL");
78 }
79 if(sfsr & SAU_SFSR_INVER_Msk) {
80 LOG_WARN_(" INVER");
81 }
82 if(sfsr & SAU_SFSR_INVIS_Msk) {
83 LOG_WARN_(" INVIS");
84 }
85 if(sfsr & SAU_SFSR_INVEP_Msk) {
86 LOG_WARN_(" INVEP");
87 }
88}
89/*---------------------------------------------------------------------------*/
90void
91SecureFault_Handler(void)
92{
93 fault_info.magic = FAULT_MAGIC;
94 fault_info.sfar = SAU->SFAR;
95 fault_info.sfsr = SAU->SFSR;
96 NVIC_SystemReset();
97}
98/*---------------------------------------------------------------------------*/
99void
100tz_fault_init(void)
101{
102 if(fault_info.magic == FAULT_MAGIC) {
103 fault_info.magic = 0;
104
105 LOG_WARN("Reboot caused by Secure Fault! Address 0x%"PRIx32
106 ", SFSR 0x%"PRIx32"\n",
107 fault_info.sfar, fault_info.sfsr);
108 LOG_WARN("Secure Fault status:");
109 print_sfsr(fault_info.sfsr);
110 LOG_WARN_("\n");
111 }
112}
113/*---------------------------------------------------------------------------*/
Header file for the logging system.