Skip to content

Commit f59b99d

Browse files
committed
Removing support for printing error-report after reboot and other minor fixes
1 parent 423b52e commit f59b99d

File tree

5 files changed

+48
-58
lines changed

5 files changed

+48
-58
lines changed

TESTS/host_tests/crash_reporting.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def test_steps(self):
5959
wait_after_reset = self.get_config_item('forced_reset_timeout')
6060
wait_after_reset = wait_after_reset if wait_after_reset is not None else DEFAULT_CYCLE_PERIOD
6161

62+
#Wait 2 seconds for system to init
63+
time.sleep(2.0)
6264
#self.send_kv(MSG_KEY_SYNC, MSG_VALUE_DUMMY)
6365
self.send_kv(MSG_KEY_DEVICE_ERROR, MSG_VALUE_DUMMY)
6466
time.sleep(5.0)

TESTS/mbed_platform/crash_reporting/main.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
#include "mbed.h"
1717
#include "mbed_error.h"
18+
#include "mbed_crash_data_offsets.h"
1819
#include "greentea-client/test_env.h"
1920
#include "unity/unity.h"
2021

@@ -29,33 +30,38 @@
2930
#define MSG_KEY_DEVICE_READY "crash_reporting_ready"
3031
#define MSG_KEY_DEVICE_ERROR "crash_reporting_inject_error"
3132

33+
static mbed_error_ctx saved_error_ctx = {0};
34+
3235
void mbed_error_reboot_callback(mbed_error_ctx *error_context)
3336
{
34-
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_OUT_OF_MEMORY, error_context->error_status);
35-
TEST_ASSERT_EQUAL_UINT(1, error_context->error_reboot_count);
37+
38+
TEST_ASSERT_EQUAL_UINT((uint32_t)error_context, ERROR_CONTEXT_LOCATION);
39+
memcpy(&saved_error_ctx, error_context, sizeof(mbed_error_ctx));
3640
mbed_reset_reboot_error_info();
3741

42+
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_OUT_OF_MEMORY, saved_error_ctx.error_status);
43+
TEST_ASSERT_EQUAL_UINT(1, saved_error_ctx.error_reboot_count);
44+
3845
//Send the ready msg to host to indicate test pass
3946
greentea_send_kv(MSG_KEY_DEVICE_READY, MSG_VALUE_DUMMY);
4047
}
4148

4249
void test_crash_reporting()
4350
{
51+
//Clear any previous status
52+
mbed_reset_reboot_error_info();
53+
4454
// Report readiness
4555
greentea_send_kv(MSG_KEY_DEVICE_READY, MSG_VALUE_DUMMY);
4656

4757
static char _key[MSG_KEY_LEN + 1] = { };
4858
static char _value[MSG_VALUE_LEN + 1] = { };
4959

50-
printf("\nWaiting for inject error\n");
5160
greentea_parse_kv(_key, _value, MSG_KEY_LEN, MSG_VALUE_LEN);
52-
printf("\nGot inject error\n");
5361
if (strcmp(_key, MSG_KEY_DEVICE_ERROR) == 0) {
54-
printf("\nErroring...\n");
5562
MBED_ERROR1(MBED_ERROR_OUT_OF_MEMORY, "Executing crash reporting test.", 0xDEADBAD);
5663
TEST_ASSERT_MESSAGE(0, "crash_reporting() error call failed.");
5764
}
58-
printf("\nWaiting for inject error");
5965
TEST_ASSERT_MESSAGE(0, "Unexpected message received.");
6066
}
6167

platform/mbed_error.c

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
#include <inttypes.h>
3838

3939
#ifndef NDEBUG
40-
#define ERROR_REPORT(ctx, error_msg, error_filename, error_line, print_thread_info) print_error_report(ctx, error_msg, error_filename, error_line, print_thread_info)
41-
static void print_error_report(const mbed_error_ctx *ctx, const char *, const char *error_filename, int error_line, bool print_thread_info);
40+
#define ERROR_REPORT(ctx, error_msg, error_filename, error_line) print_error_report(ctx, error_msg, error_filename, error_line)
41+
static void print_error_report(const mbed_error_ctx *ctx, const char *, const char *error_filename, int error_line);
4242
#else
43-
#define ERROR_REPORT(ctx, error_msg, error_filename, error_line, print_thread_info) ((void) 0)
43+
#define ERROR_REPORT(ctx, error_msg, error_filename, error_line) ((void) 0)
4444
#endif
4545

