Skip to content

Commit 5e26b6e

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

13 files changed

+232
-220
lines changed

.github/workflows/os-boot.yml

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

os-boot/Makefile

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

os-boot/README.md

Lines changed: 90 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,107 @@ 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

27-
```
28-
$ ./c_emulator/riscv_sim_<arch> -t console.log -b spike.dtb bbl > execution-trace.log 2>&1 &
29-
$ tail -f console.log
22+
```bash
23+
make sail
3024
```
3125

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

37-
## Caveats for OS boot
28+
### Results
3829

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.
30+
```log
31+
[ariel@archlinux sail-riscv]$ cat /tmp/console.log
4232
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.
33+
OpenSBI v1.6
34+
____ _____ ____ _____
35+
/ __ \ / ____| _ \_ _|
36+
| | | |_ __ ___ _ __ | (___ | |_) || |
37+
| | | | '_ \ / _ \ '_ \ \___ \| _ < | |
38+
| |__| | |_) | __/ | | |____) | |_) || |_
39+
\____/| .__/ \___|_| |_|_____/|____/_____|
40+
| |
41+
|_|
4742
48-
## Sample Linux image
43+
Platform Name : ucbbar,spike-bare
44+
Platform Features : medeleg
45+
Platform HART Count : 1
46+
Platform IPI Device : aclint-mswi
47+
Platform Timer Device : aclint-mtimer @ 10000000Hz
48+
Platform Console Device : htif
49+
Platform HSM Device : ---
50+
Platform PMU Device : ---
51+
Platform Reboot Device : htif
52+
Platform Shutdown Device : htif
53+
Platform Suspend Device : ---
54+
Platform CPPC Device : ---
55+
Firmware Base : 0x80000000
56+
Firmware Size : 317 KB
57+
Firmware RW Offset : 0x40000
58+
Firmware RW Size : 61 KB
59+
Firmware Heap Offset : 0x46000
60+
Firmware Heap Size : 37 KB (total), 2 KB (reserved), 11 KB (used), 23 KB (free)
61+
Firmware Scratch Size : 4096 B (total), 392 B (used), 3704 B (free)
62+
Runtime SBI Version : 2.0
63+
Standard SBI Extensions : time,rfnc,ipi,base,hsm,srst,pmu,dbcn,legacy
64+
Experimental SBI Extensions : fwft,sse
4965
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`:
66+
Domain0 Name : root
67+
Domain0 Boot HART : 0
68+
Domain0 HARTs : 0*
69+
Domain0 Region00 : 0x0000000000000000-0x0000000000000fff M: (I,R,W) S/U: (R,W)
70+
Domain0 Region01 : 0x0000000080040000-0x000000008004ffff M: (R,W) S/U: ()
71+
Domain0 Region02 : 0x0000000002080000-0x00000000020bffff M: (I,R,W) S/U: ()
72+
Domain0 Region03 : 0x0000000080000000-0x000000008003ffff M: (R,X) S/U: ()
73+
Domain0 Region04 : 0x0000000002000000-0x000000000207ffff M: (I,R,W) S/U: ()
74+
Domain0 Region05 : 0x0000000000000000-0xffffffffffffffff M: () S/U: (R,W,X)
75+
Domain0 Next Address : 0x0000000080200000
76+
Domain0 Next Arg1 : 0x0000000082200000
77+
Domain0 Next Mode : S-mode
78+
Domain0 SysReset : yes
79+
Domain0 SysSuspend : yes
5380
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
81+
Boot HART ID : 0
82+
Boot HART Domain : root
83+
Boot HART Priv Version : v1.12
84+
Boot HART Base ISA : rv64imafdcbv
85+
Boot HART ISA Extensions : sscofpmf,zicntr,zihpm,smcntrpmf,sdtrig
86+
Boot HART PMP Count : 16
87+
Boot HART PMP Granularity : 2 bits
88+
Boot HART PMP Address Bits : 54
89+
Boot HART MHPM Info : 29 (0xfffffff8)
90+
Boot HART Debug Triggers : 0 triggers
91+
Boot HART MIDELEG : 0x0000000000002222
92+
Boot HART MEDELEG : 0x000000000004b109
93+
[ 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
94+
[ 0.000000] Machine model: ucbbar,spike-bare
95+
[ 0.000000] SBI specification v2.0 detected
96+
[ 0.000000] SBI implementation ID=0x1 Version=0x10006
97+
[ 0.000000] SBI TIME extension detected
98+
[ 0.000000] SBI IPI extension detected
99+
[ 0.000000] SBI RFENCE extension detected
100+
[ 0.000000] SBI SRST extension detected
101+
[ 0.000000] SBI DBCN extension detected
102+
[ 0.000000] earlycon: sbi0 at I/O port 0x0 (options '')
103+
[ 0.000000] printk: legacy bootconsole [sbi0] enabled
104+
[ 0.000000] efi: UEFI not found.
105+
[ 0.000000] OF: reserved mem: 0x0000000080000000..0x000000008003ffff (256 KiB) nomap non-reusable mmode_resv1@80000000
106+
[ 0.000000] OF: reserved mem: 0x0000000080040000..0x000000008004ffff (64 KiB) nomap non-reusable mmode_resv0@80040000
107+
[ 0.000000] Zone ranges:
108+
[ 0.000000] DMA32 [mem 0x0000000080000000-0x00000000ffffffff]
109+
[ 0.000000] Normal empty
110+
[ 0.000000] Movable zone start for each node
111+
[ 0.000000] Early memory node ranges
112+
[ 0.000000] node 0: [mem 0x0000000080000000-0x000000008004ffff]
113+
[ 0.000000] node 0: [mem 0x0000000080050000-0x00000000ffffffff]
114+
[ 0.000000] Initmem setup node 0 [mem 0x0000000080000000-0x00000000ffffffff]
58115
```

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/os-boot-patch.diff

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

0 commit comments

Comments
 (0)