Skip to content

Commit 4f1102a

Browse files
committed
or1ksim: Modernize the tutorial
1 parent 089bf98 commit 4f1102a

2 files changed

Lines changed: 89 additions & 31 deletions

File tree

docs/linux-on-or1ksim.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ nav_order: 2
1515

1616
#### Files
1717

18-
- [or1ksim.cfg](or1ksim.cfg) - config needed for or1ksim
19-
- [or1ksim-2025-04-27.tar.gz](https://github.com/openrisc/or1ksim/releases/download/2025-04-27/or1ksim-2025-04-27.tar.gz)
18+
We will download these below.
19+
20+
- [or1ksim.cfg](https://github.com/stffrdhrn/or1k-utils/raw/refs/heads/master/or1ksim.cfg) - config needed for or1ksim
21+
- [or1ksim-2025-04-27.tar.gz](https://github.com/openrisc/or1ksim/releases/download/2025-04-27/or1ksim-2025-04-27.tar.gz) - The OpenRISC simulator source code
2022
- [or1k-none-linux-musl-15.1.0-20250621.tar.xz](https://github.com/stffrdhrn/or1k-toolchain-build/releases/download/or1k-15.1.0-20250621/or1k-none-linux-musl-15.1.0-20250621.tar.xz) - OpenRISC musl linux userspace toolchain
2123
- [linux-6.15.5.tar.xz](https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.15.5.tar.xz) - Linux kernel source code
2224
- [busybox-small-rootfs-20250708.tar.xz](https://github.com/stffrdhrn/or1k-rootfs-build/releases/download/or1k-20250708/busybox-small-rootfs-20250708.tar.xz) - Linux rootfs for userspace programs
@@ -34,7 +36,7 @@ provides more accurate tracing.
3436
We break this tutorial down into parts:
3537

3638
- Downloading the pieces
37-
- Comping the kernel
39+
- Compiling the kernel
3840
- Running the kernel
3941
- Interacting with the simulator
4042
- Adding custom userspace programs
@@ -57,6 +59,9 @@ curl -L -O https://github.com/openrisc/or1ksim/releases/download/2025-04-27/or1k
5759
curl -L -O https://github.com/stffrdhrn/or1k-rootfs-build/releases/download/or1k-20250708/busybox-small-rootfs-20250708.tar.xz
5860
curl -L -O https://github.com/stffrdhrn/or1k-toolchain-build/releases/download/or1k-15.1.0-20250621/or1k-none-linux-musl-15.1.0-20250621.tar.xz
5961

62+
# Download an example config for or1ksim
63+
curl -L -O https://github.com/stffrdhrn/or1k-utils/raw/refs/heads/master/or1ksim.cfg
64+
6065
# Extract everything
6166
tar -xf linux-6.15.5.tar.xz
6267
tar -xf or1ksim-2025-04-27.tar.gz
@@ -115,9 +120,6 @@ the system.
115120
#### Terminal 1
116121

117122
```bash
118-
# Download an example config for or1ksim
119-
curl -L -O https://github.com/stffrdhrn/or1k-utils/raw/refs/heads/master/or1ksim.cfg
120-
121123
or1l-elf-sim -f or1ksim.cfg linux-6.15.5/vmlinux
122124
```
123125

or1ksim/index.md

Lines changed: 81 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,98 @@ parent: Platforms
55
nav_order: 2
66
---
77

8-
# Files
8+
# Prerequisites
9+
10+
#### System
11+
12+
- An x86 Linux workstation
13+
- The `curl` and `telnet` command line utilities
14+
15+
#### Files
16+
17+
We will download these below.
918

1019
- [or1ksim.cfg](or1ksim.cfg) - config needed for or1ksim
11-
- [or1ksim-2025-04-27.tar.gz](https://github.com/openrisc/or1ksim/releases/download/2025-04-27/or1ksim-2025-04-27.tar.gz)
20+
- [or1ksim-2025-04-27.tar.gz](https://github.com/openrisc/or1ksim/releases/download/2025-04-27/or1ksim-2025-04-27.tar.gz) - The OpenRISC simulator source code
1221
- [timer.c](./sw/timer/timer.c) - timer program
22+
1323
# or1ksim Tutorial
1424

15-
If you downloaded the tutorials as a release archive, you can directly
16-
start. If you have cloned the git repository, you instead need to
17-
follow the instructions for building the hardware and software as
18-
described below. Please also follow the
19-
[common tutorial setup](../README.md).
25+
The or1ksim program is the OpenRISC [instruction set simulator](https://en.wikipedia.org/wiki/Instruction_set_simulator) which
26+
provides accurate tracing. A simulator is a fast way to debug and ensure
27+
your software works before deploying it to real hardware.
28+
29+
In this tutorial we will cover getting and building or1ksim, and building simple
30+
programs to run on or1ksim.
31+
32+
We break this tutorial down into parts:
33+
34+
- Downloading the pieces
35+
- Compiling a program
36+
- Running a program
37+
- Interacting with the simulator
38+
39+
## Downloading the Pieces
40+
41+
To get started we will create a temporary directly and setup our environment, if
42+
you plan to do a lot of OpenRISC development consider adding these tools to your
43+
`PATH` permanently.
44+
45+
To get everything you need run:
46+
47+
```bash
48+
mkdir /tmp/or1ksim/
49+
cd /tmp/or1ksim/
2050

21-
To run the demo you need:
51+
# Download or1ksim, toolchain and a test project
52+
curl -L -O https://github.com/openrisc/or1ksim/releases/download/2025-04-27/or1ksim-2025-04-27.tar.gz
53+
curl -L -O https://github.com/stffrdhrn/or1k-toolchain-build/releases/download/or1k-15.1.0-20250621/or1k-elf-15.1.0-20250621.tar.xz
2254

23-
* `or1k-sim` in your `PATH`, check with
55+
# Download example programs
56+
curl -L -O https://openrisc.io/tutorials/sw/hello/hello.c
57+
curl -L -O https://openrisc.io/tutorials/sw/timer/timer.c
2458

25-
or1k-sim --version
59+
# Download an example config for or1ksim
60+
curl -L -O https://github.com/stffrdhrn/or1k-utils/raw/refs/heads/master/or1ksim.cfg
61+
62+
# Extract everything
63+
tar -xf or1ksim-2025-04-27.tar.gz
64+
tar -xf or1k-elf-15.1.0-20250621.tar.xz
65+
66+
export PATH=$PATH:$PWD/or1k/bin:$PWD/or1k-elf/bin
67+
```
68+
69+
## Compiling a program
70+
71+
To compile programs for or1ksim we use the newlib baremetal toolchain. Binaries
72+
produced by this can run directly on systems with no Operating System. We use
73+
the `-mboard=` option to provide newlib with the proper options needed to target
74+
or1ksim. This includes RAM size, address loctions for UART and UART baud rates.
75+
76+
```bash
77+
CFLAGS="-mboard=or1ksim-uart"
78+
or1k-elf-gcc -g -Og $CFLAGS -o hello.elf hello.c
79+
or1k-elf-gcc -g -Og $CFLAGS -o timer.elf timer.c
80+
```
2681

2782
## Run hello world
2883

29-
or1k-sim -f or1ksim.cfg hello.elf
84+
To run the demo you need `or1k-elf-sim` in your `PATH`, check with:
85+
86+
```bash
87+
or1k-elf-sim --version
88+
```
89+
90+
We can then run our program with the following:
91+
92+
```bash
93+
or1k-elf-sim -f or1ksim.cfg hello.elf
94+
```
3095

3196
You can find that the last output is `Hello World!`. or1ksim can be
3297
much more verbose and give you a full execution trace:
3398

34-
or1k-sim -f or1ksim.cfg hello.elf -t
99+
or1k-elf-sim -f or1ksim.cfg hello.elf -t
35100

36101
This is of course a lot slower and the simulation exits after a
37102
while. You can finish the simulation before with `CTRL+C`, which will
@@ -40,25 +105,16 @@ command line with `quit`.
40105

41106
## Run the timer example
42107

43-
or1k-sim -f or1ksim.cfg timer.elf
108+
or1k-elf-sim -f or1ksim.cfg timer.elf
44109

45110
In the terminal you can see an UART output every *simulated*
46111
second. You can quit this as described before.
47112

48-
## Boot Linux
49-
50-
You can also boot Linux:
51-
52-
or1k-sim -f or1ksim.cfg ../vmlinux
53-
54-
## (Re-)build the baremetal software
55-
56-
Some example software is available, that you can (re-)build for the
57-
DE0 nano board by running
113+
## Next steps
58114

59-
make build-sw
115+
Also checkout our tutorial on how to run [Linux on or1ksim](../docs/linux-on-or1ksim.html).
60116

61-
## Links
117+
## Further Reading
62118

63119
- [openrisc/or1ksim](https://github.com/openrisc/or1ksim) - The home page and git repo
64120
- [Releases](https://github.com/openrisc/or1ksim/releases) - Nightly build and point release

0 commit comments

Comments
 (0)