EBAZ4205でLinuxを動かして見る


関連記事
[EBAZ4205を使って、FPGAを使ったシステム開発の環境を構築する](https://qiita.com/GeekMasahiro/items/6bdb8886fb5c32c332cb)
[EBAZ4205でLinuxを動かして見る](https://qiita.com/GeekMasahiro/items/bb411ab40bb2e80e4c2a)
[petalinuxをBuildrootでビルドする](https://qiita.com/GeekMasahiro/items/7ce3d4fe108f2cfe49a3)

# はじめに

本家のドキュメント

https://docs.amd.com/r/en-US/ug1144-petalinux-tools-reference-guide/Steps-to-Set-Up-PetaLinux-Working-Environment

このドキュメントを参照しながら、EBAZ4205でLinuxを動かして見みます。最新のVivado, Vitis, Petalinuxを使ってみます。

# ハードウエア情報(.xsaファイル)の作成

EBAZ4205のボードのハードウエア情報は、[How to Build](https://github.com/KeitetsuWorks/EBAZ4205/blob/master/docs/how-to-build.md)のvivadoの項目に記載されてる方法で、xsaファイルの作成を行いました。


vivado 2024.1, vitis 2024.1はWindowsにインストールしています。

```
> git clone https://github.com/KeitetsuWorks/EBAZ4205.git
> cd EBAZ4205
> cd vivado
> C:\Xilinx\Vivado\2024.1\bin\unwrapped\win64.o\vvgl.exe C:\Xilinx\Vivado\2024.1\bin\vivado.bat
```

```ebaz4205.tcl```をTcl Consoleで実行する。

Flow NavigatorのGenerate Bitstreamを実行する

File -> Export -> Export Hardwareを実行する
　include bitstreamをチェックする

EBAZ4205/vivado/ebaz4205/ebaz4205_wrapper.xsaに保存される

# Petalinuxのインストール

petaLinuxの作成環境は、linuxが必要なので、WSL2の環境で行います。

```petalinux-v2024.1-05202009-installer.run```を[ダウンロード](https://www.xilinx.com/support/download/index.html/content/xilinx/en/downloadNav/embedded-design-tools.html)する。

WSL2環境に次のパッケージをインストールする。
```
sudo apt-get install xterm libtool texinfo gcc-multilib
sudo apt-get install libtinfo5
```

```
mkdir -p ~/petalinux
cd /mnt/c/Users/masat/Downloads
./petalinux-v2024.1-05202009-installer.run ~/petalinux/

petalinux-util --webtalk off
```

```Enter target directory for SDK```と聞かれるので、```~/petalinux/```を入力する。

インストーラの引数に、```~/petalinux/```を指定しているが、無視されているらしい。

次のコマンドで、```petalinux```の環境変数を設定する。
```
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
source ~/petalinux/settings.sh
```

.xsaファイルの場所を指定して、buildする。
```
$ petalinux-create --type project --template zynq --name ebaz4205_linux
$ cd ebaz4205_linux/
$ petalinux-config --get-hw-description=/mnt/c/Users/masat/xilinx/linux/EBAZ4205/vivado/ebaz4205/ebaz4205_wrapper.xsa
$ petalinux-build
```

ビルド中に、NANDに関するエラーが発生したので、/EBAZ4205/vivado/ebaz4205/でNAND Flashを無効にして再度ビルドする。

```shell
$ petalinux-build -x mrproper
$ petalinux-build
```

同じエラーが発生

petalinux-config　で、NAND Flashを無効にする。
改めてビルドすとビルド成功。

BOOT.BINを作成する
--fpgaをつけないと、bitstreamのファイルが含まれず、起動してもPLが動作しないので、注意しましょう。

```shell
$ petalinux-package --boot --fpga ./images/linux/system.bit --u-boot --force
```


wicファイルを作成する
```shell
$ petalinux-package wic
```

```/home/masa/ebaz4205/ebaz4205_linux/images/linux/petalinux-sdimage.wic```が作成された。
これをSDカードに書き込んで起動する。

これでKernelは起動したが、rootfsが見つからないエラーが発生した。

U-bootのシェルで、次のコマンドを実行する。
U-boot起動中に3秒以内に何かキーを押すと、U-bootのシェルを起動できる。
```
setenv bootargs "root=/dev/mmcblk0p2 rw rootwait console=ttyPS0,115200"
saveenv
```

再度起動すると、rootfsが見つかり、ログイン画面が表示された。

ログインはID:petalinux,　パスワードは、最初のログイン時に設定する。

起動時のメッセージを載せておきます。

```text


U-Boot 2024.01 (May 14 2024 - 03:31:48 +0000)

CPU:   Zynq 7z010
Silicon: v3.1
DRAM:  ECC disabled 256 MiB
Core:  23 devices, 16 uclasses, devicetree: board
Flash: 0 Bytes
NAND:  0 MiB
MMC:   mmc@e0100000: 0
Loading Environment from FAT... *** Warning - some problems detected reading environment; recovered successfully
OK
In:    serial@e0001000
Out:   serial@e0001000
Err:   serial@e0001000
Net:
ZYNQ GEM: e000b000, mdio bus e000b000, phyaddr 0, interface gmii
eth0: ethernet@e000b000
Hit any key to stop autoboot:  0
switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0:1...
Found U-Boot script /boot.scr
3473 bytes read in 13 ms (260.7 KiB/s)
## Executing script at 03000000
Trying to load boot images from mmc0
4924664 bytes read in 425 ms (11.1 MiB/s)
## Booting kernel from Legacy Image at 00200000 ...
   Image Name:   Linux-6.6.10-xilinx-v2024.1-g3af
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    4924600 Bytes = 4.7 MiB
   Load Address: 00200000
   Entry Point:  00200000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 00100000
   Booting using the fdt blob at 0x100000
Working FDT set to 100000
   Loading Kernel Image
   Loading Device Tree to 0dabd000, end 0dac4864 ... OK
Working FDT set to dabd000

Starting kernel ...

Booting Linux on physical CPU 0x0
Linux version 6.6.10-xilinx-v2024.1-g3af4295e00ef (oe-user@oe-host) (arm-xilinx-linux-gnueabi-gcc (GCC) 12.2.0, GNU ld (GNU Binutils) 2.39.0.20220819) #1 SMP PREEMPT Sat Apr 27 05:22:24 UTC 2024
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
Memory policy: Data cache writealloc
cma: Reserved 16 MiB at 0x0f000000 on node -1
Zone ranges:
  Normal   [mem 0x0000000000000000-0x000000000fffffff]
  HighMem  empty
Movable zone start for each node
Early memory node ranges
  node   0: [mem 0x0000000000000000-0x000000000fffffff]
Initmem setup node 0 [mem 0x0000000000000000-0x000000000fffffff]
percpu: Embedded 12 pages/cpu s17940 r8192 d23020 u49152
Kernel command line: root=/dev/mmcblk0p2 rw rootwait console=ttyPS0,115200
Dentry cache hash table entries: 32768 (order: 5, 131072 bytes, linear)
Inode-cache hash table entries: 16384 (order: 4, 65536 bytes, linear)
Built 1 zonelists, mobility grouping on.  Total pages: 65024
mem auto-init: stack:all(zero), heap alloc:off, heap free:off
Memory: 231128K/262144K available (7168K kernel code, 251K rwdata, 2124K rodata, 1024K init, 146K bss, 14632K reserved, 16384K cma-reserved, 0K highmem)
SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=2, Nodes=1
rcu: Preemptible hierarchical RCU implementation.
rcu:    RCU event tracing is enabled.
rcu:    RCU restricting CPUs from NR_CPUS=4 to nr_cpu_ids=2.
rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=2
NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
efuse mapped to (ptrval)
slcr mapped to (ptrval)
GIC physical location is 0xf8f01000
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
rcu: srcu_init: Setting srcu_struct sizes based on contention.
zynq_clock_init: clkc starts at (ptrval)
Zynq clock init
sched_clock: 64 bits at 167MHz, resolution 6ns, wraps every 4398046511103ns
clocksource: arm_global_timer: mask: 0xffffffffffffffff max_cycles: 0x26703d7dd8, max_idle_ns: 440795208065 ns
Switching to timer-based delay loop, resolution 6ns
Console: colour dummy device 80x30
Calibrating delay loop (skipped), value calculated using timer frequency.. 333.33 BogoMIPS (lpj=1666666)
CPU: Testing write buffer coherency: ok
CPU0: Spectre v2: using BPIALL workaround
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
Setting up static identity map for 0x100000 - 0x100060
rcu: Hierarchical SRCU implementation.
rcu:    Max phase no-delay instances is 1000.
smp: Bringing up secondary CPUs ...
CPU1: thread -1, cpu 1, socket 0, mpidr 80000001
CPU1: Spectre v2: using BPIALL workaround
smp: Brought up 1 node, 2 CPUs
SMP: Total of 2 processors activated (666.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, linear)
pinctrl core: initialized pinctrl subsystem
NET: Registered PF_NETLINK/PF_ROUTE protocol family
DMA: preallocated 256 KiB pool for atomic coherent allocations
thermal_sys: Registered thermal governor 'step_wise'
cpuidle: using governor menu
platform axi: Fixed dependency cycle(s) with /axi/interrupt-controller@f8f01000
amba f8801000.etb: Fixed dependency cycle(s) with /replicator/out-ports/port@1/endpoint
amba f8803000.tpiu: Fixed dependency cycle(s) with /replicator/out-ports/port@0/endpoint
amba f8804000.funnel: Fixed dependency cycle(s) with /replicator/in-ports/port/endpoint
amba f889c000.ptm: Fixed dependency cycle(s) with /axi/funnel@f8804000/in-ports/port@0/endpoint
amba f889d000.ptm: Fixed dependency cycle(s) with /axi/funnel@f8804000/in-ports/port@1/endpoint
hw-breakpoint: found 5 (+1 reserved) breakpoint and 1 watchpoint registers.
hw-breakpoint: maximum watchpoint size is 4 bytes.
e0001000.serial: ttyPS0 at MMIO 0xe0001000 (irq = 26, base_baud = 6249999) is a xuartps
printk: console [ttyPS0] enabled
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
mc: Linux media interface: v0.10
videodev: 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
Advanced Linux Sound Architecture Driver Initialized.
vgaarb: loaded
clocksource: Switched to clocksource arm_global_timer
NET: Registered PF_INET protocol family
IP idents hash table entries: 4096 (order: 3, 32768 bytes, linear)
tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 4096 bytes, linear)
Table-perturb hash table entries: 65536 (order: 6, 262144 bytes, linear)
TCP established hash table entries: 2048 (order: 1, 8192 bytes, linear)
TCP bind hash table entries: 2048 (order: 3, 32768 bytes, linear)
TCP: Hash tables configured (established 2048 bind 2048)
UDP hash table entries: 256 (order: 1, 8192 bytes, linear)
UDP-Lite hash table entries: 256 (order: 1, 8192 bytes, linear)
NET: Registered PF_UNIX/PF_LOCAL protocol family
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp-with-tls transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
PCI: CLS 0 bytes, default 64
armv7-pmu f8891000.pmu: hw perfevents: no interrupt-affinity property, guessing.
hw perfevents: enabled with armv7_cortex_a9 PMU driver, 7 counters available
workingset: timestamp_bits=30 max_order=16 bucket_order=0
jffs2: version 2.2. (NAND) (SUMMARY)  c 2001-2006 Red Hat, Inc.
io scheduler mq-deadline registered
io scheduler kyber registered
io scheduler bfq registered
zynq-pinctrl 700.pinctrl: zynq pinctrl initialized
dma-pl330 f8003000.dma-controller: Loaded driver for PL330 DMAC-241330
dma-pl330 f8003000.dma-controller:      DBUFF-128x8bytes Num_Chans-8 Num_Peri-4 Num_Events-16
brd: module loaded
loop: module loaded
CAN device driver interface
macb e000b000.ethernet eth0: Cadence GEM rev 0x00020118 at 0xe000b000 irq 43 (00:0a:35:00:1e:53)
e1000e: Intel(R) PRO/1000 Network Driver
e1000e: Copyright(c) 1999 - 2015 Intel Corporation.
usbcore: registered new interface driver usb-storage
i2c_dev: i2c /dev entries driver
cdns-i2c e0004000.i2c: can't get pinctrl, bus recovery not supported
cdns-i2c e0004000.i2c: 400 kHz mmio e0004000 irq 44
cdns-i2c e0005000.i2c: can't get pinctrl, bus recovery not supported
cdns-i2c e0005000.i2c: 400 kHz mmio e0005000 irq 45
cdns-wdt f8005000.watchdog: Xilinx Watchdog Timer 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
ledtrig-cpu: registered to indicate activity on CPUs
clocksource: ttc_clocksource: mask: 0xffff max_cycles: 0xffff, max_idle_ns: 537538477 ns
timer #0 at (ptrval), irq=48
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
pl353-smc e000e000.memory-controller: no matching children
mmc0: SDHCI controller on e0100000.mmc [e0100000.mmc] using ADMA
fpga_manager fpga0: Xilinx Zynq FPGA Manager registered
NET: Registered PF_INET6 protocol family
Segment Routing with IPv6
In-situ OAM (IOAM) with IPv6
sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
NET: Registered PF_PACKET protocol family
can: controller area network core
NET: Registered PF_CAN protocol family
mmc0: new high speed SDHC card at address 1234
can: raw protocol
can: broadcast manager protocol
mmcblk0: mmc0:1234 SA32G 28.9 GiB
can: netlink gateway - max_hops=1
 mmcblk0: p1 p2
Registering SWP/SWPB emulation handler
of-fpga-region fpga-region: FPGA Region probed
of_cfs_init
of_cfs_init: OK
clk: Disabling unused clocks
ALSA device list:
  No soundcards found.
EXT4-fs (mmcblk0p2): mounted filesystem e4500f13-58d2-427e-8c76-1a274eb062e9 r/w with ordered data mode. Quota mode: disabled.
VFS: Mounted root (ext4 filesystem) on device 179:2.
devtmpfs: mounted
Freeing unused kernel image (initmem) memory: 1024K
Run /sbin/init as init process
INIT: version 3.04 booting
Starting udev
Starting version 251.8+
EXT4-fs (mmcblk0p2): re-mounted e4500f13-58d2-427e-8c76-1a274eb062e9 r/w. Quota mode: disabled.
hwclock: can't open '/dev/misc/rtc': No such file or directory
Fri Mar  9 12:34:56 UTC 2018
hwclock: can't open '/dev/misc/rtc': No such file or directory
random: crng init done
hwclock: can't open '/dev/misc/rtc': No such file or directory
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... macb e000b000.ethernet eth0: PHY [e000b000.ethernet-ffffffff:00] driver [Generic PHY] (irq=POLL)
macb e000b000.ethernet eth0: configuring for phy/gmii link mode
udhcpc: started, v1.35.0
udhcpc: broadcasting discover
macb e000b000.ethernet eth0: unable to generate target frequency: 25000000 Hz
macb e000b000.ethernet eth0: Link is Up - 100Mbps/Full - flow control tx
udhcpc: broadcasting discover
udhcpc: broadcasting select for 192.168.0.7, server 192.168.0.1
udhcpc: lease of 192.168.0.7 obtained from 192.168.0.1, lease time 86400
/etc/udhcpc.d/50default: Adding DNS 192.168.0.1
done.
Starting OpenBSD Secure Shell server: sshd
  generating ssh RSA host key...
  generating ssh ECDSA host key...
  generating ssh ED25519 host key...
done.
Starting rpcbind daemon...done.
starting statd: done
Starting internet superserver: inetd.
NFS daemon support not enabled in kernel
Starting syslogd/klogd: done
Starting tcf-agent: OK

********************************************************************************************
The PetaLinux source code and images provided/generated are for demonstration purposes only.
Please refer to https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/2741928025/Moving+from+PetaLinux+to+Production+Deployment
for more details.
********************************************************************************************
PetaLinux 2024.1+release-S05201002 ebaz4205_test02_petalinux ttyPS0

ebaz4205_test02_petalinux login: petalinux
You are required to change your password immediately (administrator enforced).
New password:
Retype new password:
ebaz4205_test02_petalinux:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0A:35:00:1E:53
          inet addr:192.168.0.7  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: 240f:68:4c37:1:20a:35ff:fe00:1e53/64 Scope:Global
          inet6 addr: fe80::20a:35ff:fe00:1e53/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:16 errors:0 dropped:0 overruns:0 frame:0
          TX packets:22 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2018 (1.9 KiB)  TX bytes:2948 (2.8 KiB)
          Interrupt:43 Base address:0xb000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:2 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:140 (140.0 B)  TX bytes:140 (140.0 B)

ebaz4205_test02_petalinux:~$ ping 192.168.0.1
PING 192.168.0.1 (192.168.0.1): 56 data bytes
64 bytes from 192.168.0.1: seq=0 ttl=64 time=0.642 ms
64 bytes from 192.168.0.1: seq=1 ttl=64 time=0.398 ms
64 bytes from 192.168.0.1: seq=2 ttl=64 time=0.369 ms
```

関連記事
[EBAZ4205を使って、FPGAを使ったシステム開発の環境を構築する](https://qiita.com/GeekMasahiro/items/6bdb8886fb5c32c332cb)
[EBAZ4205でLinuxを動かして見る](https://qiita.com/GeekMasahiro/items/bb411ab40bb2e80e4c2a)
[petalinuxをBuildrootでビルドする](https://qiita.com/GeekMasahiro/items/7ce3d4fe108f2cfe49a3)

参考
[1500円ZYNQ基板でPetaLinuxを動作させる(後編:PetaLinux ビルドと EBAZ4205 での動作)](https://qiita.com/kan573/items/98f364eec46cb3842d79)