-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
518 lines (425 loc) · 17.9 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
flake-utils.url = "github:numtide/flake-utils";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, treefmt-nix, ... } @ inputs: flake-utils.lib.eachSystem [ "x86_64-linux" ]
(system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
#
### Custom cross-compilation Environments
#
pkgsCross = nixpkgs.lib.attrsets.genAttrs [
"aarch64-unknown-linux-gnu"
"aarch64-unknown-none-elf"
"armv7l-unknown-linux-gnueabihf"
"armv7l-unknown-none-eabihf"
"i686-unknown-none-elf"
"microblazeel-none-elf"
"riscv32-unknown-none-elf"
"riscv64-unknown-linux-gnu"
"riscv64-unknown-none-elf"
"x86_64-unknown-none-elf"
]
(config: import nixpkgs {
inherit system;
crossSystem = { inherit config; };
overlays = [ self.overlays.default ];
});
in
{
packages = {
#
### Re-export toolchains to cause proper caching
#
toolchain-aarch64-elf = pkgsCross.aarch64-unknown-none-elf.stdenvNoLibs;
toolchain-aarch64-linux = pkgsCross.aarch64-unknown-linux-gnu.stdenvNoLibs;
toolchain-armv7l-eabihf = pkgsCross.armv7l-unknown-none-eabihf.stdenvNoLibs;
toolchain-armv7l-linux = pkgsCross.armv7l-unknown-linux-gnueabihf.stdenvNoLibs;
toolchain-i686-elf = pkgsCross.i686-unknown-none-elf.stdenvNoLibs;
toolchain-riscv32-elf = pkgsCross.riscv32-unknown-none-elf.stdenvNoLibs;
toolchain-riscv64-elf = pkgsCross.riscv64-unknown-none-elf.stdenvNoLibs;
toolchain-riscv64-linux = pkgsCross.riscv64-unknown-linux-gnu.stdenvNoLibs;
toolchain-x86_64-elf = pkgsCross.x86_64-unknown-none-elf.stdenvNoLibs;
#
### seL4 related tools and dependencies
#
capDL-tool = pkgs.capDL-tool;
# python dependencies for seL4
# these are not actually part of the nixpkgs, but provided over the default overlay of
# this flake
guardonce = pkgs.python3Packages.guardonce;
pyfdt = pkgs.python3Packages.pyfdt;
concurrencytest = pkgs.python3Packages.concurrencytest;
seL4-deps = pkgs.python3Packages.seL4-deps;
camkes-deps = pkgs.python3Packages.camkes-deps;
#
### microkit(-sdk)
#
microkit-sdk = pkgs.microkit-sdk;
#
### Linux
#
linux-aarch64 = pkgsCross.aarch64-unknown-linux-gnu.callPackage pkgs/linux-vm.nix {
kernel = pkgsCross.aarch64-unknown-linux-gnu.linuxPackages_6_1.kernel.override {
autoModules = false;
kernelPreferBuiltin = true;
enableCommonConfig = false; # only use our extraStructuredConfig
#extraStructuredConfig = with lib.kernel; {
# DEBUG_KERNEL = yes;
# FRAME_POINTER = yes;
# KGDB = yes;
# KGDB_SERIAL_CONSOLE = yes;
# DEBUG_INFO = yes;
#};
#ignoreConfigErrors = true;
};
# Use the following to build a custom kernel with the .config generated by
#
# nix develop .\#linux-aarch64.menuconfigShell
#kernel = pkgsCross.aarch64-unknown-linux-gnu.linuxManualConfig {
# inherit (aarch64-elf.linuxPackages.kernel) version src;
# configfile = ./.config;
#};
};
#
### seL4 verified kernel flavours
#
seL4-kernel-aarch64 = pkgsCross.aarch64-unknown-none-elf.callPackage pkgs/seL4-kernel.nix {
verifiedConfig = "AARCH64_verified";
};
seL4-kernel-arm-hyp-exynos5 = pkgsCross.armv7l-unknown-none-eabihf.callPackage pkgs/seL4-kernel.nix {
verifiedConfig = "ARM_HYP_exynos5_verified";
};
seL4-kernel-arm-hyp = pkgsCross.armv7l-unknown-none-eabihf.callPackage pkgs/seL4-kernel.nix {
verifiedConfig = "ARM_HYP_verified";
};
seL4-kernel-arm-mcs = pkgsCross.armv7l-unknown-none-eabihf.callPackage pkgs/seL4-kernel.nix {
verifiedConfig = "ARM_MCS_verified";
};
seL4-kernel-arm-imx8mm = pkgsCross.armv7l-unknown-none-eabihf.callPackage pkgs/seL4-kernel.nix {
verifiedConfig = "ARM_imx8mm_verified";
};
seL4-kernel-arm = pkgsCross.armv7l-unknown-none-eabihf.callPackage pkgs/seL4-kernel.nix {
verifiedConfig = "ARM_verified";
};
seL4-kernel-riscv64-mcs = pkgsCross.riscv64-unknown-none-elf.callPackage pkgs/seL4-kernel.nix {
verifiedConfig = "RISCV64_MCS_verified";
};
seL4-kernel-riscv64-elf = pkgsCross.riscv64-unknown-none-elf.callPackage pkgs/seL4-kernel.nix {
verifiedConfig = "RISCV64_verified";
};
seL4-kernel-x64 = pkgsCross.x86_64-unknown-none-elf.callPackage pkgs/seL4-kernel.nix {
verifiedConfig = "X64_verified";
};
#
### seL4 test suite for various platforms
#
seL4-test-aarch64-imx8mq-evk = pkgsCross.aarch64-unknown-none-elf.callPackage pkgs/seL4-test.nix
{ extraCmakeFlags = [ "-DPLATFORM=imx8mq-evk" ]; };
seL4-test-aarch64-rpi4-1GB = pkgsCross.aarch64-unknown-none-elf.callPackage pkgs/seL4-test.nix
{
extraCmakeFlags = [
"-DPLATFORM=rpi4"
"-DRPI4_MEMORY=1024" # one of 1024 2048 4096 8192
];
};
seL4-test-aarch64-rpi4-2GB = pkgsCross.aarch64-unknown-none-elf.callPackage pkgs/seL4-test.nix
{
extraCmakeFlags = [
"-DPLATFORM=rpi4"
"-DRPI4_MEMORY=2048" # one of 1024 2048 4096 8192
];
};
seL4-test-aarch64-rpi4-4GB = pkgsCross.aarch64-unknown-none-elf.callPackage pkgs/seL4-test.nix
{
extraCmakeFlags = [
"-DPLATFORM=rpi4"
"-DRPI4_MEMORY=4096" # one of 1024 2048 4096 8192
];
};
seL4-test-aarch64-rpi4-8GB = pkgsCross.aarch64-unknown-none-elf.callPackage pkgs/seL4-test.nix
{
extraCmakeFlags = [
"-DPLATFORM=rpi4"
"-DRPI4_MEMORY=8192" # one of 1024 2048 4096 8192
];
};
seL4-test-aarch64-zcu102 = pkgsCross.aarch64-unknown-none-elf.callPackage pkgs/seL4-test.nix
{ extraCmakeFlags = [ "-DPLATFORM=zcu102" ]; };
seL4-test-armv7l-rpi3 = pkgsCross.armv7l-unknown-none-eabihf.callPackage pkgs/seL4-test.nix
{ extraCmakeFlags = [ "-DPLATFORM=rpi3" ]; };
seL4-test-armv7l-zynq7000 = pkgsCross.armv7l-unknown-none-eabihf.callPackage pkgs/seL4-test.nix
{ extraCmakeFlags = [ "-DPLATFORM=zynq7000" ]; };
seL4-test-armv7l-zynq7000-simulate = pkgsCross.armv7l-unknown-none-eabihf.callPackage pkgs/seL4-test.nix
{
extraCmakeFlags = [
"-DPLATFORM=zynq7000"
"-DSIMULATION=1"
];
};
# seL4-test-riscv32-spike = (import nixpkgs {
# inherit system;
# crossSystem.config = "riscv32-unknown-linux-gnu";
# overlays = [ self.overlays.default ];
# }).callPackage pkgs/seL4-test.nix
# { extraCmakeFlags = [ "-DPLATFORM=spike" ]; };
# seL4-test-riscv32-spike-simulate = (import nixpkgs {
# inherit system;
# crossSystem.config = "riscv32-unknown-linux-gnu";
# overlays = [ self.overlays.default ];
# }).callPackage pkgs/seL4-test.nix
# {
# extraCmakeFlags = [
# "-DPLATFORM=spike"
# "-DSIMULATION=1"
# ];
# };
# seL4-test-riscv64-spike = (import nixpkgs {
# inherit system;
# crossSystem.config = "riscv64-unknown-linux-musl";
# overlays = [ self.overlays.default ];
# }).callPackage pkgs/seL4-test.nix
# { extraCmakeFlags = [ "-DPLATFORM=spike" ]; };
# seL4-test-riscv64-spike-simulate = (import nixpkgs {
# inherit system;
# crossSystem.config = "riscv64-unknown-linux-musl";
# overlays = [ self.overlays.default ];
# }).callPackage pkgs/seL4-test.nix
# {
# extraCmakeFlags = [
# "-DPLATFORM=spike"
# "-DSIMULATION=1"
# ];
# };
seL4-test-i686-ia32 = pkgsCross.i686-unknown-none-elf.callPackage pkgs/seL4-test.nix
{ extraCmakeFlags = [ "-DPLATFORM=ia32" ]; };
seL4-test-i686-ia32-simulate = pkgsCross.i686-unknown-none-elf.callPackage pkgs/seL4-test.nix
{
extraCmakeFlags = [
"-DPLATFORM=ia32"
"-DSIMULATION=TRUE"
];
};
seL4-test-x86_64-x86_64 = pkgsCross.x86_64-unknown-none-elf.callPackage pkgs/seL4-test.nix
{ extraCmakeFlags = [ "-DPLATFORM=x86_64" ]; };
seL4-test-x86_64-x86_64-simulate = pkgsCross.x86_64-unknown-none-elf.callPackage pkgs/seL4-test.nix
{
extraCmakeFlags = [
"-DPLATFORM=x86_64"
"-DSIMULATION=TRUE"
];
};
#
### seL4 CAmkES VM Examples
#
seL4-camkes-vm-examples-aarch64-tx1 = pkgsCross.aarch64-unknown-none-elf.callPackage pkgs/seL4-camkes-vm-examples.nix {
extraCmakeFlags = [
"-DPLATFORM=tx1"
"-DCAMKES_VM_APP=vm_minimal"
];
};
seL4-camkes-vm-examples-aarch64-tx2 = pkgsCross.aarch64-unknown-none-elf.callPackage pkgs/seL4-camkes-vm-examples.nix {
extraCmakeFlags = [
"-DPLATFORM=tx2"
"-DCAMKES_VM_APP=vm_minimal"
];
};
seL4-camkes-vm-examples-aarch64-qemu-arm-virt = pkgsCross.aarch64-unknown-none-elf.callPackage pkgs/seL4-camkes-vm-examples.nix {
extraCmakeFlags = [
"-DPLATFORM=qemu-arm-virt"
"-DCAMKES_VM_APP=vm_minimal"
];
};
seL4-camkes-vm-examples-aarch64-zcu102 = pkgsCross.aarch64-unknown-none-elf.callPackage pkgs/seL4-camkes-vm-examples.nix {
extraCmakeFlags = [
"-DPLATFORM=zcu102"
"-DCAMKES_VM_APP=vm_minimal"
];
};
seL4-camkes-vm-examples-armv7l-exynos5422 = pkgsCross.armv7l-unknown-none-eabihf.callPackage pkgs/seL4-camkes-vm-examples.nix {
extraCmakeFlags = [
"-DPLATFORM=exynos5422"
"-DCAMKES_VM_APP=vm_minimal"
];
};
#
### Arm Trusted Firmware
#
atf-aarch64-zcu102 = pkgsCross.aarch64-unknown-linux-gnu.buildArmTrustedFirmware rec {
platform = "zynqmp";
extraMeta.platforms = [ "aarch64-linux" ];
extraMakeFlags = [ "RESET_TO_BL31=1" ];
filesToInstall = [ "build/${platform}/release/bl31.bin" ];
version = "xilinx-v2023.2";
src = pkgs.fetchFromGitHub {
owner = "Xilinx";
repo = "arm-trusted-firmware";
rev = version;
hash = "sha256-RvdBsskiSgquwnDf0g0dU8P6v4QxK4OqhtkF5K7lfyI=";
};
};
#
### Firmware
#
opensbi-riscv64-cva6 = (pkgsCross.riscv64-unknown-linux-gnu.opensbi.overrideAttrs
(_: {
src = pkgs.fetchFromGitHub {
owner = "riscv-software-src";
repo = "opensbi";
rev = "be245acfffa297b5ed4e0c7bb473a6bd55231bf8";
hash = "sha256-EtG5MgeeAo7Lw0XkvcDonpIhSmb/1Y4GnA2/DB8yCJg=";
};
env.NIX_CFLAGS_COMPILE = "-march=rv64imafdc_zicsr_zifencei";
}));
pmufw-mblaze-zcu102 = pkgsCross.microblazeel-none-elf.callPackage ./pkgs/xilinx-pmufw.nix { };
#
### UBoot with specific patches
#
uboot-aarch64-rpi4 = pkgsCross.aarch64-unknown-linux-gnu.ubootRaspberryPi4_64bit;
# For more information on compiling the Xilinx U-Boot fork see
# https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18841973/Build+U-Boot
uboot-aarch64-zcu102 = pkgsCross.aarch64-unknown-linux-gnu.buildUBoot rec {
extraMeta.platforms = [ "aarch64-linux" ];
defconfig = "xilinx_zynqmp_virt_defconfig";
# The `DEVICE_TREE` environment variable must only be propagated __after__ the initial
# `make xilinx_zynqmp_virt_defconfig` call.
preInstall = ''
export DEVICE_TREE="zynqmp-zcu102-rev1.0"
'';
filesToInstall = [ "spl/boot.bin" "u-boot.elf" "u-boot.img" ];
version = "xilinx-v2023.2";
dontPatch = true; # avoid unapplicable raspberrypi patches
# u-boot-xlnx ignores the CONFIG_ARMV8_SWITCH_TO_EL1 macro, and always unconditionally
# boots into EL1 when doing `go`. This little patch changes that behavior to stay in
# EL2, so that seL4 can happily boot even in hypervisor mode.
prePatch = ''
substituteInPlace board/xilinx/zynqmp/zynqmp.c \
--replace armv8_switch_to_el1 armv8_switch_to_el2
'';
src = pkgs.fetchFromGitHub {
owner = "Xilinx";
repo = "u-boot-xlnx";
rev = version;
hash = "sha256-tSOw7+Pe3/JYIgrPYB6exPzfGrRTuolxXXTux80w/X8=";
};
};
# based of https://github.com/Xilinx/u-boot-xlnx/blob/master/doc/board/xilinx/zynq.rst
uboot-armv7l-zynq-zc702 = pkgsCross.armv7l-unknown-linux-gnueabihf.buildUBoot rec {
extraMeta.platforms = [ "armv7l-linux" ];
defconfig = "xilinx_zynq_virt_defconfig";
env.DEVICE_TREE = "zynq-zc702";
filesToInstall = [ "spl/boot.bin" "u-boot.elf" "u-boot.img" ];
version = "xilinx-v2023.2";
dontPatch = true; # avoid unapplicable raspberrypi patches
src = pkgs.fetchFromGitHub {
owner = "Xilinx";
repo = "u-boot-xlnx";
rev = version;
hash = "sha256-tSOw7+Pe3/JYIgrPYB6exPzfGrRTuolxXXTux80w/X8=";
};
};
### SD Card
#
sd-aarch64-rpi4 =
let
inherit (pkgs) lib;
# Reference: https://www.raspberrypi.com/documentation/computers/config_txt.html
# Default: https://github.com/RPi-Distro/pi-gen/blob/master/stage1/00-boot-files/files/config.txt
config = {
arm_boost = 1;
arm_64bit = 1;
kernel = "u-boot.bin";
dtoverlay = "disable-bt";
enable_uart = 1;
uart_2ndstage = 1;
};
config_txt = pkgs.writeText "config.txt" (lib.generators.toKeyValue { } config);
in
pkgs.runCommand "assemble-sd" { } ''
mkdir -- $out
# copy firmware stuff
pushd ${pkgs.raspberrypifw}/share/raspberrypi/boot
cp --recursive -- bootcode.bin start4.elf bcm2711-rpi-4-b.dtb overlays $out/
popd
# copy u-boot
cp ${self.packages.${system}.uboot-aarch64-rpi4}/u-boot.bin $out/
# config.txt
cp ${config_txt} $out/config.txt
'';
};
#
### DevShells
#
devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
# seL4
ccache
cmake
cmakeCurses
curl
doxygen
dtc
git
gitRepo
libxml2
ncurses
ninja
protobuf
qemu_full
ubootTools
gcc-arm-embedded-8
# CAmkES
stack
haskell.compiler.ghc902
# both
python3Packages.camkes-deps # includes seL4-deps
];
};
devShells.microkit = pkgs.mkShell.override { stdenv = pkgs.stdenvNoCC; } {
nativeBuildInputs = (with pkgs; [
bear
gnumake
qemu
microkit-sdk
]) ++ [
pkgs.pkgsCross.aarch64-embedded.stdenv.cc.bintools.bintools
pkgs.pkgsCross.aarch64-embedded.stdenv.cc.cc
pkgs.pkgsCross.riscv64-embedded.stdenv.cc.bintools.bintools
pkgs.pkgsCross.riscv64-embedded.stdenv.cc.cc
];
# mitigates the following errors:
# undefined reference to `__stack_chk_guard'
# undefined reference to `__stack_chk_fail'
hardeningDisable = [ "all" ];
env.MICROKIT_SDK = pkgs.microkit-sdk;
};
#
### Checks & CI
#
# for `nix fmt`
formatter = treefmtEval.config.build.wrapper;
# for `nix flake check`
checks.formatting = treefmtEval.config.build.check self;
# instructions for the CI server
hydraJobs =
let
inherit (nixpkgs.lib.attrsets) filterAttrs;
checks = self.checks.${system};
packages = self.packages.${system};
in
(filterAttrs (n: v: n != "default") packages) // checks;
}) // {
# declare overlay with added deps, i. e. the python packages not available in official nixpkgs
overlays.default = import ./overlay.nix;
};
}