Skip to content

Commit 9726150

Browse files
bors[bot]malbarbo
andcommitted
Merge #166
166: Add qemu-system support for more targets r=Dylan-DPC a=malbarbo Add qemu-system support for the following targets: - aarch64-unknown-linux-gnu - armv7-unknown-linux-gnueabihf - i686-unknown-linux-gnu - mips-unknown-linux-gnu - mipsel-unknown-linux-gnu - mips64el-unknown-linux-gnuabi64 - powerpc-unknown-linux-gnu - powerpc64-unknown-linux-gnu - powerpc64le-unknown-linux-gnu - s390x-unknown-linux-gnu - sparc64-unknown-linux-gnu - x86_64-unknown-linux-gnu Running `cross test` fails for `s390x-unknown-linux-gnu` and `sparc64-unknown-linux-gnu`, but `cargo run` works. This maybe be a bug in qemu or rustc. Debian does not have a port for `mips64-unknown-linux-gnuabi64`. Support for arm targets can be add later, but I think a custom kernel will be need. musl targets can get qemu-system support latter. Co-authored-by: Marco A L Barbosa <[email protected]>
2 parents 200f06c + 831f073 commit 9726150

File tree

15 files changed

+343
-88
lines changed

15 files changed

+343
-88
lines changed

.travis.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ matrix:
99
# Linux
1010
- env: TARGET=aarch64-unknown-linux-gnu CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1 RUNNERS="qemu-user qemu-system" CROSS_DEBUG=1
1111
- env: TARGET=arm-unknown-linux-gnueabi CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1
12-
- env: TARGET=armv7-unknown-linux-gnueabihf CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1
12+
- env: TARGET=armv7-unknown-linux-gnueabihf CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1 RUNNERS="qemu-user qemu-system"
1313
- env: TARGET=i586-unknown-linux-gnu CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1
14-
- env: TARGET=i686-unknown-linux-gnu CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1
15-
- env: TARGET=mips-unknown-linux-gnu CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1
14+
- env: TARGET=i686-unknown-linux-gnu CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1 RUNNERS="native qemu-user qemu-system"
15+
- env: TARGET=mips-unknown-linux-gnu CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1 RUNNERS="qemu-user qemu-system"
16+
- env: TARGET=mipsel-unknown-linux-gnu CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1 RUNNERS="qemu-user qemu-system"
1617
- env: TARGET=mips64-unknown-linux-gnuabi64 CPP=1 DYLIB=1 STD=1 OPENSSL=0.7.17 RUN=1
17-
- env: TARGET=mips64el-unknown-linux-gnuabi64 CPP=1 DYLIB=1 STD=1 OPENSSL=0.7.17 RUN=1
18-
- env: TARGET=mipsel-unknown-linux-gnu CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1
19-
- env: TARGET=powerpc-unknown-linux-gnu CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1
20-
- env: TARGET=powerpc64-unknown-linux-gnu CPP=1 DYLIB=1 STD=1 OPENSSL=0.7.17 RUN=1
21-
- env: TARGET=powerpc64le-unknown-linux-gnu CPP=1 DYLIB=1 STD=1 OPENSSL=0.7.17 RUN=1
22-
- env: TARGET=s390x-unknown-linux-gnu CPP=1 DYLIB=1 STD=1 OPENSSL=0.7.17
23-
- env: TARGET=sparc64-unknown-linux-gnu CPP=1 DYLIB=1 OPENSSL=0.5.5 RUN=1
24-
- env: TARGET=x86_64-unknown-linux-gnu CPP=1 DYLIB=1 OPENSSL=0.5.5 RUN=1 DEPLOY=1
18+
- env: TARGET=mips64el-unknown-linux-gnuabi64 CPP=1 DYLIB=1 STD=1 OPENSSL=0.7.17 RUN=1 RUNNERS="qemu-user qemu-system"
19+
- env: TARGET=powerpc-unknown-linux-gnu CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1 RUNNERS="qemu-user qemu-system"
20+
- env: TARGET=powerpc64-unknown-linux-gnu CPP=1 DYLIB=1 STD=1 OPENSSL=0.7.17 RUN=1 RUNNERS="qemu-user qemu-system"
21+
- env: TARGET=powerpc64le-unknown-linux-gnu CPP=1 DYLIB=1 STD=1 OPENSSL=0.7.17 RUN=1 RUNNERS="qemu-user qemu-system"
22+
- env: TARGET=s390x-unknown-linux-gnu CPP=1 DYLIB=1 STD=1 OPENSSL=0.7.17 RUN=1 RUNNERS="qemu-system"
23+
- env: TARGET=sparc64-unknown-linux-gnu CPP=1 DYLIB=1 STD=1 OPENSSL=0.7.17 RUN=1 RUNNERS="qemu-system"
24+
- env: TARGET=x86_64-unknown-linux-gnu CPP=1 DYLIB=1 OPENSSL=0.5.5 RUN=1 DEPLOY=1 RUNNERS="native qemu-user qemu-system"
2525

