Skip to content

Commit a6e7604

Browse files
committed
Adding usage scenarios
1 parent 28a0b45 commit a6e7604

File tree

1 file changed

+77
-11
lines changed

1 file changed

+77
-11
lines changed

docs/design-documents/platform/crash-reporting/crash_reporting.md

Lines changed: 77 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
### Overview and background
2828

29-
MbedOS currently implements error/exception handlers which gets invoked when the system encounters a fatal error/exception. The error handler capture information such as register context/thread info etc and these are valuable information required to debug the issue later. This information is currently printed over the serial port, but in many cases the serial port is not accessible and the serial terminal log is not captured, particularly in the case of field deployed devices. We cannot send this information using mechanisms like Network because the state of the system might be unstable after the fatal error. And thus a different mechanism is needed to record and report this data. So, if we can auto-reboot the system after a fatal error has occured, without losing the RAM contents where we have the error information collected, we can send this information over network or other interfaces to be logged externally(E.g:- ARM Pelion cloud) or can even be written to file system if required.
29+
MbedOS currently implements error/exception handlers which gets invoked when the system encounters a fatal error/exception. The error handler capture information such as register context/thread info etc and these are valuable information required to debug the issue later. This information is currently printed over the serial port, but in many cases the serial port is not accessible and the serial terminal log is not captured, particularly in the case of field deployed devices. We cannot send this information using mechanisms like Network because the state of the system might be unstable after the fatal error. And thus a different mechanism is needed to record and report this data. So, if we can auto-reboot the system after a fatal error has occurred, without losing the RAM contents where we have the error information collected, we can send this information over network or other interfaces to be logged externally(E.g:- ARM Pelion cloud) or can even be written to file system if required.
3030

3131
### Requirements and assumptions
3232

@@ -38,7 +38,7 @@ Below are the high-level design goals for "Crash Reporting" feature:
3838

3939
**Error information collection including exception context**
4040

41-
The current error handling implementation in Mbed OS already collects error and exception context. With this feature the above mentioned data structures should be placed in an uninitialized RAM region so that the data is retained after an auto-reboot(warm-reset).
41+
The current error handling implementation in MbedOS already collects error and exception context. With this feature the above mentioned data structures should be placed in an uninitialized RAM region so that the data is retained after an auto-reboot(warm-reset).
4242

4343
**Mechanism to auto reboot(also called warm-reset) the system without losing RAM contents where error info is stored**
4444

@@ -84,7 +84,7 @@ Note that the actual location of the data should be carefully chosen without aff
8484

8585
### Mechanism to auto reboot(also called warm-reset) the system without losing RAM contents where error info is stored
8686

87-
The current mbed_error() implementation should be modified to cause an auto-reboot at the end of error handling if this feature is enabled. The mechanism used for rebooting should make sure it doesn't cause a reset of RAM contents. This can be done by calling system_reset() function already implemented by MbedOS which cause the system to reboot without resetting the RAM. The mbed_error() implementation also should make sure it updates the error context stored in Crash-Report RAM with the right CRC value and it should also implement mechanism to track the reboot count caused by fatal errors. The below psuedo-code shows how the mbed_error() implementation should be modified.
87+
The current mbed_error() implementation should be modified to cause an auto-reboot at the end of error handling if this feature is enabled. The mechanism used for rebooting should make sure it doesn't cause a reset of RAM contents. This can be done by calling system_reset() function already implemented by MbedOS which cause the system to reboot without resetting the RAM. The mbed_error() implementation also should make sure it updates the error context stored in Crash-Report RAM with the right CRC value and it should also implement mechanism to track the reboot count caused by fatal errors. The below pueudo-code shows how the mbed_error() implementation should be modified.
8888

8989
```
9090
mbed_error_status_t mbed_error( ... )
@@ -97,7 +97,7 @@ mbed_error_status_t mbed_error( ... )
9797
Update Reboot Count
9898
Calculate new CRC
9999
Update with new CRC value
100-
Else (if CRC doesnt match)
100+
Else (if CRC doesn't match)
101101
//This is the case when we dont have a crash report already stored.
102102
Update the location with new error information
103103
Set Reboot count to 1
@@ -118,21 +118,21 @@ The below APIs should be implemented.
118118

119119
The below API can be called by application to retrieve the error context captured in the Crash-Report RAM. The error context is copied into the location pointed by *error_info*. Note that the caller should allocate the memory for this location.
120120
The function should return MBED_ERROR_NOT_FOUND if there is no error context currently stored.
121-
```
121+
```C
122122
//Retrieve the reboot error context
123123
mbed_error_status_t mbed_get_reboot_error_info(mbed_error_ctx *error_info)
124124
```
125125
126126
The below API can be called by application to retrieve the fault context captured in the Crash-Report RAM. The error context is copied into the location pointed by *fault_context*. Note that the caller should allocate the memory for this location. Note that the fault context is valid only if the previous reboot was caused by an exception. Whether the previous reboot was caused by an exception can be determined from the error code stored in error context information retrieved using mbed_get_reboot_error_info() API above.
127127
The function should return MBED_ERROR_NOT_FOUND if there is no fault context currently stored.
128-
```
128+
```C
129129
//Call this function to retrieve the last reboot fault context
130130
mbed_error_status_t mbed_get_reboot_fault_context (mbed_fault_context_t *fault_context);
131131
```
132132

133133
The below API can be called by application to reset the error context captured in the Crash-Report RAM.
134134
The function should MBED_ERROR_NOT_FOUND if there is no error context currently stored.
135-
```
135+
```C
136136
//Reset the reboot error context
137137
mbed_error_status_t mbed_reset_reboot_error_info()
138138
```
@@ -145,10 +145,10 @@ MbedOS initialization sequence should be modified as shown in below diagram to r
145145

