diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 68c766773d..91f81b292c 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -1288,6 +1288,13 @@ config ARM_MPU_EARLY_RESET Note: This can be used without MPU Support enabled. +config ARM_COREDUMP_REGION + bool "Add coredump region" + depends on COREDUMP + default n + ---help--- + Add coredump region includes nvic and mpu for cortex-M. + config ARCH_HAVE_LOWVECTORS bool diff --git a/arch/arm/src/armv6-m/CMakeLists.txt b/arch/arm/src/armv6-m/CMakeLists.txt index 6bfb544929..2522ef79ab 100644 --- a/arch/arm/src/armv6-m/CMakeLists.txt +++ b/arch/arm/src/armv6-m/CMakeLists.txt @@ -32,7 +32,8 @@ set(SRCS arm_trigger_irq.c arm_vectors.c) -if(CONFIG_DEBUG_FEATURES) +if((DEFINED CONFIG_DEBUG_FEATURES AND CONFIG_DEBUG_FEATURES) + OR (DEFINED CONFIG_ARM_COREDUMP_REGION AND CONFIG_ARM_COREDUMP_REGION)) list(APPEND SRCS arm_dumpnvic.c) endif() diff --git a/arch/arm/src/armv6-m/Make.defs b/arch/arm/src/armv6-m/Make.defs index 9a39ab04bf..287ef74ac0 100644 --- a/arch/arm/src/armv6-m/Make.defs +++ b/arch/arm/src/armv6-m/Make.defs @@ -29,7 +29,7 @@ CMN_CSRCS += arm_schedulesigaction.c arm_sigdeliver.c arm_svcall.c CMN_CSRCS += arm_systemreset.c arm_tcbinfo.c arm_vectors.c CMN_CSRCS += arm_trigger_irq.c -ifeq ($(CONFIG_DEBUG_FEATURES),y) +ifneq ($(filter y,$(CONFIG_DEBUG_FEATURES)$(CONFIG_ARM_COREDUMP_REGION)),) CMN_CSRCS += arm_dumpnvic.c endif diff --git a/arch/arm/src/armv6-m/arm_dumpnvic.c b/arch/arm/src/armv6-m/arm_dumpnvic.c index 04032feab4..325c8e9086 100644 --- a/arch/arm/src/armv6-m/arm_dumpnvic.c +++ b/arch/arm/src/armv6-m/arm_dumpnvic.c @@ -23,7 +23,7 @@ ****************************************************************************/ #include - +#include #include #include @@ -87,3 +87,22 @@ void arm_dumpnvic(const char *msg) } #endif /* CONFIG_DEBUG_FEATURES */ + +#ifdef CONFIG_ARM_COREDUMP_REGION + +/**************************************************************************** + * Function: arm_coredump_add_region + * + * Description: + * Dump all NVIC registers during a core dump. + * + ****************************************************************************/ + +void arm_coredump_add_region(void) +{ + coredump_add_memory_region((uint32_t *)ARMV6M_NVIC1_BASE, + ARMV6M_NVIC_IPR7 + 4 - ARMV6M_NVIC1_BASE, + PF_REGISTER); +} + +#endif /* CONFIG_ARM_COREDUMP_REGION */ diff --git a/arch/arm/src/armv7-m/CMakeLists.txt b/arch/arm/src/armv7-m/CMakeLists.txt index 1dc4dbbd14..fcb5b0f57b 100644 --- a/arch/arm/src/armv7-m/CMakeLists.txt +++ b/arch/arm/src/armv7-m/CMakeLists.txt @@ -66,4 +66,8 @@ if(CONFIG_ARM_MPU OR CONFIG_ARM_MPU_EARLY_RESET) list(APPEND SRCS arm_mpu.c) endif() +if(CONFIG_ARM_COREDUMP_REGION) + list(APPEND SRCS arm_dumpnvic.c) +endif() + target_sources(arch PRIVATE ${SRCS}) diff --git a/arch/arm/src/armv7-m/Make.defs b/arch/arm/src/armv7-m/Make.defs index c8fb3766e3..85f3a9af48 100644 --- a/arch/arm/src/armv7-m/Make.defs +++ b/arch/arm/src/armv7-m/Make.defs @@ -55,3 +55,7 @@ endif ifneq ($(filter y,$(CONFIG_ARM_MPU) $(CONFIG_ARM_MPU_EARLY_RESET)),) CMN_CSRCS += arm_mpu.c endif + +ifeq ($(CONFIG_ARM_COREDUMP_REGION),y) + CMN_CSRCS += arm_dumpnvic.c +endif diff --git a/arch/arm/src/armv7-m/arm_dumpnvic.c b/arch/arm/src/armv7-m/arm_dumpnvic.c new file mode 100644 index 0000000000..7dd91b8ac4 --- /dev/null +++ b/arch/arm/src/armv7-m/arm_dumpnvic.c @@ -0,0 +1,56 @@ +/**************************************************************************** + * arch/arm/src/armv7-m/arm_dumpnvic.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include + +#include + +#include "arm_internal.h" +#include "nvic.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#ifdef CONFIG_ARM_COREDUMP_REGION + +/**************************************************************************** + * Function: arm_coredump_add_region + * + * Description: + * Dump all NVIC registers during a core dump. + * + ****************************************************************************/ + +void arm_coredump_add_region(void) +{ + coredump_add_memory_region((uint32_t *)ARMV7M_NVIC_BASE, + NVIC_CID3 + 4 - ARMV7M_NVIC_BASE, + PF_REGISTER); +} + +#endif /* CONFIG_ARM_COREDUMP_REGION */ diff --git a/arch/arm/src/armv8-m/CMakeLists.txt b/arch/arm/src/armv8-m/CMakeLists.txt index 37112596b5..0278a3b56f 100644 --- a/arch/arm/src/armv8-m/CMakeLists.txt +++ b/arch/arm/src/armv8-m/CMakeLists.txt @@ -71,4 +71,8 @@ if(CONFIG_ARCH_TRUSTZONE_SECURE) list(APPEND SRCS arm_gen_nonsecfault.c) endif() +if(CONFIG_ARM_COREDUMP_REGION) + list(APPEND SRCS arm_dumpnvic.c) +endif() + target_sources(arch PRIVATE ${SRCS}) diff --git a/arch/arm/src/armv8-m/Make.defs b/arch/arm/src/armv8-m/Make.defs index 8c80208381..cec4256f62 100644 --- a/arch/arm/src/armv8-m/Make.defs +++ b/arch/arm/src/armv8-m/Make.defs @@ -60,3 +60,7 @@ endif ifeq ($(CONFIG_ARCH_TRUSTZONE_SECURE),y) CMN_CSRCS += arm_gen_nonsecfault.c endif + +ifeq ($(CONFIG_ARM_COREDUMP_REGION),y) + CMN_CSRCS += arm_dumpnvic.c +endif diff --git a/arch/arm/src/armv8-m/arm_dumpnvic.c b/arch/arm/src/armv8-m/arm_dumpnvic.c new file mode 100644 index 0000000000..106afb7e70 --- /dev/null +++ b/arch/arm/src/armv8-m/arm_dumpnvic.c @@ -0,0 +1,56 @@ +/**************************************************************************** + * arch/arm/src/armv8-m/arm_dumpnvic.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include + +#include + +#include "arm_internal.h" +#include "nvic.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#ifdef CONFIG_ARM_COREDUMP_REGION + +/**************************************************************************** + * Function: arm_coredump_add_region + * + * Description: + * Dump all NVIC registers during a core dump. + * + ****************************************************************************/ + +void arm_coredump_add_region(void) +{ + coredump_add_memory_region((uint32_t *)ARMV8M_NVIC_BASE, + NVIC_CID3 + 4 - ARMV8M_NVIC_BASE, + PF_REGISTER); +} + +#endif /* CONFIG_ARM_COREDUMP_REGION */ diff --git a/arch/arm/src/common/arm_initialize.c b/arch/arm/src/common/arm_initialize.c index fa79353698..e3b6c295c6 100644 --- a/arch/arm/src/common/arm_initialize.c +++ b/arch/arm/src/common/arm_initialize.c @@ -150,6 +150,10 @@ void up_initialize(void) arm_usbinitialize(); #endif +#ifdef CONFIG_ARM_COREDUMP_REGION + arm_coredump_add_region(); +#endif + /* Initialize the L2 cache if present and selected */ arm_l2ccinitialize(); diff --git a/arch/arm/src/common/arm_internal.h b/arch/arm/src/common/arm_internal.h index 3d2d3b40d8..5b8ee49d4f 100644 --- a/arch/arm/src/common/arm_internal.h +++ b/arch/arm/src/common/arm_internal.h @@ -525,6 +525,10 @@ int arm_gen_nonsecurefault(int irq, uint32_t *regs); void arm_stack_check_init(void) noinstrument_function; #endif +#ifdef CONFIG_ARM_COREDUMP_REGION + void arm_coredump_add_region(void); +#endif + #undef EXTERN #ifdef __cplusplus } diff --git a/include/nuttx/coredump.h b/include/nuttx/coredump.h index ee798223a0..45423d2b94 100644 --- a/include/nuttx/coredump.h +++ b/include/nuttx/coredump.h @@ -32,6 +32,7 @@ #include #include +#include /**************************************************************************** * Pre-processor Definitions