Crosscompile the Raspberry Pi OS kernel on WSL

This topic is as a side note that build the Rasberry Pi OS kernel System on WSL enviroment. Previously, this site is noted how to OpenWRT build system setup on WSL. This topic is similally previous one, two topics difference is target of Linux distribusion.

OpenWRT build on WSL – Shimoha Tech (shimoha-tech.com)

WSL Enviroment for crosscompile

WSL version: 2.2.4.0
Kernel version: 5.15.153.1-2
WSLg version: 1.0.61
MSRDC version: 1.2.5326
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26091.1-240325-1447.ge-release
Windows version: 10.0.22631.3880

How to crosscompile the Raspberry Pi OS kernel on WSL

Installing packages for build

sudo apt update
sudo apt upgrade
sudo apt install bc bison flex libssl-dev make -y
sudo apt install g++-aarch64-linux-gnu -y

making folder

Allowing permissions of folder using Windows OS folder property.

  • Open target foleder property
  • Select [Security] tab
  • Select Users from list of Goup or usr names , and Press [Edit] button
  • Allow permissions [Full control], [Modify]
folder property settings for casesensitive

Enabling CaseSensitivity of the created folder

fsutil.exe file setCaseSensitiveInfo <folder path> enable

Getting built Raspberry Pi OS kernel code using git clone command.

git clone --depth=1 https://github.com/raspberrypi/linux

Build Configuration

Raspberry Pi 3 or 4 64bit:

cd linux
KERNEL=kernel8 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make bcm2711_defconfig

Raspberry Pi 5 64bit:

cd linux
KERNEL=kernel_2712 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make bcm2712_defconfig

  • For Crosscompile

ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -j$(nproc)/2 Image.gz modules dtbs

  • For Raspberry Pi 3 or 4 64bit:
ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -j$(nproc)/2 Image modules dtbs
  • For Raspberry Pi 5 64bit:
ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -j$(nproc)/2 Image modules dtbs

Mount a SD card for Raspberry Pi OS in WSL.

A Following Microsoft website is wrritten about how to mounting.

  • Settings on Windows

Get started mounting a Linux disk in WSL 2 | Microsoft Learn

  • Setting on WSL:

Run lsblk command. checking a SD card of boot partition, root partition.

mkdir mnt
sudo mount /dev/(boot partition) mnt/boot
sudo mount /dev/(root partition) mnt/root

Writting built to a SD card

sudo cp arch/arm64/boot/Image mnt/boot/$KERNEL.img
sudo cp arch/arm64/boot/dts/broadcom/*.dtb mnt/boot/
sudo cp arch/arm64/boot/dts/overlays/*.dtb* mnt/boot/overlays/
sudo make modules_install INSTALL_MOD_PATH=mnt/root

Completed!

Tags:

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *