Skip to content

Commit

Permalink
Merge NixOS#479
Browse files Browse the repository at this point in the history
479: starfive/visionfive/v1: init r=Mic92 a=Madouura



Co-authored-by: Madoura <madouura@gmail.com>
  • Loading branch information
bors[bot] and Madouura authored Oct 9, 2022
2 parents 99c8f75 + 0a71df5 commit ec396f0
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ See code for all available configurations.
| [Raspberry Pi 2](raspberry-pi/2) | `<nixos-hardware/raspberry-pi/2>` |
| [Raspberry Pi 4](raspberry-pi/4) | `<nixos-hardware/raspberry-pi/4>` |
| [Samsung Series 9 NP900X3C](samsung/np900x3c) | `<nixos-hardware/samsung/np900x3c>` |
| [StarFive VisionFive v1](starfive/visionfive/v1) | `<nixos-hardware/starfive/visionfive/v1>` |
| [Supermicro A1SRi-2758F](supermicro/a1sri-2758f) | `<nixos-hardware/supermicro/a1sri-2758f>` |
| [Supermicro M11SDV-8C-LN4F](supermicro/m11sdv-8c-ln4f) | `<nixes-hardware/supermicro/m11sdv-8c-ln4f>` |
| [Supermicro X10SLL-F](supermicro/x10sll-f) | `<nixos-hardware/supermicro/x10sll-f>` |
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
raspberry-pi-4 = import ./raspberry-pi/4;
kobol-helios4 = import ./kobol/helios4;
samsung-np900x3c = import ./samsung/np900x3c;
starfive-visionfive-v1 = import ./starfive/visionfive/v1;
supermicro = import ./supermicro;
supermicro-a1sri-2758f = import ./supermicro/a1sri-2758f;
supermicro-m11sdv-8c-ln4f = import ./supermicro/m11sdv-8c-ln4f;
Expand Down
25 changes: 25 additions & 0 deletions starfive/visionfive/v1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
### Build the SD image
- ``nix-build "<nixpkgs/nixos>" -A config.system.build.sdImage -I nixos-config=iso.nix``

- ``iso.nix``
```nix
{ config, ... }:
{
imports = [ <nixos-hardware/starfive/visionfive/v1/sd-image-installer.nix> ];
# or imports = [ "${nixos-hardware-directory}/starfive/visionfive/v1/sd-image-installer.nix" ];
nixpkgs.crossSystem = {
config = "riscv64-unknown-linux-gnu";
system = "riscv64-linux";
};
}
```

### Relevant documentation
- Flashing
- - https://doc-en.rvspace.org/VisionFive/Quick_Start_Guide/VisionFive_QSG/hardware_connection.html
- - https://doc-en.rvspace.org/VisionFive/Quick_Start_Guide/VisionFive_QSG/using_xmodem1.html
- Recovery
- - https://doc-en.rvspace.org/VisionFive/Quick_Start_Guide/VisionFive_QSG/hardware_setup.html
- - https://doc-en.rvspace.org/VisionFive/Quick_Start_Guide/VisionFive_QSG/for_maclinux4.html
31 changes: 31 additions & 0 deletions starfive/visionfive/v1/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{ config, lib, pkgs, ...}:

{
hardware.deviceTree.name = lib.mkDefault "starfive/jh7100-starfive-visionfive-v1.dtb";
systemd.services."serial-getty@hvc0".enable = lib.mkDefault false;
environment.systemPackages = with pkgs; lib.mkDefault [ mtdutils ];

boot = {
# Force no ZFS (from nixos/modules/profiles/base.nix) until updated to kernel 6.0
supportedFilesystems = lib.mkForce [ "btrfs" "reiserfs" "vfat" "f2fs" "xfs" "ntfs" "cifs" ];
consoleLogLevel = lib.mkDefault 7;
kernelPackages = lib.mkDefault (pkgs.callPackage ./linux.nix { inherit (config.boot) kernelPatches; });

kernelParams = lib.mkDefault [
"console=tty0"
"console=ttyS0,115200n8"
"earlycon=sbi"
];

initrd.kernelModules = lib.mkDefault [
"dw-axi-dmac-platform"
"dw_mmc-pltfm"
"spi-dw-mmio"
];

loader = {
grub.enable = lib.mkDefault false;
generic-extlinux-compatible.enable = lib.mkDefault true;
};
};
}
35 changes: 35 additions & 0 deletions starfive/visionfive/v1/firmware.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{ runCommand
, buildPackages
, pkgs
}:

let
uboot = pkgs.callPackage ./uboot.nix { };

