labs.beatcraft.com
DE0-Nano

DE0-Nano/Nios II uClinux

terasic社製FPGAボード DE0-NanoへNios II uCLinuxを導入する手順について記載します。

DE0Nano.jpg

導入手順、動作確認は以下のURLを元に行います。

Running uClinux on Terasic DE0-Nano Altera Board

DE0-Nanoの主なハードウェア仕様は以下のとおりです、
ハードウェア仕様の詳細についてはterasic社の
DE0-Nano Specificationを参照してください。

  • Cyclone IV EP4CE22F17C6N
  • Memory
    • 32MB SDRAM
    • 2Kb I2C EEPROM
  • INPUT/OUTPUT
    • LED: 8(緑)
    • Push button: 2
    • Dip switch: 4
  • Clock System
    • オンボードクロック発振機: 50MHz
  • Power Supply
    • USB: mini-AB x1

Nios II版uClinuxビルド環境

VMware上に以下の構成でビルド環境構築を行います。

  • OS: Ubuntu 12.04.2 Desktop(32bit版)
  • ディスク容量: 30GB
  • FPGA開発ツール: Quartus II Web Edition 11.1sp2 Web editon (Linux版)

VMwareのディスク容量は30GBを設定しています、Nios II uClinuxプロジェクトの
ダウンロード、展開などで約9GB使用し、Quartus II のダウンロードと
インストールで約9GB使用するためです。

Quartus II のバージョンは11.1sp2(無償版)を使用します。
Nios II EDSはQuartus IIのインストールと共に導入されます。

Ubuntuの環境設定

Ubuntu 12.04.2 Desktop(32bit版)をVMware上にインストールし、
アップデートと下記のパッケージインストールを行います。

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install ssh
$ sudo apt-get install build-essential vim
$ sudo apt-get install automake git-core libncurses5-dev bison flex gawk
$ sudo apt-get install gettext ccache zlib1g-dev libx11-dev texinfo \
        liblzo2-dev pax-utils uboot-mkimage corkscrew mtd-utils subversion

標準shellをdashからbashへ変更します。

$ sudo dpkg-reconfigure dash

Nios II uClinux用ファイル取得と設定

Nios II uClinuxのプロジェクトをチェックアウトします。

ディスク使用量はプロジェクトのチェックアウトで約4.1GB、各アーカイブの展開、
ブランチのチェックアウト、ビルドまで含めると合計で約9GB必要です。

$ cd ~
$ svn co http://www.ccm.ece.vt.edu/usvn/svn/alteraApps/trunk/uClinux/ --username=anonymous --password=anonymous


toolchainのインストールを行います。
toolchainはuClinux/tools/nios2gcc-20080203.tar.bz2を使用します
nios2gcc-20080203.tar.bz2を解凍するとoptディレクトリが作成されます
${HOME}/.bashrcの末尾にPATHを追加し環境変数の更新を行います。

$ cd uClinux/tools/
$ tar xvfj nios2gcc-20080203.tar.bz2
$ vi ~/.bashrc 
...<略>
PATH=$PATH:${HOME}/uClinux/tools/opt/nios2/bin
$ source ~/.bashrc

DE0-Nanoのプロジェクトファイル(simple.zip)を解凍します。

$ cd uClinux/hardware/DE0-Nano
$ unzip simple.zip

uClinux/distro/内にあるnios2-linux-20090929.tarを展開します。

$ cd ~/uClinux/distro/
$ tar xvf nios2-linux-20090929.tar

展開後のディレクトリ構成は以下のとおりです

$ ls nios2-linux
3c120_default  elf2flt  linux-2.6        u-boot        use_git_for_update
README         gcc3     sshkey           uClibc        use_http_for_update
binutils       glibc    toolchain-build  uClinux-dist  use_ssh443_for_update
checkout       insight  toolchain-mmu    update

nios2-linuxに移動しcheckoutスクリプトを実行し該当ディレクトリのチェックアウトを行います。
スクリプト実行後linux-2.6、uClinux-distの各ディレクトリに移動し、
DE0-Nano用ブランチ(test-nios2)のチェックアウトを行います。

$ cd nios2-linux
$ ./checkout
$ cd linux-2.6
$ git branch -a
* nios2mmu
  test-nios2
  remotes/origin/HEAD -> origin/test-nios2
  remotes/origin/master
  remotes/origin/nios2mmu
  remotes/origin/test-lm32
  remotes/origin/test-nios2
  remotes/origin/unstable
  remotes/origin/unstable-nios2mmu
