Skip to content

Commit c6e9b3c

Browse files
ppryga-nordiccarlescufi
authored andcommitted
Bluetooth: hci: Extend VS fatal error for hard hault and assert
Extend current implementation of vendor-specific HCI events related with Zephyr Fatal Error. The extended event is able to carry Zephyr system wide fatal error as well as Controller related assertion. That gives a possibility to use the event by bt_ctlr_assert_handle or k_sys_fatal_error_handler to send information about unrecoverable failures over HCI interface. There are added two types of errors to Zephyr Fatal Error event: - system fault error like e.g. Hard Fault. This one caries reason of a fault and a stack frame in the data field. The stack frame is defined for Corte-M SoCs only. - Controller assert. The data field caries file name and line of code where an assert happened. Except that the extended event can be used by Host, it can serve as a debug mean to conformance testing of the Controller. Signed-off-by: Piotr Pryga <[email protected]>
1 parent 0aa116a commit c6e9b3c

File tree

2 files changed

+136
-8
lines changed

2 files changed

+136
-8
lines changed

doc/connectivity/bluetooth/api/hci.txt

Lines changed: 105 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,25 +1077,124 @@ Zephyr Fatal Error
10771077
==================
10781078

10791079
This event reports a fatal non-recoverable error from the local Controller.
1080+
The event may represent Hard Fault, Bluetooth Controller assert or some other
1081+
non-recoverable error. The content of the event depends on a type of error it
1082+
represents.
10801083

10811084
+-------------------------------+------------+-------------------------------+
10821085
| Event | Event Code | Event Parameters |
10831086
+-------------------------------+------------+-------------------------------+
10841087
| Fatal_Error | 0xFF | Subevent_Code, |
1085-
| | | Program_Counter, |
1086-
| | | Error_Info |
1088+
| | | Error_Data_Type, |
1089+
| | | Error_Data |
10871090
+-------------------------------+------------+-------------------------------+
10881091

1089-
The Error_Info provides a string representation of the occurred error. It may
1090-
include information like file name and line numbers.
1092+
The Error_Data_Type provides an information about what is the Error_Data size
1093+
and content.
10911094

1092-
Subevent_Code: Size: 1 Octet
1095+
Error_Data_Type: Size: 1 Octet
1096+
+--------------------+--------------------------------------+
1097+
| Value | Parameter Description |
1098+
+--------------------+--------------------------------------+
1099+
| 0x01 | Stack frame |
1100+
| 0x02 | Controller assert data |
1101+
| 0x03 | Trace data |
1102+
+--------------------+--------------------------------------+
1103+
1104+
Error_Data: Size: variable
1105+
+--------------------+--------------------------------------+
1106+
| Value | Parameter Description |
1107+
+--------------------+--------------------------------------+
1108+
| | Content and size of the parameter |
1109+
| | depends on the Error_Data_Type |
1110+
+--------------------+--------------------------------------+
1111+
1112+
Zephyr Fatal Error event with Stack Frame data represents a Hard Fault error.
1113+
The event is tightly related with an architecture of a CPU the Controller is
1114+
running on.
1115+
1116+
+------------------------+--------------------+
1117+
| Error Data Type | Parameters |
1118+
+------------------------+--------------------+
1119+
| Stack_Frame | Error_Reason, |
1120+
| | Cpu_Type, |
1121+
| | Cpu_Data |
1122+
+------------------------+--------------------+
1123+
1124+
The Cpu_Type provides information about architecture the event was
1125+
generated for. Cpu_Data size and content depends on Cpu_Type. This kind of a
1126+
Zephyr Fatal Error event may be generated by k_sys_fatal_error_handler.
1127+
1128+
Error_Reason: Size: 4 Octets
1129+
+--------------------+--------------------------------------+
1130+
| Value | Parameter Description |
1131+
+--------------------+--------------------------------------+
1132+
| 0xXXXXXXXX | The reason for the fatal error |
1133+
+--------------------+--------------------------------------+
1134+
1135+
Cpu Type: Size: 1 Octet
10931136
+--------------------+--------------------------------------+
10941137
| Value | Parameter Description |
10951138
+--------------------+--------------------------------------+
1096-
| 0x02 | Subevent code for Fatal Error event |
1139+
| 0x01 | Cortex-M |
10971140
+--------------------+--------------------------------------+
10981141

