LoginSignup
3
1

More than 5 years have passed since last update.

UltraZed 向け Debian GNU/Linux の構築(Debian9 Root File System編)

Last updated at Posted at 2017-12-28

はじめに

UltraZed-EG スターターキットに Debian GNU/Linux を構築する方法について、具体的な方法をいくつかに分けて説明します。

この記事では、Debian9 Root File System の構築について説明をします。

必要な環境

私は Ubuntu 上で Debian9 Root File System を構築しました。Debian 系のプラットフォームを用意してください。

まずはプラットフォームに構築に必要なツールをインストールします。

shell$ apt-get install qemu-user-static debootstrap binfmt-support

構築

構築環境の準備

次の URL から git clone でリポジトリをダウンロードして v2017.3.0 をチェックアウトします。

shell$ git clone git://github.com/ikwzm/ZynqMP-FPGA-Linux
shell$ cd ZynqMP-FPGA-Linux
shell$ git checkout v2017.3.0

環境変数の設定

shell$ export targetdir=debian9-rootfs
shell$ export distro=stretch

構築(ステージ1)

shell$ mkdir $targetdir
shell$ sudo debootstrap --arch=arm64 --foreign $distro    $targetdir
shell$ sudo cp /usr/bin/qemu-aarch64-static               $targetdir/usr/bin
shell$ sudo cp /etc/resolv.conf                           $targetdir/etc
shell$ sudo cp scripts/build-debian9-rootfs-with-qemu.sh  $targetdir
shell$ sudo cp linux-image-4.9.0-xlnx-v2017.3-zynqmp-fpga_4.9.0-xlnx-v2017.3-zynqmp-fpga-1_arm64.deb   $targetdir
shell$ sudo cp linux-headers-4.9.0-xlnx-v2017.3-zynqmp-fpga_4.9.0-xlnx-v2017.3-zynqmp-fpga-1_arm64.deb $targetdir

QEMU による構築(ステージ2)

これ以降は QEMU(arm64版) と chroot を使ってRoot File System を構築します。

shell$ sudo chroot $targetdir

ここから、次の2種類の方法があります。

  1. build-debian9-rootfs-with-qemu.sh を使って楽々構築
  2. 一歩一歩コマンドを打ち込みつつ構築

どちらもやってることは同じなので、ここでは一歩一歩コマンドを打ち込む方法を説明します。

APT の設定

debian9-rootfs# distro=stretch
debian9-rootfs# export LANG=C
debian9-rootfs# /debootstrap/debootstrap --second-stage
debian9-rootfs# cat <<EOT > /etc/apt/sources.list
deb     http://ftp.jp.debian.org/debian            stretch         main contrib non-free
deb-src http://ftp.jp.debian.org/debian            stretch         main contrib non-free
deb     http://ftp.jp.debian.org/debian            stretch-updates main contrib non-free
deb-src http://ftp.jp.debian.org/debian            stretch-updates main contrib non-free
deb     http://security.debian.org/debian-security stretch/updates main contrib non-free
deb-src http://security.debian.org/debian-security stretch/updates main contrib non-free
EOT
debian9-rootfs# cat <<EOT > /etc/apt/apt.conf.d/71-no-recommends
APT::Install-Recommends "0";
APT::Install-Suggests   "0";
EOT
debian9-rootfs# apt-get update

基本的なアプリケーションのインストール

debian9-rootfs# apt-get install -y locales dialog
debian9-rootfs# dpkg-reconfigure locales
debian9-rootfs# apt-get install -y net-tools openssh-server ntpdate resolvconf sudo less hwinfo ntp tcsh zsh

hostname の設定

ここでは debian-fpga という名前をつけています。ここらへんはお好みに合わせてください。

debian9-rootfs# echo debian-fpga > /etc/hostname

root のパスワードの設定

debian9-rootfs# passwd

ここで rootのパスワードを何にするか聞かれるので適当に admin とか入力してください。

debian9-rootfs# cat <<EOT >> /etc/securetty
# Seral Port for Xilinx Zynq
ttyPS0
EOT

FPGA ユーザーの追加

debian9-rootfs# adduser fpga

ここで fpga ユーザーのパスワードを何にするか聞かれるので適当に fpga とか入力してください。

debian9-rootfs# echo "fpga ALL=(ALL:ALL) ALL" > /etc/sudoers.d/fpga

sshd config の設定

debian9-rootfs# sed -i -e 's/#PasswordAuthentication/PasswordAuthentication/g' /etc/ssh/sshd_config

Time Zone の設定

debian9-rootfs# dpkg-reconfigure tzdata

または Time Zone を noninteractive に指定したい時は次のようにしてください。

debian9-rootfs# echo "Asia/Tokyo" > /etc/timezone
debian9-rootfs# dpkg-reconfigure -f noninteractive tzdata

