From 163bcc4bbc82283ef37c3e5dab11c1ab621d73cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Fri, 20 Jan 2017 13:21:33 -0800 Subject: [PATCH] drivers: boards: Share board_crashdump() implementation --- src/drivers/boards/aerofc-v1/CMakeLists.txt | 1 + src/drivers/boards/aerofc-v1/aerofc_init.c | 153 ---------------- src/drivers/boards/auav-x21/CMakeLists.txt | 1 + src/drivers/boards/auav-x21/auav_init.c | 157 ----------------- .../boards/common/stm32/board_crashdump.c | 165 ++++++++++++++++++ src/drivers/boards/crazyflie/CMakeLists.txt | 1 + src/drivers/boards/crazyflie/crazyflie_init.c | 154 ---------------- src/drivers/boards/mindpx-v2/CMakeLists.txt | 1 + src/drivers/boards/mindpx-v2/mindpx2_init.c | 154 ---------------- src/drivers/boards/px4fmu-v2/CMakeLists.txt | 1 + src/drivers/boards/px4fmu-v2/px4fmu2_init.c | 150 ---------------- src/drivers/boards/px4fmu-v4/CMakeLists.txt | 1 + src/drivers/boards/px4fmu-v4/px4fmu_init.c | 154 ---------------- .../boards/px4fmu-v4pro/CMakeLists.txt | 1 + src/drivers/boards/px4fmu-v4pro/px4fmu_init.c | 154 ---------------- src/drivers/boards/px4fmu-v5/CMakeLists.txt | 1 + src/drivers/boards/px4fmu-v5/px4fmu_init.c | 154 ---------------- .../boards/px4nucleoF767ZI-v1/CMakeLists.txt | 1 + .../px4nucleoF767ZI-v1/px4nucleo_init.c | 154 ---------------- src/drivers/boards/tap-v1/CMakeLists.txt | 1 + src/drivers/boards/tap-v1/tap_init.c | 154 ---------------- 21 files changed, 175 insertions(+), 1538 deletions(-) create mode 100644 src/drivers/boards/common/stm32/board_crashdump.c diff --git a/src/drivers/boards/aerofc-v1/CMakeLists.txt b/src/drivers/boards/aerofc-v1/CMakeLists.txt index 409c5b1e72..1b39e1a4c1 100644 --- a/src/drivers/boards/aerofc-v1/CMakeLists.txt +++ b/src/drivers/boards/aerofc-v1/CMakeLists.txt @@ -35,6 +35,7 @@ px4_add_module( MODULE drivers__boards__aerofc-v1 COMPILE_FLAGS SRCS + ../common/stm32/board_crashdump.c aerofc_init.c aerofc_spi.c aerofc_usb.c diff --git a/src/drivers/boards/aerofc-v1/aerofc_init.c b/src/drivers/boards/aerofc-v1/aerofc_init.c index 19a5a10207..6f912497b1 100644 --- a/src/drivers/boards/aerofc-v1/aerofc_init.c +++ b/src/drivers/boards/aerofc-v1/aerofc_init.c @@ -366,156 +366,3 @@ __EXPORT int board_app_initialize(uintptr_t arg) return OK; } -static void copy_reverse(stack_word_t *dest, stack_word_t *src, int size) -{ - while (size--) { - *dest++ = *src--; - } -} - -__EXPORT void board_crashdump(uintptr_t currentsp, FAR void *tcb, FAR const uint8_t *filename, int lineno) -{ - /* We need a chunk of ram to save the complete context in. - * Since we are going to reboot we will use &_sdata - * which is the lowest memory and the amount we will save - * _should be_ below any resources we need herein. - * Unfortunately this is hard to test. See dead below - */ - - fullcontext_s *pdump = (fullcontext_s *)&_sdata; - - (void)enter_critical_section(); - - struct tcb_s *rtcb = (struct tcb_s *)tcb; - - /* Zero out everything */ - - memset(pdump, 0, sizeof(fullcontext_s)); - - /* Save Info */ - - pdump->info.lineno = lineno; - - if (filename) { - - int offset = 0; - unsigned int len = strlen((char *)filename) + 1; - - if (len > sizeof(pdump->info.filename)) { - offset = len - sizeof(pdump->info.filename) ; - } - - strncpy(pdump->info.filename, (char *)&filename[offset], sizeof(pdump->info.filename)); - } - - /* Save the value of the pointer for current_regs as debugging info. - * It should be NULL in case of an ASSERT and will aid in cross - * checking the validity of system memory at the time of the - * fault. - */ - - pdump->info.current_regs = (uintptr_t) CURRENT_REGS; - - /* Save Context */ - - -#if CONFIG_TASK_NAME_SIZE > 0 - strncpy(pdump->info.name, rtcb->name, CONFIG_TASK_NAME_SIZE); -#endif - - pdump->info.pid = rtcb->pid; - - - /* If current_regs is not NULL then we are in an interrupt context - * and the user context is in current_regs else we are running in - * the users context - */ - - if (CURRENT_REGS) { - pdump->info.stacks.interrupt.sp = currentsp; - - pdump->info.flags |= (eRegsPresent | eUserStackPresent | eIntStackPresent); - memcpy(pdump->info.regs, (void *)CURRENT_REGS, sizeof(pdump->info.regs)); - pdump->info.stacks.user.sp = pdump->info.regs[REG_R13]; - - } else { - - /* users context */ - pdump->info.flags |= eUserStackPresent; - - pdump->info.stacks.user.sp = currentsp; - } - - if (pdump->info.pid == 0) { - - pdump->info.stacks.user.top = g_idle_topstack - 4; - pdump->info.stacks.user.size = CONFIG_IDLETHREAD_STACKSIZE; - - } else { - pdump->info.stacks.user.top = (uint32_t) rtcb->adj_stack_ptr; - pdump->info.stacks.user.size = (uint32_t) rtcb->adj_stack_size;; - } - -#if CONFIG_ARCH_INTERRUPTSTACK > 3 - - /* Get the limits on the interrupt stack memory */ - - pdump->info.stacks.interrupt.top = (uint32_t)&g_intstackbase; - pdump->info.stacks.interrupt.size = (CONFIG_ARCH_INTERRUPTSTACK & ~3); - - /* If In interrupt Context save the interrupt stack data centered - * about the interrupt stack pointer - */ - - if ((pdump->info.flags & eIntStackPresent) != 0) { - stack_word_t *ps = (stack_word_t *) pdump->info.stacks.interrupt.sp; - copy_reverse(pdump->istack, &ps[arraySize(pdump->istack) / 2], arraySize(pdump->istack)); - } - - /* Is it Invalid? */ - - if (!(pdump->info.stacks.interrupt.sp <= pdump->info.stacks.interrupt.top && - pdump->info.stacks.interrupt.sp > pdump->info.stacks.interrupt.top - pdump->info.stacks.interrupt.size)) { - pdump->info.flags |= eInvalidIntStackPrt; - } - -#endif - - /* If In interrupt context or User save the user stack data centered - * about the user stack pointer - */ - if ((pdump->info.flags & eUserStackPresent) != 0) { - stack_word_t *ps = (stack_word_t *) pdump->info.stacks.user.sp; - copy_reverse(pdump->ustack, &ps[arraySize(pdump->ustack) / 2], arraySize(pdump->ustack)); - } - - /* Is it Invalid? */ - - if (!(pdump->info.stacks.user.sp <= pdump->info.stacks.user.top && - pdump->info.stacks.user.sp > pdump->info.stacks.user.top - pdump->info.stacks.user.size)) { - pdump->info.flags |= eInvalidUserStackPtr; - } - - int rv = stm32_bbsram_savepanic(HARDFAULT_FILENO, (uint8_t *)pdump, sizeof(fullcontext_s)); - - /* Test if memory got wiped because of using _sdata */ - - if (rv == -ENXIO) { - char *dead = "Memory wiped - dump not saved!"; - - while (*dead) { - up_lowputc(*dead++); - } - - } else if (rv == -ENOSPC) { - - /* hard fault again */ - - up_lowputc('!'); - } - - -#if defined(CONFIG_BOARD_RESET_ON_CRASH) - px4_systemreset(false); -#endif -} diff --git a/src/drivers/boards/auav-x21/CMakeLists.txt b/src/drivers/boards/auav-x21/CMakeLists.txt index bce1a0c327..243e372356 100644 --- a/src/drivers/boards/auav-x21/CMakeLists.txt +++ b/src/drivers/boards/auav-x21/CMakeLists.txt @@ -34,6 +34,7 @@ px4_add_module( MODULE drivers__boards__auav-x21 COMPILE_FLAGS SRCS + ../common/stm32/board_crashdump.c ../common/board_dma_alloc.c auav_can.c auav_init.c diff --git a/src/drivers/boards/auav-x21/auav_init.c b/src/drivers/boards/auav-x21/auav_init.c index cef8a19c65..885f169d8e 100644 --- a/src/drivers/boards/auav-x21/auav_init.c +++ b/src/drivers/boards/auav-x21/auav_init.c @@ -473,160 +473,3 @@ __EXPORT int board_app_initialize(uintptr_t arg) return OK; } - -static void copy_reverse(stack_word_t *dest, stack_word_t *src, int size) -{ - while (size--) { - *dest++ = *src--; - } -} - -__EXPORT void board_crashdump(uintptr_t currentsp, FAR void *tcb, FAR const uint8_t *filename, int lineno) -{ - if (hardfault_check_status) { - /* We need a chunk of ram to save the complete context in. - * Since we are going to reboot we will use &_sdata - * which is the lowest memory and the amount we will save - * _should be_ below any resources we need herein. - * Unfortunately this is hard to test. See dead below - */ - - fullcontext_s *pdump = (fullcontext_s *)&_sdata; - - (void)enter_critical_section(); - - struct tcb_s *rtcb = (struct tcb_s *)tcb; - - /* Zero out everything */ - - memset(pdump, 0, sizeof(fullcontext_s)); - - /* Save Info */ - - pdump->info.lineno = lineno; - - if (filename) { - - int offset = 0; - unsigned int len = strlen((char *)filename) + 1; - - if (len > sizeof(pdump->info.filename)) { - offset = len - sizeof(pdump->info.filename) ; - } - - strncpy(pdump->info.filename, (char *)&filename[offset], sizeof(pdump->info.filename)); - } - - /* Save the value of the pointer for current_regs as debugging info. - * It should be NULL in case of an ASSERT and will aid in cross - * checking the validity of system memory at the time of the - * fault. - */ - - pdump->info.current_regs = (uintptr_t) CURRENT_REGS; - - /* Save Context */ - - -#if CONFIG_TASK_NAME_SIZE > 0 - strncpy(pdump->info.name, rtcb->name, CONFIG_TASK_NAME_SIZE); -#endif - - pdump->info.pid = rtcb->pid; - - - /* If current_regs is not NULL then we are in an interrupt context - * and the user context is in current_regs else we are running in - * the users context - */ - - if (CURRENT_REGS) { - pdump->info.stacks.interrupt.sp = currentsp; - - pdump->info.flags |= (eRegsPresent | eUserStackPresent | eIntStackPresent); - memcpy(pdump->info.regs, (void *)CURRENT_REGS, sizeof(pdump->info.regs)); - pdump->info.stacks.user.sp = pdump->info.regs[REG_R13]; - - } else { - - /* users context */ - pdump->info.flags |= eUserStackPresent; - - pdump->info.stacks.user.sp = currentsp; - } - - if (pdump->info.pid == 0) { - - pdump->info.stacks.user.top = g_idle_topstack - 4; - pdump->info.stacks.user.size = CONFIG_IDLETHREAD_STACKSIZE; - - } else { - pdump->info.stacks.user.top = (uint32_t) rtcb->adj_stack_ptr; - pdump->info.stacks.user.size = (uint32_t) rtcb->adj_stack_size;; - } - -#if CONFIG_ARCH_INTERRUPTSTACK > 3 - - /* Get the limits on the interrupt stack memory */ - - pdump->info.stacks.interrupt.top = (uint32_t)&g_intstackbase; - pdump->info.stacks.interrupt.size = (CONFIG_ARCH_INTERRUPTSTACK & ~3); - - /* If In interrupt Context save the interrupt stack data centered - * about the interrupt stack pointer - */ - - if ((pdump->info.flags & eIntStackPresent) != 0) { - stack_word_t *ps = (stack_word_t *) pdump->info.stacks.interrupt.sp; - copy_reverse(pdump->istack, &ps[arraySize(pdump->istack) / 2], arraySize(pdump->istack)); - } - - /* Is it Invalid? */ - - if (!(pdump->info.stacks.interrupt.sp <= pdump->info.stacks.interrupt.top && - pdump->info.stacks.interrupt.sp > pdump->info.stacks.interrupt.top - pdump->info.stacks.interrupt.size)) { - pdump->info.flags |= eInvalidIntStackPrt; - } - -#endif - - /* If In interrupt context or User save the user stack data centered - * about the user stack pointer - */ - if ((pdump->info.flags & eUserStackPresent) != 0) { - stack_word_t *ps = (stack_word_t *) pdump->info.stacks.user.sp; - copy_reverse(pdump->ustack, &ps[arraySize(pdump->ustack) / 2], arraySize(pdump->ustack)); - } - - /* Is it Invalid? */ - - if (!(pdump->info.stacks.user.sp <= pdump->info.stacks.user.top && - pdump->info.stacks.user.sp > pdump->info.stacks.user.top - pdump->info.stacks.user.size)) { - pdump->info.flags |= eInvalidUserStackPtr; - } - - int rv = stm32_bbsram_savepanic(HARDFAULT_FILENO, (uint8_t *)pdump, sizeof(fullcontext_s)); - - /* Test if memory got wiped because of using _sdata */ - - if (rv == -ENXIO) { - char *dead = "Memory wiped - dump not saved!"; - - while (*dead) { - up_lowputc(*dead++); - } - - } else if (rv == -ENOSPC) { - - /* hard fault again */ - - up_lowputc('!'); - } - - -#if defined(CONFIG_BOARD_RESET_ON_CRASH) - px4_systemreset(false); -#endif - } // hardfault_check_status - -} diff --git a/src/drivers/boards/common/stm32/board_crashdump.c b/src/drivers/boards/common/stm32/board_crashdump.c new file mode 100644 index 0000000000..cdaa4a793c --- /dev/null +++ b/src/drivers/boards/common/stm32/board_crashdump.c @@ -0,0 +1,165 @@ +#include +#include + +#include +#include + +#include + +#include "board_config.h" + +#include + +static void copy_reverse(stack_word_t *dest, stack_word_t *src, int size) +{ + while (size--) { + *dest++ = *src--; + } +} + +__EXPORT void board_crashdump(uintptr_t currentsp, FAR void *tcb, FAR const uint8_t *filename, int lineno) +{ + /* We need a chunk of ram to save the complete context in. + * Since we are going to reboot we will use &_sdata + * which is the lowest memory and the amount we will save + * _should be_ below any resources we need herein. + * Unfortunately this is hard to test. See dead below + */ + + fullcontext_s *pdump = (fullcontext_s *)&_sdata; + + (void)enter_critical_section(); + + struct tcb_s *rtcb = (struct tcb_s *)tcb; + + /* Zero out everything */ + + memset(pdump, 0, sizeof(fullcontext_s)); + + /* Save Info */ + + pdump->info.lineno = lineno; + + if (filename) { + + int offset = 0; + unsigned int len = strlen((char *)filename) + 1; + + if (len > sizeof(pdump->info.filename)) { + offset = len - sizeof(pdump->info.filename) ; + } + + strncpy(pdump->info.filename, (char *)&filename[offset], sizeof(pdump->info.filename)); + } + + /* Save the value of the pointer for current_regs as debugging info. + * It should be NULL in case of an ASSERT and will aid in cross + * checking the validity of system memory at the time of the + * fault. + */ + + pdump->info.current_regs = (uintptr_t) CURRENT_REGS; + + /* Save Context */ + + +#if CONFIG_TASK_NAME_SIZE > 0 + strncpy(pdump->info.name, rtcb->name, CONFIG_TASK_NAME_SIZE); +#endif + + pdump->info.pid = rtcb->pid; + + + /* If current_regs is not NULL then we are in an interrupt context + * and the user context is in current_regs else we are running in + * the users context + */ + + if (CURRENT_REGS) { + pdump->info.stacks.interrupt.sp = currentsp; + + pdump->info.flags |= (eRegsPresent | eUserStackPresent | eIntStackPresent); + memcpy(pdump->info.regs, (void *)CURRENT_REGS, sizeof(pdump->info.regs)); + pdump->info.stacks.user.sp = pdump->info.regs[REG_R13]; + + } else { + + /* users context */ + pdump->info.flags |= eUserStackPresent; + + pdump->info.stacks.user.sp = currentsp; + } + + if (pdump->info.pid == 0) { + + pdump->info.stacks.user.top = g_idle_topstack - 4; + pdump->info.stacks.user.size = CONFIG_IDLETHREAD_STACKSIZE; + + } else { + pdump->info.stacks.user.top = (uint32_t) rtcb->adj_stack_ptr; + pdump->info.stacks.user.size = (uint32_t) rtcb->adj_stack_size;; + } + +#if CONFIG_ARCH_INTERRUPTSTACK > 3 + + /* Get the limits on the interrupt stack memory */ + + pdump->info.stacks.interrupt.top = (uint32_t)&g_intstackbase; + pdump->info.stacks.interrupt.size = (CONFIG_ARCH_INTERRUPTSTACK & ~3); + + /* If In interrupt Context save the interrupt stack data centered + * about the interrupt stack pointer + */ + + if ((pdump->info.flags & eIntStackPresent) != 0) { + stack_word_t *ps = (stack_word_t *) pdump->info.stacks.interrupt.sp; + copy_reverse(pdump->istack, &ps[arraySize(pdump->istack) / 2], arraySize(pdump->istack)); + } + + /* Is it Invalid? */ + + if (!(pdump->info.stacks.interrupt.sp <= pdump->info.stacks.interrupt.top && + pdump->info.stacks.interrupt.sp > pdump->info.stacks.interrupt.top - pdump->info.stacks.interrupt.size)) { + pdump->info.flags |= eInvalidIntStackPrt; + } + +#endif + + /* If In interrupt context or User save the user stack data centered + * about the user stack pointer + */ + if ((pdump->info.flags & eUserStackPresent) != 0) { + stack_word_t *ps = (stack_word_t *) pdump->info.stacks.user.sp; + copy_reverse(pdump->ustack, &ps[arraySize(pdump->ustack) / 2], arraySize(pdump->ustack)); + } + + /* Is it Invalid? */ + + if (!(pdump->info.stacks.user.sp <= pdump->info.stacks.user.top && + pdump->info.stacks.user.sp > pdump->info.stacks.user.top - pdump->info.stacks.user.size)) { + pdump->info.flags |= eInvalidUserStackPtr; + } + + int rv = stm32_bbsram_savepanic(HARDFAULT_FILENO, (uint8_t *)pdump, sizeof(fullcontext_s)); + + /* Test if memory got wiped because of using _sdata */ + + if (rv == -ENXIO) { + char *dead = "Memory wiped - dump not saved!"; + + while (*dead) { + up_lowputc(*dead++); + } + + } else if (rv == -ENOSPC) { + + /* hard fault again */ + + up_lowputc('!'); + } + + +#if defined(CONFIG_BOARD_RESET_ON_CRASH) + px4_systemreset(false); +#endif +} diff --git a/src/drivers/boards/crazyflie/CMakeLists.txt b/src/drivers/boards/crazyflie/CMakeLists.txt index 1b2a7533bc..af26581758 100644 --- a/src/drivers/boards/crazyflie/CMakeLists.txt +++ b/src/drivers/boards/crazyflie/CMakeLists.txt @@ -33,6 +33,7 @@ px4_add_module( MODULE drivers__boards__crazyflie SRCS + ../common/stm32/board_crashdump.c ../common/board_dma_alloc.c crazyflie_init.c crazyflie_usb.c diff --git a/src/drivers/boards/crazyflie/crazyflie_init.c b/src/drivers/boards/crazyflie/crazyflie_init.c index e3c2cfe95f..2724e6cc2a 100644 --- a/src/drivers/boards/crazyflie/crazyflie_init.c +++ b/src/drivers/boards/crazyflie/crazyflie_init.c @@ -337,157 +337,3 @@ __EXPORT int board_app_initialize(uintptr_t arg) return OK; } - -static void copy_reverse(stack_word_t *dest, stack_word_t *src, int size) -{ - while (size--) { - *dest++ = *src--; - } -} - -__EXPORT void board_crashdump(uintptr_t currentsp, FAR void *tcb, FAR const uint8_t *filename, int lineno) -{ - /* We need a chunk of ram to save the complete context in. - * Since we are going to reboot we will use &_sdata - * which is the lowest memory and the amount we will save - * _should be_ below any resources we need herein. - * Unfortunately this is hard to test. See dead below - */ - - fullcontext_s *pdump = (fullcontext_s *)&_sdata; - - (void)enter_critical_section(); - - struct tcb_s *rtcb = (struct tcb_s *)tcb; - - /* Zero out everything */ - - memset(pdump, 0, sizeof(fullcontext_s)); - - /* Save Info */ - - pdump->info.lineno = lineno; - - if (filename) { - - int offset = 0; - unsigned int len = strlen((char *)filename) + 1; - - if (len > sizeof(pdump->info.filename)) { - offset = len - sizeof(pdump->info.filename) ; - } - - strncpy(pdump->info.filename, (char *)&filename[offset], sizeof(pdump->info.filename)); - } - - /* Save the value of the pointer for current_regs as debugging info. - * It should be NULL in case of an ASSERT and will aid in cross - * checking the validity of system memory at the time of the - * fault. - */ - - pdump->info.current_regs = (uintptr_t) CURRENT_REGS; - - /* Save Context */ - - -#if CONFIG_TASK_NAME_SIZE > 0 - strncpy(pdump->info.name, rtcb->name, CONFIG_TASK_NAME_SIZE); -#endif - - pdump->info.pid = rtcb->pid; - - - /* If current_regs is not NULL then we are in an interrupt context - * and the user context is in current_regs else we are running in - * the users context - */ - - if (CURRENT_REGS) { - pdump->info.stacks.interrupt.sp = currentsp; - - pdump->info.flags |= (eRegsPresent | eUserStackPresent | eIntStackPresent); - memcpy(pdump->info.regs, (void *)CURRENT_REGS, sizeof(pdump->info.regs)); - pdump->info.stacks.user.sp = pdump->info.regs[REG_R13]; - - } else { - - /* users context */ - pdump->info.flags |= eUserStackPresent; - - pdump->info.stacks.user.sp = currentsp; - } - - if (pdump->info.pid == 0) { - - pdump->info.stacks.user.top = g_idle_topstack - 4; - pdump->info.stacks.user.size = CONFIG_IDLETHREAD_STACKSIZE; - - } else { - pdump->info.stacks.user.top = (uint32_t) rtcb->adj_stack_ptr; - pdump->info.stacks.user.size = (uint32_t) rtcb->adj_stack_size;; - } - -#if CONFIG_ARCH_INTERRUPTSTACK > 3 - - /* Get the limits on the interrupt stack memory */ - - pdump->info.stacks.interrupt.top = (uint32_t)&g_intstackbase; - pdump->info.stacks.interrupt.size = (CONFIG_ARCH_INTERRUPTSTACK & ~3); - - /* If In interrupt Context save the interrupt stack data centered - * about the interrupt stack pointer - */ - - if ((pdump->info.flags & eIntStackPresent) != 0) { - stack_word_t *ps = (stack_word_t *) pdump->info.stacks.interrupt.sp; - copy_reverse(pdump->istack, &ps[arraySize(pdump->istack) / 2], arraySize(pdump->istack)); - } - - /* Is it Invalid? */ - - if (!(pdump->info.stacks.interrupt.sp <= pdump->info.stacks.interrupt.top && - pdump->info.stacks.interrupt.sp > pdump->info.stacks.interrupt.top - pdump->info.stacks.interrupt.size)) { - pdump->info.flags |= eInvalidIntStackPrt; - } - -#endif - - /* If In interrupt context or User save the user stack data centered - * about the user stack pointer - */ - if ((pdump->info.flags & eUserStackPresent) != 0) { - stack_word_t *ps = (stack_word_t *) pdump->info.stacks.user.sp; - copy_reverse(pdump->ustack, &ps[arraySize(pdump->ustack) / 2], arraySize(pdump->ustack)); - } - - /* Is it Invalid? */ - - if (!(pdump->info.stacks.user.sp <= pdump->info.stacks.user.top && - pdump->info.stacks.user.sp > pdump->info.stacks.user.top - pdump->info.stacks.user.size)) { - pdump->info.flags |= eInvalidUserStackPtr; - } - - int rv = stm32_bbsram_savepanic(HARDFAULT_FILENO, (uint8_t *)pdump, sizeof(fullcontext_s)); - - /* Test if memory got wiped because of using _sdata */ - - if (rv == -ENXIO) { - char *dead = "Memory wiped - dump not saved!"; - - while (*dead) { - up_lowputc(*dead++); - } - - } else if (rv == -ENOSPC) { - - /* hard fault again */ - - up_lowputc('!'); - } - - -#if defined(CONFIG_BOARD_RESET_ON_CRASH) - px4_systemreset(false); -#endif -} diff --git a/src/drivers/boards/mindpx-v2/CMakeLists.txt b/src/drivers/boards/mindpx-v2/CMakeLists.txt index 25f0de9ead..ac0e3a1b30 100644 --- a/src/drivers/boards/mindpx-v2/CMakeLists.txt +++ b/src/drivers/boards/mindpx-v2/CMakeLists.txt @@ -34,6 +34,7 @@ px4_add_module( MODULE drivers__boards__mindpx-v2 COMPILE_FLAGS SRCS + ../common/stm32/board_crashdump.c ../common/board_dma_alloc.c mindpx_can.c mindpx2_init.c diff --git a/src/drivers/boards/mindpx-v2/mindpx2_init.c b/src/drivers/boards/mindpx-v2/mindpx2_init.c index 083cbe8fb8..167dc0fa42 100644 --- a/src/drivers/boards/mindpx-v2/mindpx2_init.c +++ b/src/drivers/boards/mindpx-v2/mindpx2_init.c @@ -467,157 +467,3 @@ __EXPORT int board_app_initialize(uintptr_t arg) return OK; } - -static void copy_reverse(stack_word_t *dest, stack_word_t *src, int size) -{ - while (size--) { - *dest++ = *src--; - } -} - -__EXPORT void board_crashdump(uintptr_t currentsp, FAR void *tcb, FAR const uint8_t *filename, int lineno) -{ - /* We need a chunk of ram to save the complete context in. - * Since we are going to reboot we will use &_sdata - * which is the lowest memory and the amount we will save - * _should be_ below any resources we need herein. - * Unfortunately this is hard to test. See dead below - */ - - fullcontext_s *pdump = (fullcontext_s *)&_sdata; - - (void)enter_critical_section(); - - struct tcb_s *rtcb = (struct tcb_s *)tcb; - - /* Zero out everything */ - - memset(pdump, 0, sizeof(fullcontext_s)); - - /* Save Info */ - - pdump->info.lineno = lineno; - - if (filename) { - - int offset = 0; - unsigned int len = strlen((char *)filename) + 1; - - if (len > sizeof(pdump->info.filename)) { - offset = len - sizeof(pdump->info.filename) ; - } - - strncpy(pdump->info.filename, (char *)&filename[offset], sizeof(pdump->info.filename)); - } - - /* Save the value of the pointer for current_regs as debugging info. - * It should be NULL in case of an ASSERT and will aid in cross - * checking the validity of system memory at the time of the - * fault. - */ - - pdump->info.current_regs = (uintptr_t) CURRENT_REGS; - - /* Save Context */ - - -#if CONFIG_TASK_NAME_SIZE > 0 - strncpy(pdump->info.name, rtcb->name, CONFIG_TASK_NAME_SIZE); -#endif - - pdump->info.pid = rtcb->pid; - - - /* If current_regs is not NULL then we are in an interrupt context - * and the user context is in current_regs else we are running in - * the users context - */ - - if (CURRENT_REGS) { - pdump->info.stacks.interrupt.sp = currentsp; - - pdump->info.flags |= (eRegsPresent | eUserStackPresent | eIntStackPresent); - memcpy(pdump->info.regs, (void *)CURRENT_REGS, sizeof(pdump->info.regs)); - pdump->info.stacks.user.sp = pdump->info.regs[REG_R13]; - - } else { - - /* users context */ - pdump->info.flags |= eUserStackPresent; - - pdump->info.stacks.user.sp = currentsp; - } - - if (pdump->info.pid == 0) { - - pdump->info.stacks.user.top = g_idle_topstack - 4; - pdump->info.stacks.user.size = CONFIG_IDLETHREAD_STACKSIZE; - - } else { - pdump->info.stacks.user.top = (uint32_t) rtcb->adj_stack_ptr; - pdump->info.stacks.user.size = (uint32_t) rtcb->adj_stack_size;; - } - -#if CONFIG_ARCH_INTERRUPTSTACK > 3 - - /* Get the limits on the interrupt stack memory */ - - pdump->info.stacks.interrupt.top = (uint32_t)&g_intstackbase; - pdump->info.stacks.interrupt.size = (CONFIG_ARCH_INTERRUPTSTACK & ~3); - - /* If In interrupt Context save the interrupt stack data centered - * about the interrupt stack pointer - */ - - if ((pdump->info.flags & eIntStackPresent) != 0) { - stack_word_t *ps = (stack_word_t *) pdump->info.stacks.interrupt.sp; - copy_reverse(pdump->istack, &ps[arraySize(pdump->istack) / 2], arraySize(pdump->istack)); - } - - /* Is it Invalid? */ - - if (!(pdump->info.stacks.interrupt.sp <= pdump->info.stacks.interrupt.top && - pdump->info.stacks.interrupt.sp > pdump->info.stacks.interrupt.top - pdump->info.stacks.interrupt.size)) { - pdump->info.flags |= eInvalidIntStackPrt; - } - -#endif - - /* If In interrupt context or User save the user stack data centered - * about the user stack pointer - */ - if ((pdump->info.flags & eUserStackPresent) != 0) { - stack_word_t *ps = (stack_word_t *) pdump->info.stacks.user.sp; - copy_reverse(pdump->ustack, &ps[arraySize(pdump->ustack) / 2], arraySize(pdump->ustack)); - } - - /* Is it Invalid? */ - - if (!(pdump->info.stacks.user.sp <= pdump->info.stacks.user.top && - pdump->info.stacks.user.sp > pdump->info.stacks.user.top - pdump->info.stacks.user.size)) { - pdump->info.flags |= eInvalidUserStackPtr; - } - - int rv = stm32_bbsram_savepanic(HARDFAULT_FILENO, (uint8_t *)pdump, sizeof(fullcontext_s)); - - /* Test if memory got wiped because of using _sdata */ - - if (rv == -ENXIO) { - char *dead = "Memory wiped - dump not saved!"; - - while (*dead) { - up_lowputc(*dead++); - } - - } else if (rv == -ENOSPC) { - - /* hard fault again */ - - up_lowputc('!'); - } - - -#if defined(CONFIG_BOARD_RESET_ON_CRASH) - px4_systemreset(false); -#endif -} diff --git a/src/drivers/boards/px4fmu-v2/CMakeLists.txt b/src/drivers/boards/px4fmu-v2/CMakeLists.txt index 2d7a50354a..2752be3805 100644 --- a/src/drivers/boards/px4fmu-v2/CMakeLists.txt +++ b/src/drivers/boards/px4fmu-v2/CMakeLists.txt @@ -34,6 +34,7 @@ px4_add_module( MODULE drivers__boards__px4fmu-v2 COMPILE_FLAGS SRCS + ../common/stm32/board_crashdump.c ../common/board_dma_alloc.c px4fmu_can.c px4fmu2_init.c diff --git a/src/drivers/boards/px4fmu-v2/px4fmu2_init.c b/src/drivers/boards/px4fmu-v2/px4fmu2_init.c index 907bb69222..3ed0d5b379 100644 --- a/src/drivers/boards/px4fmu-v2/px4fmu2_init.c +++ b/src/drivers/boards/px4fmu-v2/px4fmu2_init.c @@ -484,153 +484,3 @@ static void copy_reverse(stack_word_t *dest, stack_word_t *src, int size) *dest++ = *src--; } } - -__EXPORT void board_crashdump(uintptr_t currentsp, FAR void *tcb, FAR const uint8_t *filename, int lineno) -{ - if (hardfault_check_status) { - /* We need a chunk of ram to save the complete context in. - * Since we are going to reboot we will use &_sdata - * which is the lowest memory and the amount we will save - * _should be_ below any resources we need herein. - * Unfortunately this is hard to test. See dead below - */ - - fullcontext_s *pdump = (fullcontext_s *)&_sdata; - - (void)enter_critical_section(); - - struct tcb_s *rtcb = (struct tcb_s *)tcb; - - /* Zero out everything */ - - memset(pdump, 0, sizeof(fullcontext_s)); - - /* Save Info */ - - pdump->info.lineno = lineno; - - if (filename) { - - int offset = 0; - unsigned int len = strlen((char *)filename) + 1; - - if (len > sizeof(pdump->info.filename)) { - offset = len - sizeof(pdump->info.filename) ; - } - - strncpy(pdump->info.filename, (char *)&filename[offset], sizeof(pdump->info.filename)); - } - - /* Save the value of the pointer for current_regs as debugging info. - * It should be NULL in case of an ASSERT and will aid in cross - * checking the validity of system memory at the time of the - * fault. - */ - - pdump->info.current_regs = (uintptr_t) CURRENT_REGS; - - /* Save Context */ - - -#if CONFIG_TASK_NAME_SIZE > 0 - strncpy(pdump->info.name, rtcb->name, CONFIG_TASK_NAME_SIZE); -#endif - - pdump->info.pid = rtcb->pid; - - - /* If current_regs is not NULL then we are in an interrupt context - * and the user context is in current_regs else we are running in - * the users context - */ - - if (CURRENT_REGS) { - pdump->info.stacks.interrupt.sp = currentsp; - - pdump->info.flags |= (eRegsPresent | eUserStackPresent | eIntStackPresent); - memcpy(pdump->info.regs, (void *)CURRENT_REGS, sizeof(pdump->info.regs)); - pdump->info.stacks.user.sp = pdump->info.regs[REG_R13]; - - } else { - - /* users context */ - pdump->info.flags |= eUserStackPresent; - - pdump->info.stacks.user.sp = currentsp; - } - - if (pdump->info.pid == 0) { - - pdump->info.stacks.user.top = g_idle_topstack - 4; - pdump->info.stacks.user.size = CONFIG_IDLETHREAD_STACKSIZE; - - } else { - pdump->info.stacks.user.top = (uint32_t) rtcb->adj_stack_ptr; - pdump->info.stacks.user.size = (uint32_t) rtcb->adj_stack_size;; - } - -#if CONFIG_ARCH_INTERRUPTSTACK > 3 - - /* Get the limits on the interrupt stack memory */ - - pdump->info.stacks.interrupt.top = (uint32_t)&g_intstackbase; - pdump->info.stacks.interrupt.size = (CONFIG_ARCH_INTERRUPTSTACK & ~3); - - /* If In interrupt Context save the interrupt stack data centered - * about the interrupt stack pointer - */ - - if ((pdump->info.flags & eIntStackPresent) != 0) { - stack_word_t *ps = (stack_word_t *) pdump->info.stacks.interrupt.sp; - copy_reverse(pdump->istack, &ps[arraySize(pdump->istack) / 2], arraySize(pdump->istack)); - } - - /* Is it Invalid? */ - - if (!(pdump->info.stacks.interrupt.sp <= pdump->info.stacks.interrupt.top && - pdump->info.stacks.interrupt.sp > pdump->info.stacks.interrupt.top - pdump->info.stacks.interrupt.size)) { - pdump->info.flags |= eInvalidIntStackPrt; - } - -#endif - - /* If In interrupt context or User save the user stack data centered - * about the user stack pointer - */ - if ((pdump->info.flags & eUserStackPresent) != 0) { - stack_word_t *ps = (stack_word_t *) pdump->info.stacks.user.sp; - copy_reverse(pdump->ustack, &ps[arraySize(pdump->ustack) / 2], arraySize(pdump->ustack)); - } - - /* Is it Invalid? */ - - if (!(pdump->info.stacks.user.sp <= pdump->info.stacks.user.top && - pdump->info.stacks.user.sp > pdump->info.stacks.user.top - pdump->info.stacks.user.size)) { - pdump->info.flags |= eInvalidUserStackPtr; - } - - int rv = stm32_bbsram_savepanic(HARDFAULT_FILENO, (uint8_t *)pdump, sizeof(fullcontext_s)); - - /* Test if memory got wiped because of using _sdata */ - - if (rv == -ENXIO) { - char *dead = "Memory wiped - dump not saved!"; - - while (*dead) { - up_lowputc(*dead++); - } - - } else if (rv == -ENOSPC) { - - /* hard fault again */ - - up_lowputc('!'); - } - - -#if defined(CONFIG_BOARD_RESET_ON_CRASH) - px4_systemreset(false); -#endif - } // hardfault_check_status - -} diff --git a/src/drivers/boards/px4fmu-v4/CMakeLists.txt b/src/drivers/boards/px4fmu-v4/CMakeLists.txt index 6ad5e86bb1..fb9250dd9e 100644 --- a/src/drivers/boards/px4fmu-v4/CMakeLists.txt +++ b/src/drivers/boards/px4fmu-v4/CMakeLists.txt @@ -34,6 +34,7 @@ px4_add_module( MODULE drivers__boards__px4fmu-v4 COMPILE_FLAGS SRCS + ../common/stm32/board_crashdump.c ../common/board_dma_alloc.c px4fmu_can.c px4fmu_init.c diff --git a/src/drivers/boards/px4fmu-v4/px4fmu_init.c b/src/drivers/boards/px4fmu-v4/px4fmu_init.c index a9c260a063..4b52b8b8c8 100644 --- a/src/drivers/boards/px4fmu-v4/px4fmu_init.c +++ b/src/drivers/boards/px4fmu-v4/px4fmu_init.c @@ -482,157 +482,3 @@ __EXPORT int board_app_initialize(uintptr_t arg) return OK; } - -static void copy_reverse(stack_word_t *dest, stack_word_t *src, int size) -{ - while (size--) { - *dest++ = *src--; - } -} - -__EXPORT void board_crashdump(uintptr_t currentsp, FAR void *tcb, FAR const uint8_t *filename, int lineno) -{ - /* We need a chunk of ram to save the complete context in. - * Since we are going to reboot we will use &_sdata - * which is the lowest memory and the amount we will save - * _should be_ below any resources we need herein. - * Unfortunately this is hard to test. See dead below - */ - - fullcontext_s *pdump = (fullcontext_s *)&_sdata; - - (void)enter_critical_section(); - - struct tcb_s *rtcb = (struct tcb_s *)tcb; - - /* Zero out everything */ - - memset(pdump, 0, sizeof(fullcontext_s)); - - /* Save Info */ - - pdump->info.lineno = lineno; - - if (filename) { - - int offset = 0; - unsigned int len = strlen((char *)filename) + 1; - - if (len > sizeof(pdump->info.filename)) { - offset = len - sizeof(pdump->info.filename) ; - } - - strncpy(pdump->info.filename, (char *)&filename[offset], sizeof(pdump->info.filename)); - } - - /* Save the value of the pointer for current_regs as debugging info. - * It should be NULL in case of an ASSERT and will aid in cross - * checking the validity of system memory at the time of the - * fault. - */ - - pdump->info.current_regs = (uintptr_t) CURRENT_REGS; - - /* Save Context */ - - -#if CONFIG_TASK_NAME_SIZE > 0 - strncpy(pdump->info.name, rtcb->name, CONFIG_TASK_NAME_SIZE); -#endif - - pdump->info.pid = rtcb->pid; - - - /* If current_regs is not NULL then we are in an interrupt context - * and the user context is in current_regs else we are running in - * the users context - */ - - if (CURRENT_REGS) { - pdump->info.stacks.interrupt.sp = currentsp; - - pdump->info.flags |= (eRegsPresent | eUserStackPresent | eIntStackPresent); - memcpy(pdump->info.regs, (void *)CURRENT_REGS, sizeof(pdump->info.regs)); - pdump->info.stacks.user.sp = pdump->info.regs[REG_R13]; - - } else { - - /* users context */ - pdump->info.flags |= eUserStackPresent; - - pdump->info.stacks.user.sp = currentsp; - } - - if (pdump->info.pid == 0) { - - pdump->info.stacks.user.top = g_idle_topstack - 4; - pdump->info.stacks.user.size = CONFIG_IDLETHREAD_STACKSIZE; - - } else { - pdump->info.stacks.user.top = (uint32_t) rtcb->adj_stack_ptr; - pdump->info.stacks.user.size = (uint32_t) rtcb->adj_stack_size;; - } - -#if CONFIG_ARCH_INTERRUPTSTACK > 3 - - /* Get the limits on the interrupt stack memory */ - - pdump->info.stacks.interrupt.top = (uint32_t)&g_intstackbase; - pdump->info.stacks.interrupt.size = (CONFIG_ARCH_INTERRUPTSTACK & ~3); - - /* If In interrupt Context save the interrupt stack data centered - * about the interrupt stack pointer - */ - - if ((pdump->info.flags & eIntStackPresent) != 0) { - stack_word_t *ps = (stack_word_t *) pdump->info.stacks.interrupt.sp; - copy_reverse(pdump->istack, &ps[arraySize(pdump->istack) / 2], arraySize(pdump->istack)); - } - - /* Is it Invalid? */ - - if (!(pdump->info.stacks.interrupt.sp <= pdump->info.stacks.interrupt.top && - pdump->info.stacks.interrupt.sp > pdump->info.stacks.interrupt.top - pdump->info.stacks.interrupt.size)) { - pdump->info.flags |= eInvalidIntStackPrt; - } - -#endif - - /* If In interrupt context or User save the user stack data centered - * about the user stack pointer - */ - if ((pdump->info.flags & eUserStackPresent) != 0) { - stack_word_t *ps = (stack_word_t *) pdump->info.stacks.user.sp; - copy_reverse(pdump->ustack, &ps[arraySize(pdump->ustack) / 2], arraySize(pdump->ustack)); - } - - /* Is it Invalid? */ - - if (!(pdump->info.stacks.user.sp <= pdump->info.stacks.user.top && - pdump->info.stacks.user.sp > pdump->info.stacks.user.top - pdump->info.stacks.user.size)) { - pdump->info.flags |= eInvalidUserStackPtr; - } - - int rv = stm32_bbsram_savepanic(HARDFAULT_FILENO, (uint8_t *)pdump, sizeof(fullcontext_s)); - - /* Test if memory got wiped because of using _sdata */ - - if (rv == -ENXIO) { - char *dead = "Memory wiped - dump not saved!"; - - while (*dead) { - up_lowputc(*dead++); - } - - } else if (rv == -ENOSPC) { - - /* hard fault again */ - - up_lowputc('!'); - } - - -#if defined(CONFIG_BOARD_RESET_ON_CRASH) - px4_systemreset(false); -#endif -} diff --git a/src/drivers/boards/px4fmu-v4pro/CMakeLists.txt b/src/drivers/boards/px4fmu-v4pro/CMakeLists.txt index 8900b86d49..67a0665735 100644 --- a/src/drivers/boards/px4fmu-v4pro/CMakeLists.txt +++ b/src/drivers/boards/px4fmu-v4pro/CMakeLists.txt @@ -34,6 +34,7 @@ px4_add_module( MODULE drivers__boards__px4fmu-v4pro COMPILE_FLAGS SRCS + ../common/stm32/board_crashdump.c ../common/board_dma_alloc.c px4fmu_can.c px4fmu_init.c diff --git a/src/drivers/boards/px4fmu-v4pro/px4fmu_init.c b/src/drivers/boards/px4fmu-v4pro/px4fmu_init.c index cde7db895a..d48d68fd4d 100644 --- a/src/drivers/boards/px4fmu-v4pro/px4fmu_init.c +++ b/src/drivers/boards/px4fmu-v4pro/px4fmu_init.c @@ -519,157 +519,3 @@ __EXPORT int board_app_initialize(uintptr_t arg) return OK; } - -static void copy_reverse(stack_word_t *dest, stack_word_t *src, int size) -{ - while (size--) { - *dest++ = *src--; - } -} - -__EXPORT void board_crashdump(uintptr_t currentsp, FAR void *tcb, FAR const uint8_t *filename, int lineno) -{ - /* We need a chunk of ram to save the complete context in. - * Since we are going to reboot we will use &_sdata - * which is the lowest memory and the amount we will save - * _should be_ below any resources we need herein. - * Unfortunately this is hard to test. See dead below - */ - - fullcontext_s *pdump = (fullcontext_s *)&_sdata; - - (void)enter_critical_section(); - - struct tcb_s *rtcb = (struct tcb_s *)tcb; - - /* Zero out everything */ - - memset(pdump, 0, sizeof(fullcontext_s)); - - /* Save Info */ - - pdump->info.lineno = lineno; - - if (filename) { - - int offset = 0; - unsigned int len = strlen((char *)filename) + 1; - - if (len > sizeof(pdump->info.filename)) { - offset = len - sizeof(pdump->info.filename) ; - } - - strncpy(pdump->info.filename, (char *)&filename[offset], sizeof(pdump->info.filename)); - } - - /* Save the value of the pointer for current_regs as debugging info. - * It should be NULL in case of an ASSERT and will aid in cross - * checking the validity of system memory at the time of the - * fault. - */ - - pdump->info.current_regs = (uintptr_t) CURRENT_REGS; - - /* Save Context */ - - -#if CONFIG_TASK_NAME_SIZE > 0 - strncpy(pdump->info.name, rtcb->name, CONFIG_TASK_NAME_SIZE); -#endif - - pdump->info.pid = rtcb->pid; - - - /* If current_regs is not NULL then we are in an interrupt context - * and the user context is in current_regs else we are running in - * the users context - */ - - if (CURRENT_REGS) { - pdump->info.stacks.interrupt.sp = currentsp; - - pdump->info.flags |= (eRegsPresent | eUserStackPresent | eIntStackPresent); - memcpy(pdump->info.regs, (void *)CURRENT_REGS, sizeof(pdump->info.regs)); - pdump->info.stacks.user.sp = pdump->info.regs[REG_R13]; - - } else { - - /* users context */ - pdump->info.flags |= eUserStackPresent; - - pdump->info.stacks.user.sp = currentsp; - } - - if (pdump->info.pid == 0) { - - pdump->info.stacks.user.top = g_idle_topstack - 4; - pdump->info.stacks.user.size = CONFIG_IDLETHREAD_STACKSIZE; - - } else { - pdump->info.stacks.user.top = (uint32_t) rtcb->adj_stack_ptr; - pdump->info.stacks.user.size = (uint32_t) rtcb->adj_stack_size;; - } - -#if CONFIG_ARCH_INTERRUPTSTACK > 3 - - /* Get the limits on the interrupt stack memory */ - - pdump->info.stacks.interrupt.top = (uint32_t)&g_intstackbase; - pdump->info.stacks.interrupt.size = (CONFIG_ARCH_INTERRUPTSTACK & ~3); - - /* If In interrupt Context save the interrupt stack data centered - * about the interrupt stack pointer - */ - - if ((pdump->info.flags & eIntStackPresent) != 0) { - stack_word_t *ps = (stack_word_t *) pdump->info.stacks.interrupt.sp; - copy_reverse(pdump->istack, &ps[arraySize(pdump->istack) / 2], arraySize(pdump->istack)); - } - - /* Is it Invalid? */ - - if (!(pdump->info.stacks.interrupt.sp <= pdump->info.stacks.interrupt.top && - pdump->info.stacks.interrupt.sp > pdump->info.stacks.interrupt.top - pdump->info.stacks.interrupt.size)) { - pdump->info.flags |= eInvalidIntStackPrt; - } - -#endif - - /* If In interrupt context or User save the user stack data centered - * about the user stack pointer - */ - if ((pdump->info.flags & eUserStackPresent) != 0) { - stack_word_t *ps = (stack_word_t *) pdump->info.stacks.user.sp; - copy_reverse(pdump->ustack, &ps[arraySize(pdump->ustack) / 2], arraySize(pdump->ustack)); - } - - /* Is it Invalid? */ - - if (!(pdump->info.stacks.user.sp <= pdump->info.stacks.user.top && - pdump->info.stacks.user.sp > pdump->info.stacks.user.top - pdump->info.stacks.user.size)) { - pdump->info.flags |= eInvalidUserStackPtr; - } - - int rv = stm32_bbsram_savepanic(HARDFAULT_FILENO, (uint8_t *)pdump, sizeof(fullcontext_s)); - - /* Test if memory got wiped because of using _sdata */ - - if (rv == -ENXIO) { - char *dead = "Memory wiped - dump not saved!"; - - while (*dead) { - up_lowputc(*dead++); - } - - } else if (rv == -ENOSPC) { - - /* hard fault again */ - - up_lowputc('!'); - } - - -#if defined(CONFIG_BOARD_RESET_ON_CRASH) - px4_systemreset(false); -#endif -} diff --git a/src/drivers/boards/px4fmu-v5/CMakeLists.txt b/src/drivers/boards/px4fmu-v5/CMakeLists.txt index 210d2c6460..4f5cd609ad 100644 --- a/src/drivers/boards/px4fmu-v5/CMakeLists.txt +++ b/src/drivers/boards/px4fmu-v5/CMakeLists.txt @@ -35,6 +35,7 @@ px4_add_module( COMPILE_FLAGS -Os SRCS + ../common/stm32/board_crashdump.c ../common/board_dma_alloc.c # WIP px4fmu_can.c px4fmu_init.c diff --git a/src/drivers/boards/px4fmu-v5/px4fmu_init.c b/src/drivers/boards/px4fmu-v5/px4fmu_init.c index 2e6617c2da..028fdb63cd 100644 --- a/src/drivers/boards/px4fmu-v5/px4fmu_init.c +++ b/src/drivers/boards/px4fmu-v5/px4fmu_init.c @@ -499,157 +499,3 @@ __EXPORT int board_app_initialize(uintptr_t arg) return OK; } - -static void copy_reverse(stack_word_t *dest, stack_word_t *src, int size) -{ - while (size--) { - *dest++ = *src--; - } -} - -__EXPORT void board_crashdump(uintptr_t currentsp, FAR void *tcb, FAR const uint8_t *filename, int lineno) -{ - /* We need a chunk of ram to save the complete context in. - * Since we are going to reboot we will use &_sdata - * which is the lowest memory and the amount we will save - * _should be_ below any resources we need herein. - * Unfortunately this is hard to test. See dead below - */ - - fullcontext_s *pdump = (fullcontext_s *)&_sdata; - - (void)enter_critical_section(); - - struct tcb_s *rtcb = (struct tcb_s *)tcb; - - /* Zero out everything */ - - memset(pdump, 0, sizeof(fullcontext_s)); - - /* Save Info */ - - pdump->info.lineno = lineno; - - if (filename) { - - int offset = 0; - unsigned int len = strlen((char *)filename) + 1; - - if (len > sizeof(pdump->info.filename)) { - offset = len - sizeof(pdump->info.filename) ; - } - - strncpy(pdump->info.filename, (char *)&filename[offset], sizeof(pdump->info.filename)); - } - - /* Save the value of the pointer for current_regs as debugging info. - * It should be NULL in case of an ASSERT and will aid in cross - * checking the validity of system memory at the time of the - * fault. - */ - - pdump->info.current_regs = (uintptr_t) CURRENT_REGS; - - /* Save Context */ - - -#if CONFIG_TASK_NAME_SIZE > 0 - strncpy(pdump->info.name, rtcb->name, CONFIG_TASK_NAME_SIZE); -#endif - - pdump->info.pid = rtcb->pid; - - - /* If current_regs is not NULL then we are in an interrupt context - * and the user context is in current_regs else we are running in - * the users context - */ - - if (CURRENT_REGS) { - pdump->info.stacks.interrupt.sp = currentsp; - - pdump->info.flags |= (eRegsPresent | eUserStackPresent | eIntStackPresent); - memcpy(pdump->info.regs, (void *)CURRENT_REGS, sizeof(pdump->info.regs)); - pdump->info.stacks.user.sp = pdump->info.regs[REG_R13]; - - } else { - - /* users context */ - pdump->info.flags |= eUserStackPresent; - - pdump->info.stacks.user.sp = currentsp; - } - - if (pdump->info.pid == 0) { - - pdump->info.stacks.user.top = g_idle_topstack - 4; - pdump->info.stacks.user.size = CONFIG_IDLETHREAD_STACKSIZE; - - } else { - pdump->info.stacks.user.top = (uint32_t) rtcb->adj_stack_ptr; - pdump->info.stacks.user.size = (uint32_t) rtcb->adj_stack_size;; - } - -#if CONFIG_ARCH_INTERRUPTSTACK > 3 - - /* Get the limits on the interrupt stack memory */ - - pdump->info.stacks.interrupt.top = (uint32_t)&g_intstackbase; - pdump->info.stacks.interrupt.size = (CONFIG_ARCH_INTERRUPTSTACK & ~3); - - /* If In interrupt Context save the interrupt stack data centered - * about the interrupt stack pointer - */ - - if ((pdump->info.flags & eIntStackPresent) != 0) { - stack_word_t *ps = (stack_word_t *) pdump->info.stacks.interrupt.sp; - copy_reverse(pdump->istack, &ps[arraySize(pdump->istack) / 2], arraySize(pdump->istack)); - } - - /* Is it Invalid? */ - - if (!(pdump->info.stacks.interrupt.sp <= pdump->info.stacks.interrupt.top && - pdump->info.stacks.interrupt.sp > pdump->info.stacks.interrupt.top - pdump->info.stacks.interrupt.size)) { - pdump->info.flags |= eInvalidIntStackPrt; - } - -#endif - - /* If In interrupt context or User save the user stack data centered - * about the user stack pointer - */ - if ((pdump->info.flags & eUserStackPresent) != 0) { - stack_word_t *ps = (stack_word_t *) pdump->info.stacks.user.sp; - copy_reverse(pdump->ustack, &ps[arraySize(pdump->ustack) / 2], arraySize(pdump->ustack)); - } - - /* Is it Invalid? */ - - if (!(pdump->info.stacks.user.sp <= pdump->info.stacks.user.top && - pdump->info.stacks.user.sp > pdump->info.stacks.user.top - pdump->info.stacks.user.size)) { - pdump->info.flags |= eInvalidUserStackPtr; - } - - int rv = stm32_bbsram_savepanic(HARDFAULT_FILENO, (uint8_t *)pdump, sizeof(fullcontext_s)); - - /* Test if memory got wiped because of using _sdata */ - - if (rv == -ENXIO) { - char *dead = "Memory wiped - dump not saved!"; - - while (*dead) { - up_lowputc(*dead++); - } - - } else if (rv == -ENOSPC) { - - /* hard fault again */ - - up_lowputc('!'); - } - - -#if defined(CONFIG_BOARD_RESET_ON_CRASH) - px4_systemreset(false); -#endif -} diff --git a/src/drivers/boards/px4nucleoF767ZI-v1/CMakeLists.txt b/src/drivers/boards/px4nucleoF767ZI-v1/CMakeLists.txt index d78ad2f922..c955a0b985 100644 --- a/src/drivers/boards/px4nucleoF767ZI-v1/CMakeLists.txt +++ b/src/drivers/boards/px4nucleoF767ZI-v1/CMakeLists.txt @@ -35,6 +35,7 @@ px4_add_module( COMPILE_FLAGS -Os SRCS + ../common/stm32/board_crashdump.c ../common/board_dma_alloc.c # WIP px4nucleo_can.c px4nucleo_init.c diff --git a/src/drivers/boards/px4nucleoF767ZI-v1/px4nucleo_init.c b/src/drivers/boards/px4nucleoF767ZI-v1/px4nucleo_init.c index 8d675becf3..438057528d 100644 --- a/src/drivers/boards/px4nucleoF767ZI-v1/px4nucleo_init.c +++ b/src/drivers/boards/px4nucleoF767ZI-v1/px4nucleo_init.c @@ -438,157 +438,3 @@ __EXPORT int board_app_initialize(uintptr_t arg) return OK; } - -static void copy_reverse(stack_word_t *dest, stack_word_t *src, int size) -{ - while (size--) { - *dest++ = *src--; - } -} - -__EXPORT void board_crashdump(uintptr_t currentsp, FAR void *tcb, FAR const uint8_t *filename, int lineno) -{ - /* We need a chunk of ram to save the complete context in. - * Since we are going to reboot we will use &_sdata - * which is the lowest memory and the amount we will save - * _should be_ below any resources we need herein. - * Unfortunately this is hard to test. See dead below - */ - - fullcontext_s *pdump = (fullcontext_s *)&_sdata; - - (void)enter_critical_section(); - - struct tcb_s *rtcb = (struct tcb_s *)tcb; - - /* Zero out everything */ - - memset(pdump, 0, sizeof(fullcontext_s)); - - /* Save Info */ - - pdump->info.lineno = lineno; - - if (filename) { - - int offset = 0; - unsigned int len = strlen((char *)filename) + 1; - - if (len > sizeof(pdump->info.filename)) { - offset = len - sizeof(pdump->info.filename) ; - } - - strncpy(pdump->info.filename, (char *)&filename[offset], sizeof(pdump->info.filename)); - } - - /* Save the value of the pointer for current_regs as debugging info. - * It should be NULL in case of an ASSERT and will aid in cross - * checking the validity of system memory at the time of the - * fault. - */ - - pdump->info.current_regs = (uintptr_t) CURRENT_REGS; - - /* Save Context */ - - -#if CONFIG_TASK_NAME_SIZE > 0 - strncpy(pdump->info.name, rtcb->name, CONFIG_TASK_NAME_SIZE); -#endif - - pdump->info.pid = rtcb->pid; - - - /* If current_regs is not NULL then we are in an interrupt context - * and the user context is in current_regs else we are running in - * the users context - */ - - if (CURRENT_REGS) { - pdump->info.stacks.interrupt.sp = currentsp; - - pdump->info.flags |= (eRegsPresent | eUserStackPresent | eIntStackPresent); - memcpy(pdump->info.regs, (void *)CURRENT_REGS, sizeof(pdump->info.regs)); - pdump->info.stacks.user.sp = pdump->info.regs[REG_R13]; - - } else { - - /* users context */ - pdump->info.flags |= eUserStackPresent; - - pdump->info.stacks.user.sp = currentsp; - } - - if (pdump->info.pid == 0) { - - pdump->info.stacks.user.top = g_idle_topstack - 4; - pdump->info.stacks.user.size = CONFIG_IDLETHREAD_STACKSIZE; - - } else { - pdump->info.stacks.user.top = (uint32_t) rtcb->adj_stack_ptr; - pdump->info.stacks.user.size = (uint32_t) rtcb->adj_stack_size;; - } - -#if CONFIG_ARCH_INTERRUPTSTACK > 3 - - /* Get the limits on the interrupt stack memory */ - - pdump->info.stacks.interrupt.top = (uint32_t)&g_intstackbase; - pdump->info.stacks.interrupt.size = (CONFIG_ARCH_INTERRUPTSTACK & ~3); - - /* If In interrupt Context save the interrupt stack data centered - * about the interrupt stack pointer - */ - - if ((pdump->info.flags & eIntStackPresent) != 0) { - stack_word_t *ps = (stack_word_t *) pdump->info.stacks.interrupt.sp; - copy_reverse(pdump->istack, &ps[arraySize(pdump->istack) / 2], arraySize(pdump->istack)); - } - - /* Is it Invalid? */ - - if (!(pdump->info.stacks.interrupt.sp <= pdump->info.stacks.interrupt.top && - pdump->info.stacks.interrupt.sp > pdump->info.stacks.interrupt.top - pdump->info.stacks.interrupt.size)) { - pdump->info.flags |= eInvalidIntStackPrt; - } - -#endif - - /* If In interrupt context or User save the user stack data centered - * about the user stack pointer - */ - if ((pdump->info.flags & eUserStackPresent) != 0) { - stack_word_t *ps = (stack_word_t *) pdump->info.stacks.user.sp; - copy_reverse(pdump->ustack, &ps[arraySize(pdump->ustack) / 2], arraySize(pdump->ustack)); - } - - /* Is it Invalid? */ - - if (!(pdump->info.stacks.user.sp <= pdump->info.stacks.user.top && - pdump->info.stacks.user.sp > pdump->info.stacks.user.top - pdump->info.stacks.user.size)) { - pdump->info.flags |= eInvalidUserStackPtr; - } - - int rv = stm32_bbsram_savepanic(HARDFAULT_FILENO, (uint8_t *)pdump, sizeof(fullcontext_s)); - - /* Test if memory got wiped because of using _sdata */ - - if (rv == -ENXIO) { - char *dead = "Memory wiped - dump not saved!"; - - while (*dead) { - up_lowputc(*dead++); - } - - } else if (rv == -ENOSPC) { - - /* hard fault again */ - - up_lowputc('!'); - } - - -#if defined(CONFIG_BOARD_RESET_ON_CRASH) - px4_systemreset(false); -#endif -} diff --git a/src/drivers/boards/tap-v1/CMakeLists.txt b/src/drivers/boards/tap-v1/CMakeLists.txt index c117a22ed8..df12827147 100644 --- a/src/drivers/boards/tap-v1/CMakeLists.txt +++ b/src/drivers/boards/tap-v1/CMakeLists.txt @@ -35,6 +35,7 @@ px4_add_module( MODULE drivers__boards__tap-v1 COMPILE_FLAGS SRCS + ../common/stm32/board_crashdump.c ../common/board_dma_alloc.c tap_init.c tap_pwr.c diff --git a/src/drivers/boards/tap-v1/tap_init.c b/src/drivers/boards/tap-v1/tap_init.c index de53b9f66f..fcc7941da5 100644 --- a/src/drivers/boards/tap-v1/tap_init.c +++ b/src/drivers/boards/tap-v1/tap_init.c @@ -404,157 +404,3 @@ __EXPORT int board_app_initialize(uintptr_t arg) return OK; } - -static void copy_reverse(stack_word_t *dest, stack_word_t *src, int size) -{ - while (size--) { - *dest++ = *src--; - } -} - -__EXPORT void board_crashdump(uintptr_t currentsp, FAR void *tcb, FAR const uint8_t *filename, int lineno) -{ - /* We need a chunk of ram to save the complete context in. - * Since we are going to reboot we will use &_sdata - * which is the lowest memory and the amount we will save - * _should be_ below any resources we need herein. - * Unfortunately this is hard to test. See dead below - */ - - fullcontext_s *pdump = (fullcontext_s *)&_sdata; - - (void)enter_critical_section(); - - struct tcb_s *rtcb = (struct tcb_s *)tcb; - - /* Zero out everything */ - - memset(pdump, 0, sizeof(fullcontext_s)); - - /* Save Info */ - - pdump->info.lineno = lineno; - - if (filename) { - - int offset = 0; - unsigned int len = strlen((char *)filename) + 1; - - if (len > sizeof(pdump->info.filename)) { - offset = len - sizeof(pdump->info.filename) ; - } - - strncpy(pdump->info.filename, (char *)&filename[offset], sizeof(pdump->info.filename)); - } - - /* Save the value of the pointer for current_regs as debugging info. - * It should be NULL in case of an ASSERT and will aid in cross - * checking the validity of system memory at the time of the - * fault. - */ - - pdump->info.current_regs = (uintptr_t) CURRENT_REGS; - - /* Save Context */ - - -#if CONFIG_TASK_NAME_SIZE > 0 - strncpy(pdump->info.name, rtcb->name, CONFIG_TASK_NAME_SIZE); -#endif - - pdump->info.pid = rtcb->pid; - - - /* If current_regs is not NULL then we are in an interrupt context - * and the user context is in current_regs else we are running in - * the users context - */ - - if (CURRENT_REGS) { - pdump->info.stacks.interrupt.sp = currentsp; - - pdump->info.flags |= (eRegsPresent | eUserStackPresent | eIntStackPresent); - memcpy(pdump->info.regs, (void *)CURRENT_REGS, sizeof(pdump->info.regs)); - pdump->info.stacks.user.sp = pdump->info.regs[REG_R13]; - - } else { - - /* users context */ - pdump->info.flags |= eUserStackPresent; - - pdump->info.stacks.user.sp = currentsp; - } - - if (pdump->info.pid == 0) { - - pdump->info.stacks.user.top = g_idle_topstack - 4; - pdump->info.stacks.user.size = CONFIG_IDLETHREAD_STACKSIZE; - - } else { - pdump->info.stacks.user.top = (uint32_t) rtcb->adj_stack_ptr; - pdump->info.stacks.user.size = (uint32_t) rtcb->adj_stack_size;; - } - -#if CONFIG_ARCH_INTERRUPTSTACK > 3 - - /* Get the limits on the interrupt stack memory */ - - pdump->info.stacks.interrupt.top = (uint32_t)&g_intstackbase; - pdump->info.stacks.interrupt.size = (CONFIG_ARCH_INTERRUPTSTACK & ~3); - - /* If In interrupt Context save the interrupt stack data centered - * about the interrupt stack pointer - */ - - if ((pdump->info.flags & eIntStackPresent) != 0) { - stack_word_t *ps = (stack_word_t *) pdump->info.stacks.interrupt.sp; - copy_reverse(pdump->istack, &ps[arraySize(pdump->istack) / 2], arraySize(pdump->istack)); - } - - /* Is it Invalid? */ - - if (!(pdump->info.stacks.interrupt.sp <= pdump->info.stacks.interrupt.top && - pdump->info.stacks.interrupt.sp > pdump->info.stacks.interrupt.top - pdump->info.stacks.interrupt.size)) { - pdump->info.flags |= eInvalidIntStackPrt; - } - -#endif - - /* If In interrupt context or User save the user stack data centered - * about the user stack pointer - */ - if ((pdump->info.flags & eUserStackPresent) != 0) { - stack_word_t *ps = (stack_word_t *) pdump->info.stacks.user.sp; - copy_reverse(pdump->ustack, &ps[arraySize(pdump->ustack) / 2], arraySize(pdump->ustack)); - } - - /* Is it Invalid? */ - - if (!(pdump->info.stacks.user.sp <= pdump->info.stacks.user.top && - pdump->info.stacks.user.sp > pdump->info.stacks.user.top - pdump->info.stacks.user.size)) { - pdump->info.flags |= eInvalidUserStackPtr; - } - - int rv = stm32_bbsram_savepanic(HARDFAULT_FILENO, (uint8_t *)pdump, sizeof(fullcontext_s)); - - /* Test if memory got wiped because of using _sdata */ - - if (rv == -ENXIO) { - char *dead = "Memory wiped - dump not saved!"; - - while (*dead) { - up_lowputc(*dead++); - } - - } else if (rv == -ENOSPC) { - - /* hard fault again */ - - up_lowputc('!'); - } - - -#if defined(CONFIG_BOARD_RESET_ON_CRASH) - px4_systemreset(false); -#endif -}