2626
# Linux musl
2727
- env: TARGET=aarch64-unknown-linux-musl STD=1 OPENSSL=0.5.5 RUN=1

docker/armv7-unknown-linux-gnueabihf/Dockerfile

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,26 @@ COPY cmake.sh /
1616
RUN apt-get purge --auto-remove -y cmake && \
1717
bash /cmake.sh 3.5.1
1818

19-
COPY openssl.sh qemu.sh /
2019
RUN apt-get install -y --no-install-recommends \
2120
g++-arm-linux-gnueabihf \
22-
libc6-dev-armhf-cross && \
23-
bash /openssl.sh linux-armv4 arm-linux-gnueabihf- && \
24-
bash /qemu.sh arm
21+
libc6-dev-armhf-cross
22+
23+
COPY openssl.sh /
24+
RUN bash /openssl.sh linux-armv4 arm-linux-gnueabihf-
25+
26+
COPY qemu.sh /
27+
RUN bash /qemu.sh arm linux softmmu
28+
29+
COPY dropbear.sh /
30+
RUN bash /dropbear.sh
31+
32+
COPY linux-image.sh /
33+
RUN bash /linux-image.sh armv7
34+
35+
COPY linux-runner /
2536

2637
ENV CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \
27-
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUNNER=qemu-arm \
38+
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUNNER="/linux-runner armv7" \
2839
CC_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc \
2940
CXX_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++ \
3041
OPENSSL_DIR=/openssl \

docker/i686-unknown-linux-gnu/Dockerfile

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,24 @@ COPY cmake.sh /
1616
RUN apt-get purge --auto-remove -y cmake && \
1717
bash /cmake.sh 3.5.1
1818

19-
COPY openssl.sh /
2019
RUN apt-get install -y --no-install-recommends \
21-
g++-multilib && \
22-
bash /openssl.sh linux-elf "" -m32
20+
g++-multilib
21+
22+
COPY openssl.sh /
23+
RUN bash /openssl.sh linux-elf "" -m32
24+
25+
COPY qemu.sh /
26+
RUN bash /qemu.sh i386 linux softmmu
27+
28+
COPY dropbear.sh /
29+
RUN bash /dropbear.sh
30+
31+
COPY linux-image.sh /
32+
RUN bash /linux-image.sh i686
33+
34+
COPY linux-runner /
2335

24-
ENV OPENSSL_DIR=/openssl \
36+
ENV CARGO_TARGET_I686_UNKNOWN_LINUX_GNU_RUNNER="/linux-runner i686" \
37+
OPENSSL_DIR=/openssl \
2538
OPENSSL_INCLUDE_DIR=/openssl/include \
2639
OPENSSL_LIB_DIR=/openssl/lib

docker/linux-image.sh

