2012年2月25日土曜日

w11aをAvnet Microboardに移植

Avnet Microboard(秋月電子などで安価に入手できるXilinxのSpartan-6搭載のFPGA開発ボード)でOpenCoresのPDP-11が動いた。差分は最新のw11a_V0.55に対するパッチにまとめてある。具体的な動かし方などはOpenCoresのサイトや、アーカイブ中のドキュメントを参照。@magoroku15さんによる解説は非常に参考になる。


動作はUbuntu 10.04上のXilinx ISE 13.4で確認した。(私が買った時点でMicroboardに付属していた)13.2や13.3でも問題なく動作するはず。

MicroboardのオンボードのLEDやスイッチ、ボタンが貧弱であまり役に立たない。とりあえずDIPスイッチを(左から右へ)下上下下と設定しておくのを忘れなければ動くはず。

メインメモリはFPGA内蔵のblock RAMのみ使用しているので、64kbyteしかない。UNIX Version 5はちゃんと動くが、2.11BSDはboot中に例外が発生して停止してしまう。

MicroboardにはLPDDR SDRAMがたっぷり乗っているのでこちらをメインメモリにすれば2.11BSDも動くはず。そのためにはSpartan-6内蔵のメモリコントローラを利用するなど多少手間がかかるので、そのあたりは今後のお楽しみ。

2012年2月5日日曜日

ChipScope Pro Inserter をコマンドラインで使う(2)

ChipScope Pro Inserterを使うと、解析用のロジアナ等の回路を既存のngcに組み込むことができる。command lineからの使い方にはちょっと癖があってドキュメントだけではわかりにくいのでメモ。

まず、inserter -createで記述ファイルの雛形 *.cdcをつくる。この段階では何の情報も入力しない。したがって出力は実質、空。

つぎに、inserter -editで記述ファイルの中身を埋める。ここはGUIが起動する。引数にパーツ番号 -p xc6slx9-csg324-2 等を忘れず指定する必要がある(GUIの編集画面は何故か使えない)。ngdを生成するが、この段階のngdの必要性は謎。

最後に、inserter -insertで実際に回路をngcに追加する。この段階はcommand lineのみで処理できる。

ChipScope等のライセンスが必要となるのはngdbuildをかけるとき(きちんと確認してない)。したがって、inserterはwebpackでも実行可能。

2012年1月31日火曜日

w11でOSを実行する

FPGA上のPDP-11には各種デバイスは載っていない。実際にOSを実行する際には、PC上でハードディスクやシリアルによるコンソール接続をエミュレートするサーバーを動かして、FPGAと通信してデバイスの機能を提供する。その際、rlinkという専用の通信経路を使う。rlinkはPDP-11を動作させるためのインフラなので、PDP-11にとっては見えない。実際のFPGAボードではrlinkの入出力はおもにシリアル経由のUSBを利用する。

エミュレーターの場合は事情がすこし異なる。エミュレーター内の状態の変化を取り出すには、専用のインターフェースが必要である。w11aで提供されているghdlの場合、rlinkへの入出力部分はVHDLの記述をC言語で拡張したインターフェースによりnamed pipe経由で通信する。こういった拡張はエミュレーター依存であることに注意。

XilinxのISimなら実際のハードウェアに近いエミュレーションが可能なのだが、現在提供されていない。ISimはtclスクリプトによるコントロールが可能なので、これを使ってインターフェースを作ればいいはず。

ChipScope Pro Inserter をコマンドラインで使う(1)

XilinxのFPGAをJTAG経由で解析できるChipScope Proは、統合環境のISEだけでなくコマンドラインからも利用できる。詳しくはXilinxのドキュメントUG029であるChipScope Pro Software and Coresに詳しい記述がある。以下は、その際の注意書きである。

inserterを使う場合、Ubuntu 10.04では妙ちくりんなエラーが出た。

