日曜技術者のメモ

趣味でやった事のメモ書きです。

qemu2svを試してみた-2-

qemu2svを試してみた-1- - 日曜技術者のメモの続き
Device Treeの準備と動作確認

Linux

Device Tree

Linuxカーネルに付属しているDevice Treeを使うとqemu上でブートはするがネットワークが繋がらなかった。
色々試した結果zynq-zed.dtsを修正する事で接続できた。

  • zynq-zed.dtsを以下の様に修正
    chosen {                                                                                                                          
        /*bootargs = "console=ttyPS0,115200 root=/dev/ram rw earlyprintk";*/                                                          
         bootargs = "console=ttyPS0,115200 root=/dev/ram rw earlyprintk ip=:::::eth0:dhcp";                                           
        linux,stdout-path = "/amba@0/serial@e0001000";                                                                                
    } ; 

修正後dtsからdtbを生成する。

zynq_linux/linux-xlnx/scripts/dtc/dtc  -I dts -O dtb -o zynq-zed.dtb zynq-zed.dts

QEMU

スタートスクリプト

QEMU起動コマンドをスクリプトにしておく

#!/bin/sh

qemu-system-arm -M xilinx-zynq-a9 -m 1024 -serial null -serial mon:stdio \                          
    -dtb ./zynq-zed.dts -smp 1 -nographic \                                                               
    -kernel ./zImage \                                                                                
    -initrd filesystem/ramdisk.img \                                                                  
    -net nic,model=cadence_gem \                                                                      
    -net user \                                                                                       
    -tftp ~/ \                                                                                        
    -redir tcp:10023::23 -redir tcp:10080::80 -redir tcp:10022::22 -redir tcp:10021::21 -redir tcp:1234::1234

A9 MPコアなので-smp 2だと思うのだが、そうするとQEMUがエラーになったので-smp 1にしている。
-redirのオプションはポートフォワーディングで<tcp or udp> : <ホスト側ポート> :: <QEMU上OSのポート>となっている。
-initrdでしていしているramdisk.imgはhttp://www.xilinx.com/member/zynq_linux/zynq_linux.tar.gzの中にあるファイルをそのまま 使っている。

動作テスト

OSブート

