default.nix, nix/openocd: replace shell script with makeWrapper

This commit is contained in:
Astro 2019-04-05 23:04:45 +02:00
parent 462c5e2668
commit cbfe3a177b
2 changed files with 35 additions and 29 deletions

View File

@ -19,26 +19,30 @@ stdenv.mkDerivation {
buildInputs = [
adc2tcp
openocd
makeWrapper
];
src = ./.;
dontBuild = true;
installPhase = ''
mkdir -p $out/bin $out/lib $out/nix-support
installPhase =
let
firmwareBinary = "$out/lib/adc2tcp.elf";
openOcdFlags = [
"-c" "reset halt"
"-c" "flash write_image erase ${firmwareBinary}"
"-c" "verify_image ${firmwareBinary}"
"-c" "reset run"
"-c" "shutdown"
];
in ''
mkdir -p $out/bin $out/lib $out/nix-support
BIN=$out/lib/adc2tcp
ln -s ${adc2tcp}/lib/adc2tcp $BIN
cat >> $out/bin/flash-adc2tcp <<EOF
#!/usr/bin/env bash
${openocd}/bin/openocd-nucleo-f429zi \
-c "reset halt" \
-c "flash write_image erase $BIN" \
-c "verify_image $BIN" \
-c "reset run" \
-c "shutdown"
EOF
chmod +x $out/bin/flash-adc2tcp
BIN=$out/lib/adc2tcp
ln -s ${adc2tcp}/lib/adc2tcp $BIN
echo file binary-dist $BIN >> $out/nix-support/hydra-build-products
'';
makeWrapper ${openocd}/bin/openocd-nucleo-f429zi $out/bin/flash-adc2tcp \
--add-flags "${lib.escapeShellArgs openOcdFlags}"
echo file binary-dist ${firmwareBinary} >> $out/nix-support/hydra-build-products
'';
}

View File

@ -1,22 +1,24 @@
{ stdenv, openocd }:
{ stdenv, lib, openocd, makeWrapper }:
stdenv.mkDerivation {
name = "openocd-nucleo-f429zi";
buildInputs = [
openocd
makeWrapper
];
src = ./.;
noBuild = true;
installPhase = ''
mkdir -p $out/bin
cat >> $out/bin/openocd-nucleo-f429zi <<EOF
#!/usr/bin/env bash
${openocd}/bin/openocd \
-f ${openocd}/share/openocd/scripts/interface/stlink-v2-1.cfg \
-f ${openocd}/share/openocd/scripts/target/stm32f4x.cfg \
-c "init" \
"\$@"
EOF
chmod +x $out/bin/openocd-nucleo-f429zi
'';
installPhase =
let
openOcdFlags = [
"-f" "${openocd}/share/openocd/scripts/interface/stlink-v2-1.cfg"
"-f" "${openocd}/share/openocd/scripts/target/stm32f4x.cfg"
"-c" "init"
];
in ''
mkdir -p $out/bin
makeWrapper ${openocd}/bin/openocd $out/bin/openocd-nucleo-f429zi \
--add-flags "${lib.escapeShellArgs openOcdFlags}"
'';
}