Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kernel/os/include/os/arch/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions kernel/os/include/os/os_fault.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ 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);
#endif

#if MYNEWT_VAL(OS_CRASH_FILE_LINE)
#define OS_CRASH() (HAL_DEBUG_BREAK(), __assert_func(__FILE__, __LINE__, NULL, NULL))
#else
Expand Down
8 changes: 6 additions & 2 deletions kernel/os/src/arch/cortex_m33/os_fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct coredump_regs {
uint32_t psr;
};

#if MYNEWT_VAL(OS_COREDUMP)
#if MYNEWT_VAL(OS_COREDUMP) && !MYNEWT_VAL(OS_COREDUMP_CB)
static void
trap_to_coredump(struct trap_frame *tf, struct coredump_regs *regs)
{
Expand Down Expand Up @@ -204,7 +204,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)
Expand Down Expand Up @@ -243,9 +243,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, &regs);
coredump_dump(&regs, sizeof(regs));
#endif
#endif

#if MYNEWT_VAL(OS_CRASH_RESTORE_REGS)
if (((SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) < 16) &&
Expand Down
8 changes: 6 additions & 2 deletions kernel/os/src/arch/cortex_m4/os_fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct coredump_regs {
uint32_t psr;
};

#if MYNEWT_VAL(OS_COREDUMP)
#if MYNEWT_VAL(OS_COREDUMP) && !MYNEWT_VAL(OS_COREDUMP_CB)
static void
trap_to_coredump(struct trap_frame *tf, struct coredump_regs *regs)
{
Expand Down Expand Up @@ -161,7 +161,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)
Expand Down Expand Up @@ -196,9 +196,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, &regs);
coredump_dump(&regs, sizeof(regs));
#endif
#endif

#if MYNEWT_VAL(OS_CRASH_RESTORE_REGS)
if (((SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) < 16) &&
Expand Down
5 changes: 5 additions & 0 deletions kernel/os/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
79 changes: 79 additions & 0 deletions util/memfault_sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<!--
#
# 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.
#
-->
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"'
```
22 changes: 22 additions & 0 deletions util/memfault_sdk/include/memfault_sdk/memfault_sdk.h
Original file line number Diff line number Diff line change
@@ -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"
28 changes: 28 additions & 0 deletions util/memfault_sdk/pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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 <dev@mynewt.apache.org>"
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"
34 changes: 34 additions & 0 deletions util/memfault_sdk/src/memfault_sdk.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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)
void os_coredump_cb(void *tf) {
memfault_fault_handler((sMfltRegState *)tf, kMfltRebootReason_HardFault);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also handle assertions, not just hardfaults I would think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assertions also call the fault handler so we will be able to capture core dumps in those scenarios

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reset reason set here will be wrong though?

}
#endif
#endif
28 changes: 28 additions & 0 deletions util/memfault_sdk/syscfg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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'