$ inserter
/opt/Xilinx/13.3/ISE_DS/ISE/bin/lin/unwrapped/cs_common.sh: 76: XIL_DIRS[0]=/opt/Xilinx/13.3/ISE_DS/ISE/: not found
/opt/Xilinx/13.3/ISE_DS/ISE/bin/lin/unwrapped/cs_common.sh: 76: count++: not found
/opt/Xilinx/13.3/ISE_DS/ISE/bin/lin/unwrapped/cs_common.sh: 152: Syntax error: Bad for loop variable
このcs_common.shというのは環境設定か何かをしているshell scriptで、先頭が#!/bin/shとなっているにもかかわらず、拡張文法を使っているのでshはエラーになる。bashなら処理できそうなので先頭を書き換えてみたが、症状は変わらない。どこかで/bin/shを決め打ちで呼んでいるようだ。したがって、/bin/shを/bin/bashに入れ替えるなどの対策が必要となる。


2012年1月4日水曜日

LinuxからAvnet Spartan-6 LX9 MicroBoardをプログラミングする

Avnet Spartan-6 LX9 MicroBoardのでかいほうのUSBの口にはAtmelのマイコンがぶらさがっていて、Digilentのfirmwareが乗っている。つまり、DigilentのUSB-jtagデバイスに見える。

これを操作するためのコマンドやライブラリーのたぐいは
/opt/Xilinx/13.4/ISE_DS/ISE/bin/lin/digilent/
に移動して(「13.4」はインストールしてあるISEのバージョン番号に置き換える)
./install_digilent.sh
を実行するとインストールできる(本来はISEのインストール時にインストールされるのかもしれないが未確認)。

Digilentから公開されている新しいファイルなどの情報は以下。
http://lighttomorrow.wordpress.com/2011/12/18/how-to-install-digilent-cable-driver-for-xilinx-design-suite-on-ubuntu-11-10/

bitstream(.bit)をMicroBoardに流し込むには、バッチファイルを作って、impactに渡す。

impact -batch foobar.impact

foobar.impactの中身はこんな感じ。

setMode -bscan
setCable -port auto
identify
assignfile -p 1 -file foobar.bit
program -p 1
quit

この時点ではfpgaのRAMに書かれているだけなので、リセットや電源を切ると忘れてしまう。

フラッシュROMイメージ.mcsの生成には以下のようなバッチファイルを使う。

setMode -pff
setPreference -pref StartupClock:Auto_Correction
setSubmode -pffspi
addDesign -version 0 -name "0"
addDeviceChain -index 0
addDevice -spi N25Q128 -p 1 -file foobar.bit
generate -format mcs -generic -spi -fillvalue FF -output foobar.mcs
quit

フラッシュROMイメージ.mcsの書き込みには以下のようなバッチファイルを使う。

setMode -bs
setCable -port auto
Identify -inferir
attachflash -position 1 -spi N25Q128
assignfiletoattachedflash -position 1 -file foobar.mcs
Program -p 1 -dataWidth 1 -spionly -e -v -loadfpga
quit
といってもimpcatを使ったROMイメージの書き込みはものすごく遅い。WindowsであればDigilentのSerial Flash Utilityを使ったほうがお手軽のようだ。そのへんのまとめが発売元の掲示板にあって参考になる。

2011年12月28日水曜日

w11コード生成メモ

OpenCoresのPDP-11/70のbitstreamを生成するためのメモ。
OSはUbuntu 10.04(とりあえずx86版)を使用する。11.10など新しいUbuntuでは、xstやmapの際にコマンド内部でシンボル名が解決できずに異常終了するなど厄介な症状が起きる。

追加インストールの必要なパッケージは以下のとおり:ghdl libboost-dev libboost-thread-dev g++ tcl-dev tclreadline

このほかkernel header(linux-headers-2.6.32-37-generic等)がないと、ISE Design Suiteのインストール時にドライバーのインストールに失敗するかもしれない(未確認)。

あとはISE Design Suite(13.2, 13.3, 13.4で確認)をインストールしてw11/trunk/doc/INSTALL.txtのとおりにすすめる。
ただし、tcl/setup_packageの実行時にLD_LIBRARY_PATHにISEが入っていると余計なライブラリに捕まってエラーが出るので、
tools/libのみにしておく必要がある。
また、current working directoryにpathが通っていることが前提になっているようなので、適宜修正しながら実行すること。

以上はNEXYS 3用でおこなって実際に動作することを確認済。

付記:
FPGA Editorを動かすためにはlibmotif3と、libstdc++.so.5が必要。
後者はaptで取れないので、陽に取得する必要がある。

