SBC (Single Board Computer)/Raspberry Pi 3

라즈베리파이, 커널 다운받고 설치 해볼까? ( Crosscompile)

LEEHANDS 2022. 1. 21. 18:15
반응형

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

32-bit Configs

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

First, use lsblk before and after plugging in your SD card to identify it. You should end up with something a lot like this:

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:

For 32-bit
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:

For 32-bit
 
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

The menuconfig tool requires the ncurses development headers to compile properly. These can be installed with the following command:
 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.

 

대부분은 라즈베리파이 홈페이지에서 복붙했습니다.

링크를 정독해주시면 되겠습니다.

https://www.raspberrypi.com/documentation/computers/linux_kernel.html#install-directly-onto-the-sd-card

 

Raspberry Pi Documentation - The Linux kernel

The official documentation for Raspberry Pi computers and microcontrollers

www.raspberrypi.com

 

반응형