Skip to content

Commit 9a7f7e2

Browse files
committed
os-boot: Add Makefile and CI.
1 parent 3f12183 commit 9a7f7e2

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed

.github/workflows/os-boot.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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/ob-boot.yml'
11+
pull_request:
12+
paths:
13+
- '.github/workflows/ob-boot.yml'
14+
workflow_dispatch:
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-22.04
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: Generate SBOM attestation
35+
uses: actions/attest-sbom@v1
36+
with:
37+
subject-path: 'build/fw_payload.elf'
38+
sbom-path: 'SBOM.sha256'
39+
40+
- name: Upload ELF
41+
uses: actions/upload-artifact@v4
42+
id: upload
43+
with:
44+
name: os-boot-${{ github.run_id }}
45+
path: build/fw_payload.elf
46+
47+
- name: Generate artifact attestation
48+
uses: actions/attest-build-provenance@v2
49+
id: attest
50+
with:
51+
subject-path: build/fw_payload.elf
52+
subject-digest: sha256:${{ steps.upload.outputs.artifact-digest }}
53+
54+
- name: Upload Paper Work
55+
working-directory: os-boot
56+
env:
57+
ELFURL: ${{ steps.upload.outputs.artifact-url }}
58+
ATTESTURL: ${{ steps.attest.outputs.attestation-url }}
59+
run: |
60+
echo "# os-boot ELF" >> $GITHUB_STEP_SUMMARY
61+
echo "" >> $GITHUB_STEP_SUMMARY
62+
echo "The generated [ELF file]("$ELFURL") can be verified from [here]("$ATTESTURL")." >> $GITHUB_STEP_SUMMARY
63+
echo "" >> $GITHUB_STEP_SUMMARY
64+
echo "## Header" >> $GITHUB_STEP_SUMMARY
65+
echo "" >> $GITHUB_STEP_SUMMARY
66+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
67+
readelf -h build/fw_payload.elf >> $GITHUB_STEP_SUMMARY
68+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
69+
echo "" >> $GITHUB_STEP_SUMMARY
70+
echo "## SBOM" >> $GITHUB_STEP_SUMMARY
71+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
72+
cat SBOM.sha256 >> $GITHUB_STEP_SUMMARY
73+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
74+
75+

os-boot/Makefile

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

os-boot/fw_payload.elf

-22.6 MB
Binary file not shown.

0 commit comments

Comments
 (0)