···11+{ stdenv, lib, fetchFromGitHub
22+, gcc-arm-embedded, bash, libftdi
33+, python, pythonPackages
44+}:
55+66+with lib;
77+88+stdenv.mkDerivation rec {
99+ name = "blackmagic-${version}";
1010+ version = "1.6.1";
1111+1212+ src = fetchFromGitHub {
1313+ owner = "blacksphere";
1414+ repo = "blackmagic";
1515+ rev = "d3a8f27fdbf952194e8fc5ce9b2fc9bcef7c545c";
1616+ sha256 = "0c3l7cfqag3g7zrfn4mmikkx7076hb1r856ybhhdh0f6zji2j6jx";
1717+ fetchSubmodules = true;
1818+ };
1919+2020+ buildInputs = [
2121+ gcc-arm-embedded
2222+ libftdi
2323+ python
2424+ pythonPackages.intelhex
2525+ ];
2626+2727+ postPatch = ''
2828+ # Prevent calling out to `git' to generate a version number:
2929+ substituteInPlace src/Makefile \
3030+ --replace '`git describe --always --dirty`' '${version}'
3131+3232+ # Fix scripts that generate headers:
3333+ for f in $(find scripts libopencm3/scripts -type f); do
3434+ patchShebangs "$f"
3535+ done
3636+ '';
3737+3838+ buildPhase = "${stdenv.shell} ${./helper.sh}";
3939+ installPhase = ":"; # buildPhase does this.
4040+4141+ meta = {
4242+ description = "In-application debugger for ARM Cortex microcontrollers";
4343+ longDescription = ''
4444+ The Black Magic Probe is a modern, in-application debugging tool
4545+ for embedded microprocessors. It allows you to see what is going
4646+ on "inside" an application running on an embedded microprocessor
4747+ while it executes.
4848+4949+ This package builds the firmware for all supported platforms,
5050+ placing them in separate directories under the firmware
5151+ directory. It also places the FTDI version of the blackmagic
5252+ executable in the bin directory.
5353+ '';
5454+ homepage = https://github.com/blacksphere/blackmagic;
5555+ license = licenses.gpl3Plus;
5656+ maintainers = with maintainers; [ pjones ];
5757+ platforms = platforms.unix;
5858+ };
5959+}
+49
pkgs/development/tools/misc/blackmagic/helper.sh
···11+################################################################################
22+# Build all of the platforms manually since the `all_platforms' target
33+# doesn't preserve all of the build outputs and overrides CFLAGS.
44+set -e
55+set -u
66+77+################################################################################
88+# Prevent a warning from shellcheck:
99+out=${out:-/tmp}
1010+1111+################################################################################
1212+export CFLAGS=$NIX_CFLAGS_COMPILE
1313+1414+################################################################################
1515+PRODUCTS="blackmagic.bin blackmagic.hex blackmagic_dfu.bin blackmagic_dfu.hex"
1616+1717+################################################################################
1818+make_platform() {
1919+ echo "Building for hardware platform $1"
2020+2121+ make clean
2222+ make PROBE_HOST="$1"
2323+2424+ if [ "$1" = libftdi ]; then
2525+ mkdir -p "$out/bin"
2626+ install -m 0555 blackmagic "$out/bin"
2727+ fi
2828+2929+ for f in $PRODUCTS; do
3030+ if [ -r "$f" ]; then
3131+ mkdir -p "$out/firmware/$1"
3232+ install -m 0444 "$f" "$out/firmware/$1"
3333+ fi
3434+ done
3535+3636+}
3737+3838+################################################################################
3939+# Start by building libopencm3:
4040+make -C libopencm3
4141+4242+################################################################################
4343+# And now all of the platforms:
4444+cd src
4545+4646+for platform in platforms/*/Makefile.inc; do
4747+ probe=$(basename "$(dirname "$platform")")
4848+ make_platform "$probe"
4949+done