網頁

2014年10月25日 星期六

OpenRISC with DE0-Nano

Last Update: 2014/10/29 00:24+08
Type: Note



---Intro---


把 OpenRISC 燒進 DE0-Nano 執行嵌入式的 Linux 系統

Environment & Requirement:
VMWare
Ubuntu 12.04.2 Desktop i386
FPGA板 - DE0-Nano
USB to UART (FTDI接腳, ex. UB-391 記得裝驅動)



---Content---


如果有哪邊卡住的話, 建議用 su 試試看
su

基本上是看 這篇 完成的
安裝相依lib
apt-get install autoconf pkg-config automake libtool libusb-1.0-0-dev libtclcl1-dev libftdi-dev

PATH 設置
export PATH=$PATH:/opt/or1k-elf-4.8.1/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/or1k-elf-4.8.1/i686-pc-linux-gnu/or1k-elf/lib

export PATH=$PATH:/opt/altera/12.0sp2/quartus/bin
export PATH=$PATH:$HOME/orconf2013ws/orpsoc-3.1/bin

安裝 or1k-elf
參考 這篇 的 Installation of development versions
或用 Prebuilt versions, 載下來解壓縮即可
cd /opt
wget ftp://ocuser:ocuser@openrisc.opencores.org/toolchain/gcc-or1k-elf-4.8.1-ubuntu-13.04-x86.tar.bz2
tar jxvf gcc-or1k-elf-4.8.1-ubuntu-13.04-x86.tar.bz2
mv gcc-or1k-elf-4.8.1-ubuntu-13.04-x86 or1k-elf-4.8.1

安裝Quartus
下載 Quartus 12.0sp2
過程中的安裝路徑設定在 /opt/altera/12.0sp2
tar -xzvf 12.0sp2_263_quartus_free_linux.tar.gz
12.0sp2_263_quartus_free_linux/setup

下載 openocd 作為 控制&debug
mkdir orconf2013ws; cd orconf2013ws
git clone git://repo.or.cz/openocd.git
cd openocd
./bootstrap
./configure --enable-ftdi --enable-usb_blaster_libftdi --enable-maintainer-mode
make


下載 orpsoc
cd ..
wget ftp://ocuser:ocuser@openrisc.opencores.org/orpsoc/orpsoc-3.1.tar.gz
tar xzf orpsoc-3.1.tar.gz
cd orpsoc-3.1
./configure
make
sudo make install

下載 orpsoc-cores
其中 "git checkout orconf2013/master" 似乎會有錯
改 "git checkout master"
cd ..
git clone https://github.com/openrisc/orpsoc-cores.git
cd orpsoc-cores
git remote add orconf2013 https://github.com/juliusbaxter/orpsoc-cores.git 
git remote update
git checkout orconf2013/master

先下載 bare metal demo 用的 software
待會可以載入到device執行
可以先到底下的 sw/xxxxx/ 執行 "make", compile 待會要demo的軟體
cd ..
git clone https://github.com/juliusbaxter/orconf2013.git

準備 Build 目錄
cd ..
mkdir orpsoc-build
cd orpsoc-build

生成一個檔案 orpsoc.conf 其內容為
[main] 
cores_root   = ../orpsoc-cores/cores
systems_root = ../orpsoc-cores/systems

build de0-nano 並寫入FPGA
orpsoc build de0_nano
quartus_pgm --mode=jtag -o p\;build/de0_nano/bld-quartus/de0_nano.sof
若有 Error code 89 參考 這邊
就是執行下述代碼後, 再跑一次 quartus_pgm
sudo killall jtagd
which jtagd
sudo `which jtagd`

執行openocd
cd ../openocd
./src/openocd -s ./tcl -f ./tcl/interface/altera-usb-blaster.cfg -f ./tcl/board/or1k_generic.cfg
讓它停在 "Target ready..."
這個terminal視窗 不要關掉
待會用另一個 terminal 連線過來



---Download and run OpenRISC software on SoC
再開另一個terminal視窗繼續
剛剛的 openocd 會開啟 localhost:4444 作為通訊
telnet localhost 4444
telnet 進去以後, 可以打
halt
load_image /path/to/your_image
reset
reg npc 0x100
resume
"halt" : 暫停 device
"load_image /path/to/your_image" : 載入你的軟體映象
   "/path/to/your_image" => e.q. ~/orconf2013ws/orconf2013/sw/timer/timer
"reset" : 重置, 載入映象後, 有可能需要重置
"reg npc 0x100" : Next Program Counter 從 0x100 開始
"resume" : 恢復暫停的device



在載入 Linux 到 device 之前, 建議先把連線接好
用 FTDI 跟 PC 端的 Com Port 連接
Pin腳設定在 "$HOME/orconf2013ws/orpsoc-build/build/de0_nano/bld-quartus/de0_nano.tcl"
#
# UART0: RX <-> GPIO_2[0] (Pin 5, bottom header)
#        TX <-> GPIO_2[1] (Pin 6, bottom header)
#
set_location_assignment PIN_A14 -to uart0_srx_pad_i
set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to uart0_srx_pad_i
set_location_assignment PIN_B16 -to uart0_stx_pad_o
set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to uart0_stx_pad_o
再對照 DE0-Nano官方使用手冊
若不確定自己板子的UART有沒有正常運作 可以參考 這篇 來測試


接著下載官方提供的 image vmlinux-de0_nano
含 linux kernel 來測試你的板子
halt; load_image /path_to_your_image/vmlinx-de0_nano; reg npc 0x100; resume
載入後稍微等個幾秒
de0-nano 會有2顆LED在閃爍

回到windows用PuTTY 開啟com port
或用 Linux 的 screen 連線到板子上
screen /dev/ttyUSB0 115200

連線成功~ Congratulation!


---Reference---


ORCONF2013 Workshop ORPSoC On DE0 Nano
DE0-Nano官方使用手冊



1 則留言:

  1. Hello

    I am Prudhvi, Masters student at Arizona State University.

    As part of initial step of my masters thesis, I need to setup orpsoc on de0 nano and run linux on it. I got struck while loading the linux. Below are the steps I followed.

    1. first I downloaded fuseSoc from github
    2. Then build for de0 Nano
    $ fusesoc build de0_nano
    3. Then loaded .sof generated using quartus_pgm
    $ quartus_pgm --mode=jtag -o p\;de0_nano_0.sof
    4. Then downloaded openocd
    $ ./bootstrap
    $ ./configure --enable-ftdi --enable-usb_blaster_libftdi --enable-maintainer-mode
    $ make
    $ make install
    5. $sudo ./src/openocd -s ./tcl -f ./tcl/interface/altera-usb-blaster.cfg -f
    ./tcl/board/or1k_generic.cfg

    6. In another terminal
    $ telnet localhost 4444

    OpenOCD started
    > halt; load_image /pathto/vmlinux-de0_nano; reset

    CRC ERROR! match bit after write is 0 (computed CRC 0x2b7d8fa9)
    CRC ERROR! match bit after write is 0 (computed CRC 0x2b7d8fa9)
    CRC ERROR! match bit after write is 0 (computed CRC 0x2b7d8fa9)

    >

    The above statements are the result.

    I followed this tutorial

    https://medium.com/@rz2285/running-orpsoc-on-de0-nano-3aaf43826ecb

    Please let me know if anything wrong in the steps.

    OR please direct me how to load it.

    Thanks in advance.

    Regards

    回覆刪除