Raspberry Pi 2 / 3 向け CentOS 7 Kernel RPM の作成

CentOS の Raspberry Pi 向け Kernel はリリースされるのが遅いので、自分でビルドした。
今は昔ながらの手法でビルドしてるけど、そのうち mock に移行しよう。
ちなみに、32bit。
なお、Raspberry Pi 向け CentOS 7 のイメージ用初期設定ブートストラップにも反映しておいた。
※ブートストラップについての説明は先日の記事【Raspberry Pi 3 Model B で Wi-Fi VPN ルータを作ってみた】を参照。

■成果物だけがほしい人向け
・成果物置き場
https://www.sgv417.jp/repos/altarch/rpi2-kernel/

・上記成果物を使うためのリポジトリファイル
https://www.sgv417.jp/repos/altarch/rpi2-kernel/tsc-centos7-rpi2-kernel.repo
次のように使う。

# cd /etc/yum.repos.d/
# curl -L --output /etc/yum.repos.d/tsc-centos7-rpi2-kernel.repo https://www.sgv417.jp/repos/altarch/rpi2-kernel/tsc-centos7-rpi2-kernel.repo
# yum update --enablerepo=tsc-kernel raspberrypi2\*

・tsc-centos7-rpi2-kernel.repo の中身

[tsc-kernel]
name=CentOS 7 Kernels for Raspberry Pi by tsc
baseurl=https://www.sgv417.jp/repos/altarch/rpi2-kernel/
failovermethod=priority
enabled=0
gpgcheck=1
gpgkey=https://www.sgv417.jp/repos/altarch/rpi2-kernel/RPM-GPG-KEY-tsc-kernel

■ビルド環境を整える
・root 権限で、ビルド用パッケージをインストールする。
・ついでに wget も。

# yum install rpm-build yum-utils wget

・非 root なアカウントで、ビルド環境を整える。

$ mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
$ vi ~/.rpmmacros
%_topdir	%(echo $HOME)/rpmbuild
#%_smp_mflags	-j1
%__arch_install_post	/usr/lib/rpm/check-rpaths /usr/lib/rpm/check-buildroot
%_tmpfilesdir	/usr/lib/tmpfiles.d
%_gpg_path	/home/admin/.gnupg
%_gpg_name	NAME (COMMENT) <MAILADDR>
%_gpgbin	/usr/bin/gpg

■公式の Source RPM をダウンロードする
此処にある。
https://armv7.dev.centos.org/repodir/arm-kernels/
とりあえず最新版である【rpi2-4.4.41】から raspberrypi2-4.4.41-v7.1.el7.src.rpm をダウンロードした。

$ cd ~/rpmbuild/SRPMS/
$ wget -N https://armv7.dev.centos.org/repodir/arm-kernels/rpi2-4.4.41/raspberrypi2-4.4.41-v7.1.el7.src.rpm

■Source RPM を展開し、最新の Kernel と Firmware をダウンロードする

$ cd ~/rpmbuild/SRPMS/
$ rpm -ivh raspberrypi2-4.4.41-v7.1.el7.src.rpm
$ cd ~/rpmbuild/SPECS/
$ less raspberrypi2.spec

次のように定義されている。

%global commit_firmware_short 6df93de
%global commit_firmware_long  6df93defc76d5b511838d6802a01a05072964582
%global commit_linux_short a9fe228
%global commit_linux_long  a9fe22825add76ffefbd42f2b540c4ad7ea9edb4
Source0:        https://github.com/raspberrypi/linux/tarball/%{commit_linux_long}
Source1:        https://github.com/raspberrypi/firmware/tarball/%{commit_firmware_long}

なので、最新の Kernel と Firmware は、GitHub からダウンロードする。
後ろのコミットハッシュ番号については、それぞれのページの「commits」にある。
Kernel: https://github.com/raspberrypi/linux
Firmware: https://github.com/raspberrypi/firmware
この記事を書いた時点での最新版をダウンロードするコマンドはこんな感じ。

$ cd ~/rpmbuild/SOURCES/
$ wget -N https://github.com/raspberrypi/linux/tarball/6d6d3e98a010b4f15dc4e80b12d6a53c814eef6f
$ wget -N https://github.com/raspberrypi/firmware/tarball/475a89a94e5f1a6dea93af655529dc98e9933dd0

■SPEC ファイルを編集する
Commit No と Version, ChangeLog を修正する。

$ cd ~/rpmbuild/SPECS/
$ cp -piav raspberrypi2.spec raspberrypi2.spec.org
$ vi raspberrypi2.spec

Diff 表示すると、大体こんな感じ。

--- raspberrypi2.spec.org       2017-01-13 23:26:05.000000000 +0900
+++ raspberrypi2.spec   2017-02-04 12:11:48.000000000 +0900
@@ -1,14 +1,14 @@
-%global commit_firmware_short 6df93de
-%global commit_firmware_long  6df93defc76d5b511838d6802a01a05072964582
-%global commit_linux_short a9fe228
-%global commit_linux_long  a9fe22825add76ffefbd42f2b540c4ad7ea9edb4
+%global commit_firmware_short 475a89a
+%global commit_firmware_long  475a89a94e5f1a6dea93af655529dc98e9933dd0
+%global commit_linux_short 6d6d3e9
+%global commit_linux_long  6d6d3e98a010b4f15dc4e80b12d6a53c814eef6f

 %define Arch arm
 %define local_version v7
 %define extra_version 1

 Name:           raspberrypi2
-Version:        4.4.41
+Version:        4.4.46
 Release:        %{local_version}.%{extra_version}%{?dist}
 Summary:        Specific kernel and bootcode for Raspberry Pi

@@ -184,6 +184,12 @@
 %doc /boot/LICENCE.broadcom

 %changelog
+* Sat Feb 4 2017 NAME <MAILADDR> - 4.4.46-v7.1.el7
+- update to upstream version 4.4.46
+
 * Fri Jan 13 2017 Fabian Arrotin <arrfab@centos.org> - 4.4.41-v7.1.el7
 - update to upstream version 4.4.41

■Source RPM の作成
rpmbuild -bs だけだと、Dist部が「el7.centos」となってしまい、自作のパッケージか一目でわからなくなる。
そのため、次のように入力し、Dist部を独自の物とする。

$ cd ~/rpmbuild/SPECS/
$ rpmbuild -bs --define 'dist .el7.tsc' raspberrypi2.spec

こうすることで、パッケージおよびバージョン表記などに「.el7.tsc」という文字列が差し込まれる。

■RPM のビルドに必要なパッケージをインストールする
「yum-builddep」コマンド SPEC ファイルを引数としてを root 権限で実行することで、ビルドに必要なパッケージを一気にインストールすることができる。

# yum-builddep /home/admin/rpmbuild/SPECS/raspberrypi2.spec

■Binary RPM の作成
先ほど作成した Source RPM から生成する。

$ rpmbuild --rebuild --define 'dist .el7.tsc' ~/rpmbuild/SRPMS/raspberrypi2-4.4.46-v7.1.el7.tsc.src.rpm

■作成した RPM に署名をする
GnuPG の設定方法は割愛。

$ rpm --addsign ~/rpmbuild/SRPMS/*.rpm
$ rpm --addsign ~/rpmbuild/RPMS/armv7hl/*.rpm
カテゴリー: めも パーマリンク

1 Response to Raspberry Pi 2 / 3 向け CentOS 7 Kernel RPM の作成

  1. ピンバック: Raspberry Pi 2 / 3 向け CentOS 7 RT Kernel RPM の作成 | まこぴかっと

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です