UClinux/Building for the Terasic DE0-nano on Fedora 14

From Hamsterworks Wiki!

Jump to: navigation, search

This documents how to get ucLinux running on Terasic DE0-nano using a Fedora 14 development platform.

This is mostly lifted from http://www.ccm.ece.vt.edu/twiki/bin/view/Main/LinuxOnNIOS2InstallationDE0Nano (thank you Tony Frangieh!), but adds how to get Quartus 11.0 running on Fedora 14 x64.

Contents

Install the host Fedora 14 x64 environment

I installed the initial Fedora 14 x64 system in Virtualbox, using a VM with 20GB of disk for OS and 20GB of disk for /home. The install options was for "software development".

Once installed, I configured networking added on the Virtualbox guest additions, then run "yum update" to update everything to current.

Installing the required packages

Based on another sites, recommendations I installed the following packages:

 yum install subversion git-core git-gui make gcc ncurses-dev bison flex gawk gettext ccache zlib1g-dev libx11-dev texinfo liblzo2-dev pax-utils uboot-mkimage corkscrew

I put the Quartus install file into /usr/local/src and tried running it. It failed with "lib ld-linux.so.2 bad elf interpreter" during the install. After a bit of hunting it appears that the 32 bit library files are missing.

I fixed this by installing the following libraries (and dependencies) then rerunning the Quartus setup:

  yum -y install glibc.i686
  yum -y install libXm.i686
  yum -y install freetype.i686   
  yum -y install fontconfig.i686
  yum -y install libpng.i686
  yum -y install libXtst.i686
  /usr/local/src/11.0sp1_quartus_free_linux/setup

If you get an error that:

 quartus: error while loading shared libraries: libsys_cpt.so: cannot enable executable stack as shared object requires: Permission denied

The fix is:

  cd ~/altera/11.0sp1/quartus/linux
  execstack -c libstdc++-libc6.2-2.so.3 libicudata.so.34 libsys_cpt.so

IMPORTANT!!!

The 'make' utility needed to be downgraded from version 3.82 to version 3.81. I used the package on the Fedora 13 CD. Failure to do so will cause the build to fail with "mixed implicit and normal rules" as soon as you try to 'make' anything.

 rpm -Uvh --force make-3.81-18.fc12.x86_64.rpm

Obtaining the base distribution

In you home directory run the following command to pull down the code repository:

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

Building the SOPC hardware

In ~/uClinux/hardware/DE0-Nano/ unzip simple.zip. This archive contains DE0_Nano.qpf project for Altera Quartus II.

Open Quartus II, then open ~/uClinux/hardware/DE0-Nano/DE0_Nano.qpf.

In the Altera Quartus II main window, navigate to Tools -> SOPC Builder to open your SOPC system. You should see a window describing the different components of your system and the way they are connected. Do not use the newer 'QSYS' utility.

This is what the system looks like:

DE0 nano spoc simple.png

Generate the system by pressing the 'Generate' button.

Once done, a file called DE0_Nano_SOPC.ptf is generated - the full path to this file is required when configuring the kernel.

Close SOPC Builder saving changes to DE0_Nano_SOPC.sopc when asked.

In the Altera Quartus II main window, navigate to 'Processing' -> 'Start Compilation' to implement the design. You will get lots of warnings, but no errors.

Once done, this process will generate the bitstream file DE0_Nano.sof that will configure the FPGA on the DE0-Nano board.

Preparing the for the build

Change directory to ~/uClinux/tools/ and untar nios2gcc-20080203.tar.bz2 by executing the following commands in a terminal window:

tar xvjf nios2gcc-20080203.tar.bz2

This will create the ~/uClinux/distro/nios2-linux/ and ~/uClinux/tools/opt/ folders. The ~/uClinux/distro/nios2-linux/ folder contains the uClinux distro folder hierarchy, whereas the ~/uClinux/tools/opt/ folder contains the toolchain necessary for cross-compiling uClinux for Nios II.

Change directory to ~/uClinux/distro/nios2-linux/ and checkout the source files for uClinux and GNU tools by executing the following command in a terminal window:

./checkout

The checked out source files assume a Nios 2 system with a MMU. Since the hardware that you generated does not implement a MMU, you need to switch to test-nios2 uClinux branch for a non-MMU system. The switch has to be performed for the linux kernel (~/uClinux/distro/nios2-linux/linux-2.6/), and the distro (~/uClinux/distro/nios2-linux/uClinux-dist). Execute the following command in a terminal window in both kernel and distro folders:

git checkout test-nios2

For both cases, you should get the message " Switched to branch 'test-nios2' " informing you of the successful switch. The final step in setting up the software is to add the cross-compiler binaries to the $PATH variable. Using your editor of choice, open ~/.bashrc and append the following at the end of it:

# Nios II toolchain
export PATH=$PATH:~/uClinux/tools/opt/nios2/bin

Save your changes and close the file. Make sure to source your .bashrc from the terminal window you are using to update your PATH variable.

Build your boot image

In ~/uClinux/distro/nios2-linux/uClinux-dist run "make menuconfig" to start the configuration.

Under Vendor/Product Selection, choose 'Altera' as the Vendor, and 'nios2' as the Altera Products.

Under Kernel/Library/Defaults Selection, make sure that 'Customize Kernel Settings' is selected..

