Building Kernel Guide

From Wii-Linux Wiki
Revision as of 21:32, 19 May 2025 by Tech64DD (talk | contribs) (standalone argument)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This Guide will teach you how to cross-compile the Wii-Linux kernel and supporting elements.

Requirements

[edit]
  • An x86 or AArch64 device running GNU/Linux


Setup and Compile

[edit]
  1. Install Crosstool-NG via package manager or compile it by cloning git clone https://github.com/crosstool-ng/crosstool-ng.
  2. Make a directory to have all the files/folders to be in
  3. In that directory clone the Wii-Linux-Toolchain https://github.com/Wii-Linux/wii-linux-toolchain.
  4. cd into the wii-linux-toolchain folder and run mv ct-ng.config .config and run ct-ng build.
    • The process will take a while depending on how bad your computer is.
  5. Once it's installed, it should make a directory in your home folder called x-tools.
    • You can optionally move this directory elsewhere first, if you don't find x-tools appealing.
  6. You must now add it to your PATH. This varies per shell, and based on where you put it, but as an example:
    • for bash: echo 'PATH="$PATH:~/<path to ct-ng output>/powerpc-unknown-linux-gnu/bin"' >> ~/.bashrc && source ~/.bashrc.
  7. After you have added it to your path, go back to the main directory and run git clone https://github.com/Wii-Linux/build-stack && cd build-stack.
  8. Once you're in the build-stack folder, run ./setup.sh and follow it's instructions, to make sure that you have all the necessary requirements installed. If it asks to clone and build various requirements, answer Yes unless you have a very specific reason not to.
  9. After setup.sh finishes successfully, go back to the main directory, and now finally run https://github.com/Wii-Linux/wii-linux-ngx -b <Branch You want>.
    • The branch you clone is the source code to the kernel branch you are going to compile (this could be specialized kernels (like for OpenWRT, or just various versions of the main one). The following kernel branches are the ones currently supported:
      • wii-v4.5
      • wii-v4.14-openwrt
      • wii-v4.19
  10. After you cloned the kernel that you want to build go back into build-stack and run ./build-kernel.sh [name of your kernel directory].
    • Example: ./build-kernel.sh wii-linux-ngx.
    • The --standalone argument can be used to build a kernel that doesn't require a loader, arch/powerpc/boot/dts/wii.dts needs to be edited accordingly with the boot device that will be used.
  11. After the kernel compiles, you have to build the loader (small squashfs that the kernel boots, provides the boot menu). In the build-stack run ./build-loader.sh ../v<kernel version short>.ldr.
    • Example: ./build-loader.sh ../v4_19325.ldr.
  12. After the loader is done, you need to go install it. This consists of 2 parts:
    • Installing the kernel+loader. A script has been provided to make this easier, build-stack/copy-ssh.sh. This provides an easy way to copy the kernel+loader to a remote machine in any directory. This could even be a Wii-Linux install.
      • Example 1 (copy to local machine's SD Card on /mnt): ./copy-ssh.sh root@localhost /mnt v4_19325 4.19.325-wii+ kernel v4_19325.ldr
      • Example 2 (copy to Wii with SD Card on /boot): ./copy-ssh.sh root@wii.local /boot v4_19325 4.19.325-wii+ kernel v4_19325.ldr
    • ''Installing the kernel modules. The kernel modules are output as modules.tar.gz in your kernel directory. You will need to safely extract these to your Wii-Linux distro's rootfs. WARNING: Extracting directly to the rootfs WILL HOSE YOUR PERMISSIONS - DO NOT DO THAT. It will set the UID/HID of the root directory, and /usr, and /usr/lib, to the UID/GID of the user who built the kernel. Instead, you can extract it to a temporary directory, then mv or cp -r the modules (temp_dir/usr/lib/modules/[kernel version]-wii+ into your rootfs.