Lines changed: 79 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,70 @@ main() {
55
local arch=$1 \
66
kversion=4.9.0-8
77

8+
local debsource="deb http://http.debian.net/debian/ stretch main"
9+
debsource="$debsource\ndeb http://security.debian.org/ stretch/updates main"
10+
11+
local dropbear="dropbear-bin"
12+
local libssl="libssl1.0.2"
13+
814
# select debian arch and kernel version
915
case $arch in
1016
aarch64)
1117
arch=arm64
1218
kernel=$kversion-arm64
1319
;;
20+
armv7)
21+
arch=armhf
22+
kernel=$kversion-armmp
23+
;;
24+
i686)
25+
arch=i386
26+
kernel=$kversion-686
27+
;;
28+
mips|mipsel)
29+
kernel=$kversion-4kc-malta
30+
;;
31+
mips64el)
32+
kernel=$kversion-5kc-malta
33+
;;
34+
powerpc)
35+
# there is no stretch powerpc port, so we use jessie
36+
# use a more recent kernel from backports
37+
kernel=4.9.0-0.bpo.6-powerpc
38+
debsource="deb http://http.debian.net/debian/ jessie main"
39+
debsource="$debsource\ndeb http://http.debian.net/debian/ jessie-backports main"
40+
dropbear="dropbear"
41+
libssl="libssl1.0.0"
42+
;;
43+
powerpc64)
44+
# there is no stable port
45+
arch=ppc64
46+
kernel=4.18.0-2-powerpc64
47+
debsource="deb http://ftp.ports.debian.org/debian-ports/ unreleased main"
48+
debsource="$debsource\ndeb http://ftp.ports.debian.org/debian-ports/ unstable main"
49+
# sid version of dropbear requeries this depencendies
50+
deps="libtommath1:ppc64 libtomcrypt1:ppc64 libgmp10:ppc64"
51+
;;
52+
powerpc64le)
53+
arch=ppc64el
54+
kernel=$kversion-powerpc64le
55+
;;
56+
s390x)
57+
arch=s390x
58+
kernel=$kversion-s390x
59+
;;
60+
sparc64)
61+
# there is no stable port
62+
kernel=4.18.0-2-sparc64
63+
debsource="deb http://ftp.ports.debian.org/debian-ports/ unreleased main"
64+
debsource="$debsource\ndeb http://ftp.ports.debian.org/debian-ports/ unstable main"
65+
# sid version of dropbear requeries this depencendies
66+
deps="libtommath1:sparc64 libtomcrypt1:sparc64 libgmp10:sparc64"
67+
;;
68+
x86_64)
69+
arch=amd64
70+
kernel=$kversion-amd64
71+
;;
1472
*)
1573
echo "Invalid arch: $arch"
1674
exit 1
@@ -33,31 +91,33 @@ main() {
3391

3492
# Download packages
3593
mv /etc/apt/sources.list /etc/apt/sources.list.bak
36-
echo "deb http://http.debian.net/debian/ stretch main" > \
37-
/etc/apt/sources.list
38-
echo "deb http://security.debian.org/ stretch/updates main" >> \
39-
/etc/apt/sources.list
94+
echo -e "$debsource" > /etc/apt/sources.list
4095

4196
# Old ubuntu does not support --add-architecture, so we directly change multiarch file
4297
if [ -f /etc/dpkg/dpkg.cfg.d/multiarch ]; then
4398
cp /etc/dpkg/dpkg.cfg.d/multiarch /etc/dpkg/dpkg.cfg.d/multiarch.bak
4499
fi
45100
dpkg --add-architecture $arch || echo "foreign-architecture $arch" > /etc/dpkg/dpkg.cfg.d/multiarch
101+
46102
# Add debian keys
47103
apt-key adv --recv-key --keyserver keyserver.ubuntu.com EF0F382A1A7B6500
48104
apt-key adv --recv-key --keyserver keyserver.ubuntu.com 9D6D8F6BC857C906
49105
apt-key adv --recv-key --keyserver keyserver.ubuntu.com 8B48AD6246925553
50106
apt-key adv --recv-key --keyserver keyserver.ubuntu.com 7638D0442B90D010
107+
apt-key adv --recv-key --keyserver keyserver.ubuntu.com 8BC3A7D46F930576 # ports
108+
apt-key adv --recv-key --keyserver keyserver.ubuntu.com CBF8D6FD518E17E1
109+
apt-key adv --recv-key --keyserver keyserver.ubuntu.com 06AED62430CB581C
51110
apt-get update
52111

53112
mkdir -p -m 777 /qemu/$arch
54113
cd /qemu/$arch
55-
apt-get -t stretch -d --no-install-recommends download \
114+
apt-get -d --no-install-recommends download \
115+
$deps \
56116
busybox:$arch \
57-
dropbear-bin:$arch \
117+
$dropbear:$arch \
58118
libc6:$arch \
59119
libgcc1:$arch \
60-
libssl1*:$arch \
120+
$libssl:$arch \
61121
libstdc++6:$arch \
62122
linux-image-$kernel:$arch \
63123
ncurses-base \
@@ -66,23 +126,30 @@ main() {
66126

67127
# Install packages
68128
root=root-$arch
69-
mkdir -p $root/{bin,etc/dropbear,root,sys,dev,proc,sbin,usr/{bin,sbin},var/log}
129+
mkdir -p $root/{bin,etc/dropbear,root,sys,dev,proc,sbin,tmp,usr/{bin,sbin},var/log}
70130
for deb in $arch/*deb; do
71131
dpkg -x $deb $root/
72132
done
73133

74134
# kernel
75-
cp $root/boot/vmlinu* kernel
135+
if [ "$arch" = "sparc64" ]; then
136+
# boot fails if the kernel is compressed
137+
zcat $root/boot/vmlinu* > kernel
138+
else
139+
cp $root/boot/vmlinu* kernel
140+
fi
76141

77142
# initrd
78143
mkdir -p $root/modules
79144
cp \
145+
$root/lib/modules/*/kernel/drivers/net/net_failover.ko \
80146
$root/lib/modules/*/kernel/drivers/net/virtio_net.ko \
81147
$root/lib/modules/*/kernel/drivers/virtio/* \
82148
$root/lib/modules/*/kernel/fs/9p/9p.ko \
83149
$root/lib/modules/*/kernel/fs/fscache/fscache.ko \
84150
$root/lib/modules/*/kernel/net/9p/9pnet.ko \
85151
$root/lib/modules/*/kernel/net/9p/9pnet_virtio.ko \
152+
$root/lib/modules/*/kernel/net/core/failover.ko \
86153
$root/modules || true # some file may not exist
87154
rm -rf $root/boot
88155
rm -rf $root/lib/modules
@@ -140,6 +207,8 @@ mkdir /dev/pts
140207
mount -t devpts none /dev/pts/
141208
142209
# some archs does not have virtio modules
210+
insmod /modules/failover.ko || true
211+
insmod /modules/net_failover.ko || true
143212
insmod /modules/virtio.ko || true
144213
insmod /modules/virtio_ring.ko || true
145214
insmod /modules/virtio_mmio.ko || true
@@ -155,7 +224,7 @@ ifconfig eth0 10.0.2.15
155224
route add default gw 10.0.2.2 eth0
156225
157226
mkdir /target
158-
mount -t 9p -o trans=virtio target /target -oversion=9p2000.L || true
227+
mount -t 9p -o trans=virtio target /target -oversion=9p2000.u || true
159228
160229
exec dropbear -F -E -B
161230
EOF

docker/linux-runner

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,36 @@ fi
1313
arch=$1
1414
shift
1515

16+
# select qemu arch
17+
qarch=$arch
18+
case "$arch" in
19+
armv7)
20+
qarch="arm"
21+
;;
22+
i686)
23+
qarch="i386"
24+
;;
25+
powerpc)
26+
qarch="ppc"
27+
;;
28+
powerpc64)
29+
qarch="ppc64"
30+
;;
31+
powerpc64le)
32+
if [ "$CROSS_RUNNER" = "qemu-user" ]; then
33+
qarch="ppc64le"
34+
else
35+
qarch="ppc64"
36+
fi
37+
;;
38+
esac
39+
1640
case "$CROSS_RUNNER" in
1741
native)
1842
exec "${@}"
1943
;;
2044
qemu-user | "")
21-
exec qemu-$arch "${@}"
45+
exec qemu-$qarch "${@}"
2246
;;
2347
qemu-system)
2448
true
@@ -30,26 +54,64 @@ case "$CROSS_RUNNER" in
3054
;;
3155
esac
3256

