<<HOME>>

 

INTRO.. 2

Making the Microblaze system.. 3

Setting up the Linux computer: 13

Getting the uCLinux source. 13

Setting up the compiler 15

Compiling the kernel 15

Downloading the kernel to the FPGA.. 16


INTRO

SEE: http://www.belanger.pwp.blueyonder.co.uk/Projects/Spartan3/Spartan3.htm for Hardware.

 

Note: there are probably errors, inefficient things which I have done, please let me know of any!

 

I had successfully made a small PCB with a Spartan 3 FPGA, 32MB SRAM and a few peripherals. This is a description of how I got uCLinux to run on the board; it does not presume much prior knowledge of Linux (like me!).It mostly includes stuff which would have speeded up my development if I knew it before. I using the Windows versions of the dev software, you will need a Linux machine to compile the kernel.

 

It will hopefully be useful to anyone else who has similar hardware to me and wishes to get uCLinux running, this document presumes the following hardware:

 

Spartan 3 FPGA,

JTAG connection (Parallel 3 cable, although others shouldn’t make a difference??),

SDRAM (256Mb,16bits x 16 Mb) (Not DDR),

A push button (normally 1,0 when pressed, used for CPU reset),

NO flash.

 

 

What you will need: (what I’m using anyway)

 

  • HARDWARE:
    • Windows PC with XPS installed
    • Xilinx FPGA with download cable and serial(RS232) connection to computer.
    • A (not too old!) computer running Linux and networked to the Windows PC(I’m using Fedora 3 running GNOME)
  • SOFTWARE:
    • Xilinx Platform Studio. (I’m using: EDK 7.1 Build EDK_H.10.4+0)
    • Microblaze GCC complier: microblaze-elf-tools-20050308 (link) (Note, NOT the new 3.4 version)
    • Terminal program on Windows PC (I’m using HyperTerminal)
    • WinSCP, used for transferring files to and from Linux machine
  • FILES 
  • LINKS

 


Making the Microblaze system

Before you begin, download the uClinux BSP package from http://www.itee.uq.edu.au/~jwilliams/mblaze-uclinux/Downloads/platforms.html and extract to the correct directory.

 

To make the Microblaze system I used the excellent tutorial by Jason Wu &

Dr. John Williams, however there are some changes from the document which I found I had to make. You need the PDF from here.

 

I will show screen shots of my BSB setup, then you need for continue from page 16 of the tutorial.

(yes 2 timers…)

Leave mem test on, a useful test and will be edited later.

 

 

Now continue with the tutorial from page 16, with the following changes:

 

PAGE 16: Do NOT change C_USE_UART_WIDTH to 0, leave as 8, as in the picture.

Reason: Didn’t compile when set to 0

 

PAGE 18: Ignore page, do NOT add debug interrupt, nor add to interrupt controller.

Reason: seemed to mess up timer interrupt, you get stuck at ‘Calibrating delay loop...’ when booting kernel. XMD debug still works

 

 

PAGE 21: Change uClinux version to 1.00a

Reason: Version 1.00c seems to REQUIRE flash to be present, and it won’t compile if there is none.

 

PAGE 22/23:  Change main_memory to Generic_SDRAM

 

DO NOT Change main_memory_bank and flash_memory_bank to 0, leave as -1.

Reason: when using SDRAM, anything other than -1 means BSB files don’t compile

 

ALSO:

  • Change Microblaze version from 4.00a DOWN to 3.00a.

Reason: Kept getting ‘Kernel panic: VFS: Unable to mount root fs on 00:00’ errors when attempting to boot, this seemed to fix it

  • Add and change C_USE_DIV = 1 and C_USE_BARREL =1 in the Microblaze parameters

 

NEXT: You now have to set the pin constraints; this lets the project know where the physical pins on the package go.

In XPS, in the project tree, under ‘Project files’ open ‘UCF File: data/system.ucf’. All the pins will be commented out, so if you build now they will be assigned to random places.

