これは前回のPetalinuxをダウンロードするの続きです.Petalinux2019をインストールした状態にしておいてください.
前回の記事はこちら
前回の忘れ物ですが,Xilinxに統計データを送信したくなければ以下を実行します.
petalinux-util --webtalk off
vivadoでPSだけのプロジェクトを作る
まずはZybo Z7-20のボードファイルを指定して適宜プロジェクトを作ります.ブロックデザインを作って,Add IPからZynqを選択します.
クロック配線
次にクロックを配線します.
PSの設定をする
PSをダブルクリックして設定を開き,PeripheralからEthernet0の設定を確認します.MDIOがMIOになっていることを確認してください,バージョンによってはEMIOになっていることもあるそうなのでその場合はMIOを選択して緑色にする必要があります.
クロックの設定をする
私はこのせいで5日くらいハマっていました.なんで誰も教えてくれなかったんだ(憤怒)Clock ConfigからIO Peripheral Clockを選択し,Ethernet0のClockがIO PLLになっていることを必ず確認します.私のバージョンではなぜかデフォルトでExternalになっており,Ethernet0がつかえずはまりました.Speedは1000Mbpsで良いと思います.終わったらOKを押します.
デザインを右クリックからCreate HDLします.
Bitstreamを生成します.
エクスポート
終わったらFile-Export Hardwareしておきましょう.必ずInclude Bitstreamしてください.
プロジェクトを作る
cd ~/peta petalinux-create --type project --template zynq --name firstProject
Petalinuxに戻ります.—nameの後にプロジェクトの名前をつけることができます.今回はfirstProjectという名前にしてます.ここでエラーが出る場合はPetalinuxの設定の読み込みができていないと思うので前回後半のsource settings.shしているところをもう一度確認してください.
プロジェクトの設定をする
設定の前にVivadoの方でPSのみのプロジェクトを作ってハードウェアをビットストリーム入りで出力して.xsaファイルを生成しておきましょう.私はWindowsでやっているのでGithubからリポジトリをそのまま落として~/petaにおいておきました.PSのみのプロジェクトの作り方についてはこちらが参考になります.ハードウェアをエクスポートするの項までやればOKです.(此の方とやっていることはバージョン違いであんまりなくて恐縮です)
https://qiita.com/iwatake2222/items/24a8a94741fdbb80f62a
私はこの記事用にリポジトリつくったのでこれをクローンしてもらっても構いませんし,自分で作っていただいても構いません.
cd ~/peta git clone https://github.com/fumimaker/PS_Zybo.git
Configする
cd ~/peta/firstProject petalinux-config --get-hw-description=~/peta/PS_Zybo
ここで注意なのが,--get-hw-description=のところでスペースを入れないことです.Tab補完は聞きませんがこのままやるしかないです.スペース開けると補完が効くのでそれで--get-hw-description= ~/peta/PS_Zybo
とやっていたところ4時間くらいはまりました.
ちなみにスペースを開けてしまうとこのようになります.
fumi@ubuntu:~/peta$ petalinux-config --get-hw-description= ~/peta/PS_Zybo ERROR: Failed to locate the Vivado export to SDK directory, please make sure the directory directory exists! Configures the project or the specified component with menuconfig. Usage: petalinux-config [options] {--component <COMPONENT> |--get-hw-description[=SRC]} Options: -h, --help show function usage -p, --project <PROJECT> path to PetaLinux SDK project. default is the working project --silentconfig takes the default configuration and skips the GUI. -c, --component <COMPONENT> Specify the component If no component is specified, it will do top level project configuration . If you specify a component,it will configure it with menuconfig and saves user's config fragments in meta-user. E.g. -c rootfs, -c busybox --get-hw-description [SRC] get hardware description. if [SRC] is specified, look in that location for an Vivado export to SDK directory. Otherwise, this MUST be run from WITHIN the vivado export to SDK directory. --defconfig [DEFCONFIG_TARGET] defconfig the specified component. It applies to kernel and u-boot. -v, --verbose verbose mode Note: There is no validation for configurable components. User can provide any component, bitbake will throw error for invalid components. fumi@ubuntu:~/peta$
スペースから読んでしまうみたいで,そんなExport成果物ねえぞって言われます.
Image packing Config—>Root filesystem—>SDなどを選択(Space)します.戻る時はExitで戻れます.
Yocto Settings -> Enable Debug Tweaks を有効にする (Spaceキーを押す)
続いてRoot filesystemにExt4を追加します,他のバージョンだとExt4があるようなのですがなぜかこのバージョンでは消えているので自分で追加してあげます.(これないと後で困りました)
終わったらSaveしてExitします.すると設定が実行されます.
ビルドをする
ようやくビルドです.
petalinux-build
これだけでビルドを始めてくれます.ビルド結果を以下に示します.
fumi@ubuntu:~/peta/secondprj$ petalinux-build [INFO] building project [INFO] sourcing bitbake [INFO] generating user layers [INFO] generating workspace directory INFO: bitbake petalinux-user-image Loading cache: 100% |############################################| Time: 0:00:01 Loaded 3979 entries from dependency cache. Parsing recipes: 100% |##########################################| Time: 0:00:04 Parsing of 2893 .bb files complete (2891 cached, 2 parsed). 3980 targets, 169 skipped, 0 masked, 0 errors. NOTE: Resolving any missing task queue dependencies Initialising tasks: 100% |#######################################| Time: 0:00:04 Checking sstate mirror object availability: 100% |###############| Time: 0:00:03 Sstate summary: Wanted 115 Found 13 Missed 204 Current 790 (11% match, 88% complete) NOTE: Executing SetScene Tasks NOTE: Executing RunQueue Tasks NOTE: Tasks Summary: Attempted 3267 tasks of which 3253 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
無事に完了したみたいです.
パッケージ化する
最後にパッケージ化をします.これをしないといつまで経ってもSDカードに書き込むファイルが生成されません.恥ずかしい話ですが,Buildだけしてファイルが生成されず,数時間困っていました.
fumi@ubuntu:~/peta/firstProject$ petalinux-package --boot --force --fsbl images/linux/zynq_fsbl.elf --fpga images/linux/system.bit --u-boot INFO: File in BOOT BIN: "/home/fumi/peta/firstProject/images/linux/zynq_fsbl.elf" INFO: File in BOOT BIN: "/home/fumi/peta/firstProject/images/linux/system.bit" INFO: File in BOOT BIN: "/home/fumi/peta/firstProject/images/linux/u-boot.elf" INFO: Generating Zynq binary package BOOT.BIN... ****** Xilinx Bootgen v2019.2 **** Build date : Oct 23 2019-22:59:42 ** Copyright 1986-2019 Xilinx, Inc. All Rights Reserved. INFO: Binary is ready. WARNING: Unable to access the TFTPBOOT folder /tftpboot!!! WARNING: Skip file copy to TFTPBOOT folder!!! fumi@ubuntu:~/peta/firstProject$
最後にWARNINGが出ていますが,今回はTFTPBOOT使わないので無視して問題ありません.
SDカードのパーティションを作る
Raspi同様にFAT32とEXT4のパーティションを作る必要があります.ディスクユーティリティ?からSDカードの設定を行いましょう.リファレンスによるとFAT32は500MB以上の領域が必要とのこと.写真のように作りました.名前は適当にBOOTとSystemとかにしておきました.
SDカードを焼く
FAT32のブート用領域には普通にD&DとかCPコマンドで~/peta/firstProject/images/linux/にある成果物のBOOT.binとimage.ubをコピーします.u-boot.binではなくBOOT.binです.これだけでOKです.
次にEXT4のSystemを焼いていきます.こちらはコピーではなくでDDコマンドなどで焼く必要があります.
さっきのディスクユーティリティでSDカードのEXT4部分のデバイス名を覚えておきましょう,自分の場合は/dev/sdb2でした.これはそれぞれ環境によって違うので必ず自分のものと置き換えてください.なお,これを間違えるとHDDを飛ばしたり上書きしたりすることがあります.必ずあっていることを確認して実行してください.
ddコマンドでroofs.ext4をEXT4パーティションに書き込みます.rootfs.ext4がない場合はpetalinux-configが間違ってる可能性があるので前回の記事をもう一度見てきてください.
sudo dd if=images/linux/rootfs.ext4 of=/dev/sdb2 sync sudo resize2fs /dev/sdb2 ` sync
resize2fsではSDカードのサイズを大きくしています.
起動する
これでOKです.SDカードを外してZyboに挿してジャンパJP5をSDにして給電してみましょう.Terminalで115200bpsで開くと起動ログが出てくるはずです.DoneのLEDが光ってない場合はなにかしらの理由で起動ができていません.Petalinux設定が間違ってるか,SDカードに焼けていないか,パーティションが違うかなど色々考えられます.
U-Boot 2019.01 (Sep 28 2020 - 07:49:57 +0000) Xilinx Zynq ZC702 CPU: Zynq 7z020 Silicon: v3.1 DRAM: ECC disabled 1 GiB MMC: mmc@e0100000: 0 Loading Environment from SPI Flash... 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 ffffffff, interface rgmii-id eth0: ethernet@e000b000 U-BOOT for secondprj ethernet@e000b000 Waiting for PHY auto negotiation to complete........ done BOOTP broadcast 1 BOOTP broadcast 2 BOOTP broadcast 3 BOOTP broadcast 4 DHCP client bound to address 192.168.1.87 (3258 ms) Hit any key to stop autoboot: 0 Device: mmc@e0100000 Manufacturer ID: 27 OEM: 5048 Name: SD16G Bus Speed: 50000000 Mode : SD High Speed (50MHz) Rd Block Len: 512 SD version 3.0 High Capacity: Yes Capacity: 14.5 GiB Bus Width: 4-bit Erase Group Size: 512 Bytes 4136836 bytes read in 237 ms (16.6 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: uncompressed Data Start: 0x10000104 Data Size: 4120992 Bytes = 3.9 MiB Architecture: ARM OS: Linux Load Address: 0x00008000 Entry Point: 0x00008000 Hash algo: sha1 Hash value: d42651b2186790796db30a686e318a8187e3cd0b Verifying Hash Integrity ... sha1+ OK ## Loading fdt from FIT Image at 10000000 ... Using 'conf@system-top.dtb' configuration Verifying Hash Integrity ... OK Trying 'fdt@system-top.dtb' fdt subimage Description: Flattened Device Tree blob Type: Flat Device Tree Compression: uncompressed Data Start: 0x103ee3a4 Data Size: 13933 Bytes = 13.6 KiB Architecture: ARM Hash algo: sha1 Hash value: 535f36b172892e0c0c520b67bf9428d6426bc69e Verifying Hash Integrity ... sha1+ OK Booting using the fdt blob at 0x103ee3a4 Loading Kernel Image ... OK Loading Device Tree to 07ff9000, end 07fff66c ... OK Starting kernel ... Booting Linux on physical CPU 0x0 Linux version 4.19.0-xilinx-v2019.2 (oe-user@oe-host) (gcc version 8.2.0 (GCC)) #1 SMP PREEMPT Sat Sep 26 10:58:08 UTC 2020 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 earlycon: cdns0 at MMIO 0xe0001000 (options '115200n8') bootconsole [cdns0] enabled Memory policy: Data cache writealloc cma: Reserved 16 MiB at 0x3f000000 random: get_random_bytes called from start_kernel+0x80/0x3c4 with crng_init=0 percpu: Embedded 16 pages/cpu @(ptrval) s35916 r8192 d21428 u65536 Built 1 zonelists, mobility grouping on. Total pages: 260608 Kernel command line: console=ttyPS0,115200 earlycon root=/dev/mmcblk0p2 rw rootwait Dentry cache hash table entries: 131072 (order: 7, 524288 bytes) Inode-cache hash table entries: 65536 (order: 6, 262144 bytes) Memory: 1012964K/1048576K available (6144K kernel code, 204K rwdata, 1604K rodata, 1024K init, 132K bss, 19228K 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 : 0x(ptrval) - 0x(ptrval) (7136 kB) .init : 0x(ptrval) - 0x(ptrval) (1024 kB) .data : 0x(ptrval) - 0x(ptrval) ( 205 kB) .bss : 0x(ptrval) - 0x(ptrval) ( 133 kB) rcu: Preemptible hierarchical RCU implementation. rcu: 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 (ptrval) slcr mapped to (ptrval) 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 (ptrval) 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 (ptrval), 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: Spectre v2: using BPIALL workaround CPU0: thread -1, cpu 0, socket 0, mpidr 80000000 Setting up static identity map for 0x100000 - 0x100060 rcu: Hierarchical SRCU implementation. 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 (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 @ 0x(ptrval) zynq-pinctrl 700.pinctrl: zynq pinctrl initialized e0001000.serial: ttyPS0 at MMIO 0xe0001000 (irq = 25, base_baud = 6249999) is a xuartps console [ttyPS0] enabled console [ttyPS0] enabled bootconsole [cdns0] disabled bootconsole [cdns0] 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 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. clocksource: Switched to clocksource arm_global_timer NET: Registered protocol family 2 tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 6144 bytes) 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) 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 s25fl128s, expected n25q512a m25p80 spi0.0: s25fl128s (16384 Kbytes) 4 fixed-partitions 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 RTL8211E Gigabit Ethernet e000b000.ethernet-ffffffff:00: attached PHY driver [RTL8211E Gigabit Ethernet] (mii_bus:phy_addr=e000b000.ethernet-ffffffff:00, irq=POLL) macb e000b000.ethernet eth0: Cadence GEM rev 0x00020118 at 0xe000b000 irq 27 (00:0a:35:00:1e:53) 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-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 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 of-fpga-region fpga-full: FPGA Region probed 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 0007 mmcblk0: mmc0:0007 SD16G 14.5 GiB mmcblk0: p1 p2 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 Run /sbin/init as init process INIT: version 2.88 booting random: fast init done Starting udev udevd[729]: starting version 3.2.5 random: udevd: uninitialized urandom read (16 bytes read) random: udevd: uninitialized urandom read (16 bytes read) random: udevd: uninitialized urandom read (16 bytes read) udevd[730]: starting eudev-3.2.5 FAT-fs (mmcblk0p1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck. EXT4-fs (mmcblk0p2): re-mounted. Opts: (null) hwclock: can't open '/dev/misc/rtc': No such file or directory Mon Sep 28 07:51:05 UTC 2020 hwclock: can't open '/dev/misc/rtc': No such file or directory urandom_read: 2 callbacks suppressed random: dd: uninitialized urandom read (512 bytes read) INIT: Entering runlevel: 5 Configuring network interfaces... IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready udhcpc: started, v1.29.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.1.87 udhcpc: lease of 192.168.1.87 obtained, lease time 86400 /etc/udhcpc.d/50default: Adding DNS 192.168.1.1 done. Starting haveged: haveged: listening socket at 3 haveged: haveged starting up Starting Dropbear SSH server: random: dropbear: uninitialized urandom read (32 bytes read) dropbear. hwclock: can't open '/dev/misc/rtc': No such file or directory Starting internet superserver: inetd. Starting syslogd/klogd: done Starting tcf-agent: OK /bin/autologin: line 1: -e: command not found Last login: Mon Sep 28 07:51:13 UTC 2020 on tty1 root@secondprj:~# random: crng init done root@secondprj:~#
Ethernetを指しているのでちゃんと
ethernet@e000b000 Waiting for PHY auto negotiation to complete........ done BOOTP broadcast 1 BOOTP broadcast 2 BOOTP broadcast 3 BOOTP broadcast 4 DHCP client bound to address 192.168.1.87 (3258 ms)
というようにDHCPでIPを拾ってくれてます.
動作確認
一応動いてることを確認します.普通はDRAMに全て展開されて電源を切るとやったことが全て消えますが,今回はSDカードを使ってやったことが記録されるようにPetalinux-configしておきました.なので何か操作しても消えないことを確認しておきます.
root@secondprj:~# touch helloWorld root@secondprj:~# ls helloWorld root@secondprj:~# reboot
root@secondprj:~# ls helloWorld root@secondprj:~#
Reboot後でもちゃんと残ってますね.大丈夫そうです.
まとめ
よかったです,ここまで大変でした,落とし穴が多すぎます.2019になってから先行してやられている方の通り行かなくて困ることが非常に多かったです.何か参考になれば幸いです.