diff --git a/.bestool.nix b/.bestool.nix new file mode 100644 index 0000000..593bc85 --- /dev/null +++ b/.bestool.nix @@ -0,0 +1,26 @@ +{ lib +, pkgs +, rustPlatform +, +}: +rustPlatform.buildRustPackage { + name = "bestool"; + + src = ./bestool; + + cargoLock = { + lockFile = ./bestool/Cargo.lock; + allowBuiltinFetchGit = true; + }; + + nativeBuildInputs = with pkgs; [ pkg-config ]; + buildInputs = with pkgs; [ systemd.dev ]; + + meta = with lib; { + description = ""; + homepage = "https://github.com/Ralim/bestool"; + platforms = platforms.linux; + maintainers = with maintainers; [ shymega ]; + license = licenses.mit; + }; +} diff --git a/bestool/res/chunk1.bin b/bestool/res/chunk1.bin new file mode 100644 index 0000000..13535bc Binary files /dev/null and b/bestool/res/chunk1.bin differ diff --git a/bestool/res/chunk2.bin b/bestool/res/chunk2.bin new file mode 100644 index 0000000..0e9a20d Binary files /dev/null and b/bestool/res/chunk2.bin differ diff --git a/bestool/res/programmer.bin b/bestool/res/programmer.bin new file mode 100644 index 0000000..34eaf62 Binary files /dev/null and b/bestool/res/programmer.bin differ diff --git a/bestool/src/beslink/bootloader.rs b/bestool/src/beslink/bootloader.rs index 1196d35..6013eae 100644 --- a/bestool/src/beslink/bootloader.rs +++ b/bestool/src/beslink/bootloader.rs @@ -4,7 +4,7 @@ use std::io::Write; use tracing::error; use tracing::info; //Embed the bin file for future -const PROGRAMMER_BINARY: &[u8; 75928] = include_bytes!("../../../programmer.bin"); +const PROGRAMMER_BINARY: &[u8; 75928] = include_bytes!("../../res/programmer.bin"); pub fn load_programmer_runtime_binary_blob( serial_port: &mut Box, diff --git a/bestool/src/beslink/write_flash.rs b/bestool/src/beslink/write_flash.rs index 575bf9e..21a0b83 100644 --- a/bestool/src/beslink/write_flash.rs +++ b/bestool/src/beslink/write_flash.rs @@ -196,8 +196,8 @@ mod tests { use crate::beslink::write_flash::get_flash_chunk_msg; //Embed the bin file for future - const CHUNK1_TEST: &[u8; 32768] = include_bytes!("../../../chunk1.bin"); - const CHUNK2_TEST: &[u8; 32768] = include_bytes!("../../../chunk2.bin"); + const CHUNK1_TEST: &[u8; 32768] = include_bytes!("../../res/chunk1.bin"); + const CHUNK2_TEST: &[u8; 32768] = include_bytes!("../../res/chunk2.bin"); #[test] fn test_get_flash_chunk_msg() { diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..7aef5d9 --- /dev/null +++ b/flake.lock @@ -0,0 +1,78 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1733328505, + "narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1740019556, + "narHash": "sha256-vn285HxnnlHLWnv59Og7muqECNMS33mWLM14soFIv2g=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "dad564433178067be1fbdfcce23b546254b6d641", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..c6e2401 --- /dev/null +++ b/flake.nix @@ -0,0 +1,42 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + }; + outputs = + { self + , nixpkgs + , flake-utils + , ... + }: + flake-utils.lib.eachDefaultSystem + (system: + let + pkgs = import nixpkgs { + inherit system; + }; + in + with pkgs; { + packages.bestool = callPackage ./.bestool.nix { }; + packages.default = self.packages.${system}.bestool; + + devShells.default = mkShell { + inputsFrom = lib.singleton self.packages.${system}.default; + buildInputs = [ + cargo-edit + clippy + rustfmt + ]; + RUST_SRC_PATH = rustPlatform.rustLibSrc; + }; + }) + // { + overlays.default = final: prev: { + inherit (self.packages.${final.system}) bestool; + }; + }; +}