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

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    frist, make sure you have the compiler build,

    $ nios2-elf-gcc -v
    Reading specs from /usr/local/lib/gcc/nios2-elf/3.4.1/specs
    Configured with: ../../gcc/configure --target=nios2-elf --enable-languages=c
    Thread model: single
    gcc version 3.4.1 (Altera Nios II 5.1 b73)

    then, the hardware include header generation.

    note, this is a signle line command.

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

    next the config,

    note, this is a signle line command.

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

    next, the compile,

    note, this is a signle line command.

    make ARCH=nios2nommu O=/usr/local/src/nios2/build/kernel CROSS_COMPILE=nios2-elf-
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Another helpful info from uclibc mailing list,

    <div class='quotetop'>QUOTE </div>

    --- Quote Start ---

    basic Buildroot from scratch tutorial found

    David Smoot davidsmoot at gmail.com

    Thu Dec 1 09:11:32 PST 2005

    * Previous message: [gmail] NFS and Buildroot ...again.

    * Next message: basic Buildroot from scratch tutorial found

    * Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

    For the 90% of listers that are relatively fluent in busybox /uclibc, ignore

    this email, this is for the small percentage like me who joined this list

    because they lack understanding of busybox.

    I&#39;m still a relative newbie on busybox but have been working in my spare

    time to pull myself up the learning curve. I stumbled across some pretty

    good reference material by accident this morning that has greatly helped me

    understand busybox and uclibc. Thought I would share:

    http://free-electrons.com/articles/elfs/en (http://free-electrons.com/articles/elfs/en) A tutorial on a quick embedded

    system buildup using buildroot.

    http://free-electrons.com/articles/optimizations/en (http://free-electrons.com/articles/optimizations/en) A longer more general

    embedded linux presentation.

    Anyway, it helped me so maybe someone else on the list can benefit.

    David Smoot[/b]

    --- Quote End ---

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I have met the same problem like mountain8848.so unlucky!

    slackware 9.0,gcc 3.2.2

    --- Quote Start ---

    I got some errors when build the cross tool chain

    2.

    ==================================================

    windows_src:

    binutils->error

    gcc->ok

    elf2flt->ok

    here is the gcc error

    ...
    checking whether ANSI C string concatenation works ... yes
    *** ld does not support target nios2-elf
    *** see ld/configure.tgt for supported targets
    make: ***  Error 1
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I have setup a "fresh and clean" slackware 9.0 with only A+D+glibc.

    It builds and there is no such problem.

    Try "unset CC".