Skip to content

Commit d66a750

Browse files
committed
Move to new os-boot with Makefile and CI.
Fix #580 Signed-off-by: Ariel Xiong <ArielHeleneto@outlook.com>
1 parent da6f449 commit d66a750

13 files changed

+163
-225
lines changed

.github/workflows/linux.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Build Linux and openSBI in os-boot
2+
permissions:
3+
id-token: write
4+
attestations: write
5+
contents: read
6+
7+
on:
8+
push:
9+
paths:
10+
- ".github/workflows/linux.yml"
11+
- "os-boot/linux/**"
12+
pull_request:
13+
paths:
14+
- ".github/workflows/linux.yml"
15+
- "os-boot/linux/**"
16+
workflow_dispatch:
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Install packages
23+
run: sudo apt install -y build-essential curl
24+
25+
- name: Check out repository code
26+
uses: actions/checkout@v4
27+
28+
- name: Cache Sources
29+
uses: actions/cache@v4
30+
with:
31+
key: ${{ hashFiles('os-boot/linux/Makefile') }}
32+
path: os-boot/linux/src/*.tar.xz
33+
34+
- name: Make ELF
35+
working-directory: os-boot/linux
36+
run: make -j$(nproc)
37+
38+
- name: Upload ELF
39+
uses: actions/upload-artifact@v4
40+
id: upload
41+
with:
42+
name: os-boot-${{ github.run_id }}
43+
path: os-boot/linux/build/fw_payload.elf
44+
45+
- name: Generate Artifact Attestation
46+
if: github.event_name != 'pull_request'
47+
uses: actions/attest-build-provenance@v2
48+
id: attest
49+
with:
50+
subject-path: os-boot/linux/build/fw_payload.elf
51+
show-summary: false
52+
53+
- name: Upload Paper Work
54+
working-directory: os-boot
55+
env:
56+
ELFURL: ${{ steps.upload.outputs.artifact-url }}
57+
ATTESTURL: ${{ steps.attest.outputs.attestation-url }}
58+
run: |
59+
echo "# os-boot ELF" >> $GITHUB_STEP_SUMMARY
60+
echo "" >> $GITHUB_STEP_SUMMARY
61+
echo "The generated [ELF file]("$ELFURL") can be verified from [here]("$ATTESTURL")." >> $GITHUB_STEP_SUMMARY
62+
echo "" >> $GITHUB_STEP_SUMMARY
63+
echo "## Header" >> $GITHUB_STEP_SUMMARY
64+
echo "" >> $GITHUB_STEP_SUMMARY
65+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
66+
readelf -h linux/build/fw_payload.elf >> $GITHUB_STEP_SUMMARY
67+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
68+
echo "" >> $GITHUB_STEP_SUMMARY

os-boot/README.md

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,22 @@ 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+
## Build your own ELF
1413

15-
```
16-
sudo apt install device-tree-compiler
14+
```bash
15+
make -C os-boot
1716
```
1817

19-
## Booting Linux with the C backend
18+
This will generate `os-boot/build/platform/generic/firmware/fw_payload.elf`.
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+
### Boot ELF
2621

22+
```bash
23+
make sail
2724
```
28-
$ ./c_emulator/riscv_sim_<arch> -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
3825

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.
26+
Use `tail -f /tmp/console.log` to see the terminal log.
4227

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.
28+
### Results
4729

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/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
58-
```
30+
You should see the OpenSBI banner after a few seconds.

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/Makefile

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
.PHONY: clean all dist-clean spike sail qemu
2+
3+
elf := build/fw_payload.elf
4+
5+
all: $(elf)
6+
7+
RISCV_COMPILER_URL ?= https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/2025.01.20/riscv64-glibc-ubuntu-24.04-gcc-nightly-2025.01.20-nightly.tar.xz
8+
LINUX_VERSION ?= 6.14.4
9+
OPENSBI_VERSION ?= 1.6
10+
11+
src/gcc.tar.xz:
12+
mkdir -p src
13+
ifeq (, $(wildcard src/gcc.tar.xz))
14+
curl -L $(RISCV_COMPILER_URL) -o src/gcc.tar.xz
15+
endif
16+
17+
build/riscv/bin/riscv64-unknown-linux-gnu-gcc: src/gcc.tar.xz
18+
mkdir -p build
19+
tar -m -C build -xf src/gcc.tar.xz
20+
21+
src/linux.tar.xz:
22+
mkdir -p src
23+
ifeq (, $(wildcard src/linux.tar.xz))
24+
curl -L https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-$(LINUX_VERSION).tar.xz -o src/linux.tar.xz
25+
endif
26+
27+
build/linux-$(LINUX_VERSION)/Makefile: src/linux.tar.xz
28+
mkdir -p build
29+
tar -m -C build -xf src/linux.tar.xz
30+
31+
src/opensbi.tar.xz:
32+
mkdir -p src
33+
ifeq (, $(wildcard src/opensbi.tar.xz))
34+
curl -L https://github.com/riscv-software-src/opensbi/archive/refs/tags/v$(OPENSBI_VERSION).tar.gz -o src/opensbi.tar.xz
35+
endif
36+
37+
build/opensbi-$(OPENSBI_VERSION)/Makefile: src/opensbi.tar.xz
38+
mkdir -p build
39+
tar -m -C build -xf src/opensbi.tar.xz
40+
41+
CROSS_COMPILE := $(shell pwd)/build/riscv/bin/riscv64-unknown-linux-gnu-
42+
43+
# Number of instructions to run.
44+
LIMIT_INSTRUCTIONS ?= 250000
45+
46+
build/linux-$(LINUX_VERSION)/arch/riscv/boot/Image: build/linux-$(LINUX_VERSION)/Makefile build/riscv/bin/riscv64-unknown-linux-gnu-gcc
47+
$(MAKE) -C build/linux-$(LINUX_VERSION) CROSS_COMPILE=$(CROSS_COMPILE) ARCH=riscv defconfig
48+
$(MAKE) -C build/linux-$(LINUX_VERSION) CROSS_COMPILE=$(CROSS_COMPILE) CONFIG_HVC_RISCV_SBI=y ARCH=riscv Image
49+
50+
# FW_TEXT_START is 0 by default which doesn't leave space for the emulator bootloader.
51+
# 0x80000000 is the default start of Spike's memory.
52+
build/opensbi-$(OPENSBI_VERSION)/build/platform/generic/firmware/fw_payload.elf: build/opensbi-$(OPENSBI_VERSION)/Makefile build/linux-$(LINUX_VERSION)/arch/riscv/boot/Image build/riscv/bin/riscv64-unknown-linux-gnu-gcc
53+
$(MAKE) -C build/opensbi-$(OPENSBI_VERSION) FW_TEXT_START=0x80000000 FW_PAYLOAD=y FW_PAYLOAD_PATH=../linux-$(LINUX_VERSION)/arch/riscv/boot/Image PLATFORM=generic CROSS_COMPILE=$(CROSS_COMPILE)
54+
55+
$(elf): build/opensbi-$(OPENSBI_VERSION)/build/platform/generic/firmware/fw_payload.elf
56+
cp build/opensbi-$(OPENSBI_VERSION)/build/platform/generic/firmware/fw_payload.elf $(elf)
57+
58+
sail.dtb: sail.dts
59+
dtc < sail.dts -o sail.dtb
60+
61+
spike: $(elf)
62+
spike --instructions=$(LIMIT_INSTRUCTIONS) $(elf)
63+
64+
# Run on Sail.
65+
sail: sail.dtb $(elf)
66+
../../build/c_emulator/riscv_sim_rv64d --no-trace -p -l $(LIMIT_INSTRUCTIONS) --device-tree-blob sail.dtb -t /dev/stdout $(elf)
67+
68+
qemu: $(elf)
69+
qemu-system-riscv64 -M virt -m 256M -nographic -bios $(elf)
70+
71+
clean:
72+
rm -rf build
73+
rm -f sail.dtb
74+
75+
dist-clean:
76+
rm -rf build
77+
rm -f sail.dtb
78+
rm -rf src
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/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.

0 commit comments

Comments
 (0)