Skip to content

Commit fa95101

Browse files
committed
Merge #153
153: Add support to use qemu-system to run linux aarch64 binaries r=japaric a=malbarbo Fixes #146
2 parents ecc1180 + e4eb1b5 commit fa95101

File tree

10 files changed

+511
-17
lines changed

10 files changed

+511
-17
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ sudo: required
77
matrix:
88
include:
99
# Linux
10-
- env: TARGET=aarch64-unknown-linux-gnu CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1
10+
- env: TARGET=aarch64-unknown-linux-gnu CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1 RUNNERS="qemu-user qemu-system"
1111
- env: TARGET=arm-unknown-linux-gnueabi CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1
1212
- env: TARGET=arm-unknown-linux-musleabi STD=1 RUN=1
1313
- env: TARGET=armv7-unknown-linux-gnueabihf CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1

ci/script.sh

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ main() {
3737
https://github.com/japaric/cortest $td
3838

3939
pushd $td
40-
cross run --target $TARGET --example hello --release
40+
cross_run --target $TARGET --example hello --release
4141
popd
4242

4343
rm -rf $td
@@ -112,7 +112,7 @@ EOF
112112
$td
113113

114114
pushd $td
115-
cross test \
115+
cross_test \
116116
--no-default-features \
117117
--features "gen-tests mangled-names" \
118118
--target $TARGET
@@ -130,9 +130,9 @@ EOF
130130
mkdir examples tests
131131
echo "fn main() { println!(\"Example!\"); }" > examples/e.rs
132132
echo "#[test] fn t() {}" > tests/t.rs
133-
cross run --target $TARGET
134-
cross run --target $TARGET --example e
135-
cross test --target $TARGET
133+
cross_run --target $TARGET
134+
cross_run --target $TARGET --example e
135+
cross_test --target $TARGET
136136
popd
137137

138138
rm -rf $td
@@ -147,7 +147,7 @@ EOF
147147
pushd $td
148148
cargo update -p gcc
149149
if [ $RUN ]; then
150-
cross run --target $TARGET
150+
cross_run --target $TARGET
151151
else
152152
cross build --target $TARGET
153153
fi
@@ -180,4 +180,26 @@ EOF
180180
fi
181181
}
182182

183+
cross_run() {
184+
if [ -z "$RUNNERS" ]; then
185+
cross run "$@"
186+
else
187+
for runner in $RUNNERS; do
188+
echo -e "[target.$TARGET]\nrunner = \"$runner\"" > Cross.toml
189+
cross run "$@"
190+
done
191+
fi
192+
}
193+
194+
cross_test() {
195+
if [ -z "$RUNNERS" ]; then
196+
cross test "$@"
197+
else
198+
for runner in $RUNNERS; do
199+
echo -e "[target.$TARGET]\nrunner = \"$runner\"" > Cross.toml
200+
cross test "$@"
201+
done
202+
fi
203+
}
204+
183205
main

docker/aarch64-unknown-linux-gnu/Dockerfile

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,26 @@ RUN apt-get update && \
1212
COPY xargo.sh /
1313
RUN bash /xargo.sh
1414

15-
COPY openssl.sh qemu.sh /
1615
RUN apt-get install -y --no-install-recommends \
1716
g++-aarch64-linux-gnu \
18-
libc6-dev-arm64-cross && \
19-
bash /openssl.sh linux-aarch64 aarch64-linux-gnu- && \
20-
bash /qemu.sh aarch64
17+
libc6-dev-arm64-cross
18+
19+
COPY openssl.sh /
20+
RUN bash /openssl.sh linux-aarch64 aarch64-linux-gnu-
21+
22+
COPY qemu.sh /
23+
RUN bash /qemu.sh aarch64 linux softmmu
24+
25+
COPY dropbear.sh /
26+
RUN bash /dropbear.sh
27+
28+
COPY linux-image.sh /
29+
RUN bash /linux-image.sh aarch64
30+
31+
COPY linux-runner /
2132

2233
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
23-
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER=qemu-aarch64 \
34+
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER="/linux-runner aarch64" \
2435
CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc \
2536
CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++ \
2637
OPENSSL_DIR=/openssl \

