2022-06-25 17:37:18 +02:00
{
inputs = {
2022-07-13 08:48:06 +02:00
nixpkgs . url = " g i t h u b : m a t t h e w c r o u g h a n / n i x p k g s / m c / r i s c v - t e s t i n g " ;
2023-02-16 11:57:52 +01:00
# VisionFive ("v1")
2022-07-09 05:28:56 +02:00
vendor-kernel = {
url = " g i t h u b : s t a r f i v e - t e c h / l i n u x " ;
flake = false ;
} ;
2022-06-25 17:37:18 +02:00
jh7100_ddrinit = {
url = " h t t p s : / / g i t h u b . c o m / s t a r f i v e - t e c h / J H 7 1 0 0 _ d d r i n i t / r e l e a s e s / d o w n l o a d / d d r i n i t - 2 1 3 3 - 2 1 1 1 0 2 / d d r i n i t - 2 1 3 3 - 2 1 1 1 0 2 . b i n . o u t " ;
flake = false ;
} ;
jh7100_secondBoot = {
url = " h t t p s : / / g i t h u b . c o m / s t a r f i v e - t e c h / J H 7 1 0 0 _ s e c o n d B o o t / r e l e a s e s / d o w n l o a d / b o o t l o a d e r - 2 1 1 1 0 2 _ V i s i o n F i v e _ J H 7 1 0 0 / b o o t l o a d e r - J H 7 1 0 0 - 2 1 1 1 0 2 . b i n . o u t " ;
flake = false ;
} ;
jh7100_recovery_binary = {
url = " h t t p s : / / g i t h u b . c o m / s t a r f i v e - t e c h / b o o t l o a d e r _ r e c o v e r y / r e l e a s e s / d o w n l o a d / J H 7 1 0 0 _ r e c o v e r y _ b i n a r y / j h 7 1 0 0 _ r e c o v e r y _ b o o t . b i n " ;
flake = false ;
} ;
jh71xx-tools = {
url = " g i t h u b : x y p r o n / j h 7 1 x x - t o o l s " ;
flake = false ;
} ;
2023-02-16 11:57:52 +01:00
# VisionFive 2
jh7110-kernel = {
# url = "github:starfive-tech/linux/50a831018ed997c9fb3b603574176b221a28aa12"; # JH7110_VisionFive2_devel via VisionFive2 project submodule about two revisions back.
url = " g i t h u b : s t a r f i v e - t e c h / l i n u x / J H 7 1 1 0 _ V i s i o n F i v e 2 _ d e v e l " ;
flake = false ;
} ;
jh7110_recovery_binary = {
url = " h t t p s : / / g i t h u b . c o m / s t a r f i v e - t e c h / T o o l s / b l o b / b c 6 d c 7 e 3 3 e 0 c 2 4 6 6 d b 0 4 7 6 b 5 0 4 3 f 0 f 7 7 8 4 2 f 9 8 f 0 / r e c o v e r y / j h 7 1 1 0 - r e c o v e r y - 2 0 2 2 1 2 0 5 . b i n ? r a w = t r u e " ;
flake = false ;
} ;
# Should be possible to build from https://github.com/starfive-tech/VisionFive2
jh7110_u-boot-spl-bin = {
url = https://github.com/starfive-tech/VisionFive2/releases/download/VF2_v2.8.0/u-boot-spl.bin.normal.out ;
flake = false ;
} ;
jh7110_u-boot-bin = {
url = https://github.com/starfive-tech/VisionFive2/releases/download/VF2_v2.8.0/visionfive2_fw_payload.img ;
flake = false ;
} ;
2022-06-25 17:37:18 +02:00
} ;
2023-02-16 12:49:58 +01:00
outputs = inputs @ { self , nixpkgs , jh71xx-tools , jh7100_recovery_binary , jh7100_secondBoot , jh7100_ddrinit , vendor-kernel , . . . }:
2022-06-25 17:37:18 +02:00
let
2023-02-16 12:49:58 +01:00
inherit ( nixpkgs ) lib ;
2022-07-09 05:24:16 +02:00
system = " x 8 6 _ 6 4 - l i n u x " ;
2022-07-09 05:28:56 +02:00
pkgs = import nixpkgs { inherit system ; overlays = [ self . overlay ] ; } ;
2022-06-25 17:37:18 +02:00
modules = [
2022-07-09 05:28:56 +02:00
{ nixpkgs . overlays = [ self . overlay ] ; }
2022-06-25 17:37:18 +02:00
" ${ nixpkgs } / n i x o s / m o d u l e s / i n s t a l l e r / s d - c a r d / s d - i m a g e - r i s c v 6 4 - v i s i o n f i v e - i n s t a l l e r . n i x "
./base.nix
./configuration.nix
] ;
2023-02-16 12:49:58 +01:00
# Pass arguments to a module inside a function inside a file, while preserving
# the file name behavior of the module system.
importApply =
modulePath : staticArgs :
lib . setDefaultModuleLocation modulePath ( import modulePath staticArgs ) ;
2022-06-25 17:37:18 +02:00
in
{
2022-07-09 05:28:56 +02:00
overlay = final : prev : {
linuxPackages_visionfive = final . linuxPackagesFor ( ( final . callPackage ./kernel.nix { inherit vendor-kernel ; } ) . override { patches = [ ] ; } ) ;
} ;
2022-07-09 05:29:20 +02:00
legacyPackages . ${ system } =
{
inherit ( pkgs . pkgsCross . riscv64 . linux ) linuxPackages_visionfive ;
} ;
2022-07-09 05:24:16 +02:00
apps . ${ system } = {
2022-06-25 17:37:18 +02:00
flashBootloader =
let
expectScript = pkgs . writeScript " e x p e c t - v i s i o n f i v e . s h " ''
#!${pkgs.expect}/bin/expect -f
set timeout -1
spawn $ { pkgs . picocom } /bin/picocom [ lindex $ argv 0 ] - b 115200 - s " ${ pkgs . lrzsz } / b i n / s z - X "
2022-07-09 18:53:59 +02:00
expect " T e r m i n a l r e a d y "
send_user " \n # # # A p p l y p o w e r t o t h e V i s i o n F i v e B o a r d # # # \n "
2022-06-25 17:37:18 +02:00
expect " b o o t l o a d e r "
expect " D D R "
send " \r "
expect " 0 : u p d a t e u b o o t "
expect " s e l e c t t h e f u n c t i o n : "
send " 0 \r "
expect " s e n d f i l e b y x m o d e m "
expect " C C "
send " \x 0 1 \x 1 3 "
expect " * * * f i l e : "
send " ${ pkgs . pkgsCross . riscv64 . firmware-visionfive } / o p e n s b i _ u - b o o t _ v i s i o n f i v e . b i n "
send " \r "
expect " T r a n s f e r c o m p l e t e "
'' ;
program = pkgs . writeShellScript " f l a s h - v i s i o n f i v e . s h " ''
if $ ( groups | grep - - quiet - - word-regexp " d i a l o u t " ) ; then
echo " U s e r i s i n d i a l o u t g r o u p , f l a s h i n g t o b o a r d w i t h o u t s u d o "
$ { expectScript } $ 1
else
echo " U s e r i s n o t i n d i a l o u t g r o u p , f l a s h i n g t o b o a r d w i t h s u d o "
sudo $ { expectScript } $ 1
fi
'' ;
in
{
type = " a p p " ;
program = " ${ program } " ;
} ;
flashOriginal =
let
2022-07-11 19:39:36 +02:00
flashScript = pkgs . writeScript " j h 7 1 0 0 - r e c o v e r - v i s i o n f i v e . s h " ''
set - x
$ { pkgs . lib . getExe self . packages . ${ system } . jh7100-recover } \
- D $ 1 \
- r $ { jh7100_recovery_binary } \
- b $ { jh7100_secondBoot } \
- d $ { jh7100_ddrinit }
'' ;
2022-06-25 17:37:18 +02:00
program = pkgs . writeShellScript " f l a s h - v i s i o n f i v e . s h " ''
if $ ( groups | grep - - quiet - - word-regexp " d i a l o u t " ) ; then
echo " U s e r i s i n d i a l o u t g r o u p , f l a s h i n g t o b o a r d w i t h o u t s u d o "
2022-07-11 19:39:36 +02:00
$ { flashScript } $ 1
2022-06-25 17:37:18 +02:00
else
echo " U s e r i s n o t i n d i a l o u t g r o u p , f l a s h i n g t o b o a r d w i t h s u d o "
2022-07-11 19:39:36 +02:00
sudo $ { flashScript } $ 1
2022-06-25 17:37:18 +02:00
fi
'' ;
in
{
type = " a p p " ;
program = " ${ program } " ;
} ;
2023-02-16 13:21:01 +01:00
} // import ./visionfive2/commands.nix { inherit inputs pkgs ; } ;
2022-07-09 05:24:16 +02:00
packages . ${ system } = {
2022-06-25 17:37:18 +02:00
jh7100-recover = pkgs . writeCBin " j h 7 1 0 0 - r e c o v e r " ( builtins . readFile " ${ jh71xx-tools } / j h 7 1 0 0 - r e c o v e r . c " ) ;
} ;
images = {
2022-07-09 05:24:16 +02:00
visionfive-cross = self . nixosConfigurations . visionfive-cross . config . system . build . sdImage ;
visionfive-native = self . nixosConfigurations . visionfive-native . config . system . build . sdImage ;
2023-02-16 12:49:58 +01:00
visionfive2-cross = self . nixosConfigurations . visionfive2-cross . config . system . build . sdImage ;
visionfive2-native = self . nixosConfigurations . visionfive2-native . config . system . build . sdImage ;
2022-06-25 17:37:18 +02:00
} ;
2023-02-16 12:49:58 +01:00
nixosModules = {
visionfive2-sd-image = importApply ./visionfive2/sd-image.nix { inherit inputs importApply ; } ;
visionfive2-kernel = importApply ./visionfive2/kernel/nixos-module.nix { inherit inputs importApply ; } ;
} ;
nixosConfigurations =
let
visionfive2-example-modules = [
./base.nix
./configuration.nix
self . nixosModules . visionfive2-sd-image
] ;
in
{
2022-07-09 05:24:16 +02:00
visionfive-cross = nixpkgs . lib . nixosSystem {
system = " ${ system } " ;
2022-06-25 17:37:18 +02:00
modules = modules ++ [
{
nixpkgs . crossSystem = {
system = " r i s c v 6 4 - l i n u x " ;
} ;
}
] ;
} ;
visionfive-native = nixpkgs . lib . nixosSystem {
system = " r i s c v 6 4 - l i n u x " ;
modules = modules ;
} ;
2023-02-16 12:49:58 +01:00
visionfive2-cross = nixpkgs . lib . nixosSystem {
system = " ${ system } " ;
modules = visionfive2-example-modules ++ [
{
nixpkgs . crossSystem = {
system = " r i s c v 6 4 - l i n u x " ;
} ;
}
] ;
} ;
visionfive2-native = nixpkgs . lib . nixosSystem {
system = " r i s c v 6 4 - l i n u x " ;
modules = visionfive2-example-modules ;
} ;
2022-06-25 17:37:18 +02:00
} ;
} ;
}