Here is an extract from my file:

## FPGA pin constraints

Net fpga_0_RS232_req_to_send_pin LOC="P4" | IOSTANDARD = LVCMOS33;

Net fpga_0_RS232_RX_pin LOC="P1" | IOSTANDARD = LVCMOS33;

Net fpga_0_RS232_TX_pin LOC="P2" | IOSTANDARD = LVCMOS33;

Net fpga_0_Generic_SDRAM_SDRAM_DQ_pin<15> LOC="P113" | IOSTANDARD = LVCMOS33;

Net fpga_0_Generic_SDRAM_SDRAM_DQ_pin<14> LOC="P112" | IOSTANDARD = LVCMOS33;

Net fpga_0_Generic_SDRAM_SDRAM_DQ_pin<13> LOC="P108" | IOSTANDARD = LVCMOS33;

Net fpga_0_Generic_SDRAM_SDRAM_DQ_pin<12> LOC="P107" | IOSTANDARD = LVCMOS33;

Net fpga_0_Generic_SDRAM_SDRAM_DQ_pin<11> LOC="P105" | IOSTANDARD = LVCMOS33;

Net fpga_0_Generic_SDRAM_SDRAM_DQ_pin<10> LOC="P104" | IOSTANDARD = LVCMOS33;

 

The ‘LOC=xx’ is the pin number on the package. The ‘| IOSTANDARD = LVCMOS33’ sets the IO standard.

 

IMPORTANT: Note all the pin numbers on SDRAM are the reverse endian to the processors, this means data(15) =>data (0), data(14) => data (1), data(13) =>data(2) ect. See the Xilinx generic SDRAM datasheet.

This applies to the databus, address bus, bank bus, and  DQM bus.

(it will not pass the memory tests if these are wrong)

 

Build the BSB files and the ‘Update the Bitstream’

Open HyperTerminal (or what ever you using) and choose Tools->Download (this will update anything which is out of date)

If you lucky you will see ‘Starting memory test…’ and the tests will pass.

 

Setting up the Linux computer:

The Computer running Linux should be networked to the Windows PC as files are needed to be transferred between them.

All work is done running as root, I not sure if this is necessary.

 

These are my directories which will be used in the following text:

Home =                        /root

uClinux stuff=               /root/uClinux

uCLinux dist = /root/uClinux/uClinux-dist

MB complier=              /root/uClinux/Toolchain/mb-gcc

 

The following will tell you where to put certain files, it is obviously up to you actually where to put the files, but it make it easier to write this if I tell you where to put stuff!

 

Getting the uCLinux source

In order to get most current source code, It is necessary to download all the code via CVS. This pages describes how to get the code http://www.ucdot.org/article.pl?sid=02/09/20/1342224&mode=thread.

 

You only need to download version 2.4 of the kernel.

Download into /root/uClinux to make /root/uClinux/uClinux-dist

 

As stuff on the internet has a habit of disappearing, here is a copy of the text:

 

 

The uClinux-dist can now be obtained from CVS. The CVS version will match the tarball versions, however the kernels have been removed as they are already available under CVS. For instructions on how to setup a tree based on this read on.

 

 

 

The easiest way to obtain the uClinux-dist through CVS is to use the uClinux.org's anonymous CVS access. This will provide read only access to the CVS repository and access to any updates that are added to the repository.

Before using anonymous CVS to get the tree you must do a "cvs login". Run the following command and when it asks for a password just press <Enter>.

   cvs -d:pserver:anonymous@cvs.uclinux.org:/var/cvs login

This sets up the appropriate authorisations to run the following CVS commands. Now we can get a copy of non-kernel portions of the uClinux-dist by running a CVS checkout. Note that the uClinux-dist is a large source tree and such a check out will take quite some time even using a relatively fast link. A checked out tree may run up to about 270Mb. The following CVS commands use compression, but the download size will still be quite large.

   cvs -z3 -d:pserver:anonymous@cvs.uclinux.org:/var/cvs checkout -P uClinux-dist

