Cross-Compiling the Kernel
Install Required Dependencies and Toolchain
sudo apt install git bc bison flex libssl-dev make libc6-dev libncurses5-dev
Install the 32-bit Toolchain for a 32-bit Kernel
sudo apt install crossbuild-essential-armhf
Install the 64-bit Toolchain for a 64-bit Kernel
sudo apt install crossbuild-essential-arm64
Get the Kernel Sources
git clone --depth=1 https://github.com/raspberrypi/linux
Build sources
For Pi 1, Pi Zero, Pi Zero W, or Compute Module:
cd linux
KERNEL=kernel
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcmrpi_defconfig
For Pi 2, Pi 3, Pi 3+, or Compute Module 3:
cd linux
KERNEL=kernel7
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig
For Raspberry Pi 4:
cd linux
KERNEL=kernel7l
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2711_defconfig
64-bit Configs
For Pi 3, Pi 3+ or Compute Module 3:
cd linux
KERNEL=kernel8
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcmrpi3_defconfig
For Raspberry Pi 4:
cd linux
KERNEL=kernel8
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcm2711_defconfig
Build with Configs
For all 32-bit Builds
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs
For all 64-bit Builds
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image modules dtbs
Install Directly onto the SD Card
Mount these first, adjusting the partition letter as necessary:
mkdir mnt
mkdir mnt/fat32
mkdir mnt/ext4
sudo mount /dev/sdb1 mnt/fat32
sudo mount /dev/sdb2 mnt/ext4
Next, install the kernel modules onto the SD card:
sudo env PATH=$PATH make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=mnt/ext4 modules_install
For 64-bit
sudo env PATH=$PATH make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- INSTALL_MOD_PATH=mnt/ext4 modules_install
Finally, copy the kernel and Device Tree blobs onto the SD card, making sure to back up your old kernel:
sudo cp mnt/fat32/$KERNEL.img mnt/fat32/$KERNEL-backup.img
sudo cp arch/arm/boot/zImage mnt/fat32/$KERNEL.img
sudo cp arch/arm/boot/dts/*.dtb mnt/fat32/
sudo cp arch/arm/boot/dts/overlays/*.dtb* mnt/fat32/overlays/
sudo cp arch/arm/boot/dts/overlays/README mnt/fat32/overlays/
sudo umount mnt/fat32
sudo umount mnt/ext4
For 64-bit
sudo cp mnt/fat32/$KERNEL.img mnt/fat32/$KERNEL-backup.img
sudo cp arch/arm64/boot/Image mnt/fat32/$KERNEL.img
sudo cp arch/arm64/boot/dts/broadcom/*.dtb mnt/fat32/
sudo cp arch/arm64/boot/dts/overlays/*.dtb* mnt/fat32/overlays/
sudo cp arch/arm64/boot/dts/overlays/README mnt/fat32/overlays/
sudo umount mnt/fat32
sudo umount mnt/ext4
Configuring the Kernel
Kernel Config 하는방법은 아래와같다.
Preparing to Configure
sudo apt install libncurses5-dev
Using menuconfig
make menuconfig
If you’re cross-compiling a 32-bit kernel:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
Or, if you are cross-compiling a 64-bit kernel:
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig
Saving your Changes
Once you’re done making the changes you want, press Escape until you’re prompted to save your new configuration. By default, this will save to the .config file. You can save and load configurations by copying this file around.
대부분은 라즈베리파이 홈페이지에서 복붙했습니다.
링크를 정독해주시면 되겠습니다.
'SBC (Single Board Computer) > Raspberry Pi 3' 카테고리의 다른 글
라즈베리파이3, BCM2709 ? 뭘까? (0) | 2022.07.06 |
---|---|
라즈베리파이, 커널 다운받고 설치 해볼까? (Local ) (0) | 2022.01.21 |
터치스크린 동작 , I2C HID 활성화 (2) | 2021.09.02 |
라즈베리파이3, 라즈비안 커널 소스 내려받기 < 크로스 컴파일 > (0) | 2021.09.02 |