본문 바로가기

리눅스 커널의 구조와 원리/2. 라즈베리 파이 설정

[라즈베리파이] 특정 브랜치(rpi-4.14.y)로 소스 코드 내려받기

라즈베리파이에서 가장 많이 쓰는 라즈비안은 꾸준히 최신 커널 버전을 지원합니다.
 
최신 라즈비안 커널 소스 코드 내려받기
 
먼저 다음 명령어를 입력해 라즈비안 최신 커널 소스를 내려 받겠습니다.
"git clone --depth=3000 https://github.com/raspberrypi/linux"
 
root@raspberrypi:/home/pi/RPi_kernel_src# git clone --depth=3000 https://github.com/raspberrypi/linux
Cloning into 'linux'...
remote: Enumerating objects: 85646, done.
remote: Counting objects: 100% (85646/85646), done.
remote: Compressing objects: 100% (65774/65774), done.
Receiving objects:  33% (28569/85646), 41.45 MiB | 1.22 MiB/s     
 
커널 소스를 다 내려받고 나서 브랜치를 확인하니 rpi-4.19.y입니다.
root@raspberrypi:/home/pi/RPi_kernel_src# git branch
* rpi-4.19.y
 
linux 폴더에 생성되는 .git/config 파일을 열어보면 기본으로 rpi-4.19.y 브랜치를 Fetch합니다.
root@raspberrypi:/home/pi/RPi_kernel_src/linux# vi .git/config
.git/config
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    fetch = +refs/heads/rpi-4.19.y:refs/remotes/origin/rpi-4.19.y
[branch "rpi-4.19.y"]
    remote = origin
    merge = refs/heads/rpi-4.19.y
 
다음으로 커밋을 볼까요?
root@raspberrypi:/home/pi/RPi_kernel_src# git log
commit b40edce4d946218457aa65902c9baf313f670591
Author: Stefan Wahren <stefan.wahren@i2se.com>
Date:   Thu Mar 7 19:27:05 2019 +0100
 
    configs: Enable MT76 USB wifi
 
    Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
 
03/11/2019에 반영한 커밋이 보입니다.
 
기존 rpi-4.14.y 브랜치로 소스 코드를 어떻게 내려받을까?
 
그러면 기존 rpi-4.14.y 브랜치로 소스 코드를 내려 받고 싶으면 어떻게 해야 할까요?
방법은 간단합니다.
 
git clone 명령어에서 브랜치 이름을 지정하면 됩니다.
--branch "브랜치 이름"
 
그러면 "rpi-4.14.y" 브랜치 소스 코드를 내려 받기 위해 다음 명령어를 입력합시다.
root@raspberrypi:/home/pi/RPi_kernel_4_14_src# git clone --depth=1000 --branch rpi-4.14.y https://github.com/raspberrypi/linux
Cloning into 'linux'...
remote: Enumerating objects: 122739, done.
remote: Counting objects: 100% (122739/122739), done.
remote: Compressing objects: 100% (74357/74357), done.
remote: Total 122739 (delta 54284), reused 72109 (delta 47307), pack-reused 0
Receiving objects: 100% (122739/122739), 185.97 MiB | 1.17 MiB/s, done.
Resolving deltas: 100% (54284/54284), done.
Checking connectivity... done.
Checking out files: 100% (61885/61885), done.
 
빌드 서버 성능에 따라 소스 다운로드 시간에 차이가 있습니다만 약 10분 정도 걸립니다.
 
root@raspberrypi:/home/pi/RPi_kernel_4_14_src/linux# git branch
* rpi-4.14.y
 
.git/config를 확인하니 정말 rpi-4.14.y 브랜치가 보입니다.
root@raspberrypi:/home/pi/RPi_kernel_4_14_src/linux# vi .git/config
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    fetch = +refs/heads/rpi-4.14.y:refs/remotes/origin/rpi-4.14.y
[branch "rpi-4.14.y"]
    remote = origin
    merge = refs/heads/rpi-4.14.y
 
제대로 rpi-4.14.y 브랜치 코드를 패치해 왔습니다.
 
이번에는 리눅스 커널 버전을 확인해볼까요?
root@raspberrypi:/home/pi/RPi_kernel_4_14_src/linux# vi Makefile
# SPDX-License-Identifier: GPL-2.0
VERSION = 4
PATCHLEVEL = 14
SUBLEVEL = 98
EXTRAVERSION =
NAME = Petit Gorille
 
커널 버전 4.14.98입니다.
 
이번엔 "git log" 명령어를 입력해 가장 최신 커밋을 확인합시다. 
root@raspberrypi:/home/pi/RPi_kernel_4_14_src/linux# git log
commit e9829ff3e92f125072adae4de40750546f4268a2
Author: Chao Yu <yuchao0@huawei.com>
Date:   Sat Aug 11 23:42:09 2018 +0800
 
    f2fs: fix to skip verifying block address for non-regular inode
 
    commit dda9f4b9cac6bdd2a96253b4444d7a6ce5132edb upstream.
 
    generic/184 1s ... [failed, exit status 1]- output mismatch
        --- tests/generic/184.out       2015-01-11 16:52:27.643681072 +0800
         QA output created by 184 - silence is golden
        +rm: cannot remove '/mnt/f2fs/null': Bad address
        +mknod: '/mnt/f2fs/null': Bad address
        +chmod: cannot access '/mnt/f2fs/null': Bad address
        +./tests/generic/184: line 36: /mnt/f2fs/null: Bad address
 
2018/08/11 에 올린 커밋입니다.
 
라즈비안은 4.14에서 4.19 커널 버전으로 완전히 갈아 탔습니다.
 
결론
 
라즈비안 커널 소스를 다음 명령어로 내려 받으면 최신 브랜치를 패치합니다.
 
만약 2020년에 라즈비안 기본 브랜치가 rpi-5.4.y 라면 rpi-5.4.y 브랜치를 패치할 것입니다.
 
특정 브랜치를 지정해 라즈비안 소스 코드를 내려받으려면 다음과 같이 "--branch 브랜치 이름" 구문을 추가합시다.
git clone --depth=1000 --branch rpi-4.14.y https://github.com/raspberrypi/linux