labs.beatcraft.com
DE0-Nano

DE0-Nano/Nios II uClinux

This article explains how to install uCLinux on DE0-Nano, a FPGA board developed by Terasic Technologies Inc.

DE0Nano.jpg


The hardware specification of DE0-Nano is listed below. For the details, please look at DE0-Nano Specification.

  • FPGA
    • Cyclone IV EP4CE22F17C6N
  • Memory
    • 32MB SDRAM
    • 2Kb I2C EEPROM
  • INPUT/OUTPUT
    • LED: 8(Green)
    • Push button: 2
    • Dip switch: 4
  • Clock System
    • Clock Oscillator: 50MHz (On-board)
  • Power Supply
    • USB: Type mini-AB port (5V)

For the installation procedure and operation check of the board, please follow the instructions written at the URL below.
Running uClinux on Terasic DE0-Nano Altera Board

uClinux (Nios II version) Built Environment

The built environment for Nios II uClinux is created on VMware. The settings for the OS and hardware are listed below.

  • OS: Ubuntu 12.04.2 Desktop(32bit Version)
  • Disk space: 30GB
  • FPGA Development Tool: Quartus II Web Edition 11.1sp2 Web editon (Linux Version)

The disk space, which WMware allocates for is 30GB. 9GB is used for downloading and extracting the Nios II uClinux project. 9GB is also consumed for downloading and installing Quartus II.

The version of Quartus II is 11.1sp2, and it is free version, too.
Nios II EDS is installed as a part of Quartus II's installation process

Configuring Preference of Ubuntu

Installing Ubuntu 12.04.2 Desktop (32bit Version) on VMware, update the OS and install the packages.

$ 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

Change from the standard shell to bash.

$ sudo dpkg-reconfigure dash

Obtaining and Configuring the Files for Nios II uClinux

Checkout the project of Nios II uClinux.

4.1GB of disk space is consumed for checking-out Nios II uClinux. Totally, 9GB of disk space is required as the extraction of the archive, checking the branch, and build process are included.

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


Now, toolchain is installed. The toolchain used here is located at uClinux/tools/nios2gcc-20080203.bz2. To extract nios2gcc-20080203.tar.bz2, opt directly is created. The environment variable is added at the end of ${HOME}/.bashrc.

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

Extract the DE0-Nano project file (simple.zip).

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

Extract nios2-linux-20090929.tar, which is located at the directory of uClinux/distro/.

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

After the extraction of tar file is completed, these files are created under the directory of nios2-linux.

$ 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


Moving the directory of nios2-linux, execute the script of checkout, and checkout a working copy from the specific repository. Completing the execution of the script, move to the directory of linux-2.6, and checkout the branch of DE0-Nano (test-nios2). This checkout is also repeated at the directory of uClinux-dist.

$ 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

Caution: Do not recommend to use any nios2-linux, which is newer than nios2-linux-20090929.tar. At Altera Wiki/Install Nios II Linux, nios2-linux-20100621.tar is used. However, since newer versions of uClinux, which is contained in the tar file of nios2-linux, is merged with mmu kernel, there are gaps between the branches uClinux. Because some issues are recognized, nios2-linux-20090929 is used for this article.

Creating Nios II uClinux zImage

At uClinux directory, executing make menuconfig, make sure that its configuration is set for DE0-Nano. The key check points are Vender and Altera Products, and these parts are defined as only Altera and nios2, respectively. Make sure that “Kernel is linux-2.6.x” is shown.
As make menuconfig is executed, an error message, Run”make hwselect SYSPTF=<system.ptf>” first, appears. After menuconfig is completed, using the project file for DE0-Nano, execute male vender_hwselect SYSPTF=... The project file is located at uClinux/hardware/DE0-Nano?simple/DE0_Nano_SOPC.ptf. At the part of CPU SDRAM, select 1. Then, the preparation for creating zImage is ended.
After make command is ended, zImage is created at the image directory.
A part of log, which is generated at executing of make menuconfig and make, is shown below.

$ 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
...<skip>
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
...<skip>
$ make
$ ls images
romfs-inst.log  zImage

Installing Quartus II and Nios II EDS

Download Quartus II 11.1sp2 Web Edition (Linux version) from the download page of Altera, Inc.

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

The size of the file is about 3GB, and the required disk space for installation is at most 6 GB. The home directory is selected for the installation process.

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

Add the PATHs for Quartus II and 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

Creating the Configuration File for DE0-Nano

The configuration file of DE0-Nano (DE0_Nano.sof) is created.

Starting up Quartus II, select ${HOME}/uClinux/hardware/DE0-Nano/simple/DE0_Nano.qpf from Open Existing Project.

$ quartus

Booting up SOPC Builder (QuartusII menu bar Tools → SOPC Builder)

At this moment, a warning dialog appears, saying that a project file is created with 10.1. This waring is not critical for the current condition, so please click OK.
Also, a message dialog that urges to install QSYS. QSYS will not be used here. Click x at the upper-right conner and close the dialog.

To create DE0_Nano_SOPC.sopc, click the Generate button at the bottom of the screen of SOCP builder. The created file is saved.
Return to Quartus II, slect Processing from the menu. Then, execute Start Compilation. After De0_Nanp.sof is created, it is saved.

Installing USB-Blaster

USB-Blaster is configured for setting up and installing the image of DE0-Nano from its host machine. The new rules, which are shown below, are added to the file of udev/rules.d. As DE0-Nano is attached, it is recognized as USB-Blaster.

$ lsusb
...<&#30053;>
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

Booting up Nios II uClinix

To start up uClinux, execute the environment variable configuration script, nios2_command_shell.sh. nios2_command_shell.sh is located at ${HOME}/altera/11.1sp2/nios2eds/. While executing the script, shell will be changed.

DE0-Nano is connected and set up with configure, then the created zImage is installed. After the completion of installing zImage, execute nios2-terminal command. To command nios2-terminal, the booting of Nios II uClinux begins.

The log shown below is resulted form executing the commands after Nios II uClinux is booted.

$ 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

To install Quartus II on web edition on Windows 7 64bit, please look at the URL below as reference.

Reference

Kobayashi, M. “Introduction to Development of Embedded System, Studying with an FPGA Board [Altera Version]”, pp383,
Tokyo, Gijutysu-Hyohron Co.,Ltd., 2011.

Revision History

  • 2013/07/01 This article is initially uploaded

Attach file: fileDE0Nano.jpg 1028 download [Information]

Front page   Edit Freeze Diff Backup Upload Copy Rename Reload   New List of pages Search Recent changes   RSS of recent changes
Last-modified: 2013-07-01 (Mon) 13:22:25 (1607d)