···1+{ stdenv, lib, fetchFromGitHub
2+, gcc-arm-embedded, bash, libftdi
3+, python, pythonPackages
4+}:
5+6+with lib;
7+8+stdenv.mkDerivation rec {
9+ name = "blackmagic-${version}";
10+ version = "1.6.1";
11+12+ src = fetchFromGitHub {
13+ owner = "blacksphere";
14+ repo = "blackmagic";
15+ rev = "d3a8f27fdbf952194e8fc5ce9b2fc9bcef7c545c";
16+ sha256 = "0c3l7cfqag3g7zrfn4mmikkx7076hb1r856ybhhdh0f6zji2j6jx";
17+ fetchSubmodules = true;
18+ };
19+20+ buildInputs = [
21+ gcc-arm-embedded
22+ libftdi
23+ python
24+ pythonPackages.intelhex
25+ ];
26+27+ postPatch = ''
28+ # Prevent calling out to `git' to generate a version number:
29+ substituteInPlace src/Makefile \
30+ --replace '`git describe --always --dirty`' '${version}'
31+32+ # Fix scripts that generate headers:
33+ for f in $(find scripts libopencm3/scripts -type f); do
34+ patchShebangs "$f"
35+ done
36+ '';
37+38+ buildPhase = "${stdenv.shell} ${./helper.sh}";
39+ installPhase = ":"; # buildPhase does this.
40+41+ meta = {
42+ description = "In-application debugger for ARM Cortex microcontrollers";
43+ longDescription = ''
44+ The Black Magic Probe is a modern, in-application debugging tool
45+ for embedded microprocessors. It allows you to see what is going
46+ on "inside" an application running on an embedded microprocessor
47+ while it executes.
48+49+ This package builds the firmware for all supported platforms,
50+ placing them in separate directories under the firmware
51+ directory. It also places the FTDI version of the blackmagic
52+ executable in the bin directory.
53+ '';
54+ homepage = https://github.com/blacksphere/blackmagic;
55+ license = licenses.gpl3Plus;
56+ maintainers = with maintainers; [ pjones ];
57+ platforms = platforms.unix;
58+ };
59+}
···1+################################################################################
2+# Build all of the platforms manually since the `all_platforms' target
3+# doesn't preserve all of the build outputs and overrides CFLAGS.
4+set -e
5+set -u
6+7+################################################################################
8+# Prevent a warning from shellcheck:
9+out=${out:-/tmp}
10+11+################################################################################
12+export CFLAGS=$NIX_CFLAGS_COMPILE
13+14+################################################################################
15+PRODUCTS="blackmagic.bin blackmagic.hex blackmagic_dfu.bin blackmagic_dfu.hex"
16+17+################################################################################
18+make_platform() {
19+ echo "Building for hardware platform $1"
20+21+ make clean
22+ make PROBE_HOST="$1"
23+24+ if [ "$1" = libftdi ]; then
25+ mkdir -p "$out/bin"
26+ install -m 0555 blackmagic "$out/bin"
27+ fi
28+29+ for f in $PRODUCTS; do
30+ if [ -r "$f" ]; then
31+ mkdir -p "$out/firmware/$1"
32+ install -m 0444 "$f" "$out/firmware/$1"
33+ fi
34+ done
35+36+}
37+38+################################################################################
39+# Start by building libopencm3:
40+make -C libopencm3
41+42+################################################################################
43+# And now all of the platforms:
44+cd src
45+46+for platform in platforms/*/Makefile.inc; do
47+ probe=$(basename "$(dirname "$platform")")
48+ make_platform "$probe"
49+done