Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
20 years ago

Mini howto build toolschain and initramfs on Linux

UPDATE : This post is out of date. Please follow the new one,

http://forum.niosforum.com/forum/ind...showtopic=3174

This is a mini howto about building toolchains ,uClinux and initramfs for NIOS2 on Linux platform.

It is for those unable to access marc's site, or want to do it from scratch.

Please help to improve it. And give feed back to me. I will move this to a project when ready.

Why build the tools when you have the IDE on Windows?

The IDE on Windows are just not good for kernel development.

The tools run much faster and less trouble on Linux.

Why use Initramfs? It is common in major Linux distributions with 2.6 kernel.

It replaces romfs. It is compressed. The rootfs (initrd) image can be linked into the kernel, and make the booting easier.

You don't need other devices, such as MTD,CF/IDE,NFS to bring up your root fs.

As they are not yet available for a new custom board.

You can mount other devices or filesystem later, in user space.

Jdhar and I had worked on another thread,

"uClinux without Flash (again)"

There were what we had tried with IDE on Windows, but failed.

It was successed then, based on marc's site to build the tools on Linux.

You may follow it to learn more about Initramfs and the booting process.

If you are new to uClinux, it is very helpful to read the FAQ on the www.ucdot.org.

You should start with a mininal system with only nios2 cpu core,dram,timer,jtag/serial console and a cfi flash, (which can be dummy and removed later).

Here we go!

First get the sources file from your Windows platform.

You should enable "gnutools source" package selection when installing nios2 distribution CD (not available in eval CD).

The compiler sources are located in the dir altera/kits/nios2/bin/nios-gnutools/src.

Downloaded and install the uClinux 2.6 release 1.4 of microtronic from this forum.

Find the sources in altera/kits/nios2/examples/software/linux and the kernel linux-2.6.x .

Sample config files and Rules.mak for apps are included at the end of this post.

We will do all the works with command line on Linux. No IDE except when you want to download.

Convert the CRLF in the source trees with zip -r and unzip -a.

Place converted source trees in /usr/local/src/nios2/ , including binutils,gcc,elf2flt,linux-2.6.x,uClibc,apps and busybox.

Make build dirs in /usr/local/src/nios2/build/ binutils,gcc,elf2flt, kernel,rootfs.

The exec,lib files will be in /usr/local/bin /usr/local/nios2-elf.

### create the root file system

mkdir /usr/local/src/nios2/build/rootfs

cd /usr/local/src/nios2/build/rootfs

mkdir bin sbin usr usr/bin usr/sbin etc var var/log dev proc sys tmp mnt

# create a simple etc/inittab

echo "::askfirst:/bin/sh" >etc/inittab

# prepare for user space init

ln -s /sbin/init init

# make some basic devices

# Look at linux-2.6.x/Documents/devices.txt for the list of devices numbers.

cd dev

mknod console c 5 1

mknod null c 1 3

mknod zero c 1 5

mknod hda b 3 0

mknod hda1 b 3 1

### prepare the compiler

cd /usr/local/src/nios2/build/binutils

../../binutils/configure --target=nios2-elf

make

make install

cd /usr/local/src/nios2/build/gcc

../../gcc/configure --target=nios2-elf --enable-languages=c

make

make install

cd /usr/local/src/nios2/build/elf2flt

../../elf2flt/configure --target=nios2-elf --with-bfd-include-dir=../binutils/bfd --with-libbfd=../binutils/bfd/libbfd.a --with-libiberty=../binutils/libiberty/libiberty.a

make

make install

### compile the kernel

cd /usr/local/src/nios2/linux-2.6.x

# remove the lines contain "dos2unix" in Makefile, scripts/Makefile.build, scripts/Makefile.lib.

make ARCH=nios2nommu O=/usr/local/src/nios2/build/kernel CROSS_COMPILE=nios2-elf- hwselect SYSPTF=/usr/local/src/nios2/build/yoursystem.ptf

make ARCH=nios2nommu O=/usr/local/src/nios2/build/kernel CROSS_COMPILE=nios2-elf- menuconfig

#### .config must have

# Miscellaneous Options

CONFIG_CMDLINE=""

# Block devices

CONFIG_INITRAMFS_SOURCE="/usr/local/src/nios2/build/rootfs"

# Kernel hacking

# CONFIG_FULLDEBUG is not set

make ARCH=nios2nommu O=/usr/local/src/nios2/build/kernel CROSS_COMPILE=nios2-elf-

### compile the uClibc

ln -s /usr/bin/install /bin/install

cd /usr/local/src/nios2/uClibc

make CROSS=nios2-elf- menuconfig

#### .config must have

# Target Architecture Features and Options

KERNEL_SOURCE="/usr/local/src/nios2/linux-2.6.x"

KERNEL_AUTOCONF="/usr/local/src/nios2/build/kernel"

# Library Installation Options

RUNTIME_PREFIX="/usr/local/nios2-elf/"

DEVEL_PREFIX="/usr/local/nios2-elf/"

make CROSS=nios2-elf-

make CROSS=nios2-elf- install

### compile the buysbox

ln -s /usr/local/nios2-elf/lib /usr/local/nios2-elf/scripts

cd /usr/local/src/nios2/busybox

make UCLIBC_PLUGIN=/usr/local/nios2-elf APP_PLUGIN=/usr/local/nios2-elf menuconfig

#### .config must have

# Build Options

CONFIG_STATIC=y

USING_CROSS_COMPILER=y

CROSS_COMPILER_PREFIX="nios2-elf-"

KERNEL_BUILD_DIRECTORY="/usr/local/src/nios2/build/kernel"

# Installation Options

PREFIX="/usr/local/src/nios2/build/rootfs"

make UCLIBC_PLUGIN=/usr/local/nios2-elf APP_PLUGIN=/usr/local/nios2-elf

make UCLIBC_PLUGIN=/usr/local/nios2-elf APP_PLUGIN=/usr/local/nios2-elf install

### update the rootfs with busybox added

### you should rebuild the kernel whenever the rootfs is updated

cd /usr/local/src/nios2/linux-2.6.x

make ARCH=nios2nommu O=/usr/local/src/nios2/build/kernel CROSS_COMPILE=nios2-elf-

cd /usr/local/src/nios2/build/kernel

nios2-elf-objcopy -O binary vmlinux vmlinux.bin

Then you can download and get the busybox shell prompt.

Enjoy!!

The minimal kernel config to be placed in /usr/local/src/nios2/build/kernel/.config

Code:

<1>

The sample config for uClibc ot be placed in /usr/local/src/nios2/uClibc/.config

Code:

<2>

The sample config file for busybox to be placed in /usr/local/src/nios2/busybox/.config

Code:

<3>

The file to help make apps in /usr/local/src/nios2/apps/Rules.mak

eg,

cd /usr/local/src/nios2/apps/samples

ln -s ../Rules.mak .

make KERNELBUILDDIR=/usr/local/src/nios2/build/kernel install

Then the apps will be installed into /usr/local/src/nios2/build/rootfs/bin.

Code:

<4>

16 Replies