1# Note: lib/systems/default.nix takes care of producing valid,
2# fully-formed "platform" values (e.g. hostPlatform, buildPlatform,
3# targetPlatform, etc) containing at least the minimal set of attrs
4# required (see types.parsedPlatform in lib/systems/parse.nix). This
5# file takes an already-valid platform and further elaborates it with
6# optional fields; currently these are: linux-kernel, gcc, and rustc.
7
8{ lib }:
9rec {
10 pc = {
11 linux-kernel = {
12 name = "pc";
13
14 baseConfig = "defconfig";
15 # Build whatever possible as a module, if not stated in the extra config.
16 autoModules = true;
17 target = "bzImage";
18 };
19 };
20
21 pc_simplekernel = lib.recursiveUpdate pc {
22 linux-kernel.autoModules = false;
23 };
24
25 powernv = {
26 linux-kernel = {
27 name = "PowerNV";
28
29 baseConfig = "powernv_defconfig";
30 target = "vmlinux";
31 autoModules = true;
32 # avoid driver/FS trouble arising from unusual page size
33 extraConfig = ''
34 PPC_64K_PAGES n
35 PPC_4K_PAGES y
36 IPV6 y
37
38 ATA_BMDMA y
39 ATA_SFF y
40 VIRTIO_MENU y
41 '';
42 };
43 };
44
45 ##
46 ## ARM
47 ##
48
49 pogoplug4 = {
50 linux-kernel = {
51 name = "pogoplug4";
52
53 baseConfig = "multi_v5_defconfig";
54 autoModules = false;
55 extraConfig = ''
56 # Ubi for the mtd
57 MTD_UBI y
58 UBIFS_FS y
59 UBIFS_FS_XATTR y
60 UBIFS_FS_ADVANCED_COMPR y
61 UBIFS_FS_LZO y
62 UBIFS_FS_ZLIB y
63 UBIFS_FS_DEBUG n
64 '';
65 makeFlags = [ "LOADADDR=0x8000" ];
66 target = "uImage";
67 # TODO reenable once manual-config's config actually builds a .dtb and this is checked to be working
68 #DTB = true;
69 };
70 gcc = {
71 arch = "armv5te";
72 };
73 };
74
75 sheevaplug = {
76 linux-kernel = {
77 name = "sheevaplug";
78
79 baseConfig = "multi_v5_defconfig";
80 autoModules = false;
81 extraConfig = ''
82 BLK_DEV_RAM y
83 BLK_DEV_INITRD y
84 BLK_DEV_CRYPTOLOOP m
85 BLK_DEV_DM m
86 DM_CRYPT m
87 MD y
88 REISERFS_FS m
89 BTRFS_FS m
90 XFS_FS m
91 JFS_FS m
92 EXT4_FS m
93 USB_STORAGE_CYPRESS_ATACB m
94
95 # mv cesa requires this sw fallback, for mv-sha1
96 CRYPTO_SHA1 y
97 # Fast crypto
98 CRYPTO_TWOFISH y
99 CRYPTO_TWOFISH_COMMON y
100 CRYPTO_BLOWFISH y
101 CRYPTO_BLOWFISH_COMMON y
102
103 IP_PNP y
104 IP_PNP_DHCP y
105 NFS_FS y
106 ROOT_NFS y
107 TUN m
108 NFS_V4 y
109 NFS_V4_1 y
110 NFS_FSCACHE y
111 NFSD m
112 NFSD_V2_ACL y
113 NFSD_V3 y
114 NFSD_V3_ACL y
115 NFSD_V4 y
116 NETFILTER y
117 IP_NF_IPTABLES y
118 IP_NF_FILTER y
119 IP_NF_MATCH_ADDRTYPE y
120 IP_NF_TARGET_LOG y
121 IP_NF_MANGLE y
122 IPV6 m
123 VLAN_8021Q m
124
125 CIFS y
126 CIFS_XATTR y
127 CIFS_POSIX y
128 CIFS_FSCACHE y
129 CIFS_ACL y
130
131 WATCHDOG y
132 WATCHDOG_CORE y
133 ORION_WATCHDOG m
134
135 ZRAM m
136 NETCONSOLE m
137
138 # Disable OABI to have seccomp_filter (required for systemd)
139 # https://github.com/raspberrypi/firmware/issues/651
140 OABI_COMPAT n
141
142 # Fail to build
143 DRM n
144 SCSI_ADVANSYS n
145 USB_ISP1362_HCD n
146 SND_SOC n
147 SND_ALI5451 n
148 FB_SAVAGE n
149 SCSI_NSP32 n
150 ATA_SFF n
151 SUNGEM n
152 IRDA n
153 ATM_HE n
154 SCSI_ACARD n
155 BLK_DEV_CMD640_ENHANCED n
156
157 FUSE_FS m
158
159 # systemd uses cgroups
160 CGROUPS y
161
162 # Latencytop
163 LATENCYTOP y
164
165 # Ubi for the mtd
166 MTD_UBI y
167 UBIFS_FS y
168 UBIFS_FS_XATTR y
169 UBIFS_FS_ADVANCED_COMPR y
170 UBIFS_FS_LZO y
171 UBIFS_FS_ZLIB y
172 UBIFS_FS_DEBUG n
173
174 # Kdb, for kernel troubles
175 KGDB y
176 KGDB_SERIAL_CONSOLE y
177 KGDB_KDB y
178 '';
179 makeFlags = [ "LOADADDR=0x0200000" ];
180 target = "uImage";
181 DTB = true; # Beyond 3.10
182 };
183 gcc = {
184 arch = "armv5te";
185 };
186 };
187
188 raspberrypi = {
189 linux-kernel = {
190 name = "raspberrypi";
191
192 baseConfig = "bcm2835_defconfig";
193 DTB = true;
194 autoModules = true;
195 preferBuiltin = true;
196 extraConfig = ''
197 # Disable OABI to have seccomp_filter (required for systemd)
198 # https://github.com/raspberrypi/firmware/issues/651
199 OABI_COMPAT n
200 '';
201 target = "zImage";
202 };
203 gcc = {
204 arch = "armv6";
205 fpu = "vfp";
206 };
207 };
208
209 # Legacy attribute, for compatibility with existing configs only.
210 raspberrypi2 = armv7l-hf-multiplatform;
211
212 zero-gravitas = {
213 linux-kernel = {
214 name = "zero-gravitas";
215
216 baseConfig = "zero-gravitas_defconfig";
217 # Target verified by checking /boot on reMarkable 1 device
218 target = "zImage";
219 autoModules = false;
220 DTB = true;
221 };
222 gcc = {
223 fpu = "neon";
224 cpu = "cortex-a9";
225 };
226 };
227
228 zero-sugar = {
229 linux-kernel = {
230 name = "zero-sugar";
231
232 baseConfig = "zero-sugar_defconfig";
233 DTB = true;
234 autoModules = false;
235 preferBuiltin = true;
236 target = "zImage";
237 };
238 gcc = {
239 cpu = "cortex-a7";
240 fpu = "neon-vfpv4";
241 float-abi = "hard";
242 };
243 };
244
245 utilite = {
246 linux-kernel = {
247 name = "utilite";
248 maseConfig = "multi_v7_defconfig";
249 autoModules = false;
250 extraConfig = ''
251 # Ubi for the mtd
252 MTD_UBI y
253 UBIFS_FS y
254 UBIFS_FS_XATTR y
255 UBIFS_FS_ADVANCED_COMPR y
256 UBIFS_FS_LZO y
257 UBIFS_FS_ZLIB y
258 UBIFS_FS_DEBUG n
259 '';
260 makeFlags = [ "LOADADDR=0x10800000" ];
261 target = "uImage";
262 DTB = true;
263 };
264 gcc = {
265 cpu = "cortex-a9";
266 fpu = "neon";
267 };
268 };
269
270 guruplug = lib.recursiveUpdate sheevaplug {
271 # Define `CONFIG_MACH_GURUPLUG' (see
272 # <http://kerneltrap.org/mailarchive/git-commits-head/2010/5/19/33618>)
273 # and other GuruPlug-specific things. Requires the `guruplug-defconfig'
274 # patch.
275 linux-kernel.baseConfig = "guruplug_defconfig";
276 };
277
278 beaglebone = lib.recursiveUpdate armv7l-hf-multiplatform {
279 linux-kernel = {
280 name = "beaglebone";
281 baseConfig = "bb.org_defconfig";
282 autoModules = false;
283 extraConfig = ""; # TBD kernel config
284 target = "zImage";
285 };
286 };
287
288 # https://developer.android.com/ndk/guides/abis#v7a
289 armv7a-android = {
290 linux-kernel.name = "armeabi-v7a";
291 gcc = {
292 arch = "armv7-a";
293 float-abi = "softfp";
294 fpu = "vfpv3-d16";
295 };
296 };
297
298 armv7l-hf-multiplatform = {
299 linux-kernel = {
300 name = "armv7l-hf-multiplatform";
301 Major = "2.6"; # Using "2.6" enables 2.6 kernel syscalls in glibc.
302 baseConfig = "multi_v7_defconfig";
303 DTB = true;
304 autoModules = true;
305 preferBuiltin = true;
306 target = "zImage";
307 extraConfig = ''
308 # Serial port for Raspberry Pi 3. Wasn't included in ARMv7 defconfig
309 # until 4.17.
310 SERIAL_8250_BCM2835AUX y
311 SERIAL_8250_EXTENDED y
312 SERIAL_8250_SHARE_IRQ y
313
314 # Hangs ODROID-XU4
315 ARM_BIG_LITTLE_CPUIDLE n
316
317 # Disable OABI to have seccomp_filter (required for systemd)
318 # https://github.com/raspberrypi/firmware/issues/651
319 OABI_COMPAT n
320
321 # >=5.12 fails with:
322 # drivers/net/ethernet/micrel/ks8851_common.o: in function `ks8851_probe_common':
323 # ks8851_common.c:(.text+0x179c): undefined reference to `__this_module'
324 # See: https://lore.kernel.org/netdev/20210116164828.40545-1-marex@denx.de/T/
325 KS8851_MLL y
326 '';
327 };
328 gcc = {
329 # Some table about fpu flags:
330 # http://community.arm.com/servlet/JiveServlet/showImage/38-1981-3827/blogentry-103749-004812900+1365712953_thumb.png
331 # Cortex-A5: -mfpu=neon-fp16
332 # Cortex-A7 (rpi2): -mfpu=neon-vfpv4
333 # Cortex-A8 (beaglebone): -mfpu=neon
334 # Cortex-A9: -mfpu=neon-fp16
335 # Cortex-A15: -mfpu=neon-vfpv4
336
337 # More about FPU:
338 # https://wiki.debian.org/ArmHardFloatPort/VfpComparison
339
340 # vfpv3-d16 is what Debian uses and seems to be the best compromise: NEON is not supported in e.g. Scaleway or Tegra 2,
341 # and the above page suggests NEON is only an improvement with hand-written assembly.
342 arch = "armv7-a";
343 fpu = "vfpv3-d16";
344
345 # For Raspberry Pi the 2 the best would be:
346 # cpu = "cortex-a7";
347 # fpu = "neon-vfpv4";
348 };
349 };
350
351 aarch64-multiplatform = {
352 linux-kernel = {
353 name = "aarch64-multiplatform";
354 baseConfig = "defconfig";
355 DTB = true;
356 autoModules = true;
357 preferBuiltin = true;
358 extraConfig = ''
359 # Raspberry Pi 3 stuff. Not needed for s >= 4.10.
360 ARCH_BCM2835 y
361 BCM2835_MBOX y
362 BCM2835_WDT y
363 RASPBERRYPI_FIRMWARE y
364 RASPBERRYPI_POWER y
365 SERIAL_8250_BCM2835AUX y
366 SERIAL_8250_EXTENDED y
367 SERIAL_8250_SHARE_IRQ y
368
369 # Cavium ThunderX stuff.
370 PCI_HOST_THUNDER_ECAM y
371
372 # Nvidia Tegra stuff.
373 PCI_TEGRA y
374
375 # The default (=y) forces us to have the XHCI firmware available in initrd,
376 # which our initrd builder can't currently do easily.
377 USB_XHCI_TEGRA m
378 '';
379 target = "Image";
380 };
381 gcc = {
382 arch = "armv8-a";
383 };
384 };
385
386 apple-m1 = {
387 gcc = {
388 arch = "armv8.3-a+crypto+sha2+aes+crc+fp16+lse+simd+ras+rdm+rcpc";
389 cpu = "apple-a13";
390 };
391 };
392
393 ##
394 ## MIPS
395 ##
396
397 ben_nanonote = {
398 linux-kernel = {
399 name = "ben_nanonote";
400 };
401 gcc = {
402 arch = "mips32";
403 float = "soft";
404 };
405 };
406
407 fuloong2f_n32 = {
408 linux-kernel = {
409 name = "fuloong2f_n32";
410 baseConfig = "lemote2f_defconfig";
411 autoModules = false;
412 extraConfig = ''
413 MIGRATION n
414 COMPACTION n
415
416 # nixos mounts some cgroup
417 CGROUPS y
418
419 BLK_DEV_RAM y
420 BLK_DEV_INITRD y
421 BLK_DEV_CRYPTOLOOP m
422 BLK_DEV_DM m
423 DM_CRYPT m
424 MD y
425 REISERFS_FS m
426 EXT4_FS m
427 USB_STORAGE_CYPRESS_ATACB m
428
429 IP_PNP y
430 IP_PNP_DHCP y
431 IP_PNP_BOOTP y
432 NFS_FS y
433 ROOT_NFS y
434 TUN m
435 NFS_V4 y
436 NFS_V4_1 y
437 NFS_FSCACHE y
438 NFSD m
439 NFSD_V2_ACL y
440 NFSD_V3 y
441 NFSD_V3_ACL y
442 NFSD_V4 y
443
444 # Fail to build
445 DRM n
446 SCSI_ADVANSYS n
447 USB_ISP1362_HCD n
448 SND_SOC n
449 SND_ALI5451 n
450 FB_SAVAGE n
451 SCSI_NSP32 n
452 ATA_SFF n
453 SUNGEM n
454 IRDA n
455 ATM_HE n
456 SCSI_ACARD n
457 BLK_DEV_CMD640_ENHANCED n
458
459 FUSE_FS m
460
461 # Needed for udev >= 150
462 SYSFS_DEPRECATED_V2 n
463
464 VGA_CONSOLE n
465 VT_HW_CONSOLE_BINDING y
466 SERIAL_8250_CONSOLE y
467 FRAMEBUFFER_CONSOLE y
468 EXT2_FS y
469 EXT3_FS y
470 REISERFS_FS y
471 MAGIC_SYSRQ y
472
473 # The kernel doesn't boot at all, with FTRACE
474 FTRACE n
475 '';
476 target = "vmlinux";
477 };
478 gcc = {
479 arch = "loongson2f";
480 float = "hard";
481 abi = "n32";
482 };
483 };
484
485 # can execute on 32bit chip
486 gcc_mips32r2_o32 = { gcc = { arch = "mips32r2"; abi = "32"; }; };
487 gcc_mips32r6_o32 = { gcc = { arch = "mips32r6"; abi = "32"; }; };
488 gcc_mips64r2_n32 = { gcc = { arch = "mips64r2"; abi = "n32"; }; };
489 gcc_mips64r6_n32 = { gcc = { arch = "mips64r6"; abi = "n32"; }; };
490 gcc_mips64r2_64 = { gcc = { arch = "mips64r2"; abi = "64"; }; };
491 gcc_mips64r6_64 = { gcc = { arch = "mips64r6"; abi = "64"; }; };
492
493 # based on:
494 # https://www.mail-archive.com/qemu-discuss@nongnu.org/msg05179.html
495 # https://gmplib.org/~tege/qemu.html#mips64-debian
496 mips64el-qemu-linux-gnuabi64 = {
497 linux-kernel = {
498 name = "mips64el";
499 baseConfig = "64r2el_defconfig";
500 target = "vmlinuz";
501 autoModules = false;
502 DTB = true;
503 # for qemu 9p passthrough filesystem
504 extraConfig = ''
505 MIPS_MALTA y
506 PAGE_SIZE_4KB y
507 CPU_LITTLE_ENDIAN y
508 CPU_MIPS64_R2 y
509 64BIT y
510 CPU_MIPS64_R2 y
511
512 NET_9P y
513 NET_9P_VIRTIO y
514 9P_FS y
515 9P_FS_POSIX_ACL y
516 PCI y
517 VIRTIO_PCI y
518 '';
519 };
520 };
521
522 ##
523 ## Other
524 ##
525
526 riscv-multiplatform = {
527 linux-kernel = {
528 name = "riscv-multiplatform";
529 target = "Image";
530 autoModules = true;
531 baseConfig = "defconfig";
532 DTB = true;
533 extraConfig = ''
534 SERIAL_OF_PLATFORM y
535 '';
536 };
537 };
538
539 # This function takes a minimally-valid "platform" and returns an
540 # attrset containing zero or more additional attrs which should be
541 # included in the platform in order to further elaborate it.
542 select = platform:
543 # x86
544 /**/ if platform.isx86 then pc
545
546 # ARM
547 else if platform.isAarch32 then let
548 version = platform.parsed.cpu.version or null;
549 in if version == null then pc
550 else if lib.versionOlder version "6" then sheevaplug
551 else if lib.versionOlder version "7" then raspberrypi
552 else armv7l-hf-multiplatform
553
554 else if platform.isAarch64 then
555 if platform.isDarwin then apple-m1
556 else aarch64-multiplatform
557
558 else if platform.isRiscV then riscv-multiplatform
559
560 else if platform.parsed.cpu == lib.systems.parse.cpuTypes.mipsel then (import ./examples.nix { inherit lib; }).mipsel-linux-gnu
561
562 else if platform.parsed.cpu == lib.systems.parse.cpuTypes.powerpc64le then powernv
563
564 else { };
565}