OpenCores
URL https://opencores.org/ocsvn/orsoc_graphics_accelerator/orsoc_graphics_accelerator/trunk

Subversion Repositories orsoc_graphics_accelerator

[/] [orsoc_graphics_accelerator/] [trunk/] [doc/] [src/] [orpsocSetup.tex] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 Orka
\documentclass[10pt,a4paper]{article}
2
\usepackage[latin1]{inputenc}
3
\usepackage{amsmath}
4
\usepackage{amsfonts}
5
\usepackage{amssymb}
6
\usepackage{listings}
7
\title{Getting started with ORPSoC on the ATLYS board}
8
\author{Anton Fosselius, Per Lenander}
9
 
10
\begin{document}
11
\maketitle
12
\newpage
13
 
14
\tableofcontents
15
\newpage
16
 
17
\section{Introduction}
18
This document will explain how to set up an development environment in Ubuntu Linux for ORPSoC on the Atlys development board. It will give detailed descriptions on where to get the correct software and how to use it.
19
 
20
The document contains various examples on how to configure the hardware and software to work correctly with the ORPSoC build system, from simply getting a led to blink to compiling a custom Linux kernel to run on the OpenRISC processor.
21
 
22
\section{Hardware}
23
To be able to follow every step of this article you will need the following hardware:
24
 
25
\begin{itemize}
26
        \item One Computer with a recent edition of Ubuntu installed (11.10 or later)
27
        \item One Atlys FPGA board
28
        \item One Computer with Windows XP or later installed
29
\end{itemize}
30
 
31
The Windows computer is only used to do SPI Flash with the application Adept from Digilent. The authors of this document have to their regret not found any reliable way to do this in Linux. The Xilinx iMPACT programming tool can be used to program the FPGA itself, but is very unreliable and slow when programming the SPI Flash.
32
 
33
\section{Installing Software}
34
To be able to boot Linux on ORPSoC with the Atlys board, you will have to install a wide range of tools. This will take some time and lot of disk space (close to 20GB).
35
 
36
\subsection{Xilinx ISE}
37
\textbf{Note:} The trial version of Xilinx ISE does not work because it do not allow you to generate bitstreams.
38
 
39
The first thing you want to do is to sign up at Xilinx homepage and download the ISE webpack edition. The ISE webpack file is about 6Gbyte big, it will take a while to download. When the ISE is installed it will take about 13-15Gbyte of disk space. Make sure you have enough disk space available!
40
 
41
\begin{quote}
42
http://www.xilinx.com/products/design-tools/ise-design-suite/ise-webpack.html
43
\end{quote}
44
 
45
Now when the ISE is downloading its time to download a webpack license, this is also done on the Xilinx homepage. When the ISE download is finished run the installer as "sudo" and follow the instructions.
46
 
47
\subsection{Subversion and Git}
48
To follow this document you need to have both subversion and git installed on your computer.
49
\begin{quote}
50
\item sudo apt-get install subversion git
51
\end{quote}
52
 
53
\subsection{ORPSoC}
54
Checkout the ORPSoC directory from OpenCores:
55
 
56
\begin{quote}
57
git clone git://git.openrisc.net/stefan/orpsocv2
58
\end{quote}
59
 
60
You have to build the PDF file first to be able to read the documentation for orpsocv2. First cd into the orpsocv2/doc folder and type the following:
61
\begin{quote}
62
./configure \newline
63
make pdf
64
\end{quote}
65
 
66
You can then read the pdf by running:
67
 
68
\begin{quote}
69
evince orpsoc.pdf
70
\end{quote}
71
 
72
\subsection{ork1sim}
73
To install the OpenRISC toolchain we first need to install the or1ksim simulator. First check out the subversion repository to get the latest version.
74
 
75
\begin{quote}
76
svn co http://opencores.org/ocsvn/openrisc/openrisc/trunk/or1ksim
77
\end{quote}
78
 
79
Create a build folder and cd into it.
80
\begin{quote}
81
mkdir builddir\_or1ksim \newline
82
cd builddir\_or1ksim
83
\end{quote}
84
 
