電気回路/z-turn/Linuxの設定 のバックアップソース(No.8)

更新

[[公開メモ]]

#contents

* z-turn 付属の SD カードにインストールされている Linux ディストリビューション [#d5836972]

付属の SD カードで z-turn を立ち上げて、

 LANG:console
 $ uname --all
  Linux localhost.localdomain 3.15.0-xilinx #9 SMP PREEMPT Tue May 26 17:26:14 CST 2015 armv7l armv7l armv7l GNU/Linux
 $ gcc --version
  gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
  Copyright (C) 2011 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 $ cat /etc/apt/sources.list
  deb http://ports.ubuntu.com/ubuntu-ports/ precise main restricted
  deb-src http://ports.ubuntu.com/ubuntu-ports/ precise main restricted
  #
  deb http://ports.ubuntu.com/ubuntu-ports/ precise-updates main restricted
  deb-src http://ports.ubuntu.com/ubuntu-ports/ precise-updates main restricted
  #
  deb http://ports.ubuntu.com/ubuntu-ports/ precise-security main restricted
  deb-src http://ports.ubuntu.com/ubuntu-ports/ precise-security main restricted

ふむ。

インストール済みのカーネルバージョンは
- 3.15.0-xilinx 

インストール済みの Ubuntu のバージョンは 
- precise (12.04LTS, Linux kernel 3.2)

こうして見ると、カーネルバージョンはそこそこ高いけれど
ディストリビューションバージョンが低い感じです。

https://ja.wikipedia.org/wiki/Ubuntu によれば precise 
はまだギリギリサポートは続いているけれど、
それも今年 2017 年の4月までなので、早めに
- trusty (14.04 LTS, Linux Kernel 3.13) あるいは 
- xenial (16.04 LTS, Linux Kernel 4.3) に

上げたいところ。

ちなみに Debian は
- wheezy が Linux 3.2
- jessie が Linux 3.16
- stretch が Linux >= 4.8

となっています。

* ゼロから Debian 8 (jessie) を入れる [#l73821e0]

Ubuntu のアップグレードも試したけれど、途中で動作が不安定になってしまったのと、
必要のないパッケージやファイルが多数含まれているのとが気になるところ。

そこで、http://www.slideshare.net/shtaxxx/debian-linux-on-zynq-setup-flow-vivado-20154#67 ~
を参考にしつつ、1から Debian 8 (jessie) をインストールしてみました。

GUI を含まない最小構成で、ルートファイルシステムは 420MB 程度になったので、
再インストールしてまっさらから始める場合にもかなり楽にできるようになりました。
(元のディスクイメージは 1.4GB くらいありました)

* 作業の流れ [#l324c49f]

Debian にはクロス開発用のインストールツールが debootstrap 
というパッケージとして提供されています。これを使うことで、
ホストPCのファイルシステム上に z-turn で使う SD カード用の
ルートファイルシステムを作成し、最後に SD カードにコピーします。

具体的な流れは以下のようになります。

+ arm エミュレータおよびツール群をインストール
+ debootstrap で最小限のファイルを用意する
+ debootstrap の2段目(arm エミュレータ)を起動
+ apt の設定
+ 必要最低限のパッケージをインストール
+ ネットワークとファイルシステムの設定
+ ユーザーの作成
+ ファイルシステムのコピー 
** arm エミュレータおよびツール群をインストール [#j604ed4d]

 LANG:console
 $ sudo apt-get install qemu-user-static debootstrap binfmt-support

** debootstrap で最小限のファイルを用意する [#vef75621]

 LANG:console
 $ mkdir ~/z-turn/rootfs
 $ export targetdir=~/z-turn/rootfs
 $ export distro=jessie
 $ sudo debootstrap --arch=armhf --foreign $distro $targetdir
 $ sudo cp /usr/bin/qemu-arm-static $targetdir/usr/bin
 $ sudo cp /etc/resolv.conf $targetdir/etc
 $ sudo chroot $targetdir

以降は ~/z-turn/rootfs をルートディレクトリとして実行されることになります。


** debootstrap の2段目(arm エミュレータ)を起動 [#i0357483]

 LANG:console
 $ export distro=jessie
 $ export LANG=C
 $ /debootstrap/debootstrap --second-stage
 $ uname -a
  Linux debian8 3.16.0-4-amd64 #1 SMP Debian 3.16.36-1+deb8u1 (2016-09-03) armv7l GNU/Linux
                                                                           ^^^^^^

以降は arm エミュレータ上で実行していることになります。

** apt の設定 [#o3545f51]

 LANG:console
 $ cat <<EOT > /etc/apt/sources.list
 deb http://ftp.jp.debian.org/debian $distro main contrib non-free
 deb-src http://ftp.jp.debian.org/debian $distro main contrib non-free
 deb http://ftp.debian.org/debian $distro-updates main contrib non-free
 deb-src http://ftp.debian.org/debian $distro-updates main contrib non-free
 deb http://security.debian.org/debian-security $distro/updates main contrib non-free
 deb-src http://security.debian.org/debian-security $distro/updates main contrib non-free
 EOT
 $ cat << EOT > /etc/apt/apt.conf.d/71-no-recommends
 APT::Install-Recommends "0";
 APT::Install-Suggests "0";
 EOT
 $ apt-get update
 $ apt-get install locales dialog
 $ dpkg-reconfigure locales
  Generating locales (this might take a while)...
    en_US.ISO-8859-1... done
    en_US.ISO-8859-15... done
    en_US.UTF-8... done
    ja_JP.EUC-JP... done
    ja_JP.UTF-8... done
  Generation complete.

** 必要最低限のパッケージをインストール [#mbd4f937]

 LANG:console
 $ apt-get install openssh-server ntpdate resolvconf sudo hwinfo ntp tcsh zsh jed
  The following extra packages will be installed:
    jed-common libbsd0 libedit2 libgpm2 libgssapi-krb5-2 libhd21 libk5crypto3 libkeyutils1
    libkrb5-3 libkrb5support0 libonig2 libopts25 libpng12-0 libslang2-modules libwrap0
    openssh-client openssh-sftp-server slsh zsh-common
  Suggested packages:
    gpm info info-browser krb5-doc krb5-user ntp-doc ssh-askpass libpam-ssh keychain
    monkeysphere rssh molly-guard ufw zsh-doc
  Recommended packages:
    krb5-locales tcpd perl lockfile-progs xauth ncurses-term
  The following NEW packages will be installed:
    hwinfo jed jed-common libbsd0 libedit2 libgpm2 libgssapi-krb5-2 libhd21 libk5crypto3
    libkeyutils1 libkrb5-3 libkrb5support0 libonig2 libopts25 libpng12-0 libslang2-modules
    libwrap0 ntp ntpdate openssh-client openssh-server openssh-sftp-server resolvconf slsh
    sudo tcsh zsh zsh-common
  0 upgraded, 28 newly installed, 0 to remove and 0 not upgraded.
  Need to get 8946 kB of archives.
  After this operation, 28.4 MB of additional disk space will be used.
  ...
  [ ok ] Starting NTP server: ntpd.
  ...
  [ ok ] Starting OpenBSD Secure Shell server: sshd.

** ネットワークとファイルシステムの設定 [#ldbd3b11]

- eth0 を DHCP でネットワーク接続
- SD カードのブート領域を /boot にマウント

 LANG:console
 $ cat /etc/network/interfaces
  # interfaces(5) file used by ifup(8) and ifdown(8)
  # Include files from /etc/network/interfaces.d:
  source-directory /etc/network/interfaces.d
 $ cat << EOT >> /etc/network/interfaces
  allow-hotplug eth0
  iface eth0 inet dhcp
  EOT
 $ echo debian8-zynq > /etc/hostname
 $ echo "127.0.0.1    debian8-zynq" >> /etc/hosts
 $ echo "/dev/mmcblk0p1  /boot auto  defaults   0   0" >> /etc/fstab

** ユーザーの作成 [#uc191ae6]

 LANG:console
 $ adduser osamu
 $ adduser osamu sudo
  Adding user `osamu' to group `sudo' ...
  Adding user osamu to group sudo
  Done.

** ファイルシステムのコピー [#kac02ea1]

以上でファイルシステムは完成しているので、SD カードへコピーすれば終了です。

以下では既存の SD カードのファイルシステムを書き換える形で
インストールしたけれど、既存ファイルの消去にとても時間が掛かるので
一旦フォーマットしてから始めた方が手早く済みそう。

SD カードへ書き込む際、
- /lib/firmware/*
- /lib/modules/*

については、カーネルに合ったバージョンを入れておかなければならないので、
カーネルコンパイル時にホストPC上の上記ディレクトリに始めからインストールしておくか、
あるいは SD カードにインストールしてあるものを残すようにする。
以下ではすでに SD カードにインストールしてあるものとして、
上記ディレクトリのみを残すようにしている。

 LANG:console
 $ exit    # chroot から抜ける
  exit
 $ ls ~/z-turn/rootfs/
  bin   dev  home  media  opt   root  sbin  sys  usr
  boot  etc  lib   mnt    proc  run   srv   tmp  var
 $ sudo mount /dev/sdf2 /mnt/sdcard2    # SD カードをマウント
 $ ls /mnt/sdcard2/usr/lib/firmware
  3com         bnx2    e100      keyspan      mts_gsm.fw  sb16        ttusb-budget
  acenic       bnx2x   edgeport  keyspan_pda  myricom     sun         vicam
  adaptec      cis     emi26     korg         ositech     tehuti      whiteheat.fw
  advansys     cpia2   emi62     matrox       qlogic      ti_3410.fw  whiteheat_loader.fw
  atmsar11.fw  cxgb3   ess       mts_cdma.fw  r128        ti_5052.fw  yam
  av7110       dsp56k  kaweth    mts_edge.fw  radeon      tigon       yamaha
 $ ls /mnt/sdcard2/lib/modules/
  3.15.0-xilinx  4.6.0+
 $ cd /mnt/sdcard2
 $ # 以下、現在インストールされているファイルを firmware, modules を除き削除する
 $ sudo mkdir trash
 $ sudo mv * trash        # 一旦全て rash へ入れて、必要なものだけ救出する
  mv: `trash' を自分自身のサブディレクトリ `trash/trash' に移動できません
 $ sudo mv trash/lib .
 $ sudo rm -rf trash      # lib だけ消さない
 $ cd lib
 $ sudo mkdir trash
 $ sudo mv * trash        # 一旦全て rash へ入れて、必要なものだけ救出する
  mv: `trash' を自分自身のサブディレクトリ `trash/trash' に移動できません
 $ sudo mv trash/firmware .
 $ sudo mv trash/modules .
 $ sudo rm -rf trash      # lib/firmware, lib/modules だけ消さない
 $ # ファイルをすべてコピーする
 $ sudo cp -a ~/z-turn/rootfs/* /mnt/sdcard2
 $ cd
 $ sudo umount /dev/sdf2
 $ df /dev/sdf2
  ファイルシス   1K-ブロック   使用  使用可 使用% マウント位置
  /dev/sdf2          7457484 420292 6635324    6% /mnt/sdcard2

使用領域は 420MB 程度となっています。

* 起動してみる [#va79b2c4]

 LANG:console
 Debian GNU/Linux 8 debian8-zynq ttyPS0
 
 debian8-zynq login: osamu
 パスワード:
 Linux debian8-zynq 4.6.0+ #1 SMP PREEMPT Thu Feb 2 21:19:10 JST 2017 armv7l
 
 The programs included with the Debian GNU/Linux system are free software;
 the exact distribution terms for each program are described in the
 individual files in /usr/share/doc/*/copyright.
 
 Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
 permitted by applicable law.
 $ uname -a
 Linux debian8-zynq 4.6.0+ #1 SMP PREEMPT Thu Feb 2 21:19:10 JST 2017 armv7l GNU/Linux
 $ sudo ifconfig
 eth0      Link encap:イーサネット  ハードウェアアドレス 00:0a:35:00:01:22
           inetアドレス:10.225.225.168 ブロードキャスト:10.225.225.255  マスク:255.255.255.0
           inet6アドレス: fe80::20a:35ff:fe00:122/64 範囲:リンク
           UP BROADCAST RUNNING MULTICAST  MTU:1500  メトリック:1
           RXパケット:8798 エラー:0 損失:588 オーバラン:0 フレーム:0
           TXパケット:324 エラー:0 損失:0 オーバラン:0 キャリア:0
       衝突(Collisions):0 TXキュー長:1000
           RXバイト:741578 (724.1 KiB)  TXバイト:26614 (25.9 KiB)
           割り込み:145 ベースアドレス:0xb000
 
 lo        Link encap:ローカルループバック
           inetアドレス:127.0.0.1 マスク:255.0.0.0
           inet6アドレス: ::1/128 範囲:ホスト
           UP LOOPBACK RUNNING  MTU:65536  メトリック:1
           RXパケット:776 エラー:0 損失:0 オーバラン:0 フレーム:0
           TXパケット:776 エラー:0 損失:0 オーバラン:0 キャリア:0
       衝突(Collisions):0 TXキュー長:1
           RXバイト:61584 (60.1 KiB)  TXバイト:61584 (60.1 KiB)
 $ lsblk
 NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
 mmcblk0     179:0    0  7.4G  0 disk
 tqmmcblk0p1 179:1    0   64M  0 part /boot
 mqmmcblk0p2 179:2    0  7.4G  0 part /
 $ date
 2017年  2月  6日 月曜日 07:07:16 UTC
 $ sudo apt-get update
  ヒット http://security.debian.org jessie/updates InRelease
  ...
  取得:4 http://ftp.debian.org jessie-updates/non-free Translation-en/DiffIndex [736 B]
  11.1 kB を 26秒 で取得しました (420 B/s)
  パッケージリストを読み込んでいます... 完了
 $ ls -l /usr/bin/qemu-arm-static
 -rwxr-xr-x 1 root root 2898728  2月  6 04:53 /usr/bin/qemu-arm-static
 $ sudo rm /usr/bin/qemu-arm-static

Shinya Takamaeda-Y さんのおかげで
あっけないほと簡単にインストールできました。

* その他設定 [#m176c9ad]

** samba を入れて /boot を共有してしまう [#q478491b]

[[管理者/smbd の設定]] も参考にしつつ

 LANG:console
 $ apt-get install samba
 $ sudo jed /etc/samba/smb.conf
    [global]
  +    # プリンタ関連の警告が出ないようにする
  +    printing = bsd
  +    load printers = no
  +    printcap name = /dev/null
    ...
    [homes]
    ...
  -    read only = yes
  +    # ホームディレクトリを書き込み可能にする
  +    read only = no
    ...
  + # /boot 以下を共有する
  + [boot]
  +    path = /boot
  +    force group = root
  +    force user = root
  +    create mode = 600
  +    directory mode = 755
  +    valid user = osamu
  +    writable = yes
 $ # samba インストール前に作られた既存ユーザーについては
 $ # 別途 samba に登録してやる必要がある
 $ sudo pdbedit -a -u osamu
  new password:
  retype new password:

これで Windows から //debian8-zynq/boot としてブート領域にアクセスが可能となり、
ネットワーク越しに内容を書き換えたい放題になります。

ロジック (*.bit) やデバイスツリー (*.dtb) を書き換えるのに
SD カードを抜き差ししなくてよくなるのでとても楽です。

* コメント・質問 [#x541d936]

#article_kcaptcha

Counter: 5716 (from 2010/06/03), today: 1, yesterday: 1