Skip to content

Commit 82f2b12

Browse files
authored
Merge pull request #58 from SoftwareDefinedVehicle/fix-runner-script
Simplify runner scripts
2 parents d57c3d1 + 3d997d4 commit 82f2b12

File tree

7 files changed

+48
-156
lines changed

7 files changed

+48
-156
lines changed

resources/runners/README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,4 @@
22

33
The Leda runner scripts are for users to run a released Leda distro image using QEMU.
44

5-
The scripts perform these additional steps:
6-
- Install dependencies (qemu-system, uml-utilities for tunctl)
7-
- Setting up virtual network (TAP)
8-
- Populating QEMU command line arguments
9-
10-
The functionality is similar to the `runqemu` script from BitBake.
11-
125
The files get packaged into the Leda release archive.

resources/runners/qemuarm64/readme.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
Quickstart Image for QEMU ARM-64 Bit
1+
Eclipse Leda - Quickstart Image for QEMU ARM-64 Bit
22

33
Usage
4-
- Install qemu-system-aarch64
5-
- Set up TAP Networking, see https://en.wikibooks.org/wiki/QEMU/Networking
6-
- Start the image (requires sudo)
4+
- Install qemu-system-arm
5+
- Start the image by executing the script:
76

87
./run-leda.sh
98

