LoginSignup
10
4

More than 3 years have passed since last update.

ZYBO Z7上でYoctoでビルドしたLinuxを走らせてみた

Last updated at Posted at 2019-07-27

積みボードと化していたZYBO Z7を使おうと思ったのでその時の構築録です。他の記事を参考にしましたが、つまずいたところがあるのでまとめました。

環境

ハードウェア
・AMD Ryzen 5 1600X Six-Core Processor 3.99GHz
※BIOSでSVM ModeをEnableにしておきました。
・RAM 16GB
・SSD 1TB(最初は250GBSSDで試しましたが,仮想マシンでかなり容量を使ったので拡張しました)
ソフトウェア
・Windows 10
・Ubuntu 18.04 (Virtual Box)
・Vivado
・Yocto等

仮想環境構築

Ubuntuを入手する
からisoファイル(ubuntu-18.04.2-desktop-amd64.iso)を取得してVirtualBoxで仮想環境を構築します。
RAMとしては4GB割り当て、HDDとしては最終的に130GB以上消費したので、200GB程度必要かと思います。またビルドでかなりリソースを必要とするのでVMの設定でコア数は12個中6個を割り当てています。またインストールしたら「Guest Additions CD」を使って機能を追加してください。またVivado tarファイルをUbuntu側で取得するためにWindowsでのダウンロード先をVMの共有フォルダにしておきます。
参考記事
Ubuntu 18.04 LTSインストールガイド【スクリーンショットつき解説】

Vivado tarファイルダウンロード

ダウンロードに時間がかかるので、
ザイリンクス - Adaptable. Intelligent. サポート ダウンロード
から
「Vivado HLx 2019.1: すべての OS インストーラー シングルファイル ダウンロード」
をダウンロードしておきます。ダウンロードするためにはXilinxアカウントへのサインインが必要です。

Yocto環境構築

概ね以下の記事2の通りですが、バージョンの違いかファイル名等に違いがあったので補足します。
初めてのYocto環境で作成したLinuxをZYBOで動かす

まず必要なパッケージをインストールします。 初めてのYocto環境で作成したLinuxをZYBOで動かす に加えてlibssl-dev, vim, bison, flex, gcc-arm-linux-gnueabihfを追加しています

$ sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib build-essential chrpath socat cpio python python3 python3-pip python3-pexpect xz-utils debianutils iputils-ping libsdl1.2-dev xterm libssl-dev vim bison flex
$ sudo apt-get install gcc-arm-linux-gnueabihf

また以下のスクリプトで必要なリポジトリをクローンしておきます。

download.sh
#!/bin/bash

# version
VERSION=sumo

# download poky
git clone git://git.yoctoproject.org/poky.git -b $VERSION

# download additional recipie
mkdir -p sources
cd sources

git clone git://github.com/openembedded/meta-openembedded.git -b $VERSION
git clone git://git.linaro.org/openembedded/meta-linaro.git -b $VERSION
git clone git://github.com/meta-qt5/meta-qt5.git -b $VERSION
git clone git://github.com/xilinx/meta-xilinx -b $VERSION

cd ..

スクリプトの実行(時間がかかります)

cd
chmod +x download.sh
./download.sh

poky環境構築

cd poky
source ./oe-init-build-env

初めてのYocto環境で作成したLinuxをZYBOで動かすではoe-init-envでしたが、最新バージョンではoe-init-build-envになっていました。

エミュレータ実行のためのビルド

練習でエミュレータで実行してみます。VMでCPU割り当て数を増やせば自動的に並列化するようです。

bitbake core-image-minimal #1時間くらいかかります
runqemu qemux86 #ターミナルが開いてLinuxが立ち上がります

原因がわかっていませんが、以下のエラーが出るときはbuildディレクトリ全体を削除してビルドしなおしたらうまくいきました。

ERROR: linux-yocto-5.0.3+gitAUTOINC+f0b575cda6_3df4aae607-r0 do_unpack:

Zybo-Z7実行のためのビルド

bblayers.confの編集

~/poky/build/conf/bblayers.confの末尾に以下の内容を追加します。

BBLAYERS += " ${TOPDIR}/../../sources/meta-openembedded/meta-oe "
BBLAYERS += " ${TOPDIR}/../../sources/meta-xilinx/meta-xilinx-bsp "
BBLAYERS += " ${TOPDIR}/../../sources/meta-xilinx/meta-xilinx-contrib "

local.confの編集

末尾に以下の分を追加します。