opensbi = pkgs.opensbi.override {
withPayload = "${uboot}/u-boot.bin";
withFDT = "${uboot}/u-boot.dtb";
};
in runCommand "firmware-starfive-visionfive-v1" {
nativeBuildInputs = with buildPackages; [ xxd ];
} ''
function handle_file {
inFile=$1
echo inFile: $inFile
outFile=$2
inSize=`stat -c "%s" $inFile`
inSize32HexBe=`printf "%08x\n" $inSize`
inSize32HexLe=''${inSize32HexBe:6:2}''${inSize32HexBe:4:2}''${inSize32HexBe:2:2}''${inSize32HexBe:0:2}
echo "inSize: $inSize (0x$inSize32HexBe, LE:0x$inSize32HexLe)"
echo $inSize32HexLe | xxd -r -ps > $outFile
cat $inFile >> $outFile
echo outFile: $outFile
outSize=`stat -c "%s" $outFile`
outSize32HexBe=`printf "%08x\n" $outSize`
echo "outSize: $outSize (0x$outSize32HexBe)"
}
mkdir -p "$out/nix-support"
echo "file bin \"$out/opensbi_u-boot_starfive_visionfive_v1.bin\"" >> "$out/nix-support/hydra-build-products"
handle_file ${opensbi}/share/opensbi/lp64/generic/firmware/fw_payload.bin $out/opensbi_u-boot_starfive_visionfive_v1.bin
''
36 changes: 36 additions & 0 deletions starfive/visionfive/v1/linux.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{ lib
, callPackage
, linuxPackagesFor
, kernelPatches
, ... }:

let
modDirVersion = "6.0.0";

linuxPkg = { fetchFromGitHub, buildLinux, ... } @ args:
buildLinux (args // {
inherit modDirVersion kernelPatches;
version = "${modDirVersion}-starfive-visionfive-v1";

src = fetchFromGitHub {
owner = "starfive-tech";
repo = "linux";
rev = "cfcb617265422c0af0ae5bc9688dceba2d10b27a";
sha256 = "sha256-EAMCOtJZ51xSLySQPaZyomfa/1Xs9kNedz04tIbELqg=";
};

defconfig = "starfive_jh7100_fedora_defconfig";

structuredExtraConfig = with lib.kernel; {
KEXEC = yes;
SERIAL_8250_DW = yes;
PINCTRL_STARFIVE = yes;
DW_AXI_DMAC_STARFIVE = yes;
PTP_1588_CLOCK = yes;
STMMAC_ETH = yes;
STMMAC_PCI = yes;
};

extraMeta.branch = "visionfive";
} // (args.argsOverride or { }));
in lib.recurseIntoAttrs (linuxPackagesFor (callPackage linuxPkg { }))
12 changes: 12 additions & 0 deletions starfive/visionfive/v1/sd-image-installer.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To build, use:
# nix-build "<nixpkgs/nixos>" -I nixos-config=starfive/visionfive/v1/sd-image-installer.nix -A config.system.build.sdImage
{
imports = [
<nixpkgs/nixos/modules/profiles/installation-device.nix>
./sd-image.nix
];

# the installation media is also the installation target,
# so we don't want to provide the installation configuration.nix.
installer.cloneConfig = false;
}
29 changes: 29 additions & 0 deletions starfive/visionfive/v1/sd-image.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# To build, use:
# nix-build "<nixpkgs}/nixos>" -I nixos-config=starfive/visionfive/v1/sd-image.nix -A config.system.build.sdImage
{ config, pkgs, ... }:

let
firmware = pkgs.callPackage ./firmware.nix { };
in {
imports = [
<nixpkgs/nixos/modules/profiles/base.nix>
<nixpkgs/nixos/modules/installer/sd-card/sd-image.nix>
./default.nix
];

sdImage = {
imageName = "${config.sdImage.imageBaseName}-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}-starfive-visionfive-v1.img";

# We have to use custom boot firmware since we do not support
# StarFive's Fedora MMC partition layout. Thus, we include this in
# the image's firmware partition so the user can flash the custom firmware.
populateFirmwareCommands = ''
cp ${firmware}/opensbi_u-boot_starfive_visionfive_v1.bin firmware/opensbi_u-boot_starfive_visionfive_v1.bin
'';

populateRootCommands = ''
mkdir -p ./files/boot
${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot
'';
};
}
17 changes: 17 additions & 0 deletions starfive/visionfive/v1/uboot.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ fetchFromGitHub
, buildUBoot
}:

buildUBoot {
version = "2022.04";

src = fetchFromGitHub {
owner = "Madouura";
repo = "u-boot";
rev = "fe61fbcc8c5d3f7a589d2a6ea61855ab77de621f";
sha256 = "sha256-jMZYxAHB37pNzzLdb8wupZA1CeD0gB84x18B7XVzq/M=";
};

defconfig = "starfive_jh7100_visionfive_smode_defconfig";
filesToInstall = [ "u-boot.bin" "u-boot.dtb" ];
}

0 comments on commit ec396f0

Please sign in to comment.