Skip to content

Commit 560fc8b

Browse files
ArielfoeverTimmmm
andcommitted
Move to new os-boot.
Fix riscv#580 Signed-off-by: Ariel Xiong <ArielHeleneto@outlook.com> Co-authored-by: Tim Hutt <tdhutt@gmail.com>
1 parent 5872942 commit 560fc8b

11 files changed

+126
-219
lines changed

os-boot/README.md

Lines changed: 119 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,137 @@ interrupt controller). Console input is not currently supported.
99
32-bit OS boots require a workaround for the 64-bit HTIF interface,
1010
which is currently not supported.
1111

12-
OS boots use device-tree binary blobs generated by the `dtc` compiler,
13-
installable on Ubuntu and Debian machines with
12+
## Boot with prebuild ELF
1413

15-
```
16-
sudo apt install device-tree-compiler
17-
```
14+
This ELF is built with these materials.
1815

19-
## Booting Linux with the C backend
16+
- [Linux 6.14.4](https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.14.4.tar.xz)
17+
- [riscv-collab/riscv-gnu-toolchain](https://github.com/riscv-collab/riscv-gnu-toolchain/commit/d0193d173cb43468b1ddf3f3a4ea57950b4a4a8c)
18+
- [riscv-software-src/opensbi](https://github.com/riscv-software-src/opensbi/commit/99aabc6b8431a2bcf2b28a2423952e529de9fbc5)
2019

21-
The C model needs an ELF-version of the BBL (Berkeley-Boot-Loader)
22-
that contains the Linux kernel as an embedded payload. It also needs
23-
a DTB (device-tree blob) file describing the platform (say in the file
24-
`spike.dtb`). Once those are available (see below for suggestions),
25-
the model should be run as:
20+
### Build dtb
2621

22+
```bash
23+
dtc < sos-boot/ail.dts > os-boot/sail.dtb
2724
```
28-
$ ./c_emulator/riscv_sim_<arch> -t console.log -b spike.dtb bbl > execution-trace.log 2>&1 &
29-
$ tail -f console.log
25+
26+
### Boot ELF
27+
28+
```bash
29+
build/c_emulator/riscv_sim_rv64d -t /tmp/console.log --no-trace -p --device-tree-blob os-boot/sail.dtb os-boot/fw_payload.elf
3030
```
3131

32-
The `console.log` file contains the console boot messages. For maximum
33-
performance and benchmarking a model without any execution tracing is
34-
available on the optimize branch (`git checkout optimize`) of this
35-
repository. This currently requires the latest Sail built from source.
32+
Use `tail -f /tmp/console.log` to see the terminal log.
33+
34+
### Results
35+
36+
```log
37+
[ariel@archlinux sail-riscv]$ cat /tmp/console.log
3638
37-
## Caveats for OS boot
39+
OpenSBI v1.6
40+
____ _____ ____ _____
41+
/ __ \ / ____| _ \_ _|
42+
| | | |_ __ ___ _ __ | (___ | |_) || |
43+
| | | | '_ \ / _ \ '_ \ \___ \| _ < | |
44+
| |__| | |_) | __/ | | |____) | |_) || |_
45+
\____/| .__/ \___|_| |_|_____/|____/_____|
46+
| |
47+
|_|
3848
39-
- Some OS toolchains generate obsolete LR/SC instructions with now
40-
illegal combinations of `.aq` and `.rl` flags. You can work-around
41-
this by changing `riscv_mem.sail` to accept these flags.
49+
Platform Name : ucbbar,spike-bare
50+
Platform Features : medeleg
51+
Platform HART Count : 1
52+
Platform IPI Device : aclint-mswi
53+
Platform Timer Device : aclint-mtimer @ 10000000Hz
54+
Platform Console Device : htif
55+
Platform HSM Device : ---
56+
Platform PMU Device : ---
57+
Platform Reboot Device : htif
58+
Platform Shutdown Device : htif
59+
Platform Suspend Device : ---
60+
Platform CPPC Device : ---
61+
Firmware Base : 0x80000000
62+
Firmware Size : 317 KB
63+
Firmware RW Offset : 0x40000
64+
Firmware RW Size : 61 KB
65+
Firmware Heap Offset : 0x46000
66+
Firmware Heap Size : 37 KB (total), 2 KB (reserved), 11 KB (used), 23 KB (free)
67+
Firmware Scratch Size : 4096 B (total), 392 B (used), 3704 B (free)
68+
Runtime SBI Version : 2.0
69+
Standard SBI Extensions : time,rfnc,ipi,base,hsm,srst,pmu,dbcn,legacy
70+
Experimental SBI Extensions : fwft,sse
4271
43-
- One needs to manually ensure that the DTB used for the C model
44-
accurately describes the physical memory map implemented in the C
45-
platform. This will not be needed once the C model can generate its
46-
own DTB.
72+
Domain0 Name : root
73+
Domain0 Boot HART : 0
74+
Domain0 HARTs : 0*
75+
Domain0 Region00 : 0x0000000000000000-0x0000000000000fff M: (I,R,W) S/U: (R,W)
76+
Domain0 Region01 : 0x0000000080040000-0x000000008004ffff M: (R,W) S/U: ()
77+
Domain0 Region02 : 0x0000000002080000-0x00000000020bffff M: (I,R,W) S/U: ()
78+
Domain0 Region03 : 0x0000000080000000-0x000000008003ffff M: (R,X) S/U: ()
79+
Domain0 Region04 : 0x0000000002000000-0x000000000207ffff M: (I,R,W) S/U: ()
80+
Domain0 Region05 : 0x0000000000000000-0xffffffffffffffff M: () S/U: (R,W,X)
81+
Domain0 Next Address : 0x0000000080200000
82+
Domain0 Next Arg1 : 0x0000000082200000
83+
Domain0 Next Mode : S-mode
84+
Domain0 SysReset : yes
85+
Domain0 SysSuspend : yes
4786
48-
## Sample Linux image
87+
Boot HART ID : 0
88+
Boot HART Domain : root
89+
Boot HART Priv Version : v1.12
90+
Boot HART Base ISA : rv64imafdcbv
91+
Boot HART ISA Extensions : sscofpmf,zicntr,zihpm,smcntrpmf,sdtrig
92+
Boot HART PMP Count : 16
93+
Boot HART PMP Granularity : 2 bits
94+
Boot HART PMP Address Bits : 54
95+
Boot HART MHPM Info : 29 (0xfffffff8)
96+
Boot HART Debug Triggers : 0 triggers
97+
Boot HART MIDELEG : 0x0000000000002222
98+
Boot HART MEDELEG : 0x000000000004b109
99+
[ 0.000000] Linux version 6.14.4 (ariel@archlinux) (riscv64-unknown-linux-gnu-gcc (g04696df09) 14.2.0, GNU ld (GNU Binutils) 2.44) #1 SMP Sat Apr 26 14:42:54 CST 2025
100+
[ 0.000000] Machine model: ucbbar,spike-bare
101+
[ 0.000000] SBI specification v2.0 detected
102+
[ 0.000000] SBI implementation ID=0x1 Version=0x10006
103+
[ 0.000000] SBI TIME extension detected
104+
[ 0.000000] SBI IPI extension detected
105+
[ 0.000000] SBI RFENCE extension detected
106+
[ 0.000000] SBI SRST extension detected
107+
[ 0.000000] SBI DBCN extension detected
108+
[ 0.000000] earlycon: sbi0 at I/O port 0x0 (options '')
109+
[ 0.000000] printk: legacy bootconsole [sbi0] enabled
110+
[ 0.000000] efi: UEFI not found.
111+
[ 0.000000] OF: reserved mem: 0x0000000080000000..0x000000008003ffff (256 KiB) nomap non-reusable mmode_resv1@80000000
112+
[ 0.000000] OF: reserved mem: 0x0000000080040000..0x000000008004ffff (64 KiB) nomap non-reusable mmode_resv0@80040000
113+
[ 0.000000] Zone ranges:
114+
[ 0.000000] DMA32 [mem 0x0000000080000000-0x00000000ffffffff]
115+
[ 0.000000] Normal empty
116+
[ 0.000000] Movable zone start for each node
117+
[ 0.000000] Early memory node ranges
118+
[ 0.000000] node 0: [mem 0x0000000080000000-0x000000008004ffff]
119+
[ 0.000000] node 0: [mem 0x0000000080050000-0x00000000ffffffff]
120+
[ 0.000000] Initmem setup node 0 [mem 0x0000000080000000-0x00000000ffffffff]
121+
```
122+
123+
## Build your own ELF
49124

50-
`rv64-linux-4.15.0-gcc-7.2.0-64mb.bbl` contains a sample Linux RV64
51-
image that can be booted as follows, after first generating the
52-
device-tree blob for a 64MB RV64 machine using `dtc`:
125+
### Build Kernel Image
53126

127+
```bash
128+
wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.14.4.tar.xz
129+
tar -xzf linux-6.14.4.tar.xz
130+
cd linux-6.14.4
131+
make ARCH=riscv CROSS_COMPILE=../toolchain/riscv64-unknown-linux-gnu- defconfig
132+
make ARCH=riscv CROSS_COMPILE=../toolchain/riscv64-unknown-linux-gnu- Image vmlinux
54133
```
55-
dtc < os-boot/rv64-64mb.dts > os-boot/rv64-64mb.dtb
56-
./c_emulator/riscv_sim_RV64 -b os-boot/rv64-64mb.dtb -t /tmp/console.log os-boot/rv64-linux-4.15.0-gcc-7.2.0-64mb.bbl > >(gzip -c > execution-trace.log.gz) 2>&1
57-
tail -f /tmp/console.log
134+
135+
This will generate `arch/riscv/boot/Image` which will be a part of payload.
136+
137+
### Build openSBI
138+
139+
```bash
140+
git clone https://github.com/riscv-software-src/opensbi --depth=1
141+
cd opensbi
142+
make FW_TEXT_START=0x80000000 FW_PAYLOAD=y FW_PAYLOAD_PATH=../linux-6.14.4/arch/riscv/boot/Image CROSS_COMPILE=../toolchain/riscv64-unknown-linux-gnu- PLATFORM=generic
58143
```
144+
145+
This will generate `build/platform/generic/firmware/fw_payload.elf`.
Binary file not shown.

os-boot/image-notes.txt

Lines changed: 0 additions & 39 deletions
This file was deleted.

os-boot/linux-rv64-64mb.bbl

-9.26 MB
Binary file not shown.

os-boot/os-boot-patch.diff

Lines changed: 0 additions & 49 deletions
This file was deleted.

os-boot/rv64-2gb-hafnium.dts

Lines changed: 0 additions & 53 deletions
This file was deleted.

os-boot/rv64-64mb.dts

Lines changed: 0 additions & 45 deletions
This file was deleted.
Binary file not shown.
-9.58 MB
Binary file not shown.

os-boot/rv64-2gb.dts renamed to os-boot/sail.dts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#size-cells = <2>;
66
compatible = "ucbbar,spike-bare-dev";
77
model = "ucbbar,spike-bare";
8+
chosen {
9+
bootargs = "console=hvc0 earlycon=sbi";
10+
};
811
cpus {
912
#address-cells = <1>;
1013
#size-cells = <0>;
@@ -14,10 +17,13 @@
1417
reg = <0>;
1518
status = "okay";
1619
compatible = "riscv";
17-
riscv,isa = "rv64imac";
20+
riscv,isa = "rv64imafd";
1821
mmu-type = "riscv,sv39";
22+
riscv,pmpregions = <16>;
23+
riscv,pmpgranularity = <4>;
1924
clock-frequency = <1000000000>;
2025
CPU0_intc: interrupt-controller {
26+
#address-cells = <2>;
2127
#interrupt-cells = <1>;
2228
interrupt-controller;
2329
compatible = "riscv,cpu-intc";

os-boot/sel4-rv64.bbl

-9.24 MB
Binary file not shown.

0 commit comments

Comments
 (0)