conf/local.confの追加分
MACHINE ?= "zybo-zynq7"

DL_DIR ?= "${TOPDIR}/../downloads"
EXTRA_IMAGE_FEATURES ?= "debug-tweaks tools-sdk"
# Install Application
IMAGE_INSTALL_append = " nano"
IMAGE_INSTALL_append = " minicom"
IMAGE_INSTALL_append = " lrzsz"
IMAGE_INSTALL_append = " ethtool"
IMAGE_INSTALL_append = " libdrm"
#バージョンによってうまくいかないことがある
IMAGE_INSTALL_append = " i2c-tools"
# remove splash
IMAGE_INSTALL_remove = " psplash"
DISTRO_FEATURES_append = " x11"

に書き換えます。

Yoctoコンパイル

export CROSS_COMPILE=arm-linux-gnueabihf- #これが省略できるかは未確認
export ARCH=arm #これが省略できるかは未確認
bitbake core-image-minimal #これが省略できるかは未確認
bitbake core-image-minimal -c populate_sdk #SDKをコンパイル

SDKのインストール

cd tmp/deploy/sdk/
sudo ./poky-glibc-x86_64-core-image-minimal-cortexa9hf-neon-toolchain-2.5.3.sh

バージョンは頻繁に変わるようなので、「2.5.3」のところは適宜あるファイルに読み替えてください。

u-boot作業

cd
git clone git://github.com/Xilinx/u-boot-xlnx

ZYBO (Zynq) 初心者ガイド (2) Hello Worldプロジェクト で作成したzynq_wrapper.hdfをコピーしてボードの設定ディレクトリに展開します

sudo cp /media/sf_project_1/project_1.sdk/design_1_wrapper.hdf /home/$USERNAME/u-boot-xlnx/
cd ~/u-boot-xlnx
sudo chown $USERNAME design_1_wrapper.hdf
unzip design_1_wrapper.hdf
cp ps7_init* ./board/xilinx/zynq/zynq-zybo/
cp ~/poky/build/tmp/work/zybo_zynq7-poky-linux-gnueabi/u-boot/1_2018.01-r0/git/configs/zynq_zybo_defconfig ~/u-boot-xlnx/include/configs/
cp ~/poky/build/tmp/work/zybo_zynq7-poky-linux-gnueabi/u-boot/1_2018.01-r0/git/include/configs/zynq_zybo.h ~/u-boot-xlnx/include/configs/
make zynq_zybo_defconfig

設定ファイルを展開した後makeしてデバイスツリー(zynq-zybo.dts)を編集する。これをしないと後でCOMポート通信ができません。

arch/arm/dts/zynq-zybo.dts
&clkc {
//      ps-clk-frequency = <50000000>;
        ps-clk-frequency = <33333333>;
};

環境変数を設定してmakeします。

export CROSS_COMPILE=arm-linux-gnueabihf-
export ARCH=arm
make -j6 #20秒程度で終わります

linux-xlnx作業

cd ~
git clone git://github.com/Xilinx/linux-xlnx -b xilinx-v2018.2 #かなり時間がかかります
cd linux-xlnx
export ARCH=arm
make xilinx_zynq_defconfig

u-boot同様にデバイスツリーの修正を行います。クロック周波数を33.3MHzへメモリを512MBの設定から1GBへ変更します。

arch/arm/boot/dts/zynq-zybo.dts
        memory@0 {
                device_type = "memory";
//              reg = <0x0 0x20000000>;
                reg = <0x0 0x40000000>;
        };

&clkc {
//      ps-clk-frequency = <50000000>;
        ps-clk-frequency = <33333333>;
};

ビルドします

make -j6

書き込み作業

VirtualBoxの設定でUbuntuにSDカードを認識させてから SDカードにUbuntuのルートファイルシステムを作成する の「SDカードの準備」~「root file systemの準備」直前までの通りにパーティションを作成してから以下の作業をします。

SDカードを認識しないときはVirtualBoxでのUSBデバイス認識

まずuEnv.txtを作成します。

~/uEnv.txt
bootargs=console=ttyPS0,115200 root=/dev/mmcblk0p2 rw earlyprintk rootfstype=ext4 rootwait devtmpfs.mount=1
uenvcmd=fatload mmc 0 0x03000000 design_1_wrapper.bit && fpga loadb 0 0x03000000 $filesize && fatload mmc 0 0x03000000 zImage && fatload mmc 0 0x02A00000 zynq-zybo.dtb && bootz 0x03000000 - 0x02A00000

