Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 stdenv, 3 lib, 4 fetchFromGitHub, 5 gcc-arm-embedded-13, 6 pkg-config, 7 meson, 8 ninja, 9 hidapi, 10 libftdi1, 11 libusb1, 12 libgpiod_1, 13 versionCheckHook, 14 udevCheckHook, 15}: 16let 17 libopencm3Src = fetchFromGitHub { 18 owner = "libopencm3"; 19 repo = "libopencm3"; 20 rev = "8a96a9d95a8e5c187a53652540b25a8f4d73a432"; 21 hash = "sha256-PylP95hpPeg3rqfelHW9qz+pi/qOP60RfvkurxbkWDs="; 22 }; 23 24 ctxlinkWinc1500Src = fetchFromGitHub { 25 owner = "sidprice"; 26 repo = "ctxlink_winc1500"; 27 rev = "debeab9516e33622439f727a68bddabcdf52c528"; 28 hash = "sha256-IWLIJu2XuwsnP8/2C9uj09EBU2VtwTke3XXbc3NyZt4="; 29 }; 30in 31stdenv.mkDerivation rec { 32 pname = "blackmagic"; 33 version = "2.0.0"; 34 # `git describe --always` 35 firmwareVersion = "v${version}"; 36 37 src = fetchFromGitHub { 38 owner = "blackmagic-debug"; 39 repo = "blackmagic"; 40 rev = firmwareVersion; 41 hash = "sha256-JbPeN0seSkxV2uZ8BvsvjDUBMOyJu2BxqMgNkhLOiFI="; 42 }; 43 44 nativeBuildInputs = [ 45 gcc-arm-embedded-13 # fails to build with 14 46 pkg-config 47 meson 48 ninja 49 udevCheckHook 50 ]; 51 52 buildInputs = [ 53 hidapi 54 libftdi1 55 libusb1 56 ] 57 ++ lib.optional stdenv.hostPlatform.isLinux libgpiod_1; 58 59 strictDeps = true; 60 61 postUnpack = '' 62 mkdir -p $sourceRoot/deps/libopencm3 63 cp -r ${libopencm3Src}/* $sourceRoot/deps/libopencm3/ 64 65 mkdir -p $sourceRoot/deps/winc1500 66 cp -r ${ctxlinkWinc1500Src}/* $sourceRoot/deps/winc1500/ 67 ''; 68 69 buildPhase = '' 70 runHook preBuild 71 72 echo "Building host cli" 73 meson compile -C . 74 75 echo "Building probe firmware" 76 pushd .. 77 for cf in cross-file/*.ini; do 78 target=$(basename "''${cf%.ini}") 79 80 if [ "$target" = "arm-none-eabi" ]; then 81 echo "Skipping arm-none-eabi target" 82 continue 83 fi 84 85 echo "Building target: $target" 86 mkdir -p "build/firmware/$target" 87 meson setup "build/firmware/$target" --cross-file "$cf" 88 meson compile -C "build/firmware/$target" 89 done 90 popd 91 92 runHook postBuild 93 ''; 94 95 installPhase = '' 96 runHook preInstall 97 98 echo "Installing host cli" 99 install -Dm555 blackmagic $out/bin/blackmagic 100 101 echo "Installing probe firmware" 102 for targetDir in firmware/*; do 103 target=$(basename "$targetDir") 104 echo "Installing firmware for target: $target" 105 for f in $targetDir/*.{bin,elf}; do 106 install -Dm444 $f $out/firmware/$target/$(basename "$f") 107 done 108 done 109 110 echo "Installing udev rules" 111 install -Dm444 ../driver/99-blackmagic-plugdev.rules $out/lib/udev/rules.d/99-blackmagic-plugdev.rules 112 113 runHook postInstall 114 ''; 115 116 nativeInstallCheckInputs = [ versionCheckHook ]; 117 versionCheckProgramArg = "--help"; 118 doInstallCheck = true; 119 120 meta = with lib; { 121 description = "In-application debugger for ARM Cortex microcontrollers"; 122 mainProgram = "blackmagic"; 123 longDescription = '' 124 The Black Magic Probe is a modern, in-application debugging tool 125 for embedded microprocessors. It allows you to see what is going 126 on "inside" an application running on an embedded microprocessor 127 while it executes. 128 129 This package builds the firmware for all supported platforms, 130 placing them in separate directories under the firmware 131 directory. It also places the FTDI version of the blackmagic 132 executable in the bin directory. 133 ''; 134 homepage = "https://github.com/blacksphere/blackmagic"; 135 license = licenses.gpl3Plus; 136 maintainers = with maintainers; [ 137 pjones 138 sorki 139 carlossless 140 ]; 141 platforms = platforms.unix; 142 }; 143}