diff --git a/Cargo.lock b/Cargo.lock index 91cbb91..550f8f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -429,6 +429,20 @@ dependencies = [ "regex", ] +[[package]] +name = "rkbfirm" +version = "0.1.0" +dependencies = [ + "cortex-m", + "cortex-m-rt", + "defmt", + "defmt-rtt", + "embedded-hal", + "embedded-time", + "panic-probe", + "rp-pico", +] + [[package]] name = "rp-pico" version = "0.4.1" @@ -500,20 +514,6 @@ dependencies = [ "vcell", ] -[[package]] -name = "rust-template" -version = "0.1.0" -dependencies = [ - "cortex-m", - "cortex-m-rt", - "defmt", - "defmt-rtt", - "embedded-hal", - "embedded-time", - "panic-probe", - "rp-pico", -] - [[package]] name = "rustc_version" version = "0.2.3" diff --git a/Cargo.nix b/Cargo.nix index 0b5a936..68586ef 100644 --- a/Cargo.nix +++ b/Cargo.nix @@ -4,7 +4,7 @@ args@{ release ? true, rootFeatures ? [ - "rust-template/default" + "rkbfirm/default" ], rustPackages, buildRustPackages, @@ -41,7 +41,7 @@ in { cargo2nixVersion = "0.11.0"; workspace = { - rust-template = rustPackages.unknown.rust-template."0.1.0"; + rkbfirm = rustPackages.unknown.rkbfirm."0.1.0"; }; "registry+https://github.com/rust-lang/crates.io-index".aho-corasick."0.7.18" = overridableMkRustCrate (profileName: rec { name = "aho-corasick"; @@ -622,6 +622,23 @@ in }; }); + "unknown".rkbfirm."0.1.0" = overridableMkRustCrate (profileName: rec { + name = "rkbfirm"; + version = "0.1.0"; + registry = "unknown"; + src = fetchCrateLocal workspaceSrc; + dependencies = { + cortex_m = rustPackages."registry+https://github.com/rust-lang/crates.io-index".cortex-m."0.7.5" { inherit profileName; }; + cortex_m_rt = rustPackages."registry+https://github.com/rust-lang/crates.io-index".cortex-m-rt."0.7.1" { inherit profileName; }; + defmt = rustPackages."registry+https://github.com/rust-lang/crates.io-index".defmt."0.3.2" { inherit profileName; }; + defmt_rtt = rustPackages."registry+https://github.com/rust-lang/crates.io-index".defmt-rtt."0.3.2" { inherit profileName; }; + embedded_hal = rustPackages."registry+https://github.com/rust-lang/crates.io-index".embedded-hal."0.2.7" { inherit profileName; }; + embedded_time = rustPackages."registry+https://github.com/rust-lang/crates.io-index".embedded-time."0.12.1" { inherit profileName; }; + panic_probe = rustPackages."registry+https://github.com/rust-lang/crates.io-index".panic-probe."0.3.0" { inherit profileName; }; + rp_pico = rustPackages."registry+https://github.com/rust-lang/crates.io-index".rp-pico."0.4.1" { inherit profileName; }; + }; + }); + "registry+https://github.com/rust-lang/crates.io-index".rp-pico."0.4.1" = overridableMkRustCrate (profileName: rec { name = "rp-pico"; version = "0.4.1"; @@ -712,23 +729,6 @@ in }; }); - "unknown".rust-template."0.1.0" = overridableMkRustCrate (profileName: rec { - name = "rust-template"; - version = "0.1.0"; - registry = "unknown"; - src = fetchCrateLocal workspaceSrc; - dependencies = { - cortex_m = rustPackages."registry+https://github.com/rust-lang/crates.io-index".cortex-m."0.7.5" { inherit profileName; }; - cortex_m_rt = rustPackages."registry+https://github.com/rust-lang/crates.io-index".cortex-m-rt."0.7.1" { inherit profileName; }; - defmt = rustPackages."registry+https://github.com/rust-lang/crates.io-index".defmt."0.3.2" { inherit profileName; }; - defmt_rtt = rustPackages."registry+https://github.com/rust-lang/crates.io-index".defmt-rtt."0.3.2" { inherit profileName; }; - embedded_hal = rustPackages."registry+https://github.com/rust-lang/crates.io-index".embedded-hal."0.2.7" { inherit profileName; }; - embedded_time = rustPackages."registry+https://github.com/rust-lang/crates.io-index".embedded-time."0.12.1" { inherit profileName; }; - panic_probe = rustPackages."registry+https://github.com/rust-lang/crates.io-index".panic-probe."0.3.0" { inherit profileName; }; - rp_pico = rustPackages."registry+https://github.com/rust-lang/crates.io-index".rp-pico."0.4.1" { inherit profileName; }; - }; - }); - "registry+https://github.com/rust-lang/crates.io-index".rustc_version."0.2.3" = overridableMkRustCrate (profileName: rec { name = "rustc_version"; version = "0.2.3"; diff --git a/Cargo.toml b/Cargo.toml index cdb9336..f531d72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "rust-template" +name = "rkbfirm" version = "0.1.0" edition = "2021" diff --git a/elf2uf2.patch b/elf2uf2.patch new file mode 100644 index 0000000..42c3285 --- /dev/null +++ b/elf2uf2.patch @@ -0,0 +1,13 @@ +diff --git a/src/main.rs b/src/main.rs +index 7d55e7b..72bfdeb 100644 +--- a/src/main.rs ++++ b/src/main.rs +@@ -176,7 +176,7 @@ fn elf2uf2(mut input: impl Read + Seek, mut output: impl Write) -> Result<(), Bo + fn main() -> Result<(), Box> { + OPTS.set(Opts::parse()).unwrap(); + +- let serial_ports_before = serialport::available_ports()?; ++ let serial_ports_before = Vec::new(); + let mut deployed_path = None; + + { diff --git a/flake.nix b/flake.nix index 1579b41..319be6c 100644 --- a/flake.nix +++ b/flake.nix @@ -43,9 +43,11 @@ targets = ["thumbv6m-none-eabi"]; }) cargo2nix.packages.${system}.cargo2nix + elf2uf2-rs + cargo-embed ]; }; - packages = { + packages = rec { rkbfirm-source = pkgs.releaseTools.sourceTarball { name = "rkbfirm-source"; src = self; @@ -60,8 +62,34 @@ (cd .. && tar -cf- $releaseName | zstd --ultra -22 > $out/tarballs/$releaseName.tar.zst) || false ''; }; - rust-template = rustPkgs.workspace.rust-template { }; - + rkbfirm-crate = (rustPkgs.workspace.rkbfirm { }).overrideAttrs(old: { + configureCargo = "true"; + }); + rkbfirm = pkgs.stdenvNoCC.mkDerivation { + pname = "rkbfirm"; + src = self; + version = self.lastModifiedDate; + nativeBuildInputs = with pkgs; [ + (elf2uf2-rs.overrideAttrs (old: { + patches = [ + ./elf2uf2.patch + ]; + })) + zstd + ]; + buildInputs = [rkbfirm-crate]; + buildPhase = '' + elf2uf2-rs ${rkbfirm-crate}/bin/rkbfirm rkbfirm.uf2 --verbose + ''; + installPhase = '' + mkdir $out + zstd --ultra -22 < rkbfirm.uf2 > $out/rkbfirm.uf2.zst + mkdir $out/nix-support + echo "file binary-dist $out/rkbfirm.uf2.zst" > $out/nix-support/hydra-build-products + echo "$pname-$version" > $out/nix-support/hydra-release-name + ''; + }; + default = rkbfirm; }; nixosModules.default = import ./nixos { inherit inputs system;