-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdefault.nix
185 lines (179 loc) · 6.13 KB
/
default.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
{ risc ? false, qemu ? false }:
let
sources = import ./nix/sources.nix;
pkgs = import (builtins.fetchTarball {
url = "https://github.com/input-output-hk/nixpkgs/archive/0ee0489d42e.tar.gz";
sha256 = "1ldlg2nm8fcxszc29rngw2893z8ci4bpa3m0i6kfwjadfrcrfa42";
}) { system = "x86_64-linux"; };
lib = pkgs.lib;
rpi-tools = pkgs.fetchFromGitHub {
owner = "raspberrypi";
repo = "tools";
rev = "439b6198a9b340de5998dd14a26a0d9d38a6bcac";
hash = "sha256-rcrVDSi5wArStnCm5kUtOzlw64WVDl7fV94/aQu77Qg=";
};
overlay = self: super: {
littlekernel = self.stdenv.mkDerivation {
name = "littlekernel";
src = lib.cleanSource ./.;
#nativeBuildInputs = [ x86_64.uart-manager ];
nativeBuildInputs = [ x86_64.python x86_64.imagemagick x86_64.qemu ];
hardeningDisable = [ "format" ];
};
uart-manager = self.stdenv.mkDerivation {
name = "uart-manager";
src = sources.rpi-open-firmware + "/uart-manager";
};
};
vc4 = pkgs.pkgsCross.vc4.extend overlay;
x86_64 = pkgs.extend overlay;
arm7 = pkgs.pkgsCross.arm-embedded.extend overlay;
in lib.fix (self: {
# https://leiradel.github.io/2019/01/20/Raspberry-Pi-Stubs.html
# armstub.bin, for the bcm2835, armv6 mode
# armstub7.bin for the bcm2836, armv7 mode, parks secondary cores waiting for mail from primary core
# armstub8-32.bin for the bcm2837, 32bit armv7 mode, parks secondary cores
# armstub8.bin for the bcm2837, 64bit armv8 mode
# 0xf0 the magic 0x5afe570b
# 0xf4 the stub version
# 0xf8 atags/FDT addr
# 0xfc kernel entry-point
armstubs = pkgs.runCommand "armstubs" {
src = "${rpi-tools}/armstubs";
buildInputs = with pkgs; [
pkgsCross.arm-embedded.stdenv.cc
pkgsCross.aarch64-embedded.stdenv.cc
];
CC7 = "arm-none-eabi-gcc -march=armv7-a";
LD7 = "arm-none-eabi-ld";
OBJCOPY7 = "arm-none-eabi-objcopy";
CC8 = "aarch64-none-elf-gcc";
LD8 = "aarch64-none-elf-ld";
OBJCOPY8 = "aarch64-none-elf-objcopy";
} ''
echo $buildInputs
unpackPhase
cd $sourceRoot
make
mkdir $out
cp *.bin $out/
'';
shell = pkgs.stdenv.mkDerivation {
name = "shell";
buildInputs = with pkgs; [
pkgsCross.arm-embedded.stdenv.cc
libpng
nodejs
#pkgsCross.i686-embedded.stdenv.cc
pkgsCross.vc4.stdenv.cc
pkgsCross.aarch64-embedded.stdenv.cc
python
python3
imagemagick
pkgsi686Linux.lua
#texlive.combined.scheme-full
sox
] ++ lib.optionals risc [
pkgsCross.riscv32-embedded.stdenv.cc
pkgsCross.riscv64-embedded.stdenv.cc
] ++ lib.optionals qemu [
qemu
];
ARCH_x86_TOOLCHAIN_PREFIX = "i686-elf-";
ARCH_x86_TOOLCHAIN_INCLUDED = true;
ARCH_arm64_TOOLCHAIN_PREFIX = "aarch64-none-elf-";
ARMSTUBS = self.armstubs;
shellHook = ''
unset CC OBJDUMP LD OBJCOPY
'';
};
roots = pkgs.writeText "gc-roots" ''
${pkgs.pkgsCross.vc4.stdenv.cc}"
'';
arm7 = {
inherit (arm7) littlekernel;
};
arm = {
rpi1-test = arm7.callPackage ./lk.nix { project = "rpi1-test"; };
rpi2-test = arm7.callPackage ./lk.nix { project = "rpi2-test"; };
rpi3-test = pkgs.pkgsCross.aarch64-embedded.callPackage ./lk.nix { project = "rpi3-test"; };
};
vc4 = {
shell = vc4.littlekernel;
rpi3.bootcode = vc4.callPackage ./lk.nix { project = "rpi3-bootcode"; };
rpi3.start = vc4.callPackage ./lk.nix { project = "rpi3-start"; };
rpi4.recovery = vc4.callPackage ./lk.nix { project = "rpi4-recovery"; };
rpi4.start4 = vc4.callPackage ./lk.nix { project = "rpi4-start4"; };
stage1-bad-apple = vc4.callPackage ./lk.nix { project = "stage1-bad-apple"; };
vc4.stage1 = vc4.callPackage ./lk.nix { project = "vc4-stage1"; };
vc4.stage2 = vc4.callPackage ./lk.nix {
project = "vc4-stage2";
preBuild = ''
rm -rf build-rpi{1,2,3}-test
mkdir build-rpi{1,2,3}-test
ln -sv ${self.arm.rpi1-test}/lk.bin build-rpi1-test/lk.bin
ln -sv ${self.arm.rpi2-test}/lk.bin build-rpi2-test/lk.bin
ln -sv ${self.arm.rpi3-test}/lk.bin build-rpi3-test/lk.bin
mkdir $out
ln -sv ${self.arm.rpi1-test} $out/rpi1-test
ln -sv ${self.arm.rpi2-test} $out/rpi2-test
ln -sv ${self.arm.rpi3-test} $out/rpi3-test
'';
extraAttrs = {
ARMSTUBS = self.armstubs;
};
};
vc4.start = vc4.callPackage ./lk.nix {
project = "vc4-start";
preBuild = ''
rm -rf build-rpi2-test build-rpi3-test
mkdir build-rpi2-test build-rpi3-test -pv
ln -sv ${self.arm.rpi2-test}/lk.bin build-rpi2-test/lk.bin
ln -sv ${self.arm.rpi3-test}/lk.bin build-rpi3-test/lk.bin
'';
};
vc4.bootcode-fast-ntsc = vc4.callPackage ./lk.nix { project = "bootcode-fast-ntsc"; };
};
x86_64 = {
inherit (x86_64) uart-manager;
};
testcycle = pkgs.writeShellScript "testcycle" ''
set -e
scp ${self.vc4.rpi3.bootcode}/lk.bin [email protected]:/tftproot/open-firmware/bootcode.bin
exec ${x86_64.uart-manager}/bin/uart-manager
'';
disk_image = lib.overrideDerivation (pkgs.vmTools.runInLinuxVM (pkgs.runCommand "disk-image" {
buildInputs = with pkgs; [ utillinux dosfstools e2fsprogs mtools libfaketime ];
preVM = ''
mkdir -p $out
diskImage=$out/disk-image.img
truncate $diskImage -s 64m
'';
postVM = ''
mkdir -pv $out/nix-support/
echo "file sd-image $out/disk-image.img" > $out/nix-support/hydra-build-products
'';
} ''
sfdisk /dev/vda <<EOF
label: dos
label-id: 0x245a585c
unit: sectors
1: size=${toString (32 * 2048)}, type=c
2: type=83
EOF
mkdir -p ext-dir/{etc,boot/firmware/}
cp ${self.vc4.vc4.stage2}/lk.elf ext-dir/boot/lk.elf -v
cat <<EOF > ext-dir/etc/fstab
LABEL=root / defaults 0 0
LABEL=firmware /boot/firmware defaults 0 0
EOF
faketime "1970-01-01 00:00:00" mkfs.fat /dev/vda1 -i 0x2178694e -n firmware
mkfs.ext4 /dev/vda2 -d ext-dir -L root
mkdir fat-dir
cp -v ${self.vc4.vc4.stage1}/lk.bin fat-dir/bootcode.bin
cd fat-dir
faketime "1970-01-01 00:00:00" mcopy -psvm -i /dev/vda1 * ::
'')) (old: {
requiredSystemFeatures = [];
});
})