33-
# 8 is the max number of cpu supported by qemu-aarch64
3457
n=$(nproc)
35-
n=$(( n > 8 ? 8 : n ))
3658
memory=1G
37-
driver9p="virtio-9p-device"
38-
drivernet="virtio-net-device"
59+
driver9p="virtio-9p-pci"
60+
drivernet="virtio-net-pci"
3961

4062
# select qemu parameters
4163
case "$arch" in
4264
aarch64)
65+
# 8 is the max number of cpu supported by qemu-aarch64
66+
n=$(( n > 8 ? 8 : n ))
4367
opt="-machine virt -cpu cortex-a57"
4468
;;
69+
armv7)
70+
opt="-machine virt"
71+
driver9p="virtio-9p-device"
72+
drivernet="virtio-net-device"
73+
;;
74+
i686)
75+
opt="-append console=ttyS0"
76+
;;
77+
mips|mipsel)
78+
# avoid kernel error
79+
# https://blahcat.github.io/2017/07/14/building-a-debian-stretch-qemu-image-for-mipsel/
80+
opt="-append nokaslr"
81+
n=1
82+
;;
83+
mips64el)
84+
# avoid kernel error
85+
# https://blahcat.github.io/2017/07/14/building-a-debian-stretch-qemu-image-for-mipsel/
86+
opt="-append nokaslr -cpu MIPS64R2-generic"
87+
n=1
88+
;;
89+
powerpc)
90+
opt="-append console=ttyPZ0"
91+
n=1
92+
;;
93+
powerpc64|powerpc64le)
94+
opt="-append console=hvc0 --nodefaults -serial stdio"
95+
;;
96+
s390x)
97+
n=1
98+
driver9p="virtio-9p-ccw"
99+
drivernet="virtio-net-ccw"
100+
;;
101+
sparc64)
102+
n=1
103+
;;
104+
x86_64)
105+
opt="-append console=ttyS0"
106+
;;
45107
esac
46108

47109
(
48110
flock -n 200 || exit 0
49111

50112
echo Booting QEMU virtual machine with $n cpus...
51113

52-
QEMU_CMD="qemu-system-$arch \
114+
QEMU_CMD="qemu-system-$qarch \
53115
-m $memory \
54116
-smp $n \
55117
-nographic \
@@ -88,13 +150,8 @@ esac
88150
fi
89151
fi
90152

91-
echo Booted in $(dbclient -K 1 -p 10022 -y -y root@localhost "cut -d' ' -f1 /proc/uptime") seconds
153+
echo Booted in $SECONDS seconds
92154

93155
) 200>$LOCK
94156

95-
dbclient \
96-
-t \
97-
-p 10022 \
98-
-y -y \
99-
root@localhost \
100-
"${@}"
157+
exec dbclient -t -p 10022 -y -y root@localhost "${@}"

0 commit comments

Comments
 (0)