wget http://ftp.us.debian.org/debian/pool/main/g/gcc-3.3/libstdc++5_3.3.6-18_i386.deb
sudo dpkg -i libstdc++5_3.3.6-18_i386.deb

さらに、DISPLAY変数に:0を設定しておくこと。

2010年4月10日土曜日

FON2305Eのシリアルコンソール

構成がFON2405Eにそっくりなことに気がついたので、FON2305Eも入手して調べてみた。
たいへん鬱陶しいことに、FON2405Eとはシリアルコンソールの配列が違う。

1 +3.3
2 RX
3 GND
4 TX

という具合にTXとGNDが逆になっている。コンソールの出力はFON2405Eとほとんど同じ。何故か定期的に文字化けするので、以下はFON2405Eの情報をもとに補正してある(ので、一部は嘘)。

U-Boot 1.1.3 (Nov 29 2009 - 20:59:38)

Board: Fonera
DRAM: 32 MB
relocate_code Pointer at: 81fac000
spi_wait_nsec: 3e
spi deice id: c2 20 15 c2 20 (2015c220)
find flash: mx25l1605d
raspi_read: from:41030000 len:1000
Using default environment

##### The CPU freq = 320 MHZ ####

SDRAM bus set to 16 bit
SDRAM size =32 Mbytes

Please choose the operation:
1: Boot system code via Flash (default).
2: Load system code then write to Flash via TFTP.
3: Entr boot command line interface.

booting from flash
## Booting image at bf020000 ...
raspi_read: from:20000 len:40
Image Name: MIPS OpenWrt Linux-2.6.21
Created: 2010-01-15 17:37:49 UTC
Image Type: MIPS Linux Kernel Image (lzma compressed)
Data Size: 613655 Bytes = 599.3 kB
Load Address: 80000000
Entry Point: 80000000
raspi_read: from:20040 len:95d17
1Verifying Checksum ... OK
Uncompressing Kernel Image ... OK
No initrd
## Transferring control to Linux (at address 80000000) ...
## Giving linux memsize in MB, 32

Starting kernel ...


LINUX started...

THIS IS ASIC
Linux version 2.6.21 (blogic@blap4) (gcc version 4.1.2) #143 Thu Jan 15 09:09:18 CET 2010