Exit the configuration menu by saving the new kernel configuration when asked to. At this stage, you should get a message like

 *** Run "make hwselect SYSPTF=<system.ptf>" first.  Stop., causing an error. 

Specify your hardware architecture by executing the following command:

  make vendor_hwselect SYSPTF=~/uClinux/hardware/DE0-Nano/simple/DE0_Nano_SOPC.ptf

Choose cpu as the CPU you wish to build the kernel against, and SDRAM as the device to execute kernel from. Once done, you should get a summary message similar to the one below:

 --- Summary using
 PTF: ~/uClinux/hardware/DE0-Nano/simple/DE0_Nano_SOPC.ptf
 CPU:                            cpu
 Program memory to execute from: sdram

Execute make menuconfig once again, and verify that Kernel/Library/Defaults Selection ---> 'Customize Kernel Settings' is still selected.

Exit the configuration menu by saving the new kernel configuration if asked to. The Linux Kernel Configuration menu opens at this stage.

Uncheck the 'Network Support' option.

Exit the configuration menu by saving the new kernel configuration when asked to.

Finally, generate your Linux image by executing the following command in a terminal window:

make

Once done, this command will generate a Linux image called zImage under ~/uClinux/distro/nios2-linux/uClinux-dist/images/

Configuring the FGPA and Booting Linux, with a fully licensed NIOS2

Set up your environment to run use the Quartus environment:

export PATH=$PATH:/opt/system/software/Altera/10.1/quartus/bin
export PATH=$PATH:/opt/system/software/Altera/10.1/nios2eds/bin
export PATH=$PATH:/opt/system/software/Altera/10.1/quartus/sopc_builder/bin
export PATH=$PATH:/opt/system/software/Altera/10.1/nios2eds/bin/gnu/H-i686-pc-linux-gnu/bin

It might pay to put these in a script.

In a terminal window, load the generated bitstream by executing the following command:

nios2-configure-sof ~/uClinux/hardware/DE0-Nano/simple/DE0_Nano.sof

Load the generated Linux image to memory and run it by executing the following command in a terminal window:

 nios2-download -g ~/uClinux/distro/nios2-linux/uClinux-dist/images/zImage
 The message displayed below informs you that the operation was successful:
 Downloaded 992KB in 8.5s (116.7KB/s)
 Verified OK                         
 Starting processor at address 0x02500000

Once loading is successful, open the Nios II terminal by executing the following command in terminal window:

 nios2-terminal

You should see uClinux booting and eventually the command prompt.

NOTE: I currently copy my '.sof' and 'zImage' file out into my Windows Hosting OS and program my device from there using the "NIOS II Command Line"

If you are using time-limited NIOS2 cores

If you haven't licensed the full NIOS2 processor it will only run while tethered to the JTAG programmer, so you have to do things slightly differently.

Set up your environment to run use the Quartus environment:

export PATH=$PATH:/opt/system/software/Altera/10.1/quartus/bin
export PATH=$PATH:/opt/system/software/Altera/10.1/nios2eds/bin
export PATH=$PATH:/opt/system/software/Altera/10.1/quartus/sopc_builder/bin
export PATH=$PATH:/opt/system/software/Altera/10.1/nios2eds/bin/gnu/H-i686-pc-linux-gnu/bin

It might pay to put these in a script

In a terminal window, load the generated bitstream by executing the following command:

 $ nios2-configure-sof DE0_Nano_time_limited.sof

You should see the following output

 Searching for SOF file:
 in .
   DE0_Nano_time_limited.sof
 
 File DE0_Nano_time_limited.sof contains one or more time-limited megafunctions that support the OpenCore Plus feature that will not work after the hardware evaluation time expires. Refer to the Messages window for evaluation time details.
 Info: SRAM Object File DE0_Nano_time_limited.sof contains time-limited megafunct
 ion that supports OpenCore Plus feature -- Vendor: 0x6AF7, Product: 0x00A2
 Info: *******************************************************************
 Info: Running Quartus II Programmer
 Info: Command: quartus_pgm --no_banner --mode=jtag -o p;DE0_Nano_time_limited.so  f
 Info: Using programming cable "USB-Blaster [USB-0]"
 Info: Using programming file DE0_Nano_time_limited.sof with checksum 0x004053A1
 for device EP4CE22F17@1
 Info: Started Programmer operation at Sun Sep 25 23:32:20 2011
 Info: Configuring device index 1
 Info: Device 1 contains JTAG ID code 0x020F30DD
 Info: Configuration succeeded -- 1 device(s) configured
 Info: Successfully performed operation(s)
 Info: Ended Programmer operation at Sun Sep 25 23:32:22 2011
 Please enter i for info and q to quit:q

DO NOT ENTER 'Q' OR CLOSE THIS WINDOW! The core is running 'tethered' - if you close this window the processor will be held in reset.

IN A SECOND WINDOW Load the generated Linux image to memory and run it by executing the following command in a terminal window:

 $ nios2-download -g ~/uClinux/distro/nios2-linux/uClinux-dist/images/zImage
 The message displayed below informs you that the operation was successful:
 Downloaded 992KB in 8.5s (116.7KB/s)
 Verified OK                         
 Starting processor at address 0x02500000

Then open the console by running:

 $ nios2-terminal.sh

Easy once somebody shows you how!

Adding your own functions

See uClinux/Expanding your DE0-NIOS2 system for how to add extra functions to your system (e.g using the LEDs, switches or GPIO.

Personal tools