SBC (Single Board Computer)/Raspberry Pi 3

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

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

아주잘된 레퍼런스 사이트 : https://www.raspberrypi.org/documentation/linux/kernel/building.md

 

Raspberry Pi Documentation - The Linux kernel

The official documentation for Raspberry Pi computers and microcontrollers

www.raspberrypi.com

위 영문 사이트가 가장 정확하는걸 알리면서 시작합니다.

 

Building the Kernel Locally

 

리눅스 유틸리티 프로그램 설치

sudo apt install git bc bison flex libssl-dev make

리눅스 소스코드 다운로드

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

리눅스 폴더에 생성되는 .git/config 를 열어보면 브랜치 정보 확인

 

Kernel Configuration

 

Apply default configuration

Raspberry Pi Zero 
cd linux
KERNEL=kernel
make bcmrpi_defconfig

Raspberry Pi 2 3 3+

cd linux
KERNEL=kernel7
make bcm2709_defconfig

Raspberry Pi 4 ( 32 bit )

cd linux
KERNEL=kernel7l
make bcm2711_defconfig

Raspberry Pi 4 (64 Bit)

cd linux
KERNEL=kernel8
make bcm2711_defconfig

Building the Kernel

 

make -j4 zImage modules dtbs
sudo make modules_install
sudo cp arch/arm/boot/dts/*.dtb /boot/
sudo cp arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/
sudo cp arch/arm/boot/dts/overlays/README /boot/overlays/
sudo cp arch/arm/boot/zImage /boot/$KERNEL.img

 

Shell Script 

 

For Kernel build

#!/bin/bash

echo "configure build output path"

KERNEL_TOP_PATH="$( cd "$(dirname "$0")" ; pwd -P )"        # Working directory save to KERNEL_TOP_PATH
OUTPUT="$KERNEL_TOP_PATH/out"                               # Variable of OUTPUT change to left tree
echo "$OUTPUT"

KERNEL=kernel7     # raspberry pi 3
BUILD_LOG="$KERNEL_TOP_PATH/rpi_preproccess_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

실행파일형태로 변환

" chmod +x build_preprocess_rpi_kernel.sh "

 

Install Kernel

#!/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/dts/overlays/README /boot/overlays/
cp $OUTPUT/arch/arm/boot/zImage /boot/kernel7.img
반응형