Linux on FPGA4U/Start from scratch

From Fpga4u

Jump to: navigation, search

Ok, now you want to build the system from scratch, so you can add more hardware/software components.

If you find the following page a bit short, more information can be found on NiosWiki

Quartus project

You need in your design at least:

  • 1 Nios II CPU (version s or preferably f, 50 MHz gives reasonable performance)
  • 1 SDRAM controller (see FPGA4U_Description - SDRAM_Clk for the configuration)
  • 1 JTAG UART slave
  • 1 full-featured timer (period: 1 ms, counter size: 32 bits, hardware options preset "Full-featured").

You can find a sample design here: nios2test-more.tar.bz2. To use it, open SOPC Builder, generate the system, then compile the system. Your sof file is ready.

Software

More information can be found on NiosWiki, and you definitely need to be on Linux to do that.

Build the toolchain

Here, we will build the toolchain (i.e. the compiler, assembler...).

In short (assuming you have all the necessary tools (git, gcc...)):

Download and extract ftp://ftp.altera.com/outgoing/nios2-linux-20080619.tar.

In nios2-linux, fetch the latest sources:

bash checkout
bash update

Then compile the toolchain:

cd toolchain-build
git clean -f -x -d
make gcc elf2flt
cd ..

Reclaim some hard disk space

If you want to save some hard disk space, you can safely remove the following directories in toolchain-build/build:

binutils-build  gcc-bootstrap-build  gcc-build

You can also remove all the files (except the .git directory, so using rm -rf * works fine) in the following directories:

binutils elf2flt gcc3 insight u-boot

If needed, you can always recover the files by typing, in every directory:

git checkout

Build the embedded system

Now we have the needed tools, we can build the new system.

First, setup the path correctly:

export PATH=$PATH:/path_to/nios2-linux/toolchain-build/build/nios2/bin
export PATH=$PATH:/opt/altera8.0/quartus/bin
export PATH=$PATH:/opt/altera8.0/nios2eds/bin:/opt/altera8.0/nios2eds/bin/nios2-gnutools/H-i686-pc-linux-gnu/bin/

(correct the paths where needed)

Apply the patches

First, download and extract my patches and default configurations, available here: fpga4u-linux.tar.bz2.

Apply the kernel patches (in nios2-linux/linux-2.6):

patch -p1 < /path/to/fpga4u-linux/linux-2.6/XX-name.patch

(repeat the last step for all the patches, starting from 01-name.patch)

And apply the uClinux distribution patches (in nios2-linux/uClinux-dist):

cd uClinux-dist
patch -p1 < /path/to/fpga4u-linux/uClinux-dist/XX-name.patch

(repeat the last step for all the patches, starting from 01-name.patch)

Configuration

You may want to start from my working configuration (in nios2-linux/uClinux-dist):

cp /path/to/fpga4u-linux/config-.config-nolcd config/.config
cp /path/to/fpga4u-linux/linux-2.6.x-.config-nolcd linux-2.6.x/.config

(use *-.config-lcd if you have a LCD controller in your design, but you will need to change the driver if you are not using my hardware component)

If you want to fine-tune the configuration:

make menuconfig

Then, inform the kernel about your system configuration (this allows the kernel to know about the addresses of your components):

make vendor_hwselect SYSPTF=/path_to_quartus_project/niostest.ptf

Compilation and download

Then compile the kernel and the system:

make

It should complete successfully. If it does, download your system on the FPGA4U:

nios2-configure-sof /path_to_quartus_project/nios2test.sof 
nios2-download -g images/zImage && nios2-terminal

Create the EPCS files

If you want to burn the system to the EPCS to get your Linux to boot when the FPGA4U is powered up. (See EPCSGuide and FlashProgrammer):

To get that to work, you need, in SOPC builder, to set the reset vector of the the CPU on the EPCS (put 0x0 as offset). This will actually generate a small block of On-Chip RAM (1 M4K I think), which contains a simple bootloader, whose role is to copy the ELF binary from the EPCS to the SDRAM and boot the system from there.

Generate the flash files:

sof2flash --epcs --input=/path_to_quartus_project/nios2test.sof --output=config.flash --verbose --offset=0x0
elf2flash --epcs --after=config.flash --input=/path_to_nios2-linux/uClinux-dist/images/zImage
          --output=epcs_controller.flash --boot=$SOPC_KIT_NIOS2/components/altera_nios2

And burn them:

nios2-configure-sof /path_to_quartus_project/nios2test.sof 
nios2-flash-programmer --epcs --base=0x04021800 config.flash
nios2-flash-programmer --epcs --base=0x04021800 epcs_controller.flash

(change the EPCS controller base address if you're using your own design)

We're using around 1.5 MB out of 2 MB on the EPCS.

--Nicolas Boichat 19:41, 11 November 2008 (CET)

Personal tools