From e41f0e9f20ac62e57b7cdf271276261fe4d31066 Mon Sep 17 00:00:00 2001 From: Tian Zeng Date: Mon, 13 Sep 2021 15:37:03 -0400 Subject: [PATCH 1/4] Memfault MyNewt Integration --- kernel/os/include/os/os_fault.h | 6 ++ kernel/os/src/arch/cortex_m33/os_fault.c | 31 +++++++- kernel/os/src/arch/cortex_m4/os_fault.c | 31 +++++++- kernel/os/syscfg.yml | 5 ++ util/memfault_sdk/README.md | 79 +++++++++++++++++++ .../include/memfault_sdk/memfault_sdk.h | 22 ++++++ util/memfault_sdk/pkg.yml | 31 ++++++++ util/memfault_sdk/src/memfault_sdk.c | 44 +++++++++++ util/memfault_sdk/syscfg.yml | 33 ++++++++ 9 files changed, 278 insertions(+), 4 deletions(-) create mode 100644 util/memfault_sdk/README.md create mode 100644 util/memfault_sdk/include/memfault_sdk/memfault_sdk.h create mode 100644 util/memfault_sdk/pkg.yml create mode 100644 util/memfault_sdk/src/memfault_sdk.c create mode 100644 util/memfault_sdk/syscfg.yml diff --git a/kernel/os/include/os/os_fault.h b/kernel/os/include/os/os_fault.h index e830e7afe6..e26ecec1aa 100644 --- a/kernel/os/include/os/os_fault.h +++ b/kernel/os/include/os/os_fault.h @@ -32,6 +32,12 @@ extern "C" { void __assert_func(const char *file, int line, const char *func, const char *e) __attribute((noreturn)); +#if MYNEWT_VAL(OS_COREDUMP_CB) +typedef void (*coredump_cb_t)(void *tf); + +void os_register_coredump_cb(coredump_cb_t coredump_cb); +#endif + #if MYNEWT_VAL(OS_CRASH_FILE_LINE) #define OS_CRASH() (HAL_DEBUG_BREAK(), __assert_func(__FILE__, __LINE__, NULL, NULL)) #else diff --git a/kernel/os/src/arch/cortex_m33/os_fault.c b/kernel/os/src/arch/cortex_m33/os_fault.c index bd4716eb86..c8b7c2b75e 100644 --- a/kernel/os/src/arch/cortex_m33/os_fault.c +++ b/kernel/os/src/arch/cortex_m33/os_fault.c @@ -77,7 +77,11 @@ struct coredump_regs { uint32_t psr; }; -#if MYNEWT_VAL(OS_COREDUMP) +#if MYNEWT_VAL(OS_COREDUMP_CB) +static coredump_cb_t g_coredump_cb; +#endif + +#if MYNEWT_VAL(OS_COREDUMP) && !MYNEWT_VAL(OS_COREDUMP_CB) static void trap_to_coredump(struct trap_frame *tf, struct coredump_regs *regs) { @@ -124,6 +128,25 @@ struct mtb_state { } mtb_state_at_crash; #endif +#if MYNEWT_VAL(OS_COREDUMP_CB) +void +os_coredump_cb(void *tf) +{ + if (g_coredump_cb) { + g_coredump_cb(tf); + } +} + +void +os_register_coredump_cb(coredump_cb_t coredump_cb) +{ + /* Register callback function */ + if (!g_coredump_cb) { + g_coredump_cb = coredump_cb; + } +} +#endif + static void mtb_stop(void) { @@ -204,7 +227,7 @@ os_default_irq(struct trap_frame *tf) #if MYNEWT_VAL(OS_CRASH_LOG) struct log_reboot_info lri; #endif -#if MYNEWT_VAL(OS_COREDUMP) +#if MYNEWT_VAL(OS_COREDUMP) && !MYNEWT_VAL(OS_COREDUMP_CB) struct coredump_regs regs; #endif #if MYNEWT_VAL(OS_CRASH_RESTORE_REGS) @@ -243,9 +266,13 @@ os_default_irq(struct trap_frame *tf) #if MYNEWT_VAL(OS_COREDUMP) hal_watchdog_tickle(); +#if MYNEWT_VAL(OS_COREDUMP_CB) + os_coredump_cb(tf); +#else trap_to_coredump(tf, ®s); coredump_dump(®s, sizeof(regs)); #endif +#endif #if MYNEWT_VAL(OS_CRASH_RESTORE_REGS) if (((SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) < 16) && diff --git a/kernel/os/src/arch/cortex_m4/os_fault.c b/kernel/os/src/arch/cortex_m4/os_fault.c index 16069ae6c7..581bfd86a5 100644 --- a/kernel/os/src/arch/cortex_m4/os_fault.c +++ b/kernel/os/src/arch/cortex_m4/os_fault.c @@ -76,7 +76,11 @@ struct coredump_regs { uint32_t psr; }; -#if MYNEWT_VAL(OS_COREDUMP) +#if MYNEWT_VAL(OS_COREDUMP_CB) +static coredump_cb_t g_coredump_cb; +#endif + +#if MYNEWT_VAL(OS_COREDUMP) && !MYNEWT_VAL(OS_COREDUMP_CB) static void trap_to_coredump(struct trap_frame *tf, struct coredump_regs *regs) { @@ -123,6 +127,25 @@ trap_to_coredump(struct trap_frame *tf, struct coredump_regs *regs) } #endif +#if MYNEWT_VAL(OS_COREDUMP_CB) +void +os_coredump_cb(void *tf) +{ + if (g_coredump_cb) { + g_coredump_cb(tf); + } +} + +void +os_register_coredump_cb(coredump_cb_t coredump_cb) +{ + /* Register callback function */ + if (!g_coredump_cb) { + g_coredump_cb = coredump_cb; + } +} +#endif + void __assert_func(const char *file, int line, const char *func, const char *e) { @@ -161,7 +184,7 @@ os_default_irq(struct trap_frame *tf) #if MYNEWT_VAL(OS_CRASH_LOG) struct log_reboot_info lri; #endif -#if MYNEWT_VAL(OS_COREDUMP) +#if MYNEWT_VAL(OS_COREDUMP) && !MYNEWT_VAL(OS_COREDUMP_CB) struct coredump_regs regs; #endif #if MYNEWT_VAL(OS_CRASH_RESTORE_REGS) @@ -196,9 +219,13 @@ os_default_irq(struct trap_frame *tf) #endif #if MYNEWT_VAL(OS_COREDUMP) +#if MYNEWT_VAL(OS_COREDUMP_CB) + os_coredump_cb(tf); +#else trap_to_coredump(tf, ®s); coredump_dump(®s, sizeof(regs)); #endif +#endif #if MYNEWT_VAL(OS_CRASH_RESTORE_REGS) if (((SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) < 16) && diff --git a/kernel/os/syscfg.yml b/kernel/os/syscfg.yml index 8ee620f533..d67bead087 100644 --- a/kernel/os/syscfg.yml +++ b/kernel/os/syscfg.yml @@ -32,6 +32,11 @@ syscfg.defs: OS_COREDUMP: description: 'Attempt to dump corefile when system crashes' value: 0 + OS_COREDUMP_CB: + description: 'Calls a custom OS coredump callback function' + value: 0 + restriction: + - 'OS_COREDUMP if 1' OS_CRASH_STACKTRACE: description: 'Attempt to print stack trace when system crashes.' value: 0 diff --git a/util/memfault_sdk/README.md b/util/memfault_sdk/README.md new file mode 100644 index 0000000000..b4b1911170 --- /dev/null +++ b/util/memfault_sdk/README.md @@ -0,0 +1,79 @@ + +To use mynewt-memfault-sdk add following lines to **project.yml**. + +```yaml +repository.mynewt-memfault-sdk: + type: github + vers: 0.0.0 + user: proxyco + repo: mynewt-memfault-sdk +``` + +This dependency will allow you to pull in memfault features +```yaml +pkg.deps: + - "@mynewt-memfault-sdk/memfault-firmware-sdk/ports/mynewt" +``` + +To use mynewt-memfault-sdk, set this values in **syscfg.vals:** section +```yaml + MEMFAULT_ENABLE: 1 +``` + +Other syscfgs you can configure are: +```yaml + MEMFAULT_DEVICE_INFO_SOFTWARE_TYPE: + description: A name to represent the firmware running on the MCU. + value: '"app-fw"' + + MEMFAULT_DEVICE_INFO_SOFTWARE_VERS: + description: The version of the "software_type" currently running. + value: '"1.0.0"' + + MEMFAULT_DEVICE_INFO_HARDWARE_VERS: + description: The revision of hardware for the device. This value must remain the same for a unique device. + value: '"dvt1"' + + MEMFAULT_EVENT_STORAGE_SIZE: + description: Storage size for Memfault events + value: 1024 + + MEMFAULT_SANITIZE_START: + description: Start address of address sanitization range + value: 0x00000000 + restrictions: + - $notnull + + MEMFAULT_SANITIZE_SIZE: + description: Size of address sanitization range + value: 0xFFFFFFFF + restrictions: + - $notnull + + MEMFAULT_DEBUG_LOG_BUFFER_SIZE: + description: Size of debug log buffer in bytes + value: 128 + + MEMFAULT_MEM_NZ_AREA: + description: Memory area that does not get zeroed out at init time + value: '".mflt.core.nz"' +``` \ No newline at end of file diff --git a/util/memfault_sdk/include/memfault_sdk/memfault_sdk.h b/util/memfault_sdk/include/memfault_sdk/memfault_sdk.h new file mode 100644 index 0000000000..8097cab3fe --- /dev/null +++ b/util/memfault_sdk/include/memfault_sdk/memfault_sdk.h @@ -0,0 +1,22 @@ +/* + * 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. + */ + +#pragma once + +#include "os/mynewt.h" \ No newline at end of file diff --git a/util/memfault_sdk/pkg.yml b/util/memfault_sdk/pkg.yml new file mode 100644 index 0000000000..de5f20a54b --- /dev/null +++ b/util/memfault_sdk/pkg.yml @@ -0,0 +1,31 @@ +# 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. + +pkg.name: util/memfault_sdk +pkg.description: "Memfault SDK package" +pkg.author: "Apache Mynewt " +pkg.homepage: "http://mynewt.apache.org/" +pkg.keywords: + +pkg.deps: + - "@apache-mynewt-core/kernel/os" + +pkg.deps.MEMFAULT_ENABLE: + - "@mynewt-memfault-sdk/memfault-firmware-sdk/ports/mynewt" + +pkg.init.MEMFAULT_ENABLE: + memfault_sdk_pkg_init: 'MYNEWT_VAL(MEMFAULT_SDK_SYSINIT_STAGE)' diff --git a/util/memfault_sdk/src/memfault_sdk.c b/util/memfault_sdk/src/memfault_sdk.c new file mode 100644 index 0000000000..42a296a15e --- /dev/null +++ b/util/memfault_sdk/src/memfault_sdk.c @@ -0,0 +1,44 @@ +/* + * 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. + */ + +#include "memfault_sdk/memfault_sdk.h" + +#if MYNEWT_VAL(MEMFAULT_ENABLE) +#include "memfault/panics/coredump.h" +#include "memfault/panics/arch/arm/cortex_m.h" +#include "memfault/panics/platform/coredump.h" +#endif + +#if MYNEWT_VAL(MEMFAULT_ENABLE) +#if MYNEWT_VAL(MEMFAULT_COREDUMP_CB) +static void +memfault_fault_handler_cb(void *tf) { + memfault_fault_handler((sMfltRegState *)tf, kMfltRebootReason_HardFault); +} +#endif + +void +memfault_sdk_pkg_init(void) +{ +#if MYNEWT_VAL(MEMFAULT_COREDUMP_CB) + /* Register callback function */ + os_register_coredump_cb(&memfault_fault_handler_cb); +#endif +} +#endif \ No newline at end of file diff --git a/util/memfault_sdk/syscfg.yml b/util/memfault_sdk/syscfg.yml new file mode 100644 index 0000000000..0ccc177f21 --- /dev/null +++ b/util/memfault_sdk/syscfg.yml @@ -0,0 +1,33 @@ +# 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. +# + +syscfg.defs: + MEMFAULT_ENABLE: + description: 'Enables Memfault SDK features' + value: 0 + + MEMFAULT_COREDUMP_CB: + description: 'Enable custom memfault coredump handling cb' + value: 0 + restriction: + - 'OS_COREDUMP_CB if 1' + + MEMFAULT_SDK_SYSINIT_STAGE: + description: > + Sysinit stage for memfault. + value: 600 From 97b8dfd6942171fc5b1b7b80b8c073e1f244ba26 Mon Sep 17 00:00:00 2001 From: Tian Zeng Date: Tue, 28 Sep 2021 10:35:04 -0400 Subject: [PATCH 2/4] Replace callback registration with compile time function pointer --- kernel/os/include/os/arch/common.h | 1 + kernel/os/include/os/os_fault.h | 2 -- kernel/os/src/arch/cortex_m33/os_fault.c | 23 ----------------------- kernel/os/src/arch/cortex_m4/os_fault.c | 23 ----------------------- util/memfault_sdk/pkg.yml | 3 --- util/memfault_sdk/src/memfault_sdk.c | 12 +----------- util/memfault_sdk/syscfg.yml | 5 ----- 7 files changed, 2 insertions(+), 67 deletions(-) diff --git a/kernel/os/include/os/arch/common.h b/kernel/os/include/os/arch/common.h index ce80fbb32e..c5f09f3a7e 100644 --- a/kernel/os/include/os/arch/common.h +++ b/kernel/os/include/os/arch/common.h @@ -71,6 +71,7 @@ void os_set_env(os_stack_t *); void os_arch_init_task_stack(os_stack_t *sf); void os_default_irq_asm(void); void os_assert_cb(void); +void os_coredump_cb(void *tf); #ifdef __cplusplus } diff --git a/kernel/os/include/os/os_fault.h b/kernel/os/include/os/os_fault.h index e26ecec1aa..098bf74900 100644 --- a/kernel/os/include/os/os_fault.h +++ b/kernel/os/include/os/os_fault.h @@ -34,8 +34,6 @@ void __assert_func(const char *file, int line, const char *func, const char *e) #if MYNEWT_VAL(OS_COREDUMP_CB) typedef void (*coredump_cb_t)(void *tf); - -void os_register_coredump_cb(coredump_cb_t coredump_cb); #endif #if MYNEWT_VAL(OS_CRASH_FILE_LINE) diff --git a/kernel/os/src/arch/cortex_m33/os_fault.c b/kernel/os/src/arch/cortex_m33/os_fault.c index c8b7c2b75e..15b5f242f8 100644 --- a/kernel/os/src/arch/cortex_m33/os_fault.c +++ b/kernel/os/src/arch/cortex_m33/os_fault.c @@ -77,10 +77,6 @@ struct coredump_regs { uint32_t psr; }; -#if MYNEWT_VAL(OS_COREDUMP_CB) -static coredump_cb_t g_coredump_cb; -#endif - #if MYNEWT_VAL(OS_COREDUMP) && !MYNEWT_VAL(OS_COREDUMP_CB) static void trap_to_coredump(struct trap_frame *tf, struct coredump_regs *regs) @@ -128,25 +124,6 @@ struct mtb_state { } mtb_state_at_crash; #endif -#if MYNEWT_VAL(OS_COREDUMP_CB) -void -os_coredump_cb(void *tf) -{ - if (g_coredump_cb) { - g_coredump_cb(tf); - } -} - -void -os_register_coredump_cb(coredump_cb_t coredump_cb) -{ - /* Register callback function */ - if (!g_coredump_cb) { - g_coredump_cb = coredump_cb; - } -} -#endif - static void mtb_stop(void) { diff --git a/kernel/os/src/arch/cortex_m4/os_fault.c b/kernel/os/src/arch/cortex_m4/os_fault.c index 581bfd86a5..7928d8a786 100644 --- a/kernel/os/src/arch/cortex_m4/os_fault.c +++ b/kernel/os/src/arch/cortex_m4/os_fault.c @@ -76,10 +76,6 @@ struct coredump_regs { uint32_t psr; }; -#if MYNEWT_VAL(OS_COREDUMP_CB) -static coredump_cb_t g_coredump_cb; -#endif - #if MYNEWT_VAL(OS_COREDUMP) && !MYNEWT_VAL(OS_COREDUMP_CB) static void trap_to_coredump(struct trap_frame *tf, struct coredump_regs *regs) @@ -127,25 +123,6 @@ trap_to_coredump(struct trap_frame *tf, struct coredump_regs *regs) } #endif -#if MYNEWT_VAL(OS_COREDUMP_CB) -void -os_coredump_cb(void *tf) -{ - if (g_coredump_cb) { - g_coredump_cb(tf); - } -} - -void -os_register_coredump_cb(coredump_cb_t coredump_cb) -{ - /* Register callback function */ - if (!g_coredump_cb) { - g_coredump_cb = coredump_cb; - } -} -#endif - void __assert_func(const char *file, int line, const char *func, const char *e) { diff --git a/util/memfault_sdk/pkg.yml b/util/memfault_sdk/pkg.yml index de5f20a54b..115ebcc83e 100644 --- a/util/memfault_sdk/pkg.yml +++ b/util/memfault_sdk/pkg.yml @@ -26,6 +26,3 @@ pkg.deps: pkg.deps.MEMFAULT_ENABLE: - "@mynewt-memfault-sdk/memfault-firmware-sdk/ports/mynewt" - -pkg.init.MEMFAULT_ENABLE: - memfault_sdk_pkg_init: 'MYNEWT_VAL(MEMFAULT_SDK_SYSINIT_STAGE)' diff --git a/util/memfault_sdk/src/memfault_sdk.c b/util/memfault_sdk/src/memfault_sdk.c index 42a296a15e..f514d5668e 100644 --- a/util/memfault_sdk/src/memfault_sdk.c +++ b/util/memfault_sdk/src/memfault_sdk.c @@ -27,18 +27,8 @@ #if MYNEWT_VAL(MEMFAULT_ENABLE) #if MYNEWT_VAL(MEMFAULT_COREDUMP_CB) -static void -memfault_fault_handler_cb(void *tf) { +void os_coredump_cb(void *tf) { memfault_fault_handler((sMfltRegState *)tf, kMfltRebootReason_HardFault); } #endif - -void -memfault_sdk_pkg_init(void) -{ -#if MYNEWT_VAL(MEMFAULT_COREDUMP_CB) - /* Register callback function */ - os_register_coredump_cb(&memfault_fault_handler_cb); -#endif -} #endif \ No newline at end of file diff --git a/util/memfault_sdk/syscfg.yml b/util/memfault_sdk/syscfg.yml index 0ccc177f21..d601af9ad0 100644 --- a/util/memfault_sdk/syscfg.yml +++ b/util/memfault_sdk/syscfg.yml @@ -26,8 +26,3 @@ syscfg.defs: value: 0 restriction: - 'OS_COREDUMP_CB if 1' - - MEMFAULT_SDK_SYSINIT_STAGE: - description: > - Sysinit stage for memfault. - value: 600 From 01281f43449d5a4ec5ee15a35a9a1f3e7823788c Mon Sep 17 00:00:00 2001 From: Tian Zeng Date: Wed, 6 Oct 2021 16:53:57 -0400 Subject: [PATCH 3/4] Point util package depedency directly to official memfault sdk --- util/memfault_sdk/README.md | 101 ++++++++++++++++++++---------------- util/memfault_sdk/pkg.yml | 2 +- 2 files changed, 57 insertions(+), 46 deletions(-) diff --git a/util/memfault_sdk/README.md b/util/memfault_sdk/README.md index b4b1911170..722735fb6e 100644 --- a/util/memfault_sdk/README.md +++ b/util/memfault_sdk/README.md @@ -18,62 +18,73 @@ # under the License. # --> -To use mynewt-memfault-sdk add following lines to **project.yml**. +## Overview + +To use the memfault-firmware-sdk with mynewt add following lines to +**project.yml**. ```yaml -repository.mynewt-memfault-sdk: - type: github - vers: 0.0.0 - user: proxyco - repo: mynewt-memfault-sdk +repository.memfault-firmware-sdk: + type: github + vers: 0.0.0 + user: memfault + repo: memfault-firmware-sdk ``` -This dependency will allow you to pull in memfault features +Adding this dependency will allow you to pull in Memfault features + ```yaml pkg.deps: - - "@mynewt-memfault-sdk/memfault-firmware-sdk/ports/mynewt" + - "@memfault-firmware-sdk/ports/mynewt" ``` -To use mynewt-memfault-sdk, set this values in **syscfg.vals:** section +You will also need to enable the following options in the **syscfg.vals:** +section of your `syscfg.yml` file: + ```yaml +syscfg.vals: + [...] + MEMFAULT_COREDUMP_CB: 1 MEMFAULT_ENABLE: 1 + OS_COREDUMP: 1 + OS_COREDUMP_CB: 1 ``` -Other syscfgs you can configure are: -```yaml - MEMFAULT_DEVICE_INFO_SOFTWARE_TYPE: - description: A name to represent the firmware running on the MCU. - value: '"app-fw"' - - MEMFAULT_DEVICE_INFO_SOFTWARE_VERS: - description: The version of the "software_type" currently running. - value: '"1.0.0"' - - MEMFAULT_DEVICE_INFO_HARDWARE_VERS: - description: The revision of hardware for the device. This value must remain the same for a unique device. - value: '"dvt1"' +Other syscfgs you can configure can be found in [syscfg.yml](syscfg.yml) + +Finally, on boot up initialize the Memfault subsystem from your `main` routine: + +```c +#include "memfault/components.h" +int +main(int argc, char **argv) +{ +// ... + memfault_platform_boot(); +// ... +} +``` + +## Using the GNU Build Id for Indexing - MEMFAULT_EVENT_STORAGE_SIZE: - description: Storage size for Memfault events - value: 1024 - - MEMFAULT_SANITIZE_START: - description: Start address of address sanitization range - value: 0x00000000 - restrictions: - - $notnull - - MEMFAULT_SANITIZE_SIZE: - description: Size of address sanitization range - value: 0xFFFFFFFF - restrictions: - - $notnull - - MEMFAULT_DEBUG_LOG_BUFFER_SIZE: - description: Size of debug log buffer in bytes - value: 128 - - MEMFAULT_MEM_NZ_AREA: - description: Memory area that does not get zeroed out at init time - value: '".mflt.core.nz"' +We recommend enabling the generation of a unique identifier for your project. +See https://mflt.io/symbol-file-build-ids for more details. + +To enable, add the following compilation flags to your `pkg.yml`: + +``` +pkg.lflags: + - -Wl,--build-id +pkg.cflags: + - -DMEMFAULT_USE_GNU_BUILD_ID=1 +``` + +And add the following **after** the `.text` in your targets linker script: + +``` + .note.gnu.build-id : + { + __start_gnu_build_id_start = .; + KEEP(*(.note.gnu.build-id)) + } > FLASH ``` \ No newline at end of file diff --git a/util/memfault_sdk/pkg.yml b/util/memfault_sdk/pkg.yml index 115ebcc83e..45cc0fd019 100644 --- a/util/memfault_sdk/pkg.yml +++ b/util/memfault_sdk/pkg.yml @@ -25,4 +25,4 @@ pkg.deps: - "@apache-mynewt-core/kernel/os" pkg.deps.MEMFAULT_ENABLE: - - "@mynewt-memfault-sdk/memfault-firmware-sdk/ports/mynewt" + - "@memfault-firmware-sdk/ports/mynewt" From 35269fbe0869aac4e057bae8b078b351e89ffba3 Mon Sep 17 00:00:00 2001 From: Tian Zeng Date: Wed, 6 Oct 2021 18:07:08 -0400 Subject: [PATCH 4/4] Define different reboot reason for asserts --- util/memfault_sdk/README.md | 2 ++ util/memfault_sdk/src/memfault_sdk.c | 12 +++++++++++- util/memfault_sdk/syscfg.yml | 9 +++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/util/memfault_sdk/README.md b/util/memfault_sdk/README.md index 722735fb6e..3e8b8eeaee 100644 --- a/util/memfault_sdk/README.md +++ b/util/memfault_sdk/README.md @@ -44,10 +44,12 @@ section of your `syscfg.yml` file: ```yaml syscfg.vals: [...] + MEMFAULT_ASSERT_CB: 1 MEMFAULT_COREDUMP_CB: 1 MEMFAULT_ENABLE: 1 OS_COREDUMP: 1 OS_COREDUMP_CB: 1 + OS_ASSERT_CB: 1 ``` Other syscfgs you can configure can be found in [syscfg.yml](syscfg.yml) diff --git a/util/memfault_sdk/src/memfault_sdk.c b/util/memfault_sdk/src/memfault_sdk.c index f514d5668e..f158f50017 100644 --- a/util/memfault_sdk/src/memfault_sdk.c +++ b/util/memfault_sdk/src/memfault_sdk.c @@ -27,8 +27,18 @@ #if MYNEWT_VAL(MEMFAULT_ENABLE) #if MYNEWT_VAL(MEMFAULT_COREDUMP_CB) + +eMemfaultRebootReason reboot_reason = kMfltRebootReason_HardFault; + +#if MYNEWT_VAL(MEMFAULT_ASSERT_CB) +void os_assert_cb(void) +{ + reboot_reason = kMfltRebootReason_Assert; +} +#endif + void os_coredump_cb(void *tf) { - memfault_fault_handler((sMfltRegState *)tf, kMfltRebootReason_HardFault); + memfault_fault_handler((sMfltRegState *)tf, reboot_reason); } #endif #endif \ No newline at end of file diff --git a/util/memfault_sdk/syscfg.yml b/util/memfault_sdk/syscfg.yml index d601af9ad0..14eebe1e91 100644 --- a/util/memfault_sdk/syscfg.yml +++ b/util/memfault_sdk/syscfg.yml @@ -25,4 +25,13 @@ syscfg.defs: description: 'Enable custom memfault coredump handling cb' value: 0 restriction: + - 'MEMFAULT_ENABLE if 1' - 'OS_COREDUMP_CB if 1' + + MEMFAULT_ASSERT_CB: + description: 'Enable custom memfault coredump handling cb' + value: 0 + restriction: + - 'MEMFAULT_ENABLE if 1' + - 'MEMFAULT_COREDUMP_CB if 1' + - 'OS_ASSERT_CB if 1'