85
Now build and install the or1ksim with the following commands:
86
\begin{quote}
87
../or1ksim/configure --target=or32-elf --prefix=/opt/or1ksim \newline
88
make all  \newline
89
make install \newline
90
export PATH=/opt/or1ksim/bin:\$PATH
91
\end{quote}
92
To test the Simulator you will need to install the OpenRISC toolchain.
93
If DejaGNU and the OpenRISC GNU tool chain are installed, the build can be tested as follows.
94
 
95
\begin{quote}
96
make check
97
\end{quote}
98
 
99
All tests should pass.
100
 
101
\subsection{OpenRISC toolchain}
102
Checkout the gnu-src subversion directory:
103
 
104
\begin{quote}
105
svn co http://opencores.org/ocsvn/openrisc/openrisc/trunk/gnu-src
106
\end{quote}
107
 
108
We can build uClibc and Linux along with the toolchain. This will download more then 500mb, it might take a while.
109
 
110
\begin{quote}
111
cd gnu-src \newline
112
git clone git://git.openrisc.net/jonas/uClibc \newline
113
git clone git://git.openrisc.net/stefan/linux
114
\end{quote}
115
 
116
You will need a bunch of other tools to be able to build everything correctly.
117
 
118
\begin{quote}
119
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
120
\end{quote}
121
 
122
Now we got everything! run the following command:
123
 
124
\begin{quote}
125
./bld-all.sh --force --prefix /opt/openrisc --or1ksim-dir /opt/or1ksim --uclibc-dir uClibc --linux-dir linux
126
\end{quote}
127
 
128
Add the following to your .bashrc file located in (/home/USERNAME/.bashrc). Open .bashrc with a editor and then add the export statement at the end of the file.
129
 
130
\begin{quote}
131
gedit .bashrc \newline
132
\end{quote}
133
 
134
Add this:
135
 
136
\begin{quote}
137
export PATH=\$PATH:/opt/openrisc/bin
138
\end{quote}
139
 
140
Start a new terminal and type "or" and double tab. If everything works you will see a list of or32-elf and or32-linux tools.
141
 
142
\subsection{SPI Flash}
143
\textbf{Note:} You can try to use SPI Flash with iMPACT in Linux, for this to work at all you will have to set the JP11 jumper (next to the USB port). The SPI Flash will now start but it is SLOW and will most likely fail.
144
 
145
This instructions are for installing Digilent Adept in Windows, no good solution for Linux have been found.
146
 
147
You need to download and install Digilent Adept and the Digilent plugin. Adept can be downloaded from:
148
 
149
\begin{quote}
150
http://www.digilentinc.com/Products/Detail.cfm?Prod=ADEPT
151
\end{quote}
152
 
153
The plugin can be downloaded from:
154
 
155
\begin{quote}
156
http://www.digilentinc.com/Products/Detail.cfm?NavPath=2,66,768\&Prod=DIGILENT-PLUGIN
157
\end{quote}
158
 
159
Run the installs and follow the instructions.
160
 
161
For Linux to recognise the board we have to set some udev rules.
162
 
163
Copy the udev-rules from the xilinx folder to your udev folder.
164
 
165
\begin{lstlisting}
166
sudo cp /xilinix/13.4/ISE_DS/common/bin/lin64/digilent/\
167
digilent.adept.runtime_2.7.4-x86_64/52-digilent-usb.rules /etc/udev/rules.d/
168
 
169
sudo cp /opt/Xilinx/13.4/ISE_DS/common/bin/lin64/\
170
xusbdfwu.rules /etc/udev/rules.d/
171
 
172
sudo /etc/init.d/udev restart
173
\end{lstlisting}
174
Done!
175
 