The CPU feqenuce set to 320 MHz
CPU revision is: 0001964c
Determined physical RAM map:
memory: 01000000 @ 00000000 (usable)
Built 1 zonelists. Total pages: 4064
Kernel command line: console=ttyS1,57600n8 root=/dev/mtdblock4 init=/sbin/preinit
Primary instruction cache 32kB, physically tagged, 4-way, linesize 32 bytes.
Primary data cache 16kB, 4-way, linesize 32 bytes.
Synthesized TLB refill handler (20 instructions).
Synthesized TLB load handler fastpath (32 instructions).
Synthesized TLB store handler fastpath (32 instructions).
Synthesized TLB modify handler fastpath (31 instructions).
Cache parity protection disabled
cause = 800060, status = 1100ff00
PID hash table entries: 64 (order: 6, 256 bytes)
calculating r4koff... 0030d400(3200000)
CPU frequency 320.00 MHz
Using 160.000 MHz high precision timer.
Dentry cache hash table entries: 2048 (order: 1, 8192 bytes)
Inode-cache hash table entries: 1024 (order: 0, 4096 bytes)
Memory: 14172k/16384k available (1689k kernel code, 2212k reserved, 186k data, 100k init, 0k highmem)
Mount-cache hash table entries: 512
NET: Registered protocol family 16
Generic PHY: Registered new driver
NET: Registered protocol family 2
Time: MIPS clocksource has been installed.
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 512 (order: 0, 4096 bytes)
TCP bind hash table entries: 512 (order: -1, 2048 bytes)
TCP: Hash tables configured (established 512 bind 512)
TCP reno registered
was not able to assign mahjor 200 to button chardev
ramips_gpio: done
squashfs: version 3.2-r2 (2007/01/15) Phillip Lougher
squashfs: LZMA suppport for slax.org by jro
io scheduler noop registered
io scheduler deadline registered (default)
ramips_wdt: loaded
Serial: 8250/16550 driver $Revision: 1.3 $ 2 ports, IRQ sharing disabled
serial8250: ttyS0 at I/O 0xb0000500 (irq = 37) is a 16550A
serial8250: ttyS1 at I/O 0xb0000c00 (irq = 12) is a 16550A
PPP generic driver version 2.4.2
NET: Registered protocol family 24
tun: Universal TUN/TAP device driver, 1.6
tun: (C) 1999-2004 Max Krasnyansky
deice id : c2 20 15 c2 20 (2015c220)
mx25l3205d(c2 20160000) (4096 Kbytes)
mtd .name = raspi, .size = 0x00400000 (4M) .erasesize = 0x00010000 (64K) .numeraseregions = 0
ramips_mtd: kernel size is 613719
padded kernel is 00096000
Creating 6 MTD partitions on "raspi":
0x00000000-0x00010000 : "uboot"
0x00010000-0x00020000 : "boardconfig"
0x00020000-0x00200000 : "image"
0x00020000-0x000b6000 : "linux"
mtd: partition "linux" doesn't end on an erase block -- force read-only
0x000b6000-0x001f0000 : "rootfs"
mtd: partition "rootfs" doesn't start on an erase block boundary -- force read-only
mtd: partition "rootfs" set to be root filesystem
0x001f0000-0x00200000 : "uci_overlay"
Registered led device: power
Registered led device: wps
Registered led device: wlan
nf_conntrack version 0.5.0 (128 buckets, 1024 max)
IPv4 over IPv4 tunneling driver
ip_tables: (C) 2000-2006 Netfilter Core Team, Type=Linux
TCP cubic registered
NET: Registered protocol family 1
NET: Registered protocol family 17
802.1Q VLAN Support v1.8 Ben Greear
All bugs added by David S. Miller
ramips: ethernet loaded
VFS: Mounted root (squashfs filesystem) readonly.
Freeing unused kernel memory: 100k freed
Warning: unable to open an initial console.
Preinit complete, spawning microd
found uci_overlay -> /dev/mtd5
i found OPENWRT_UCI_OVERLAY inside /dev/mtd5
loading file zepttho 275
loading file wireless 696
loading file user 70
loading file system 72
loading file reg 16
loading file network 473
loading file led 342
loading file lang 33
loading file form 4768
loading file fonsmcd 290
loading file fon 406
loading fileAlgorithmics/MIPS FPU Emulator v1.5
firewall 907
loading file passwd 149
loading file chilli.conf 566
loading fon config
Spawning syslogd
registering led wps -> /sys/class/leds/wps/
registering led wlan -> /sys/class/leds/wlan/
registering led power -> /sys/class/leds/power/
loading base firewall ...iptables: Chain already exists
done
adding zone wannet
adding zone lan
adding zone wan
adding zone hotspotwifi
adding zone hotspot
adding forwarding lan->wan
adding forwarding hotspot->wan
interface loopback
proto = static
ipaddr = 127.0.0.1
netmask = 255.0.0.0
ifname = lo
interface lan
proto = static
ipaddr = 192.168.10.1
netmask = 255.255.255.0
ifname = eth0.1
type = bridge
interface wan
proto = dhcp
ifname = eth0.2
interface hotspot
ifname = tun0
interface hotspotwifi
proto = none
ifname = ra1
net event up loopback ...bringing up lo
done
net event up lan ...bringing up eth0.1
eth0.1: dev_set_promiscuity(master, 1)
device eth0 entered promiscuous mode
device eth0.1 entered promiscuous mode
br-lan: port 1(eth0.1) entering learning state
adding br-lan to zone lan
done
net event up wan ...bringing up eth0.2
Spawning udhcpc for eth0.2
adding eth0.2 to zone wan
udhcpc (v0.9.9-pre) started
Trying to connect...
sending -> "udhcpc|deconfig|eth0.2|"
Sending discover...
done
wifi device rt305x
type = rt305x
channel = 11
mode = 9
wifi interface public
ifname = ra1
ssid = FON_FREE_INTERNET
encryption = none
network = hotspotwifi
device = rt305x
isolate = 1
auto = 1
wifi interface private
ifname = ra0
ssid = MyPlace
encryption = wpa-wpa2
key = 4141414141
password = iXHH3iPCI9
wpa_crypto = mixed
network = lan
device = rt305x
channel = 0
mode = bgn
txpower = 100
br-lan: topology change detected, propagating
br-lan: port 1(eth0.1) entering forwarding state
rt2860v2_ap: module license 'unspecified' taints kernel.
Sending discover...
WSending discover...
0x1300 = 00064380
bringing up rt30device ra0 entered promiscuous mode
5x ...done
br-lan: port 2(ra0) entering learning state
Terminate the task(RtmpCmdQTask) with pid(202)!
Terminate the task(RtmpWscTask) with pid(203)!
br-lan: port 2(ra0) entering disabled state
W0x1300 = 00064380
br-lan: port 2(ra0) entering learning state
Trying to connect...
sending -> "udhcpc|leasefail|eth0.2|"
br-lan: topology change detected, propagating
br-lan: port 2(ra0) entering forwarding state
bringing up private ...done
configured coova for mac 00:18:84:AF:38:71
Spawning dnsmasq
DHCP server is enabled
Spawning fonsmcd
Spawning zepttho
Spawning Onlined
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
KAMIKAZE (bleeding edge, r3201) -------------------
* 10 oz Vodka Shake well with ice and strain
* 10 oz Triple sec mixture into 10 shot glasses.
* 10 oz lime juice Salute!
---------------------------------------------------
I booted userland in 13 seconds
System bring up complete
syslogd: Jan 1 00:00:03 udhcpc[183]: udhcpc (v0.9.9-pre) started
deconfigure eth0.2
syslogd: Jan 1 00:00:03 udhcpc[183]: Sending discover...
syslogd: Jan 1 00:00:05 udhcpc[183]: Sending discover...
syslogd: Jan 1 00:00:07 udhcpc[183]: Sending discover...
syslogd: Nov 5 20:07:16 syslog: starting onlined

