Petalinux2018.3によるzynq-7000ブート用SDカード作成

(1820d) 更新


電気回路/zynq

Petalinux 2018.3 を使って zynq-7000 用のブートSDカードを作る

電気回路/zynq/Petalinux2018.3環境を整える の続き。

以前、Petalinux 2016.4 でやった 電気回路/zynq/Petalinux のビルド#aabc4100 および 電気回路/zynq/Petalinux のカスタマイズ#p4f8f224 を新しいバージョンでやり直すことになる。

ターゲットは z-turn board で、これまで 2016.4 を使った記事をいくつか書いていた。

z-turn ボードは Petalinux により標準でサポートされている環境ではない(BSP が提供されていない)ので、 いろいろ調べながらやることになる。

目次

petalinux プロジェクトの作成

z-turn ボードに対応する BSP は配布されていないので、 zynq の汎用テンプレートを使ってプロジェクトを作る。 (BSP が配布されているシステムであればプロジェクト作成時に BSP を指定する)

プロジェクトルートに .gitignore が作られるので、 それをそのまま使うことで git による管理が形式的には可能となる。

ただし、現時点で petalinux の git 対応は完全ではないため、 プロジェクトを共有するには BSP を使った方が良い、との注意もあった。 実際、git で管理するファイルのみから全体をビルドする方法ってあるんだろうか???

多分、作業履歴を取っておく程度の意味しかない気がする。

LANG:console
$ cd
$ mkdir petalinux
$ cd petalinux
$ petalinux-create -t project --template zynq -n zturn_v2018.3
 INFO: Create project: zturn_v2018.3
 INFO: New project successfully created in /home/takeuchi/petalinux/zturn_v2018.3
$ cd zturn_v2018.3
$ ls -a
 ./  ../  .gitignore  .petalinux/  config.project  project-spec/