$ git checkout test-nios2
$ cd ../uClinux-dist
$ git branch -a
  test-nios2
* trunk
  remotes/origin/HEAD -> origin/test-nios2
  remotes/origin/test-nios2
  remotes/origin/trunk
  remotes/origin/unstable
$ git checkout test-nios2

注:Altera Wiki/Install Nios II Linuxに記載のあるnios2-linux-20090929.tar以降の
uClinuxはmmu kernelがマージされており、ブランチ間にkernelバージョンのズレなど
幾つか問題を確認したため本稿ではnios2-linux-20090929版を使用しています

Nios II uClinux zImage作成

uClinux-distディレクトリ内でmake menuconfig コマンドを実行しDE0-Nano用の 
設定になっているか確認を行います。

確認項目はVendorがAltera、Altera Productsがnios2のみであること、
Kernel is linux-2.6.xと表示されていることです。

make menuconfig実行時 Run "make hwselect SYSPTF=<system.ptf>" first. という
エラーメッセージが表示されます、menuconfig完了後上記のDE0-Nano用プロジェクト
ファイルuClinux/hardware/DE0-Nano/simple/DE0_Nano_SOPC.ptfを使用し
make vendor_hwselect SYSPTF=... を実行します。
CPU SDRAMの項目で1を選択し準備完了です。

makeコマンド完了後、imagesディレクトリ以下にzImageが作成されます。
make menuconfigの内容とmake実行までの簡易ログを以下に添付します。

$ make menuconfig

Vendor/Product Selection  --->
  --- Select the Vendor you wish to target
      Vendor (Altera)  --->
  --- Select the Product you wish to target
      Altera Products (nios2)  --->
Kernel/Library/Defaults Selection  --->
  --- Kernel is linux-2.6.x
  Libc Version (None)  --->
  [ ] Default all settings (lose changes)
  [ ] Customize Kernel Settings
  [ ] Customize Application/Library Settings
  [ ] Update Default Vendor Settings
$ make vendor_hwselect SYSPTF=/home/beat/uClinux/hardware/DE0-Nano/simple/DE0_Nano_SOPC.ptf
...<略>
scripts/kconfig/conf -s arch/nios2/Kconfig
  no emulation specific options.
  RUNNING hwselect

--- Please select which CPU you wish to build the kernel against:

(1) cpu - Class: altera_nios2 Type: f Version: 7.08101

Selection: 
Invalid response, please try again.
Selection: 1

--- Please select a device to execute kernel from:

(1) sdram
	Class: altera_avalon_new_sdram_controller
	Size: 33554432 bytes

Selection: 1
...<略>
$ make
$ ls images
romfs-inst.log  zImage

Quartus II, Nios II EDSの導入

Quartus II 11.1sp2 Web Edition (Linux版)をAltera社ダウンロードページ内の
”個別ダウンロード”よりダウンロードします。

https://www.altera.com/jp/download/dnl-index.jsp

ダウンロードファイルは約3GBあります。
またインストールに必要なディスク容量は最大で6GB使用します。
インストールディレクトリはホームディレクトリを選択しています。

$ chmod +x 11.0sp1_quartus_free_linux.sh
$ ./11.0sp1_quartus_free_linux.sh

Quartus II、Nios II EDSのパスを追加します。

$ export PATH=$PATH:/home/beat/altera/11.1sp2/quartus/bin
$ export PATH=$PATH:/home/beat/altera/11.1sp2/nios2eds/bin
$ export PATH=$PATH:/home/beat/altera/11.1sp2/quartus/sopc_builder/bin
$ export PATH=$PATH:/home/beat/altera/11.1sp2/nios2eds/bin/gnu/H-i686-pc-linux-gnu/bin

コンフィグレーションファイル作成

DE0-Nanoコンフィグレーションファイル(DE0_Nano.sof)を作成します。

Quartus IIを起動し、Open Existing Projectから
${HOME}/uClinux/hardware/DE0-Nano/simple/DE0_Nano.qpfを選択します。

$ quartus

SOPC Builder(QuartusIIメニューバー Tools -> SOPC Builder)を起動します

この際プロジェクトファイルが10.1で作成されている旨のWarningダイアログが
表示されますがOKを押して問題ありません。
またQSYSのインストールを促すメッセージダイアログが表示されますが、
本稿では使用しないので「x」を押してメッセージを閉じます。

