Add debug script for deploying the debug tools tarball on Witherspoon
The debug script captures work-arounds required for getting perf(1) to work on
Witherspoon.
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/amboar/obmc-scripts/witherspoon-debug/README.md b/amboar/obmc-scripts/witherspoon-debug/README.md
new file mode 100644
index 0000000..3840aba
--- /dev/null
+++ b/amboar/obmc-scripts/witherspoon-debug/README.md
@@ -0,0 +1,33 @@
+Description
+===========
+
+The OpenBMC debugtools tarball clashes with the filesystem layout of
+witherspoon systems, and contains a number of other outstanding issues with
+respect to the tools it deploys. The debug script here documents and executes
+the workarounds necessary to make it functional.
+
+Usage
+-----
+```
+./debug [USER@]HOST TARBALL
+```
+
+For example:
+
+```
+$ ./debug root@my-witherspoon obmc-phosphor-debug-tarball-witherspoon.tar.xz
+```
+
+Notes
+-----
+
+The script will:
+
+1. Ensure `/usr/local` is a tmpfs mountpoint (may not be if system is
+ configured for Field Mode)
+2. Deploy the debugtools tarball to `/usr/local`
+3. Make `perf(1)` work by
+ 1. Installing a fake `expand(1)` if necessary
+ 2. Fixing the `objdump(1)` symlink
+ 3. Disabling `perf(1)`'s buildid tracking (fills the RW filesystem)
+4. Make `latencytop(1)` work by deploying and symlinking libncurses{,w}.so
diff --git a/amboar/obmc-scripts/witherspoon-debug/debug b/amboar/obmc-scripts/witherspoon-debug/debug
new file mode 100755
index 0000000..42c7581
--- /dev/null
+++ b/amboar/obmc-scripts/witherspoon-debug/debug
@@ -0,0 +1,93 @@
+#!/bin/bash
+#
+# SPDX-License-Identifier: Apache-2.0
+# Copyright (C) 2018 IBM Corp.
+
+set -eou pipefail
+
+if [ $# -lt 2 ]
+then
+ echo Usage: $0 [user@][host] [tarball]
+ exit 1
+fi
+
+TARGET="$1"
+DEBUGTOOLS_PATH="$2"
+DEBUGTOOLS="$(basename "${DEBUGTOOLS_PATH}")"
+
+scp "${DEBUGTOOLS_PATH}" libncurses.so.5.9 libncursesw.so.5.9 "${TARGET}":/tmp/
+ssh "${TARGET}" <<-EOF
+set -eou pipefail
+
+set -x
+
+on_exit() {
+ rm -f /tmp/'${DEBUGTOOLS}'
+ rm -f /tmp/libncurses.so.5.9 /tmp/libncursesw.so.5.9
+}
+
+trap on_exit EXIT
+
+# Deal with field mode
+if ! mountpoint /usr/local
+then
+ systemctl unmask usr-local.mount
+ systemctl start usr-local.mount
+fi
+
+# Untar debug tools tarball into /usr/local
+pushd /usr/local
+tar -xvJf /tmp/"${DEBUGTOOLS}"
+popd
+
+# Work around bugs preventing perf from working
+# Tracking issue: https://github.com/openbmc/openbmc/issues/2880
+
+# Fake expand(1): https://github.com/openbmc/openbmc/issues/2879
+mkdir -p bin
+pushd /usr/local/bin
+# which expand isn't enough as expand might be a symlink to a busybox not built with CONFIG_EXPAND
+if ! echo "" | expand
+then
+ # Remove what is likely a symlink to busybox before trying to overwrite
+ # file because:
+ #
+ # 1) We get errors through trying to write to a read-only filesystem
+ # 2) If the filesystem were read-write, we would overwrite the busybox binary
+ [ -f expand ] && rm expand
+ # Fake out expand(1) in the cheapest way possible
+ echo -e "#!/bin/sh\ncat" > expand
+ chmod +x expand
+fi
+
+# Fix the broken objdump link: https://github.com/openbmc/openbmc/issues/2878
+ln -sf arm-openbmc-linux-gnueabi-objdump objdump
+popd
+
+# perf-config(1) is terrible and won't write your configuration unless the
+# configuration file exists
+touch \${HOME}/.perfconfig
+
+# Disable writing junk to \${HOME}, otherwise we fill up the RW volume and
+# cause systemic failures.
+LD_LIBRARY_PATH=/usr/local/lib /usr/local/bin/perf config --user buildid.dir=/dev/null
+
+# Deal with latencytop's missing shared object dependency on ncurses, tracked by
+# https://github.com/openbmc/openbmc/issues/2430
+pushd /usr/local/lib
+if [ -f /tmp/libncurses.so.5.9 -o -f /tmp/libncursesw.so.5.9 ]
+then
+ cp /tmp/libncurses.so.5.9 /tmp/libncursesw.so.5.9 .
+ ln -sf libncurses.so.5.9 libncurses.so.5
+ ln -sf libncurses.so.5.9 libncurses.so
+ ln -sf libncursesw.so.5.9 libncursesw.so.5
+ ln -sf libncursesw.so.5.9 libncursesw.so
+fi
+popd
+EOF
+
+echo
+echo Make sure to run the following in your shell:
+echo
+echo export LD_LIBRARY_PATH=/usr/local/lib PYTHONPATH=/usr/local/lib/python2.7
+echo
diff --git a/amboar/obmc-scripts/witherspoon-debug/libncurses.so.5.9 b/amboar/obmc-scripts/witherspoon-debug/libncurses.so.5.9
new file mode 100755
index 0000000..f0b6ec1
--- /dev/null
+++ b/amboar/obmc-scripts/witherspoon-debug/libncurses.so.5.9
Binary files differ
diff --git a/amboar/obmc-scripts/witherspoon-debug/libncursesw.so.5.9 b/amboar/obmc-scripts/witherspoon-debug/libncursesw.so.5.9
new file mode 100755
index 0000000..9388407
--- /dev/null
+++ b/amboar/obmc-scripts/witherspoon-debug/libncursesw.so.5.9
Binary files differ