電気回路/zynq/Petalinux のカスタマイズ
概要†
電気回路/zynq/Petalinux のビルド の続きです。
z-turn ボード用に Petalinux から起動 SD カードを作ったのですが、
- シリアルポート番号の問題でメインコンソールが正常起動しない
- BOOT.bin と image.ub だけ、という構成は部分的な差し替えが難しいので改善したい
- その他諸々
いろいろ不満があるので解決しようと思います。
フォルダ構成†
- ~/z-turn/
- petalinux/ : petalinux SDK のルートフォルダ
- zturn-v2016.4/ : プロジェクトのルートフォルダ
- design_1_wrapper_hw_platform_1/ : vivado から export したフォルダ
主にプロジェクトのルートフォルダである ~/z-turn/zturn-v2016.4/ で作業します。
環境設定スクリプト†
- petalinux-setup というコマンドで petalinux 環境を整えられるようにした
- petalinux のコマンドは LANG=C でないと動かないので、 忘れずに LANG=C するために alias を設定した
$ alias petalinux-setup='source ~/z-turn/petalinux/settings.sh'
$ petalinux-setup
PetaLinux environment set to '/home/osamu/z-turn/petalinux'
WARNING: /bin/sh is not bash!
bash is PetaLinux recommended shell. Please set your default shell to bash.
INFO: Checking free disk space
INFO: Checking installed tools
INFO: Checking installed development libraries
INFO: Checking network and other services
$ set | grep PETA
PETALINUX=/home/osamu/z-turn/petalinux
PETALINUX_VER=2016.4
$ petalinux-^t
petalinux-boot petalinux-config petalinux-package petalinux-util
petalinux-build petalinux-create petalinux-setup
$ petalinux-^c
$ cat >> ~/.bashrc # 自動実行スクリプトに登録する
alias petalinux-setup='export LANG=C; source ~/z-turn/petalinux/settings.sh'
alias petalinux-boot='LANG=C petalinux-boot'
alias petalinux-build='LANG=C petalinux-build'
alias petalinux-config='LANG=C petalinux-config'
alias petalinux-create='LANG=C petalinux-create'
alias petalinux-package='LANG=C petalinux-package'
alias petalinux-util='LANG=C petalinux-util'
^D
パッケージング方法の変更†
Petalinux のデフォルト設定では、
- BOOT.BIN
- fsbl.elf = First Stage Boot Loader
- u-boot.bin = 初期ロジック設定?
- u-boot.elf = Second Stage Boot Loader
- design.bit = ロジック設定
- image.ub
- system.dtb = デバイスツリー設定
- uImage = カーネル
- rootfs = ルートファイルシステム
の2つのファイルに起動に必要なすべてのファイルをまとめるようになっています。
BOOT.BIN はまあこれでもいいとして、 image.ub については中の dtb, uImage, rootfs をすべて別々にしておいた方が、 個別にビルドできて便利です。
ということで、設定を変更してみます。
petalinux-config & build†
$ petalinux-setup
$ petalinux-config
Linux Components Selection --->
[Uncheck] First Stage Bootloader
Auto Config Settings --->
[Uncheck] fsbl autoconfig
Subsystem AUTO Hardware Settings --->
Advanced bootable images storage Settings --->
dtb image settings --->
image storage media --->
primary sd
Image Packing Configuration --->
Root filesystem type = SD Card
$ petalinux-build
$ petalinux-package --boot --fsbl ../design_1_wrapper_hw_platform_1/fsbl.elf --fpga images/linux/design_1_wrapper.bit --u-boot --force
$ ls -l images/linux/
-rw-rw-r-- 1 4545920 BOOT.BIN
-rw-r--r-- 1 2077787 System.map.linux
-rw-r--r-- 1 4045676 design_1_wrapper.bit
-rw-r--r-- 1 9055012 image.ub
-rw-r--r-- 1 67108864 rootfs.ext3
-rw-r--r-- 1 67108864 rootfs.ext4
-rw-r--r-- 1 5280887 rootfs.ext4.gz
-rw-r--r-- 1 13702 system.dtb
-rwxr-xr-x 1 396096 u-boot.bin
-rwxr-xr-x 1 2507500 u-boot.elf
-rw-r--r-- 1 11615732 vmlinux
-rw-r--r-- 1 3827624 zImage
UART 設定†
たぶん4つの方法があって、
- vivaldo の mio 設定で UART0 のピン配置と
UART1 のピン配置を入れ替えてしまう方法。
- これをしてしまうと、z-turn 付属の DVD から作った SD カードなどとは設定が異なってしまうので、後々ちょっとだけ 面倒かもしれない。
- devicetree で ttyPS0 と ttyPS1 を入れ替える方法
- Linux 側の設定項目を探して ttyPS1 を使ってもらう方法
- そもそも使っていない UART を off にしてしまう方法
- 問題が解決したわけでは無いので、後からこのポートを使いたいときに同じ問題が再発する。
始め3つ目を目指したのですが、bootargs の設定だけでなく、/etc/inittab も設定しなければ ならないようで、結構面倒くさい。
で、z-turn 付属の BOOT.bin, uEnv.txt, uImage から立ち上げたコンソールを見直したところ、
Debian GNU/Linux 8 debian8-zynq ttyPS0
debian8-zynq login:
となっていて、普通に ttyPS0 を使っている?!
対応する devicetree.dts を見ると、
...
chosen {
bootargs = "console=ttyPS0,115200 root=/dev/ram rw earlyprintk maxcpus=1";
linux,stdout-path = "/amba/serial@e0001000";
};
aliases {
ethernet0 = "/amba/ethernet@e000b000";
serial0 = "/amba/serial@e0001000";
serial1 = "/amba/serial@e0000000";
spi0 = "/amba/spi@e000d000";
};
...
ふむ、e0000000 を serial1 に、e0001000 を serial0 に割り当てていて、 これは 2. の方法を使っているみたい。
一方で、
$ less components/plnx_workspace/device-tree-generation/system.dts
...
chosen {
bootargs = "console=ttyPS0,115200";
};
aliases {
ethernet0 = &gem0;
serial0 = &uart1;
serial1 = &uart0;
spi0 = &qspi;
};
...
なので、やはり入れ替えられているようにも見えるのだけれど・・・
$ less components/plnx_workspace/device-tree-generation/pcw.dtsi
...
&uart0 {
device_type = "serial";
port-number = <1>;
status = "okay";
} ;
&uart1 {
device_type = "serial";
port-number = <0>;
status = "okay";
};
...
$ less components/plnx_workspace/device-tree-generation/pcw.dtsi
...
uart0: serial@e0000000 {
compatible = "xlnx,xuartps", "cdns,uart-r1p8";
status = "disabled";
clocks = <&clkc 23>, <&clkc 40>;
clock-names = "uart_clk", "pclk";
reg = <0xE0000000 0x1000>;
interrupts = <0 27 4>;
};
uart1: serial@e0001000 {
compatible = "xlnx,xuartps", "cdns,uart-r1p8";
status = "disabled";
clocks = <&clkc 24>, <&clkc 41>;
clock-names = "uart_clk", "pclk";
reg = <0xE0001000 0x1000>;
interrupts = <0 50 4>;
};
...
えーと、これ、どう見ればいいのかしら?
USB_UART が uart1:serial@e0001000 に繋がっているのは間違いなくて、 serial0 = &uart1 で serial0 に接続されているように読める?
で、chosen が console=ttyPS0,115200 のままになっているのはどうしてなのか。
git で様子を見ると、
components/plnx_workspace/device-tree-generation/plnx_arm-system.dts と~
components/plnx_workspace/device-tree-generation/system-conf.dtsi ~
は console=ttyPS1,115200 に書き換わっているのに、
components/plnx_workspace/device-tree-generation/system.dts ~
は影響を受けていない?
system.dts の冒頭のタイムスタンプは変わっているので、 コンパイルし直されていないわけでは無いみたいなのだけれど?
(ここでちょっと中断中)
あー、ところで、components は .gitignore しておくべきなんですね。
$ jed project-spec/meta-user/recipes-dt/device-tree/files/system-top.dts
$ cat project-spec/meta-user/recipes-dt/device-tree/files/system-top.dts
/dts-v1/;
/include/ "system-conf.dtsi"
/ {
chosen {
bootargs = "console=ttyPS0,115200";
};
};
inittab をいじる余地はある?†
(裏で)立ち上がった z-turn 上の linux に ssh で繋いで inittab を見てみると、
login as: root
root@10.225.225.142's password: (root)
$ cat /etc/inittab
# /etc/inittab: init(8) configuration.
# $Id: inittab,v 1.91 2002/01/25 13:35:21 miquels Exp $
# The default runlevel.
id:5:initdefault:
# Boot-time system configuration/initialization script.
# This is run first except when booting in emergency (-b) mode.
si::sysinit:/etc/init.d/rcS
# What to do in single-user mode.
~~:S:wait:/sbin/sulogin
# /etc/init.d executes the S and K scripts upon change
# of runlevel.
#
# Runlevel 0 is halt.
# Runlevel 1 is single-user.
# Runlevels 2-5 are multi-user.
# Runlevel 6 is reboot.
l0:0:wait:/etc/init.d/rc 0
l1:1:wait:/etc/init.d/rc 1
l2:2:wait:/etc/init.d/rc 2
l3:3:wait:/etc/init.d/rc 3
l4:4:wait:/etc/init.d/rc 4
l5:5:wait:/etc/init.d/rc 5
l6:6:wait:/etc/init.d/rc 6
# Normally not reached, but fallthrough in case of emergency.
z6:6:respawn:/sbin/sulogin
PS0:12345:respawn:/bin/start_getty 115200 ttyPS0
# /sbin/getty invocations for the runlevels.
#
# The "id" field MUST be the same as the last
# characters of the device (after "tty").
#
# Format:
# <id>:<runlevels>:<action>:<process>
#
1:12345:respawn:/sbin/getty 38400 tty1
$ runlevel
N 5