Initial commit

This commit is contained in:
Peder Bergebakken Sundt 2023-06-24 14:56:10 +02:00
commit 805e48523d
6 changed files with 431 additions and 0 deletions

30
builders/make-nvme.nix Normal file
View File

@ -0,0 +1,30 @@
{ config, lib, pkgs, modulesPath, ... }:
with lib;
{
system.build.nvmeImage = import "${modulesPath}/../lib/make-disk-image.nix" {
inherit config lib pkgs;
diskSize = 8*1024; # megabytes
# TODO: zstd
format = "raw"; # one of qcow2, qcow2-compressed, vdi, vpc, raw.
installBootLoader = true;
partitionTableType = "efi";
configFile = pkgs.writeText "configuration.nix" ''
{
imports = [ <./machine-config.nix> ];
}
'';
};
boot.growPartition = true;
boot.initrd.kernelModules = [ "nvme" ];
/** /
boot.loader.grub.efiSupport = true;
boot.loader.grub.efiInstallAsRemovable = true;
boot.loader.grub.device = "nodev";
/**/
fileSystems."/boot" = { device = "/dev/nvme0n1p1"; fsType = "vfat"; };
fileSystems."/" = { device = "/dev/nvme0n1p2"; fsType = "ext4"; };
}

21
configuration.nix Normal file
View File

@ -0,0 +1,21 @@
{ config, lib, pkgs, modulesPath, ... }:
{
imports = [ "${modulesPath}/profiles/base.nix" ];
boot.enableContainers = false;
console.keyMap = "no";
programs.command-not-found.enable = false;
i18n.supportedLocales = [ "en_US.UTF-8/UTF-8" ];
documentation.man.enable = false;
documentation.info.enable = false;
security.polkit.enable = lib.mkForce false;
security.audit.enable = false;
system.stateVersion = "22.11";
environment.systemPackages = with pkgs;[
neofetch
fd
ripgrep
];
}

118
flake.lock generated Normal file
View File

