mcu: temporarily roll back Stabilizer to pre-MQTT, & generate all variants #59

Merged
sb10q merged 5 commits from harry/nix-scripts:fix-mcu into master 2021-07-02 16:30:02 +08:00
2 changed files with 39 additions and 17 deletions

View File

@ -14,7 +14,7 @@
"nixpkgs": { "type": "git", "value": "git://github.com/NixOS/nixpkgs nixos-21.05", "emailresponsible": false }, "nixpkgs": { "type": "git", "value": "git://github.com/NixOS/nixpkgs nixos-21.05", "emailresponsible": false },
"mozillaOverlay": { "type": "git", "value": "git://github.com/mozilla/nixpkgs-mozilla.git", "emailresponsible": false }, "mozillaOverlay": { "type": "git", "value": "git://github.com/mozilla/nixpkgs-mozilla.git", "emailresponsible": false },
"nixScripts": { "type": "git", "value": "https://git.m-labs.hk/M-Labs/nix-scripts.git", "emailresponsible": false }, "nixScripts": { "type": "git", "value": "https://git.m-labs.hk/M-Labs/nix-scripts.git", "emailresponsible": false },
"stabilizerSrc": { "type": "git", "value": "git://github.com/quartiq/stabilizer.git", "emailresponsible": false }, "stabilizerSrc": { "type": "git", "value": "git://github.com/HarryMakes/stabilizer.git pre-mqtt 1", "emailresponsible": false },
"thermostatSrc": { "type": "git", "value": "https://git.m-labs.hk/M-Labs/thermostat.git", "emailresponsible": false }, "thermostatSrc": { "type": "git", "value": "https://git.m-labs.hk/M-Labs/thermostat.git", "emailresponsible": false },
"humpbackDdsSrc": { "type": "git", "value": "https://git.m-labs.hk/M-Labs/humpback-dds.git", "emailresponsible": false }, "humpbackDdsSrc": { "type": "git", "value": "https://git.m-labs.hk/M-Labs/humpback-dds.git", "emailresponsible": false },
"saymaMmcSrc": { "type": "git", "value": "git://github.com/sinara-hw/openMMC sayma-devel", "emailresponsible": false } "saymaMmcSrc": { "type": "git", "value": "git://github.com/sinara-hw/openMMC sayma-devel", "emailresponsible": false }

View File

@ -8,23 +8,24 @@ let
rustPlatform = pkgs.recurseIntoAttrs (pkgs.callPackage ./rustPlatform.nix { rustPlatform = pkgs.recurseIntoAttrs (pkgs.callPackage ./rustPlatform.nix {
inherit rustManifest; inherit rustManifest;
}); });
buildStm32Firmware = { name, src, patchPhase ? "", extraNativeBuildInputs ? [], checkPhase ? "", ... } @ args: buildStm32Firmware = { name, src, cargoDepsName ? name, patchPhase ? "", extraNativeBuildInputs ? [], checkPhase ? "", doCheck ? true, ... } @ args:
let let
# If binaryName is specified as an arg of buildStm32Firmware,
# then the .nix containing the cargoSha256 must be named "cargosha256-${binaryName}.nix";
# otherwise, the .nix must be named "cargosha256.nix".
cargoSha256Drv = pkgs.runCommand "${name}-cargosha256" { } '' cargoSha256Drv = pkgs.runCommand "${name}-cargosha256" { } ''
cp "${src}/cargosha256${ cp "${src}/cargosha256.nix" $out
if (args ? binaryName) then "-" + args.binaryName else ""
}.nix" $out
''; '';
# If binaryName is specified as an arg of buildStm32Firmware, # If binaryName is specified,
# then pass it as an argument for `cargo build`; otherwise, do not add such argument.
extraCargoBuildArgs = (
(if (args ? extraCargoBuildArgs) then (args.extraCargoBuildArgs + " ") else "") +
(if (args ? binaryName) then ("--bin " + binaryName) else "")
);
# If binaryName is specified,
# then use it as the filename of the ELF generated from `cargo build`; # then use it as the filename of the ELF generated from `cargo build`;
# otherwise, use the `name` arg (i.e. the Rust package name) as the ELF filename. # otherwise, use the `name` arg (i.e. the Rust package name) as the ELF filename.
binaryName = if (args ? binaryName) then args.binaryName else name; binaryName = if (args ? binaryName) then args.binaryName else name;
in in
rustPlatform.buildRustPackage rec { rustPlatform.buildRustPackage rec {
inherit name; inherit name cargoDepsName;
version = "0.0.0"; version = "0.0.0";
inherit src; inherit src;
@ -34,10 +35,10 @@ let
nativeBuildInputs = [ pkgs.llvm ] ++ extraNativeBuildInputs; nativeBuildInputs = [ pkgs.llvm ] ++ extraNativeBuildInputs;
buildPhase = '' buildPhase = ''
export CARGO_HOME=$(mktemp -d cargo-home.XXX) export CARGO_HOME=$(mktemp -d cargo-home.XXX)
cargo build --release cargo build --release ${extraCargoBuildArgs}
''; '';
inherit checkPhase; inherit checkPhase doCheck;
installPhase = '' installPhase = ''
mkdir -p $out $out/nix-support mkdir -p $out $out/nix-support
cp target/thumbv7em-none-eabihf/release/${binaryName} $out/${name}.elf cp target/thumbv7em-none-eabihf/release/${binaryName} $out/${name}.elf
@ -50,10 +51,13 @@ let
}; };
migen = (import ../artiq-fast/pkgs/python-deps.nix { inherit (pkgs) lib fetchgit fetchFromGitHub python3Packages; misoc-new = true; }).migen; migen = (import ../artiq-fast/pkgs/python-deps.nix { inherit (pkgs) lib fetchgit fetchFromGitHub python3Packages; misoc-new = true; }).migen;
in in
{ pkgs.lib.attrsets.mapAttrs'
stabilizer-dual-iir = buildStm32Firmware { (name: value: pkgs.lib.attrsets.nameValuePair ("stabilizer-" + name)
name = "stabilizer-dual-iir"; (buildStm32Firmware {
binaryName = "dual-iir"; name = "stabilizer-" + name;
# If binaryName is not specified, use the attribute name as binaryName by default.
binaryName = if (value ? binaryName) then value.binaryName else name;
cargoDepsName = "stabilizer";
src = <stabilizerSrc>; src = <stabilizerSrc>;
patchPhase = '' patchPhase = ''
substituteInPlace src/hardware/configuration.rs \ substituteInPlace src/hardware/configuration.rs \
@ -62,7 +66,25 @@ in
--replace "Ipv4Address::new(10, 34, 16, 1)" \ --replace "Ipv4Address::new(10, 34, 16, 1)" \
"Ipv4Address::new(192, 168, 1, 1)" "Ipv4Address::new(192, 168, 1, 1)"
''; '';
}; doCheck = false;
})) {
dual-iir = {};
dual-iir-pounder_v1_1 = {
binaryName = "dual-iir";
extraCargoBuildArgs = "--features pounder_v1_1";
};
lockin-external = {};
lockin-external-pounder_v1_1 = {
binaryName = "lockin-external";
extraCargoBuildArgs = "--features pounder_v1_1";
};
lockin-internal = {};
lockin-internal-pounder_v1_1 = {
binaryName = "lockin-internal";
extraCargoBuildArgs = "--features pounder_v1_1";
};
} //
{
thermostat = buildStm32Firmware { thermostat = buildStm32Firmware {
name = "thermostat"; name = "thermostat";
src = <thermostatSrc>; src = <thermostatSrc>;