Install TRAP (TRansaction level Automatic Processor generator)

安裝完 SystemC-2.2.0 and TLM 後,
在來安裝 TRAP 來玩玩看,這裡有詳細的安裝步驟說明。

一些準備工作
請先確認系統是否已安裝以下的 Library or Tools
libELF, SystemC, TLM, Boots, Python, networkx

Checkout TRAP Source Code

% svn checkout http://trap-gen.googlecode.com/svn/trunk/ trap-gen

Compile and Install TRAP

% cd trap-gen
% ./waf configure --with-systemc=/opt/systemc/systemc-2.2.0 --prefix=/opt/systemc/trap
% ./waf
% ./waf install

Compile LEON3 Processor

% cd processors/LEON3
% python LEON3Arch.py
% cd processors
% ./waf configure --with-systemc=/opt/systemc/systemc-2.2.0 --with-tlm=/opt/systemc/TLM-2009-07-15 --with-trap=/opt/systemc/trap
% ./waf

TRAP 產生的 CPU Simulator 可以有四種類型:funcLT, funcAT, accLT, accAT

    funcLT : Instruction-Accurate with loosely-timed TLM interfaces
    funcAT : Instruction-Accurate with accurate-timed TLM interfaces
    accLT : Cycle-Accurate with loosely-timed TLM interfaces
    accAT : Cycle-Accurate with accurate-timed TLM interfaces

但這次編譯,只會生出 funcLT and funcAT。

Install cross compiler
有已經做好的 sparc-elf, arm-elf compiler,替我省下不少時間!
若要自己做 cross compiler,要記得 compiler 安裝完後要將 BSP 檔案 copy 到 compiler 安裝目錄,以 sparc-elf 為例:

