diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2015-03-04 07:00:29 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2015-03-04 07:00:29 -0600 |
commit | bcbdb2135a6aca11ad081ab9a6c65e95a91ae78a (patch) | |
tree | a56f13e576e4b7ec58b709c95b40661dc536a673 | |
parent | ed21da90e783fc6b944413e69de0901b2aac4462 (diff) | |
download | px4-nuttx-bcbdb2135a6aca11ad081ab9a6c65e95a91ae78a.tar.gz px4-nuttx-bcbdb2135a6aca11ad081ab9a6c65e95a91ae78a.tar.bz2 px4-nuttx-bcbdb2135a6aca11ad081ab9a6c65e95a91ae78a.zip |
Add support for dumping board-specific information on assertion. From David Sidrane
-rw-r--r-- | nuttx/arch/arm/src/arm/up_assert.c | 6 | ||||
-rw-r--r-- | nuttx/arch/arm/src/armv6-m/up_assert.c | 5 | ||||
-rw-r--r-- | nuttx/arch/arm/src/armv7-a/arm_assert.c | 5 | ||||
-rw-r--r-- | nuttx/arch/arm/src/armv7-m/up_assert.c | 5 | ||||
-rw-r--r-- | nuttx/arch/arm/src/common/up_createstack.c | 1 | ||||
-rw-r--r-- | nuttx/arch/avr/src/common/up_assert.c | 4 | ||||
-rw-r--r-- | nuttx/arch/hc/src/m9s12/m9s12_assert.c | 5 | ||||
-rw-r--r-- | nuttx/arch/mips/src/mips32/up_assert.c | 4 | ||||
-rw-r--r-- | nuttx/arch/rgmp/src/nuttx.c | 4 | ||||
-rw-r--r-- | nuttx/arch/sh/src/common/up_assert.c | 4 | ||||
-rw-r--r-- | nuttx/arch/sim/src/up_head.c | 5 | ||||
-rw-r--r-- | nuttx/arch/x86/src/common/up_assert.c | 5 | ||||
-rw-r--r-- | nuttx/arch/z16/src/common/up_assert.c | 4 | ||||
-rw-r--r-- | nuttx/arch/z80/src/common/up_assert.c | 4 | ||||
-rw-r--r-- | nuttx/configs/Kconfig | 25 | ||||
-rw-r--r-- | nuttx/include/nuttx/board.h | 30 |
16 files changed, 116 insertions, 0 deletions
diff --git a/nuttx/arch/arm/src/arm/up_assert.c b/nuttx/arch/arm/src/arm/up_assert.c index d706c1bb3..427799d98 100644 --- a/nuttx/arch/arm/src/arm/up_assert.c +++ b/nuttx/arch/arm/src/arm/up_assert.c @@ -352,6 +352,12 @@ void up_assert(const uint8_t *filename, int lineno) lldbg("Assertion failed at file:%s line: %d\n", filename, lineno); #endif + up_dumpstate(); + +#ifdef CONFIG_BOARD_CRASHDUMP + board_crashdump(up_getsp(), g_readytorun.head, filename, lineno); +#endif + _up_assert(EXIT_FAILURE); } diff --git a/nuttx/arch/arm/src/armv6-m/up_assert.c b/nuttx/arch/arm/src/armv6-m/up_assert.c index 160ced2f9..7b143d819 100644 --- a/nuttx/arch/arm/src/armv6-m/up_assert.c +++ b/nuttx/arch/arm/src/armv6-m/up_assert.c @@ -369,5 +369,10 @@ void up_assert(const uint8_t *filename, int lineno) #endif up_dumpstate(); + +#ifdef CONFIG_BOARD_CRASHDUMP + board_crashdump(up_getsp(), g_readytorun.head, filename, lineno); +#endif + _up_assert(EXIT_FAILURE); } diff --git a/nuttx/arch/arm/src/armv7-a/arm_assert.c b/nuttx/arch/arm/src/armv7-a/arm_assert.c index 3ee0e2ffe..501119d3a 100644 --- a/nuttx/arch/arm/src/armv7-a/arm_assert.c +++ b/nuttx/arch/arm/src/armv7-a/arm_assert.c @@ -367,5 +367,10 @@ void up_assert(const uint8_t *filename, int lineno) filename, lineno); #endif up_dumpstate(); + +#ifdef CONFIG_BOARD_CRASHDUMP + board_crashdump(up_getsp(), g_readytorun.head, filename, lineno); +#endif + _up_assert(EXIT_FAILURE); } diff --git a/nuttx/arch/arm/src/armv7-m/up_assert.c b/nuttx/arch/arm/src/armv7-m/up_assert.c index f663802e0..56c6b4457 100644 --- a/nuttx/arch/arm/src/armv7-m/up_assert.c +++ b/nuttx/arch/arm/src/armv7-m/up_assert.c @@ -378,5 +378,10 @@ void up_assert(const uint8_t *filename, int lineno) #endif up_dumpstate(); + +#ifdef CONFIG_BOARD_CRASHDUMP + board_crashdump(up_getsp(), g_readytorun.head, filename, lineno); +#endif + _up_assert(EXIT_FAILURE); } diff --git a/nuttx/arch/arm/src/common/up_createstack.c b/nuttx/arch/arm/src/common/up_createstack.c index a7a49a9b7..460e1b235 100644 --- a/nuttx/arch/arm/src/common/up_createstack.c +++ b/nuttx/arch/arm/src/common/up_createstack.c @@ -46,6 +46,7 @@ #include <nuttx/kmalloc.h> #include <nuttx/arch.h> +#include <nuttx/board.h> #include <arch/board/board.h> #include "up_arch.h" diff --git a/nuttx/arch/avr/src/common/up_assert.c b/nuttx/arch/avr/src/common/up_assert.c index 3ee369767..402556eb3 100644 --- a/nuttx/arch/avr/src/common/up_assert.c +++ b/nuttx/arch/avr/src/common/up_assert.c @@ -175,6 +175,10 @@ void up_assert(const uint8_t *filename, int lineno) up_dumpstate(); +#ifdef CONFIG_BOARD_CRASHDUMP + board_crashdump(up_getsp(), g_readytorun.head, filename, lineno); +#endif + #ifdef CONFIG_ARCH_USBDUMP /* Dump USB trace data */ diff --git a/nuttx/arch/hc/src/m9s12/m9s12_assert.c b/nuttx/arch/hc/src/m9s12/m9s12_assert.c index 479dfb005..efc5d6492 100644 --- a/nuttx/arch/hc/src/m9s12/m9s12_assert.c +++ b/nuttx/arch/hc/src/m9s12/m9s12_assert.c @@ -337,5 +337,10 @@ void up_assert(const uint8_t *filename, int lineno) #endif up_dumpstate(); + +#ifdef CONFIG_BOARD_CRASHDUMP + board_crashdump(up_getsp(), g_readytorun.head, filename, lineno); +#endif + _up_assert(EXIT_FAILURE); } diff --git a/nuttx/arch/mips/src/mips32/up_assert.c b/nuttx/arch/mips/src/mips32/up_assert.c index f768f5d6a..29cd6d737 100644 --- a/nuttx/arch/mips/src/mips32/up_assert.c +++ b/nuttx/arch/mips/src/mips32/up_assert.c @@ -181,5 +181,9 @@ void up_assert(const uint8_t *filename, int lineno) (void)usbtrace_enumerate(assert_tracecallback, NULL); #endif +#ifdef CONFIG_BOARD_CRASHDUMP + board_crashdump(up_getsp(), g_readytorun.head, filename, lineno); +#endif + _up_assert(EXIT_FAILURE); } diff --git a/nuttx/arch/rgmp/src/nuttx.c b/nuttx/arch/rgmp/src/nuttx.c index dc5478bd2..893ee5cc9 100644 --- a/nuttx/arch/rgmp/src/nuttx.c +++ b/nuttx/arch/rgmp/src/nuttx.c @@ -487,6 +487,10 @@ void up_assert(const uint8_t *filename, int line) { fprintf(stderr, "Assertion failed at file:%s line: %d\n", filename, line); +#ifdef CONFIG_BOARD_CRASHDUMP + board_crashdump(up_getsp(), g_readytorun.head, filename, line); +#endif + // in interrupt context or idle task means kernel error // which will stop the OS // if in user space just terminate the task diff --git a/nuttx/arch/sh/src/common/up_assert.c b/nuttx/arch/sh/src/common/up_assert.c index 2814083d6..127f79d5e 100644 --- a/nuttx/arch/sh/src/common/up_assert.c +++ b/nuttx/arch/sh/src/common/up_assert.c @@ -169,5 +169,9 @@ void up_assert(const uint8_t *filename, int lineno) (void)usbtrace_enumerate(assert_tracecallback, NULL); #endif +#ifdef CONFIG_BOARD_CRASHDUMP + board_crashdump(up_getsp(), g_readytorun.head, filename, lineno); +#endif + _up_assert(EXIT_FAILURE); } diff --git a/nuttx/arch/sim/src/up_head.c b/nuttx/arch/sim/src/up_head.c index 128936183..24c764636 100644 --- a/nuttx/arch/sim/src/up_head.c +++ b/nuttx/arch/sim/src/up_head.c @@ -81,5 +81,10 @@ int main(int argc, char **argv, char **envp) void up_assert(const uint8_t *filename, int line) { fprintf(stderr, "Assertion failed at file:%s line: %d\n", filename, line); + +#ifdef CONFIG_BOARD_CRASHDUMP + board_crashdump(up_getsp(), g_readytorun.head, filename, line); +#endif + longjmp(sim_abort, 1); } diff --git a/nuttx/arch/x86/src/common/up_assert.c b/nuttx/arch/x86/src/common/up_assert.c index 0288702c3..a3b82d3b7 100644 --- a/nuttx/arch/x86/src/common/up_assert.c +++ b/nuttx/arch/x86/src/common/up_assert.c @@ -299,5 +299,10 @@ void up_assert(const uint8_t *filename, int lineno) #endif up_dumpstate(); + +#ifdef CONFIG_BOARD_CRASHDUMP + board_crashdump(up_getsp(), g_readytorun.head, filename, lineno); +#endif + _up_assert(EXIT_FAILURE); } diff --git a/nuttx/arch/z16/src/common/up_assert.c b/nuttx/arch/z16/src/common/up_assert.c index 729a10bcb..55d985357 100644 --- a/nuttx/arch/z16/src/common/up_assert.c +++ b/nuttx/arch/z16/src/common/up_assert.c @@ -181,5 +181,9 @@ void up_assert(void) (void)usbtrace_enumerate(assert_tracecallback, NULL); #endif +#ifdef CONFIG_BOARD_CRASHDUMP + board_crashdump(up_getsp(), g_readytorun.head, filename, lineno); +#endif + _up_assert(EXIT_FAILURE); } diff --git a/nuttx/arch/z80/src/common/up_assert.c b/nuttx/arch/z80/src/common/up_assert.c index 1ae825e4c..be886dc44 100644 --- a/nuttx/arch/z80/src/common/up_assert.c +++ b/nuttx/arch/z80/src/common/up_assert.c @@ -180,5 +180,9 @@ void up_assert(void) (void)usbtrace_enumerate(assert_tracecallback, NULL); #endif +#ifdef CONFIG_BOARD_CRASHDUMP + board_crashdump(up_getsp(), g_readytorun.head, filename, lineno); +#endif + _up_assert(EXIT_FAILURE); } diff --git a/nuttx/configs/Kconfig b/nuttx/configs/Kconfig index a3f04406c..58583c015 100644 --- a/nuttx/configs/Kconfig +++ b/nuttx/configs/Kconfig @@ -1043,6 +1043,31 @@ config ARCH_BOARD_CUSTOM_DIR to some location outside of the NuttX source tree (like "~/projects/myboard"). +config BOARD_CRASHDUMP + bool "Enable Board level logging of crash dumps" + default n + ---help--- + If selected up_asseert will call out to board_crashdump, in the case + of an assertion failure, prior to calling exit. Or in the + case of a hardfault prior to looping indefinitely. board_crashdump + then has a chance to save the state of the machine. + + The purpose of board_crashdump is to save as much information as it can + about the cause of the fault and then most likely reset the system. + + N.B. There is limited system resources that can be used, who knows + what memory is trashed? So all we can expect to do is save the + "machine state" in a place where on the next reset can write it + to more sophisticated storage in a sane operating environment. + +config BOARD_RESET_ON_CRASH + bool "Eanble Board Reset after the crashdump is saved" + default n + depends on BOARD_CRASHDUMP + ---help--- + If selected the board_crashdump should reset the machine after + saveing the state of the machine + config BOARD_CUSTOM_LEDS bool "Custom board LEDs" default n diff --git a/nuttx/include/nuttx/board.h b/nuttx/include/nuttx/board.h index 55aa85b60..4c9e1731f 100644 --- a/nuttx/include/nuttx/board.h +++ b/nuttx/include/nuttx/board.h @@ -291,4 +291,34 @@ uint8_t board_buttons(void); xcpt_t board_button_irq(int id, xcpt_t irqhandler); #endif +/**************************************************************************** + * Name: board_crashdump + * + * Description: + * If CONFIG_BOARD_CRASHDUMP is selected then up_asseert will call out to + * board_crashdump prior to calling exit in the case of an assertion failure. + * Or in the case of a hardfault looping indefinitely. board_crashdump then + * has a chance to save the state of the machine. The provided + * board_crashdump should save as much information as it can about the cause + * of the fault and then most likely reset the system. + * + * N.B. There are limited system resources that can be used by the provided + * board_crashdump function. The tems from the fact that most critical/fatal + * crashes are because of a hard fault or during interrupt processing. + * In these cases, up_assert is running from the context of an interrupt + * handlerand it is impossible to use any device driver in this context. + * + * Also consider the following: Who knows what state the system is in? Is + * memory trashed? Is the Heap intact? Therefore all we can expect to do in + * board_crashdump is save the "machine state" in a place where on the next + * reset we can write it to more sophisticated storage in a sane operating + * environment. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARD_CRASHDUMP +void board_crashdump(uint32_t currentsp, void *tcb, uint8_t *filename, + int lineno); +#endif + #endif /* __INCLUDE_NUTTX_BOARD_H */ |