nix: add openocd flashing

softspi
Astro 2019-03-07 18:24:21 +01:00
parent 51ee455fe7
commit 092ea7f824
6 changed files with 69 additions and 26 deletions

View File

@ -4,5 +4,33 @@ in
with import <nixpkgs> { overlays = [ mozillaOverlay ]; };
let
rustPlatform = recurseIntoAttrs (callPackage (import ./nix/rustPlatform.nix) {});
adc2tcp = callPackage (import ./nix/adc2tcp.nix) { inherit rustPlatform; };
openocd = callPackage (import ./nix/openocd.nix) {};
in
callPackage (import ./nix/adc2tcp.nix) { inherit rustPlatform; }
stdenv.mkDerivation {
name = "adc2tcp-dist";
buildInputs = [
adc2tcp
openocd
gdb
];
src = ./.;
dontBuild = true;
installPhase = ''
mkdir -p $out/bin $out/lib
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
'';
}

View File

@ -10,4 +10,8 @@ buildRustPackage rec {
cargoSha256 = "0q3cn3jzgmrqiymisxymn19vbnnpsj7if052w5zh25x9ikin6lpl";
doCheck = false;
installPhase = ''
mkdir -p $out/lib
cp target/thumbv7em-none-eabihf/release/adc2tcp $out/lib/
'';
}

View File

@ -1,16 +0,0 @@
{ stdenv, callPackage }:
let
adc2tcp = callPackage (import ./adc2tcp.nix) {};
in
stdenv.mkDerivation {
name = "adc2tcp";
buildInputs = [
adc2tcp
];
src = ./.;
noBuild = true;
installPhase = ''
find ${adc2tcp} -type f
'';
}

22
nix/openocd.nix Normal file
View File

@ -0,0 +1,22 @@
{ stdenv, openocd }:
stdenv.mkDerivation {
name = "openocd-nucleo-f429zi";
buildInputs = [
openocd
];
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
'';
}

View File

@ -7,7 +7,7 @@ let
# "thumbv7em-none-eabi"
"thumbv7em-none-eabihf"
];
rust = builtins.trace "Selected channel ${rustChannel}"
rust = builtins.trace "rustChannel: selected channel ${rustChannel}"
rustChannelOfTargets rustChannel null targets;
in
makeRustPlatform {

View File

@ -5,15 +5,9 @@ let
in
with import <nixpkgs> { overlays = [ mozillaOverlay ]; };
let
rustPlatform = recurseIntoAttrs (
callPackage (import ./nix/rustPlatform.nix) { inherit rustChannel; }
);
rustPlatform = callPackage (import ./nix/rustPlatform.nix) { inherit rustChannel; };
openocd = callPackage (import ./nix/openocd.nix) {};
in
# mkShell {
# inputsFrom = with rustPlatform.rust; [
# rustc cargo
# ];
# }
stdenv.mkDerivation {
name = "adc2tcp-env";
buildInputs = with rustPlatform.rust; [
@ -22,4 +16,15 @@ stdenv.mkDerivation {
# Set Environment Variables
RUST_BACKTRACE = 1;
shellHook = ''
echo "Starting openocd"
${openocd}/bin/openocd-nucleo-f429zi &
# Let openocd output scroll by
sleep 1
echo "Run 'cargo build --release'"
echo "Then 'gdb target/thumbv7em-none-eabihf/release/adc2tcp'"
'';
}