1# To build, use:
2# nix-build nixos -I nixos-config=nixos/modules/installer/cd-dvd/sd-image-armv7l-multiplatform.nix -A config.system.build.sdImage
3{ config, lib, pkgs, ... }:
4
5let
6 extlinux-conf-builder =
7 import ../../system/boot/loader/generic-extlinux-compatible/extlinux-conf-builder.nix {
8 inherit pkgs;
9 };
10in
11{
12 imports = [
13 ../../profiles/base.nix
14 ../../profiles/installation-device.nix
15 ./sd-image.nix
16 ];
17
18 assertions = lib.singleton {
19 assertion = pkgs.stdenv.hostPlatform.system == "armv7l-linux"
20 && pkgs.stdenv.hostPlatform.system == pkgs.stdenv.buildPlatform.system;
21 message = "sd-image-armv7l-multiplatform.nix can be only built natively on ARMv7; " +
22 "it cannot be cross compiled";
23 };
24
25 boot.loader.grub.enable = false;
26 boot.loader.generic-extlinux-compatible.enable = true;
27
28 boot.consoleLogLevel = lib.mkDefault 7;
29 boot.kernelPackages = pkgs.linuxPackages_latest;
30 # The serial ports listed here are:
31 # - ttyS0: for Tegra (Jetson TK1)
32 # - ttymxc0: for i.MX6 (Wandboard)
33 # - ttyAMA0: for Allwinner (pcDuino3 Nano) and QEMU's -machine virt
34 # - ttyO0: for OMAP (BeagleBone Black)
35 # - ttySAC2: for Exynos (ODROID-XU3)
36 boot.kernelParams = ["console=ttyS0,115200n8" "console=ttymxc0,115200n8" "console=ttyAMA0,115200n8" "console=ttyO0,115200n8" "console=ttySAC2,115200n8" "console=tty0"];
37
38 sdImage = {
39 populateBootCommands = let
40 configTxt = pkgs.writeText "config.txt" ''
41 # Prevent the firmware from smashing the framebuffer setup done by the mainline kernel
42 # when attempting to show low-voltage or overtemperature warnings.
43 avoid_warnings=1
44
45 [pi2]
46 kernel=u-boot-rpi2.bin
47
48 [pi3]
49 kernel=u-boot-rpi3.bin
50
51 # U-Boot used to need this to work, regardless of whether UART is actually used or not.
52 # TODO: check when/if this can be removed.
53 enable_uart=1
54 '';
55 in ''
56 (cd ${pkgs.raspberrypifw}/share/raspberrypi/boot && cp bootcode.bin fixup*.dat start*.elf $NIX_BUILD_TOP/boot/)
57 cp ${pkgs.ubootRaspberryPi2}/u-boot.bin boot/u-boot-rpi2.bin
58 cp ${pkgs.ubootRaspberryPi3_32bit}/u-boot.bin boot/u-boot-rpi3.bin
59 cp ${configTxt} boot/config.txt
60 ${extlinux-conf-builder} -t 3 -c ${config.system.build.toplevel} -d ./boot
61 '';
62 };
63}