고급 개발자로 가는 길

Embedded/Raspberry Pi

[Raspberry Pi] 라즈베리파이 라즈비안 리눅스 커널 빌드

다크엔지니어 2022. 1. 21. 00:10
반응형

라즈비안 리눅스에서 커널을 빌드 하기 위한 방법이다.

아래 경로를 참고하면 라즈베리파이 공식사이트에서 방법을 제공한다.

https://www.raspberrypi.com/documentation/computers/linux_kernel.html

 

Raspberry Pi Documentation - The Linux kernel

The official documentation for Raspberry Pi computers and microcontrollers

www.raspberrypi.com

 

공식사이트에서는 커맨드 형식으로 타이핑 해야되서 자주사용하기에는 불편하다.

이럴 경우, 임베디드 개발 시 빌드 쉘 스크립트를 사용하면 된다.

 

라즈비안 리눅스 커널 코드의 경우, 아래 경로에서 git clone 가능하다.

https://github.com/raspberrypi/linux 

 

GitHub - raspberrypi/linux: Kernel source tree for Raspberry Pi Foundation-provided kernel builds. Issues unrelated to the linux

Kernel source tree for Raspberry Pi Foundation-provided kernel builds. Issues unrelated to the linux kernel should be posted on the community forum at https://forums.raspberrypi.com/ - GitHub - ras...

github.com

 

Build Sheel Script 는 아래와 같다. apt-get or apt update 및 upgrade는 필수 이다.

#!/bin/bash

echo "configure build output path"

KERNEL_TOP_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
OUTPUT="$KERNEL_TOP_PATH/out"
echo "$OUTPUT"

KERNEL=kernel7
BUILD_LOG="$KERNEL_TOP_PATH/rpi_build_log.txt"

echo "move kernel source"
cd linux

echo "make defconfig"
make O=$OUTPUT bcm2709_defconfig

echo "kernel build"
make O=$OUTPUT zImage modules dtbs -j4 2>&1 | tee $BUILD_LOG

라즈베리파이4에  라즈비안 21.10 쯤 버전으로 5.10.y 커널로 빌드를 한다면

kernel7l, bcm2711_defconfig 로 수정하여 빌드하면 된다.

 

아래는 빌드된 이미즈를 보드에 설치하는 script 이다.

#!/bin/bash

KERNEL_TOP_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
OUTPUT="$KERNEL_TOP_PATH/out"
echo "$OUTPUT"

cd linux

make O=$OUTPUT modules_install
cp $OUTPUT/arch/arm/boot/dts/*.dtb /boot/
cp $OUTPUT/arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/
cp $OUTPUT/arch/arm/boot/zImage /boot/kernel7l.img
반응형