これまでに作成したファイルを1つ目のパーティションに書きこみます。

cd /media/$USERNAME/ZYBO_BOOT
sudo cp ~/u-boot-xlnx/u-boot.img ~/u-boot-xlnx/spl/boot.bin ./
sudo cp ~/linux-xlnx/arch/arm/boot/zImage ~/linux-xlnx/arch/arm/boot/dts/zynq-zybo.dtb ./
sudo cp ~/u-boot-xlnx/design_1_wrapper.bit ./
sudo cp ~/uEnv.txt ./

ビルドで生成したLinuxファイルを2つ目のパーティション書き込みます。

cd /media/$USERNAME/ROOT_FS
sudo tar xvf ~/poky/build/tmp/deploy/images/zybo-zynq7/core-image-minimal-zybo-zynq7.tar.gz

以上でSDカードの準備は完了です

ZYBOでの実行と起動ログ

ZYBO (Zynq) 初心者ガイド にあるように、SDカードをZYBOに接続、PCとZYBOをUSBケーブルで接続、TeraTermなどでCOMポート経由でシリアル通信を行うと以下のようなログが見れます。

1 USB Device(s) found
       scanning usb for storage devices... 0 Storage Device(s) found

Device 0: unknown device
ethernet@e000b000 Waiting for PHY auto negotiation to complete...... done
BOOTP broadcast 1
BOOTP broadcast 2
BOOTP broadcast 3
DHCP client bound to address 192.168.4.10 (780 ms)
*** ERROR: `serverip' not set
Cannot autoload with TFTPGET
missing environment variable: pxefile_addr_r
BOOTP broadcast 1
BOOTP broadcast 2
BOOTP broadcast 3
DHCP client bound to address 192.168.4.10 (1442 ms)
*** ERROR: `serverip' not set
Cannot autoload with TFTPGET
BOOTP broadcast 1
BOOTP broadcast 2
BOOTP broadcast 3
DHCP client bound to address 192.168.4.10 (1419 ms)
*** ERROR: `serverip' not set
Cannot autoload with TFTPGET
!!!
!!! Booting cmd is deprecated (will be removed in 2020).
!!! Please move to distro bootcmd.
!!!
Device: mmc@e0100000
Manufacturer ID: 13
OEM: 4b47
Name: SD01G 
Bus Speed: 50000000
Mode : SD High Speed (50MHz)
Rd Block Len: 512
SD version 1.10
High Capacity: No
Capacity: 952.5 MiB
Bus Width: 4-bit
Erase Group Size: 512 Bytes
310 bytes read in 3 ms (100.6 KiB/s)
Loaded environment from uEnv.txt
Importing environment from SD ...
Running uenvcmd ...
4045676 bytes read in 462 ms (8.4 MiB/s)
  design filename = "design_1_wrapper;UserID=0XFFFFFFFF;Version=2019.1"
  part number = "7z020clg400"
  date = "2019/07/09"
  time = "01:20:33"
  bytes in bitstream = 4045564
zynq_align_dma_buffer: Align buffer at 3000070 to 2ffff80(swap 1)
INFO:post config was not run, please run manually if needed
3960352 bytes read in 454 ms (8.3 MiB/s)
9222 bytes read in 14 ms (642.6 KiB/s)
## Flattened Device Tree blob at 02a00000
   Booting using the fdt blob at 0x2a00000
   Loading Device Tree to 1eb1b000, end 1eb20405 ... OK

Starting kernel ...

Booting Linux on physical CPU 0x0
Linux version 4.14.0-xilinx-dirty (muramasa@muramasa-VirtualBox) (gcc version 7.4.0 (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1)) #1 SMP PREEMPT Sat Jul 27 20:10:54 JST 2019
CPU: ARMv7 Processor [413fc090] revision 0 (ARMv7), cr=18c5387d
CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
OF: fdt: Machine model: Zynq ZYBO Development Board
Memory policy: Data cache writealloc
cma: Reserved 16 MiB at 0x1f000000
random: fast init done
percpu: Embedded 16 pages/cpu @debc8000 s34764 r8192 d22580 u65536
Built 1 zonelists, mobility grouping on.  Total pages: 130048
Kernel command line: console=ttyPS0,115200 root=/dev/mmcblk0p2 rw earlyprintk rootfstype=ext4 rootwait devtmpfs.mount=1
PID hash table entries: 2048 (order: 1, 8192 bytes)
Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
Memory: 493068K/524288K available (6144K kernel code, 238K rwdata, 1560K rodata, 1024K init, 153K bss, 14836K reserved, 16384K cma-reserved, 0K highmem)
Virtual kernel memory layout:
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)
    fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
    vmalloc : 0xe0800000 - 0xff800000   ( 496 MB)
    lowmem  : 0xc0000000 - 0xe0000000   ( 512 MB)
    pkmap   : 0xbfe00000 - 0xc0000000   (   2 MB)
    modules : 0xbf000000 - 0xbfe00000   (  14 MB)
      .text : 0xc0008000 - 0xc0700000   (7136 kB)
      .init : 0xc0900000 - 0xc0a00000   (1024 kB)
      .data : 0xc0a00000 - 0xc0a3b8c0   ( 239 kB)
       .bss : 0xc0a3b8c0 - 0xc0a61f84   ( 154 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 e0800000
slcr mapped to e0802000
L2C: platform modifies aux control register: 0x02060000 -> 0x32460000
L2C: DT/platform modifies aux control register: 0x02060000 -> 0x32460000
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 dynamic clock gating enabled, standby mode enabled
L2C-310 cache controller enabled, 8 ways, 512 kB
L2C-310: CACHE_ID 0x410000c8, AUX_CTRL 0x46460001
zynq_clock_init: clkc starts at e0802100
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 e080a000, 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: 1024 (order: 0, 4096 bytes)
Mountpoint-cache hash table entries: 1024 (order: 0, 4096 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
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
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 @ 0xe0840000
zynq-pinctrl 700.pinctrl: zynq pinctrl initialized
e0001000.serial: ttyPS0 at MMIO 0xe0001000 (irq = 25, base_baud = 6249999) is a xuartps
console [ttyPS0] enabled
vgaarb: loaded
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
usb_phy_generic phy0: phy0 supply vcc not found, using dummy regulator
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: 4096 (order: 2, 16384 bytes)
TCP bind hash table entries: 4096 (order: 3, 32768 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
UDP hash table entries: 256 (order: 1, 8192 bytes)
UDP-Lite hash table entries: 256 (order: 1, 8192 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.
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=17 bucket_order=0
jffs2: version 2.2. (NAND) (SUMMARY)  c 2001-2006 Red Hat, Inc.
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
zynq-qspi e000d000.spi: couldn't determine configuration info
zynq-qspi e000d000.spi: about dual memories. defaulting to single memory
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 27 (16:c6:8c:71:c0:1e)
RTL8211E Gigabit Ethernet e000b000.ethernet-ffffffff:00: attached PHY driver [RTL8211E Gigabit Ethernet] (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
chipidea-usb2 e0002000.usb: e0002000.usb supply vbus not found, using dummy regulator
ci_hdrc ci_hdrc.0: EHCI Host Controller
ci_hdrc ci_hdrc.0: new USB bus registered, assigned bus number 1
ci_hdrc ci_hdrc.0: USB 2.0 started, EHCI 1.00
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 1 port detected
i2c /dev entries driver
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 e0944000 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.sdhci [e0100000.sdhci] 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.
Waiting for root device /dev/mmcblk0p2...
mmc0: new high speed SD card at address b368
mmcblk0: mmc0:b368 SD01G 953 MiB 
 mmcblk0: p1 p2
EXT4-fs (mmcblk0p2): recovery complete
EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
VFS: Mounted root (ext4 filesystem) on device 179:2.
devtmpfs: mounted
Freeing unused kernel memory: 1024K
INIT: version 2.88 booting
Starting udev
udevd[701]: starting version 3.2.5
udevd[702]: starting eudev-3.2.5
EXT4-fs (mmcblk0p2): re-mounted. Opts: data=ordered
Sat Jul 27 05:32:54 UTC 2019
INIT: Entering runlevel: 5
Configuring network interfaces... IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
udhcpc: started, v1.27.2
udhcpc: sending discover
udhcpc: sending discover
macb e000b000.ethernet eth0: link up (1000/Full)
IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
udhcpc: sending discover
udhcpc: sending select for 192.168.4.10
udhcpc: lease of 192.168.4.10 obtained, lease time 14400
/etc/udhcpc.d/50default: Adding DNS 192.168.4.1
done.
Starting syslogd/klogd: done

Poky (Yocto Project Reference Distro) 2.5.3 zybo-zynq7 /dev/ttyPS0

zybo-zynq7 login: 
10
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
4