docker/dropbear.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
set -ex
2+
3+
main() {
4+
local version=2017.75 \
5+
td=$(mktemp -d)
6+
7+
local dependencies=(
8+
autoconf
9+
automake
10+
bzip2
11+
curl
12+
make
13+
zlib1g-dev
14+
)
15+
16+
apt-get update
17+
local purge_list=()
18+
for dep in ${dependencies[@]}; do
19+
if ! dpkg -L $dep; then
20+
apt-get install --no-install-recommends -y $dep
21+
purge_list+=( $dep )
22+
fi
23+
done
24+
25+
pushd $td
26+
27+
curl -L https://matt.ucc.asn.au/dropbear/dropbear-$version.tar.bz2 | \
28+
tar --strip-components=1 -xj
29+
30+
# Remove some unwanted message
31+
sed -i '/skipping hostkey/d' cli-kex.c
32+
sed -i '/failed to identify current user/d' cli-runopts.c
33+
34+
./configure \
35+
--disable-syslog \
36+
--disable-shadow \
37+
--disable-lastlog \
38+
--disable-utmp \
39+
--disable-utmpx \
40+
--disable-wtmp \
41+
--disable-wtmpx \
42+
--disable-pututline \
43+
--disable-pututxline
44+
45+
nice make -j$(nproc) PROGRAMS=dbclient
46+
cp dbclient /usr/local/bin/
47+
48+
# Clean up
49+
apt-get purge --auto-remove -y ${purge_list[@]}
50+
51+
popd
52+
53+
rm -rf $td
54+
rm $0
55+
}
56+
57+
main "${@}"

