How to cross-compile kernel for aarch64 on x86 host without qemu?

I’m building custom sd card image with nixos for aarch64 target (mt7622 soc) on x86 host computer and faced with kernel cross-compile issue. In general everything works, but when I’m trying to apply patches to kernel or changes in config kernel recompiles from scratch (obviously) using user-space qemu to call aarch64 version of gcc (which is less obvious for me). It takes a lot of time even on 12-core i7. Is it possible to build kernel using native gcc without qemu emulation?

I’m building my image using this command:

NIXOS_CONFIG=$(pwd)/configuration.nix nix-build ./image.nix

and using configuration.nix, image.nix

I’ve used this in the past:

  boot.kernelPackages = let
    crossPkgs = import pkgs.path {
      localSystem.system = "x86_64-linux";
      crossSystem.system = "aarch64-linux";
    };
  in crossPkgs.linuxPackages_latest;

i.e. build everything natively, but build the kernel with a cross compiling builder. It works quite well.

1 Like