$ cat .gitignore
 */*/config.old
 */*/rootfs_config.old
 build/
 images/linux/
 pre-built/linux/
 .petalinux/*
 !.petalinux/metadata
 *.o
 *.jou
 *.log
 project-spec/meta-plnx-generated/
 /components/plnx_workspace
$ git init
 Initialized empty Git repository in /home/takeuchi/petalinux/zturn_v2018.3/.git/
$ git add .
$ git config --global user.email "osamu@big.jp"
$ git config --global user.name "Osamu Takeuchi"
$ git commit -m "newly created"
 [master (root-commit) 1f2a538] newly created
  22 files changed, 997 insertions(+)

config.project と project-spec/ とがプロジェクトの本体になる。

vivado のハードウェア設定を取り込みつつ基本の設定

vivado のハードウェア設定を出力する の手順で vivado 2018.3 を使って design_1_wrapper.hdf を作成して、zturn_v2018.3/hw_platform/design_1_wrapper.hdf に置いた。 (.hdf ファイルの実体は主要ファイルを .zip 形式でまとめたもの。拡張子を .zip に変えると中味を見られる)

実は hdf ファイルを出力する前に vivado 上で ZYNQ7 Processor System の SDIO Clock を 50MHz にしておかなければダメだった

LANG:console
$ ls hw_platform/
 design_1_wrapper.hdf 
$ petalinux-config --get-hw-description=hw_platform
 INFO: Getting hardware description...
 [INFO] generating Kconfig for project
 [INFO] menuconfig project
 (設定画面が現れる → とりあえず何も変更せずに Exit して設定を保存する)
 configuration written to /home/takeuchi/petalinux/zturn_v2018.3/project-spec/configs/config
 
 *** End of the configuration.
 *** Execute 'make' to start the build or try 'make help'.
 
 [INFO] sourcing bitbake
 [INFO] generating plnxtool conf
 [INFO] generating meta-plnx-generated layer
 [INFO] generating machine configuration
 [INFO] generating bbappends for project . This may take time !
 [INFO] generating u-boot configuration files
 [INFO] generating kernel configuration files
 [INFO] generating kconfig for Rootfs
 [INFO] oldconfig rootfs
 [INFO] generating petalinux-user-image.bb
$ ls
 build/  components/  config.project  hw_platform/  project-spec/
$ ls build/
 bitbake-cookerdaemon.log  cache/  conf/  config.log  misc/  sstate-cache/  tmp/
$ git add .
$ git commit -m "configured as default"
 [master 3c376ac] configured as default
  12 files changed, 173923 insertions(+), 25 deletions(-)
  create mode 100644 .petalinux/metadata
  create mode 100644 hw_platform/design_1_wrapper.hdf
  create mode 100644 project-spec/hw-description/design_1_wrapper.bit
  create mode 100644 project-spec/hw-description/ps7_init.c
  create mode 100644 project-spec/hw-description/ps7_init.h
  create mode 100644 project-spec/hw-description/ps7_init.html
  create mode 100644 project-spec/hw-description/ps7_init.tcl
  create mode 100644 project-spec/hw-description/ps7_init_gpl.c
  create mode 100644 project-spec/hw-description/ps7_init_gpl.h
  create mode 100644 project-spec/hw-description/system.hdf

とりあえず何も変更せずに Exit し、git へ登録した。

罫線の表示がおかしい

設定画面が現れたのだけれど・・・そのままだと罫線部分が文字化けする。

petalinux-config1.png

https://islandcnt.exblog.jp/16849117/ の "-YaSTのライン化け-" にあるように、 PuTTY の設定で Charactor set を use font encording にすればいいらしい。

petalinux-config2.png

ただこれだと LANG=ja_JP.UTF-8 での日本語表示がおかしくなる。

http://totech.hateblo.jp/entry/2014/09/22/071012 にあるように ja_JP.sjis ロケールを追加して、

LANG:console
$ sudo localedef -f SHIFT_JIS -i ja_JP ja_JP.SJIS
 character map `SHIFT_JIS' is not ASCII compatible, locale not ISO C compliant
$ export LANG=ja_JP.sjis
 takeuchi@petalinux2019-3:~/petalinux/zturn_v2018.3$ ls -l
 合計 28
 drwxrwxr-x 7 takeuchi takeuchi 4096  3月 15 20:38 build
 drwxrwxr-x 3 takeuchi takeuchi 4096  3月 15 20:31 components
 -rw-r--r-- 1 takeuchi takeuchi  248  3月 15 20:14 config.project
 drwxrwxr-x 2 takeuchi takeuchi 4096  3月 15 20:30 hw_platform
 drwxr-xr-x 6 takeuchi takeuchi 4096  3月 15 20:36 project-spec

のようにすれば文字化けはなくなるのだけれど・・・今時 Linux ターミナルで SJIS 使うのはどうなのかと。

LANG=C で進めるか、その都度 PuTTY の設定を変える方がよいのかもしれない。

ロケール問題再び?

ああそういえば、以前試したときは 電気回路/zynq/Petalinux のビルド#y0c5addb で痛い目に遭ったように、Petalinux 自体が LANG=C 以外だとおかしな事になるという 問題があったんだった。

今はどうかというと、、、

LANG:console
$ export LANG=ja_JP.sjis
$ petalinux-build -c kernel
 [INFO] building kernel
 [INFO] sourcing bitbake
 INFO: bitbake virtual/kernel
 Please use a locale setting which supports UTF-8 (such as LANG=en_US.UTF-8).
 Python can't change the filesystem locale after loading so we need a UTF-8 when Python starts or things won't work.
 ERROR: Failed to build kernel

のように、自ら検出してエラーを出してくれるようになっていた。

あれ?エラーメッセージを読むと UTF-8 なら問題ないと書いてある???

というかむしろ、

LANG:console
$ export LANG=C
$ petalinux-build -c kernel
 [INFO] building kernel
 [INFO] sourcing bitbake
 INFO: bitbake virtual/kernel
 Please use a locale setting which supports UTF-8 (such as LANG=en_US.UTF-8).
 Python can't change the filesystem locale after loading so we need a UTF-8 when Python starts or things won't work.
 ERROR: Failed to build kernel

LANG=C だと UTF-8 が処理できないのでダメらしい。

暗号化ファイルシステムの問題

ということは、LANG=ja_JP.UTF-8 なら問題ない?

LANG:console
$ export LANG=ja_JP.UTF-8
$ petalinux-build -c kernel
 [INFO] building kernel
 [INFO] sourcing bitbake
 INFO: bitbake virtual/kernel
 ERROR:  OE-core's config sanity checker detected a potential misconfiguration.
     Either fix the cause of this error or at your own risk disable the checker (see sanity.conf).
     Following is the list of potential problems / advisories:
 
     Failed to create a file with a long name in TMPDIR. Please use a filesystem that does not unreasonably limit filename length.
 Failed to create a file with a long name in SSTATE_DIR. Please use a filesystem that does not unreasonably limit filename length.

 Summary: There was 1 ERROR message shown, returning a non-zero exit code.
ERROR: Failed to build kernel

今度は長いファイル名を使えないのがダメと言われた。

うわーこれきついや。

仕方がないので ホームディレクトリ暗号化の解除 の手順で暗号化を解除した。

すると、

LANG:console
$ source /opt/petalinux_2018.3/settings.sh
$ petalinux-build -c kernel
 [INFO] building kernel
 [INFO] sourcing bitbake
 INFO: bitbake virtual/kernel
 Parsing recipes:   5%

のようにビルドが進むようになった。

LANG=ja_JP.UTF-8 のままで大丈夫みたいだ。

WARNING は出たけど build できた

LANG:console
$ petalinux-build -c kernel
 ...
  WARNING: petalinux-user-image-1.0-r0 do_rootfs: [log_check] petalinux-user-image: found 1 warning message in the logfile:
 [log_check] warning: %post(sysvinit-inittab-2.88dsf-r10.plnx_zynq7) scriptlet failed, exit status 1
 
 NOTE: Tasks Summary: Attempted 2350 tasks of which 2122 didn't need to be rerun and all succeeded.
 
 Summary: There was 1 WARNING message shown.
 INFO: Copying Images from deploy to images
 INFO: Creating images/linux directory
 NOTE: Failed to copy built images to tftp dir:  /tftpboot
 [INFO] successfully built kernel
$ grep sysvinit-inittab build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/petalinux-user-image/1.0-r0/temp/log.do_rootfs
 sysvinit-inittab                plnx_zynq7      2.88dsf-r10      oe-repo 7.5 k
 sysvinit-inittab-lic            plnx_zynq7      2.88dsf-r10      oe-repo  12 k
  Installing       : sysvinit-inittab-2.88dsf-r10.plnx_zynq7             69/122
  Running scriptlet: sysvinit-inittab-2.88dsf-r10.plnx_zynq7             69/122
warning: %post(sysvinit-inittab-2.88dsf-r10.plnx_zynq7) scriptlet failed, exit status 1
  Installing       : sysvinit-inittab-lic-2.88dsf-r10.plnx_zynq7        117/122
  Verifying        : sysvinit-inittab-2.88dsf-r10.plnx_zynq7             79/122
  Verifying        : sysvinit-inittab-lic-2.88dsf-r10.plnx_zynq7         94/122
  sysvinit-inittab-lic.plnx_zynq7 2.88dsf-r10
  sysvinit-inittab.plnx_zynq7 2.88dsf-r10
Non-fatal POSTIN scriptlet failure in rpm package sysvinit-inittab
Non-fatal POSTIN scriptlet failure in rpm package sysvinit-inittab
NOTE: Saving postinstall script of sysvinit-inittab
NOTE: Delayed package scriptlet: 100-sysvinit-inittab
[log_check] warning: %post(sysvinit-inittab-2.88dsf-r10.plnx_zynq7) scriptlet failed, exit status 1

Non-fatal となっているので、無視しても良いってことかしら???

以下のように、全体のビルドも問題なかった。

LANG:console
$ petalinux-build
 ...

 NOTE: Tasks Summary: Attempted 3065 tasks of which 2474 didn't need to be rerun and all succeeded.
 INFO: Copying Images from deploy to images
 NOTE: Failed to copy built images to tftp dir:  /tftpboot
 [INFO] successfully built project
$ ls images/linux/
 image.ub         rootfs.cpio.gz         rootfs.ext4     rootfs.manifest       system.bit        u-boot.elf
 rootfs.bin       rootfs.cpio.gz.u-boot  rootfs.ext4.gz  rootfs.tar.bz2        system.dtb        vmlinux
 rootfs.cpio      rootfs.ext3            rootfs.its      rootfs.tar.gz         System.map.linux  zImage
 rootfs.cpio.bz2  rootfs.ext3.bz2        rootfs.jffs2    rootfs.testdata.json  u-boot.bin        zynq_fsbl.elf

いろいろとできていることを確認できる。

古い .hdf だとエラーが出た

同じソースから vivado 2016.4 で作成した hdf を与えた場合には "Unable to find ps7 init files" というエラーが出た。

新しいバージョンで作り直さないとダメみたい。

LANG:console
$ petalinux-build -c kernel
 [INFO] building kernel
 [INFO] sourcing bitbake
 INFO: bitbake virtual/kernel
 Loading cache: 100% |############################################| Time: 0:00:03
 Loaded 3444 entries from dependency cache.
 Parsing recipes: 100% |##########################################| Time: 0:00:31
 Parsing of 2569 .bb files complete (2532 cached, 37 parsed). 3445 targets, 149 skipped, 0 masked, 0 errors.
 NOTE: Resolving any missing task queue dependencies
 Initialising tasks: 100% |#######################################| Time: 0:00:21
 Checking sstate mirror object availability: 100% |###############| Time: 0:00:46
 NOTE: Executing SetScene Tasks
 NOTE: Executing RunQueue Tasks
 WARNING: petalinux-user-image-1.0-r0 do_rootfs: [log_check] petalinux-user-image: found 1 warning message in the logfile:
 [log_check] warning: %post(sysvinit-inittab-2.88dsf-r10.plnx_zynq7) scriptlet failed, exit status 1
 
 ERROR: fsbl-2018.3+gitAUTOINC+56f3da2afb-r0 do_configure: Function failed: do_configure (log file is located at /home/takeuchi/petalinux/zturn_v2018.3/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/fsbl/2018.3+gitAUTOINC+56f3da2afb-r0/temp/log.do_configure.5645)
 ERROR: Logfile of failure stored in: /home/takeuchi/petalinux/zturn_v2018.3/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/fsbl/2018.3+gitAUTOINC+56f3da2afb-r0/temp/log.do_configure.5645
 Log data follows:
 | DEBUG: Executing shell function do_configure
 | MISC_ARG is  -yamlconf /home/takeuchi/petalinux/zturn_v2018.3/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/fsbl/2018.3+gitAUTOINC+56f3da2afb-r0/fsbl.yaml
 | APP_ARG is  -app "Zynq FSBL"
 | Using xsct from: /opt/petalinux_2018.3/tools/xsct/SDK/2018.3/bin/xsct
 | cmd is: xsct -sdx -nodisp /home/takeuchi/petalinux/zturn_v2018.3/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/fsbl/2018.3+gitAUTOINC+56f3da2afb-r0/app.tcl -ws /home/takeuchi/petalinux/zturn_v2018.3/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/fsbl/2018.3+gitAUTOINC+56f3da2afb-r0/build -pname fsbl -rp /home/takeuchi/petalinux/zturn_v2018.3/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/fsbl/2018.3+gitAUTOINC+56f3da2afb-r0/git -processor ps7_cortexa9_0 -hdf /home/takeuchi/petalinux/zturn_v2018.3/build/tmp/deploy/images/plnx-zynq7/Xilinx-plnx-zynq7.hdf -arch 32  -app "Zynq FSBL"  -yamlconf /home/takeuchi/petalinux/zturn_v2018.3/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/fsbl/2018.3+gitAUTOINC+56f3da2afb-r0/fsbl.yaml
 | INFO: [Hsi 55-1698] elapsed time for repository loading 0 seconds
 | Opening the hardware design, this may take few seconds.
 | ERROR: [Hsi 55-1606] Unable to find ps7 init files in the directory /home/takeuchi/petalinux/zturn_v2018.3/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/fsbl/2018.3+gitAUTOINC+56f3da2afb-r0/build/fsbl_plat/_platform/dsa.
 | INFO: create bsp using fsbl_domain
 | Creating app at: /home/takeuchi/petalinux/zturn_v2018.3/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/fsbl/2018.3+gitAUTOINC+56f3da2afb-r0/build
 | ERROR: [Hsi 55-1606] Unable to find ps7 init files in the directory /home/takeuchi/petalinux/zturn_v2018.3/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/fsbl/2018.3+gitAUTOINC+56f3da2afb-r0/build/fsbl_plat/_platform/dsa.
 | ERROR: [Hsi 55-1438] Error running generate_app.
 | ERROR: [Common 17-39] 'hsi::generate_app' failed due to earlier errors.
 |
 |     while executing
 | "::hsi::generate_app -app $hsitemplate"
 |     (procedure "app" line 323)
 |     invoked from within
 | "app create -name $params(pname) -lang c -template $params(app) -plnx"
 |     invoked from within
 | "if { $params(ws) ne "" } {
 |       #Local Work Space available
 |       if { $params(pname) ne "" } {
 |               # hwpname/bspname is empty then default it to pname+_hwproj/b..."
 |     (file "/home/takeuchi/petalinux/zturn_v2018.3/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/fsbl/2018.3+gitAUTOINC+56f3da2afb-r0/app.tcl" line 139)
 | WARNING: exit code 1 from a shell command.
 | ERROR: Function failed: do_configure (log file is located at /home/takeuchi/petalinux/zturn_v2018.3/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/fsbl/2018.3+gitAUTOINC+56f3da2afb-r0/temp/log.do_configure.5645)
 ERROR: Task (/opt/petalinux_2018.3/components/yocto/source/arm/layers/meta-xilinx-tools/recipes-bsp/fsbl/fsbl_git.bb:do_configure) failed with exit code '1'
 NOTE: Tasks Summary: Attempted 2330 tasks of which 2115 didn't need to be rerun and 1 failed.
 
 Summary: 1 task failed:
   /opt/petalinux_2018.3/components/yocto/source/arm/layers/meta-xilinx-tools/recipes-bsp/fsbl/fsbl_git.bb:do_configure
 Summary: There was 1 WARNING message shown.
 Summary: There was 1 ERROR message shown, returning a non-zero exit code.
 ERROR: Failed to build kernel
$ ls /home/takeuchi/petalinux/zturn_v2018.3/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/fsbl/2018.3+gitAUTOINC+56f3da2afb-r0/temp/run.do_configure
 /home/takeuchi/petalinux/zturn_v2018.3/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/fsbl/2018.3+gitAUTOINC+56f3da2afb-r0/temp/run.do_configure
$ ls /home/takeuchi/petalinux/zturn_v2018.3/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/fsbl/2018.3+gitAUTOINC+56f3da2afb-r0/build/fsbl_plat/_platform/dsa
 Xilinx-plnx-zynq7.dsa  Xilinx-plnx-zynq7.hdf

BOOT.BIN の作成

LANG:console
$ petalinux-package --boot --fsbl images/linux/zynq_fsbl.elf --fpga  images/linux/system.bit --u-boot --force
 INFO: File in BOOT BIN: "/home/takeuchi/petalinux/zturn_v2018.3/images/linux/zynq_fsbl.elf"
 INFO: File in BOOT BIN: "/home/takeuchi/petalinux/zturn_v2018.3/images/linux/system.bit"
 INFO: File in BOOT BIN: "/home/takeuchi/petalinux/zturn_v2018.3/images/linux/u-boot.elf"
 INFO: Generating Zynq binary package BOOT.BIN...
 
 
 ****** Xilinx Bootgen v2018.3
   **** Build date : Nov 15 2018-19:22:29
     ** Copyright 1986-2018 Xilinx, Inc. All Rights Reserved.
 
 INFO: Binary is ready.
 WARNING: Unable to access the TFTPBOOT folder /tftpboot!!!
 WARNING: Skip file copy to TFTPBOOT folder!!!
$ ls
 build  components  config.project  hw_platform  hw_platform_old  images  project-spec
$ ls images/linux/
 BOOT.BIN     rootfs.cpio.bz2        rootfs.ext3.bz2  rootfs.jffs2     rootfs.testdata.json  u-boot.bin  zynq_fsbl.elf
 image.ub     rootfs.cpio.gz         rootfs.ext4      rootfs.manifest  system.bit            u-boot.elf
 rootfs.bin   rootfs.cpio.gz.u-boot  rootfs.ext4.gz   rootfs.tar.bz2   system.dtb            vmlinux
 rootfs.cpio  rootfs.ext3            rootfs.its       rootfs.tar.gz    System.map.linux      zImage

昔と違って カレントフォルダに BOOT.BIN が生成されてしまうこと はなくなったみたい。

SD カードに書き込んで試す

電気回路/z-turn/VirtualBox に Debia8 を入れる#g8dc93aa の手順 (USB3.0 に繋いだカードリーダーでは一手間必要なのだった)で VirtualBox から SD カードへアクセスできるようにして、

LANG:console
$ lsblk
 NAME                            MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
 sda                               8:0    0   100G  0 disk
 ├─sda1                            8:1    0   731M  0 part  /boot
 ├─sda2                            8:2    0     1K  0 part
 └─sda5                            8:5    0  99.3G  0 part
   ├─petalinux2019--3--vg-root   252:0    0  98.3G  0 lvm   /
   └─petalinux2019--3--vg-swap_1 252:1    0   976M  0 lvm
     └─cryptswap1                252:2    0 975.5M  0 crypt [SWAP]
 sdf                               8:80   1   3.7G  0 disk
 ├─sdf1                            8:81   1 196.1M  0 part
 └─sdf2                            8:82   1   3.5G  0 part
 sr0                              11:0    1  1024M  0 rom
$ ls /mnt
$ sudo mkdir /mnt/sdcard1 /mnt/sdcard2
$ sudo mount /dev/sdf1 /mnt/sdcard1
$ ls 
 ... (消していい内容であることを確認)

$ sudo mount /dev/sdf2 /mnt/sdcard2
$ ls 
 ... (消していい内容であることを確認)

$ sudo umount /mnt/sdcard?

まっさらな FAT パーティションおよび ext4 パーティションを作成

LANG:console
$ sudo fdisk /dev/sdf
   p (print)
   d (delete) 1  # 必要に応じて
   d (delete) 2  # 必要に応じて
   n (new) p (primary) 1 ret (start=default) +64M (size)
   n (new) p (primary) 2 retrn (start=default) return (size=default)
   t (type) 1 b (W95 FAT32)
   a (bootable) 1
   p (print)

 デバイス   起動  Start 最後から セクタ  Size Id タイプ
 /dev/sdf1  *      2048   264191  262144  128M  b W95 FAT32
 /dev/sdf2       264192  7744511 7480320  3.6G 83 Linux

   w (write & exit)
$ lsblk
 NAME                            MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
 ...
 sdf                               8:80   1   3.7G  0 disk
 ├─sdf1                            8:81   1   128M  0 part
 └─sdf2                            8:82   1   3.6G  0 part
 ...
$ sudo mkfs.msdos -n BOOT /dev/sdf1
$ sudo mkfs.ext4  -L ROOT /dev/sdf2

http://engineernote.hatenablog.com/entry/2016/01/31/012227

によると、

BOOT.binはbitstreamとFSBL、u-bootをひとつのバイナリに結合したもので、image.ubはkernelとrootfs、デバイスツリーのようです。

とのことなので、まっさらな FAT フォーマットの SD カードに BOOT.bin と image.ub だけ入れればいい。

LANG:console
$ sudo mount /dev/sdf1 /mnt/sdcard1
$ sudo cp images/linux/BOOT.BIN images/linux/image.ub /mnt/sdcard1
$ sudo umount /dev/sdf1

これでいいはず。

SDIO Clock = 50MHz にしないとだめだった

上でもちょっと書いたけれど 「電気回路/zynq/最新の fsbl で Linux が起動しない理由を調べる」 で判明したのと同じ原因で、 .hdf を作る際に ZYNQ7 Processor System の設定で SDIO Clock を 50MHz にしないとまったくうんともすんとも言わなかった。

sdio-clock-50MHz.png

起動した

以下は、USB_UART に USB ケーブルを繋ぎ、Tera Term で COM6 を見ながら z-turn board をリセットした際に表示された起動メッセージ。

LANG:console
U-Boot 2018.01 (Mar 19 2019 - 03:03:19 +0000) Xilinx Zynq ZC702

Board: Xilinx Zynq
Silicon: v3.1
I2C:   ready
DRAM:  ECC disabled 1 GiB
MMC:   mmc@e0100000: 0 (SD)
SF: Detected w25q128bv with page size 256 Bytes, erase size 4 KiB, total 16 MiB
*** Warning - bad CRC, using default environment

## Error: flags type check failure for "serverip" <= "AUTO" (type: i)
himport_r: can't insert "serverip=AUTO" into hash table
In:    serial@e0001000
Out:   serial@e0001000
Err:   serial@e0001000
Board: Xilinx Zynq
Silicon: v3.1
Net:   ZYNQ GEM: e000b000, phyaddr ffffffff, interface rgmii-id
eth0: ethernet@e000b000
U-BOOT for zturn_v2018.3

ethernet@e000b000 Waiting for PHY auto negotiation to complete......... TIMEOUT !
Hit any key to stop autoboot:  0
Device: mmc@e0100000
Manufacturer ID: 3
OEM: 5344
Name: SU04G
Tran Speed: 50000000
Rd Block Len: 512
SD version 3.0
High Capacity: Yes
Capacity: 3.7 GiB
Bus Width: 4-bit
Erase Group Size: 512 Bytes
reading image.ub
10000404 bytes read in 559 ms (17.1 MiB/s)
## Loading kernel from FIT Image at 10000000 ...
   Using 'conf@system-top.dtb' configuration
   Verifying Hash Integrity ... OK
   Trying 'kernel@1' kernel subimage
     Description:  Linux kernel
     Type:         Kernel Image
     Compression:  gzip compressed
     Data Start:   0x10000104
     Data Size:    3941035 Bytes = 3.8 MiB
     Architecture: ARM
     OS:           Linux
     Load Address: 0x00008000
     Entry Point:  0x00008000
     Hash algo:    sha1
     Hash value:   70dd39c3d4c46f9073ba1a881abb498a1bfd9191
   Verifying Hash Integrity ... sha1+ OK
## Loading ramdisk from FIT Image at 10000000 ...
   Using 'conf@system-top.dtb' configuration
   Trying 'ramdisk@1' ramdisk subimage
     Description:  petalinux-user-image
     Type:         RAMDisk Image
     Compression:  gzip compressed
     Data Start:   0x103c5ca4
     Data Size:    6043105 Bytes = 5.8 MiB
     Architecture: ARM
     OS:           Linux
     Load Address: unavailable
     Entry Point:  unavailable
     Hash algo:    sha1
     Hash value:   a9a00f2e7dda4f17404055e7afa2b3244ca7afd9
   Verifying Hash Integrity ... sha1+ OK
## Loading fdt from FIT Image at 10000000 ...
   Using 'conf@system-top.dtb' configuration
   Trying 'fdt@system-top.dtb' fdt subimage
     Description:  Flattened Device Tree blob
     Type:         Flat Device Tree
     Compression:  uncompressed
     Data Start:   0x103c24b0
     Data Size:    14132 Bytes = 13.8 KiB
     Architecture: ARM
     Hash algo:    sha1
     Hash value:   d1094e4d7bd40491e9cae7952924c378a7d2d1b0
   Verifying Hash Integrity ... sha1+ OK
   Booting using the fdt blob at 0x103c24b0
   Uncompressing Kernel Image ... OK
   Loading Ramdisk to 07a3c000, end 07fff5e1 ... OK
   Loading Device Tree to 07a35000, end 07a3b733 ... OK

Starting kernel ...

Booting Linux on physical CPU 0x0
Linux version 4.14.0-xilinx-v2018.3 (oe-user@oe-host) (gcc version 7.3.0 (GCC)) #1 SMP PREEMPT Mon Mar 18 15:35:06 UTC 2019
CPU: ARMv7 Processor [413fc090] revision 0 (ARMv7), cr=18c5387d
CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
OF: fdt: Machine model: xlnx,zynq-7000
bootconsole [earlycon0] enabled
Memory policy: Data cache writealloc
cma: Reserved 16 MiB at 0x3f000000
percpu: Embedded 16 pages/cpu @ef7ce000 s34764 r8192 d22580 u65536
Built 1 zonelists, mobility grouping on.  Total pages: 260608
Kernel command line: console=ttyPS0,115200 earlyprintk
PID hash table entries: 4096 (order: 2, 16384 bytes)
Dentry cache hash table entries: 131072 (order: 7, 524288 bytes)
Inode-cache hash table entries: 65536 (order: 6, 262144 bytes)
Memory: 1006984K/1048576K available (6144K kernel code, 238K rwdata, 1564K rodata, 1024K init, 152K bss, 25208K reserved, 16384K cma-reserved, 245760K highmem)
Virtual kernel memory layout:
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)
    fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
    vmalloc : 0xf0800000 - 0xff800000   ( 240 MB)
    lowmem  : 0xc0000000 - 0xf0000000   ( 768 MB)
    pkmap   : 0xbfe00000 - 0xc0000000   (   2 MB)
    modules : 0xbf000000 - 0xbfe00000   (  14 MB)
      .text : 0xc0008000 - 0xc0700000   (7136 kB)
      .init : 0xc0900000 - 0xc0a00000   (1024 kB)
      .data : 0xc0a00000 - 0xc0a3b880   ( 239 kB)
       .bss : 0xc0a3b880 - 0xc0a61bc4   ( 153 kB)
Preemptible hierarchical RCU implementation.
        RCU restricting CPUs from NR_CPUS=4 to nr_cpu_ids=2.
        Tasks RCU enabled.
RCU: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=2
NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
efuse mapped to f0802000
slcr mapped to f0804000
L2C: platform modifies aux control register: 0x72360000 -> 0x72760000
L2C: DT/platform modifies aux control register: 0x72360000 -> 0x72760000
L2C-310 erratum 769419 enabled
L2C-310 enabling early BRESP for Cortex-A9
L2C-310 full line of zeros enabled for Cortex-A9
L2C-310 ID prefetch enabled, offset 1 lines
L2C-310 dynamic clock gating enabled, standby mode enabled
L2C-310 cache controller enabled, 8 ways, 512 kB
L2C-310: CACHE_ID 0x410000c8, AUX_CTRL 0x76760001
zynq_clock_init: clkc starts at f0804100
Zynq clock init
sched_clock: 64 bits at 333MHz, resolution 3ns, wraps every 4398046511103ns
clocksource: arm_global_timer: mask: 0xffffffffffffffff max_cycles: 0x4ce07af025, max_idle_ns: 440795209040 ns
Switching to timer-based delay loop, resolution 3ns
clocksource: ttc_clocksource: mask: 0xffff max_cycles: 0xffff, max_idle_ns: 537538477 ns
timer #0 at f080c000, irq=17
Console: colour dummy device 80x30
Calibrating delay loop (skipped), value calculated using timer frequency.. 666.66 BogoMIPS (lpj=3333333)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 2048 (order: 1, 8192 bytes)
Mountpoint-cache hash table entries: 2048 (order: 1, 8192 bytes)
CPU: Testing write buffer coherency: ok
CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
Setting up static identity map for 0x100000 - 0x100060
Hierarchical SRCU implementation.
smp: Bringing up secondary CPUs ...
CPU1: thread -1, cpu 1, socket 0, mpidr 80000001
smp: Brought up 1 node, 2 CPUs
SMP: Total of 2 processors activated (1333.33 BogoMIPS).
CPU: All CPU(s) started in SVC mode.
devtmpfs: initialized
random: get_random_u32 called from bucket_table_alloc+0x1c4/0x204 with crng_init=0
VFP support v0.3: implementor 41 architecture 3 part 30 variant 9 rev 4
clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
futex hash table entries: 512 (order: 3, 32768 bytes)
pinctrl core: initialized pinctrl subsystem
random: fast init done
NET: Registered protocol family 16
DMA: preallocated 256 KiB pool for atomic coherent allocations
cpuidle: using governor menu
hw-breakpoint: found 5 (+1 reserved) breakpoint and 1 watchpoint registers.
hw-breakpoint: maximum watchpoint size is 4 bytes.
zynq-ocm f800c000.ocmc: ZYNQ OCM pool: 256 KiB @ 0xf0880000
zynq-pinctrl 700.pinctrl: zynq pinctrl initialized
e0000000.serial: ttyPS1 at MMIO 0xe0000000 (irq = 28, base_baud = 6249999) is a xuartps
e0001000.serial: ttyPS0 at MMIO 0xe0001000 (irq = 29, base_baud = 6249999) is a xuartps
・onsole [ttyPS0] enabled
console [ttyPS0] enabled
bootconsole [earlycon0] disabled
bootconsole [earlycon0] disabled
vgaarb: loaded
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
media: Linux media interface: v0.10
Linux video capture interface: v2.00
pps_core: LinuxPPS API ver. 1 registered
pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
PTP clock support registered
EDAC MC: Ver: 3.0.0
FPGA manager framework
fpga-region fpga-full: FPGA Region probed
Advanced Linux Sound Architecture Driver Initialized.
clocksource: Switched to clocksource arm_global_timer
NET: Registered protocol family 2
TCP established hash table entries: 8192 (order: 3, 32768 bytes)
TCP bind hash table entries: 8192 (order: 4, 65536 bytes)
TCP: Hash tables configured (established 8192 bind 8192)
UDP hash table entries: 512 (order: 2, 16384 bytes)
UDP-Lite hash table entries: 512 (order: 2, 16384 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
Trying to unpack rootfs image as initramfs...
Freeing initrd memory: 5904K
hw perfevents: no interrupt-affinity property for /pmu@f8891000, guessing.
hw perfevents: enabled with armv7_cortex_a9 PMU driver, 7 counters available
workingset: timestamp_bits=30 max_order=18 bucket_order=0
jffs2: version 2.2. (NAND) (SUMMARY)  c 2001-2006 Red Hat, Inc.
bounce: pool size: 64 pages
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
io scheduler mq-deadline registered
io scheduler kyber registered
dma-pl330 f8003000.dmac: Loaded driver for PL330 DMAC-241330
dma-pl330 f8003000.dmac:        DBUFF-128x8bytes Num_Chans-8 Num_Peri-4 Num_Events-16
brd: module loaded
loop: module loaded
m25p80 spi0.0: found w25q128, expected n25q512a
m25p80 spi0.0: w25q128 (16384 Kbytes)
4 ofpart partitions found on MTD device spi0.0
Creating 4 MTD partitions on "spi0.0":
0x000000000000-0x000000500000 : "boot"
0x000000500000-0x000000520000 : "bootenv"
0x000000520000-0x000000fa0000 : "kernel"
0x000000fa0000-0x000001000000 : "spare"
libphy: Fixed MDIO Bus: probed
CAN device driver interface
libphy: MACB_mii_bus: probed
macb e000b000.ethernet eth0: Cadence GEM rev 0x00020118 at 0xe000b000 irq 31 (00:0a:35:00:1e:53)
Generic PHY e000b000.ethernet-ffffffff:00: attached PHY driver [Generic PHY] (mii_bus:phy_addr=e000b000.ethernet-ffffffff:00, irq=POLL)
e1000e: Intel(R) PRO/1000 Network Driver - 3.2.6-k
e1000e: Copyright(c) 1999 - 2015 Intel Corporation.
ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
ehci-pci: EHCI PCI platform driver
usbcore: registered new interface driver usb-storage
i2c /dev entries driver
cdns-i2c e0004000.i2c: 400 kHz mmio e0004000 irq 24
cdns-i2c e0005000.i2c: 400 kHz mmio e0005000 irq 25
IR NEC protocol handler initialized
IR RC5(x/sz) protocol handler initialized
IR RC6 protocol handler initialized
IR JVC protocol handler initialized
IR Sony protocol handler initialized
IR SANYO protocol handler initialized
IR Sharp protocol handler initialized
IR MCE Keyboard/mouse protocol handler initialized
IR XMP protocol handler initialized
cdns-wdt f8005000.watchdog: Xilinx Watchdog Timer at f098d000 with timeout 10s
EDAC MC: ECC not enabled
Xilinx Zynq CpuIdle Driver started
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
sdhci-pltfm: SDHCI platform and OF driver helper
mmc0: SDHCI controller on e0100000.mmc [e0100000.mmc] using ADMA
ledtrig-cpu: registered to indicate activity on CPUs
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
fpga_manager fpga0: Xilinx Zynq FPGA Manager registered
NET: Registered protocol family 10
Segment Routing with IPv6
sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
NET: Registered protocol family 17
can: controller area network core (rev 20170425 abi 9)
NET: Registered protocol family 29
can: raw protocol (rev 20170425)
can: broadcast manager protocol (rev 20170425 t)
can: netlink gateway (rev 20170425) max_hops=1
Registering SWP/SWPB emulation handler
hctosys: unable to open rtc device (rtc0)
of_cfs_init
of_cfs_init: OK
ALSA device list:
  No soundcards found.
Freeing unused kernel memory: 1024K
mmc0: new high speed SDHC card at address aaaa
mmcblk0: mmc0:aaaa SU04G 3.69 GiB
INIT:  mmcblk0: p1 p2
version 2.88 booting
Starting udev
udevd[743]: starting version 3.2.2
udevd[744]: starting eudev-3.2.2
EXT4-fs (mmcblk0p2): recovery complete
EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
FAT-fs (mmcblk0p1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
hwclock: can't open '/dev/misc/rtc': No such file or directory
Tue Mar 19 03:03:03 UTC 2019
hwclock: can't open '/dev/misc/rtc': No such file or directory
Starting internet superserver: inetd.
Configuring packages on first boot....
 (This may take several minutes. Please do not power off the machine.)
Running postinst /etc/rpm-postinsts/100-sysvinit-inittab...
update-rc.d: /etc/init.d/run-postinsts exists during rc.d purge (continuing)
 Removing any system startup links for run-postinsts ...
  /etc/rcS.d/S99run-postinsts
INIT: Entering runlevel: 5
Configuring network interfaces... IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
udhcpc (v1.24.1) started
Sending discover...
Sending discover...
Sending discover...
No lease, forking to background
done.
Starting Dropbear SSH server: Generating key, this may take a while...
Public key portion is:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCaB+HRMpl/uuag+WGIACkJu6SU3hMa+RZ/qA/7PCELRCDQF7mFLm0nYYh/ZRwmU+WRf1W+Aef17A4Mvuv8tJPq/FLgeft/3/XkQrPFepAV4ZGfPKA0UCgwf+D+NpgU8IH5hraVXPtj+UHpbrdfQOn6Cs2AdOuEa0ExF5k+aRdWMllK1ItO3bmJqEUU1QSml9t0SgpVu5gCViHszKDzYz5b3K9NLnXJ9TbEcfAUTfoENTZyg0f7bonnis9n1DYmLig+dKLr8AMVyPImMDGrr+YhSx1UI41mEj+4MUTvfjK4vuANbvHwRD60lOsRFA2qU0vWLkMxg4MT7bjhy18eX+Pv root@zturn_v2018.3
Fingerprint: md5 8b:58:66:af:30:d6:4e:98:9b:bf:10:67:40:20:63:27
dropbear.
hwclock: can't open '/dev/misc/rtc': No such file or directory
Starting syslogd/klogd: done
Starting tcf-agent: OK

PetaLinux 2018.3 zturn_v2018.3 /dev/ttyPS0

zturn_v2018.3 login: root
Password:
root@zturn_v2018:~#

FSBL の UART チャンネル設定

起動するにはしたが 「電気回路/zynq/Petalinux のビルド#ode1428c」 と比べると、 FSBL 関連のメッセージが出ていないので、どこかで UART チャンネルの指定が足りていないっぽい? (と思ったら、"#define FSBL_DEBUG_INFO 1" も足りてなかった)

対処法は・・・これかもしれない?

https://japan.xilinx.com/support/answers/61349.html

menuconfig で [Linux Components Selection] に移動し、[First Stage Bootloader] を無効にしたけれど components/ に fsbl のコードは存在しないのでどうしようもない。

えー?

しかたがないので、Windows 上の Xilinx SDK で fsbl を作成することにする。

[New]-[Aplication Project] から、 sdk-new-application-project.png

適当な名前を付けて [Next] 後、テンプレートとして ZYNQ_FSBL を選択する。

sdk-new-project1.png sdk-new-project2.png

UART のチャンネルが 0 でなく 1 なのに対応して、 fsbl_bsp\ps7_cortexa9_0\include\xparameters.h にて、

LANG:C
#define STDIN_BASEADDRESS 0xE0001000
#define STDOUT_BASEADDRESS 0xE0001000

とする。

fsbl-uart-channel.png

そして、fsbl_debug.h の冒頭に

LANG:C
#define	FSBL_DEBUG_INFO	1

を追加した。

fsbl_debug_info_1.png

[Project]-[Build] したところ、

arm-none-eabi-gcc.exe - アプリケーション エラー
----
アプリケーションを正しく起動できませんでした (0xc0000142)。
[OK] をクリックしてアプリケーションを閉じて下さい。

errror-0xc0000142.png

が出た。

https://forums.xilinx.com/t5/Embedded-Development-Tools/The-application-was-unable-to-start-correctly-0xc0000142/td-p/563029

によると、WinAVR など一部のツールと PATH 設定でバッティングするらしい。

[Xilinx]-[Launch Shell] からコマンドプロンプトを立ち上げて試すと

LANG:console
> which arm-none-eabi-gcc.exe
 C:\Xilinx\SDK\2018.3\gnu\aarch32\nt\gcc-arm-none-eabi\bin\arm-none-eabi-gcc.exe
>arm-none-eabi-gcc.exe --version
 arm-none-eabi-gcc.exe (Linaro GCC 7.3-2018.04-rc3) 7.3.1 20180314
 Copyright (C) 2017 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.
> type %PATH%
 ... ;C:\WinAVR-20100110\bin;C:\WinAVR-20100110\utils\bin; ...
 ... ;C:\Xilinx\Vivado\2018.3\tps\mingw\6.2.0\win64.o\nt\bin;...

のように一見正しく起動するようなのだが、、、PATH 設定で tps\mingw 関連の優先度が WinAVR より低くなっているのが気になる。

そこで、

  • C:\Xilinx\Vivado\2018.3\.settings64-Vivado.bat
  • C:\Xilinx\Vivado\2018.3\bin\vivado.bat
  • C:\Xilinx\SDK\2018.3\bin\xsdk.bat

の先頭に、

LANG:bat
SET PATH=%PATH:C:\WinAVR-20100110\bin;=%
SET PATH=%PATH:C:\WinAVR-20100110\utils\bin;=%

を追加して、vivado や SDK の起動時に AVR 関連の PATH 設定を除去することにした。

その後、vivado および SDK を立ち上げ直し、プロジェクトの設定を Release に変更したら

fsbl-config-release.png

[Project]-[Build All] でコンパイルする。Release フォルダに fsbl の elf ファイルができるので、これを Petalinux 側の hw_platform フォルダへコピーした。

fsbl_elf.png

fsbl_elf2.png

設定

build できそうなところまで確認できたため、 もう一度始めから 電気回路/zynq/Petalinux のカスタマイズ#p4f8f224 を参照しつつやり直す。

基本的に zynq の Linux 上で開発をやりたいので、 設定変更は SD カードの中を書き換えるだけで簡単に済ませられる形にしておきたい。

設定や開発中のコードを変更するたびに petalinux-build して SD カードに焼いて再起動なんてやってられるか、っていう話。

LANG:console
$ cd ~/petalinux
$ mv zturn-v2018.3/hw_platform .
$ rm -rf zturn-v2018.3
$ cat >> ~/.bashrc  # 自動実行スクリプトに登録する
 alias petalinux-setup='source /opt/petalinux_2018.3/settings.sh;export LANG=en_US.UTF-8'
^D
$ petalinux-setup
$ petalinux-create -t project --template zynq -n zturn-v2018.3
$ cd zturn-v2018.3
$ git init
$ git add .
$ git commit -m "newly created"
$ petalinux-config --get-hw-description=../hw_platform
 (何もしないで Exit)
$ git add .
$ git commit -m "configure as default"
$ petalinux-config --get-hw-description=../hw_platform
 Linux Components Selection --->
   [Uncheck] First Stage Bootloaer
 Auto Config Settings --->
   [Uncheck] fsbl autoconfig
 Subsystem AUTO Hardware Settings --->
   Advanced bootable images storage Settings --->
     dtb image settings --->
       image storage media --->
         primary sd
 DTG Settings --->
   [Check] Devicetree overlay
 u-boot Configuration --->
   U-boot config --->  
     other
 Image Packaging Configuration --->
   Root filesystem type --->
     SD card
   [Uncheck] Copy final images to tftpboot
 Yocto Settings --->
   Parallel thread execution --->
     BB_NUMBER_THREADS = 3
     PARALLEL_MAKE = 3
$ git add .
$ git commit -m "petalinux configured"
$ petalinux-config -c u-boot
 (何もしないで Exit)
$ git add .
$ git commit -m "u-boot configured as default"
$ petalinux-config -c u-boot
 Boot images --->
   [Uncheck] Support Flattened Image Tree
 Boot media --->
   [Check] Support for booting from SD/EMMC
 Environment  --->
   Select the location of the environment --->  
     Environment is not stored
 Networking support --->
   [Uncheck] all
 Device Drivers --->
   [Uncheck] Ethernet PHY support
$ git add .
$ git commit -m "u-boot configured"
$ mkdir -p images/linux/
$ petalinux-package --image -c kernel --format uImage
 NOTE: Tasks Summary: Attempted 713 tasks of which 614 didn't need to be rerun and all succeeded.
$ ls images/linux
 uImage
$ ls -F build/tmp/deploy/images/plnx-zynq7/
 fitImage-4.14-xilinx-v2018.3+gitAUTOINC+eeab73d120-r0-plnx-zynq7-20190320020532.bin
 fitImage-its-4.14-xilinx-v2018.3+gitAUTOINC+eeab73d120-r0-plnx-zynq7-20190320020532.its
 fitImage-its-plnx-zynq7.its@
 fitImage-linux.bin-4.14-xilinx-v2018.3+gitAUTOINC+eeab73d120-r0-plnx-zynq7-20190320020532.bin
 fitImage-linux.bin-plnx-zynq7.bin@
 fitImage-plnx-zynq7.bin@
 modules--4.14-xilinx-v2018.3+git0+eeab73d120-r0-plnx-zynq7-20190320020532.tgz
 modules-plnx-zynq7.tgz@
 plnx-zynq7-system-20190320020532.dtb
 plnx-zynq7-system.dtb@
 System.map.linux
 uImage@
 uImage--4.14-xilinx-v2018.3+git0+eeab73d120-r0-plnx-zynq7-20190320020532.bin
 uImage-plnx-zynq7.bin@
 vmlinux@
 vmlinux--4.14-xilinx-v2018.3+git0+eeab73d120-r0-plnx-zynq7-20190320020532.bin
 vmlinux-plnx-zynq7.bin@
 Xilinx-plnx-zynq7.hdf
 zImage@
 zImage--4.14-xilinx-v2018.3+git0+eeab73d120-r0-plnx-zynq7-20190320020532.bin
 zImage-plnx-zynq7.bin@
$ ls build/tmp/deploy/images/plnx-zynq7/u-boot.elf
 ls: cannot access 'build/tmp/deploy/images/plnx-zynq7/u-boot.elf': No such file or directory
$ petalinux-build -c u-boot
 ...
 WARNING: /opt/petalinux_2018.3/components/yocto/source/arm/layers/meta-xilinx/meta-xilinx-bsp/recipes-bsp/u-boot/u-boot-xlnx_2018.3.bb.do_compile is tainted from a forced run
 ...
 Summary: There was 1 WARNING message shown.
$ ls images/linux/
 image.ub  system.bit  system.dtb  System.map.linux  u-boot.bin  u-boot.elf  uImage  vmlinux  zImage
$ petalinux-package --boot --fsbl ../hw_platform/zturn_fsbl_2018_3.elf --u-boot --force
$ ls images/linux/
 BOOT.BIN  image.ub  system.bit  system.dtb  System.map.linux  u-boot.bin  u-boot.elf  uImage  vmlinux  zImage  zynq_fsbl.elf
$ ln -s system.dtb images/linux/devicetree.dtb
$ cat >images/linux/uEnv.txt
 bootargs=console=ttyPS0,115200 root=/dev/mmcblk0p2 rw earlyprintk rootfstype=ext4 devtmpfs.mount=0 rootwait
 uenvcmd=echo Copying Linux from SD to RAM... && mmcinfo && run load_image && bootm ${kernel_load_address} - ${devicetree_load_address}
 load_image=fatload mmc 0 ${kernel_load_address} ${kernel_image} && fatload mmc 0 ${devicetree_load_address} ${devicetree_image}
^D

ユーザー権限で sdcard をマウント可能にする。

LANG:console
$ vi fstab
+ /dev/sdf1 /mnt/sdcard1 auto defaults,user 0 0
+ /dev/sdf2 /mnt/sdcard2 auto defaults,user 0 0

起動ファイルのコピー

LANG:console
$ mount /dev/sdf1 /mnt/sdcard1
$ sudo rm /mnt/sdcard1/*
$ cp images/linux/BOOT.BIN images/linux/devicetree.dtb images/linux/uEnv.txt images/linux/uImage /mnt/sdcard1
$ umount /dev/sdf1

ルートファイルシステムを作成してコピー

LANG:console
$ petalinux-build -c rootfs
 ...
 WARNING: petalinux-user-image-1.0-r0 do_rootfs: [log_check] petalinux-user-image: found 1 warning message in the logfile:
[log_check] warning: %post(sysvinit-inittab-2.88dsf-r10.plnx_zynq7) scriptlet failed, exit status 1
 ...
 Summary: There was 1 WARNING message shown.
 [INFO] successfully built rootfs
$ ls images/linux/
 BOOT.BIN        rootfs.cpio.bz2        rootfs.ext3.bz2  rootfs.manifest       system.bit        u-boot.bin  vmlinux
 devicetree.dtb  rootfs.cpio.gz         rootfs.ext4      rootfs.tar.bz2        system.bit.bin    u-boot.elf  zImage
 image.ub        rootfs.cpio.gz.u-boot  rootfs.ext4.gz   rootfs.tar.gz         system.dtb        uEnv.txt    zynq_fsbl.elf
 rootfs.cpio     rootfs.ext3            rootfs.jffs2     rootfs.testdata.json  System.map.linux  uImage
$ sudo mount /dev/sdf2 /mnt/sdcard2
$ sudo tar fxz images/linux/rootfs.tar.gz -C /mnt/sdcard2
$ sudo umount /dev/sdf2

いくつか問題を解決する

以上、ほぼ 電気回路/zynq/Petalinux のカスタマイズ#p4f8f224 を踏襲することで起動するようにはなったが、いくつか問題があった。対処法が分かったものについてはすでに上の「設定」に含めてある。

Warning - bad CRC, using default environment

U-Boot 起動メッセージに

LANG:console
U-Boot 2018.01 (Mar 20 2019 - 04:12:57 +0000) Xilinx Zynq ZC702

Board: Xilinx Zynq
Silicon: v3.1
I2C:   ready
DRAM:  ECC disabled 1 GiB
MMC:   mmc@e0100000: 0 (SD)
SF: Detected w25q128bv with page size 256 Bytes, erase size 4 KiB, total 16 MiB
*** Warning - bad CRC, using default environment

として、"Warning - bad CRC, using default environment" が出た。

これは Serial Flash (SF) に environment が書き込まれていないという警告のようで、 ZYNQ> プロンプトでの saveenv コマンドで現在の環境変数を保存すると出なくなるらしいのだが、 その必要はないのでむしろ u-boot の設定で

LANG:console
Environment  --->
  Select the location of the environment --->  
    Environment is not stored

として、環境変数を保存する機能を切っておく。

LANG:console
U-Boot 2018.01-00083-gd8fc4b3b70 (Mar 20 2019 - 09:59:27 +0000) Xilinx Zynq ZC702

Board: Xilinx Zynq
Silicon: v3.1
I2C:   ready
DRAM:  ECC disabled 1 GiB
MMC:   mmc@e0100000: 0 (SD)
Using default environment

これで WARNING は出なくなった。

"reading uEnv.txt" が2回表示される

LANG:console
reading uEnv.txt
371 bytes read in 8 ms (44.9 KiB/s)
Importing environment from SD ...
Hit any key to stop autoboot:  0
Device: mmc@e0100000
Manufacturer ID: 3
OEM: 5344
Name: SU04G
Tran Speed: 50000000
Rd Block Len: 512
SD version 3.0
High Capacity: Yes
Capacity: 3.7 GiB
Bus Width: 4-bit
Erase Group Size: 512 Bytes
reading uEnv.txt
371 bytes read in 8 ms (44.9 KiB/s)
Loaded environment from uEnv.txt
Importing environment from SD ...
Running uenvcmd ...

無駄な気がする。

uEnv.txt で指定する環境変数の規定値などは

LANG:console
less ./build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/u-boot-xlnx/v2018.01-xilinx-v2018.3+gitAUTOINC+d8fc4b3b70-r0/git/include/configs/zynq-common.h

で確認できるのでこれをよく見ると、1回目の読み込みは preboot で行われていて、 ソースコード的には "#define CONFIG_PREBOOT" を無効にすれば良さそうだ。

今のところ、petalinux-config のメニューからこれを変更する方法が分からず、しかたなく放置している。

カーネルをソースから make

petalinux-config & petalinux-build では時間がかかりすぎるので、 電気回路/zynq/Petalinux のカスタマイズ#g5728922 を踏襲して カーネルをソースファイルの make でビルドできるようにしておく。

LANG:console
$ cp -R build/tmp/work-shared/plnx-zynq7/kernel-source/ .
$ cp build/tmp/work-shared/plnx_arm/kernel-build-artifacts/.config kernel-source/
$ echo /kernel-source >> .gitignore
$ git add -f kernel-source/.config
$ git commit -m "add kernel .config"
$ cd kernel-source/
$ sudo apt-get install -y crossbuild-essential-armhf bc u-boot-tools # 必要なパッケージを導入
$ make ARCH=arm menuconfig # kernel 設定のメニューを表示
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- UIMAGE_LOADADDR=0x8000 uImage modules
$ cp arch/arm/boot/uImage ../images/linux # 一応ここにコピーしておく
$ sudo mount /dev/sdf1 /mnt/sdcard1/
$ sudo cp arch/arm/boot/uImage /mnt/sdcard1/
$ sudo umount /dev/sdf1
$ sudo mount /dev/sdf2 /mnt/sdcard2/
$ sudo make ARCH=arm INSTALL_MOD_PATH=/mnt/sdcard2 modules_install
$ sudo umount /dev/sdf2

デフォルトのままでビルドすると iptables (ファイアーウォール) 機能が盛り込まれていないことが後で分かった。 この段階から、menu-config で iptables を有効にしておくのが良い気がする。

ルートファイルシステムに Ubuntu 18.04 LTS を採用

上記のようにしてインストールしたカーネルは、

LANG:console
$ uname -a
 Linux zturn-v2018.3 4.14.0-xilinx-v2018.3 #1 SMP PREEMPT Wed Mar 20 02:25:46 UTC 2019 armv7l GNU/Linux

となる。

Ubuntu の 18.04 LTS が Linux Kernel 4.15 ベースなので、ギリギリこれが入れられるのかもしれない?
→ 公式にサポートされているとの記載を発見 https://japan.xilinx.com/support/answers/71653.html

以下の手順で ~/petalinux/zturn-v2018.3/rootfs に Ubuntu 18.04 LTS のディスクイメージを作成して、SD カードに焼いて使うことにする。

VirtualBox 内の Ubuntu から、

LANG:console
$ sudo apt-get install qemu-user-static debootstrap binfmt-support
$ export targetdir=~/petalinux/zturn-v2018.3/rootfs
$ export distro=bionic
$ mkdir -p $targetdir
$ 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
LANG:console
$ export distro=bionic
$ export LANG=C
$ export hostname=zturn2018_3
$ /debootstrap/debootstrap --second-stage
$ cat << EOT > /etc/apt/sources.list
 # http://ascii.jp/elem/000/000/441/441502/index-3.html によれば、
 #   main が Canonical によりメンテナンスされているオープンソースウェア
 #   restricted が Canonical によりメンテナンスされているクローズウェア
 #   universe が オープンソースウェア
 #   multiverse が オープンソースでないもの
 deb http://ports.ubuntu.com/ubuntu-ports/ $distro main restricted universe multiverse
 deb http://ports.ubuntu.com/ubuntu-ports/ $distro-backports main restricted universe multiverse
 deb http://ports.ubuntu.com/ubuntu-ports/ $distro-security main restricted universe multiverse
 deb http://ports.ubuntu.com/ubuntu-ports/ $distro-updates main restricted universe multiverse
 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 -y etckeeper  # /etc 以下の更新履歴を取る
$ apt-get install -y locales dialog
$ dpkg-reconfigure locales
 Generating locales (this might take a while)...
   en_US.UTF-8... done
   ja_JP.UTF-8... done
 Generation complete.
$ apt-get install -y openssh-server ntpdate hwinfo ntp samba jed aptitude dbus ca-certificates \
> build-essential device-tree-compiler cmake doxygen libsysfs-dev libhugetlbfs-dev \
> dbus bash-completion
$ cat /etc/network/interfaces
 # ifupdown has been replaced by netplan(5) on this system.  See
 # /etc/netplan for current configuration.
 # To re-enable ifupdown on this system, you can run:
 #    sudo apt install ifupdown
$ cat << EOT > /etc/netplan/eth0.yaml
 network:
     version: 2
     renderer: networkd
     ethernets:
         enp3s0:
             dhcp4: y
             dhcp6: n
 EOT
$ cat << EOT > /usr/lib/networkd-dispatcher/routable.d/ntp-restart
> #!/bin/sh
> /usr/sbin/service ntp restart
> EOT
$ chmod u+x /usr/lib/networkd-dispatcher/routable.d/ntpdate
$ echo $hostname > /etc/hostname
$ echo "127.0.0.1    " $hostname >> /etc/hosts
$ echo "/dev/mmcblk0p1  /boot auto  defaults   0   0" >> /etc/fstab
$ adduser takeuchi
$ adduser takeuchi sudo
 Adding user `takeuchi' to group `sudo' ...
 Adding user takeuchi to group sudo
 Done.
$ su takeuchi
$ groups
 takeuchi sudo
$ exit
$ vi /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 = takeuchi
 +    writable = yes
$ # samba インストール前に作られた既存ユーザーについては
$ # 別途 samba に登録してやる必要がある
$ pdbedit -a -u takeuchi
 new password:
 retype new password:
$ exit
LANG:console
$ sudo tar fcz ubuntu18.04LTS_rootfs.tar.gz rootfs
$ sudo rm -rf rootfs/
$ mount /dev/sdf2
$ sudo rm -rf /mnt/sdcard2/*  # 以前のファイルを全て消す
$ sudo tar fxz ubuntu18.04LTS_rootfs.tar.gz -C /mnt/sdcard2
$ umount /dev/sdf2

Petalinux で作成した images/linux/rootfs.tar.gz が 6MB 程度だったのに対して、
ubuntu18.04LTS_rootfs.tar.gz は 408MB あるので非常に大きい。

でも http を使ってブラウザ経由で制御するようなことを考えると 慣れた環境がうれしい。

ネットワークが繋がらない?

はじめ、/etc/netplan 以下のファイルのファイル名を eth0.dhcp としていたために、 ネットワーク接続が得られなかった。

zynq 上のコンソールから:

LANG:console
$ ip address show
 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
     inet 127.0.0.1/8 scope host lo
        valid_lft forever preferred_lft forever
     inet6 ::1/128 scope host
        valid_lft forever preferred_lft forever
 2: can0: <NOARP,ECHO> mtu 16 qdisc noop state DOWN group default qlen 10
     link/can
 3: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
     link/ether 00:0a:35:00:01:22 brd ff:ff:ff:ff:ff:ff
 4: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
     link/sit 0.0.0.0 brd 0.0.0.0
$ sudo ip link set eth0 up
$ ip address show eth0
 3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
     link/ether 00:0a:35:00:01:22 brd ff:ff:ff:ff:ff:ff
     inet6 fe80::20a:35ff:fe00:122/64 scope link
        valid_lft forever preferred_lft forever
$ sudo mv /etc/netplan/eth0.dhcp /etc/netplan/eth0.yaml
$ sudo netplan apply
$ ip address show eth0
 3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
     link/ether 00:0a:35:00:01:22 brd ff:ff:ff:ff:ff:ff
     inet 10.225.225.181/24 brd 10.225.225.255 scope global dynamic eth0
        valid_lft 3069652548sec preferred_lft 3069652548sec
     inet6 fe80::20a:35ff:fe00:122/64 scope link
        valid_lft forever preferred_lft forever

繋がった。

/etc/netplan/ の設定ファイルは拡張子を .yaml にしておかなければならないらしい。 はじめ、変な拡張子にしていたためにうまく行かなかった。

上記の設定で、再起動しても問題なく繋がるようになった。

ネットワークに繋がった際に実行するスクリプト

z-turn board はバッテリーを積んでいないので、電源を切ると時刻が初期化されてしまう。 ネットワークケーブルを繋いだ状態で電源を入れれば起動直後に ntpd が時刻を合わせてくれるようなのだけれど、 電源を入れた後でネットワークケーブルを繋ぐとしばらくは時刻がずれたままになってしまう。

そこで、ネットワークが link up した際に ntp を再起動するよう設定したい。

netplan は現状で、ネットワークに繋がった際に特定のスクリプトを実行するための Hook を提供していないものの、networkd-dispatcher が同様の機能を提供しているそうだ。

ifupdown であれば /etc/network/if-up.d に置いていたようなスクリプトに対応するには networkd-dispatcher を使うことになるのだそうだ。

networkd-dispatcher は Ubuntu 18.04LTS にはデフォルトで入っているみたい。

LANG:console
$ # ネットワークケーブルを挿さずに起動
$ date # 時刻がおかしい
 2018年  1月 28日 日曜日 15:58:34 UTC
$ sudo apt show networkd-dispatcher # すでに入っている
 Package: networkd-dispatcher
 Version: 1.7-0ubuntu3.3
 Priority: important
 Section: utils
 Origin: Ubuntu
 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
 Bugs: https://bugs.launchpad.net/ubuntu/+filebug
 Installed-Size: 59.4 kB
 Depends: gir1.2-glib-2.0, python3-dbus, python3-gi, python3:any
 Suggests: iw | wireless-tools
 Homepage: https://github.com/craftyguy/networkd-dispatcher
 Task: minimal
 Supported: 5y
 Download-Size: 13.3 kB
 APT-Sources: http://ports.ubuntu.com/ubuntu-ports bionic-updates/main armhf Packages
 Description: Dispatcher service for systemd-networkd connection status changes
  Networkd-dispatcher is a dispatcher daemon for systemd-networkd
  connection status changes. It is similar to NetworkManager-dispatcher,
  but is much more limited in the types of events it supports due to the
  limited nature of systemd-networkd.
 
 N: 追加レコードが 1 件あります。表示するには '-a' スイッチを付けてください。
$ ls -F /usr/lib/networkd-dispatcher/
 dormant.d/  no-carrier.d/  off.d/  routable.d/
$ ls -F /usr/lib/networkd-dispatcher/routable.d/ # 何も設定されていない
$ cat << EOT | sudo tee /usr/lib/networkd-dispatcher/routable.d/ntp-restart
> #!/bin/sh
> /usr/sbin/service ntp restart
> EOT
$ sudo chmod u+x /usr/lib/networkd-dispatcher/routable.d/ntpdate
$ # ネットワークケーブルを挿す
$ date
 2019年  3月 22日 金曜日 10:06:45 UTC

うまくいった。

Ubuntu の動作中はローカルの ntpd が動いており、に時刻を合わせている。

計測のための制御などで秒単位で正確な時間間隔が必要なときにシステムクロックを当てにしてしまうと、 ntpd による時刻の微調整のタイミングで間隔がズレる可能性があるため注意が必要だ。

独自にタイマーを持って、そちらを基準にすべきだ。

作業履歴へ戻る → 電気回路/zynq

コメント・質問





Counter: 12741 (from 2010/06/03), today: 3, yesterday: 0