ZYNQ搭載のADCボード「Cosmo-Z」では、いままでXILINXのプレーンなLinuxを使っていました。

プレーンなLinuxでも正しく動作していたのですが、いくつかの不満もありました。具体的には
- 全体的にコマンドが貧弱(基本的にbusybox)
- aptなどのツールを使って新しいパッケージを入れられない
- ApacheやPHPが動かない
- sambaが動かない
といったところです。
そこで、アルバイトさんに調査をしてもらって、ZYNQでUbuntuを動かす方法を考えてもらいました。
結論としては、
- プレーンなLinuxもubuntuもカーネルは同じ。ファイルシステムをごっそりとUbuntuのものにすれば、ubuntuになる
- Petalinuxは使わなくてよい
- デバイスツリーの一部修正が必要
ということのようでした。
実際には、下記のWebサイトを参考にして
http://marsee101.blog19.fc2.com/blog-entry-2818.html
https://keitetsu.blogspot.jp/2015/01/zyboubuntu.html
ほぼ同じ手順で起動用SDカードを作成したようです。以下、アルバイトさんの残したメモにしたがって書いていきます。
① パーティションを分けます。
sudo gparted /dev/sdb

② 第二パーティションにubuntuのroot file systemだけを書き込みます。
https://releases.linaro.org/archive/12.11/ubuntu/precise-images/ からubuntu-desktopのlinaro-precise-ubuntu-desktop-20121124-560.tar.gzをダウンロード(nanoのほうを入れたら起動が早くなるかもしれない)
sudo tar --strip-components=3 -C /media/tkdn/ROOT_FS -xzpf linaro-precise-ubuntu-desktop-20121124-560.tar.gz binary/boot/filesystem.dir
③ 第一パーティションに入れるもの。
- BOOT.bin (busyboxを起動したときと同じもの)
- uImage (Linuxのカーネル)
- devicetree.dtb
なお、DeviceTreeのbootargsに
"console=ttyPS0,115200 root=/dev/mmcblk0p2 rw earlyprintk rootfstype=ext4 rootwait devtmpfs.mount=1";
を指定します。さらに、ここにmem=256Mと追加すれば、Linuxの認識するDRAM容量を制限できます。そうすると、Linuxからは後ろの768MBを認識しなくなるので、FPGAのPLから自由に使えます。
Cosmo-Zに特有の操作として、devicetree内のcpu0のプロパティoperating-pointを以下のように変更する必要があったようです。
前 : operating-points = <0xa2c2b 0xf4240 0x51616 0xf4240 0x3640f 0xf4240>;
後 : operating-points = <0xa2c2b 0xf4240 0x51616 0xf4240>;
- uEnv.txt (u-bootが読み込む設定ファイル)
uenvcmd=fatload mmc 0 0x03000000 uImage && fatload mmc 0 0x02A00000 devicetree.dtb && bootm 0x03000000 - 0x02A00000
(u-Bootの設定で読み込むかどうかを変えられるが、Cosmozで使っているu-bootがどういう設定になっているかわからないので一応入れておく。)
このようにして作ったファイルシステムと設定ファイルで、Ubuntuが起動するようになりました。

何より嬉しいのは、DHCPでIPアドレスを自動設定したあと、Windows PCから名前でCosmo-Zを探すことができるようになったことです。

Cosmo-Zのような機器がDHCPで自動的に取得したアドレスをネットワーク内の他のマシンから知るには、一般的で簡単な方法はありません。(よく、ネットワークプリンタなどではUDPでブロードキャストする専用のネットワーク設定ツールがありますが、それと同じ理由です。)
ですが、Sambaが動けばNetBIOSで名前が解決できます。
Windows PCからは
ping cosmoz-ubuntu
と打つだけで名前解決できてしまいます。nbtstatで探すこともできます。