1142+
Cpu Data: Size: variable
1143+
+--------------------+--------------------------------------+
1144+
| Value | Parameter Description |
1145+
+--------------------+--------------------------------------+
1146+
| | CPU architecture dependent data that |
1147+
| | represent a stack frame |
1148+
+--------------------+--------------------------------------+
1149+
1150+
CPU Data Cortex-M:
1151+
+--------------------+----------+---------------------------------+
1152+
| Parameters | Size | Description |
1153+
+--------------------+----------+---------------------------------+
1154+
| a1 | 4 octets | General purpose register |
1155+
| a2 | 4 octets | General purpose register |
1156+
| a3 | 4 octets | General purpose register |
1157+
| a4 | 4 octets | General purpose register |
1158+
| ip | 4 octets | Instruction pointer register |
1159+
| lr | 4 octets | Link register |
1160+
| xpsr | 4 octets | Program status register |
1161+
+--------------------+--------------------------------------------+
1162+
1163+
Zephyr Fatal Error event with Controller Assert data can be generated by the
1164+
bt_ctlr_assert_handle.
1165+
1166+
+------------------------+--------------------+
1167+
| Error Data Type | Parameters |
1168+
+------------------------+--------------------+
1169+
| Controller_Assert_Data | File_Name |
1170+
| | Line_Number |
1171+
+------------------------+--------------------+
1172+
1173+
File Name: Size: variable
1174+
+--------------------+--------------------------------------+
1175+
| Value | Parameter Description |
1176+
+--------------------+--------------------------------------+
1177+
| | Null terminated string with file |
1178+
| | name where an assert happened |
1179+
+--------------------+--------------------------------------+
1180+
1181+
Line Number: Size: 4 Octets
1182+
+--------------------+--------------------------------------+
1183+
| Value | Parameter Description |
1184+
+--------------------+--------------------------------------+
1185+
| 0xXXXXXXXX | Line number where assert happened |
1186+
+--------------------+--------------------------------------+
1187+
1188+
Other kinds of a non-recoverable system errors can be represented by Zephyr
1189+
Fatal Error with Trace data.
1190+
1191+
+------------------------+--------------------+
1192+
| Error Data Type | Parameters |
1193+
+------------------------+--------------------+
1194+
| Trace_Data | Program_Counter |
1195+
| | Error_Info |
1196+
+------------------------+--------------------+
1197+
10991198
Program_Counter: Size: 8 Octets
11001199
+--------------------+--------------------------------------+
11011200
| Value | Parameter Description |

include/zephyr/bluetooth/hci_vs.h

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,34 @@ struct bt_hci_evt_vs {
216216
} __packed;
217217

218218
#define BT_HCI_EVT_VS_FATAL_ERROR 0x02
219-
struct bt_hci_evt_vs_fatal_error {
219+
220+
#define BT_HCI_EVT_VS_ERROR_DATA_TYPE_STACK_FRAME 0x01
221+
#define BT_HCI_EVT_VS_ERROR_DATA_TYPE_CTRL_ASSERT 0x02
222+
#define BT_HCI_EVT_VS_ERROR_DATA_TYPE_TRACE 0x03
223+
struct bt_hci_vs_fata_error_cpu_data_cortex_m {
224+
uint32_t a1;
225+
uint32_t a2;
226+
uint32_t a3;
227+
uint32_t a4;
228+
uint32_t ip;
229+
uint32_t lr;
230+
uint32_t xpsr;
231+
} __packed;
232+
#define BT_HCI_EVT_VS_ERROR_CPU_TYPE_CORTEX_M 0x01
233+
struct bt_hci_vs_fatal_error_stack_frame {
234+
uint32_t reason;
235+
uint8_t cpu_type;
236+
uint8_t cpu_data[0];
237+
} __packed;
238+
239+
struct bt_hci_evt_vs_fatal_error_trace_data {
220240
uint64_t pc;
221-
uint8_t err_info[0];
241+
uint8_t err_info[0];
242+
} __packed;
243+
244+
struct bt_hci_evt_vs_fatal_error {
245+
uint8_t type;
246+
uint8_t data[0];
222247
} __packed;
223248

224249
#define BT_HCI_VS_TRACE_LMP_TX 0x01
@@ -380,6 +405,10 @@ struct bt_hci_evt_mesh_scanning_report {
380405
struct bt_hci_evt_mesh_scan_report reports[0];
381406
} __packed;
382407

408+
struct net_buf *hci_vs_err_stack_frame(unsigned int reason, const z_arch_esf_t *esf);
409+
struct net_buf *hci_vs_err_trace(const char *file, uint32_t line, uint64_t pc);
410+
struct net_buf *hci_vs_err_assert(const char *file, uint32_t line);
411+
383412
#ifdef __cplusplus
384413
}
385414
#endif

0 commit comments

Comments
 (0)