% cp $(TRAP_SRC_DIR)/BSP_and_Compiler/sparc/* $(SPARC_ELF_INSTALL_DIR)/sparc-elf/lib
% sparc-elf-gcc -c exceptionTrap.S -o exceptionTrap.o
% sparc-elf-gcc -c libcStub.c -o libcStub.o
% sparc-elf-gcc -c osemu-crt0.S -o osemu-crt0.o

run Hello-World
hello.c

#include "stdio.h"
int main(void) {
    printf("Hello Worldn");
}

Compile hello.c

% sparc-elf-gcc -specs=osemu.specs -g -O2 hello.c -o hello

Simulate with funcAT

% $(TRAP-SRC-DIR)/processors/LEON3/processor/_build_/funcAT/funcAT -a hello

             SystemC 2.2.0 --- Apr 17 2012 12:05:44
        Copyright (c) 1996-2006 by all Contributors
                    ALL RIGHTS RESERVED

	
	      _/        _/_/_/_/    _/_/    _/      _/   _/_/_/
	     _/        _/        _/    _/  _/_/    _/         _/
	    _/        _/_/_/    _/    _/  _/  _/  _/     _/_/
	   _/        _/        _/    _/  _/    _/_/         _/
	  _/_/_/_/  _/_/_/_/    _/_/    _/      _/   _/_/_/
	


	Luca Fossati  -    email: fossati.l@gmail.com




Loading the application and initializing the tools ...
... tools initialized

Hello World

Program exited with value 10

SystemC: simulation stopped by user.

Elapsed 0 sec. (real time)
Executed 1924 instructions
Execution Speed: inf MIPS
Simulated time: 2330 us
Elapsed 2330 cycles

Simulate with funcCT

% $(TRAP-SRC-DIR)/processors/LEON3/processor/_build_/funcAT/funcAT -a hello

             SystemC 2.2.0 --- Apr 17 2012 12:05:44
        Copyright (c) 1996-2006 by all Contributors
                    ALL RIGHTS RESERVED

	
	      _/        _/_/_/_/    _/_/    _/      _/   _/_/_/
	     _/        _/        _/    _/  _/_/    _/         _/
	    _/        _/_/_/    _/    _/  _/  _/  _/     _/_/
	   _/        _/        _/    _/  _/    _/_/         _/
	  _/_/_/_/  _/_/_/_/    _/_/    _/      _/   _/_/_/
	


	Luca Fossati  -    email: fossati.l@gmail.com




Loading the application and initializing the tools ...
... tools initialized

Hello World

Program exited with value 10

SystemC: simulation stopped by user.

Elapsed 0.01 sec. (real time)
Executed 1924 instructions
Execution Speed: 0.1924 MIPS
Simulated time: 2330 us
Elapsed 2330 cycles
%

run Testsuite

% cd $(TRAP-SRC-DIR)/testsuite
% setenv CC_CROSS sparc-elf-gcc
% setenv CFLAGS "-DBIG_TARGET -specs=osemu.specs"
% setenv SIMULATOR "../processors/LEON3/processor/_build_/funcAT/funcAT"
% make test

run Benchmark

% cd $(TRAP-SRC-DIR)/benchmarks
% setenv CC_CROSS sparc-elf-gcc
% setenv CFLAGS "-DBIG_TARGET -specs=osemu.specs"
% setenv SIMULATOR "../processors/LEON3/processor/_build_/funcAT/funcAT"
% make run

Simulate Amber on Mac OS

The Amber processor core is an ARM-compatible 32-bit RISC processor. The Amber core is fully compatible with the ARM® v2a instruction set architecture (ISA) and is therefore supported by the GNU toolset.
I would like to try run on my Mac Mini, so, I install Armber, tools and do some modification…

1. Download the Amber project from the Opencores Subversion server

$ mkdir ~/AmberInstallPath
$ cd ~/AmberInstallPath
$ svn --username YOUR_NAME -password PASSWORD co http://opencores.org/ocsvn/amber/amber/trunk

2. Install the GNU cross compiler

$ sudo port install arm-none-linux-gnueabi-gcc
$ sudo port install gawk
$ cd /opt/local/bin
$ sudo ln -s gawk awk
$ sudo ln -s arm-none-linux-gnueabi-gcc-2005q3 arm-none-linux-gnueabi-gcc

3. Install Icarus Verilog Simulator

$ sudo port install iverilog

4. Edit ~/.profile and add the following

$ export AMBER_BASE=~/AmberInstallPath/trunk
$ export AMBER_CROSSTOOL=arm-none-linux-gnueabi

5. Make scripts executable and create a run link

$ cd $AMBER_BASE
$ chmod +x hw/tools/*.sh sw/tools/*.sh
$ ln -s ../tools/run.sh hw/sim/run

6. Create $AMBER_BASE/hw/tools/runIV.patch by following

--- run.sh	2011-04-29 08:47:23.000000000 +0800
+++ runIV.sh	2011-04-29 09:14:21.000000000 +0800
@@ -46,12 +46,9 @@
 AMBER_LOAD_MAIN_MEM=" "
 AMBER_TIMEOUT=0
 AMBER_LOG_FILE="tests.log"
-SET_G=0
 SET_M=0
 SET_D=0
 SET_T=0
-SET_S=0
-SET_V=0
 SET_A=0
 SET_5=0

@@ -59,14 +56,11 @@ SET_5=0
 # show program usage
 show_usage() {
     echo "Usage:"
-    echo "run  [-a] [-g] [-d] [-t] [-s] [-v]"
+    echo "run  [-a] [-d] [-t]"
     echo " -h : Help"
     echo " -a : Run hardware tests (all tests in $AMBER_BASE/hw/tests)"
-    echo " -g : Use Modelsim GUI"
     echo " -d : Create vcd file"
     echo " -t : Create vcd file and terminate"
-    echo " -s : Use Xilinx Spatran6 Libraries (slower sim)"
-    echo " -v : Use Xilinx Virtex6 Libraries (slower sim)"
     echo " -5 : Use Amber25 core instead of Amber23 core"
     echo ""
     exit
@@ -103,14 +97,8 @@ do
             case $1 in
                 -a)     SET_A=1   # all tests
                         shift ;;
-                -s)     SET_S=1   # Xilinx libs
-                        shift ;;
-                -v)     SET_V=1   # Xilinx libs
-                        shift ;;
                 -5)     SET_5=1   # Xilinx libs
                         shift ;;
-                -g)     SET_G=1   # Bring up GUI
-                        shift ;;
                 -d)     SET_D=1
                         DUMP_START=$2
                         shift 2;;
@@ -135,24 +123,7 @@ done
 # Set comfiguration based on command-line options
 #--------------------------------------------------------

-if [ $SET_G == 1 ]; then
-    RUN_OPTIONS="-do cmd.do"
-else    
-    RUN_OPTIONS="${RUN_OPTIONS} -c -do run.do"
-fi
-
-if [ $SET_S == 1 ]; then
-    FPGA="+define+XILINX_SPARTAN6_FPGA +define+XILINX_FPGA"
-    RUN_OPTIONS="${RUN_OPTIONS} -t ps  +notimingchecks -L unisims_ver -L secureip"
-else    
-    if [ $SET_V == 1 ]; then
-        FPGA="+define+XILINX_VIRTEX6_FPGA +define+XILINX_FPGA"
-        RUN_OPTIONS="${RUN_OPTIONS} -t ps  +notimingchecks"
-    else    
-        FPGA=" "
-    fi
-fi
-
+RUN_OPTIONS="-f iverilog.f"

 if [ $SET_D == 1 ]; then
     AMBER_DUMP_VCD="+define+AMBER_DUMP_VCD +define+AMBER_DUMP_START=$DUMP_START"
@@ -173,13 +144,8 @@ else    
 fi

 if [ $SET_A == 1 ]; then
-    if [ $SET_S == 1 ]; then
-        TECH="-s"
-    elif [ $SET_V == 1 ]; then
-        TECH="-v"
-    else    
-        TECH=" "
-    fi        
+
+    TECH=" "

     if [ $SET_5 == 1 ]; then
         CORE="-5"
@@ -273,54 +239,42 @@ fi

 #--------------------------------------------------------
-# Modelsim
+# iVerilog
 #--------------------------------------------------------
-if [ $MAKE_STATUS == 0 ]; then
-   if [ ! -d work ]; then
-       vlib work
-   fi
-
-   if [ $? == 0 ]; then
-       vlog +libext+.v 
-            +incdir+../vlog/amber23+../vlog/amber25+../vlog/system+../vlog/tb+../vlog/ethmac 
-            +incdir+../vlog/lib+../vlog/xs6_ddr3+../vlog/xv6_ddr3 
-            -y ../vlog/amber23 -y ../vlog/amber25 -y ../vlog/system  -y ../vlog/tb -y ../vlog/ethmac 
-            -y ../vlog/lib   -y ../vlog/xs6_ddr3 -y ../vlog/xv6_ddr3  
-            -y $XILINX/verilog/src/unisims 
-            -y $XILINX/verilog/src 
-            ../vlog/tb/tb.v 
-            $XILINX/verilog/src/glbl.v 
-            +define+BOOT_MEM_FILE="$BOOT_MEM_FILE" 
-            +define+BOOT_MEM_PARAMS_FILE="$BOOT_MEM_PARAMS_FILE" 
-            +define+MAIN_MEM_FILE="$MAIN_MEM_FILE" 
-            +define+AMBER_LOG_FILE="$AMBER_LOG_FILE" 
-            +define+AMBER_TEST_NAME="$AMBER_TEST_NAME" 
-            +define+AMBER_SIM_CTRL=$TEST_TYPE 
-            +define+AMBER_TIMEOUT=$AMBER_TIMEOUT 
-            ${FPGA} 
-            $AMBER_CORE 
-            $AMBER_DUMP_VCD 
-            $AMBER_TERMINATE 
-            $AMBER_LOAD_MAIN_MEM
-                  
-        if [ $? == 0 ]; then
-            vsim -voptargs="+acc=rnpc" tb ${RUN_OPTIONS}
-            
-            # Set a timeout value for the test if it passed
-            if [ $TEST_TYPE == 1 ]; then
-                tail -1  /dev/null
-                if  [ $? == 0 ]; then
-                    TICKS=`tail -1 > $AMBER_LOG_FILE
-fi
+      echo "+libext+.v"                > iverilog.f
+      echo "+incdir+../vlog/amber23"  >> iverilog.f
+      echo "+incdir+../vlog/amber25"  >> iverilog.f
+      echo "+incdir+../vlog/system"   >> iverilog.f
+      echo "+incdir+../vlog/tb"       >> iverilog.f
+      echo "+incdir+../vlog/ethmac"   >> iverilog.f
+      echo "+incdir+../vlog/lib"      >> iverilog.f
+      echo "+incdir+../vlog/xs6_ddr3" >> iverilog.f
+      echo "+incdir+../vlog/xv6_ddr3" >> iverilog.f
+      echo "-y../vlog/amber23"        >> iverilog.f
+      echo "-y../vlog/amber25"        >> iverilog.f
+      echo "-y../vlog/system"         >> iverilog.f
+      echo "-y../vlog/tb"             >> iverilog.f
+      echo "-y../vlog/ethmac"         >> iverilog.f
+      echo "-y../vlog/lib"            >> iverilog.f
+      echo "-y../vlog/xs6_ddr3"       >> iverilog.f
+      echo "-y../vlog/xv6_ddr"        >> iverilog.f
+      echo "+define+BOOT_MEM_FILE="$BOOT_MEM_FILE""               >> iverilog.f
+      echo "+define+BOOT_MEM_PARAMS_FILE="$BOOT_MEM_PARAMS_FILE"" >> iverilog.f
+      echo "+define+MAIN_MEM_FILE="$MAIN_MEM_FILE""               >> iverilog.f
+      echo "+define+AMBER_LOG_FILE="$AMBER_LOG_FILE""             >> iverilog.f
+      echo "+define+AMBER_TEST_NAME="$AMBER_TEST_NAME""           >> iverilog.f
+      echo "+define+AMBER_SIM_CTRL=$TEST_TYPE"                      >> iverilog.f
+      echo "+define+AMBER_TIMEOUT=$AMBER_TIMEOUT"                   >> iverilog.f
+      echo "$AMBER_CORE"          >> iverilog.f
+      echo "$AMBER_DUMP_VCD"      >> iverilog.f
+      echo "$AMBER_TERMINATE"     >> iverilog.f
+      echo "$AMBER_LOAD_MAIN_MEM" >> iverilog.f
+      echo "../vlog/tb/tb.v"      >> iverilog.f
+
+      rm -rf ./armber
+      iverilog -f iverilog.f -o armber
+      ./armber

7. Create runIV script for iverilog simulator

$ cd $AMBER_BASE/hw/tools
$ patch -o runIV.sh -i runIV.patch
$ chmod +x runIV.sh
$ cd $AMBER_BASE/hw/sim
$ ln -s ../tools/runIV.sh runIV

8. If you see the iverilog compile error message for log2 function in next step, you could replace log2 by $clog2 to solve the problem.

9. Run a Hello-World Test with Amber 25

$ cd $AMBER_BASE/hw/sim
$ runIV -5 hello-world

10. Hello-World simulation Result

Amber Boot Loader v20110202130047
Hello, World!

----------------------------------------------------------------------------
Amber Core
       > User         FIRQ         IRQ          SVC
r0       0x00000010
r1       0x16000000
r2       0x00000000
r3       0x00000000
r4       0x0c80e403
r5       0x00000000
r6       0x00000000
r7       0x00000000
r8       0xdeadbeef   0xdeadbeef 
r9       0xdeadbeef   0xdeadbeef 
r10      0x00000011   0xdeadbeef 
r11      0xf0000000   0xdeadbeef 
r12      0x00000000   0xdeadbeef 
r13      0x08000000   0xdeadbeef   0xdeadbeef   0x01ffffb8
r14 (lr) 0x0080e420   0xdeadbeef   0xdeadbeef   0x20000787
r15 (pc) 0x0080e960

Status Bits: N=0, Z=1, C=1, V=0, IRQ Mask 0, FIRQ Mask 0, Mode = User          
----------------------------------------------------------------------------

++++++++++++++++++++
Passed hello-world 29320 ticks
++++++++++++++++++++

Fail to Download Firmware to LPC2103

不知為什麼, 有時候要 Download Firmware to LPC2103 時會出現
下列錯誤訊息:

No Algorithm found for: 00000000H - 00001FC3H
Programming skipped!

後來發現要檢查 Options for Target -> Utilities -> Setting 設定:
1. RAM for Algorithm: Star: 0x40000000, Size: 0x0800
2. Programming Algorithm: LPC2000 IAP2 32KB Flash