This will create a new directory called "uClinux-dist" in the current directory. This directory is the top level directory of the uClinux-dist and contains all the target, application and library source code. Before you can go any further you will also need to checkout a kernel. If you already have a kernel from CVS then instructions are included below for that as well. Firstly:

   cd uClinux-dist

If you do not have a current CVS kernel to use then checkout either or both of the 2.0 or 2.4 kernels with the following commands:

   cvs -z3 -d:pserver:anonymous@cvs.uclinux.org:/var/cvs checkout -d linux-2.0.x -P uClinux-2.0.x
 
 
   cvs -z3 -d:pserver:anonymous@cvs.uclinux.org:/var/cvs checkout -d linux-2.4.x -P uClinux-2.4.x

This checks out a copy of the uClinux kernels and names the directories either linux-2.0.x or linux-2.4.x as the uClinux-dist expects. If you already have a uClinux kernel from CVS then you can rename the directory or link it to the current directory. For example, if you had a copy in ~/uClinux-2.4.x, run the following command to sym-link the directory into the tree.

   ln -s ~/uClinux-2.4.x linux-2.4.x

For instructions on compiling and using the uClinux-dist consult the README file in the toplevel uClinux-dist directory and the other documentation in the Documentation directory.

Now that you have a copy of the sources from CVS there are a couple of things that you may wish to do. Firstly, when an announcement of an update is posted on uCdot or the uClinux-dev mailing list you will want to update your files. You can do this by running the following command from the uClinux-dist directory:

   cvs -z3 update -Pd

-------unneeded stuff deleted-------

Cheers,
Davidm

 
                       

 

 

You now need to apply any patches required. Go to http://www.itee.uq.edu.au/~jwilliams/mblaze-uclinux/Downloads/patches.html and apply all required patches.

 

Setting up the compiler

Now you have uClinux source code, you need the Microblaze compiler, I couldn’t get it to compile with the new 3.4 version of the compiler (although I didn’t try very hard) so you need the old version.

 Download microblaze-elf-tools-20050308.tar.gz to /root/uClinux/mb-gcc

 

Open a terminal to /root/uClinux/mb-gcc and extract the complier:

tar xzfv microblaze-elf-tools-20050308.tar.gz

This will extract the compiler to /root/uClinux/mb-gcc

 

In order to compile for Microblaze, the computer must know where the mb-gcc executable is, enter the command:

export PATH=/root/uClinux/mb-gcc/bin/:${PATH}

 

The appends the mb-gcc path to the list of paths the computer searches when a command is entered.

 

To see if it has worked type:

mb-gcc

 

You should see ‘mb-gcc: No input files’

 

NOTE!: The export command only applies to the terminal you typed it in, and is lost when you close the terminal, SO, you must type export command above every time you want to compile from that terminal.

 

Compiling the kernel

You should have a working XPS project and downloaded uClinux-dist, and have a working Microblaze complier on your Linux comp.

 

Your XPS will have created a file called ‘auto-config.in’(the location of this file will have been set in ‘Library/OS Parameters’ under ‘Software Platform Settings’) , the kernel compiling scripts use this file. You need to locate this file and copy to /root/uClinux/uClinux-dist/linux-2.4.x/arch/Microblaze/platform/uclinux-auto

 

TIP: The uClinux_auto project  located here includes a working auto_config.in file, if your auto-config.in files does not work, it is helpful to open the one from uClinux_auto and compare it to your one, change your project so they give the same parameters (obviously ignoring different peripherals)

 

Now continue with the tutorial uClinux_ready_Microblaze_design.pdf from page 24. However, when configuring the kernel, disable anything to do with flash memory

 

After running ‘make all’ (this will take some time), it should finish with no errors (read the last few lines to make sure!). It will have made 6 files in /root/uClinux/uClinux-dist/images, you need ‘image.bin’.

 

Downloading the kernel to the FPGA

 

