LoginSignup
3
4

More than 5 years have passed since last update.

ZYBO-Z7用Linuxブートイメージ生成環境にPLを取り込むための覚え書き

Posted at

はじめに

前々回前回で、ZYBO-Z7用のLinuxブート環境を作成して、SDカードよりZYBO-Z7のLinuxブートをすることできました。
今回は、簡単なPL部分(ハードウェア)を取り込んでLinuxブートさせるための覚え書きです。

用意するもの

  • Xilinx FPGA bitファイル
    • Vivadoより作成します。今回は「design_1_wrapper.bit」というファイル名とします。
  • FPGA設定プログラム
    • SDKより生成される、「ps_init_gpl.h」および「ps_init_gpl.c」
  • devicetreeファイル
    • SDKより生成される、「pl.dtsi」

この辺りの準備方法はこちらを参照ください。

今回はPLとして、AXI GPIOを追加し確認をおこないます(出力のみ)。

image.png

コンテナログイン後の作業

Docker上で生成されたコンテナで起動しているOS(Ubuntu 18.04)の作業です。
ここでは、前回の手順に沿って、bitbakeによるビルドが完了した時点からおこないます。
また、これまでの環境であれば、Dockerコンテナとホストでは/sharedディレクトリにてファイルの授受が可能です。このディレクトリを通じてFPGA設定プログラムやdevicetreeファイルをコンテナに取り込みます。

FPGA設定プログラムの上書き

Yoctoで元々あるFPGA設定プログラムを用意したものに書き替えます。/sharedに用意したFPGA設定プログラムがあるとすると、下記の通りとなります。

cp /shared/ps7_init.* ./tmp/work/zybo_zynq7-poky-linux-gnueabi/u-boot/1_2018.01-r0/git/board/xilinx/zynq/zynq-zybo/

デバイスツリーの変更

pl.dtsiをU-bootおよびLinux rootfsにコピーして、zynq-zybo.dtsに追記します。

cp /shared/pl.dtsi ./tmp/work/zybo_zynq7-poky-linux-gnueabi/u-boot/1_2018.01-r0/git/arch/arm/dts/
cp /shared/pl.dtsi ./tmp/work-shared/zybo-zynq7/kernel-source/arch/arm/boot/dts/

追記内容は下記の通りです。

zynq-zybo.dts
@@ -8,6 +8,7 @@
  */
 /dts-v1/;
 #include "zynq-7000.dtsi"