Ubuntuが動くようになったので、早速apt-getでいろんなものを入れたくなります。
私はviは嫌いでemacsが好きなのですが、apt-getでさくっと入りました。便利ですね。
では最後に起動メッセージを
U-Boot 2014.07-00004-ga38e1e3-dirty (Jan 08 2015 - 00:30:24)
Board: Xilinx Zynq
I2C: ready
DRAM: ECC disabled 256 MiB
MMC: zynq_sdhci: 0
SF: Detected N25Q128A 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: Gem.e000b000
Hit any key to stop autoboot: 0
Device: zynq_sdhci
Manufacturer ID: 74
OEM: 4a60
Name: SDU1
Tran Speed: 50000000
Rd Block Len: 512
SD version 3.0
High Capacity: Yes
Capacity: 30.2 GiB
Bus Width: 4-bit
reading uEnv.txt
115 bytes read in 8 ms (13.7 KiB/s)
Loaded environment from uEnv.txt
Importing environment from SD ...
Running uenvcmd ...
reading uImage
3451432 bytes read in 303 ms (10.9 MiB/s)
reading devicetree.dtb
7396 bytes read in 16 ms (451.2 KiB/s)
## Booting kernel from Legacy Image at 03000000 ...
Image Name: Linux-3.17.0-xilinx-00085-gde136
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 3451368 Bytes = 3.3 MiB
Load Address: 00008000
Entry Point: 00008000
Verifying Checksum ... OK
## Flattened Device Tree blob at 02a00000
Booting using the fdt blob at 0x2a00000
Loading Kernel Image ... OK
Loading Device Tree to 0ed1e000, end 0ed22ce3 ... OK
Starting kernel ...
Booting Linux on physical CPU 0x0
Linux version 3.17.0-xilinx-00085-gde13611 (naitou@ubuntu) (gcc version 4.7.2 (Sourcery CodeBench Lite 2012.09-104) ) #1 SMP PREEMPT Thu Jan 8 07:40:50 JST 2015
CPU: ARMv7 Processor [413fc090] revision 0 (ARMv7), cr=18c5387d
CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
Machine model: Tokuden Cosmo-Z
cma: Reserved 16 MiB at 0f000000
Memory policy: Data cache writealloc
PERCPU: Embedded 8 pages/cpu @4edd9000 s8768 r8192 d15808 u32768
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 65024
Kernel command line: mem=256M console=ttyPS0,115200 root=/dev/mmcblk0p2 rw earlyprintk rootfstype=ext4 rootwait devtmpfs.mount=1
PID hash table entries: 1024 (order: 0, 4096 bytes)
Dentry cache hash table entries: 32768 (order: 5, 131072 bytes)
Inode-cache hash table entries: 16384 (order: 4, 65536 bytes)
Memory: 236376K/262144K available (4688K kernel code, 239K rwdata, 1592K rodata, 204K init, 210K bss, 25768K reserved, 0K highmem)
Virtual kernel memory layout:
vector : 0xffff0000 - 0xffff1000 ( 4 kB)
fixmap : 0xffc00000 - 0xffe00000 (2048 kB)
vmalloc : 0x50800000 - 0xff000000 (2792 MB)
lowmem : 0x40000000 - 0x50000000 ( 256 MB)
pkmap : 0x3fe00000 - 0x40000000 ( 2 MB)
modules : 0x3f000000 - 0x3fe00000 ( 14 MB)
.text : 0x40008000 - 0x4062a3b4 (6281 kB)
.init : 0x4062b000 - 0x4065e240 ( 205 kB)
.data : 0x40660000 - 0x4069be20 ( 240 kB)
.bss : 0x4069be20 - 0x406d07ac ( 211 kB)
Preemptible hierarchical RCU implementation.
Dump stacks of tasks blocking RCU-preempt GP.
RCU restricting CPUs from NR_CPUS=4 to nr_cpu_ids=2.
RCU: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=2
NR_IRQS:16 nr_irqs:16 16
L2C: platform provided aux values match the hardware, so have no effect. Please remove them.
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 0x76360001
ps7-slcr mapped to 50804000
zynq_clock_init: clkc starts at 50804100
Zynq clock init
sched_clock: 64 bits at 333MHz, resolution 3ns, wraps every 3298534883328ns
ps7-ttc #0 at 50806000, irq=43
Console: colour dummy device 80x30
Calibrating delay loop... 1332.01 BogoMIPS (lpj=6660096)
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 0x46ca18 - 0x46ca70
CPU1: Booted secondary processor
CPU1: thread -1, cpu 1, socket 0, mpidr 80000001
Brought up 2 CPUs
SMP: Total of 2 processors activated.
CPU: All CPU(s) started in SVC mode.
devtmpfs: initialized
VFP support v0.3: implementor 41 architecture 3 part 30 variant 9 rev 4
regulator-dummy: no parameters
NET: Registered protocol family 16
DMA: preallocated 256 KiB pool for atomic coherent allocations
cpuidle: using governor ladder
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.ps7-ocmc: ZYNQ OCM pool: 256 KiB @ 0x50880000
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
Advanced Linux Sound Architecture Driver Initialized.
Switched to clocksource arm_global_timer
NET: Registered protocol family 2
TCP established hash table entries: 2048 (order: 1, 8192 bytes)
TCP bind hash table entries: 2048 (order: 2, 16384 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP: reno registered
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: enabled with armv7_cortex_a9 PMU driver, 7 counters available
futex hash table entries: 512 (order: 3, 32768 bytes)
jffs2: version 2.2. (NAND) (SUMMARY) c 2001-2006 Red Hat, Inc.
msgmni has been set to 493
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
dma-pl330 f8003000.ps7-dma: Loaded driver for PL330 DMAC-2364208
dma-pl330 f8003000.ps7-dma: DBUFF-128x8bytes Num_Chans-8 Num_Peri-4 Num_Events-16
e0001000.serial: ttyPS0 at MMIO 0xe0001000 (irq = 82, base_baud = 6249999) is a xuartps
console [ttyPS0] enabled
xdevcfg f8007000.ps7-dev-cfg: ioremap 0xf8007000 to 5086a000
[drm] Initialized drm 1.1.0 20060810
brd: module loaded
loop: module loaded
m25p80 spi0.0: n25q128a11 (16384 Kbytes)
1 ofpart partitions found on MTD device spi0.0
Creating 1 MTD partitions on "spi0.0":
0x000000000000-0x000001000000 : "qspi-all"
CAN device driver interface
e1000e: Intel(R) PRO/1000 Network Driver - 2.3.2-k
e1000e: Copyright(c) 1999 - 2014 Intel Corporation.
libphy: XEMACPS mii bus: probed
xemacps e000b000.ps7-ethernet: pdev->id -1, baseaddr 0xe000b000, irq 54
ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
ehci-pci: EHCI PCI platform driver
zynq-dr e0002000.ps7-usb: Unable to init USB phy, missing?
usbcore: registered new interface driver usb-storage
mousedev: PS/2 mouse device common for all mice
i2c /dev entries driver
cdns-i2c e0004000.ps7-i2c: 40 kHz mmio e0004000 irq 57
zynq-edac f8006000.ps7-ddrc: ecc not enabled
cpufreq_cpu0: failed to get cpu0 regulator: -19
cpufreq: __cpufreq_add_dev: CPU0: Running at unlisted freq: 666666 KHz
cpufreq: __cpufreq_add_dev: CPU0: Unlisted initial frequency changed to: 666667 KHz
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
sdhci-arasan e0100000.ps7-sdio: No vmmc regulator found
sdhci-arasan e0100000.ps7-sdio: No vqmmc regulator found
mmc0: SDHCI controller on e0100000.ps7-sdio [e0100000.ps7-sdio] using ADMA
ledtrig-cpu: registered to indicate activity on CPUs
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
TCP: cubic registered
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 20120528 t)
can: netlink gateway (rev 20130117) max_hops=1
Registering SWP/SWPB emulation handler
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
ALSA device list:
No soundcards found.
mmc0: new high speed SDHC card at address 59b4
mmcblk0: mmc0:59b4 SDU1 30.1 GiB
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: 204K (4062b000 - 4065e000)
* Starting mDNS/DNS-SD daemon 24 bits of entropy available [ OK ]
* Starting configure network device security [ OK ]
* Starting network connection manager [ OK ]
* Starting bluetooth daemon [ OK ]
* Starting configure network device [ OK ]
* Starting configure network device security [ OK ]
* Starting Mount network filesystems [ OK ]
* Starting Failsafe Boot Delay [ OK ]
* Starting SMB/CIFS File Server [ OK ]
* Stopping cold plug devices [ OK ]
* Starting CUPS printing spooler/server [ OK ]
* Starting load fallback graphics devices [ OK ]
* Starting configure network device security [ OK ]
* Stopping Mount network filesystems [ OK ]
* Stopping log initial device creation [ OK ]
* Starting load fallback graphics devices [fail]
* Starting configure virtual network devices [ OK ]
* Starting save udev log and update rules [ OK ]
* Stopping save udev log and update rules [ OK ]
* Stopping configure virtual network devices [ OK ]
* Starting configure network device [ OK ]
* Stopping Failsafe Boot Delay [ OK ]
* Starting System V initialisation compatibility [ OK ]
* Starting set sysctls from /etc/sysctl.conf [ OK ]
* Stopping set sysctls from /etc/sysctl.conf [ OK ]
* Starting bluetooth daemon [ OK ]
* Starting Bridge socket events into upstart [ OK ]
* Starting bluetooth daemon [ OK ]
* Starting bluetooth daemon [ OK ]
* Starting bluetooth daemon [ OK ]
speech-dispatcher disabled; edit /etc/default/speech-dispatcher
saned disabled; edit /etc/default/saned
* Stopping System V initialisation compatibility [ OK ]
* Starting System V runlevel compatibility [ OK ]
* Starting automatic crash report generation [ OK ]
* Starting LightDM Display Manager [ OK ]
* Starting save kernel messages [ OK ]
* Starting regular background program processing daemon [ OK ]
* Starting anac(h)ronistic cron [ OK ]
* Stopping System V runlevel compatibility [ OK ]
* Stopping anac(h)ronistic cron [ OK ]
Last login: Thu Jan 1 00:00:09 UTC 1970 on tty1
* Starting bluetooth daemon [ OK ]
* Stopping System PulseAudio sound server [ OK ]
* Starting crash report submission daemon [ OK ]
* Stopping save kernel messages [ OK ]
run-parts: /etc/update-motd.d/98-fsck-at-reboot exited with return code 1
Welcome to Linaro 12.11 (GNU/Linux 3.17.0-xilinx-00085-gde13611 armv7l)
* Documentation: https://wiki.linaro.org/
root@cosmoz-ubuntu:~#
ここで入ったLinuxは、開発環境付の本格的なもののようで、gccも入っていました。ZYNQ上でセルフコンパイルして、実行することもできてしまいます。
emacsでプログラムを書いて・・

コンパイルして、実行!

ZYNQ上でセルフでできるというのが面白いですね。
最近のコメント