I have the Spartan board connected to my windows PC, any files to uploaded to the device are copied for ‘c:\’ to speed up typing.

 

NOTE: In order for the cache to work, it seems that you need to initialise it in software.

 

  1. Go back to XPS and open the source for TestApp_Memory (TestApp_Memory.c) now edit it to the following: (make a backup if you want)

 

 

#include "xparameters.h"

 

#include "xutil.h"

 

//====================================================

typedef void (*void_fn)(void);

void_fn kernel_start;

int main (void) {

 

   microblaze_init_icache_range(0, 8192);

   microblaze_enable_icache();

 

   microblaze_init_dcache_range(0, 8192);

   microblaze_enable_dcache();

 

   kernel_start = (void_fn)0x22000000;

 

gonna_jump:

            kernel_start();

 

 

   return 0;

}

 

Change the ‘0x22000000’ to the start of the SDRAM if different

 

 

Now goto Tools->Build all User Application. There should be no errors. This will build a file called executable.elf  under the ‘TestApp_Memory’ directory of your project folder.

Copy this file to c:\ and rename to c:\boot.elf

Now edit the source again by putting in an infinite while loop just after main, so the processors stop in the loop:

#include "xparameters.h"

 

#include "xutil.h"

 

//====================================================

typedef void (*void_fn)(void);

void_fn kernel_start;

int main (void) {

 

  while (1)

{

 

}

   microblaze_init_icache_range(0, 8192);

   microblaze_enable_icache();

 

   microblaze_init_dcache_range(0, 8192);

   microblaze_enable_dcache();

 

   kernel_start = (void_fn)0x22000000;

 

gonna_jump:

            kernel_start();

 

 

   return 0;

}

 

Now goto Tools->download. This will program the FPGA and update anything.

 

The processors will now just be looping, and doing nothing.

 

Goto Tools->XDM, this will open the debug command window, it should connect to  the board though the JTAG.

 

If connected, type:

 

dow c:\boot.elf

 

It will upload file

 

Next upload the kernel:

 

dow –data c:\image.bin 0x220000000

 

note: 0x22000000 is the start of SDRAM

 

(it will appear to hang, its actually uploading the file)

 

Now, if all’s gone well, open the terminal program, and press the reset button on your FPGA!

 

If you’re very, very lucky you will see:

 

CPU: MICROBLAZE               

Kernel command line: °                     

Console: xmbserial on UARTLite                             

Calibrating delay loop... 19.66 BogoMIPS                                       

Memory: 32MB = 32MB total                        

Memory: 30916KB available (562K code, 927K data, 32K init)                                                         

Dentry cache hash table entries: 4096 (order: 3, 32768 bytes)                                                            

Inode cache hash table entries: 2048 (order: 2, 16384 bytes)                                                           

Mount cache hash table entries: 512 (order: 0, 4096 bytes)                                                         

Buffer cache hash table entries: 1024 (order: 0, 4096 bytes)                                                           

Page-cache hash table entries: 8192 (order: 3, 32768 bytes)                    

POSIX conformance testing by UNIFIX

Linux NET4.0 for Linux 2.4

Based upon Swansea University Computer Society NET3.039

Microblaze UARTlite serial driver version 1.00

ttyS0 at 0x40600000 (irq = 1) is a Microblaze UARTlite

Starting kswapd

RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize

uclinux[mtd]: RAM probe address=0x220bd93c size=0xb7000

uclinux[mtd]: root filesystem index=0

VFS: Mounted root (romfs filesystem) readonly.

Freeing init memory: 32K

Mounting proc:

Mounting var:

Populating /var:

Running local start scripts.

Remounting / (rw):

Mounting /etc/config:

Populating /etc/config:

flatfsd: Nonexistent or bad flatfs (-43), creating new one...

flatfsd: Failed to write flatfs (-43): No such device

flatfsd: Created 3 configuration files (414 bytes)

Setting hostname:

 

uclinux-auto login:

 

 

Good luck J

Emile