Petalinux2018.3によるzynq-7000ブート用SDカード作成 のバックアップ差分(No.8)

更新


  • 追加された行はこの色です。
  • 削除された行はこの色です。
[[公開メモ]]

* Petalinux 2018.3 を使って zynq-7000 用のブートSDカードを作る [#xf4d6dda]

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

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

#contents

ターゲットは z-turn board で、これまで以下のような記事を書いていた。

#ls2(電気回路/z-turn,compact)

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

* プロジェクトの作成 [#o40aac7b]

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

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

ただし、現時点で petalinux の git 対応は完全ではないため、
プロジェクトを共有するには BSP を使った方が良い、との注意もあった。

 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 のハードウェア設定を取り込みつつ基本の設定 [#o3495afb]

[[vivado のハードウェア設定を出力する>電気回路/zynq/Petalinux のビルド#a82e50cc]] の手順で 
vivado 2018.3 を使って design_1_wrapper.hdf  を作成して、zturn_v2018.3/hw_platform/design_1_wrapper.hdf  に置いた。
(.hdf ファイルの実体は hw_platform ディレクトリ内の主要ファイルを .zip 形式でまとめたもの)

実はこのとき、[[ZYNQ7 Processor System の SDIO Clock を 50MHz にしておかなければダメだった>#i8da51ff]]。

 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 へ登録した。

** 罫線の表示がおかしい [#t90ff50a]

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

&ref(petalinux-config1.png,,50%);

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

&ref(petalinux-config2.png,,50%);

ただこれだと 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 の設定を変える方がよいのかもしれない。

** ロケール問題再び? [#rfb10738]

ああそうか、そもそも [[電気回路/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 が処理できないのでダメらしい。

** 暗号化ファイルシステムの問題 [#haea0979]

ということは、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

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

うわーこれきついや。

仕方がないので [[ホームディレクトリ暗号化の解除>電気回路/zynq/Petalinux2018.3環境を整える#e1dacfc9]]
の手順で暗号化を解除した。

すると、

 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%

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



* WARNING は出たけど build できた [#a30662f2]

 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 だとエラーが出た [#x53811ae]

同じソースから 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 の作成 [#x067d23c]

 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 が生成されてしまうこと>電気回路/zynq/Petalinux のビルド#w888792f]] はなくなったみたい。

* SD カードに書き込んで試す [#e5d26699]

[[電気回路/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 パーティションを作成

 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 にしないとだめだった [#i8da51ff]

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

&ref(sdio-clock-50MHz.png,,50%);

** 起動した [#c542cf35]

以下は、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 チャンネル設定 [#lfc4ab30]

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

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

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

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

えー?

 LANG:console
 $ ls components/
  plnx_workspace
 $ find -name system.mss
  ./build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/fsbl/2018.3+gitAUTOINC+56f3da2afb-r0/build/fsbl_plat/_platform/sysconfig1/fsbl_domain/mss/system.mss
  ./build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/fsbl/2018.3+gitAUTOINC+56f3da2afb-r0/build/fsbl_plat/export/fsbl_plat/sw/sysconfig1/fsbl_domain/system.mss
  ./build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/fsbl/2018.3+gitAUTOINC+56f3da2afb-r0/build/fsbl/zynq_fsbl_bsp/system.mss
 $ cp -r ./build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/fsbl/2018.3+gitAUTOINC+56f3da2afb-r0/build/fsbl/zynq_fsbl_bsp/ components/
 $ 

build フォルダの奥深くにあったみたい。
* 設定 [#ne1acba3]

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

 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
 $ git add .
 $ git commit -m "petalinux configured"
 $ petalinux-config -c u-boot
 $ git add .
 $ git commit -m "u-boot configured"
 $ petalinux-config -c rootfs
 $ git add .
 $ git commit -m "rootfs configured"


Counter: 12809 (from 2010/06/03), today: 2, yesterday: 0