Skip to content

Commit ed45b4a

Browse files
Adam Josephsamueldr
andcommitted
nixos/modules/installer/sd-card/sd-image-mips64el.nix: init
This cross-compiles a complete NixOS installer image. The image is built specifically for Cavium Octeon chips, because currently these are the Mips64 products that are commercially available: you can order a Ubiquiti Edgerouter from Amazon and have it the next day. All of Debian's non-Longsoon MIPS builders are Octeons: https://wiki.debian.org/MIPSPort Co-authored-by: Samuel Dionne-Riel <samuel@dionne-riel.com>
1 parent 3c24c7b commit ed45b4a

3 files changed

Lines changed: 84 additions & 0 deletions

File tree

lib/systems/examples.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ rec {
106106
mips64-linux-gnuabi64 = { config = "mips64-unknown-linux-gnuabi64"; } // platforms.gcc_mips64r2_64;
107107
mips64el-linux-gnuabi64 = { config = "mips64el-unknown-linux-gnuabi64"; } // platforms.gcc_mips64r2_64;
108108

109+
octeon = { config = "mips64el-unknown-linux-gnuabi64"; } // platforms.gcc_mips64r2_64 // platforms.octeon;
110+
109111
muslpi = raspberryPi // {
110112
config = "armv6l-unknown-linux-musleabihf";
111113
};

lib/systems/platforms.nix

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,46 @@ rec {
526526
};
527527
};
528528

529+
# Cavium Octeon series chips, which represent nearly all mips64
530+
# chips in production as of 2023
531+
octeon = {
532+
533+
# Note: qemu will segfault if you try to run a binary that uses
534+
# the -march=octeon instructions. Much of nixpkgs'
535+
# cross-compilation requires qemu.
536+
537+
# gcc = { arch = "octeon"; };
538+
539+
linux-kernel = {
540+
name = "mips64el";
541+
baseConfig = "cavium_octeon_defconfig";
542+
target = "vmlinux";
543+
DTB = true;
544+
autoModules = true;
545+
extraConfig =
546+
lib.concatStringsSep "\n"
547+
(lib.mapAttrsToList (k: v: "${k} ${v}") {
548+
CPU_CAVIUM_OCTEON = "y";
549+
CPU_LITTLE_ENDIAN = "y";
550+
KBUILD_SYM32 = "n";
551+
MODULES = "y";
552+
553+
# MIPS kernels are ELF images, with ELF structure, so you
554+
# can stick things into them (and patchelf them!). We can
555+
# also attach the desired DTB directly to the kernel image,
556+
# and even use the DTB as a "grub.conf".
557+
MIPS_ELF_APPENDED_DTB = "y";
558+
559+
# Take boot command line from the DTB, but allow the
560+
# bootloader to supersede those choices.
561+
MIPS_CMDLINE_DTB_EXTEND = "y";
562+
563+
# > ERROR: modpost: "__tracepoint_ata_bmdma_stop" [drivers/ata/pata_octeon_cf.ko] undefined!
564+
PATA_OCTEON_CF = "n";
565+
});
566+
};
567+
};
568+
529569
##
530570
## Other
531571
##
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
To build, use:
3+
nix-build nixos -I nixos-config=nixos/modules/installer/sd-card/sd-image-mips64el.nix -A config.system.build.sdImage
4+
5+
Since mips hardware is found mostly in routers which are optimized
6+
for I/O throughput rather than compilation speed, you probably
7+
want to cross-compile this. To do so, use:
8+
9+
nix-build nixos \
10+
-A config.system.build.sdImage \
11+
--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; }'
12+
*/
13+
{ config, lib, pkgs, ... }:
14+
15+
{
16+
imports = [
17+
../../profiles/base.nix
18+
./sd-image.nix
19+
];
20+
21+
boot.loader = {
22+
grub.enable = false;
23+
generic-extlinux-compatible = {
24+
enable = true;
25+
};
26+
};
27+
28+
services.xserver.enable = lib.mkForce false;
29+
services.xserver.libinput.enable = lib.mkForce false;
30+
31+
boot.consoleLogLevel = lib.mkDefault 7;
32+
boot.kernelParams = [ "console=ttyS0,115200" ];
33+
boot.initrd.includeDefaultModules = false;
34+
35+
sdImage = {
36+
populateFirmwareCommands = "";
37+
populateRootCommands = ''
38+
mkdir -p ./files/boot
39+
${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot
40+
'';
41+
};
42+
}

0 commit comments

Comments
 (0)