SOCP Builder画面下側のGenerateボタンでDE0_Nano_SOPC.sopcを作成、保存します
Quartus IIに戻りQuartus II上Processing -> Start Compilationを実行し
DE0_Nano.sofを作成、保存します。

USB-Blasterインストール

ホストマシンからDE0-Nanoのコンフィグレーション、イメージ投入を行うためUSB-Blasterの設定をします。
以下のようにudev/rules.dにファイルを追加しルールの更新を行います。
DE0-Nanoを接続した際、USBデバイスが追加されUSB-Blasterと認識されます。

$ lsusb
...<略>
Bus 002 Device 008: ID 09fb:6001 Altera Blaster
$ sudo vi /etc/udev/rules.d/51-usbblaster.rules

SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTR{idVendor}=="09fb", 
ATTR{idProduct}=="6001", MODE="0666", 
NAME="bus/usb/$env{BUSNUM}/$env{DEVNUM}", RUN+="/bin/chmod 0666 %c"

$ sudo udevadm control --reload-rules

Nios II uClinuxの起動

Nios II uClinux起動のため、環境変数設定スクリプトnios2_command_shell.shを実行します。
nios2_command_shell.shは${HOME}/altera/11.1sp2/nios2eds内にあります。
またスクリプト実行時shellが切り替わります。

DE0-Nanoを接続しconfigureを行い、作成したzImageを投入します。
完了後nios2-terminalコマンドを実行すると
Nios II uClinuxのbootが開始します。

以下にその手順およびログ、Nios II uClinux起動後の各コマンド実行結果を記載します。

$ cd altera/11.1sp2/nios2eds/
$ ./nios2_command_shell.sh
$ nios2-configure-sof ~/uClinux/hardware/DE0-Nano/simple/DE0_Nano.sof

/home/beat/altera/11.1sp2/quartus/adm/qenv.sh: line 87: warning: setlocale: 
LC_CTYPE: cannot change locale (en_US): No such file or directory
Info: *******************************************************************
Info: Running Quartus II 32-bit Programmer
Info: Command: quartus_pgm --no_banner --mode=jtag -o p;/home/beat/uClinux /hardware/DE0-Nano/simple/DE0_Nano.sof
Info (213045): Using programming cable "USB-Blaster [2-2.1]"
Info (213011): Using programming file /home/beat/uClinux/hardware/DE0-Nano/simple/DE0_Nano.sof with checksum 0x003F2B7E for device EP4CE22F17@1
Info (209060): Started Programmer operation at Wed Mar  6 20:45:12 2013
Info (209016): Configuring device index 1
Info (209017): Device 1 contains JTAG ID code 0x020F30DD
Info (209007): Configuration succeeded -- 1 device(s) configured
Info (209011): Successfully performed operation(s)
Info (209061): Ended Programmer operation at Wed Mar  6 20:45:13 2013
Info: Quartus II 32-bit Programmer was successful. 0 errors, 0 warnings
    Info: Peak virtual memory: 104 megabytes
    Info: Processing ended: Wed Mar  6 20:45:13 2013
    Info: Elapsed time: 00:00:05
    Info: Total CPU time (on all processors): 00:00:01
$ ./altera/11.1sp2/nios2eds/nios2_command_shell.sh
------------------------------------------------
Altera Nios2 Command Shell [GCC 4]

Version 11.1sp2, Build 259
------------------------------------------------
$ nios2-download -g ~/uClinux/distro/nios2-linux/uClinux-dist/images/zImage
Using cable "USB-Blaster [2-2.1]", device 1, instance 0x00
Pausing target processor: OK
Initializing CPU cache (if present)
OK
Downloaded 1349KB in 343.0s (3.9KB/s)
Verified OK in 3.4s (396.7KB/s)
Starting processor at address 0x02500000
$ nios2-terminal
nios2-terminal: connected to hardware target using JTAG UART on cable
nios2-terminal: "USB-Blaster [2-2.1]", device 1, instance 0
nios2-terminal: (Use the IDE stop button or Ctrl-C to terminate)

Uncompressing Linux... Ok, booting the kernel.
Linux version 2.6.30 (beat@DE0NanoVM) (gcc version 3.4.6) #2 PREEMPT Wed Mar 6 15:44:48 JST 2013


