Version 28, changed by hippo5329@yahoo.com.tw. 08/21/2008. Show version history
Here we will setup the source to build Nios2 uClinux. branch "test-nios2" , per 20080619.
If you already have the toolchain and working uClinux-dist git repo, then you can skip the "new install" below and go to the second half, "Distro upgrade".
You must have a Linux desktop with software development packages. Login as root or use sudo to install these packages.
On Fedora,RHEL,Centos
sudo yum install git-core make gcc ncurses-devel bison flex gawk gettext ccache zlib-devel gtk2-devel
On Suse,
sudo zypper install git-core make gcc ncurses-devel bison flex gawk gettext ccache zlib-devel
On Debian/Ubuntu,
sudo apt-get update
sudo apt-get install git-core make gcc ncurses-dev bison flex gawk gettext ccache zlib1g-dev libx11-dev texinfo
Please check your git version with "git --version". If it is older than 1.5.3.x, please update to the latest.
On Ubuntu, check if the default shell is "bash"
ls -l /bin/sh
This should give "/bin/sh -> bash",
Otherwise, change it with,
sudo rm /bin/sh
sudo ln -s bash /bin/sh
followed by a logout and log back in again.
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
Make sure you have 5GB or more free disk space. Please download the tar file nios2-linux-20080619.tar , 880MB. Best thanks to Altera's kindly hosting these files.
(but don't use Windows ftp, it corrupt the files)
ftp://ftp.altera.com/outgoing/nios2-linux-20080619.tar
(SHA1SUM bb851b5494b4ae5c6ccdcfa5625b0f4d9340252a nios2-linux-20080619.tar)
We use "git" to keep the source. You make check out GitServer later. The git database inside the tar file was compressed, so we don't do compression on the tar file.
You can build in any working directory as a user account, eg. in your home (say /home/hippo). The tar file contains a nios2-linux dir.
tar xf <path_to>nios2-linux-20080619.tar # untar the package
cd nios2-linux
ls # see what's in
binutils gcc3 README uClibc use_http_for_update
checkout insight toolchain-build uClinux-dist
elf2flt linux-2.6 u-boot update
# check out the source
./checkout
Now the source for the Nios2 uClinux and gnutools was ready.
linux-2.6: the Linux kernel source, which is stock Linux kernel plus Nios2 specific patches. The current version is v2.6.26-rc6.
uClinux-dist: the uClinux userspace libraries and applications. We will build uClinux here.
binutils,gcc3,elf2flt,insight: the gnu tools.
uClibc: the main userspace libraries, which is smaller that glibc. please note, newlib doesn't support Nios2 uClinux.
u-boot: a powerful boot loader and monitor, DasUBoot .
We will proceed to build the toolchain. If you don't want or fail to build it yourself, you may use the prebuild BinaryToolchain.
cd toolchain-build
git clean -f -x -d # clean on restart
make gcc elf2flt gdb-host
cd ..
It might take hours to build.
The default installation path is 'toolchain-build/build/nios2'. Then setup the PATH for the tools, you can add a line at the end of
file ~/.bash_profile (or ~/.profile on Debian/Ubuntu) ( the file is
hidden, you have to use "ls -a" to find it . For "gedit" use open
Location, and enter the file name), like this
PATH=$PATH:/home/hippo/nios2-linux/toolchain-build/build/nios2/bin
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
Try to compile a simple hello.c like this,
#include <stdio.h>
int main(void)
{
printf("hello world\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n");
}nios2-linux-uclibc-gcc hello.c -o hello -elf2flt
The compiled object format is FLAT.
You may check it with,
nios2-linux-uclibc-flthdr hello
Optionally, add links for ccache, as root or via sudo
ln -s /usr/bin/ccache /usr/lib/ccache/nios2-linux-uclibc-gcc
ln -s /usr/bin/ccache /usr/lib/ccache/nios2-linux-uclibc-g++
ln -s /usr/bin/ccache /usr/lib/ccache/nios2-linux-uclibc-c++
When you compile something, the cache will be used and the compilation run faster. You can check cache status with,
ccache -s
Now you can follow UClinuxDist to build the kernel. You should build in the new source tree, nios2-linux/uClinux-dist .
cd uClinux-dist
make menuconfig
make vendor_hwselect SYSPTF=<path to your system ptf>
make
Important changes in this release, nios2-linux-20080619,
1. the arch name is now "nios2", (but not nios2nommu). Use current development branch test-nios2 by default.
2. the kernel source linux-2.6.x and uClibc are removed from uClinux-dist. the kernel source is now external linux-2.6 (from linux-2.6.git) at the same directory level as uClinux-dist.
3. the previous nios2_system.h is relocated to include/asm-nios2/nios2.h, and now the port/memory address is physical address , without cache-bypass, ie no address bit 31 set.
4. mtd partition maps file altera.c , microtronix.c and EPCS drivers are removed. Now they are in the platform device data of arch/nios2/kernel/config.c, using generic physical maps , m25p80 and altera spi driver.
5. many arch/drivers reworked/added, such as timer, interrupt handler, cache, ioremap, uart/jtaguart, framebuffer, spi, TSE.
6. adopt the Makefile from blackfin uclinux-dist, with many userspace libs/apps merged from blackfin. eg, ncurses, openssl, directfb, freetype..etc.
7. introduce the staging dir, with all libs and headers installed there. the previous include dir was removed.
The latest branch is "test-nios2". Despite the "test" in the name, this
does not mean "unstable". All future works and support will base on
this branch. I won't update those older branches with the limited time
available. Please migrate to the new branch.
The uClinux-dist
dose not contain the kernel now. It should stick with "test-nios2"
branch. It will merge updates from uclinux.org and blackfin uclinux.
The
development of nios2 kernel will stick with mainly the "test-nios2"
branch, with proper tags follow Linus' releases. eg "v2.6.26-nios2" tag
when Linus release "v2.6.26" stable. Then it will move on to
v2.6.27-rc1, but not with a new branch. It is still "test-nios2" branch.
Though
there will be some experimental branches from time to time, but they
will be merged into the main branch "test-nios2" at proper time. And
then deleted.
If you need a "stable" branch, you can create
local branch off the stable tags. You might apply patches from stable-queue git. Or you want to freeze. It is all up to you.
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git # patches for stable releases
After you have first successful boot, you can get updates from server.
Change to the nios2-linux dir,
Please disable optimize for size, or start with default config again.
General setup -->
[ ] Optimize for size <== unselect
++++++++++++++++++++++++++++++
If you got such error in updating,
~/nios2-linux/uClinux-dist$ git pull
.
vendors/Altera/nios2/config.vendor: needs update
fatal: Entry 'vendors/Altera/nios2/config.vendor' not uptodate. Cannot merge.
Please do a "git checkout -f" . Then "git pull" again.
If you already have the toolchain and working uClinux-dist git repo, you don't have to download the new tar ball nios2-linux-20080619.tar .
As the kernel source is removed from the uClinux-dist dir, you need a kernel source dir. At the same dir level of uClinux-dist, don't cd uClinux-dist. Clone the kernel source from the Linus' git.
git clone -n
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
Or if you are behind a proxy firewall,
git clone -n http://www.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
ls # see what's in
linux-2.6 uClinux-dist
cd linux-2.6
Edit the file .git/config, change the origin url to sopc server,
[remote "origin"]
url = git://sopc.et.ntust.edu.tw/git/linux-2.6.git
fetch = +refs/heads/*:refs/remotes/origin/*
Or if you are behind a proxy firewall,
[remote "origin"]
url = http://sopc.et.ntust.edu.tw/git/linux-2.6.git
fetch = +refs/heads/*:refs/remotes/origin/*
Next, create the new branch "test-nios2" and checkout,
git fetch origin
git branch --track test-nios2 origin/test-nios2
git checkout test-nios2
cd ..
Then, checkout the "test-nios2" branch of uClinux-dist,
cd uClinux-dist
git clean -f -x -d
git fetch origin
git branch --track test-nios2 origin/test-nios2
git checkout -f test-nios2 # forced
Now, you may build as before in this uClinux-dist dir,
make menuconfig
make vendor_hwselect SYSPTF=<your_system.ptf>
make
If you have local commit in older branches, either v2.6.26-nios2 or pre v2.6.26-nios2, you will have to move the local kernel patches from uClinux-dist/linux-2.6.x/ to linux-2.6/ .
First, find your local commit sha1 id in the old branch of uClinux-dist, using
git log <old branch> <dir of interest>
or
gitk <old branch> <dir of interest>
eg,
cd uClinux-dist
gitk v2.6.24-uc-myabc linux-2.6.x/
Take down the sha1 ID of the commit, 7-8 digits is enough. say, abc6789.
Use git-format-patch to generate patches for cherry-pick,
git format-patch abc6789^..abc6789
Or you can use a range, and pick only you need.
git format-patch <from>..<to>
Some 0001-......patch will be generated.
Filter the patches to change the path and arch reference,
sed -i -e szlinux-2.6.x/zzg 0*patch
sed -i -e sznios2nommuznios2zg 0*patch
Then create your local branch from test-nios2 branch of linux-2.6/
Now you can apply these patches
cd ../linux-2.6
# create and checkout local branch from test-nios2
# track the remote, depend on how you set remote,
# in the new tar ball, the origin is sopc.et.ntust.edu.tw
git branch --track test-nios2-myabc origin/test-nios2
git checkout test-nios2-myabc
git am <path_to_the_patches>
****************************************************
For other dir in uClinux-dist, eg, vendors/Altera, generate patches from
your local commit.
cd uClinux-dist
gitk v2.6.24-uc-myabc vendors/Altera
gitk format-patch <from>..<to>
Filter the patches to change the arch reference,
sed -i -e sznios2nommuznios2zg 0*patch
Now create your local branch from test-nios2 of uClinux-dist, and apply
the patches,
git branch --track test-nios2-myabc origin/test-nios2
git checkout test-nios2-myabc
git am <path_to_the_patches>