1
0
Fork 0
mirror of https://github.com/NixOS/nixos-hardware synced 2024-11-23 03:19:42 +01:00

starfive/visionfive/v1: init

This commit is contained in:
Madoura 2022-10-08 10:27:03 -05:00
parent c156c31e1d
commit 68e08aa56b
No known key found for this signature in database
GPG key ID: 50CCE80199B1F736
7 changed files with 185 additions and 0 deletions

View file

@ -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

View file

@ -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;
};
};
}

View file

@ -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
''

View file

@ -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 { }))

View file

@ -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;
}

View file

@ -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
'';
};
}

View file

@ -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" ];
}