uClinux/Nios II
Built 1 zonelists in Zone order, mobility grouping off.  Total pages: 8128
Kernel command line:
NR_IRQS:32
PID hash table entries: 128 (order: 7, 512 bytes)
Dentry cache hash table entries: 4096 (order: 2, 16384 bytes)
Inode-cache hash table entries: 2048 (order: 1, 8192 bytes)
Memory available: 29976k/2492k RAM, 0k/0k ROM (1669k kernel code, 823k data)
Calibrating delay loop... 49.04 BogoMIPS (lpj=245248)
Mount-cache hash table entries: 512
net_namespace: 264 bytes
NET: Registered protocol family 16
init_BSP(): registering device resources
bio: create slab <bio-0> at 0
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 1024 (order: 1, 8192 bytes)
TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
TCP: Hash tables configured (established 1024 bind 1024)
TCP reno registered
NET: Registered protocol family 1
io scheduler noop registered
io scheduler deadline registered (default)
ttyJ0 at MMIO 0x4001030 (irq = 1) is a Altera JTAG UART
console [ttyJ0] enabled
dm9000 Ethernet Driver, V1.31
TCP cubic registered
NET: Registered protocol family 17
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
Freeing unused kernel memory: 596k freed (0x21da000 - 0x226e000)
Shell invoked to run file: /etc/rc
Command: hostname uClinux
Command: mount -t proc proc /proc -o noexec,nosuid,nodev
Command: mount -t sysfs sysfs /sys -o noexec,nosuid,nodev
Command: mount -t devpts devpts /dev/pts -o noexec,nosuid
Command: mount -t usbfs none /proc/bus/usb
mount: mounting none on /proc/bus/usb failed: No such file or directory
Command: mkdir /var/tmp
Command: mkdir /var/log
Command: mkdir /var/run
Command: mkdir /var/lock
Command: mkdir /var/empty
Command: ifconfig lo 127.0.0.1
Command: route add -net 127.0.0.0 netmask 255.0.0.0 lo
Command: cat /etc/motd
Welcome to
          ____ _  _
         /  __| ||_|
    _   _| |  | | _ ____  _   _  _  _
   | | | | |  | || |  _ \| | | |\ \/ /
   | |_| | |__| || | | | | |_| |/    \
   |  ___\____|_||_|_| |_|\____|\_/\_/
   | |
   |_|

For further information check:
http://www.uclinux.org/

Execution Finished, Exiting

Sash command shell (version 1.1.1)
/>
/> cat /proc/cpuinfo
CPU:            NIOS2
MMU:            none
FPU:            none
Clocking:       100.0MHz
BogoMips:       49.04
Calibration:    24524800 loops
/> cat /proc/meminfo
MemTotal:          30572 kB
MemFree:           28880 kB
Buffers:               0 kB
Cached:              780 kB
SwapCached:            0 kB
Active:              192 kB
Inactive:            536 kB
Active(anon):          0 kB
Inactive(anon):        0 kB
Active(file):        192 kB
Inactive(file):      536 kB
Unevictable:           0 kB
Mlocked:               0 kB
MmapCopy:            244 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:             0 kB
Mapped:                0 kB
Slab:                508 kB
SReclaimable:        160 kB
SUnreclaim:          348 kB
PageTables:            0 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:       15284 kB
Committed_AS:          0 kB
VmallocTotal:          0 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
/> dmesg 
Linux version 2.6.30 (beat@DE0NanoVM) (gcc version 3.4.6) #2 PREEMPT Wed Mar 6 15:44:48 JST 2013


uClinux/Nios II
On node 0 totalpages: 8192
free_area_init_node: node 0, pgdat 021d6a60, node_mem_map 02274000
  DMA zone: 64 pages used for memmap
  DMA zone: 0 pages reserved
  DMA zone: 8128 pages, LIFO batch:0