176
\subsection{Board specific library for bare metal}
177
\label{sec:libboard}
178
The or32-elf toolchain needs to know how your board is structured to properly compile elfs for it. \textbf{NOTE:} These steps are not needed to build Linux applications, only bare metal. If your board is supported here\footnote{http://opencores.org/openrisc,newlib\_toolchain} you don't need to take these steps, just make sure to call or32-elf-gcc/g++ with the correct flags.
179
 
180
In the gnu-src/newlib-1.18.0/libgloss/or32 folder of the toolchain, find the ml501.S file. This file contains basic definitions for the board, and will be used to build libboard.a. Make a copy of the file called atlys.S and edit the copy with the following changes:
181
 
182
\begin{itemize}
183
\item \_board\_mem\_size is the size of connected RAM. In the case of the atlys, it should be changed to 0x8000000 (128MB DDR2).
184
\item \_board\_clk\_freq is the clock frequency in hertz. For the atlys, it should be 50000000.
185
\end{itemize}
186
 
187
UART settings should already be correct.
188
 
189
Build libboard.a from the file and move it to the path where the OpenRISC toolchain is installed:
190
 
191
\begin{lstlisting}
192
or32-elf-as -o atlys atlys.S
193
or32-elf-ar -q libboard.a atlys
194
sudo mkdir /opt/openrisc/or32-elf/lib/boards/atlys
195
sudo cp libboard.a /opt/openrisc/or32-elf/lib/boards/atlys/
196
\end{lstlisting}
197
 
198
This process should be similar for other boards, check their specification for correct memory size and clock speed.
199
 
200
\subsection{Toolchain Done!}
201
Now you have a working toolchain! congratulations!
202
 
203
\section{Building and Flashing}
204
When building and flashing your FPGA or your flash you will be faced with some different file types.
205
\begin{itemize}
206
\item   Makefile, this file contains building instructions.
207
\item   file.v is a Verilog source code file
208
\item   file.vhd is a VHDL source code file
209
\item   file.bit is a Xilinx bitstream file, The .bit is used to program the FPGA
210
\item   file.mcs is a Intel MCS-86 Hexadecimal Object. The MCS can be loaded to the flash.
211
\end{itemize}
212
 
213
\subsection{Bare metal "hello world"}
214
 
215
Writing a hello world for the processor is simple:
216
 
217
\textbf{FIX: REDO EXAMPLE (NEEDS PRINTF.H)}
218
 
219
\begin{lstlisting} [tabsize=4]
220
#include "printf.h"
221
 
222
int main()
223
{
224
        printf("Hello world!\n");
225
        return 0;
226
}
227
\end{lstlisting}
228
 
229
This file needs the board-specific headers to compile.
230
 
231
Build it with:
232
 
233
\begin{lstlisting}
234
or32-elf-gcc -mboard=atlys hello.c -o hello
235
or32-elf-objcopy -O binary hello
236
bin2binsizeword hello hello-bsw.bin
237
\end{lstlisting}
238
 
239
\textbf{Note:} for the -mboard=atlys flag to work, libboard.a has to have been built and moved to the correct directory, see section \ref{sec:libboard}.
240
 
241
Load the hello-bsw.bin to the simulator or the FPGA as described below.
242
 
243
\subsection{Running the "hello world" on or1ksim}
244
Change your directory to your or1ksim folder and run:
245
\begin{lstlisting}
246
./sim -f sim.cfg /path/to/your/file/hello
247
\end{lstlisting}
248
Now you will see a lot of funny text and if you look closely you will see a "hello world" in the middle of all the output.
249
 
250
\subsection{Running the "hello world" on the FPGA}
251
\begin{quote}
252
make orpsoc.mcs BOOTLOADER\_BIN=hello-bsw.bin
253
\end{quote}
254
 
255
Load the mcs and reset the FPGA.
256
 
257
\subsection{Building the Linux kernel}
258
To get a linux kernel specific for the OpenRISC platform and the Atlys board, check out:
259
 
260
\begin{quote}
261
git clone git://git.openrisc.net/stefan/linux
262
\end{quote}
263
 
264
Build the kernel by entering:
265
 
266
\begin{quote}
267
make atlys\_defconfig \newline
268
make ARCH=openrisc menuconfig \newline
269
make ARCH=openrisc
270
\end{quote}
271
 
272
(The first line loads a default configuration for the atlys board, which can be overwritten by running the second line. The third line actually builds the kernel.) Something that can be interesting to change is the modeline sent to the VGA module on boot. This can be changed in the menuconfig by entering the \textit{Processor type and features} menu, and changing the line at the very bottom of the list.
273
 
274
This will build vmlinux.bin, which will be loaded to the FPGA. To change what basic programs are loaded with the linux dist, add your own programs to arch/openrisc/support/initramfs. These must be compiled with the or32-linux tools.
275
 
276
\subsection{Running the Linux kernel in or1ksim}
277
Same procedure as for ordinary elf. Linux will open a telnet interface you can connect to \textbf{AT PORT NR?}.
278
 
279
\subsection{Running the Linux kernel on the FPGA}
280
The OpenRISC processor need the linux image to be in the correct format, so convert the vmlinux.bin with the bin2binsizeword found in orpsoc/sw/utils:
281
 
282
\begin{quote}
283
cd sw/utils \newline
284
make \newline
285
./bin2binsizeword /path/to/image/vmlinux.bin /path/to/new/image/vmlinux.bin
286
\end{quote}
287
 
288
\subsubsection{Bad way}
289
Put the word size bin in the boards/xilinx/atlys/backend/par/run folder. Then load it as a "bootloader" into the mcs file by typing:
290
 
291
\begin{quote}
292
make orpsoc.mcs BOOTLOADER\_BIN=vmlinux.bin
293
\end{quote}
294
 
295
This will program the linux image into the mcs file, which should be about 15MB in size by now. Load this file to the FPGA SPI-flash using iMPACT or Digilent Adept.
296
 
297
\subsubsection{Good way}
298
Load a bootloader into the BOOTLOADER\_BIN section and load the linux image from flash or from an external memory. We use u-boot for this. Download it by running:
299
 
300
\begin{quote}
301
git clone git://openrisc.net/stefan/u-boot
302
\end{quote}
303
 
304
Then run:
305
 
306
\begin{quote}
307
make atlys\_config \newline
308
make
309
\end{quote}
310
 
311
To build u-boot.bin for the atlys board (several other orpsoc board configurations exist). Convert it to word size with:
312
 
313
\begin{quote}
314
bin2binsizeword u-boot.bin u-boot-wordsize.bin
315
\end{quote}
316
 
317
Load it to flash using the instructions above (BOOTLOADER\_BIN flag).
318
 
319
Use the mkimage program in the tools directory to build a u-boot compatible image to boot:
320
 
321
\begin{enumerate}
322
\item Linux image:
323
 
324
\begin{quote}
325
tools/mkimage -n 'Linux for OpenRISC' -A or1k -O linux -T kernel -C none -a 0 -e 0x100 -d vmlinux.bin uImage
326
\end{quote}
327
 
328
\item Bare metal image:
329
 
330
\begin{quote}
331
tools/mkimage -A or1k -T standalone -C none -a 0 -e 0x100 -n helloWorld -d hello.bin uImage
332
\end{quote}
333
 
334
\end{enumerate}
335
 
336
Connect to the board through a serial terminal (connect to the UART microUSB port, connect other end to computer USB port). The device will probably show up as ttyACM0, but check dmesg to verify. Start a serial terminal such as gtkterm and connect to the board using a baudrate of 115200, 8 data bits, 1 stop bit, no parity. Type help and you should get a list of available commands.
337
 
338
You must have a network connection to a computer with nfs installed (sudo apt-get install nfs-kernel-server). Export a directory (add a line to /etc/exports) containing the uImage you want.
339
 
340
On the board (through the u-boot uart interface) set the ipaddr and serverip. These can be saved to flash with \textbf{saveenv}. Set the \textit{bootfile} to /the/path/to/your/export/uImage. Type \textbf{nfs}. The image should load (check network connection if fails) in around 10-20 seconds. Type \textbf{bootm}. Image should boot.
341
 
342
To make it easier to boot, write:
343
 
344
\begin{quote}
345
setenv bootcmd nfs 0x100000 192.168.1.10:/export/share/uImage \; bootm 100000 \newline
346
saveenv
347
\end{quote}
348
 
349
The only command needed to be run through the uart terminal is boot. \textit{Currently this doesn't work so good for some reason. Should though...}
350
 
351
\section{Extra}
352
 
353
\subsection{UART}
354
You can get UART output from the MicroUSB port located beside the USB port, In Ubuntu it shows as /dev/ttyACM0.
355
use a baudrate of 115200 with 8 databit, 1 stop bit, no parity. GtkTerm is a good tool for reading from the uart.
356
\begin{quote}
357
sudo apt-get install gtkterm
358
\end{quote}
359
 
360
\subsection{Adding a RTL Module}
361
 
362
A good way to start making your own RTL modules is to first check how the other RTL modules are structured. The GPIO module is simple and a good module to start with. Make a copy of the GPIO folder (orpsocv2/boards/xilinx/atlys/rtl/verilog) with your wanted module name. Now modify the content of the folders to your needs and make sure to follow all the naming conventions. The folder, the verilog file and the module must have the same name.
363
 
364
Files that need to be updated:
365
\begin{itemize}
366
\item atlys/rtl/verilog/orpsoc\_top/orpsoc\_top.h
367
\item atlys/rtl/verilog/include/orpsoc-defines.v
368
\item atlys/rtl/verilog/orpsoc\_testbench.v
369
\item atlys/backend/par/bin/atlys.ucf
370
\item If any wishbone buses are used, many things need to be updated:
371
\begin{itemize}
372
\item atlys/rtl/verilog/arbiter/(the bus you are adding to).v
373
\item atlys/rtl/verilog/orpsoc\_top/orpsoc\_top.h
374
\item atlys/rtl/verilog/include/orpsoc\_params.h
375
\end{itemize}
376
\end{itemize}
377
 
378
atlys.ucf only needs to be updated if any IO pins where modified.
379
 
380
 
381
\subsection{Bare metal light LEDs in assembly}
382
This is an example to test to set the gpio register (through the wishbone bus) on the board.
383
The LED register on GPIO module lights the LEDs according to the input.
384
You need to "cd" to the following directory orpsocv2/boards/xilinx/atlys/sw/bootrom/
385
\begin{lstlisting} [tabsize=4]
386
##### name pio.S
387
l.movhi r3,0x9100 # Set the memory address for the LEDs (GPIO module)
388
l.addi r4,r0,0xff # Set r4 to 0xff (set all GPIO to high)
389
 
390
l.sb 0x0(r3),r4 # sb = set byte, sets register at address r3 with value r4
391
l.sb 0x1(r3),r4 # sets the GPIO register to output
392
 
393
l.j 0
394
l.nop
395
l.nop
396
\end{lstlisting}
397
 
398
To compile this, run the following:
399
\begin{lstlisting}
400
or32-elf-as -o pio pio.S
401
or32-elf-objcopy -O binary pio
402
\end{lstlisting}
403
Now, lets do some magic. (the magic of pipes updates the bootrom.v)
404
\begin{lstlisting}
405
bin2vlogarray < pio
406
bin2vlogarray < pio > bootrom.v
407
\end{lstlisting}
408
Now you need to rebuild your entire system then flash the FPGA with the new image.
409
When you have loaded the .mcs file to your flash and restarted your board, the LEDs should be lit!
410
 
411
All available assembly instructions and their implementation are explained in the openrisc\_arch.pdf document.
412
 
413
\subsection{DDR2 RAM}
414
The Atlys board contains a DDR2 RAM that allows for simultaneous reads and writes.
415
The DDR2 RAM contains 6 ports, 3 Read/Write ports 2 Read only and 1 Write only.
416
The Write only port can be combined with a Read only to form an extra Read/Write port.
417
 
418
\subsection{Memory Mapping}
419
OpenRISC Reference Platform (ORP) Address Space \\
420
\begin{tabular}{|l|l|l|l|l|}
421
\hline
422
\textbf{Start adr} & \textbf{End adr} & \textbf{cached} & \textbf{Size(Mb)} & \textbf{Content} \\
423
\hline
424
0xf000\_0000 & 0xffff\_ffff & Cached & 256 & ROM \\
425
\hline
426
0xc000\_0000 & 0xefff\_ffff & Cached & 768 & Reserved \\
427
\hline
428
0xb800\_0000 & 0xbfff\_ffff & Uncached & 128 & Reserved for custom devices \\
429
\hline
430
0xa600\_0000 & 0xb7ff\_ffff & Uncached & 288 & Reserved \\
431
\hline
432
0xa500\_0000 & 0xa5ff\_ffff & Uncached & 16 & Debug 0-15 \\
433
\hline
434
0xa400\_0000 & 0xa4ff\_ffff & Uncached & 16 & Digital Camera Controller 0-15 \\
435
\hline
436
0xa300\_0000 & 0xa3ff\_ffff & Uncached & 16 & I2C Controller 0-15 \\
437
\hline
438
0xa200\_0000 & 0xa2ff\_ffff & Uncached & 16 & TDM Controller 0-15 \\
439
\hline
440
0xa100\_0000 & 0xa1ff\_ffff & Uncached & 16 & HDLC Controller 0-15 \\
441
\hline
442
0xa000\_0000 & 0xa0ff\_ffff & Uncached & 16 & Real-Time Clock 0-15 \\
443
\hline
444
0x9f00\_0000 & 0x9fff\_ffff & Uncached & 16 & Firewire Controller 0-15 \\
445
\hline
446
0x9e00\_0000 & 0x9eff\_ffff & Uncached & 16 & IDE Controller 0-15 \\
447
\hline
448
0x9d00\_0000 & 0x9dff\_ffff & Uncached & 16 & Audio Controller 0-15 \\
449
\hline
450
0x9c00\_0000 & 0x9cff\_ffff & Uncached & 16 & USB Host Controller 0-15 \\
451
\hline
452
0x9b00\_0000 & 0x9bff\_ffff & Uncached & 16 & USB Func Controller 0-15 \\
453
\hline
454
0x9a00\_0000 & 0x9aff\_ffff & Uncached & 16 & General-Purpose DMA 0-15 \\
455
\hline
456
0x9900\_0000 & 0x99ff\_ffff & Uncached & 16 & PCI Controller 0-15 \\
457
\hline
458
0x9800\_0000 & 0x98ff\_ffff & Uncached & 16 & IrDA Controller 0-15 \\
459
\hline
460
0x9700\_0000 & 0x97ff\_ffff & Uncached & 16 & Graphics Controller 0-15 \\
461
\hline
462
0x9600\_0000 & 0x96ff\_ffff & Uncached & 16 & PWM/Timer/Counter Controller 0-15 \\
463
\hline
464
0x9500\_0000 & 0x95ff\_ffff & Uncached & 16 & Traffic COP 0-15 \\
465
\hline
466
0x9400\_0000 & 0x94ff\_ffff & Uncached & 16 & PS/2 Controller 0-15 \\
467
\hline
468
0x9300\_0000 & 0x93ff\_ffff & Uncached & 16 & Memory Controller 0-15 \\
469
\hline
470
0x9200\_0000 & 0x92ff\_ffff & Uncached & 16 & Ethernet Controller 0-15 \\
471
\hline
472
0x9100\_0000 & 0x91ff\_ffff & Uncached & 16 & General-Purpose I/O 0-15 \\
473
\hline
474
0x9000\_0000 & 0x90ff\_ffff & Uncached & 16 & UART16550 Controller 0-15 \\
475
\hline
476
0x8000\_0000 & 0x8fff\_ffff & Uncached & 256 & PCI I/O \\
477
\hline
478
0x4000\_0000 & 0x7fff\_ffff & Uncached & 1024 & Reserved \\
479
\hline
480
0x0000\_0000 & 0x3fff\_ffff & Cached & 1024 & RAM \\
481
\hline
482
\end{tabular}
483
 
484
 
485
\section{References}
486
 
487
\begin{quote}
488
OpenRISC: http://opencores.org/or1k/Main\_Page \newline
489
ORPSoC: http://opencores.org/openrisc,orpsocv2 \newline
490
or1ksim: http://opencores.org/openrisc,or1ksim \newline
491
Toolchan: http://opencores.org/openrisc,gnu\_toolchain \newline
492
\end{quote}
493
 
494
\end{document}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.