add RISC-V to CI using QEMU and Debian kernel, busybox as init (#6029)
This commit is contained in:
parent
d7bc9584e2
commit
b7c08f4546
3 changed files with 139 additions and 0 deletions
89
.github/riscv-qemu-setup-all.sh
vendored
Normal file
89
.github/riscv-qemu-setup-all.sh
vendored
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
#!/bin/sh
|
||||
set -eux
|
||||
|
||||
LINUX_IMG=linux-image-6.12.73+deb13-riscv64_6.12.73-1_riscv64.deb
|
||||
DEBIAN_SERVER=https://ftp.debian.org/debian/pool/main/l/linux
|
||||
BUSYBOX_PATH=busybox-1.30.1-riscv64
|
||||
BUSYBOX_VERSION=9d220791e5917fc2190c5cf405a014a483c01d86
|
||||
LIB_PATH=/usr/riscv64-linux-gnu/lib
|
||||
LIB_C=libc.so.6
|
||||
LIB_M=libm.so.6
|
||||
DYN_LD=ld-linux-riscv64-lp64d.so.1
|
||||
|
||||
# Fetch the kernel package
|
||||
wget "$DEBIAN_SERVER/$LINUX_IMG"
|
||||
# Extract
|
||||
dpkg-deb -x "$LINUX_IMG" linux-image
|
||||
|
||||
# Fetch busybox
|
||||
git clone https://github.com/rcore-os/busybox-prebuilts.git busybox
|
||||
cd busybox && git checkout "$BUSYBOX_VERSION" && cd ..
|
||||
|
||||
# Cross-compile the Rizin repo
|
||||
cd rizin
|
||||
meson setup build --cross-file doc/examples/cross_builds/meson-linux-riscv64.ini
|
||||
meson compile -C build
|
||||
cd ..
|
||||
|
||||
# Create a rootfs
|
||||
mkdir -p rootfs
|
||||
mkdir -p rootfs/lib rootfs/tmp rootfs/proc rootfs/etc
|
||||
|
||||
# Copy all .so files from the build directory to rootfs/lib (only the real ones, not shorthand symlinks)
|
||||
find rizin/build/librz/ -name "*.so.[0-9].[0-9].[0-9]" -type f \
|
||||
-exec cp {} rootfs/lib/ \; \
|
||||
-exec sh -c 'echo "linking $(basename "${1%.*}") -> $(basename "$1")"; ln -sf "$(basename "$1")" "rootfs/lib/$(basename "${1%.*}")"' _ {} \; # symlinking all *.so.0.9 to *.so.0.9.0
|
||||
|
||||
# Copy rizin binary
|
||||
cp rizin/build/binrz/rizin/rizin rootfs/rizin
|
||||
|
||||
# libc and libm, dynamic linker
|
||||
cp "$LIB_PATH/$LIB_C" "$LIB_PATH/$LIB_M" "$LIB_PATH/$DYN_LD" rootfs/lib/
|
||||
|
||||
# Copy busybox to rootfs
|
||||
cp "busybox/$BUSYBOX_PATH/busybox" rootfs/bb
|
||||
|
||||
# Make busybox the init launcher, poweroff, and mount
|
||||
ln -s bb rootfs/init
|
||||
ln -s bb rootfs/poweroff
|
||||
ln -s bb rootfs/mount
|
||||
|
||||
# Make the inittab
|
||||
cat << EOF > rootfs/etc/inittab
|
||||
::sysinit:/mount -t proc proc /proc
|
||||
::wait:$@
|
||||
::once:/poweroff -f
|
||||
EOF
|
||||
|
||||
# filesystem state
|
||||
# rootfs
|
||||
# /
|
||||
# ├── rizin
|
||||
# ├── bb
|
||||
# ├── init -> bb
|
||||
# ├── poweroff -> bb
|
||||
# ├── mount -> bb
|
||||
# ├── lib/
|
||||
# │ ├── libc.so.6
|
||||
# │ ├── libm.so.6
|
||||
# │ ├── ld-linux-riscv64-lp64d.so.1
|
||||
# │ ├── librz_arch.so.0.9.0
|
||||
# │ ├── librz_arch.so.0.9 -> librz_arch.so.0.9.0
|
||||
# │ ├── librz_bin.so.0.9.0
|
||||
# │ ├── librz_bin.so.0.9 -> librz_bin.so.0.9.0
|
||||
# │ └── ... (*.so.0.9.0 objs + *.so.0.9 symlinks)
|
||||
# ├── tmp/
|
||||
# │ └── (empty)
|
||||
# ├── proc/
|
||||
# │ └── (mounted by kernel)
|
||||
# └── etc/
|
||||
# └── inittab
|
||||
echo "#########################################################################"
|
||||
# for debugging, always check the output tree against the intended tree above
|
||||
tree rootfs
|
||||
echo "#########################################################################"
|
||||
|
||||
# Package the whole thing into an initrd archive
|
||||
cd rootfs
|
||||
find . | cpio -o -H newc | gzip > ../initrd.cpio.gz
|
||||
cd ..
|
||||
31
.github/workflows/ci.yml
vendored
31
.github/workflows/ci.yml
vendored
|
|
@ -936,6 +936,37 @@ jobs:
|
|||
ninja
|
||||
.\rizin_cmake_test
|
||||
|
||||
test-riscv-inside-qemu:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
qemu-system-riscv64 \
|
||||
gcc-riscv64-linux-gnu \
|
||||
g++-riscv64-linux-gnu \
|
||||
binutils-riscv64-linux-gnu \
|
||||
cpio
|
||||
pip3 install meson ninja
|
||||
|
||||
- name: Setup RISC-V QEMU environment
|
||||
run: |
|
||||
cd ..
|
||||
sh rizin/.github/riscv-qemu-setup-all.sh /rizin -hh
|
||||
|
||||
- name: Run inside RISC-V QEMU
|
||||
run: |
|
||||
cd ..
|
||||
qemu-system-riscv64 \
|
||||
-machine virt -cpu rv64 -m 512M \
|
||||
-kernel linux-image/boot/vmlinux-6.12.73+deb13-riscv64 \
|
||||
-initrd initrd.cpio.gz \
|
||||
-append "console=ttyS0,115200 earlycon" \
|
||||
-nographic
|
||||
|
||||
|
||||
create-release:
|
||||
name: Create draft release and upload artifacts
|
||||
runs-on: ubuntu-24.04
|
||||
|
|
|
|||
19
doc/examples/cross_builds/meson-linux-riscv64.ini
Normal file
19
doc/examples/cross_builds/meson-linux-riscv64.ini
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# SPDX-FileCopyrightText: 2024-2026 moste00 <ubermenchun@gmail.com>
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
[binaries]
|
||||
c = 'riscv64-linux-gnu-gcc'
|
||||
cpp = 'riscv64-linux-gnu-g++'
|
||||
ar = 'riscv64-linux-gnu-ar'
|
||||
as = 'riscv64-linux-gnu-as'
|
||||
ranlib = 'riscv64-linux-gnu-ranlib'
|
||||
ld = 'riscv64-linux-gnu-ld'
|
||||
strip = 'riscv64-linux-gnu-strip'
|
||||
|
||||
[host_machine]
|
||||
system = 'linux'
|
||||
cpu_family = 'riscv64'
|
||||
cpu = 'riscv64'
|
||||
endian = 'little'
|
||||
|
||||
[properties]
|
||||
sys_root = '/usr/riscv64-linux-gnu'
|
||||
Loading…
Reference in a new issue