Built 1 zonelists in Zone order, mobility grouping off.  Total pages: 8128
Kernel command line:
NR_IRQS:32
PID hash table entries: 128 (order: 7, 512 bytes)
Dentry cache hash table entries: 4096 (order: 2, 16384 bytes)
Inode-cache hash table entries: 2048 (order: 1, 8192 bytes)
Memory available: 29976k/2492k RAM, 0k/0k ROM (1669k kernel code, 823k data)
Calibrating delay loop... 49.04 BogoMIPS (lpj=245248)
Mount-cache hash table entries: 512
net_namespace: 264 bytes
NET: Registered protocol family 16
init_BSP(): registering device resources
bio: create slab <bio-0> at 0
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 1024 (order: 1, 8192 bytes)
TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
TCP: Hash tables configured (established 1024 bind 1024)
TCP reno registered
NET: Registered protocol family 1
io scheduler noop registered
io scheduler deadline registered (default)
ttyJ0 at MMIO 0x4001030 (irq = 1) is a Altera JTAG UART
console [ttyJ0] enabled
dm9000 Ethernet Driver, V1.31
TCP cubic registered
NET: Registered protocol family 17
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
Freeing unused kernel memory: 596k freed (0x21da000 - 0x226e000)
 /> ifconfig -a
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
/> ls -l /bin
-rwxr-xr-x  1 1000     1000       146884  Mar  5 2013  boa
-rwxr-xr-x  1 1000     1000       119578  Mar  5 2013  busybox
lrwxrwxrwx  1 1000     1000            7  Mar  5 2013  cp
lrwxrwxrwx  1 1000     1000            7  Mar  5 2013  dd
-rwxr-xr-x  1 1000     1000        52289  Mar  5 2013  dhcpcd
lrwxrwxrwx  1 1000     1000            7  Mar  5 2013  dmesg
-rwxr-xr-x  1 1000     1000        67414  Mar  5 2013  ftp
-rwxr-xr-x  1 1000     1000        67272  Mar  5 2013  ftpd
-rwxr-xr-x  1 1000     1000        24082  Mar  5 2013  inetd
-rwxr-xr-x  1 1000     1000        20892  Mar  5 2013  init
lrwxrwxrwx  1 1000     1000            7  Mar  5 2013  login
lrwxrwxrwx  1 1000     1000            7  Mar  5 2013  mount
lrwxrwxrwx  1 1000     1000            7  Mar  5 2013  netstat
lrwxrwxrwx  1 1000     1000            7  Mar  5 2013  ping
lrwxrwxrwx  1 1000     1000            7  Mar  5 2013  rm
-rwxr-xr-x  1 1000     1000        49587  Mar  5 2013  sh
-rwxr-xr-x  1 1000     1000        30050  Mar  5 2013  telnetd
/> ls -l /sbin
lrwxrwxrwx  1 1000     1000           14  Mar  5 2013  ifconfig
lrwxrwxrwx  1 1000     1000           14  Mar  5 2013  insmod
lrwxrwxrwx  1 1000     1000           14  Mar  5 2013  lsmod
lrwxrwxrwx  1 1000     1000           14  Mar  5 2013  modprobe
lrwxrwxrwx  1 1000     1000           14  Mar  5 2013  rmmod
lrwxrwxrwx  1 1000     1000           14  Mar  5 2013  route
/> ls -l /usr/bin
lrwxrwxrwx  1 1000     1000           17  Mar  5 2013  passwd
lrwxrwxrwx  1 1000     1000           17  Mar  5 2013  wget
/> ls -l /usr/sbin
/> busybox --help
BusyBox v1.15.0.svn (2013-03-06 15:43:22 JST) multi-call binary
Copyright (C) 1998-2008 Erik Andersen, Rob Landley, Denys Vlasenko
and others. Licensed under GPLv2.
See source distribution for full notice.

Usage: busybox [function] [arguments]...
   or: function [arguments]...

        BusyBox is a multi-call binary that combines many common Unix
        utilities into a single executable.  Most people will create a
        link to busybox for each function they wish to use and BusyBox
        will act like whatever it was invoked as!

Currently defined functions:
        cp, dd, dmesg, ifconfig, insmod, login, lsmod, modprobe, mount,
        netstat, passwd, ping, rm, rmmod, route, wget

/>

Tips

Quartus II web edition の Windows7 64bit へのインストールは以下のURLを参考にしてください

またWindows7 へインストールした場合、JTAG server が動かず DE0-Nanoなど
接続したボードが Quartus II から見えない場合があります
その場合の対処法については以下のURLを参考にしてください

参考文献

小林 優 (2011)『FPGAボードで学ぶ組込みシステム開発入門[Altera編]』技術評論社 383pp.


添付ファイル: fileDE0Nano.jpg 2483件 [詳細]

BC::labsへの質問は、bc9-dev @ googlegroups.com までお願い致します。
トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   最終更新のRSS
Last-modified: 2014-05-26 (月) 20:00:46 (3623d)