This commit is contained in:
matthewcroughan 2022-06-25 16:37:18 +01:00
commit 6152bd2ba9
6 changed files with 284 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*result*

37
base.nix Normal file
View File

@ -0,0 +1,37 @@
{ config, pkgs, lib, ... }:
{
# Use the kernel from ./kernel.nix
boot.kernelPackages = let
linux_VisionFive = pkgs.callPackage ./kernel.nix { };
in lib.mkForce (pkgs.recurseIntoAttrs (pkgs.linuxPackagesFor linux_VisionFive));
# Remove ZFS
boot.supportedFilesystems = lib.mkForce [ "btrfs" "reiserfs" "vfat" "f2fs" "xfs" "ntfs" "cifs" "ext4" "vfat" ];
# Awaiting upstream linux-firmware patch
# https://lore.kernel.org/all/CADWks+YJm8bi+KPXYTvQ3JrriDW2dcdxfSZ2O5J0vfhfC654Tw@mail.gmail.com/
# https://github.com/NixOS/nixpkgs/pull/168826#issuecomment-1152990386
nixpkgs.overlays = [
(final: prev: {
linux-firmware = prev.linux-firmware.overrideAttrs (old: {
postInstall = ''
cp $out/lib/firmware/brcm/brcmfmac43430-sdio.AP6212.txt \
$out/lib/firmware/brcm/brcmfmac43430-sdio.starfive,visionfive-v1.txt
'';
outputHash = null;
});
})
];
# Enable ssh on boot
services = {
openssh.enable = true;
};
users = {
users.default = {
password = "visionfive-nix";
isNormalUser = true;
};
};
}

4
configuration.nix Normal file
View File

@ -0,0 +1,4 @@
{
networking.firewall.allowedTCPPorts = [ 19999 ];
services.netdata.enable = true;
}

83
flake.lock Normal file
View File

