Software development notes
by Andrew
I recently pushed a couple of tools (overlay and bbdbg) into the openbmc-tools repository that help me develop userspace software for OpenBMC. This post describes how I work with all the different tools involved.
Without modifying anything in a stock OpenBMC image, the process to generate the
build artifacts is to issue bitbake obmc-phosphor-image
. Building a stock
image doesn’t help much with developing userspace applications though, so there
needs to be more to the story.
An approach to building specific applications to run in the target environment
generated by bitbake
is to use the SDK, configuring your shell session so you
can build arbitrary applications for the target. But there are at least two
pitfalls to the SDK: It takes a long time to build and install, and in
OpenBMC’s case there’s no promise of ABI stability. In general this means
building an SDK that’s specific to the state of the target environment, down to
the specific commit the target image was built from.
With those constraints in mind, I prefer to try routes that don’t involve the
SDK. bitbake
is the tool for building the images, so it would be useful if we
could reuse it or its environment. With devtool
it turns out we can.
Here’s a run-down of the process I follow:
cd ~/src/openbmc/openbmc
. setup p10bmc
bitbake obmc-phosphor-image
From here we deploy the resulting image onto the target in the usual fashion.
cd ~/src/openbmc
git clone https://github.com/openbmc/dbus-sensors.git
cd dbus-sensors
git checkout -b my-hacks
vi src/NVMeSensorMain.cpp
git commit -a -m "my hacks"
In this case we’ve modified src/NVMeSensorMain.cpp
which forms part of the
source for the nvmesensor
application installed into /usr/bin
on the target.
devtool modify dbus-sensors
cd ~/src/openbmc/openbmc/build/p10bmc/workspace/sources/dbus-sensors
git remote add local ~/src/openbmc/dbus-sensors
git fetch local my-hacks && git merge FETCH_HEAD
devtool build dbus-sensors
overlay add /usr/bin /lib/systemd/system ...
For systems with a read-only rootfs, this makes the directory arguments writable
by overlaying them with a tmpfs
. The overlay
script handles the grunt work of
setting up the necessary tmpfs
mountpoints, whose location we don’t really
care about in the general case.
The overlay
script lives here and should just be copied onto the target
using scp
.
devtool deploy-target --no-host-check --show-status --no-check-space --strip dbus-sensors
Note this may require a rather hacky patch to devtool
/usr/bin/nvmesensor
/usr/bin/nvmesensor
generates a core-dumpcoredumpctl dump $PID -o /tmp/core
bitbake -c do_rootfs obmc-phosphor-image
devtool build
doesn’t run the step of packaging up the application for opkg
to deploy and updating the package index, so we have to explicitly invoke this
step ourselves.
scp $BMC:/tmp/core .
bbdbg ~/src/openbmc/openbmc/build/p10bmc /usr/bin/nvmesensor core dbus-sensors dbus-sensors-dbg
Using bbdbg
we create ourselves a gdb
session where we can perform
sensible analysis of the nvmesensor
core with all the necessary symbols loaded
in. The easiest way to access bbdbg
is to clone the openbmc-tools
repository onto your development machine.
gdbserver
and bbdbg
If we return to the step 16 where we’re testing nvmesensor
on the target, we
can also do interactive debug rather than core debug if we use gdbserver
on
the target.
gdbserver
to a running applicationgdbserver --attach localhost:1234 $PID
Note that gdbserver
typically ignores the host
portion of host:port
, so we
just pick localhost
here.
bbdbg
to attach to the remote gdbserver
bbdbg ~/src/openbmc/openbmc/build/p10bmc /usr/bin/nvmesensor - dbus-sensors dbus-sensors-dbg
(gdb) target remote $BMC:1234