From 683e7ea92e3126494af571587fe651f267ceb6ab Mon Sep 17 00:00:00 2001 From: Richard Goulter Date: Wed, 20 Dec 2023 22:59:38 +0700 Subject: [PATCH] check in nix --- flake.lock | 61 ++++++++++++++++++++++ flake.nix | 26 ++++++++++ nix/libmcuupdate.nix | 40 ++++++++++++++ nix/mrs-toolchain.nix | 37 +++++++++++++ nix/wchisp.nix | 13 +++++ nix/xpack-riscv-none-elf-gcc.nix | 37 +++++++++++++ nix/xpack-riscv-none-embed-gcc-8.2.nix | 41 +++++++++++++++ nix/xpack-riscv-none-embed-gcc.nix | 38 ++++++++++++++ shell.nix | 72 ++++++++++++++++++++++++++ 9 files changed, 365 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/libmcuupdate.nix create mode 100644 nix/mrs-toolchain.nix create mode 100644 nix/wchisp.nix create mode 100644 nix/xpack-riscv-none-elf-gcc.nix create mode 100644 nix/xpack-riscv-none-embed-gcc-8.2.nix create mode 100644 nix/xpack-riscv-none-embed-gcc.nix create mode 100644 shell.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..37dda7d --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1701680307, + "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1703105089, + "narHash": "sha256-1F7hDLj58OQCADRtG2DRKpmJ8QVza0M0NK/kfLWLs3k=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2b9c57d33e3d5be6262e124fc66e3a8bc650b93d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "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..e285037 --- /dev/null +++ b/flake.nix @@ -0,0 +1,26 @@ +{ + description = "The CH592 HID_Keyboard EVT Example"; + + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + }; + + outputs = { + self, + nixpkgs, + flake-utils, + }: + flake-utils.lib.eachSystem [ + flake-utils.lib.system.x86_64-linux + ] (system: let + pkgs = nixpkgs.legacyPackages.${system}; + in { + devShells = { + default = import ./shell.nix { + inherit pkgs; + }; + }; + }); +} diff --git a/nix/libmcuupdate.nix b/nix/libmcuupdate.nix new file mode 100644 index 0000000..d99ee2d --- /dev/null +++ b/nix/libmcuupdate.nix @@ -0,0 +1,40 @@ +{ lib +, stdenv +, fetchurl +, hidapi +, libusb1 +, runtimeShell +, mrs_toolchain_version ? "1.90" +, mrs_toolchain_hash ? "sha256-PO7uddJg0L2Ugv7CYLpIyRKAiE+8oXU0nG3NAdYse6g=" +}: + +stdenv.mkDerivation rec { + pname = "libmcuupdate"; + version = mrs_toolchain_version; + + src = fetchurl { + url = "http://file.mounriver.com/tools/MRS_Toolchain_Linux_x64_V${mrs_toolchain_version}.tar.xz"; + hash = mrs_toolchain_hash; + }; + + dontConfigure = true; + dontBuild = true; + dontPatchELF = true; + dontStrip = true; + + installPhase = '' + mkdir -p $out/lib + cp -r beforeinstall/libmcuupdate.so $out/lib/ + ''; + + preFixup = '' + find $out -type f | while read f; do + patchelf "$f" > /dev/null 2>&1 || continue + patchelf --set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) "$f" || true + patchelf --set-rpath ${lib.makeLibraryPath [ "$out" stdenv.cc.cc hidapi libusb1 ]} "$f" || true + done + ''; + + meta = { + }; +} diff --git a/nix/mrs-toolchain.nix b/nix/mrs-toolchain.nix new file mode 100644 index 0000000..4d86e61 --- /dev/null +++ b/nix/mrs-toolchain.nix @@ -0,0 +1,37 @@ +{ lib +, stdenv +, fetchurl +, runtimeShell +, mrs_toolchain_version ? "1.90" +, mrs_toolchain_hash ? "sha256-PO7uddJg0L2Ugv7CYLpIyRKAiE+8oXU0nG3NAdYse6g=" +}: + +stdenv.mkDerivation rec { + pname = "gcc-risc-v-embedded"; + version = mrs_toolchain_version; + + src = fetchurl { + url = "http://file.mounriver.com/tools/MRS_Toolchain_Linux_x64_V${mrs_toolchain_version}.tar.xz"; + hash = mrs_toolchain_hash; + }; + + dontConfigure = true; + dontBuild = true; + dontPatchELF = true; + dontStrip = true; + + installPhase = '' + mkdir -p $out/ + cp -r RISC-V_Embedded_GCC/. $out + ''; + + preFixup = '' + find $out -type f | while read f; do + patchelf "$f" > /dev/null 2>&1 || continue + patchelf --set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) "$f" || true + done + ''; + + meta = { + }; +} diff --git a/nix/wchisp.nix b/nix/wchisp.nix new file mode 100644 index 0000000..f871144 --- /dev/null +++ b/nix/wchisp.nix @@ -0,0 +1,13 @@ +{ lib, fetchFromGitHub, rustPlatform }: + +rustPlatform.buildRustPackage rec { + pname = "wchisp"; + version = "0.3-git"; + src = fetchFromGitHub { + owner = "ch32-rs"; + repo = pname; + rev = "4b4787243ef9bc87cbbb0d95c7482b4f7c9838f1"; + hash = "sha256-Ju2DBv3R4O48o8Fk/AFXOBIsvGMK9hJ8Ogxk47f7gcU="; + }; + cargoHash = "sha256-MbCLQBk7aJXcUOalsNbSxozvI2Tx3kerLXgi4l7BKoc="; +} diff --git a/nix/xpack-riscv-none-elf-gcc.nix b/nix/xpack-riscv-none-elf-gcc.nix new file mode 100644 index 0000000..2e782f9 --- /dev/null +++ b/nix/xpack-riscv-none-elf-gcc.nix @@ -0,0 +1,37 @@ +{ lib +, stdenv +, fetchurl +, runtimeShell +, xpack_toolchain_version ? "13.2.0-1" +, xpack_toolchain_hash ? "sha256-1+/1xdd4hzw9SG5dLIBbglgucwgfk+2zdaHvXYR2S0M=" +}: + +stdenv.mkDerivation rec { + pname = "gcc-risc-v-elf"; + version = xpack_toolchain_version; + + src = fetchurl { + url = "https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v${version}/xpack-riscv-none-elf-gcc-${version}-linux-x64.tar.gz"; + hash = xpack_toolchain_hash; + }; + + dontConfigure = true; + dontBuild = true; + dontPatchELF = true; + dontStrip = true; + + installPhase = '' + mkdir -p $out/ + cp -r * $out + ''; + + preFixup = '' + find $out -type f | while read f; do + patchelf "$f" > /dev/null 2>&1 || continue + patchelf --set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) "$f" || true + done + ''; + + meta = { + }; +} diff --git a/nix/xpack-riscv-none-embed-gcc-8.2.nix b/nix/xpack-riscv-none-embed-gcc-8.2.nix new file mode 100644 index 0000000..f15413c --- /dev/null +++ b/nix/xpack-riscv-none-embed-gcc-8.2.nix @@ -0,0 +1,41 @@ +{ lib +, stdenv +, fetchurl +, runtimeShell +# , xpack_toolchain_version ? "8.3.0-2.3" +# , xpack_toolchain_hash ? "sha256-cI0Mtf8S61rQcBU1lMT3dxzYbUtnIad7I/j+aVyPlAI=" +# , ext ? "tar.gz" + , xpack_toolchain_version ? "8.2.0-3.1" +, xpack_toolchain_hash ? "sha256-PUD6tQ662EJP+FdI8l0uruUPhqXVIiq9ekWi5JDx5PU=" +, ext ? "tgz" +}: + +stdenv.mkDerivation rec { + pname = "gcc-risc-v-elf"; + version = xpack_toolchain_version; + + src = fetchurl { + url = "https://github.com/xpack-dev-tools/riscv-none-embed-gcc-xpack/releases/download/v${version}/xpack-riscv-none-embed-gcc-${version}-linux-x64.${ext}"; + hash = xpack_toolchain_hash; + }; + + dontConfigure = true; + dontBuild = true; + dontPatchELF = true; + dontStrip = true; + + installPhase = '' + mkdir -p $out/ + cp -r riscv-none-embed-gcc/8.2.0-3.1/* $out + ''; + + preFixup = '' + find $out -type f | while read f; do + patchelf "$f" > /dev/null 2>&1 || continue + patchelf --set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) "$f" || true + done + ''; + + meta = { + }; +} diff --git a/nix/xpack-riscv-none-embed-gcc.nix b/nix/xpack-riscv-none-embed-gcc.nix new file mode 100644 index 0000000..3bf31dc --- /dev/null +++ b/nix/xpack-riscv-none-embed-gcc.nix @@ -0,0 +1,38 @@ +{ lib +, stdenv +, fetchurl +, runtimeShell +, xpack_toolchain_version ? "8.3.0-2.3" +, xpack_toolchain_hash ? "sha256-cI0Mtf8S61rQcBU1lMT3dxzYbUtnIad7I/j+aVyPlAI=" +, ext ? "tar.gz" +}: + +stdenv.mkDerivation rec { + pname = "gcc-risc-v-elf"; + version = xpack_toolchain_version; + + src = fetchurl { + url = "https://github.com/xpack-dev-tools/riscv-none-embed-gcc-xpack/releases/download/v${version}/xpack-riscv-none-embed-gcc-${version}-linux-x64.${ext}"; + hash = xpack_toolchain_hash; + }; + + dontConfigure = true; + dontBuild = true; + dontPatchELF = true; + dontStrip = true; + + installPhase = '' + mkdir -p $out/ + cp -r * $out + ''; + + preFixup = '' + find $out -type f | while read f; do + patchelf "$f" > /dev/null 2>&1 || continue + patchelf --set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) "$f" || true + done + ''; + + meta = { + }; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..e24a5b4 --- /dev/null +++ b/shell.nix @@ -0,0 +1,72 @@ +{ pkgs ? import {} +, mrs_toolchain_version ? "1.90" +, mrs_toolchain_hash ? "sha256-PO7uddJg0L2Ugv7CYLpIyRKAiE+8oXU0nG3NAdYse6g=" +}: + +let + libmcuupdate = pkgs.callPackage ./nix/libmcuupdate.nix { + inherit + mrs_toolchain_version + mrs_toolchain_hash; + }; + mrs-toolchain = pkgs.callPackage ./nix/mrs-toolchain.nix { + inherit + mrs_toolchain_version + mrs_toolchain_hash; + }; + xpack-riscv-none-embed-gcc-8_2 = pkgs.callPackage ./nix/xpack-riscv-none-embed-gcc-8.2.nix { + xpack_toolchain_version = "8.2.0-3.1"; + xpack_toolchain_hash = "sha256-PUD6tQ662EJP+FdI8l0uruUPhqXVIiq9ekWi5JDx5PU="; + ext = "tgz"; + }; + xpack-riscv-none-embed-gcc-8_3 = pkgs.callPackage ./nix/xpack-riscv-none-embed-gcc.nix { + xpack_toolchain_version = "8.3.0-2.3"; + xpack_toolchain_hash = "sha256-cI0Mtf8S61rQcBU1lMT3dxzYbUtnIad7I/j+aVyPlAI="; + }; + xpack-riscv-none-embed-gcc-10_1 = pkgs.callPackage ./nix/xpack-riscv-none-embed-gcc.nix { + xpack_toolchain_version = "10.1.0-1.2"; + xpack_toolchain_hash = "sha256-xg3oiAzqnfIHst+CDTfOq44CtIeD5znCyM/h8qBv4xA="; + }; + xpack-riscv-none-embed-gcc = pkgs.callPackage ./nix/xpack-riscv-none-embed-gcc.nix { + xpack_toolchain_version = "10.2.0-1.2"; + xpack_toolchain_hash = "sha256-1yvc0e7kHcWiCKigOXa3DQFFEN61iQyehzjoBLoj+YU="; + }; + xpack-riscv-none-elf-gcc-11_3 = pkgs.callPackage ./nix/xpack-riscv-none-elf-gcc.nix { + xpack_toolchain_version = "11.3.0-1"; + xpack_toolchain_hash = "sha256-HJn7FXP/LtXe/85ky5a7knLzUfBUaExJ39WtQcbdgE0="; + }; + xpack-riscv-none-elf-gcc-12_3 = pkgs.callPackage ./nix/xpack-riscv-none-elf-gcc.nix { + xpack_toolchain_version = "12.3.0-2"; + xpack_toolchain_hash = "sha256-mSHWPARhGVSvAWucp0zVLBzLgygA0yHWfk5lHxYUbRY="; + }; + xpack-riscv-none-elf-gcc = pkgs.callPackage ./nix/xpack-riscv-none-elf-gcc.nix { + xpack_toolchain_version = "13.2.0-1"; + xpack_toolchain_hash = "sha256-1+/1xdd4hzw9SG5dLIBbglgucwgfk+2zdaHvXYR2S0M="; + }; + python = pkgs.python3.withPackages (python-packages: with python-packages; [ + cbor2 + click + cryptography + intelhex + pyyaml + ]); + wchisp = pkgs.callPackage ./nix/wchisp.nix {}; +in + +pkgs.mkShell { + buildInputs = with pkgs; [ + hidapi + libjaylink + libusb1 + mbedtls + ncurses5 + cmake + ccache + ] ++ [ + libmcuupdate + mrs-toolchain + xpack-riscv-none-elf-gcc + python + wchisp + ]; +}