+#include "pl.dtsi"

 / {
        model = "Zynq ZYBO Development Board";

bitbakeビルド

下記の通りbitbakeコマンドにてu-bootとLinux kernelを再コンパイルし、その後イメージを再生成させます。

MACHINE=zybo-zynq7 bitbake u-boot -c compile -f
MACHINE=zybo-zynq7 bitbake linux-xlnx -c compile -f
MACHINE=zybo-zynq7 bitbake core-image-minimal

上記以降の作業は前回と同様なので省略します。

これ以降は、コンテナからホストに作業場を移動しての作業となります。

uEnv.txtの編集

bitbakeビルド後に生成されるuEnv.txtはPS部分のみ記述されているので、PL部分を展開するように追記します。具体的には、PLに関する定義を最初に2行追加し、uenvcmdにこの定義を追加します。

uEnv.txt
+ loadbit=fatload mmc 0 0x03000000 design_1_wrapper.bit
+ loadfpga=fpga loadb 0 0x03000000 $filesize
 devicetree_image=uImage-zynq-zybo.dtb
 devicetree_load_address=0x2000000
 bootargs=earlyprintk console=ttyPS0,115200 root=/dev/mmcblk0p2 rw rootwait
 loadkernel=fatload mmc 0 ${kernel_load_address} ${kernel_image}
 loaddtb=fatload mmc 0 ${devicetree_load_address} ${devicetree_image}
 bootkernel=run loadkernel && run loaddtb && bootm ${kernel_load_address} - ${devicetree_load_address}
- uenvcmd=run bootkernel
+ uenvcmd=run loadbit && run loadfpga && run bootkernel

SDカードへのコピー

Ubuntu等で、gparted等にてSDカードをfat32, ext4をそれぞれパーティションに分割します。
fat32でフォーマットした第1パーティションに、以下のファイルをコピーします。
ここでは、第1パーティションは/mnt/usb1となっております。
前回とほぼ同様ですが、Xilinx FPGA bitファイル(design_1_wrapper.bit)が加わります。

 sudo cp -L boot.bin u-boot.img uEnv.txt uImage uImage-zynq-zybo.dtb design_1_wrapper.bit /mnt/usb1

第2パーティション(ここでは/mnt/usb2となっております)にLinux rootfsを書き込みます。

 sudo tar xfp core-image-minimal-zybo-zynq7-20180601095104.rootfs.tar.gz -C /mnt/usb2

実機作業

上記作成したSDカードをZYBO-Z7に挿入し、ZYBO-Z7のジャンパをSDブート設定し、電源を投入します。
USB-UARTのシリアルコンソールにてLinuxがブートを確認した後に、ユーザーID「root」でログインします。

/sys/class/gpioに、PSとPLで計3種のGPIOが作成されていることを確認します。これは元々PSに1個、PLの出力用に1個、入力に1個の計3個で構成されます。

zybo-zynq7 login: root
root@zybo-zynq7:~# ls /sys/class/gpio/
export        gpiochip1016  gpiochip1020  gpiochip898   unexport

PLの出力用はgpiochip1020なので、下記のように初期化と1を書き込むようにシェルを実行します。

for i in `seq 1020 1023`; do
echo $i > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio$i/direction
done

for i in `seq 1020 1023`; do
echo 1 > /sys/class/gpio/gpio$i/value
done

4個のLEDが全て点灯すればOKです。

おわりに

ZynqのLinuxブートにはXilinx謹製のPetaLinuxがあり、今回のDockerとYoctoを中心とした作業よりもステップは少ないと思います。しかし、PetaLinuxは独特の操作となり特にSW開発作業は面倒になるかもしれません。
その点Yoctoはある程度パッケージをコントロールしながらクロスビルド環境を構築できます。その上Raspberry Pi等の豊富なボードの実績があるので、SW開発環境としてはむしろこちらの方が調べやすくなるのではないかと思い構築しました。もっとも、Yocto自体が面倒であるわけですが…。
Dockerで構築することによってDockerイメージの作成という手間もかかってしまいました。ですが、Yoctoで生成される大量のファイルをいざという時にサクッと削除してクリーンな状況から再構築したり、各ツールのバージョンを分けたコンテナを作成することで、様々な各ツールバージョンの組み合わせが容易に試行できたりできるので、メリットはあると思います。

おまけ:ZYBO-Z7のSDブートログ

前回に加えて、u-boot起動時に「design filename = "design_1_wrapper;UserID=0XFFFFFFFF;Version=2017.4"」とFPGAのbitファイルがロードされていることが確認できます。

U-Boot 2018.01 (Jun 01 2018 - 10:04:06 +0000)

Model: Zynq ZYBO Development Board
Board: Xilinx Zynq
Silicon: v3.1
I2C:   ready
DRAM:  ECC disabled 768 MiB
MMC:   sdhci@e0100000: 0
SF: Detected s25fl128s_64k with page size 256 Bytes, erase size 64 KiB, total 16 MiB
*** Warning - bad CRC, using default environment

In:    serial@e0001000
Out:   serial@e0001000
Err:   serial@e0001000
Net:   ZYNQ GEM: e000b000, phyaddr 0, interface rgmii-id
I2C EEPROM MAC address read failed

Warning: ethernet@e000b000 (eth0) using random MAC address - 7e:22:d3:74:d6:0b
eth0: ethernet@e000b000
reading uEnv.txt
607 bytes read in 17 ms (34.2 KiB/s)
Importing environment from mmc ...
Checking if uenvcmd is set ...
Running uenvcmd ...
reading design_1_wrapper.bit
4045676 bytes read in 336 ms (11.5 MiB/s)
  design filename = "design_1_wrapper;UserID=0XFFFFFFFF;Version=2017.4"
  part number = "7z020clg400"
  date = "2018/06/01"
  time = "16:15:41"
  bytes in bitstream = 4045564
zynq_align_dma_buffer: Align buffer at 3000070 to 2ffff80(swap 1)
reading uImage
3956792 bytes read in 337 ms (11.2 MiB/s)
reading uImage-zynq-zybo.dtb
9863 bytes read in 20 ms (481.4 KiB/s)
## Booting kernel from Legacy Image at 02080000 ...
   Image Name:   Linux-4.14.0-xilinx-v2018.1
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    3956728 Bytes = 3.8 MiB
   Load Address: 00008000
   Entry Point:  00008000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 02000000
   Booting using the fdt blob at 0x2000000
   Loading Kernel Image ... OK
   Loading Device Tree to 1fffa000, end 1ffff686 ... OK

Starting kernel ...

Booting Linux on physical CPU 0x0
Linux version 4.14.0-xilinx-v2018.1 (oe-user@oe-host) (gcc version 7.3.0 (GCC)) #1 SMP PREEMPT Fri Jun 1 09:19:32 UTC 2018
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 0x2f000000
random: fast init done
percpu: Embedded 16 pages/cpu @ee9c7000 s34764 r8192 d22580 u65536
Built 1 zonelists, mobility grouping on.  Total pages: 195072
Kernel command line: earlyprintk console=ttyPS0,115200 root=/dev/mmcblk0p2 rw rootwait
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: 752768K/786432K available (6144K kernel code, 238K rwdata, 1560K rodata, 1024K init, 153K bss, 17280K reserved, 16384K cma-reserved, 0K 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 - 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 f0800000
slcr mapped to f0802000
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 f0802100
Zynq clock init
sched_clock: 64 bits at 216MHz, resolution 4ns, wraps every 4398046511102ns
clocksource: arm_global_timer: mask: 0xffffffffffffffff max_cycles: 0x31f84feb25, max_idle_ns: 440795209731 ns
Switching to timer-based delay loop, resolution 4ns
clocksource: ttc_clocksource: mask: 0xffff max_cycles: 0xffff, max_idle_ns: 826992825 ns
timer #0 at f080a000, irq=17
Console: colour dummy device 80x30
Calibrating delay loop (skipped), value calculated using timer frequency.. 433.33 BogoMIPS (lpj=2166666)
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 (866.66 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 @ 0xf0840000
zynq-pinctrl 700.pinctrl: zynq pinctrl initialized
e0001000.serial: ttyPS0 at MMIO 0xe0001000 (irq = 25, base_baud = 4166666) is a xuartps
console [ttyPS0] enabled
XGpio: /amba_pl/gpio@41200000: registered, base is 1020
XGpio: /amba_pl/gpio@41200000: dual channel registered, base is 1016
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: 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.
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)  © 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 (7e:22:d3:74:d6:0b)
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 f088c000 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 SDHC card at address 59b4
mmcblk0: mmc0:59b4 USDU1 14.9 GiB
 mmcblk0: p1 p2
EXT4-fs (mmcblk0p2): couldn't mount as ext3 due to feature incompatibilities
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[709]: starting version 3.2.5
udevd[710]: starting eudev-3.2.5
EXT4-fs (mmcblk0p2): re-mounted. Opts: data=ordered
Fri Jun  1 10:05:00 UTC 2018
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: unable to generate target frequency: 125000000 Hz
macb e000b000.ethernet eth0: link up (1000/Full)
IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
udhcpc: sending discover
udhcpc: no lease, forking to background
done.
Starting syslogd/klogd: done

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

zybo-zynq7 login:
3
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
3
4