Skip to content

Commit

Permalink
nixos/modules/installer/sd-card/sd-image-mips64el.nix: init
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Adam Joseph and samueldr committed Aug 2, 2023
1 parent 3c24c7b commit ed45b4a
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/systems/examples.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
};
Expand Down
40 changes: 40 additions & 0 deletions lib/systems/platforms.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
##
Expand Down
42 changes: 42 additions & 0 deletions nixos/modules/installer/sd-card/sd-image-mips64el.nix
Original file line number Diff line number Diff line change
@@ -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
'';
};
}

0 comments on commit ed45b4a

Please sign in to comment.