@@ -50,7 +50,7 @@ static mbed_error_ctx first_error_ctx = {0};
50
50
51
51
#if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
52
52
//Global for populating the context in exception handler
53
- static mbed_error_ctx * report_error_ctx = (mbed_error_ctx * )(( uint32_t ) ERROR_CONTEXT_LOCATION );
53
+ static mbed_error_ctx * const report_error_ctx = (mbed_error_ctx * )(ERROR_CONTEXT_LOCATION );
54
54
static bool is_reboot_error_valid = false;
55
55
#endif
56
56
@@ -66,13 +66,13 @@ static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsign
66
66
//we dont have many uses cases to create a C wrapper for MbedCRC and the data
67
67
//we calculate CRC on in this context is very less we will use a local
68
68
//implementation here.
69
- static unsigned int compute_crc32 (unsigned char * data , int datalen )
69
+ static unsigned int compute_crc32 (void * data , int datalen )
70
70
{
71
71
const unsigned int polynomial = 0x04C11DB7 ; /* divisor is 32bit */
72
72
unsigned int crc = 0 ; /* CRC value is 32bit */
73
73
74
- for ( ;datalen >=0 ; datalen -- ) {
75
- unsigned char b = * data ;
74
+ for ( ;datalen >=0 ; datalen -- ) {
75
+ unsigned char b = ( * ( unsigned char * ) data ) ;
76
76
crc ^= (unsigned int )(b << 24 ); /* move byte into upper 8bit */
77
77
for (int i = 0 ; i < 8 ; i ++ ) {
78
78
/* is MSB 1 */
@@ -200,9 +200,9 @@ mbed_error_status_t mbed_error_initialize(void)
200
200
{
201
201
#if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
202
202
uint32_t crc_val = 0 ;
203
- crc_val = compute_crc32 ( ( unsigned char * ) report_error_ctx , (( uint32_t ) & ( report_error_ctx -> crc_error_ctx ) - ( uint32_t ) report_error_ctx ) );
204
- //Read report_error_ctx and check if CRC is correct for report_error_ctx
205
- if ((report_error_ctx -> crc_error_ctx == crc_val ) && (report_error_ctx -> is_error_processed == 0 )) {
203
+ crc_val = compute_crc32 ( report_error_ctx , offsetof( mbed_error_ctx , crc_error_ctx ) );
204
+ //Read report_error_ctx and check if CRC is correct, and with valid status code
205
+ if ((report_error_ctx -> crc_error_ctx == crc_val ) && (report_error_ctx -> is_error_processed == 0 ) && ( report_error_ctx -> error_status < 0 )) {
206
206
is_reboot_error_valid = true;
207
207
#if MBED_CONF_PLATFORM_REBOOT_CRASH_REPORT_ENABLED && !defined(NDEBUG )
208
208
//Report the error info
@@ -214,14 +214,14 @@ mbed_error_status_t mbed_error_initialize(void)
214
214
215
215
//Enforce max-reboot only if auto reboot is enabled
216
216
#if MBED_CONF_PLATFORM_FATAL_ERROR_AUTO_REBOOT_ENABLED
217
- if ( report_error_ctx -> error_reboot_count > MBED_CONF_PLATFORM_ERROR_REBOOT_MAX ) {
217
+ if ( report_error_ctx -> error_reboot_count >= MBED_CONF_PLATFORM_ERROR_REBOOT_MAX ) {
218
218
//We have rebooted more than enough, hold the system here.
219
219
mbed_error_printf ("\n== Reboot count(=%ld) exceeded maximum, system halting ==\n" , report_error_ctx -> error_reboot_count );
220
220
mbed_halt_system ();
221
221
}
222
222
#endif
223
223
report_error_ctx -> is_error_processed = 1 ;//Set the flag that we already processed this error
224
- crc_val = compute_crc32 ( ( unsigned char * ) report_error_ctx , (( uint32_t ) & ( report_error_ctx -> crc_error_ctx ) - ( uint32_t ) report_error_ctx ) );
224
+ crc_val = compute_crc32 ( report_error_ctx , offsetof( mbed_error_ctx , crc_error_ctx ) );
225
225
report_error_ctx -> crc_error_ctx = crc_val ;
226
226
}
227
227
#endif
@@ -270,28 +270,26 @@ WEAK MBED_NORETURN mbed_error_status_t mbed_error(mbed_error_status_t error_stat
270
270
271
271
#if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
272
272
uint32_t crc_val = 0 ;
273
- crc_val = compute_crc32 ( ( unsigned char * ) report_error_ctx , (( uint32_t ) & ( report_error_ctx -> crc_error_ctx ) - ( uint32_t ) report_error_ctx ) );
273
+ crc_val = compute_crc32 ( report_error_ctx , offsetof( mbed_error_ctx , crc_error_ctx ) );
274
274
//Read report_error_ctx and check if CRC is correct for report_error_ctx
275
- if (report_error_ctx -> crc_error_ctx == crc_val ) {
275
+ if (report_error_ctx -> crc_error_ctx == crc_val ) {
276
276
uint32_t current_reboot_count = report_error_ctx -> error_reboot_count ;
277
277
last_error_ctx .error_reboot_count = current_reboot_count + 1 ;
278
278
} else {
279
279
last_error_ctx .error_reboot_count = 1 ;
280
280
}
281
281
last_error_ctx .is_error_processed = 0 ;//Set the flag that this is a new error
282
282
//Update the struct with crc
283
- last_error_ctx .crc_error_ctx = compute_crc32 ( ( unsigned char * ) & last_error_ctx , (( uint32_t ) & ( last_error_ctx . crc_error_ctx ) - ( uint32_t ) & last_error_ctx ) );
283
+ last_error_ctx .crc_error_ctx = compute_crc32 ( & last_error_ctx , offsetof( mbed_error_ctx , crc_error_ctx ) );
284
284
//Protect report_error_ctx while we update it
285
285
core_util_critical_section_enter ();
286
286
memcpy (report_error_ctx , & last_error_ctx , sizeof (mbed_error_ctx ));
287
287
core_util_critical_section_exit ();
288
288
//We need not call delete_mbed_crc(crc_obj) here as we are going to reset the system anyway, and calling delete while handling a fatal error may cause nested exception
289
- #if MBED_CONF_PLATFORM_FATAL_ERROR_AUTO_REBOOT_ENABLED
289
+ #if MBED_CONF_PLATFORM_FATAL_ERROR_AUTO_REBOOT_ENABLED && ( MBED_CONF_PLATFORM_ERROR_REBOOT_MAX > 0 )
290
290
system_reset ();//do a system reset to get the system rebooted
291
- while (1 );
292
291
#endif
293
292
#endif
294
-
295
293
mbed_halt_system ();
296
294
297
295
return MBED_ERROR_FAILED_OPERATION ;
@@ -325,12 +323,12 @@ mbed_error_status_t mbed_reset_reboot_error_info()
325
323
mbed_error_status_t mbed_reset_reboot_count ()
326
324
{
327
325
#if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
328
- if (is_reboot_error_valid ) {
326
+ if (is_reboot_error_valid ) {
329
327
uint32_t crc_val = 0 ;
330
328
core_util_critical_section_enter ();
331
329
report_error_ctx -> error_reboot_count = 0 ;//Set reboot count to 0
332
330
//Update CRC
333
- crc_val = compute_crc32 ( ( unsigned char * ) report_error_ctx , (( uint32_t ) & ( report_error_ctx -> crc_error_ctx ) - ( uint32_t ) report_error_ctx ) );
331
+ crc_val = compute_crc32 ( report_error_ctx , offsetof( mbed_error_ctx , crc_error_ctx ) );
334
332
report_error_ctx -> crc_error_ctx = crc_val ;
335
333
core_util_critical_section_exit ();
336
334
return MBED_SUCCESS ;
@@ -345,7 +343,7 @@ mbed_error_status_t mbed_get_reboot_error_info(mbed_error_ctx *error_info)
345
343
mbed_error_status_t status = MBED_ERROR_ITEM_NOT_FOUND ;
346
344
#if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
347
345
if (is_reboot_error_valid ) {
348
- if (error_info != NULL ) {
346
+ if (error_info != NULL ) {
349
347
memcpy (error_info , report_error_ctx , sizeof (mbed_error_ctx ));
350
348
status = MBED_SUCCESS ;
351
349
} else {
@@ -519,7 +517,7 @@ static void print_error_report(const mbed_error_ctx *ctx, const char *error_msg,
519
517
#endif
520
518
521
519
#if MBED_CONF_PLATFORM_ERROR_ALL_THREADS_INFO && defined(MBED_CONF_RTOS_PRESENT )
522
- if (print_thread_info == true ) {
520
+ if (print_thread_info ) {
523
521
mbed_error_printf ("\nNext:" );
524
522
print_thread (osRtxInfo .thread .run .next );
525
523
0 commit comments