Skip to content

Commit 200f06c

Browse files
bors[bot]malbarbo
andcommitted
Merge #153
153: Add support to use qemu-system to run linux aarch64 binaries r=Dylan-DPC a=malbarbo Fixes #146 Co-authored-by: Marco A L Barbosa <[email protected]>
2 parents 0ed0fc1 + c7e04f6 commit 200f06c

File tree

9 files changed

+437
-17
lines changed

9 files changed

+437
-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" CROSS_DEBUG=1
1111
- env: TARGET=arm-unknown-linux-gnueabi CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1
1212
- env: TARGET=armv7-unknown-linux-gnueabihf CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1
1313
- env: TARGET=i586-unknown-linux-gnu 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
@@ -96,7 +96,7 @@ EOF
9696
$td
9797

9898
pushd $td
99-
cross test --manifest-path testcrate/Cargo.toml --target $TARGET
99+
cross_test --manifest-path testcrate/Cargo.toml --target $TARGET
100100
popd
101101

102102
rm -rf $td
@@ -113,7 +113,7 @@ EOF
113113
https://github.com/japaric/cortest $td
114114

115115
pushd $td
116-
cross run --target $TARGET --example hello --release
116+
cross_run --target $TARGET --example hello --release
117117
popd
118118

119119
rm -rf $td
@@ -127,9 +127,9 @@ EOF
127127
mkdir examples tests
128128
echo "fn main() { println!(\"Example!\"); }" > examples/e.rs
129129
echo "#[test] fn t() {}" > tests/t.rs
130-
cross run --target $TARGET
131-
cross run --target $TARGET --example e
132-
cross test --target $TARGET
130+
cross_run --target $TARGET
131+
cross_run --target $TARGET --example e
132+
cross_test --target $TARGET
133133
popd
134134

135135
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
@@ -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++-aarch64-linux-gnu \
22-
libc6-dev-arm64-cross && \
23-
bash /openssl.sh linux-aarch64 aarch64-linux-gnu- && \
24-
bash /qemu.sh aarch64
21+
libc6-dev-arm64-cross
22+
23+
COPY openssl.sh /
24+
RUN bash /openssl.sh linux-aarch64 aarch64-linux-gnu-
25+
26+
COPY qemu.sh /
27+
RUN bash /qemu.sh aarch64 linux softmmu
28+
29+
COPY dropbear.sh /
30+
RUN bash /dropbear.sh
31+
32+
COPY linux-image.sh /
33+
RUN bash /linux-image.sh aarch64
34+
35+
COPY linux-runner /
2536

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

0 commit comments

Comments
 (0)