diff --git a/lib/systems/examples.nix b/lib/systems/examples.nix index 8d9c09561ddb0..efa94678ca3e8 100644 --- a/lib/systems/examples.nix +++ b/lib/systems/examples.nix @@ -106,6 +106,8 @@ rec { mips64-linux-gnuabi64 = { config = "mips64-unknown-linux-gnuabi64"; } // platforms.gcc_mips64r2_64; mips64el-linux-gnuabi64 = { config = "mips64el-unknown-linux-gnuabi64"; } // platforms.gcc_mips64r2_64; + octeon = { config = "mips64el-unknown-linux-gnuabi64"; } // platforms.gcc_mips64r2_64 // platforms.octeon; + muslpi = raspberryPi // { config = "armv6l-unknown-linux-musleabihf"; }; diff --git a/lib/systems/platforms.nix b/lib/systems/platforms.nix index d2e8f77bec03e..224d191b51030 100644 --- a/lib/systems/platforms.nix +++ b/lib/systems/platforms.nix @@ -526,6 +526,46 @@ rec { }; }; + # Cavium Octeon series chips, which represent nearly all mips64 + # chips in production as of 2023 + octeon = { + + # Note: qemu will segfault if you try to run a binary that uses + # the -march=octeon instructions. Much of nixpkgs' + # cross-compilation requires qemu. + + # gcc = { arch = "octeon"; }; + + linux-kernel = { + name = "mips64el"; + baseConfig = "cavium_octeon_defconfig"; + target = "vmlinux"; + DTB = true; + autoModules = true; + extraConfig = + lib.concatStringsSep "\n" + (lib.mapAttrsToList (k: v: "${k} ${v}") { + CPU_CAVIUM_OCTEON = "y"; + CPU_LITTLE_ENDIAN = "y"; + KBUILD_SYM32 = "n"; + MODULES = "y"; + + # MIPS kernels are ELF images, with ELF structure, so you + # can stick things into them (and patchelf them!). We can + # also attach the desired DTB directly to the kernel image, + # and even use the DTB as a "grub.conf". + MIPS_ELF_APPENDED_DTB = "y"; + + # Take boot command line from the DTB, but allow the + # bootloader to supersede those choices. + MIPS_CMDLINE_DTB_EXTEND = "y"; + + # > ERROR: modpost: "__tracepoint_ata_bmdma_stop" [drivers/ata/pata_octeon_cf.ko] undefined! + PATA_OCTEON_CF = "n"; + }); + }; + }; + ## ## Other ## diff --git a/nixos/modules/installer/sd-card/sd-image-mips64el.nix b/nixos/modules/installer/sd-card/sd-image-mips64el.nix new file mode 100644 index 0000000000000..c31f4302f1516 --- /dev/null +++ b/nixos/modules/installer/sd-card/sd-image-mips64el.nix @@ -0,0 +1,42 @@ +/* +To build, use: +nix-build nixos -I nixos-config=nixos/modules/installer/sd-card/sd-image-mips64el.nix -A config.system.build.sdImage + +Since mips hardware is found mostly in routers which are optimized +for I/O throughput rather than compilation speed, you probably +want to cross-compile this. To do so, use: + +nix-build nixos \ + -A config.system.build.sdImage \ + --arg configuration '{config,lib,pkgs,...}@args: (import ./nixos/modules/installer/sd-card/sd-image-mips64el.nix args) // { nixpkgs.hostPlatform = lib.systems.examples.octeon; nixpkgs.buildPlatform = builtins.currentSystem; }' +*/ +{ config, lib, pkgs, ... }: + +{ + imports = [ + ../../profiles/base.nix + ./sd-image.nix + ]; + + boot.loader = { + grub.enable = false; + generic-extlinux-compatible = { + enable = true; + }; + }; + + services.xserver.enable = lib.mkForce false; + services.xserver.libinput.enable = lib.mkForce false; + + boot.consoleLogLevel = lib.mkDefault 7; + boot.kernelParams = [ "console=ttyS0,115200" ]; + boot.initrd.includeDefaultModules = false; + + sdImage = { + populateFirmwareCommands = ""; + populateRootCommands = '' + mkdir -p ./files/boot + ${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot + ''; + }; +}