@ -0,0 +1,118 @@
{
"nodes": {
"meta-sifive": {
"flake": false,
"locked": {
"lastModified": 1674637034,
"narHash": "sha256-63ND5ppiTZq6R0S5DQXzKwTdP+ksRN2xUBSnOuSZIVc=",
"owner": "sifive",
"repo": "meta-sifive",
"rev": "0cf45af2861140a11a3655b6c1185a1b781420a0",
"type": "github"
},
"original": {
"owner": "sifive",
"ref": "master",
"repo": "meta-sifive",
"type": "github"
}
},
"nickcao-rv64": {
"inputs": {
"meta-sifive": "meta-sifive",
"nixpkgs": [
"nixpkgs"
],
"starfive-tools": "starfive-tools",
"u-boot-starfive": "u-boot-starfive",
"uboot-vf2-src": "uboot-vf2-src"
},
"locked": {
"lastModified": 1678100894,
"narHash": "sha256-P4zsTLZeD+jZW7wdTa+gIEqaOKV5atcpiaRMMSPVyWw=",
"owner": "NickCao",
"repo": "nixos-riscv",
"rev": "a95622d7c532f0bd6271bbc937d8c55faf1f4801",
"type": "github"
},
"original": {
"owner": "NickCao",
"repo": "nixos-riscv",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1678101150,
"narHash": "sha256-Y0EAwuMqucZrH7FwkAeDAXSOIEFlQGVoQSk3+Nj07Ls=",
"owner": "NickCao",
"repo": "nixpkgs",
"rev": "d23ade162e3a0fd23479a7073eeac9da5f1a40db",
"type": "github"
},
"original": {
"owner": "NickCao",
"ref": "riscv",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nickcao-rv64": "nickcao-rv64",
"nixpkgs": "nixpkgs"
}
},
"starfive-tools": {
"flake": false,
"locked": {
"lastModified": 1674126575,
"narHash": "sha256-dKRHFWLJrXIEpsuXOO3zpiIplPFG5ghVLYR8GvBat8M=",
"owner": "NickCao",
"repo": "starfive-tools",
"rev": "7038f61fcd684fc60d2abc4fd95909782480c66b",
"type": "github"
},
"original": {
"owner": "NickCao",
"repo": "starfive-tools",
"type": "github"
}
},
"u-boot-starfive": {
"flake": false,
"locked": {
"lastModified": 1651224393,
"narHash": "sha256-48ah4mcEqrK9iRAz/QGCZUcz34xAuZyJuPanQ8IssMU=",
"owner": "NickCao",
"repo": "u-boot-starfive",
"rev": "ac75aa54020412a83b61dad46c5ea15e7f9f525c",
"type": "github"
},
"original": {
"owner": "NickCao",
"repo": "u-boot-starfive",
"type": "github"
}
},
"uboot-vf2-src": {
"flake": false,
"locked": {
"lastModified": 1678096112,
"narHash": "sha256-w6dPaok72sW7Q4ChSWDqds+djWWwigirz9f+s623r/g=",
"owner": "NickCao",
"repo": "u-boot-starfive",
"rev": "64fc719a5db536abaec42564689d96bcfdf0dfba",
"type": "github"
},
"original": {
"owner": "NickCao",
"ref": "visionfive2",
"repo": "u-boot-starfive",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

99
flake.nix Normal file
View File

@ -0,0 +1,99 @@
{
description = "My visionfive 2 setup";
inputs = {
nixpkgs.url = "github:NickCao/nixpkgs/riscv"; # https://github.com/NickCao/nixpkgs/tree/riscv
#nixpkgs.url = "github:nixos/nixpkgs/nixos-22.11"; # https://github.com/nixos/nixpkgs/tree/nixos-22.11
#unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable"; # https://github.com/nixos/nixpkgs/tree/nixpkgs-unstable
nickcao-rv64.url = "github:NickCao/nixos-riscv"; # https://github.com/NickCao/nixos-riscv
nickcao-rv64.inputs.nixpkgs.follows = "nixpkgs";
#nickcao-rv64.url = "path:../nickcao-nixos-riscv"; # broken: https://github.com/NixOS/nix/issues/3978
#zhao-rv64.url = "github:zhaofengli/nixos-riscv64"; # https://github.com/zhaofengli/nixos-riscv64
};
outputs = { self, nixpkgs, nickcao-rv64, ...}@inputs:
let
nixlib = nixpkgs.lib;
overlays = nixlib.mapAttrsToList (name: val: val) self.overlays;
hostname = hostname: {
networking.hostName = hostname;
networking.domain = "pbsds.net";
};
in {
#hydraJobs = {}
overlays = {
nickcao = nickcao-rv64.overlay;
#default = (final: prev: {});
};
nixosModules.generic-boot = {
boot.loader.grub.enable = false;
boot.loader.generic-extlinux-compatible.enable = true;
};
nixosModules.rv64 = {
system = "riscv64-unknown-linux-gnu";
#nixpkgs.overlays = [ self.overlays.nickcao ];
};
nixosModules.rv64-cross = {
nixpkgs.localSystem.config = "x86_64-unknown-linux-gnu";
nixpkgs.crossSystem.config = "riscv64-unknown-linux-gnu";
#nixpkgs.overlays = [ self.overlays.nickcao ];
};
nixosModules.nvme-image = { config, lib, pkgs, modulesPath , ... }: {
system.build.nvmeImage = import "${modulesPath}/../lib/make-disk-image.nix" {
inherit config lib pkgs;
diskSize = 8*1024; # megabytes
# TODO: zstd
format = "raw"; # one of qcow2, qcow2-compressed, vdi, vpc, raw.
installBootLoader = true;
partitionTableType = "efi";
# TODO: make this thing able to rebuild
configFile = pkgs.writeText "configuration.nix" ''
{
imports = [ <./machine-config.nix> ];
}
'';
};
boot.growPartition = true;
boot.initrd.kernelModules = [ "nvme" ];
/** /
boot.loader.grub.efiSupport = true;
boot.loader.grub.efiInstallAsRemovable = true;
boot.loader.grub.device = "nodev";
/**/
fileSystems."/boot" = { device = "/dev/nvme0n1p1"; fsType = "vfat"; };
fileSystems."/" = { device = "/dev/nvme0n1p2"; fsType = "ext4"; };
};
nixosModules.sd-image = { config, lib, pkgs, modulesPath, ... }: {
imports = [ "${modulesPath}/installer/sd-card/sd-image.nix" ];
sdImage.populateFirmwareCommands = "";
sdImage.populateRootCommands = ''
mkdir -p ./files/boot
${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot
'';
};
nixosModules.nickcao-common = "${nickcao-rv64.outPath}/common.nix"; # is equal to: generic-boot + sd-image + rv64-cross
nixosModules.nickcao-unmatched = "${nickcao-rv64.outPath}/unmatched.nix";
nixosModules.nickcao-visionfive = "${nickcao-rv64.outPath}/visionfive.nix";
nixosModules.nickcao-visionfive2 = "${nickcao-rv64.outPath}/visionfive2.nix";
nixosModules.nickcao-qemu = "${nickcao-rv64.outPath}/qemu.nix";
nixosModules.base = {
nixpkgs.overlays = overlays;
imports = [ ./configuration.nix ];
};
# TODO: gunder
# nixos-rebuild --flake .#NAME
nixosConfigurations.qemu = nickcao-rv64.nixosConfigurations.qemu.extendModules { modules = with self.nixosModules; [ base ]; };
nixosConfigurations.asgaut = nixpkgs.lib.nixosSystem { modules = with self.nixosModules; [ base (hostname "asgaut") nickcao-visionfive2 ]; };
nixosConfigurations.asgaut-nvme = nixpkgs.lib.nixosSystem { modules = with self.nixosModules; [ base (hostname "asgaut") nickcao-visionfive2 generic-boot rv64-cross nvme-image ]; };
nixosConfigurations.asgaut-sd = nixpkgs.lib.nixosSystem { modules = with self.nixosModules; [ base (hostname "asgaut") nickcao-visionfive2 generic-boot rv64-cross sd-image ]; };
nixosConfigurations.asgaut-sd2 = nixpkgs.lib.nixosSystem { modules = with self.nixosModules; [ base (hostname "asgaut") nickcao-visionfive2 nickcao-common ]; };
# nix build .#images.NAME .
images.asgaut-nvme = self.nixosConfigurations.asgaut-nvme.config.system.build.nvmeImage;
images.asgaut-sd = self.nixosConfigurations.asgaut-sd .config.system.build.sdImage;
images.asgaut-sd2 = self.nixosConfigurations.asgaut-sd2 .config.system.build.sdImage;
# nix build .#riscv64-linux.NAME-sd-image
#packages.riscv64-linux.asgaut-sd-image = self.nixosConfigurations.gunder.config.system.build.sdImage;
};
}

142
notes.md Normal file
View File

@ -0,0 +1,142 @@
# dev/build TLDRs
* `nix flake show .`
* `nix repl` followed by `:lf .` to much about in a REPL
* `nix build .#nixosConfigurations.asgaut.config.system.build.sdImage`
* `nix build .#images.asgaut-sd` to cross build
* `TODO` to build via binfmt emulation
* `zstd -vdcfT4 result/sd-image/*.img.zst | dd of=/dev/sda2 status=progress; sync`
## VF2 Overview
* The VisionFive 2
* Shortname: `vf2`
* https://www.kickstarter.com/projects/starfive/visionfive-2
* https://wiki.rvspace.org/
* StarFive JH7110 64-bit CPU
* CPU: quad SiFive U74 1.5GHz cores and comes paired with
* GPU: BXE-4-32 GPU from Imagination Technologies.
* OpenGL ES 3.2
* OpenCL 1.2
* Vulkan 1.2
* 2/4/8 GB RAM
* IO
* 1x HMDI (up to 4kp30)
* H.264 decode
* H.265 decode/encode
* 2x Gigabit Ethernet
* 2x USB 2.0
* 2x USB 3.0
* 2x M.2 NVMe
* MIPI CSI
* MIPI DSI
* MIPI LCD
* 4pin GPIO
* power:
* 5v DC via USB-C PD up to 30W
* 5v Dc via GPIO minimum 3A
* PoE (requires separate hardware module?)
* Storage
* SD
* NVMe
* SPI flash
* Their linux tree
* U-Boot
* used as firmware and bootloader (instead of GRUB like for x86) on ARM and RISCV
* [Generic Distro Configuration Concept](https://github.com/u-boot/u-boot/blob/master/doc/develop/distro.rst)
* U-Boot is scripted to scan all attached storage devices & partitions and look for a file named /extlinux/extlinux.conf or /boot/extlinux/extlinux.conf
## Some VisionFive/RISCV/U-Boot reading
* https://lobste.rs/s/4gmbhc/hands_on_experience_with_starfive
* https://rvspace.org/en/project/JH7110_Upstream_Plan
* https://nixos.wiki/wiki/NixOS_on_ARM
* https://nixos.wiki/wiki/NixOS_on_ARM/UEFI
* https://doc-en.rvspace.org/VisionFive2/PDF/VisionFive2_QSG.pdf
* https://github.com/MatthewCroughan/visionfive-nix/tree/master/visionfive2
* https://www.youtube.com/watch?v=cmjK8SLIx9E
## Nix flakes
I'm new lol
* https://nixos.wiki/wiki/Flakes
* https://zero-to-nix.com/concepts/flakes
* https://github.com/dali99/nix-dotfiles/blob/master/flake.nix
## nixos builders
* https://nixos.org/guides/building-bootable-iso-image.html
* https://rbf.dev/blog/2020/05/custom-nixos-build-for-raspberry-pis/
* https://gist.github.com/tarnacious/f9674436fff0efeb4bb6585c79a3b9ff
* https://jade.fyi/blog/nixos-disk-images-m1/
* https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/installer/sd-card/sd-image.nix
* https://github.com/NixOS/nixpkgs/blob/master/nixos/lib/make-ext4-fs.nix
* https://github.com/NixOS/nixpkgs/blob/master/nixos/lib/make-disk-image.nix
# [github:NickCao/nixos-riscv](https://github.com/NickCao/nixos-riscv)
* https://github.com/NickCao/u-boot-starfive - likely just rebased on upstream uboot
* https://github.com/starfive-tech/u-boot/tree/JH7110_VisionFive2_devel
* https://github.com/sifive/meta-sifive/tree/master - BSP layer for OpenEmbedded/Yocto
* https://github.com/NickCao/starfive-tools - `spl_tool` and `uboot_its`
sources of interest:
* https://github.com/NickCao/nixos-riscv/blob/master/common.nix
* https://github.com/NickCao/nixos-riscv/blob/master/visionfive2.nix
```
$ nix flake show github:NickCao/nixos-riscv
github:NickCao/nixos-riscv/4ebf1f02b169f2bf6103776633e873d7968bdb32
├───hydraJobs
│ ├───bootrom-unmatched: derivation 'bootrom'
│ ├───bootrom-visionfive: derivation 'bootrom-visionfive'
│ ├───firmware-vf2: derivation 'firmware-vf2-riscv64-unknown-linux-gnu'
│ ├───linux-vf2: derivation 'linux-riscv64-unknown-linux-gnu-6.1.0-vf2'
│ ├───opensbi: derivation 'opensbi-riscv64-unknown-linux-gnu-1.2'
│ ├───opensbi-vf2: derivation 'opensbi-riscv64-unknown-linux-gnu-1.2'
│ ├───qemu: derivation 'qemu-riscv64-unknown-linux-gnu-7.2.0'
│ ├───uboot-unmatched: derivation 'uboot-sifive_unmatched_defconfig-riscv64-unknown-linux-gnu-2022.10'
│ ├───uboot-unmatched-ram: derivation 'uboot-sifive_unmatched_defconfig-riscv64-unknown-linux-gnu-2022.10'
│ ├───uboot-vf2: derivation 'uboot-starfive_visionfive2_defconfig-riscv64-unknown-linux-gnu-f1d959f'
│ ├───uboot-visionfive: derivation 'uboot-starfive_jh7100_visionfive_smode_defconfig-riscv64-unknown-linux-gnu-e068256b4ea2d01562317cd47caab971815ba174'
│ ├───unmatched: derivation 'nixos-sd-image-23.05.20230119.c75b147-riscv64-linux.img-riscv64-unknown-linux-gnu'
│ ├───visionfive: derivation 'nixos-sd-image-23.05.20230119.c75b147-riscv64-linux.img-riscv64-unknown-linux-gnu'
│ └───visionfive2: derivation 'nixos-sd-image-23.05.20230119.c75b147-riscv64-linux.img-riscv64-unknown-linux-gnu'
├───nixosConfigurations
│ ├───qemu: NixOS configuration
│ ├───unmatched: NixOS configuration
│ ├───visionfive: NixOS configuration
│ └───visionfive2: NixOS configuration
└───overlay: Nixpkgs overlay
```
# [github:zhaofengli/nixos-riscv64](https://github.com/zhaofengli/nixos-riscv64)
... no visionfive 2?
* https://github.com/NixOS/nixpkgs/issues/101651#issuecomment-852725823
* https://gist.github.com/zhaofengli/275d1a0de14eceba90fd4e399af34b5c
* https://github.com/zhaofengli/nixos-riscv64/issues/3
```
$ nix flake show github:zhaofengli/nixos-riscv64
github:zhaofengli/nixos-riscv64/def02c67833bf551288c5cbd8ed6652b255d2fe8
├───hydraJobs
│ └───world
│ ├───simpleSystem: derivation 'nixos-system-nixos-23.05pre-git'
│ ├───tier0: derivation 'tier0'
│ ├───tier1: derivation 'tier1'
│ └───tier2: derivation 'tier2'
├───legacyPackages
│ └───riscv64-linux omitted (use '--legacy' to show)
├───nixosModules
│ ├───unmatched: NixOS module
│ └───visionfive: NixOS module
└───overlay: Nixpkgs overlay
```

21
profiles/cross.nix Normal file
View File

@ -0,0 +1,21 @@
{ config, pkgs, lib, modulesPath, ... }: {
nixpkgs = {
localSystem.config = "x86_64-unknown-linux-gnu";
crossSystem.config = "riscv64-unknown-linux-gnu";
};
boot.loader = {
grub.enable = false;
generic-extlinux-compatible.enable = true;
};
sdImage = {
populateFirmwareCommands = "";
populateRootCommands = ''
mkdir -p ./files/boot
${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot
'';
};
}