ターミナルを二つ用意し、一つのターミナルで`./start_qemu.shを実行後もう一つのターミナルでsv側のmakeを実行するとLinuxがブートする。
以下にログを貼っておく。

[ginnyu-tei@localhost zynq_linux]$ ./start_qemu.sh 
[hw_if] Socket is listening for connections... Please start the rtl simulation.
        Timeout after 15 sec 
Warning: nic cadence_gem.1 has no peer
console [ttyPS0] enabled
console [ttyPS0] enabled
bootconsole [earlycon0] disabled
bootconsole [earlycon0] disabled
xdevcfg f8007000.ps7-dev-cfg: ioremap 0xf8007000 to f0066000
[drm] Initialized drm 1.1.0 20060810
brd: module loaded
loop: module loaded
m25p80 spi0.0: SPI transfer timed out
m25p80: probe of spi0.0 failed with error -110
e1000e: Intel(R) PRO/1000 Network Driver - 2.3.2-k
e1000e: Copyright(c) 1999 - 2013 Intel Corporation.
libphy: XEMACPS mii bus: probed
xemacps e000b000.ps7-ethernet: invalid address, use assigned
xemacps e000b000.ps7-ethernet: MAC updated ea:05:dc:07:2d:7b
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
zynq-edac f8006000.ps7-ddrc: ecc not enabled
cpufreq_cpu0: failed to get cpu0 regulator: -19
Xilinx Zynq CpuIdle Driver started
sdhci: Secure Digital Host Controller Interface driver
[ginnyu-tei@localhost zynq_linux]$ ./start_qemu.sh                                                    
[hw_if] Socket is listening for connections... Please start the rtl simulation.
        Timeout after 15 sec 
Warning: nic cadence_gem.1 has no peer
console [ttyPS0] enabled
console [ttyPS0] enabled
bootconsole [earlycon0] disabled
bootconsole [earlycon0] disabled
xdevcfg f8007000.ps7-dev-cfg: ioremap 0xf8007000 to f0066000
[drm] Initialized drm 1.1.0 20060810
brd: module loaded
loop: module loaded
m25p80 spi0.0: SPI transfer timed out
m25p80: probe of spi0.0 failed with error -110
e1000e: Intel(R) PRO/1000 Network Driver - 2.3.2-k
e1000e: Copyright(c) 1999 - 2013 Intel Corporation.
libphy: XEMACPS mii bus: probed
xemacps e000b000.ps7-ethernet: invalid address, use assigned
xemacps e000b000.ps7-ethernet: MAC updated ae:93:fe:cd:f7:8a
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
zynq-edac f8006000.ps7-ddrc: ecc not enabled
cpufreq_cpu0: failed to get cpu0 regulator: -19
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: no vqmmc regulator found
mmc0: no vmmc regulator found
mmc0: SDHCI controller on e0100000.ps7-sdio [e0100000.ps7-sdio] using ADMA
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
TCP: cubic registered
NET: Registered protocol family 17
zynq_pm_remap_ocm: OCM pool is not available
zynq_pm_late_init: Unable to map OCM.
Registering SWP/SWPB emulation handler
regulator-dummy: disabling
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
Sending DHCP requests ., OK
IP-Config: Got DHCP answer from 10.0.2.2, my address is 10.0.2.15
IP-Config: Complete:
     device=eth0, hwaddr=ae:93:fe:cd:f7:8a, ipaddr=10.0.2.15, mask=255.255.255.0, gw=10.0.2.2
     host=10.0.2.15, domain=, nis-domain=(none)
     bootserver=10.0.2.2, rootserver=10.0.2.2, rootpath=
     nameserver0=10.0.2.3
ALSA device list:
  No soundcards found.
RAMDISK: ext2 filesystem found at block 0
RAMDISK: Loading 8192KiB [1 disk] into ram disk... done.
VFS: Mounted root (ext2 filesystem) on device 1:0.
devtmpfs: mounted
Freeing unused kernel memory: 184K (c05f9000 - c0627000)
Starting rcS...
++ Mounting filesystem
++ Setting up mdev
++ Starting telnet daemon
++ Starting http daemon
++ Starting ftp daemon
++ Starting dropbear (ssh) daemon
random: dropbear urandom read with 0 bits of entropy available
xemacps e000b000.ps7-ethernet: Set clk to 123809522 Hz
xemacps e000b000.ps7-ethernet: link up (1000/FULL)
rcS Complete
zynq> 
  • sv側
[ginnyu-tei@localhost svdpi_test]$ make
vlib work
vlog -sv -dpiheader dpiheader.h mem_model.sv
Model Technology ModelSim ALTERA vlog 10.1d Compiler 2012.11 Nov  2 2012
-- Compiling package mem_model_sv_unit
-- Compiling module mem_model

Top level modules:
        mem_model
gcc -c -g -fpic -m32 -I/mnt/sdb1/altera/13.1/modelsim_ase//include mem_model.c
gcc -O0 -shared -m32 mem_model.o -o svdpi.so
vsim -c -sv_lib svdpi mem_model  -do "run -all; quit "
Reading /mnt/sdb1/altera/13.1/modelsim_ase/tcl/vsim/pref.tcl 

# 10.1d

# vsim -do {run -all; quit } -c -sv_lib svdpi mem_model 
# Loading /var/tmp/ginnyu-tei@localhost.localdomain_dpi_13953/linuxpe_gcc-4.5.0/export_tramp.so
# Loading sv_std.std
# Loading work.mem_model_sv_unit
# Loading work.mem_model
# Compiling /var/tmp/ginnyu-tei@localhost.localdomain_dpi_13953/linuxpe_gcc-4.5.0/exportwrapper.c
# Loading /var/tmp/ginnyu-tei@localhost.localdomain_dpi_13953/linuxpe_gcc-4.5.0/dpi_auto_compile.so
# Loading ./svdpi.so
# run -all 
# Start server connect...

また長くなったので次回