-
Notifications
You must be signed in to change notification settings - Fork 6
/
ruyi-build-qemu-inner
executable file
·165 lines (145 loc) · 4.06 KB
/
ruyi-build-qemu-inner
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/bash
set -e
build_flavor="$1"
ARCH="${2:-amd64}"
build_variants="${3:-both}"
case "$build_flavor" in
upstream)
P="qemu-8.2.0"
PV="8.2.0"
RUYI_DATESTAMP=20240128
srcfile="${P}.tar.xz"
SRC_URI="https://download.qemu.org/$srcfile"
pkgversion="RuyiSDK $RUYI_DATESTAMP"
;;
xthead)
P="qemu-6.1.0"
PV="6.1.0"
RUYI_DATESTAMP=20231207
thead_commit_hash=03813c9fe8
srcfile="qemu-xthead-$PV-g$thead_commit_hash.tar.zst"
SRC_URI="https://mirror.iscas.ac.cn/ruyisdk/dist/$srcfile"
pkgversion="T-Head commit $thead_commit_hash, RuyiSDK $RUYI_DATESTAMP"
;;
*)
echo "usage: ruyi-build-qemu <upstream|xthead> [arch] [both|user|system]" >&2
exit 1
;;
esac
case "$ARCH" in
amd64)
# we're compiling from amd64
CROSS_COMPILE_PREFIX=""
;;
arm64)
CROSS_COMPILE_PREFIX="aarch64-linux-gnu-"
;;
riscv64)
CROSS_COMPILE_PREFIX="riscv64-linux-gnu-"
;;
*)
echo "invalid ARCH: choices are amd64, arm64 or riscv64" >&2
exit 1
;;
esac
case "$build_variants" in
both)
BUILD_USER=true
BUILD_SYSTEM=true
;;
user)
BUILD_USER=true
BUILD_SYSTEM=false
;;
system)
BUILD_USER=false
BUILD_SYSTEM=true
;;
*)
echo "invalid build variants: choices are user, system or both (default)" >&2
exit 1
;;
esac
USER_TARGETS="riscv32-linux-user,riscv64-linux-user"
USER_TARGET_EXES=(
qemu-riscv32
qemu-riscv64
)
SYSTEM_TARGETS="riscv32-softmmu,riscv64-softmmu"
SYSTEM_TARGET_EXES=(
qemu-system-riscv32
qemu-system-riscv64
)
INSTALL_ROOT=/tmp/prefix
INSTALL_ROOT_USER="$INSTALL_ROOT/qemu-user-riscv-$build_flavor-$PV.ruyi-$RUYI_DATESTAMP"
INSTALL_ROOT_SYSTEM="$INSTALL_ROOT/qemu-system-riscv-$build_flavor-$PV.ruyi-$RUYI_DATESTAMP"
COMMON_CONFIG_ARGS=(
--disable-docs
--with-pkgversion="$pkgversion"
)
if [[ -n $CROSS_COMPILE_PREFIX ]]; then
COMMON_CONFIG_ARGS+=( --cross-prefix="$CROSS_COMPILE_PREFIX" )
fi
# static-pie breaks the xthead qemu, because apparently too much TLS is used
# likely due to VLEN=1024 pushing the CPU state size too high
STATIC_BUILD_CONFIG_ARGS=( --static )
if [[ $build_flavor == xthead ]]; then
STATIC_BUILD_CONFIG_ARGS+=( --disable-pie )
fi
QEMU_SYSTEM_CONFIG_ARGS=(
--disable-gnutls # only 3.6.13 in ubuntu:20.04 but wants >=3.6.14
--disable-nettle # not ubiquitous
# no static libs in ubuntu:20.04, not ubiquitous on various distros in case
# of dynamic linking (which is currently the case for qemu-system builds),
# other build failures, or just too much hassle to support for now
# (will try to re-add if requested)
--disable-bpf # no ubiquitously supported soversion
--disable-curl # many indirect deps of libcurl don't have static libs available
--disable-gcrypt
--disable-libiscsi
--disable-libnfs
--disable-libssh # problems with gssapi libs
--disable-libudev
--disable-opengl # epoxy, GL, virglrenderer etc.
--disable-rbd
--disable-rdma
--disable-selinux
--disable-vnc-jpeg # no ubiquitously supported soversion
--disable-vnc-sasl
--disable-xkbcommon # no static lib
)
pushd /tmp
wget "$SRC_URI"
tar xf "$srcfile"
popd
SRC_DIR="/tmp/${srcfile%.tar.*}"
if "$BUILD_USER"; then
mkdir /tmp/build-user
pushd /tmp/build-user
"$SRC_DIR"/configure "${COMMON_CONFIG_ARGS[@]}" \
"${STATIC_BUILD_CONFIG_ARGS[@]}" \
--prefix="$INSTALL_ROOT_USER" \
--target-list="$USER_TARGETS"
ninja install
# firmware is unneeded in the static-user build
rm -rf "$INSTALL_ROOT_USER/share"
popd
fi
if "$BUILD_SYSTEM"; then
mkdir /tmp/build-sys
pushd /tmp/build-sys
"$SRC_DIR"/configure "${COMMON_CONFIG_ARGS[@]}" \
"${QEMU_SYSTEM_CONFIG_ARGS[@]}" \
--prefix="$INSTALL_ROOT_SYSTEM" \
--target-list="$SYSTEM_TARGETS"
ninja install
popd
fi
pushd "$INSTALL_ROOT"
"$BUILD_USER" && \
tar --zstd -cvf "/out/qemu-user-riscv-$build_flavor-$PV.ruyi-$RUYI_DATESTAMP.$ARCH.tar.zst" \
"qemu-user-riscv-$build_flavor-$PV.ruyi-$RUYI_DATESTAMP"
"$BUILD_SYSTEM" && \
tar --zstd -cvf "/out/qemu-system-riscv-$build_flavor-$PV.ruyi-$RUYI_DATESTAMP.$ARCH.tar.zst" \
"qemu-system-riscv-$build_flavor-$PV.ruyi-$RUYI_DATESTAMP"
popd