146146
![Error report on reboot](./diagrams/boot-error-report.jpg)
147147

148-
Below should be the siganture of the callback for reporting the error information.
148+
Below should be the signature of the callback for reporting the error information.
149149

150150
The error handing system in MbedOS will call this callback function if it detects that the current reboot has been caused by a fatal error. This function will be defined with MBED_WEAK attribute by default and applications wanting to process the error report should override this function in application implementation.
151-
```
151+
```CS
152152
void mbed_error_reboot_callback(mbed_error_ctx *error_context);
153153
```
154154
@@ -168,13 +168,79 @@ Crash reporting implementation should provide enough parameters to control diffe
168168
169169
# Usage scenarios and examples
170170
171-
Below (pseudocode) are some common usage scenarios using the new error reporting APIs.
171+
Below (pseudo code) are some common usage scenarios using the new error reporting APIs.
172172
173-
### Implementing crash reporting callback
173+
### Implementing crash reporting callback
174+
In order to implement the callback the user can override the default callback function(*mbed_error_reboot_callback()*) implemented with MBED_WEAK attribute in platform layer as below.
175+
176+
```C
177+
mbed_error_ctx my_error_ctx;
178+
//Callback during reboot
179+
void mbed_error_reboot_callback(mbed_error_ctx *error_context) {
180+
printf("Error callback received");
181+
//Copy the error context in a local struct for processing it later
182+
memcpy(&my_error_ctx, error_context, sizeof(mbed_error_ctx));
183+
}
184+
```
185+
The above function will be called during boot with a pointer to *error_context* structure.
174186

175187
### Retrieving error info after reboot
188+
The error context captured can be retrieved using mbed_get_reboot_error_info() API. See the below code
189+
for example usage of that API. In the example below, a status variable reboot_error_detected has been used to track the presence of error context capture.
190+
191+
```C
192+
mbed_error_ctx error_ctx;
193+
int reboot_error_detected = 0;
194+
195+
//Callback during reboot
196+
void mbed_error_reboot_callback(mbed_error_ctx *error_context) {
197+
printf("error callback received");
198+
reboot_error_detected = 1;
199+
}
200+
201+
// main() runs in its own thread in the OS
202+
int main() {
203+
204+
if(reboot_error_detected == 1) {
205+
if(MBED_SUCCESS == mbed_get_reboot_error_info(&error_ctx)) {
206+
printf("\nSuccessfully read error context\n");
207+
}
208+
//main continues...
209+
}
210+
```
176211
177212
### Retrieving fault context after reboot
213+
The fault context captured can be retrieved using mbed_get_reboot_fault_context() API. See the below code
214+
for example usage of that API. The example code below checks for error_status using the error context and then
215+
retrieves the fault context using mbed_get_reboot_fault_context() API.
216+
217+
```C
218+
mbed_error_ctx error_ctx;
219+
mbed_fault_context_t fault_ctx;
220+
int reboot_error_detected = 0;
221+
222+
//Callback during reboot
223+
void mbed_error_reboot_callback(mbed_error_ctx *error_context) {
224+
printf("error callback received");
225+
reboot_error_detected = 1;
226+
}
227+
228+
// main() runs in its own thread in the OS
229+
int main() {
230+
231+
if(reboot_error_detected == 1) {
232+
if(MBED_SUCCESS == mbed_get_reboot_error_info(&error_ctx)) {
233+
printf("\nRead in reboot info\n");
234+
if(error_ctx.error_status == MBED_ERROR_HARDFAULT_EXCEPTION) {
235+
if(MBED_SUCCESS == mbed_get_reboot_fault_context(&fault_ctx)) {
236+
printf("\nRead in fault context info\n");
237+
}
238+
}
239+
}
240+
}
241+
//main continues...
242+
}
243+
```
178244

179245
# Tools and configuration changes
180246

0 commit comments

Comments
 (0)