Now serving files from /www on :80
syslogd: Nov 5 20:07:16 dnsmasq[208]: started, version 2.45 cachesize 150
syslogd: Nov 5 20:07:16 dnsmasq[208]: compile time options: IPv6 GNU-getopt ISC-leasefile no-DBus no-I18N no-TFTP
syslogd: Nov 5 20:07:16 dnsmasq[208]: DHCP, IP range 192.168.10.50 -- 192.168.10.250, lease time 12h
syslogd: Nov 5 20:07:16 syslog: ERROR: unable access whitelist file: /etc/fon/whitelist.dnsmasq
syslogd: Nov 5 20:07:16 dnsmasq[208]: using local addresses only for domain lan
syslogd: Nov 5 20:07:16 dnsmasq[208]: reading /tmp/resolv.conf
syslogd: Nov 5 20:07:16 dnsmasq[208]: using nameserver 192.168.1.1#53
syslogd: Nov 5 20:07:16 dnsmasq[208]: using local addresses only for domain lan
syslogd: Nov 5 20:07:16 dnsmasq[208]: read /etc/hosts - 2 addresses
syslogd: Nov 5 20:07:16 dnsmasq[208]: failed to read /etc/ethers:No such file or directory
fonsmcd[209]: (Main) WARNING: SMC_find_boarddata: found board config /dev/mtd1ro
SMC_init(): called
fonsmcd[209]: (Main) MESSAGE: SMC_reload()
.W.....W.....fonsmcd[209]: (Main) WARNING: SMC_add_host: Error resolving host [cthulhu.fon.com], will try later
fonsmcd[209]: (Main) MESSAGE: SMC_retrieve_query_data()
fonsmcd[209]: (Main) WARNING: SMC_find_boarddata: found board config /dev/mtd1ro
wlanmac [00-18-84-af-38-71]
key_number [22aa6bec0e62fbb9abbff19646cb3cb3cf88e515560b58b7e5cc2dc11258d732]
fonsmcd[209]: (Main) WARNING: SMC_find_boarddata: found board config /dev/mtd1ro
W.....W.....W..fonsmcd[209]: (Main) CRITICAL: SMC_send_buffer: Error resolving host [cthulhu.fon.com]
...W.....W.....W...fonsmcd[209]: (Main) CRITICAL: SMC_send_buffer: Error resolving host [cthulhu.fon.com]
..W..


FON2405Eもそうなのだが、ブートセレクタやログインのプロンプトが一切出ない。コンソールから中身をいじる方法が何かあるのだろうか。