Skip to content

Commit

Permalink
blackmagic: 1.8.2 -> 1.10.2
Browse files Browse the repository at this point in the history
  • Loading branch information
carlossless committed Oct 29, 2024
1 parent 2997153 commit f7049b6
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 19 deletions.
97 changes: 97 additions & 0 deletions pkgs/by-name/gc/gcc-arm-embedded-12-2-rel1/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
lib,
stdenv,
fetchurl,
ncurses5,
python39,
libxcrypt-legacy,
runtimeShell,
}:

stdenv.mkDerivation rec {
pname = "gcc-arm-embedded";
version = "12.2.rel1";

platform =
{
aarch64-darwin = "darwin-arm64";
aarch64-linux = "aarch64";
x86_64-darwin = "darwin-x86_64";
x86_64-linux = "x86_64";
}
.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}");

src = fetchurl {
url = "https://developer.arm.com/-/media/Files/downloads/gnu/${version}/binrel/arm-gnu-toolchain-${version}-${platform}-arm-none-eabi.tar.xz";
sha256 =
{
aarch64-darwin = "0j12n631bmbfvnfbmv4q7cfhmh4l7ka3vcjcvyw0vjqb4msyia91";
aarch64-linux = "131ydgndff7dyhkivfchbk43lv3cv2p172knkqilx64aapvk5qvy";
x86_64-darwin = "00i9gd1ny00681pwinh6ng9x45xsyrnwc6hm2vr348z9gasyxh00";
x86_64-linux = "0rv8r5zh0a5621v0xygxi8f6932qgwinw2s9vnniasp9z7897gl4";
}
.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
};

dontConfigure = true;
dontBuild = true;
dontPatchELF = true;
dontStrip = true;

installPhase = ''
mkdir -p $out
cp -r * $out
'';

preFixup = ''
find $out -type f | while read f; do
patchelf "$f" > /dev/null 2>&1 || continue
patchelf --set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) "$f" || true
patchelf --set-rpath ${
lib.makeLibraryPath [
"$out"
stdenv.cc.cc
ncurses5
python39
libxcrypt-legacy
]
} "$f" || true
done
'';

postFixup = ''
mv $out/bin/arm-none-eabi-gdb $out/bin/arm-none-eabi-gdb-unwrapped
cat <<EOF > $out/bin/arm-none-eabi-gdb
#!${runtimeShell}
export PYTHONPATH=${python39}/lib/python3.9
export PYTHONHOME=${python39.interpreter}
exec $out/bin/arm-none-eabi-gdb-unwrapped "\$@"
EOF
chmod +x $out/bin/arm-none-eabi-gdb
'';

meta = {
description = "Pre-built GNU toolchain from ARM Cortex-M & Cortex-R processors";
homepage = "https://developer.arm.com/open-source/gnu-toolchain/gnu-rm";
license = with lib.licenses; [
bsd2
gpl2
gpl3
lgpl21
lgpl3
mit
];
maintainers = with lib.maintainers; [
prusnak
prtzl
carlossless
];
platforms = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
};
}
46 changes: 28 additions & 18 deletions pkgs/development/embedded/blackmagic/default.nix
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
{ stdenv, lib
, fetchFromGitHub
, gcc-arm-embedded
, pkg-config
, python3
, hidapi
, libftdi1
, libusb1
{
stdenv,
lib,
fetchFromGitHub,
gnumake,
pkg-config,
python3,
hidapi,
libftdi1,
libusb1,
gcc-arm-embedded-12-2-rel1,
}:

stdenv.mkDerivation rec {
pname = "blackmagic";
version = "1.8.2";
version = "1.10.2";
# `git describe --always`
firmwareVersion = "v${version}";

src = fetchFromGitHub {
owner = "blacksphere";
owner = "blackmagic-debug";
repo = "blackmagic";
rev = firmwareVersion;
hash = "sha256-NGzoohmpVwGOncr9AvHYANMf/oEskjmTXYj/Kdx2RwM=";
rev = "refs/tags/${firmwareVersion}";
hash = "sha256-ZhcVGSES+RPSjS7Pdk1EGWF8MfIW19HmHbvYtzMECME=";
fetchSubmodules = true;
};

nativeBuildInputs = [
gcc-arm-embedded
gnumake
pkg-config
python3
# only this or previous versions of gcc-arm-embedded builds 1.10.2 in a way that fits into rom for the native platform
# https://github.com/blackmagic-debug/blackmagic/issues/1978
gcc-arm-embedded-12-2-rel1
];

buildInputs = [
Expand All @@ -39,7 +45,7 @@ stdenv.mkDerivation rec {
postPatch = ''
# Prevent calling out to `git' to generate a version number:
substituteInPlace src/Makefile \
--replace '$(shell git describe --always --dirty)' '${firmwareVersion}'
--replace-fail '$(shell if [ -e "../.git" ]; then git describe --always --dirty --tags; fi)' '${firmwareVersion}'
# Fix scripts that generate headers:
for f in $(find scripts libopencm3/scripts -type f); do
Expand All @@ -57,7 +63,7 @@ stdenv.mkDerivation rec {

enableParallelBuilding = true;

meta = with lib; {
meta = {
description = "In-application debugger for ARM Cortex microcontrollers";
mainProgram = "blackmagic";
longDescription = ''
Expand All @@ -72,8 +78,12 @@ stdenv.mkDerivation rec {
executable in the bin directory.
'';
homepage = "https://github.com/blacksphere/blackmagic";
license = licenses.gpl3Plus;
maintainers = with maintainers; [ pjones sorki ];
platforms = platforms.unix;
license = lib.licenses.gpl3Plus;
maintainers = with lib.maintainers; [
pjones
sorki
carlossless
];
platforms = lib.platforms.unix;
};
}
5 changes: 4 additions & 1 deletion pkgs/development/embedded/blackmagic/helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ PRODUCTS="blackmagic.bin blackmagic.hex blackmagic_dfu.bin blackmagic_dfu.hex"

################################################################################
make_platform() {
if [ "$1" = "common" ]; then
return;
fi

echo "Building for hardware platform $1"

make clean
Expand All @@ -32,7 +36,6 @@ make_platform() {
install -m 0444 "$f" "$out/firmware/$1"
fi
done

}

################################################################################
Expand Down

0 comments on commit f7049b6

Please sign in to comment.