Quick guide for porting uClinux to ALTERA DE2-70

来源:互联网 发布:最好的网络英语课程 编辑:程序博客网 时间:2024/05/27 06:16

Platform and tools:  Windows XP, Ubuntu 9.04, Nios || 9.1, Quartus || 9.1,   samba,  Vmware7.0

 

 

Prepare

 

Step 1,  Install Ubuntu in Vmware;

Step 2,  Constructing Samba server to share folds with (Host)XP; (Details has been introduced in my blog);

Step 3,  Install Nios as well as Quartus;

 

 

Let's begin

 

 

Step 1, Install necessary tools

sudo apt-get update

sudo apt-get install 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

 

Step 2, Check the environment and tools

 

 

 

ls -l /bin/sh


This should give "/bin/sh -> bash",
Otherwise, change it with following commands,

sudo rm /bin/sh

sudo ln -s bash /bin/sh

 

 

 

followed by a logout and log back in again(Recommended).

As root, check if you have "cc" which is a symlink to "gcc" ?

which gcc

gcc -v

which cc

cc -v

if not,

cd /usr/bin

ln -s gcc cc

Before compiling the 20090703 toolchain on a linux ubuntu/kubuntu 9.04 you need to make sure to install gcc version 4.2 (older) and gcc's file system link is properly pointing to it:

sudo apt-get install gcc-4.1

sudo rm /usr/bin/gcc

sudo ln -s gcc-4.1 /usr/bin/gcc

 

PS:  If you have installed more than one edition of gcc, make sure the edition that you point to is lower than 4.2, or it will stick whiling building the toolchain.

 

 

 

Step 3, Downloading the nios2-linux-20090730.tar

 

wget http://www.niosftp.com/pub/uclinux/nios2-linux-20090730.tar

 

This will take several hours. Maybe you will spend much less if use Xunlei to deal with it.

 

tar xvf nios2-linux-20090730.tar /

cd /nios2-linux

 

Check out the source,this will take a while

 

./checkout

 

 

Step 4,  Building the toolchain 

cd toolchain-build
gcc --version
git clean -f -x -d   # clean on restart
make
 gcc elf2flt gdb-host       #This takes about an hour

 

cd ..

Logout and login again. You can use the tools now. Run this to verify that you have it in your command search path,

nios2-linux-uclibc-gcc -v 

 

Step 5, Now let's compile a simple hello.c by this cross gcc tool

 

First, configure the cross compile environment

vim  ~/.bashrc

# Add a line in the end

PATH=$PATH:/home/hippo/nios2-linux/toolchain-build/build/nios2/bin

write a simple test file hello.c
#include <stdio.h>
******************************************************************************************
int main(void)
{
printf("hello, world!/n");
return 0;
}
******************************************************************************************

 

nios2-linux-uclibc-gcc hello.c -o hello -elf2flt
nios2-linux-uclibc-flthdr hello  #check the format of hello

Step 6, We can build the kernel now

cd uClinux-dist

make menuconfig

 


In the menuconfig, make sure it is selected as follows:

 

Vendor/Product Selection --->               # select
    --- Select the Vendor you wish to target

        Vendor (Altera)  --->               # should have default to Altera
    --- Select the Product you wish to target 

        Altera Products (nios2)   --->      # should have defaulted to nios2

 

Kernel/Library/Defaults Selection --->      # select

    --- Kernel is linux-2.6.x

        Libc Version (None)  --->           # should default to None - very important.

    [*] Default all settings (lose changes) # select

    [ ] Customize Kernel Settings 

    [ ] Customize Vendor/User Settings 

    [ ] Update Default Vendor Settings 

 

Then <exit> <exit> <yes>

 

 

 

Switch to XP, copy DE2_System/DE2_demonstrations/DE2_NET/ DE2_70_SOPC.ptf and DE2_70_NET.sof to the share folder by samba

Switch to Ubuntu, cd the share folder,then

 

cp DE2_70_SOPC.ptf /mnt

cd uClinux-dist

make vendor_hwselect SYSPTF=/mnt/DE2_70_SOPC.ptf

 

******************************************************************************************

 

 

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

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

Selection: 1

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

(1) sdram_u2
 Class: altera_avalon_new_sdram_controller
 Size: 33554432 bytes

(2) onchip_mem
 Class: altera_avalon_onchip_memory2
 Size: 8192 bytes

(3) cfi_flash
 Class: altera_avalon_cfi_flash
 Size: 8388608 bytes

(4) ssram
 Class: altera_avalon_cy7c1380_ssram
 Size: 2097152 bytes

(5) sdram_u1
 Class: altera_avalon_new_sdram_controller
 Size: 33554432 bytes

Selection: 5

 

 

******************************************************************************************

 

make

 

#This takes a while, if it is successful , it displays :

 

LD      arch/nios2/boot/compressedgy.o
  LD      arch/nios2/boot/compressedmlinux
  OBJCOPY arch/nios2/boot/zImage
Kernel: arch/nios2/boot/zImage is ready
make[3]:正在离开目录 `/nios2-linuxnux-2.6'
cp /nios2-linux/uClinux-distnux-2.6.x/arch/nios2/boot/zImage /nios2-linux/uClinux-dist/images/zImage
make[2]:正在离开目录 `/nios2-linux/uClinux-distendors/Altera/nios2'
make[1]:正在离开目录 a_ava 

 

 

#Now we got the zImage, and copy it to the share folder

 

 

Step 7, Are you excited? This step does make you excited!

 

Goto the share folder, copy zImage and DE2_70_NET.sof  to C:/test

 

Open a Nios II command shell on Windows from Windows Start-->Programs-->Altera-->Nios II 9.1 -->Nios II 9.1 Command Shell, and change to the download dir.

cd /cygdrive/c/test

 

step 1. Configure the FPGA,
nios2-configure-sof  DE2_70_NET.sof

 

step 2. Download and run the kernel image,
nios2-download -g zImage

 

nios2-terminal

 

  Done