-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathflake.nix
189 lines (184 loc) · 7.06 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
{
inputs = {
nixpkgs.url = "github:matthewcroughan/nixpkgs/mc/riscv-testing";
# VisionFive ("v1")
vendor-kernel = {
url = "github:starfive-tech/linux";
flake = false;
};
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;
};
# VisionFive 2
jh7110-kernel = {
# url = "github:starfive-tech/linux/50a831018ed997c9fb3b603574176b221a28aa12"; # JH7110_VisionFive2_devel via VisionFive2 project submodule about two revisions back.
url = "github:starfive-tech/linux/JH7110_VisionFive2_devel";
flake = false;
};
jh7110_recovery_binary = {
url = "https://github.com/starfive-tech/Tools/blob/bc6dc7e33e0c2466db0476b5043f0f77842f98f0/recovery/jh7110-recovery-20221205.bin?raw=true";
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;
};
};
outputs = inputs@{ self, nixpkgs, jh71xx-tools, jh7100_recovery_binary, jh7100_secondBoot, jh7100_ddrinit, vendor-kernel, ... }:
let
inherit (nixpkgs) lib;
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; overlays = [ self.overlay ]; };
modules = [
{ nixpkgs.overlays = [ self.overlay ]; }
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-riscv64-visionfive-installer.nix"
./base.nix
./configuration.nix
];
# 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);
in
{
overlay = final: prev: {
linuxPackages_visionfive = final.linuxPackagesFor ((final.callPackage ./kernel.nix { inherit vendor-kernel; }).override { patches = []; });
};
legacyPackages.${system} =
{
inherit (pkgs.pkgsCross.riscv64.linux) linuxPackages_visionfive;
};
apps.${system} = {
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 "Terminal ready"
send_user "\n### Apply power to the VisionFive Board ###\n"
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
flashScript = pkgs.writeScript "jh7100-recover-visionfive.sh" ''
set -x
${pkgs.lib.getExe self.packages.${system}.jh7100-recover} \
-D $1 \
-r ${jh7100_recovery_binary} \
-b ${jh7100_secondBoot} \
-d ${jh7100_ddrinit}
'';
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"
${flashScript} $1
else
echo "User is not in dialout group, flashing to board with sudo"
sudo ${flashScript} $1
fi
'';
in
{
type = "app";
program = "${program}";
};
} // import ./visionfive2/commands.nix { inherit inputs pkgs; };
packages.${system} = {
jh7100-recover = pkgs.writeCBin "jh7100-recover" (builtins.readFile "${jh71xx-tools}/jh7100-recover.c");
};
images = {
visionfive-cross = self.nixosConfigurations.visionfive-cross.config.system.build.sdImage;
visionfive-native = self.nixosConfigurations.visionfive-native.config.system.build.sdImage;
visionfive2-cross = self.nixosConfigurations.visionfive2-cross.config.system.build.sdImage;
visionfive2-native = self.nixosConfigurations.visionfive2-native.config.system.build.sdImage;
};
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
{
visionfive-cross = nixpkgs.lib.nixosSystem {
system = "${system}";
modules = modules ++ [
{
nixpkgs.crossSystem = {
system = "riscv64-linux";
};
}
];
};
visionfive-native = nixpkgs.lib.nixosSystem {
system = "riscv64-linux";
modules = modules;
};
visionfive2-cross = nixpkgs.lib.nixosSystem {
system = "${system}";
modules = visionfive2-example-modules ++ [
{
nixpkgs.crossSystem = {
system = "riscv64-linux";
};
}
];
};
visionfive2-native = nixpkgs.lib.nixosSystem {
system = "riscv64-linux";
modules = visionfive2-example-modules;
};
};
};
}