4646
static core_util_atomic_flag error_in_progress = CORE_UTIL_ATOMIC_FLAG_INIT;
@@ -71,8 +71,8 @@ static unsigned int compute_crc32(const void *data, int datalen)
7171
const unsigned int polynomial = 0x04C11DB7; /* divisor is 32bit */
7272
unsigned int crc = 0; /* CRC value is 32bit */
7373
unsigned char *buf = (unsigned char *)data;//use a temp variable to make code readable and to avoid typecasting issues.
74-
75-
for (; datalen>0; datalen-- ) {
74+
75+
for (; datalen > 0; datalen--) {
7676
unsigned char b = *buf++;
7777
crc ^= (unsigned int)(b << 24); /* move byte into upper 8bit */
7878
for (int i = 0; i < 8; i++) {
@@ -115,7 +115,7 @@ WEAK MBED_NORETURN void error(const char *format, ...)
115115
// Prevent recursion if error is called again during store+print attempt
116116
if (!core_util_atomic_flag_test_and_set(&error_in_progress)) {
117117
handle_error(MBED_ERROR_UNKNOWN, 0, NULL, 0, MBED_CALLER_ADDR());
118-
ERROR_REPORT(&last_error_ctx, "Fatal Run-time error", NULL, 0, true);
118+
ERROR_REPORT(&last_error_ctx, "Fatal Run-time error", NULL, 0);
119119

120120
#ifndef NDEBUG
121121
va_list arg;
@@ -202,32 +202,34 @@ mbed_error_status_t mbed_error_initialize(void)
202202
{
203203
#if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
204204
uint32_t crc_val = 0;
205-
205+
206206
//Just check if we have valid value for error_status, if error_status is positive(which is not valid), no need to check crc
207207
if (report_error_ctx->error_status < 0) {
208208
crc_val = compute_crc32(report_error_ctx, offsetof(mbed_error_ctx, crc_error_ctx));
209209
//Read report_error_ctx and check if CRC is correct, and with valid status code
210210
if ((report_error_ctx->crc_error_ctx == crc_val) && (report_error_ctx->is_error_processed == 0)) {
211211
is_reboot_error_valid = true;
212-
#if MBED_CONF_PLATFORM_REBOOT_CRASH_REPORT_ENABLED && !defined(NDEBUG)
213212
//Report the error info
214-
mbed_error_printf("\n== Your last reboot was triggered by an error, below is the error information ==");
215-
ERROR_REPORT(report_error_ctx, "System rebooted due to fatal error", MBED_FILENAME, __LINE__, false);
216-
#endif
213+
printf("\n== The system has been rebooted due to a fatal error. ==\n");
214+
217215
//Call the mbed_error_reboot_callback, this enables applications to do some handling before we do the handling
218216
mbed_error_reboot_callback(report_error_ctx);
219-
220-
//Enforce max-reboot only if auto reboot is enabled
217+
218+
//We let the callback reset the error info, so check if its still valid and do the rest only if its still valid.
219+
if (report_error_ctx->error_reboot_count < 0) {
220+
221+
//Enforce max-reboot only if auto reboot is enabled
221222
#if MBED_CONF_PLATFORM_FATAL_ERROR_AUTO_REBOOT_ENABLED
222-
if (report_error_ctx->error_reboot_count >= MBED_CONF_PLATFORM_ERROR_REBOOT_MAX) {
223-
//We have rebooted more than enough, hold the system here.
224-
mbed_error_printf("\n== Reboot count(=%ld) exceeded maximum, system halting ==\n", report_error_ctx->error_reboot_count);
225-
mbed_halt_system();
226-
}
223+
if (report_error_ctx->error_reboot_count >= MBED_CONF_PLATFORM_ERROR_REBOOT_MAX) {
224+
//We have rebooted more than enough, hold the system here.
225+
printf("\n== Reboot count(=%ld) exceeded maximum, system halting ==\n", report_error_ctx->error_reboot_count);
226+
mbed_halt_system();
227+
}
227228
#endif
228-
report_error_ctx->is_error_processed = 1;//Set the flag that we already processed this error
229-
crc_val = compute_crc32(report_error_ctx, offsetof(mbed_error_ctx, crc_error_ctx));
230-
report_error_ctx->crc_error_ctx = crc_val;
229+
report_error_ctx->is_error_processed = 1;//Set the flag that we already processed this error
230+
crc_val = compute_crc32(report_error_ctx, offsetof(mbed_error_ctx, crc_error_ctx));
231+
report_error_ctx->crc_error_ctx = crc_val;
232+
}
231233
}
232234
}
233235
#endif
@@ -270,7 +272,7 @@ WEAK MBED_NORETURN mbed_error_status_t mbed_error(mbed_error_status_t error_stat
270272
(void) handle_error(error_status, error_value, filename, line_number, MBED_CALLER_ADDR());
271273

272274
//On fatal errors print the error context/report
273-
ERROR_REPORT(&last_error_ctx, error_msg, filename, line_number, true);
275+
ERROR_REPORT(&last_error_ctx, error_msg, filename, line_number);
274276
}
275277

276278
#if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
@@ -447,7 +449,7 @@ static void print_threads_info(const osRtxThread_t *threads)
447449
#endif
448450

449451
#ifndef NDEBUG
450-
static void print_error_report(const mbed_error_ctx *ctx, const char *error_msg, const char *error_filename, int error_line, bool print_thread_info)
452+
static void print_error_report(const mbed_error_ctx *ctx, const char *error_msg, const char *error_filename, int error_line)
451453
{
452454
int error_code = MBED_GET_ERROR_CODE(ctx->error_status);
453455
int error_module = MBED_GET_ERROR_MODULE(ctx->error_status);
@@ -520,19 +522,17 @@ static void print_error_report(const mbed_error_ctx *ctx, const char *error_msg,
520522
#endif
521523

522524
#if MBED_CONF_PLATFORM_ERROR_ALL_THREADS_INFO && defined(MBED_CONF_RTOS_PRESENT)
523-
if (print_thread_info) {
524-
mbed_error_printf("\nNext:");
525-
print_thread(osRtxInfo.thread.run.next);
525+
mbed_error_printf("\nNext:");
526+
print_thread(osRtxInfo.thread.run.next);
526527

527-
mbed_error_printf("\nReady:");
528-
print_threads_info(osRtxInfo.thread.ready.thread_list);
528+
mbed_error_printf("\nReady:");
529+
print_threads_info(osRtxInfo.thread.ready.thread_list);
529530

530-
mbed_error_printf("\nWait:");
531-
print_threads_info(osRtxInfo.thread.wait_list);
531+
mbed_error_printf("\nWait:");
532+
print_threads_info(osRtxInfo.thread.wait_list);
532533

533-
mbed_error_printf("\nDelay:");
534-
print_threads_info(osRtxInfo.thread.delay_list);
535-
}
534+
mbed_error_printf("\nDelay:");
535+
print_threads_info(osRtxInfo.thread.delay_list);
536536
#endif
537537
mbed_error_printf(MBED_CONF_PLATFORM_ERROR_DECODE_HTTP_URL_STR, ctx->error_status);
538538
mbed_error_printf("\n-- MbedOS Error Info --\n");

platform/mbed_error.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,7 @@ void mbed_error_reboot_callback(mbed_error_ctx *error_context);
951951

952952
/**
953953
* Initialize error handling system, this is called by the mbed-os boot sequence. This is not required to be called by Application unless the boot sequence is overridden by the system implementation.
954-
* NOTE: This function also prints the error report to serial terminal if MBED_CONF_PLATFORM_REBOOT_CRASH_REPORT_ENABLED is enabled.
955-
* If MBED_CONF_PLATFORM_FATAL_ERROR_AUTO_REBOOT_ENABLED is enabled and if the current reboot count exceeds MBED_CONF_PLATFORM_ERROR_REBOOT_MAX the system will halt when this function is called,
954+
* NOTE: If MBED_CONF_PLATFORM_FATAL_ERROR_AUTO_REBOOT_ENABLED is enabled and if the current reboot count exceeds MBED_CONF_PLATFORM_ERROR_REBOOT_MAX the system will halt when this function is called,
956955
* and in such cases the caller will not get the control back. Also note that calling this function may trigger mbed_error_reboot_callback() if application side overides mbed_error_reboot_callback().
957956
* @return MBED_SUCCESS on success.
958957
*

platform/mbed_lib.json

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,6 @@
114114
"help": "Enables crash context capture when the system enters a fatal error/crash.",
115115
"value": false
116116
},
117-
"reboot-crash-report-enabled": {
118-
"help": "Enables crash context capture when the system enters a fatal error/crash.",
119-
"value": false
120-
},
121117
"error-reboot-max": {
122118
"help": "Maximum number of auto reboots permitted when an error happens.",
123119
"value": 1
@@ -139,67 +135,54 @@
139135
},
140136
"DISCO_L475VG_IOT01A": {
141137
"crash-capture-enabled": true,
142-
"reboot-crash-report-enabled": true,
143138
"fatal-error-auto-reboot-enabled": true
144139
},
145140
"K64F": {
146141
"crash-capture-enabled": true,
147-
"reboot-crash-report-enabled": true,
148142
"fatal-error-auto-reboot-enabled": true
149143
},
150144
"K66F": {
151145
"crash-capture-enabled": true,
152-
"reboot-crash-report-enabled": true,
153146
"fatal-error-auto-reboot-enabled": true
154147
},
155148
"NUCLEO_F429ZI": {
156149
"crash-capture-enabled": true,
157-
"reboot-crash-report-enabled": true,
158150
"fatal-error-auto-reboot-enabled": true
159151
},
160152
"NUCLEO_F746ZG": {
161153
"crash-capture-enabled": true,
162-
"reboot-crash-report-enabled": true,
163154
"fatal-error-auto-reboot-enabled": true
164155
},
165156
"NUCLEO_F767ZI": {
166157
"crash-capture-enabled": true,
167-
"reboot-crash-report-enabled": true,
168158
"fatal-error-auto-reboot-enabled": true
169159
},
170160
"NUCLEO_F439ZI": {
171161
"crash-capture-enabled": true,
172-
"reboot-crash-report-enabled": true,
173162
"fatal-error-auto-reboot-enabled": true
174163
},
175164
"UBLOX_EVK_ODIN_W2": {
176165
"crash-capture-enabled": true,
177-
"reboot-crash-report-enabled": true,
178166
"fatal-error-auto-reboot-enabled": true
179167
},
180168
"UBLOX_C030_U201": {
181169
"crash-capture-enabled": true,
182-
"reboot-crash-report-enabled": true,
183170
"fatal-error-auto-reboot-enabled": true
184171
},
185172
"NUMAKER_PFM_M487": {
186173
"crash-capture-enabled": true,
187-
"reboot-crash-report-enabled": true,
188174
"fatal-error-auto-reboot-enabled": true
189175
},
190176
"NRF52840_DK": {
191177
"crash-capture-enabled": true,
192-
"reboot-crash-report-enabled": true,
193178
"fatal-error-auto-reboot-enabled": true
194179
},
195180
"NUCLEO_L476RG": {
196181
"crash-capture-enabled": true,
197-
"reboot-crash-report-enabled": true,
198182
"fatal-error-auto-reboot-enabled": true
199183
},
200184
"NUCLEO_F411RE": {
201185
"crash-capture-enabled": true,
202-
"reboot-crash-report-enabled": true,
203186
"fatal-error-auto-reboot-enabled": true
204187
}
205188
}

0 commit comments

Comments
 (0)