zyboをベアメタルでブートする

以下の記事に従う

U-Bootを使った ベアメタル・アプリケーションの作り方(FPGAマガジンNo.14)
http://www.kumikomi.net/fpga/sample/0014/FPGA14_116.pdf

build-xilteraでカーネルイメージのビルド

依存パッケージ追加

sudo apt-get install gawk chrpath
sudo apt-get install libssl-dev

Yoctoのビルド
https://github.com/aquaxis/build-xiltera

./build-xiltera.shを実行すると、以下のエラーで死んだ

ERROR: glibc-2.24-r0 do_package: QA Issue: glibc: Files/directories were installed but not shipped in any package:
  /usr/share
Please set FILES such that these items are packaged. Alternatively if they are unneeded, avoid installing them or delete them within do_install.
glibc: 1 installed and not shipped files. [installed-vs-shipped]
ERROR: glibc-2.24-r0 do_package: Fatal QA errors found, failing task.
ERROR: glibc-2.24-r0 do_package: Function failed: do_package
ERROR: Logfile of failure stored in: /home/shohei/Downloads/build-xiltera/poky/build/tmp/work/cortexa9hf-neon-poky-linux-gnueabi/glibc/2.24-r0/temp/log.do_package.2317
ERROR: Task (/home/shohei/Downloads/build-xiltera/poky/build/../meta/recipes-core/glibc/glibc_2.24.bb:do_package) failed with exit code '1'

この辺を読んで解決法を考える
http://www.sinby.com/backyard-report/004-Yocto/hello-test.html
https://lists.yoctoproject.org/pipermail/yocto/2016-January/028127.html

glibcの設定ファイルを修正する
build-xiltera/poky/meta/recipes-core/glibc/glibc-package.inc の40行目

FILES_${PN} = "${libc_baselibs} ${libexecdir}/* ${@base_conditional('USE_LDCONFIG', '1    ', '${base_sbindir}/ldconfig ${sysconfdir}/ld.so.conf', '', d)}"

を以下に変更(/usr/shareをFILES_${PN}に追加)

FILES_${PN} = "/usr/share ${libc_baselibs} ${libexecdir}/* ${@base_conditional('USE_LDCONFIG', '1    ', '${base_sbindir}/ldconfig ${sysconfdir}/ld.so.conf', '', d)}"

SDカード作成

sdカードをつくるスクリプトは以下の用に変更した
パーティション3の指定が間違っている?のを修正したのと、mkfsを実行した)
パーティション3のタイプがよくわからなかったのでext2にした)
パーティション3がブート用なのに使ってない気がする。必要なのか?)
build-sdcard.sh
実行:./build-sdcard.sh /dev/sdb

#!/bin/bash

sudo umount -l ${1}?

sudo fdisk ${1} << EOF
d

d

d

w
EOF

sudo fdisk ${1} <<EOF
o
n
p
3
2048
+8M
a
n
p
1

+20M
t
1
b
n
p
2

+768M
w
EOF

sudo mkfs.msdos /dev/sdb1 -n BOOT
sudo mkfs.ext3 /dev/sdb2 -L ROOT
sudo mkfs.ext2 /dev/sdb3 -L HOGE 

build-sdcopy.sh
実行:./build-sdcopy.sh /dev/sdb

#!/bin/bash

sudo dd if=./build/de1soc.preloader.bin of=${1}3 bs=64k seek=0
sudo dd if=./build/de1soc.u-boot-dtb.img of=${1}3 bs=64k seek=4

sudo cp ./build/zImage /media/shohei/BOOT
sudo cp ./build/socfpga.dtb /media/shohei/BOOT
sudo cp ./build/zynq-zybo.dtb /media/shohei/BOOT
sudo cp ./build/zybo.u-boot-dtb.img /media/shohei/BOOT/u-boot-dtb.img
sudo cp ./build/zybo.boot.bin /media/shohei/BOOT/boot.bin

sudo tar xjvf ./build/xiltera-image-dfb-xiltera.tar.bz2 -C /media/shohei/ROOT
sudo chmod 777 /media/shohei/ROOT/etc/init.d/psplash.sh
sudo echo "ln -s /dev/ttyS0 /dev/ttyPS0" >> /media/shohei/ROOT/etc/init.d/psplash.sh
sudo chmod 755 /media/shohei/ROOT/etc/init.d/psplash.sh

sudo cp ./build/soc_system.rbf /media/shohei/BOOT
sudo cp ./build/ZYBO_wrapper.bit /media/shohei/BOOT

sync;sync;sync;

sudo umount -l ${1}?

#sudo rm -rf /tmp/mnt

バイスツリーは以下のように変更する必要がある
http://d.hatena.ne.jp/seinzumtode/20170416/1492326984
zynq-zybo.dtbを.dtsに変換

$ dtc -I dtb -O dts -o zynq-zybo.dts zynq-zybo.dtb

zynq-zybo.dts に追記

 reserved-memory {
        #address-cells = <0x1>;
        #size-cells = <0x1>;
        ranges;

        zynq-dma-unusable-area {
            reg = <0x0 0x80000>;
        };
    };

zynq-zybo.dtbに変換する

$ dtc -I dts -O dtb -o zynq-zybo.dtb zynq-zybo.dts

.elfの実行

http://d.hatena.ne.jp/seinzumtode/20170416/1492327968

u-bootが起動した状態で以下を実行する

zynq> fatload mmc 0:1 0x1000000 hello_world
zynq> bootelf 0x1000000
Zynq> mmc
mmc - MMC sub system

Usage:
mmc info - display info of the current MMC device
mmc read addr blk# cnt
mmc write addr blk# cnt
mmc erase blk# cnt
mmc rescan
mmc part - lists available partition on current mmc device
mmc dev [dev] [part] - show or set current mmc device [partition]
mmc list - lists available devices
mmc hwpartition [args...] - does hardware partitioning
  arguments (sizes in 512-byte blocks):
    [user [enh start cnt] [wrrel {on|off}]] - sets user data area attributes
    [gp1|gp2|gp3|gp4 cnt [enh] [wrrel {on|off}]] - general purpose partition
    [check|set|complete] - mode, complete set partitioning completed
  WARNING: Partitioning is a write-once setting once it is set to complete.
  Power cycling is required to initialize partitions after set to complete.
mmc setdsr <value> - set DSR register value

Zynq> mmc info
Device: sdhci@e0100000
Manufacturer ID: 74
OEM: 4a60
Name: USD
Tran Speed: 50000000
Rd Block Len: 512
SD version 3.0
High Capacity: Yes
Capacity: 7.5 GiB
Bus Width: 4-bit
Erase Group Size: 512 Bytes

Zynq> mmc part

Partition Map for MMC device 0  --   Partition Type: DOS

Part    Start Sector    Num Sectors     UUID            Type
  1     18432           40960           ad2be2fb-01     0b
  2     59392           1572864         ad2be2fb-02     83
  3     2048            16384           ad2be2fb-03     83 Boot

Zynq> fatload mmc 0:1 0x1000000 hello_world
reading hello_world
80188 bytes read in 27 ms (2.8 MiB/s)

Zynq> bootelf 0x1000000
CACHE: Misaligned operation at range [0c100000, 0c1001f4]
CACHE: Misaligned operation at range [0c1001f4, 0c10027e]
## Starting application at 0x0c100000 ...
Example expects ABI version 9
Actual U-Boot ABI version 9
Hello World
argc = 1
argv[0] = "0x1000000"
argv[1] = "<NULL>"
Hit any key to exit ...

## Application terminated, rc = 0x0