aster_ismの工作室

FPGAとかマイコンとか

ZYBO-Z7を用いたLチカ(Ubuntu16.04編)

前回Petalinuxを使ってLチカをしました。 aster-ism.hatenablog.com PetaLinuxはopencvとか色々ビルドすることはできますが、やっぱりapt-get等で簡単にインストールしたいので、ubuntuを起動して基本的に前回の PetalinuxによるLチカと同じことをやります。

作業は下記を参考に実施

medium.com

実施手順

  1. 事前準備
  2. VivadoでGPIOによるLED回路作成、bitstreamの生成
  3. Petalinuxの設定とビルド
  4. SDカードへの書込み
  5. ブート・動作確認

1. 事前準備

前回と同じ、初めてならドライバ等をインストールしておく

2. VivadoでGPIOによるLED回路作成、bitstreamの生成

前回の「2. VivadoでGPIOによるLED回路作成、bitstreamの生成」と基本的に同じですが、PSの設定がデフォルトだとENET0のMDIOはEMIOになっているのでMIO 52..53に修正します。修正しないとEthernetが使えず、apt-getも当然使えません。

修正後のデザインは次のようになります。「MDIO_ETHERNET_0」のポートがZYNQのインスタンスからでてないこと以外は全く同じです。

Generate Bitstreamを実行し、完了後Export Hardwareを行います。

3. Petalinuxの設定とビルド

プロジェクトの設定

場所はどこでも構わないがとりあえずプロジェクトディレクトリ(lnxled.srcsとかがあるところ)でPetalinuxのプロジェクトを作成する。

$ petalinux-create -t project -n lnxled.lnx --template zynq
INFO: Create project: lnxled.lnx
INFO: New project successfully created in /home/aster_ism/Project/zybo-z7/lnxled/lnxled.lnx

Petalinuxのプロジェクトディレクトリに移動して、コンフィグを行う。

$ cd lnxled.lnx
$ petalinux-config --get-hw-description ../lnxled.sdk
INFO: Getting hardware description...
INFO: Rename design_1_wrapper.hdf to system.hdf
[INFO] generating Kconfig for project

コンフィグ画面が出てくるので、前回と異なり下記を設定する。

  • Image Package Configuration > Root filesystem type を「INITRAMFS」から「SD card」に変更

ビルド

$ petalinux-build 

BOOT.BINの作成

$ petalinux-package --boot --fsbl images/linux/zynq_fsbl.elf --fpga  images/linux/design_1_wrapper.bit --u-boot --force

4. SDカードへの書込み

前回と異なり、ここまで完了するとimage.ubはrootfsが含まれない状態で作られます。 この別になったrootfsをpetalinuxではなく別途ubuntuのものをダウンロードして使います。

Ubuntu16.04のrootfsをダウンロード

$wget https://rcn-ee.com/rootfs/eewiki/minfs/ubuntu-16.04.3-minimal-armhf-2017-10-07.tar.xz

SDカードのフォーマット

前回はすべてFat32でフォーマットしましたが、rootfsを別のパーティションに入れるため下記のようにフォーマットします。

SDカードへの書き込み

先ほどフォーマットしたSDカードの第1パーティション(Fat32)を/mnt/sd0、第2パーティション(ext4)を/mnt/sd1にマウントしたとします。 それぞれ必要なファイルをコピー・展開します。

$cp /image/linux/BOOT.BIN /mnt/sd0
$cp /image/linux/image.ub /mnt/sd1
$tar xvf ubuntu-16.04.3-minimal-armhf-2017-10-07.tar.xz
$tar xvfp ~aster_ism/ubuntu-16.04.3-minimal-armhf-2017-10-07/armhf-rootfs-ubuntu-xenial.tar -C /mnt/sd1/

5. ブート・動作確認

起動ログ。

U-Boot 2017.01 (Jan 08 2018 - 22:17:14 +0900)

Board: Xilinx Zynq
DRAM:  ECC disabled 1 GiB
MMC:   sdhci@e0100000: 0 (SD)
SF: Detected s25fl128s_64k with page size 256 Bytes, erase size 64 KiB, total 16 MiB
*** Warning - bad CRC, using default environment

In:    serial
Out:   serial
Err:   serial
Net:   ZYNQ GEM: e000b000, phyaddr ffffffff, interface rgmii-id
eth0: ethernet@e000b000
U-BOOT for project_1.lnx