fstab の設定

debian9-rootfs# cat <<EOT > /etc/fstab
/dev/mmcblk1p1  /boot   auto        defaults    0   0
none        /config configfs    defaults    0   0
EOT

/dev/mmcblk1p1 は SD-Card の第一パーティションです。ここには BOOT.BIN、Linux Kernel Image、Device Tree が入っています。ここを /boot にマウントしておけば、後で中身を更新するときに Debian 上から出来るので楽です。

Configuration File System を /config にマウントしておきます。Configuration File System は Device Tree Overlay で使います。

Network Interface の設定

debian9-rootfs# cat <<EOT > /etc/network/interfaces.d/eth0
allow-hotplug eth0
iface eth0 inet dhcp
EOT

ここでは有線LAN (eth0) に DHCP を設定しています。これはお使いの環境にあわせてください。

/lib/firmware の設定

debian9-rootfs# mkdir /lib/firmware

fpga-region による FPGA のコンフィギュレーションの際、bitstream ファイルは /lib/firmware に置かなければなりません。ここでそのディレクトリを作っておきます。

各種アプリケーションのインストール

debian9-rootfs# apt-get install -y wireless-tools
debian9-rootfs# apt-get install -y wpasupplicant
debian9-rootfs# apt-get install -y firmware-realtek
debian9-rootfs# apt-get install -y firmware-ralink
debian9-rootfs# apt-get install -y build-essential
debian9-rootfs# apt-get install -y git
debian9-rootfs# apt-get install -y u-boot-tools
debian9-rootfs# apt-get install -y socat
debian9-rootfs# apt-get install -y ruby ruby-msgpack ruby-serialport
debian9-rootfs# gem install rake
debian9-rootfs# apt-get install -y python  python-dev  python-setuptools  python-wheel  python-pip  python-numpy
debian9-rootfs# apt-get install -y python3 python3-dev python3-setuptools python3-wheel python3-pip python3-numpy
debian9-rootfs# pip3 install msgpack-rpc-python
debian9-rootfs# apt-get install -y samba
debian9-rootfs# apt-get install -y avahi-daemon

必要なアプリケーションはここでインストールします。何をインストールするかはお好みで。

Device Tree Compiler (supported symbol version) のインストール

debian9-rootfs# apt-get install -y flex bison
debian9-rootfs# cd root
debian9-rootfs# mkdir src
debian9-rootfs# cd src
debian9-rootfs# git clone https://git.kernel.org/pub/scm/utils/dtc/dtc.git dtc
debian9-rootfs# cd dtc
debian9-rootfs# make
debian9-rootfs# make HOME=/usr/local install-bin
debian9-rootfs# cd /

apt-get で install される Device Tree Compiler はバージョンが古くてシンボルがサポートされていないことがあります。ここではソースコードからビルドしています。これに関しては「デバイスツリーにシンボル情報を埋め込む」を参照してください。

Linux Header and Modules のインストール

debian9-rootfs# mv    boot boot.org
debian9-rootfs# mkdir boot
debian9-rootfs# dpkg -i linux-image-4.9.0-xlnx-v2017.3-zynqmp-fpga_4.9.0-xlnx-v2017.3-zynqmp-fpga-1_arm64.deb
debian9-rootfs# dpkg -i linux-headers-4.9.0-xlnx-v2017.3-zynqmp-fpga_4.9.0-xlnx-v2017.3-zynqmp-fpga-1_arm64.deb
debian9-rootfs# rm    boot/*
debian9-rootfs# rmdir boot
debian9-rootfs# mv    boot.org boot

APT Cache の掃除

debian9-rootfs# apt-get clean

APT Cache に大量にダウンロードしたパッケージがキャッシュされていますが、そのままだと Root File System が大きくなるので、掃除して身軽にしておきます。

後始末

debian9-rootfs# exit
shell$ sudo rm -f $targetdir/usr/bin/qemu-aarch64-static
shell$ sudo rm -f $targetdir/build-debian9-rootfs-with-qemu.sh
shell$ sudo rm -f $targetdir/linux-image-4.9.0-xlnx-v2017.3-zynqmp-fpga_4.9.0-xlnx-v2017.3-zynqmp-fpga-1_arm64.deb
shell$ sudo rm -f $targetdir/linux-headers-4.9.0-xlnx-v2017.3-zynqmp-fpga_4.9.0-xlnx-v2017.3-zynqmp-fpga-1_arm64.deb

ご苦労さまでした。chroot から出て不要になったファイルを消去してください。

debian9-rootfs-vanilla.tgz の生成

shell$ cd $targetdir
shell$ sudo tar cfz ../debian9-rootfs-vanilla.tgz *

最後に作ったディレクトリを丸ごと debian9-rootfs-vanilla.tgz にまとめて完了です。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1