docker/linux-image.sh

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
set -ex
2+
3+
main() {
4+
# arch in the rust target
5+
local arch=$1 \
6+
kversion=4.9.0-4
7+
8+
# select debian arch and kernel version
9+
case $arch in
10+
aarch64)
11+
arch=arm64
12+
kernel=$kversion-arm64
13+
;;
14+
*)
15+
echo "Invalid arch: $arch"
16+
exit 1
17+
;;
18+
esac
19+
20+
local dependencies=(
21+
cpio
22+
sharutils
23+
)
24+
25+
local purge_list=()
26+
apt-get update
27+
for dep in ${dependencies[@]}; do
28+
if ! dpkg -L $dep; then
29+
apt-get install --no-install-recommends -y $dep
30+
purge_list+=( $dep )
31+
fi
32+
done
33+
34+
# Download packages
35+
mv /etc/apt/sources.list /etc/apt/sources.list.bak
36+
echo "deb http://http.debian.net/debian/ stretch main contrib non-free" > \
37+
/etc/apt/sources.list
38+
39+
# Old ubuntu does not support --add-architecture, so we directly change multiarch file
40+
if [ -f /etc/dpkg/dpkg.cfg.d/multiarch ]; then
41+
cp /etc/dpkg/dpkg.cfg.d/multiarch /etc/dpkg/dpkg.cfg.d/multiarch.bak
42+
fi
43+
dpkg --add-architecture $arch || echo "foreign-architecture $arch" > /etc/dpkg/dpkg.cfg.d/multiarch
44+
# Add debian keys
45+
apt-key adv --recv-key --keyserver keyserver.ubuntu.com 8B48AD6246925553
46+
apt-get update
47+
48+
mkdir -p -m 777 /qemu/$arch
49+
cd /qemu/$arch
50+
apt-get -t stretch -d --no-install-recommends download \
51+
busybox:$arch \
52+
dropbear-bin:$arch \
53+
libc6:$arch \
54+
libgcc1:$arch \
55+
libssl1*:$arch \
56+
libstdc++6:$arch \
57+
linux-image-$kernel:$arch \
58+
ncurses-base \
59+
zlib1g:$arch
60+
cd /qemu
61+
62+
# Install packages
63+
root=root-$arch
64+
mkdir -p $root/{bin,etc/dropbear,root,sys,dev,proc,sbin,usr/{bin,sbin},var/log}
65+
for deb in $arch/*deb; do
66+
dpkg -x $deb $root/
67+
done
68+
69+
# kernel
70+
cp $root/boot/vmlinu* kernel
71+
72+
# initrd
73+
mkdir -p $root/modules
74+
cp \
75+
$root/lib/modules/*/kernel/drivers/net/virtio_net.ko \
76+
$root/lib/modules/*/kernel/drivers/virtio/* \
77+
$root/lib/modules/*/kernel/fs/9p/9p.ko \
78+
$root/lib/modules/*/kernel/fs/fscache/fscache.ko \
79+
$root/lib/modules/*/kernel/net/9p/9pnet.ko \
80+
$root/lib/modules/*/kernel/net/9p/9pnet_virtio.ko \
81+
$root/modules || true # some file may not exist
82+
rm -rf $root/boot
83+
rm -rf $root/lib/modules
84+
85+
cat << 'EOF' > $root/etc/hosts
86+
127.0.0.1 localhost qemu
87+
EOF
88+
89+
cat << 'EOF' > $root/etc/hostname
90+
qemu
91+
EOF
92+
93+
cat << 'EOF' > $root/etc/passwd
94+
root::0:0:root:/root:/bin/sh
95+
EOF
96+
97+
cat << 'EOF' | uudecode -o $root/etc/dropbear/dropbear_rsa_host_key
98+
begin 600 dropbear_rsa_host_key
99+
M````!W-S:"UR<V$````#`0`!```!`0"N!-<%K,3Z.!Z,OEMB2.N\O.$IWQ*F
100+
M#5%(_;(^2YKY_J_.RQW/7U@_MK&J#!Z0_\;EH#98ZW*E1\.<FF%P/*Y.W56-
101+
M31.'EJE`TN@=T5EC(8"Y%3'ZBYH)^WIVJ]S*G/_;#RH\_?S"U^1L_<<.F`O+
102+
MZVI?*]\KTDOT&QV0#B-M;"%_7:\>+3[X=QMH,B<HM$+0E[\B6*^!XKLR@V,K
103+
M)<V80HHK:_#;D]26XKN&CB./EZAC%4)78R!G""4HT@UK<5I4B^$/""`,?*\T
104+
M>*4$RYULV,V3X6]K:7@Q?80"#WXGGQZNFN6CZ7LTDX(F6J[\]F5<0`HEOF:Z
105+
MX;^53`L'4I/A```!``$L:$Z*#6<^3@+O%.[-#/5H+.C'3\#QQZN[1;J>L`8I
106+
MZ_&T'!"J'/Y+?R?55G:M^=]R*-&I3TOJYZA8@&H51ZOAF59'1_>>Z@?E4#)$
107+
MQU)X/RWH51ZB5KSDWJS:D'7GD(!?NAY`C'7\)I:_4)J")QBV/P"RJQGHG'%B
108+
M1BT2LE6676>`1K,0\NIMZTKQNB(IC+88<7#8%_-=P<&6<"9LH>60TSS?3?-C
109+
MN`T36YB/3^<(Q;`N1NT>I9EZS`BAC^-?.:,R\7EL"<4>7E=]^1]B\K9])AQU
110+
MBM\]M;4V(S(6KH-I.4[6>9E+@\UEM.J6:[2LUEEJDG:G:+:/EVF^Y75@(S$`
111+
M``"!`.O+KW=&*CBCHL"11&SVO4/K]$R-]7MV7,3RR)Q[X'0;6.?4JHW!3VR6
112+
M*FGBY--37ZD-+UV.8_+"$<?B"#&K$.[V)F7V2\UY!7(0FZ@A2`0ADDY*J-_B
113+
M4AU&.*GP#F/!I([:?E],.>6PH9)(/E.\G19#G0K`LRM?JWS!58&;D0C1````
114+
M@0"\[@NYWSTW(?Q@:_A*1Y3/AKYO5?S=0"<2>#V-AH6W-NCSDTSRP=2D79FS
115+
M"D?[;.)V>8'#9&I3"MU@+:2\Z%$0-MG0+J'(0>T1_C6?*C=4U0I$DI<=@D]1
116+
H_&DE8Y(OT%%EPG]!$H&5HX*),_D1A2\P=R.7G'`0L%YM-79Y"T">$0``
117+
`
118+
end
119+
EOF
120+
121+
# dropbear complains when this file is missing
122+
touch $root/var/log/lastlog
123+
124+
cat << 'EOF' > $root/init
125+
#!/bin/busybox sh
126+
127+
set -e
128+
129+
/bin/busybox --install
130+
131+
mount -t devtmpfs devtmpfs /dev
132+
mount -t proc none /proc
133+
mount -t sysfs none /sys
134+
mkdir /dev/pts
135+
mount -t devpts none /dev/pts/
136+
137+
# some archs does not have virtio modules
138+
insmod /modules/virtio.ko || true
139+
insmod /modules/virtio_ring.ko || true
140+
insmod /modules/virtio_mmio.ko || true
141+
insmod /modules/virtio_pci.ko || true
142+
insmod /modules/virtio_net.ko || true
143+
insmod /modules/fscache.ko
144+
insmod /modules/9pnet.ko
145+
insmod /modules/9pnet_virtio.ko || true
146+
insmod /modules/9p.ko
147+
148+
ifconfig lo 127.0.0.1
149+
ifconfig eth0 10.0.2.15
150+
route add default gw 10.0.2.2 eth0
151+
152+
mkdir /target
153+
mount -t 9p -o trans=virtio target /target -oversion=9p2000.L || true
154+
155+
exec dropbear -F -E -B
156+
EOF
157+
158+
chmod +x $root/init
159+
cd $root && find . | cpio --create --format='newc' --quiet | gzip > ../initrd.gz
160+
161+
# Clean up
162+
rm -rf /qemu/$root /qemu/$arch
163+
mv -f /etc/apt/sources.list.bak /etc/apt/sources.list
164+
if [ -f /etc/dpkg/dpkg.cfg.d/multiarch.bak ]; then
165+
mv /etc/dpkg/dpkg.cfg.d/multiarch.bak /etc/dpkg/dpkg.cfg.d/multiarch
166+
fi
167+
# can fail if arch is used (amd64 and/or i386)
168+
dpkg --remove-architecture $arch || true
169+
apt-get update
170+
apt-get purge --auto-remove -y ${purge_list[@]}
171+
ls -lh /qemu
172+
}
173+
174+
main "${@}"

0 commit comments

Comments
 (0)