Skip to content

Commit 6c44fbf

Browse files
author
Tim Hutt
committed
Update Linux image
1 parent e1fedba commit 6c44fbf

15 files changed

+119
-229
lines changed

os-boot/README.md

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,21 @@
11
# Booting OS images
22

3-
The Sail model implements a very simple platform based on the one
4-
implemented by the Spike reference simulator. It implements a console
5-
output port similar to Spike's HTIF (host-target interface) mechanism,
6-
and an interrupt controller based on Spike's CLINT (core-local
7-
interrupt controller). Console input is not currently supported.
3+
The Sail model implements a very simple platform based on the one implemented by the Spike reference simulator. It implements Spike's HTIF (Host-Target Interface) which allows console output, and an interrupt controller based on Spike's CLINT (core-local interrupt controller). Console input is not currently supported.
84

9-
32-bit OS boots require a workaround for the 64-bit HTIF interface,
10-
which is currently not supported.
5+
32-bit OS boots require a workaround for the 64-bit HTIF interface, which is currently not supported.
116

12-
OS boots use device-tree binary blobs generated by the `dtc` compiler,
13-
installable on Ubuntu and Debian machines with
7+
## Build your own ELF
148

15-
```
16-
sudo apt install device-tree-compiler
9+
```bash
10+
make -C linux -j4
1711
```
1812

19-
## Booting Linux with the C backend
13+
This will generate `os-boot/linux/build/fw_payload.elf`.
2014

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:
15+
### Boot ELF
2616

17+
```bash
18+
make -C linux sail
2719
```
28-
$ ./c_emulator/sail_riscv_sim -t console.log -b spike.dtb bbl > execution-trace.log 2>&1 &
29-
$ tail -f console.log
30-
```
31-
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.
36-
37-
## Caveats for OS boot
38-
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.
4220

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.
47-
48-
## Sample Linux image
49-
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`:
53-
54-
```
55-
dtc < os-boot/rv64-64mb.dts > os-boot/rv64-64mb.dtb
56-
./c_emulator/sail_riscv_sim -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
58-
```
21+
You should see the OpenSBI banner after a few seconds. Eventually it will crash when it fails to find an `init` process which the image does not currently include.

os-boot/freebsd-rv64.bbl

-23 MB
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/linux/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/build
2+
/downloads

os-boot/linux/Makefile

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
##### Compilation #####
2+
3+
RISCV_COMPILER_PREFIX := riscv64-buildroot-linux-gnu-
4+
5+
# This is the final bootable OpenSBI + Linux image.
6+
elf := build/fw_payload.elf
7+
8+
.PHONY: all
9+
all: $(elf)
10+
11+
# Generic rule to download tools.
12+
downloads/%.tar.xz: %.url
13+
mkdir -p downloads
14+
curl --location '$(shell cat $<)' --output $@
15+
16+
# Rules to extract tools. For simplicity we strip the first directory component because it varies.
17+
build/gcc/bin/$(RISCV_COMPILER_PREFIX)gcc: downloads/gcc.tar.xz
18+
mkdir -p build/gcc
19+
tar --touch --directory build/gcc --strip-components=1 --extract --file downloads/gcc.tar.xz
20+
21+
build/linux/Makefile: downloads/linux.tar.xz
22+
mkdir -p build/linux
23+
tar --touch --directory build/linux --strip-components=1 --extract --file downloads/linux.tar.xz
24+
25+
build/opensbi/Makefile: downloads/opensbi.tar.xz
26+
mkdir -p build/opensbi
27+
tar --touch --directory build/opensbi --strip-components=1 --extract --file downloads/opensbi.tar.xz
28+
29+
CROSS_COMPILE := $(shell pwd)/build/gcc/bin/$(RISCV_COMPILER_PREFIX)
30+
31+
# Rule to build the Linux kernel.
32+
build/linux/arch/riscv/boot/Image: build/linux/Makefile build/gcc/bin/$(RISCV_COMPILER_PREFIX)gcc
33+
$(MAKE) -C build/linux CROSS_COMPILE=$(CROSS_COMPILE) ARCH=riscv defconfig
34+
$(MAKE) -C build/linux CROSS_COMPILE=$(CROSS_COMPILE) CONFIG_HVC_RISCV_SBI=y ARCH=riscv Image
35+
36+
# Rule to build OpenSBI, with the Linux kernel embedded in it.
37+
#
38+
# FW_TEXT_START is 0 by default which doesn't leave space for the emulator bootloader.
39+
# 0x80000000 is the default start of Spike's memory.
40+
$(elf): build/opensbi/Makefile build/linux/arch/riscv/boot/Image build/gcc/bin/$(RISCV_COMPILER_PREFIX)gcc
41+
$(MAKE) -C build/opensbi FW_TEXT_START=0x80000000 FW_PAYLOAD=y FW_PAYLOAD_PATH=../linux/arch/riscv/boot/Image PLATFORM=generic CROSS_COMPILE=$(CROSS_COMPILE)
42+
cp build/opensbi/build/platform/generic/firmware/fw_payload.elf $(elf)
43+
44+
# Path to Sail emulator.
45+
SAIL_SIM ?= ../../build/c_emulator/sail_riscv_sim
46+
47+
build/sail.dts: $(SAIL_SIM)
48+
mkdir -p build
49+
$(SAIL_SIM) --print-device-tree >$@
50+
51+
build/sail.dtb: build/sail.dts
52+
mkdir -p build
53+
dtc $< -o $@
54+
55+
.PHONY: clean
56+
clean:
57+
rm -rf build
58+
59+
.PHONY: distclean
60+
distclean:
61+
rm -rf build
62+
rm -rf downloads
63+
64+
##### Running #####
65+
66+
# Number of instructions to run. The image does not include userspace; there
67+
# is no 'init' available, so it will crash at that point. It takes about
68+
# 200 million instructions to get to that point. Execution speed is around
69+
# 300 kIPS so it takes around 10 minutes. Spike and QEMU are much faster.
70+
LIMIT_INSTRUCTIONS := 20000000
71+
72+
# Run with the Sail emulator from this repo.
73+
.PHONY: sail
74+
sail: build/sail.dtb $(elf) $(SAIL_SIM)
75+
$(SAIL_SIM) --no-trace -p -l $(LIMIT_INSTRUCTIONS) --device-tree-blob build/sail.dtb $(elf)
76+
77+
# Run the profiler. This requires gperftools and pprof:
78+
#
79+
# git clone https://github.com/gperftools/gperftools
80+
# cd gperftools
81+
# # There's CMake support but unfortunately it's broken.
82+
# # See https://github.com/gperftools/gperftools/issues/1576
83+
# ./autogen.sh
84+
# ./configure
85+
# make -j4
86+
# sudo make install
87+
#
88+
# go install github.com/google/pprof@latest
89+
#
90+
.PHONY: sail_profile
91+
sail_profile: build/sail.dtb $(elf) $(SAIL_SIM)
92+
rm -f build/prof.out
93+
CPUPROFILE=build/prof.out LD_PRELOAD=/usr/local/lib/libtcmalloc_and_profiler.so $(SAIL_SIM) --no-trace -p -l 2000000 --device-tree-blob build/sail.dtb $(elf)
94+
pprof -http : build/prof.out
95+
96+
# Run with Spike: https://github.com/riscv-software-src/riscv-isa-sim
97+
.PHONY: spike
98+
spike: $(elf)
99+
spike --instructions=$(LIMIT_INSTRUCTIONS) $(elf)
100+
101+
# Run with QEMU.
102+
.PHONY: qemu
103+
qemu: $(elf)
104+
qemu-system-riscv64 -M virt -m 256M -nographic -bios $(elf)

os-boot/linux/gcc.url

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://toolchains.bootlin.com/downloads/releases/toolchains/riscv64-lp64d/tarballs/riscv64-lp64d--glibc--stable-2024.05-1.tar.xz

os-boot/linux/linux.url

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.14.4.tar.xz

os-boot/linux/opensbi.url

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/riscv-software-src/opensbi/archive/refs/tags/v1.6.tar.gz

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

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

0 commit comments

Comments
 (0)