summaryrefslogtreecommitdiffstats
path: root/meta-sota-qemux86-64/scripts/run-qemu
diff options
context:
space:
mode:
authorPatrick Vacek <patrickvacek@gmail.com>2017-09-11 17:32:26 +0200
committerPatrick Vacek <patrickvacek@gmail.com>2017-09-11 17:36:47 +0200
commit40ee5d8ab02d99ce146d93f7e42315d26f61c621 (patch)
treefc152d0474927a2aad088cd28d2829dfb782ecd1 /meta-sota-qemux86-64/scripts/run-qemu
parent26a03e46905eef25420a6e4ca4bf2d4b1ec92ffa (diff)
downloadmeta-updater-40ee5d8ab02d99ce146d93f7e42315d26f61c621.tar.gz
meta-updater-qemux86-64/scripts/run-qemu is now obsolete and redundant.
Use meta-updater/scripts/run-qemu-ota.
Diffstat (limited to 'meta-sota-qemux86-64/scripts/run-qemu')
-rwxr-xr-xmeta-sota-qemux86-64/scripts/run-qemu142
1 files changed, 0 insertions, 142 deletions
diff --git a/meta-sota-qemux86-64/scripts/run-qemu b/meta-sota-qemux86-64/scripts/run-qemu
deleted file mode 100755
index 3b178ce..0000000
--- a/meta-sota-qemux86-64/scripts/run-qemu
+++ /dev/null
@@ -1,142 +0,0 @@
1#! /usr/bin/env python
2
3from argparse import ArgumentParser
4from subprocess import Popen
5from os.path import exists, join
6from os import listdir
7import random
8import sys
9import socket
10
11DEFAULT_DIR = 'tmp/deploy/images'
12
13EXTENSIONS = {
14 'intel-corei7-64': 'wic',
15 'qemux86-64': 'otaimg'
16}
17
18def find_local_port(start_port):
19 """"
20 Find the next free TCP port after 'start_port'.
21 """
22
23 for port in range(start_port, start_port + 10):
24 try:
25 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
26 s.bind(('', port))
27 return port
28 except socket.error:
29 print("Skipping port %d" % port)
30 finally:
31 s.close()
32 raise Exception("Could not find a free TCP port")
33
34
35def random_mac():
36 """Return a random Ethernet MAC address
37 @link https://www.iana.org/assignments/ethernet-numbers/ethernet-numbers.xhtml#ethernet-numbers-2
38 """
39 head = "ca:fe:"
40 hex_digits = '0123456789abcdef'
41 tail = ':'.join([random.choice(hex_digits) + random.choice(hex_digits) for _ in range(4)])
42 return head + tail
43
44
45class QemuCommand(object):
46 def __init__(self, args):
47 if args.machine:
48 self.machine = args.machine
49 else:
50 machines = listdir(args.dir)
51 if len(machines) == 1:
52 self.machine = machines[0]
53 else:
54 raise ValueError("Could not autodetect machine type from %s" % args.dir)
55 if args.efi:
56 self.bios = 'OVMF.fd'
57 else:
58 uboot = join(args.dir, self.machine, 'u-boot-qemux86-64.rom')
59 if not exists(uboot):
60 raise ValueError("U-Boot image %s does not exist" % uboot)
61 self.bios = uboot
62 ext = EXTENSIONS.get(self.machine, 'wic')
63 self.image = join(args.dir, self.machine, '%s-%s.%s' % (args.imagename, self.machine, ext))
64 if not exists(self.image):
65 raise ValueError("OS image %s does not exist" % self.image)
66 if args.mac:
67 self.mac_address = args.mac
68 else:
69 self.mac_address = random_mac()
70 self.serial_port = find_local_port(8990)
71 self.ssh_port = find_local_port(2222)
72 self.kvm = not args.no_kvm
73 self.gui = not args.no_gui
74 self.gdb = args.gdb
75
76 def command_line(self):
77 netuser = 'user,hostfwd=tcp:0.0.0.0:%d-:22,restrict=off' % self.ssh_port
78 if self.gdb:
79 netuser += ',hostfwd=tcp:0.0.0.0:2159-:2159'
80 cmdline = [
81 "qemu-system-x86_64",
82 "-bios", self.bios,
83 "-drive", "file=%s,if=ide,format=raw,snapshot=on" % self.image,
84 "-serial", "tcp:127.0.0.1:%d,server,nowait" % self.serial_port,
85 "-m", "1G",
86 "-usb",
87 "-usbdevice", "tablet",
88 "-show-cursor",
89 "-vga", "std",
90 "-net", netuser,
91 "-net", "nic,macaddr=%s" % self.mac_address
92 ]
93 if self.gui:
94 cmdline += ["-serial", "stdio"]
95 else:
96 cmdline.append('-nographic')
97 if self.kvm:
98 cmdline.append('-enable-kvm')
99 return cmdline
100
101
102def main():
103 parser = ArgumentParser(description='Run meta-updater image in qemu')
104 parser.add_argument('imagename', default='core-image-minimal', nargs='?')
105 parser.add_argument('mac', default=None, nargs='?')
106 parser.add_argument('--dir', default=DEFAULT_DIR,
107 help='Path to build directory containing the image and u-boot-qemux86-64.rom')
108 parser.add_argument('--efi',
109 help='Boot using UEFI rather than U-Boot. This requires the image to be built with ' +
110 'OSTREE_BOOTLOADER = "grub" and OVMF.fd firmware to be installed (try "apt install ovmf")',
111 action='store_true')
112 parser.add_argument('--machine', default=None, help="Target MACHINE")
113 parser.add_argument('--no-kvm', help='Disable KVM in QEMU', action='store_true')
114 parser.add_argument('--no-gui', help='Disable GUI', action='store_true')
115 parser.add_argument('--gdb', help='Export gdbserver port 2159 from the image', action='store_true')
116 parser.add_argument('-n', '--dry-run', help='Print qemu command line rather then run it', action='store_true')
117 args = parser.parse_args()
118 try:
119 qemu_command = QemuCommand(args)
120 except ValueError as e:
121 print(e.message)
122 sys.exit(1)
123
124 print("Launching %s with mac address %s" % (args.imagename, qemu_command.mac_address))
125 print("To connect via SSH:")
126 print(" ssh -o StrictHostKeyChecking=no root@localhost -p %d" % qemu_command.ssh_port)
127 print("To connect to the serial console:")
128 print(" nc localhost %d" % qemu_command.serial_port)
129
130 cmdline = qemu_command.command_line()
131 if args.dry_run:
132 print(" ".join(cmdline))
133 else:
134 s = Popen(cmdline)
135 try:
136 s.wait()
137 except KeyboardInterrupt:
138 pass
139
140
141if __name__ == '__main__':
142 main()