Sunday, June 8, 2014

1. OpenRISC Processor:

OpenRISC processor is a project maintained by developers at OpenCores.org. OpenRISC is a general purpose RISC architecture CPU. The Verilog RTL description of the processor is released under GNU General Purpose License. A reference SoC implementation based on OpenRISC 1200 has been developed, which is known as ORPSoC (OpenRISC Reference Platform System-on-Chip).

Refer the wiki link for further details.

2. Introduction:

This document will explain how to set up a development environment in Ubuntu Linux for ORPSoC on the Atlys Spartan 6 development board. The document contains basic configuration of hardware and software to work correctly with the ORPSoC build system and to get a custom Linux kernel to run on the OpenRISC processor.

3. Hardware:

  • Ubuntu 11.10 or later installed computer (I have Ubuntu 12.04 installed). Preferably dual boot, as I was facing some driver issues while connecting the Atlys FPGA board to Ubuntu install in virtual box. But it should be fine if you don't want to use Xilinx Impact to program the development board. You can use the Digilent Adept Software, installed in Windows XP or higher to program the development board.
    • Make sure you have about 25GB of free space to install all the tools.
  • Atlys FPGA development board
  • A computer with Windows XP or later installed.
4. Installation:

4.1 Xilinx ISE:

Download the Xilinx ISE 13.x or 14.x version from the Xilinx ISE download page in your Ubuntu computer. Once the Xilinx ISE is downloaded, extract it in a temporary folder.
Change permissions on the temporary folder using the following command:

sudo chmod -R 755 <temporary folder>

Now, run the setup file,

cd <temporary folder>
sudo ./xsetup

The installation window will open. Select the ISE webpack installation.
Make sure to install Xilinx in the /opt/Xilinx directory.

4.2 ORPSoC:

Make sure subversion and git is installed in your computer.

sudo apt-get install subversion git

To get orpsocv2, checkout the OpenRISC project subversion repository, in your home folder.

svn co http://opencores.org/ocsvn/openrisc/openrisc/trunk/orpsocv2 

4.3 or1ksim simulator:

Make sure you are in the root mode. Enter the /opt directory.

Checkout the subversion repository to get the latest version of or1ksim

svn co http://opencores.org/ocsvn/openrisc/openrisc/trunk/or1ksim
 

Create a build folder in /opt directory and cd in it.

mkdir builddir or1ksim
cd builddir or1ksim
 

Build the or1ksim:

../or1ksim/configure –target=or32-elf –prefix=/opt/or1ksim
make all
make install


4.4 OpenRISC Toolchain Installation:

Go to your home directory.

Checkout the gnu stable subversion:

svn co http://opencores.org/ocsvn/openrisc/openrisc/trunk/gnu-stable

Enter inside the gnu-stable directory and clone the uClibc and Linux.

cd gnu-src
git clone git://git.openrisc.net/jonas/uClibc
git clone git://git.openrisc.net/stefan/linux




Also get a bunch of other tools required to build the toolchain:

sudo apt-get -y install build-essential make gcc g++ flex bison patch
texinfo libncurses-dev libmpfr-dev libgmp3-dev libmpc-dev libzip-
dev iverilog


Inside the gnu-stable folder, run the following command. It will take some time to build the toolchain.

./bld-all.sh –force –prefix /opt/openrisc –or1ksim-dir /opt/or1ksim
–uclibc-dir uClibc –linux-dir linux


Once build is completed, if you are not already in root mode, enter inside root mode. Open the .bashrc file and add the following statements at the end of it.

Inside root mode:

cd ~
gedit .bashrc
export PATH=$PATH:/opt/openrisc/bin
export PATH=$PATH:/opt/or1ksim/bin
export CROSS_COMPILE=or32-elf-


Close the terminal window. Open a new terminal and type "or" and press tab twice to see a list of or32-elf and or32-linux tools.

4.5 SPI flash using Xilinx Impact (Slow and not recommended. Refer section 4.8 to program the SPI flash using the Digilent Adept software):

Connect the Atlys Spartan 6 board using the USB cord to the Ubuntu Computer with the other end connected to the prog socket on the board.

Open Xilinx Impact tool (Root mode):

>cd /opt/Xilinx/14.x/ISE_DS
>source settings32.sh
>impact

Impact tool should recognize the board. (There might be problems with the cable drivers if using Virtual Box or VMware).

Following steps might help solve the problem with cable drivers:

  • Download Digilent Adept Runtime and Utilities for Linux
  •  Copy the udev-rules from the xilinx folder to your udev folder. 
    •  sudo cp /opt/Xilinix/14.x/ISE_DS/common/bin/lin/digilent/digilent.adept.runtime_2.7.4−x86_64/52−digilent−usb.rules /etc/udev/rules.d/
    • sudo cp /opt/Xilinx/14.x/ISE_DS/common/bin/lin/xusbdfwu.rules /etc/udev/rules.d/
    • sudo /etc/init.d/udev restart