ethernet@e000b000 Waiting for PHY auto negotiation to complete....... done
BOOTP broadcast 1
DHCP client bound to address 192.168.1.110 (160 ms)
Hit any key to stop autoboot:  0
Device: sdhci@e0100000
Manufacturer ID: 28
OEM: 4245
Name: 00000
Tran Speed: 50000000
Rd Block Len: 512
SD version 3.0
High Capacity: Yes
Capacity: 7.4 GiB
Bus Width: 4-bit
Erase Group Size: 512 Bytes
reading image.ub
3763220 bytes read in 330 ms (10.9 MiB/s)
## Loading kernel from FIT Image at 10000000 ...
   Using 'conf@2' configuration
   Verifying Hash Integrity ... OK
   Trying 'kernel@0' kernel subimage
     Description:  Linux Kernel
     Type:         Kernel Image
     Compression:  uncompressed
     Data Start:   0x100000d4
     Data Size:    3747376 Bytes = 3.6 MiB
     Architecture: ARM
     OS:           Linux
     Load Address: 0x00008000
     Entry Point:  0x00008000
     Hash algo:    sha1
     Hash value:   4844317843b0f5dce321e5037badee140bb2567d
   Verifying Hash Integrity ... sha1+ OK
## Loading fdt from FIT Image at 10000000 ...
   Using 'conf@2' configuration
   Trying 'fdt@0' fdt subimage
     Description:  Flattened Device Tree blob
     Type:         Flat Device Tree
     Compression:  uncompressed
     Data Start:   0x10392ff8
     Data Size:    14551 Bytes = 14.2 KiB
     Architecture: ARM
     Hash algo:    sha1
     Hash value:   ccd6dd3727294d16a84249e9d31deae1727dedd9
   Verifying Hash Integrity ... sha1+ OK
   Booting using the fdt blob at 0x10392ff8
   Loading Kernel Image ... OK
   Loading Device Tree to 07ff9000, end 07fff8d6 ... OK

Starting kernel ...

Uncompressing Linux... done, booting the kernel.
Booting Linux on physical CPU 0x0
Linux version 4.9.0-xilinx-v2017.4 (aster_ism@linuxsim) (gcc version 6.2.1 20161016 (Linaro GCC 6.2-2016.11) ) #1 SMP PREEMPT Mon Jan 8 22:20:23 JST 2018
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
bootconsole [earlycon0] enabled
cma: Reserved 16 MiB at 0x3f000000
Memory policy: Data cache writealloc
percpu: Embedded 14 pages/cpu @ef7d2000 s25932 r8192 d23220 u57344
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 260608
Kernel command line: console=ttyPS0,115200 earlyprintk 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: 1012868K/1048576K available (6144K kernel code, 200K rwdata, 1464K rodata, 1024K init, 229K bss, 19324K 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 : 0xc0008000 - 0xc0700000   (7136 kB)
      .init : 0xc0900000 - 0xc0a00000   (1024 kB)
      .data : 0xc0a00000 - 0xc0a32000   ( 200 kB)
       .bss : 0xc0a32000 - 0xc0a6b698   ( 230 kB)
Preemptible hierarchical RCU implementation.
        Build-time adjustment of leaf fanout to 32.
        RCU restricting CPUs from NR_CPUS=4 to nr_cpu_ids=2.
RCU: Adjusting geometry for rcu_fanout_leaf=32, nr_cpu_ids=2
NR_IRQS:16 nr_irqs:16 16
efuse mapped to f0802000
slcr mapped to f0804000
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 f0804100
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 f080c000, 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: thread -1, cpu 0, socket 0, mpidr 80000000
Setting up static identity map for 0x100000 - 0x100058
CPU1: thread -1, cpu 1, socket 0, mpidr 80000001
Brought up 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
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 @ 0xf0880000
zynq-pinctrl 700.pinctrl: zynq pinctrl initialized
e0001000.serial: ttyPS0 at MMIO 0xe0001000 (irq = 25, base_baud = 6249999) is a xuartps
`▒▒k׋▒▒+W/▒*LW▒Y▒X▒▒ed
console [ttyPS0] enabled
bootconsole [earlycon0] disabled
bootconsole [earlycon0] disabled
GPIO IRQ not connected
XGpio: /amba_pl/gpio@41200000: registered, base is 1020
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
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: enabled with armv7_cortex_a9 PMU driver, 7 counters available
futex hash table entries: 512 (order: 3, 32768 bytes)
workingset: timestamp_bits=30 max_order=18 bucket_order=0
jffs2: version 2.2. (NAND) (SUMMARY)  © 2001-2006 Red Hat, Inc.
bounce: pool size: 64 pages
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
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
xdevcfg f8007000.devcfg: ioremap 0xf8007000 to f0904000
[drm] Initialized
brd: module loaded
loop: module loaded
m25p80 spi0.0: found s25fl128s, expected n25q512a
m25p80 spi0.0: s25fl128s (16384 Kbytes)
4 ofpart 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
macb e000b000.ethernet eth0: Cadence GEM rev 0x00020118 at 0xe000b000 irq 27 (00:0a:35:00:1e:53)
RTL8211E Gigabit Ethernet e000b000.etherne:00: attached PHY driver [RTL8211E Gigabit Ethernet] (mii_bus:phy_addr=e000b000.etherne:00, irq=-1)
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
mousedev: PS/2 mouse device common for all mice
i2c /dev entries driver
cdns-wdt f8005000.watchdog: Xilinx Watchdog Timer at f099a000 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
NET: Registered protocol family 10
sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
NET: Registered protocol family 17
can: controller area network core (rev 20120528 abi 9)
NET: Registered protocol family 29
can: raw protocol (rev 20120528)
can: broadcast manager protocol (rev 20161123 t)
can: netlink gateway (rev 20130117) max_hops=1
Registering SWP/SWPB emulation handler
hctosys: unable to open rtc device (rtc0)
of_cfs_init
mmc0: new high speed SDHC card at address 0001
of_cfs_init: OK
ALSA device list:
  No soundcards found.
mmcblk0: mmc0:0001 00000 7.41 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 (c0900000 - c0a00000)
random: fast init done
systemd[1]: System time before build time, advancing clock.
systemd[1]: Failed to insert module 'autofs4': No such file or directory
systemd[1]: systemd 229 running in system mode. (+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN)
systemd[1]: Detected architecture arm.

Welcome to Ubuntu 16.04.3 LTS!

systemd[1]: Set hostname to <arm>.
systemd[1]: Listening on udev Kernel Socket.
[  OK  ] Listening on udev Kernel Socket.
systemd[1]: Started Dispatch Password Requests to Console Directory Watch.
[  OK  ] Started Dispatch Password Requests to Console Directory Watch.
systemd[1]: Listening on Syslog Socket.
[  OK  ] Listening on Syslog Socket.
systemd[1]: Reached target Remote File Systems (Pre).
[  OK  ] Reached target Remote File Systems (Pre).
systemd[1]: Created slice System Slice.
[  OK  ] Created slice System Slice.
systemd[1]: Reached target Remote File Systems.
[  OK  ] Reached target Remote File Systems.
systemd[1]: Listening on udev Control Socket.
[  OK  ] Listening on udev Control Socket.
[  OK  ] Listening on /dev/initctl Compatibility Named Pipe.
[  OK  ] Reached target Encrypted Volumes.
[  OK  ] Reached target Swap.
[  OK  ] Created slice User and Session Slice.
[  OK  ] Created slice system-serial\x2dgetty.slice.
[  OK  ] Started Forward Password Requests to Wall Directory Watch.
[  OK  ] Reached target Paths.
[  OK  ] Listening on Journal Socket.
         Starting Remount Root and Kernel File Systems...
         Starting Nameserver information manager...
         Starting Load Kernel Modules...
[  OK  ] Reached target Slices.
         Starting Set console keymap...
[  OK  ] Started Trigger resolvconf update for networkd DNS.
[  OK  ] Listening on Journal Socket (/dev/log).
         Starting Journal Service...
         Starting Create Static Device Nodes in /dev...
[  OK  ] Started Remount Root and Kernel File Systems.
[  OK  ] Started Load Kernel Modules.
[  OK  ] Started Create Static Device Nodes in /dev.
[  OK  ] Started Set console keymap.
[  OK  ] Started Nameserver information manager.
[  OK  ] Started Journal Service.
[  OK  ] Reached target Network (Pre).
         Starting udev Kernel Device Manager...
         Mounting Configuration File System...
         Starting Apply Kernel Variables...
[  OK  ] Reached target Local File Systems (Pre).
         Starting Flush Journal to Persistent Storage...
         Starting udev Coldplug all Devices...
[  OK  ] Reached target Local File Systems.
         Starting Set console font and keymap...
         Starting Load/Save Random Seed...
[  OK  ] Mounted Configuration File System.
[  OK  ] Started udev Kernel Device Manager.
[  OK  ] Started Apply Kernel Variables.
[  OK  ] Started Load/Save Random Seed.
[  OK  ] Started Flush Journal to Persistent Storage.
         Starting Create Volatile Files and Directories...
         Starting Raise network interfaces...
[  OK  ] Started Create Volatile Files and Directories.
[  OK  ] Started udev Coldplug all Devices.
[  OK  ] Found device /dev/ttyPS0.
         Starting Network Time Synchronization...
         Starting Update UTMP about System Boot/Shutdown...
[  OK  ] Started Set console font and keymap.
[  OK  ] Started Network Time Synchronization.
[  OK  ] Started Update UTMP about System Boot/Shutdown.
[  OK  ] Reached target System Time Synchronized.
[  OK  ] Reached target System Initialization.
[  OK  ] Listening on Avahi mDNS/DNS-SD Stack Activation Socket.
[  OK  ] Listening on D-Bus System Message Bus Socket.
[  OK  ] Reached target Sockets.
[  OK  ] Reached target Basic System.
[  OK  ] Started Regular background program processing daemon.
         Starting Permit User Sessions...
         Starting LSB: Load kernel modules needed to enable cpufreq scaling...
         Starting Cape Manager Service...
         Starting LSB: Start busybox udhcpd at boot time...
         Starting System Logging Service...
[  OK  ] Started Cgroup management daemon.
         Starting LSB: Set the CPU Frequency Scaling governor to "ondemand"...
[  OK  ] Started D-Bus System Message Bus.
         Starting Avahi mDNS/DNS-SD Stack...
         Starting Connection service...
         Starting oFono Mobile telephony stack...
         Starting Login Service...
[  OK  ] Started Daily Cleanup of Temporary Directories.
         Starting Generic Board Startup...
[  OK  ] Created slice system-getty.slice.
[  OK  ] Started System Logging Service.
[  OK  ] Started Permit User Sessions.
[  OK  ] Started Cape Manager Service.
[  OK  ] Started Raise network interfaces.
[  OK  ] Started LSB: Start busybox udhcpd at boot time.
[  OK  ] Started LSB: Set the CPU Frequency Scaling governor to "ondemand".
[  OK  ] Started LSB: Load kernel modules needed to enable cpufreq scaling.
[  OK  ] Started Avahi mDNS/DNS-SD Stack.
[  OK  ] Started oFono Mobile telephony stack.
[  OK  ] Started Connection service.
[  OK  ] Started Login Service.
         Starting WPA supplicant...
         Starting LSB: set CPUFreq kernel parameters...
[  OK  ] Stopped OpenBSD Secure Shell server.
         Starting Set console scheme...
[  OK  ] Started Set console scheme.
[  OK  ] Started WPA supplicant.
[  OK  ] Started LSB: set CPUFreq kernel parameters.
[  OK  ] Reached target Network.
[  OK  ] Reached target Network is Online.
         Starting /etc/rc.local Compatibility...
         Starting LSB: Apache2 web server...
[  OK  ] Started Daily apt download activities.
[  OK  ] Started Daily apt upgrade and clean activities.
[  OK  ] Reached target Timers.
         Starting LSB: Advanced IEEE 802.11 management daemon...
[  OK  ] Started /etc/rc.local Compatibility.
[  OK  ] Started LSB: Advanced IEEE 802.11 management daemon.
[  OK  ] Started Serial Getty on ttyPS0.
[  OK  ] Started Getty on tty1.
[  OK  ] Reached target Login Prompts.
[  OK  ] Started LSB: Apache2 web server.

Ubuntu 16.04.3 LTS arm ttyPS0

default username:password is [ubuntu:temppwd]

起動したら、メッセージ通りuser=ubuntu, password=temppwdでログイン。 前回同様devmem(今回はdevmem2)を使用するので、インストール。

$ sudo apt-get update
$ sudo apt-get install devmem2

LD0を点灯させるなら、下記の通り。以下略。

$ sudo devmem2 0x41200000 w 0x1

なお、/sys/class/gpio があるので、こちらからも制御できると思われる。 PLのGPIOが見える。以下略。眠い。

ubuntu@arm:/sys/class/gpio$ ls -la
total 0
drwxrwxr-x  2 root gpio    0 Jan 10 13:26 .
drwxr-xr-x 45 root root    0 Jan  9 14:57 ..
-rw-rw----  1 root gpio 4096 Jan 10 13:26 export
lrwxrwxrwx  1 root gpio    0 Jan  9 14:32 gpiochip1020 -> ../../devices/soc0/amba_pl/41200000.gpio/gpio/gpiochip1020
lrwxrwxrwx  1 root gpio    0 Jan  9 14:32 gpiochip902 -> ../../devices/soc0/amba/e000a000.gpio/gpio/gpiochip902
-rw-rw----  1 root gpio 4096 Jan 10 13:25 unexport