You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -16,7 +16,7 @@ into our Linux on OpenRISC tutorials. We will cover:
16
16
* Boot loaders - we need to get Linux onto the system, we will explain how this
17
17
is done.
18
18
* Device tree - how does Linux know what hardware is available in the system
19
-
* Toolchains - We covered this before, but a quick refresher on linux
19
+
* Toolchains - We covered this before, but a quick refresher on Linux
20
20
specific toolchains
21
21
* Rootfs - Applications
22
22
* Memory layout - we explain how devices, Linux and our user processes
@@ -32,32 +32,38 @@ If you wish to skip this you can continue directly with our tutorials:
32
32
33
33
### Boot loaders
34
34
35
-
The job of the [boot loader](https://en.wikipedia.org/wiki/Bootloader) is to prepare the operating system to boot
36
-
and then boot it. In the most simple sense this means loading the operating system kernel into memory and then
37
-
jumping to the entry point. Traditionally the popular Linux boot loader is [GRUB](https://www.gnu.org/software/grub/).
38
-
However, on embedded Linux platforms like OpenRISC Linux more simple loaders are used. These include:
35
+
The job of the [boot loader](https://en.wikipedia.org/wiki/Bootloader) is to
36
+
prepare the operating system to boot and then boot it. In the most simple sense
37
+
this means loading the operating system kernel into memory and then jumping to
38
+
the entry point. Traditionally the popular Linux boot loader is
39
+
[GRUB](https://www.gnu.org/software/grub/). However, on embedded Linux
40
+
platforms like OpenRISC Linux more simple loaders are used. These include:
39
41
40
42
- For Simulators - or1ksim and QEMU provide built in boot loaders
41
43
- FPGA Boards - For larger FPGA boards with litex support we use the litex bios
42
44
- Tiny FPGA Boards - For tiny FPGA boards we use GDB as a simple boot loader
43
45
44
-
Simulators like `or1ksim` and `QEMU` have the ability to be passed a kernel ELF image from the command
45
-
line. When the simulator is initialized they can read the ELF binary and load the bits directly into the simulator memory.
46
-
In `QEMU` it will additionally generate and load a device tree to describe to the kernel what hardware
47
-
is available, dynamically. After the system and memory are initialized the simulator CPU will jump to `0x100`
48
-
the entry point of the OpenRISC platform.
49
-
50
-
On typical FPGA boards there is storage available to store a bootloader and devices available to store the operating system.
51
-
For example on the [Digilent Arty](https://digilent.com/shop/arty-a7-100t-artix-7-fpga-development-board/) when
52
-
the FPGA bitstream is programmed a ROM is programmed with the [litex bios](https://github.com/enjoy-digital/litex/blob/master/litex/soc/software/bios/main.c).
53
-
This firmware plus boot loader will train DDR3 RAM before loading and jumping to the kernel entry point.
54
-
The litex bios can load the operating system from an SD-card or from TFTP over a network connection.
55
-
56
-
On very Tiny FPGA boards like a base De0 Nano lacking non-volatile storage,
57
-
there is no means to load an OS via SD-card or network. We use GDB, a debugger
46
+
Simulators like `or1ksim` and `QEMU` have the ability to be passed a kernel ELF
47
+
image from the command line. When the simulator is initialized they will read
48
+
the ELF binary and load the binary content directly into the simulator memory.
49
+
In `QEMU` it will additionally generate and load a device tree to describe to
50
+
the kernel what hardware is available, dynamically. After the system and memory
51
+
are initialized the simulator CPU will jump to `0x100` the entry point of the
52
+
OpenRISC platform.
53
+
54
+
On typical FPGA boards there is storage available to store a bootloader and
55
+
devices available to store the operating system. For example on the [Digilent Arty](https://digilent.com/shop/arty-a7-100t-artix-7-fpga-development-board/)
56
+
when the FPGA bitstream is programmed a ROM is programmed with the [litex bios](https://github.com/enjoy-digital/litex/blob/master/litex/soc/software/bios/main.c).
57
+
This firmware plus boot loader will train DDR3 RAM before loading and jumping to
58
+
the kernel entry point. The litex bios can load the operating system from an
59
+
SD-card or from TFTP over a network connection.
60
+
61
+
On very tiny FPGA boards like a base De0 Nano lacking non-volatile storage,
62
+
there may be no means to load an OS via SD-card or network. We use GDB, a debugger
58
63
typically used to read and write CPU and memory state. We can leverage this to
59
-
load ELF kernel images into memory over the JTAG debug interface. Once, memory
64
+
load ELF kernel images into memory over a JTAG debug interface. Once, memory
60
65
is loaded we can reset the CPU to have it jump to `0x100` and boot the kernel.
66
+
Address `0x100` is the OpenRISC default reset vector.
61
67
62
68
### Device tree
63
69
@@ -69,13 +75,14 @@ a boot parameter via register `r3`.
69
75
70
76
The below is a very simple device tree source file describing an OpenRISC system
71
77
with:
78
+
72
79
- 1 CPU
73
80
- 1 UART at 0x90000000
74
81
- 32 MB main memory at address 0x0
75
82
- 20 Mhz clock
76
83
77
84
The device tree will be compiled down to a `.dtb` binary file using the device
78
-
tree compiler (`dtc`) durig the build processes. During the boot process the
85
+
tree compiler (`dtc`) during the build processes. During the boot process the
79
86
kernel uses the device tree definitions to initialize devices and memory.
80
87
81
88
```
@@ -128,8 +135,9 @@ kernel uses the device tree definitions to initialize devices and memory.
128
135
129
136
To compile the Linux kernel itself the toolchain used is not very important,
130
137
as the kernel doesn't depend on any toolchain runtime features. You can use
131
-
any toolchain to build the kernel.
132
-
However, if you want to build userspace applications choosing the correct
138
+
any toolchain to build the kernel, as long as it is a recent OpenRISC
139
+
toolchain.
140
+
However, if you want to build user space applications choosing the correct
133
141
toolchain requires some thought. The main choices are:
134
142
135
143
-[musl](../musl.html) - A lightweight and efficient toolchain
@@ -141,104 +149,98 @@ runtime installed.
141
149
142
150
### Rootfs
143
151
144
-
The rootfs is like the Linux distribution for an embedded linux.
152
+
The rootfs is like the Linux distribution for an embedded Linux.
145
153
146
154
We provide some [prebuilt rootfs images](https://github.com/stffrdhrn/or1k-rootfs-build) to
147
-
help get you started. The main choices are:
155
+
help get you started. The top choices are:
148
156
149
157
- buildroot - a fully featured rootfs ideal for boards with and sd-card, with
150
-
well known utilties like `bash`.
151
-
- busybox - a lightweight single binary rootfs, comming in at under 3MB
158
+
well known utilities like `bash`.
159
+
- busybox - a lightweight single binary rootfs, coming in at under 3MB
152
160
153
161
### Memory Layout
154
162
155
163
The OpenRISC is able to address up to 32-bits of address space giving us up
156
164
to 4GB of addressable memory. The space is shared between user space, the
157
-
kernel and hardware devices.
165
+
kernel and hardware devices. Memory protection between processes is achieved
166
+
using the OpenRISC memory management unit **MMU**.
158
167
159
-
Paging
168
+
The OpenRISC MMU uses 8KB (13-bits) pages leaving the most significant 19-bits
169
+
for indexing into a software page table. The architecture uses a 2-level [page table](linux/mm/page_tables.rst)
170
+
using 8-bits to index a 256 entry page directory and 11-bits to index 2048 page table entry leaf nodes.
160
171
161
-
Openrisc uses 2-level paging
172
+
The **page global directory** or **pgd** looks like the following in OpenRISC:
162
173
163
174
```
164
-
_ 11 bits for pte offset
165
-
/
166
-
| __-- 13 bit pages
167
-
|/ \
168
-
| |
169
-
/ \ |
170
-
0xfffe0000
171
-
\/
172
-
\_ top 8 bit used for pgd
173
-
174
-
175
+
PGD (256 entries)
176
+
177
+
--> +-----+ PTE (2048 entries)
178
+
| ptr |-------> +-----+
179
+
| ptr |- | ptr |-------> PAGE
180
+
| ptr | \ | ptr |
181
+
| ptr | \ ...
182
+
| ... | \
183
+
| ptr | \ PTE
184
+
+-----+ +----> +-----+
185
+
| ptr |-------> PAGE
186
+
| ptr |
187
+
...
188
+
189
+
PMD, PUD and P4D are folded up on OpenRISC
175
190
```
176
191
177
-
Notes for or1k PGD
192
+
Virtual address bits are used to index into the page table
193
+
and derive the physical address as below:
178
194
179
195
```
180
-
PGD - dir top 8 bits - 256 enties pgd_offset
181
-
PMD - mid 1
182
-
PTE - entry least sig 11 bits of page - 2048 entries in PTE page
0 commit comments