Cross-Compiling memfaultd
Most embedded devices have very limited resources (disk, cpu, ram). Instead of
building memfaultd
directly on the device, it's usually a better idea to
cross-compile it on a more powerful machine and then transfer the binary to the
target system.
If you are using Yocto to build your system image, then we recommend using our
meta-memfault layer to integrate memfaultd
into your system
image. Follow the Yocto Integration guide.
If you are not using Yocto, then this guide will help you cross-compile
memfaultd
from source for your target architecture.
This is the recommended way to compile and install memfaultd
on Debian,
Raspbian, Ubuntu, buildroot and OpenWRT.
Steps
Install the Rust cross
tool
We recommend using the cross
tool to quickly generate a binary
compatible with your target system.
Install Rust and cross
on your system:
# Install the rust toolchain on your system
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Install cross
cargo install cross
Docker is also required. For more detailed instructions, refer to Cross Getting Started.
Download and cross-compile memfaultd
# Clone memfaultd
git clone https://github.com/memfault/memfaultd.git
# Cross-compile memfaultd for your target architecture
cross build --no-default-features --target aarch64-unknown-linux-gnu --release -F coredump,collectd,rust-tls
# Make the binary smaller by stripping debug symbols
strip target/aarch64-unknown-linux-gnu/release/memfaultd
In this example, we are building for arm64 using the target is
aarch64-unknown-linux-gnu
.
For a list of all supported targets, see Cross
Supported Targets.
Copy memfaultd
to the target
scp target/aarch64-unknown-linux-gnu/release/memfaultd \
target/aarch64-unknown-linux-gnu/release/memfaultctl \
root@<target-ip>:/usr/bin/
scp target/aarch64-unknown-linux-gnu/release/memfault-core-handler \
root@<target-ip>:/usr/sbin/
The three binaries generated by the build are identical and will change their behavior depending on how they are called (like busybox programs). To save on disk space, you can copy only one of them and create symlinks for the other two.
Create a Project and get a Project Key
Go to app.memfault.com and from the "Select A Project" dropdown, click on "Create Project" to setup your first project such as "smart-sink-dev".
Once you've created your project, you'll be automatically taken to an page that includes your Project Key. Copy the key and follow the rest of this guide.
Add memfaultd
configuration
To test memfaultd
, you will also need:
-
A configuration file
/etc/memfaultd.conf
For example:
{
"enable_data_collection": true,
"software_version": "dev",
"software_type": "dev",
"project_key": "INSERT_YOUR_PROJECT_KEY_HERE",
"persist_dir": "/tmp/memfaultd"
}cautionReplace
INSERT_YOUR_PROJECT_KEY_HERE
with your Project Key! -
A script called
memfault-device-info
whichmemfaultd
will use to detect the Hardware Version and device id of your device.For example:
#!/bin/sh
echo MEMFAULT_HARDWARE_VERSION=smart-sink-hw-proto
echo MEMFAULT_DEVICE_ID=dev-device-42Do not forget to make this script executable:
chmod +x /usr/bin/memfault-device-info
Run memfaultd
memfaultd -c /etc/memfaultd.conf --daemonize
To automatically start memfaultd
with your system, you can take inspiration
from our systemd service file or our SysVinit init
script.
Next Steps
- Verify that your device appears in Memfault dashboard
- Memfault will capture all coredumps.
- Try triggering a coredump by running
memfaultctl trigger-coredump
and thenmemfaultctl sync
. - Your coredump will appear in the dashboard.
- Try triggering a coredump by running
- Add
collectd
to capture metrics (see our sample configuration) - Add application specific metrics to your system
- Add
fluent-bit
to capture logs - Start thinking about how you will update your devices!