diff --git a/pkgs/by-name/bl/blackmagic/helper.sh b/pkgs/by-name/bl/blackmagic/helper.sh deleted file mode 100755 index 77f84ef890d4..000000000000 --- a/pkgs/by-name/bl/blackmagic/helper.sh +++ /dev/null @@ -1,51 +0,0 @@ -################################################################################ -# Build all of the platforms manually since the `all_platforms' target -# doesn't preserve all of the build outputs and overrides CFLAGS. -set -e -set -u - -################################################################################ -# Prevent a warning from shellcheck: -out=${out:-/tmp} - -################################################################################ -export MAKEFLAGS="\ - ${enableParallelBuilding:+-j${NIX_BUILD_CORES}}" - -################################################################################ -PRODUCTS="blackmagic.bin blackmagic.hex blackmagic_dfu.bin blackmagic_dfu.hex" - -################################################################################ -make_platform() { - echo "Building for hardware platform $1" - - make clean - make PROBE_HOST="$1" - - if [ "$1" = "hosted" ]; then - install -m 0555 blackmagic "$out/bin" - fi - - for f in $PRODUCTS; do - if [ -r "$f" ]; then - mkdir -p "$out/firmware/$1" - install -m 0444 "$f" "$out/firmware/$1" - fi - done - -} - -################################################################################ -# Start by building libopencm3: -make -C libopencm3 - -################################################################################ -# And now all of the platforms: -cd src - -mkdir -p "$out/bin" - -for platform in platforms/*/Makefile.inc; do - probe=$(basename "$(dirname "$platform")") - make_platform "$probe" -done diff --git a/pkgs/by-name/bl/blackmagic/package.nix b/pkgs/by-name/bl/blackmagic/package.nix index de9749036fea..5755cd4f63e2 100644 --- a/pkgs/by-name/bl/blackmagic/package.nix +++ b/pkgs/by-name/bl/blackmagic/package.nix @@ -2,62 +2,120 @@ stdenv, lib, fetchFromGitHub, - gcc-arm-embedded, + gcc-arm-embedded-13, pkg-config, - python3, + meson, + ninja, hidapi, libftdi1, libusb1, + libgpiod_1, + versionCheckHook, + udevCheckHook, }: +let + libopencm3Src = fetchFromGitHub { + owner = "libopencm3"; + repo = "libopencm3"; + rev = "8a96a9d95a8e5c187a53652540b25a8f4d73a432"; + hash = "sha256-PylP95hpPeg3rqfelHW9qz+pi/qOP60RfvkurxbkWDs="; + }; + ctxlinkWinc1500Src = fetchFromGitHub { + owner = "sidprice"; + repo = "ctxlink_winc1500"; + rev = "debeab9516e33622439f727a68bddabcdf52c528"; + hash = "sha256-IWLIJu2XuwsnP8/2C9uj09EBU2VtwTke3XXbc3NyZt4="; + }; +in stdenv.mkDerivation rec { pname = "blackmagic"; - version = "1.8.2"; + version = "2.0.0"; # `git describe --always` firmwareVersion = "v${version}"; src = fetchFromGitHub { - owner = "blacksphere"; + owner = "blackmagic-debug"; repo = "blackmagic"; rev = firmwareVersion; - hash = "sha256-NGzoohmpVwGOncr9AvHYANMf/oEskjmTXYj/Kdx2RwM="; - fetchSubmodules = true; + hash = "sha256-JbPeN0seSkxV2uZ8BvsvjDUBMOyJu2BxqMgNkhLOiFI="; }; nativeBuildInputs = [ - gcc-arm-embedded + gcc-arm-embedded-13 # fails to build with 14 pkg-config - python3 + meson + ninja + udevCheckHook ]; buildInputs = [ hidapi libftdi1 libusb1 - ]; + ] + ++ lib.optional stdenv.hostPlatform.isLinux libgpiod_1; strictDeps = true; - postPatch = '' - # Prevent calling out to `git' to generate a version number: - substituteInPlace src/Makefile \ - --replace '$(shell git describe --always --dirty)' '${firmwareVersion}' + postUnpack = '' + mkdir -p $sourceRoot/deps/libopencm3 + cp -r ${libopencm3Src}/* $sourceRoot/deps/libopencm3/ - # Fix scripts that generate headers: - for f in $(find scripts libopencm3/scripts -type f); do - patchShebangs "$f" - done + mkdir -p $sourceRoot/deps/winc1500 + cp -r ${ctxlinkWinc1500Src}/* $sourceRoot/deps/winc1500/ ''; buildPhase = '' runHook preBuild - ${stdenv.shell} ${./helper.sh} + + echo "Building host cli" + meson compile -C . + + echo "Building probe firmware" + pushd .. + for cf in cross-file/*.ini; do + target=$(basename "''${cf%.ini}") + + if [ "$target" = "arm-none-eabi" ]; then + echo "Skipping arm-none-eabi target" + continue + fi + + echo "Building target: $target" + mkdir -p "build/firmware/$target" + meson setup "build/firmware/$target" --cross-file "$cf" + meson compile -C "build/firmware/$target" + done + popd + runHook postBuild ''; - dontInstall = true; + installPhase = '' + runHook preInstall - enableParallelBuilding = true; + echo "Installing host cli" + install -Dm555 blackmagic $out/bin/blackmagic + + echo "Installing probe firmware" + for targetDir in firmware/*; do + target=$(basename "$targetDir") + echo "Installing firmware for target: $target" + for f in $targetDir/*.{bin,elf}; do + install -Dm444 $f $out/firmware/$target/$(basename "$f") + done + done + + echo "Installing udev rules" + install -Dm444 ../driver/99-blackmagic-plugdev.rules $out/lib/udev/rules.d/99-blackmagic-plugdev.rules + + runHook postInstall + ''; + + nativeInstallCheckInputs = [ versionCheckHook ]; + versionCheckProgramArg = "--help"; + doInstallCheck = true; meta = with lib; { description = "In-application debugger for ARM Cortex microcontrollers"; @@ -78,6 +136,7 @@ stdenv.mkDerivation rec { maintainers = with maintainers; [ pjones sorki + carlossless ]; platforms = platforms.unix; }; diff --git a/pkgs/by-name/bm/bmputil/package.nix b/pkgs/by-name/bm/bmputil/package.nix index 25d13da5692c..4ad081c193d5 100644 --- a/pkgs/by-name/bm/bmputil/package.nix +++ b/pkgs/by-name/bm/bmputil/package.nix @@ -29,7 +29,7 @@ rustPlatform.buildRustPackage rec { ]; postInstall = '' - install -Dm 444 ${blackmagic.src}/driver/99-blackmagic.rules $out/lib/udev/rules.d/99-blackmagic.rules + install -Dm 444 ${blackmagic.src}/driver/99-blackmagic-plugdev.rules $out/lib/udev/rules.d/99-blackmagic-plugdev.rules ''; doCheck = false; # fails at least 1 test