@ -0,0 +1,83 @@
{
"nodes": {
"jh7100_ddrinit": {
"flake": false,
"locked": {
"narHash": "sha256-pOlg3FtFdFhHHnE16izS26RkJ7RbQpglDKgpVRdyAso=",
"type": "file",
"url": "https://github.com/starfive-tech/JH7100_ddrinit/releases/download/ddrinit-2133-211102/ddrinit-2133-211102.bin.out"
},
"original": {
"type": "file",
"url": "https://github.com/starfive-tech/JH7100_ddrinit/releases/download/ddrinit-2133-211102/ddrinit-2133-211102.bin.out"
}
},
"jh7100_recovery_binary": {
"flake": false,
"locked": {
"narHash": "sha256-T3vqaelqwXiOqD8yRHw899A5GI2J+hU/5l5S3euIs2g=",
"type": "file",
"url": "https://github.com/starfive-tech/bootloader_recovery/releases/download/JH7100_recovery_binary/jh7100_recovery_boot.bin"
},
"original": {
"type": "file",
"url": "https://github.com/starfive-tech/bootloader_recovery/releases/download/JH7100_recovery_binary/jh7100_recovery_boot.bin"
}
},
"jh7100_secondBoot": {
"flake": false,
"locked": {
"narHash": "sha256-Ek8RK8t3y9JfpVfey1X9yZn9OIbOj/EJokUeWbZWZGU=",
"type": "file",
"url": "https://github.com/starfive-tech/JH7100_secondBoot/releases/download/bootloader-211102_VisionFive_JH7100/bootloader-JH7100-211102.bin.out"
},
"original": {
"type": "file",
"url": "https://github.com/starfive-tech/JH7100_secondBoot/releases/download/bootloader-211102_VisionFive_JH7100/bootloader-JH7100-211102.bin.out"
}
},
"jh71xx-tools": {
"flake": false,
"locked": {
"lastModified": 1644591616,
"narHash": "sha256-eCOI/kYmkSxL4HPqBPoJFWa6qJwqafPOxS8KhIuMF4s=",
"owner": "xypron",
"repo": "jh71xx-tools",
"rev": "afe3328923d6c3883886a00c4ed10eda019f2db1",
"type": "github"
},
"original": {
"owner": "xypron",
"repo": "jh71xx-tools",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1652789813,
"narHash": "sha256-90QPw85Vl9+YWQpM/zRjb0/OYI+IODimC4LZufpCIh4=",
"owner": "Madouura",
"repo": "nixpkgs",
"rev": "aff8bd5ce0a12ee22402cd9bc6b3c437f0845345",
"type": "github"
},
"original": {
"owner": "Madouura",
"ref": "dev/linux-riscv",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"jh7100_ddrinit": "jh7100_ddrinit",
"jh7100_recovery_binary": "jh7100_recovery_binary",
"jh7100_secondBoot": "jh7100_secondBoot",
"jh71xx-tools": "jh71xx-tools",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

117
flake.nix Normal file
View File

@ -0,0 +1,117 @@
{
inputs = {
nixpkgs.url = "github:Madouura/nixpkgs/dev/linux-riscv";
jh7100_ddrinit = {
url = "https://github.com/starfive-tech/JH7100_ddrinit/releases/download/ddrinit-2133-211102/ddrinit-2133-211102.bin.out";
flake = false;
};
jh7100_secondBoot = {
url = "https://github.com/starfive-tech/JH7100_secondBoot/releases/download/bootloader-211102_VisionFive_JH7100/bootloader-JH7100-211102.bin.out";
flake = false;
};
jh7100_recovery_binary = {
url = "https://github.com/starfive-tech/bootloader_recovery/releases/download/JH7100_recovery_binary/jh7100_recovery_boot.bin";
flake = false;
};
jh71xx-tools = {
url = "github:xypron/jh71xx-tools";
flake = false;
};
};
outputs = { self, nixpkgs, jh71xx-tools, jh7100_recovery_binary, jh7100_secondBoot, jh7100_ddrinit }:
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
modules = [
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-riscv64-visionfive-installer.nix"
./base.nix
./configuration.nix
];
in
{
apps.x86_64-linux = {
flashBootloader =
let
expectScript = pkgs.writeScript "expect-visionfive.sh" ''
#!${pkgs.expect}/bin/expect -f
set timeout -1
spawn ${pkgs.picocom}/bin/picocom [lindex $argv 0] -b 115200 -s "${pkgs.lrzsz}/bin/sz -X"
expect "bootloader"
expect "DDR"
send "\r"
expect "0:update uboot"
expect "select the function:"
send "0\r"
expect "send file by xmodem"
expect "CC"
send "\x01\x13"
expect "*** file:"
send "${pkgs.pkgsCross.riscv64.firmware-visionfive}/opensbi_u-boot_visionfive.bin"
send "\r"
expect "Transfer complete"
'';
program = pkgs.writeShellScript "flash-visionfive.sh" ''
if $(groups | grep --quiet --word-regexp "dialout"); then
echo "User is in dialout group, flashing to board without sudo"
${expectScript} $1
else
echo "User is not in dialout group, flashing to board with sudo"
sudo ${expectScript} $1
fi
'';
in
{
type = "app";
program = "${program}";
};
flashOriginal =
let
program = pkgs.writeShellScript "flash-visionfive.sh" ''
flash() {
(
set -x
${pkgs.lib.getExe self.packages.x86_64-linux.jh7100-recover} \
-D $1 \
-r ${jh7100_recovery_binary} \
-b ${jh7100_secondBoot} \
-d ${jh7100_ddrinit}
)
}
if $(groups | grep --quiet --word-regexp "dialout"); then
echo "User is in dialout group, flashing to board without sudo"
flash
else
echo "User is not in dialout group, flashing to board with sudo"
sudo flash
fi
'';
in
{
type = "app";
program = "${program}";
};
};
packages.x86_64-linux = {
jh7100-recover = pkgs.writeCBin "jh7100-recover" (builtins.readFile "${jh71xx-tools}/jh7100-recover.c");
};
images = {
visionfive-cross-x86 = self.nixosConfigurations.visionfive-cross-x86.config.system.build.sdImage;
visionfive-native = self.nixosConfigurations.visionfive-cross-x86.config.system.build.sdImage;
};
nixosConfigurations = {
visionfive-cross-x86 = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = modules ++ [
{
nixpkgs.crossSystem = {
system = "riscv64-linux";
};
}
];
};
visionfive-native = nixpkgs.lib.nixosSystem {
system = "riscv64-linux";
modules = modules;
};
};
};
}

42
kernel.nix Normal file
View File

@ -0,0 +1,42 @@
{ lib
, fetchFromGitHub
, buildLinux
, ... } @ args:
let
modDirVersion = "5.18.5";
in buildLinux (args // {
inherit modDirVersion;
version = "${modDirVersion}-visionfive";
src = fetchFromGitHub {
owner = "starfive-tech";
repo = "linux";
rev = "8fb50a9b3e5d401d4ec169c858e8b7ba0a542955";
sha256 = "sha256-kjOoNJhmmQdpmtx0m1ZovH3mj2x4NB6iInEknxZq8Dw=";
};
kernelPatches = [];
defconfig = "starfive_jh7100_fedora_defconfig";
structuredExtraConfig = with lib.kernel; {
SERIAL_8250_DW = yes;
PINCTRL_STARFIVE = yes;
# Doesn't build as a module
DW_AXI_DMAC_STARFIVE = yes;
# stmmac hangs when built as a module
PTP_1588_CLOCK = yes;
STMMAC_ETH = yes;
STMMAC_PCI = yes;
};
extraMeta = {
branch = "visionfive-5.18.y";
description = "Linux kernel for StarFive's JH7100 RISC-V SoC (VisionFive)";
platforms = [ "riscv64-linux" ];
hydraPlatforms = [ "riscv64-linux" ];
};
} // (args.argsOverride or { }))