resources/runners/qemuarm64/run-leda.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
SET Path=c:\Program Files\qemu;%Path%`
77
SET QEMU_BIN=qemu-system-aarch64
88

9-
qemu-system-aarch64 -net nic -netdev user,id=net0,hostfwd=tcp::2222-:22 -drive if=none,id=hd,file=sdv-image-all-qemux86-64.wic.qcow2,format=qcow2 -device virtio-scsi-pci,id=scsi -device scsi-hd,drive=hd -usb -device usb-tablet -serial mon:stdio -serial null -serial mon:vc -object can-bus,id=canbus0 -device kvaser_pci,canbus=canbus0 -cpu IvyBridge -machine q35 -smp 4 -m 4G -bios u-boot.bin
9+
qemu-system-aarch64 -net nic -net user,hostfwd=tcp::2222-:22,hostfwd=tcp::1880-:1880,hostfwd=tcp::1883-:1883,hostfwd=tcp::8888-:8888,hostfwd=tcp::30555-:30555 -drive if=none,id=hd,file=sdv-image-all-qemux86-64.wic.qcow2,format=qcow2 -device virtio-scsi-pci,id=scsi -device scsi-hd,drive=hd -usb -device usb-tablet -serial mon:stdio -serial null -serial mon:vc -object can-bus,id=canbus0 -device kvaser_pci,canbus=canbus0 -cpu IvyBridge -machine q35 -smp 4 -m 4G -bios u-boot.bin
1010

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,27 @@
11
#!/bin/bash
2-
3-
function askInstallQemu() {
4-
while true
5-
do
6-
echo "Do you wish to install qemu-system-arm using sudo?"
7-
select ync in "Yes" "No" "Cancel"; do
8-
case $ync in
9-
Yes )
10-
sudo apt install qemu-system-arm;
11-
return 1
12-
;;
13-
No )
14-
return 0
15-
;;
16-
Cancel )
17-
exit
18-
;;
19-
esac
20-
done
21-
done
22-
}
23-
24-
if ! command -v qemu-system-aarch64 --version &> /dev/null
25-
then
26-
echo "Qemu not installed."
27-
askInstallQemu
28-
else
29-
echo "Qemu found."
30-
fi
2+
# /********************************************************************************
3+
# * Copyright (c) 2022 Contributors to the Eclipse Foundation
4+
# *
5+
# * See the NOTICE file(s) distributed with this work for additional
6+
# * information regarding copyright ownership.
7+
# *
8+
# * This program and the accompanying materials are made available under the
9+
# * terms of the Apache License 2.0 which is available at
10+
# * https://www.apache.org/licenses/LICENSE-2.0
11+
# *
12+
# * SPDX-License-Identifier: Apache-2.0
13+
# ********************************************************************************/
3114

3215
qemu-system-aarch64 \
33-
-kernel ./Image-qemuarm64.bin \
34-
-m 4G \
35-
-machine virt -cpu cortex-a57 \
36-
-nographic \
37-
-drive if=none,file=sdv-image-all-qemuarm64.wic.qcow2,format=qcow2,id=hd \
38-
-device virtio-blk-device,drive=hd \
39-
-netdev user,id=net0,hostfwd=tcp::2222-:22 \
40-
-device virtio-net-device,netdev=net0 \
41-
-object can-bus,id=canbus0 \
42-
-device kvaser_pci,canbus=canbus0 \
43-
-bios u-boot.bin
16+
-kernel ./Image-qemuarm64.bin \
17+
-m 2G \
18+
-machine virt \
19+
-cpu cortex-a57 \
20+
-nographic \
21+
-drive if=none,file=sdv-image-all-qemuarm64.wic.qcow2,format=qcow2,id=hd \
22+
-device virtio-blk-device,drive=hd \
23+
-net nic,model=virtio \
24+
-net user,hostfwd=tcp::2222-:22,hostfwd=tcp::1880-:1880,hostfwd=tcp::1883-:1883,hostfwd=tcp::8888-:8888,hostfwd=tcp::30555-:30555 \
25+
-object can-bus,id=canbus0 \
26+
-device kvaser_pci,canbus=canbus0 \
27+
-bios u-boot.bin

resources/runners/qemux86_64/readme.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
Quickstart Image for QEMU x86_64 Bit
1+
Eclipse Leda - Quickstart Image for QEMU x86_64 Bit
22

33
Usage
44
- Install qemu-system-x86
5-
- Set up TAP Networking, see https://en.wikibooks.org/wiki/QEMU/Networking
6-
- Start the image (requires sudo)
5+
- Start the image by executing the script:
76

87
./run-leda.sh
98

resources/runners/qemux86_64/run-leda.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ SET QEMU_BIN=qemu-system-x86_64
1010
:: qemu-system-x86_64 -net nic -netdev user,id=net0,hostfwd=tcp::2222-:22 -drive if=none,id=hd,file=sdv-image-all-qemux86-64.wic.qcow2,format=qcow2 -device virtio-scsi-pci,id=scsi -device scsi-hd,drive=hd -usb -device usb-tablet -serial mon:stdio -serial null -serial mon:vc -object can-bus,id=canbus0 -device kvaser_pci,canbus=canbus0 -drive if=pflash,format=qcow2,file=ovmf.qcow2 -cpu IvyBridge -machine q35 -smp 4 -m 4G
1111

1212
:: With "-bios ovmf.qcow2", qemu directly boots to grub.
13-
qemu-system-x86_64 -net nic -netdev user,id=net0,hostfwd=tcp::2222-:22 -device virtio-blk,drive=hd,bootindex=1 -drive if=none,id=hd,file=sdv-image-all-qemux86-64.wic.qcow2,format=qcow2 -usb -device usb-tablet -serial mon:stdio -object can-bus,id=canbus0 -device kvaser_pci,canbus=canbus0 -bios ovmf.qcow2 -cpu IvyBridge -machine q35 -smp 4 -m 4G
13+
qemu-system-x86_64 -net nic -net user,hostfwd=tcp::2222-:22,hostfwd=tcp::1880-:1880,hostfwd=tcp::1883-:1883,hostfwd=tcp::8888-:8888,hostfwd=tcp::30555-:30555 -device virtio-blk,drive=hd,bootindex=1 -drive if=none,id=hd,file=sdv-image-all-qemux86-64.wic.qcow2,format=qcow2 -usb -device usb-tablet -serial mon:stdio -object can-bus,id=canbus0 -device kvaser_pci,canbus=canbus0 -bios ovmf.qcow2 -cpu IvyBridge -machine q35 -smp 4 -m 4G

resources/runners/qemux86_64/run-leda.sh

Lines changed: 17 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -11,104 +11,21 @@
1111
# *
1212
# * SPDX-License-Identifier: Apache-2.0
1313
# ********************************************************************************/
14-
#
15-
# Run qemu with TAP network
16-
#
17-
# set -x
1814

19-
USERID="-u $(id -u)"
20-
GROUP="-g $(id -g)"
21-
TUNCTL="sudo tunctl"
22-
IFCONFIG="sudo ip"
23-
IPTABLES="sudo iptables"
24-
TAP=
25-
26-
function setupTap() {
27-
TAP=`$TUNCTL -b $GROUP 2>&1`
28-
n=$[ (`echo $TAP | sed 's/tap//'` * 2) + 1 ]
29-
$IFCONFIG addr add 192.168.7.$n/32 broadcast 192.168.7.255 dev $TAP
30-
$IFCONFIG link set dev $TAP up
31-
dest=$[ (`echo $TAP | sed 's/tap//'` * 2) + 2 ]
32-
$IFCONFIG route add to 192.168.7.$dest dev $TAP
33-
$IPTABLES -A POSTROUTING -t nat -j MASQUERADE -s 192.168.7.$n/32
34-
$IPTABLES -A POSTROUTING -t nat -j MASQUERADE -s 192.168.7.$dest/32
35-
sudo bash -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
36-
sudo bash -c "echo 1 > /proc/sys/net/ipv4/conf/$TAP/proxy_arp"
37-
$IPTABLES -P FORWARD ACCEPT
38-
echo "Set up TAP network interface: $TAP"
39-
}
40-
41-
function teardownTap() {
42-
echo "Tearing down TAP network interface: $TAP"
43-
$TUNCTL -d $TAP
44-
$IFCONFIG link del $TAP
45-
n=$[ (`echo $TAP | sed 's/tap//'` * 2) + 1 ]
46-
dest=$[ (`echo $TAP | sed 's/tap//'` * 2) + 2 ]
47-
$IPTABLES -D POSTROUTING -t nat -j MASQUERADE -s 192.168.7.$n/32
48-
$IPTABLES -D POSTROUTING -t nat -j MASQUERADE -s 192.168.7.$dest/32
49-
}
50-
51-
trap teardownTap EXIT
52-
53-
function askInstall() {
54-
local package=$1
55-
while true
56-
do
57-
echo "Do you wish to install $package using sudo?"
58-
select ync in "Yes" "No" "Cancel"; do
59-
case $ync in
60-
Yes )
61-
sudo apt-get install -y $package;
62-
return 1
63-
;;
64-
No )
65-
return 0
66-
;;
67-
Cancel )
68-
exit
69-
;;
70-
esac
71-
done
72-
done
73-
}
74-
75-
if ! command -v qemu-system-x86_64 &> /dev/null
76-
then
77-
echo "Qemu not installed."
78-
askInstall "qemu-system-x86"
79-
else
80-
echo "Qemu found."
81-
fi
82-
83-
if ! command -v tunctl &> /dev/null
84-
then
85-
echo "tunctl not installed."
86-
askInstall "uml-utilities"
87-
else
88-
echo "tunctl found."
89-
fi
90-
91-
92-
93-
94-
setupTap
95-
96-
sudo qemu-system-x86_64 \
97-
-device virtio-net-pci,netdev=net0,mac=52:54:00:12:34:02 \
98-
-netdev tap,id=net0,ifname=$TAP,script=no,downscript=no \
99-
-object rng-random,filename=/dev/urandom,id=rng0 \
100-
-device virtio-rng-pci,rng=rng0 \
101-
-drive id=hd,file=sdv-image-all-qemux86-64.wic.qcow2,if=virtio,format=qcow2 \
102-
-enable-kvm \
103-
-serial mon:stdio \
104-
-serial null \
105-
-serial mon:vc \
106-
-nographic \
107-
-object can-bus,id=canbus0 \
108-
-device kvaser_pci,canbus=canbus0 \
109-
-drive if=pflash,format=qcow2,file=ovmf.qcow2 \
110-
-cpu IvyBridge \
111-
-machine q35 \
112-
-smp 4 \
113-
-m 4G
114-
15+
qemu-system-x86_64 \
16+
-net nic,model=virtio \
17+
-net user,hostfwd=tcp::2222-:22,hostfwd=tcp::1880-:1880,hostfwd=tcp::1883-:1883,hostfwd=tcp::8888-:8888,hostfwd=tcp::30555-:30555 \
18+
-object rng-random,filename=/dev/urandom,id=rng0 \
19+
-device virtio-rng-pci,rng=rng0 \
20+
-drive id=hd,file=sdv-image-all-qemux86-64.wic.qcow2,if=virtio,format=qcow2 \
21+
-serial mon:stdio \
22+
-serial null \
23+
-serial mon:vc \
24+
-nographic \
25+
-object can-bus,id=canbus0 \
26+
-device kvaser_pci,canbus=canbus0 \
27+
-drive if=pflash,format=qcow2,file=ovmf.qcow2 \
28+
-cpu IvyBridge \
29+
-machine q35 \
30+
-smp 4 \
31+
-m 2G

0 commit comments

Comments
 (0)