Toolchain Installed!

4.6 Building the Linux Kernel:

  • Running in or1ksim simulator:
Enter inside the gnu-stable directory and go inside the cloned linux directory and build the linux kernel for or1ksim:

Make sure you are in root mode.
cd gnu-stable/linux/
make defconfig
make ARCH=openrisc

Testing in or1ksim simulator:

Enter inside /opt/or1ksim directory and execute the following set of commands:

cd /opt/or1ksim
./configure
make install

Browse into the /home/<username>/gnu-stable/linux/arch/openrisc and open the or1ksim.cfg file.

gedit or1ksim.cfg

Make sure the UART section in the file is same as following, comment the other details:

section uart
  enabled = 1
  baseaddr = 0x90000000
  irq = 2
  channel = "xterm:"
  jitter = -1              
  16550 = 1
end


Go back to /opt/or1ksim directory and execute the following command to run linux inside simulator. A xterm terminal window will open:

./sim -f /home/<username>/gnu-stable/linux/arch/openrisc/or1ksim.cfg /home/<username>/gnu-stable/linux/vmlinux

  • Running on Atlys development board:
Make sure you are in root mode. Enter the linux directory and build the linux for atlys development board. But before that, we need to comment out a few things in the atlys.dts file located at /home/<username>/gnu-stable/linux/arch/openrisc/boot/dts directory

gedit atlys.dts

Your atlys.dts file should look like this:

/dts-v1/;
/ {
    compatible = "digilent,atlys";

    #address-cells = <1>;
    #size-cells = <1>;
    interrupt-parent = <&pic>;

    chosen {
        bootargs = "console=uart,mmio,0x90000000,115200";
    };

    memory@0 {
        device_type = "memory";
        reg = <0x00000000 0x08000000>;
    };

    cpus {
        #address-cells = <1>;
        #size-cells = <0>;
        cpu@0 {
            compatible = "opencores,or1200-rtlsvn481";
            reg = <0>;
            clock-frequency = <50000000>;
        };
    };

    /*
     * OR1K PIC is built into CPU and accessed via special purpose
     * registers.  It is not addressable and, hence, has no 'reg'
     * property.
     */
    pic: pic {
        compatible = "opencores,or1k-pic";
        #interrupt-cells = <1>;
        interrupt-controller;
    };

    serial0: serial@90000000 {
        compatible = "opencores,uart16550-rtlsvn105", "ns16550a";
        reg = <0x90000000 0x100>;
        interrupts = <2>;
        clock-frequency = <50000000>;
    };

    enet0: ethoc@92000000 {
        compatible = "opencores,ethmac-rtlsvn338";
        reg = <0x92000000 0x100>;
        interrupts = <4>;
    };
};

Comment out the other details.

Now we can build the kernel for the atlys development board.

cd /home/<username>/gnu-stable/linux
make clean
make atlys_defconfig
make ARCH=openrisc

Convert the vmlinux.bin generated to the correct format using the following utility:

cd /home/<username>/orpsocv2/sw/utils
make
./bin2binsizeword /home/<username>/gnu-stable/linux/vmlinux.bin /home/<username>/orpsocv2/boards/xlinix/atlys/backend/par/run/vmlinux.bin

This will put the converted bin image inside /home/<username>/orpsocv2/boards/xlinix/atlys/backend/par/run/ folder.

Make sure the correct settings for Xilinx are sourced:
cd /opt/Xilinx/14.x/ISE_DS/
source settings32.sh

Now execute the following commands:
cd home/<username>/orpsocv2/boards/xlinix/atlys/backend/par/run/
make clean
make orpsoc.mcs BOOTLOADER_BIN=vmlinux.bin

The Linux image is now programmed into the mcs file. By now this file is about 15MB in size. This file can be loaded to the FPGA through SPI-flash using Digilent Adept Software or Xilinx Impact Tool.

4.7 Loading the Linux Image on the Atlys Development Board:

Install the Digilent Adept Software in your Windows XP or later.

Launch the software and use the generated orpsoc.mcs to program the SPI flash. Make sure the development board is connected to the computer using USB and prog socket on the development board.

To test the Linux image:

Connect the development board to your Ubuntu computer after SPI flash in programmed. The other end of the development board should be connected to the UART port on the development board.
Open a terminal window and open gtkterm:

sudo apt-get install gtkterm
sudo gtkterm

Go to Configuration->Port
Following should be the settings:

Port: /dev/ACM0
Baud Rate: 115200
Parity: none
Bits: 8
Stopbits: 1
Flow control: none

Reset the development board and wait for the linux to boot up.

Linux is installed on the Atlys Spartan 6 development board! Happy kernel hacking!

References: