summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorPatrick Vacek <patrickvacek@gmail.com>2019-09-10 14:10:16 +0200
committerGitHub <noreply@github.com>2019-09-10 14:10:16 +0200
commit5348b146054e7b16dff71ceb41697157488867e7 (patch)
tree85c10f159169a04e95f247cf4a6ac4874d2a8885 /scripts
parentf4c7b3d831f232c312b50d52ff296c4678eb475b (diff)
parent357c65d44135b560b25e86ec33b1c1efccb0c7fa (diff)
downloadmeta-updater-5348b146054e7b16dff71ceb41697157488867e7.tar.gz
Merge pull request #599 from advancedtelematic/feat/better-overlays
Feat/better overlays
Diffstat (limited to 'scripts')
-rw-r--r--scripts/qemucommand.py50
-rwxr-xr-xscripts/run-qemu-ota26
2 files changed, 60 insertions, 16 deletions
diff --git a/scripts/qemucommand.py b/scripts/qemucommand.py
index a869d4d..9b23c54 100644
--- a/scripts/qemucommand.py
+++ b/scripts/qemucommand.py
@@ -2,6 +2,7 @@ from os.path import exists, isdir, join, realpath, abspath
2from os import listdir 2from os import listdir
3import random 3import random
4import socket 4import socket
5from shutil import copyfile
5from subprocess import check_output 6from subprocess import check_output
6 7
7EXTENSIONS = { 8EXTENSIONS = {
@@ -39,6 +40,8 @@ def random_mac():
39 40
40class QemuCommand(object): 41class QemuCommand(object):
41 def __init__(self, args): 42 def __init__(self, args):
43 self.dry_run = args.dry_run
44 self.overlay = args.overlay
42 if args.machine: 45 if args.machine:
43 self.machine = args.machine 46 self.machine = args.machine
44 else: 47 else:
@@ -49,21 +52,53 @@ class QemuCommand(object):
49 self.machine = machines[0] 52 self.machine = machines[0]
50 else: 53 else:
51 raise ValueError("Could not autodetect machine type. More than one entry in %s. Maybe --machine qemux86-64?" % args.dir) 54 raise ValueError("Could not autodetect machine type. More than one entry in %s. Maybe --machine qemux86-64?" % args.dir)
55
56 # If using an overlay with U-Boot, copy the rom when we create the
57 # overlay so that we can keep it around just in case.
52 if args.efi: 58 if args.efi:
53 self.bios = 'OVMF.fd' 59 self.bios = 'OVMF.fd'
54 else: 60 else:
55 uboot = abspath(join(args.dir, self.machine, 'u-boot-qemux86-64.rom')) 61 uboot_path = abspath(join(args.dir, self.machine, 'u-boot-qemux86-64.rom'))
56 if not exists(uboot): 62 if self.overlay:
57 raise ValueError("U-Boot image %s does not exist" % uboot) 63 new_uboot_path = self.overlay + '.u-boot.rom'
58 self.bios = uboot 64 if not exists(self.overlay):
65 if not exists(uboot_path):
66 raise ValueError("U-Boot image %s does not exist" % uboot_path)
67 if not exists(new_uboot_path):
68 if self.dry_run:
69 print("cp %s %s" % (uboot_path, new_uboot_path))
70 else:
71 copyfile(uboot_path, new_uboot_path)
72 uboot_path = new_uboot_path
73 if not exists(uboot_path) and not (self.dry_run and not exists(self.overlay)):
74 raise ValueError("U-Boot image %s does not exist" % uboot_path)
75 self.bios = uboot_path
76
77 # If using an overlay, we need to keep the "backing" image around, as
78 # bitbake will often clean it up, and the overlay silently depends on
79 # the hardcoded path. The easiest solution is to keep the file and use
80 # a relative path to it.
59 if exists(args.imagename): 81 if exists(args.imagename):
60 image = args.imagename 82 image = realpath(args.imagename)
61 else: 83 else:
62 ext = EXTENSIONS.get(self.machine, 'wic') 84 ext = EXTENSIONS.get(self.machine, 'wic')
63 image = join(args.dir, self.machine, '%s-%s.%s' % (args.imagename, self.machine, ext)) 85 image = join(args.dir, self.machine, '%s-%s.%s' % (args.imagename, self.machine, ext))
64 self.image = realpath(image) 86 if self.overlay:
65 if not exists(self.image): 87 new_image_path = self.overlay + '.img'
88 if not exists(self.overlay):
89 if not exists(image):
90 raise ValueError("OS image %s does not exist" % image)
91 if not exists(new_image_path):
92 if self.dry_run:
93 print("cp %s %s" % (image, new_image_path))
94 else:
95 copyfile(image, new_image_path)
96 self.image = new_image_path
97 else:
98 self.image = realpath(image)
99 if not exists(self.image) and not (self.dry_run and not exists(self.overlay)):
66 raise ValueError("OS image %s does not exist" % self.image) 100 raise ValueError("OS image %s does not exist" % self.image)
101
67 if args.mac: 102 if args.mac:
68 self.mac_address = args.mac 103 self.mac_address = args.mac
69 else: 104 else:
@@ -86,7 +121,6 @@ class QemuCommand(object):
86 self.gui = not args.no_gui 121 self.gui = not args.no_gui
87 self.gdb = args.gdb 122 self.gdb = args.gdb
88 self.pcap = args.pcap 123 self.pcap = args.pcap
89 self.overlay = args.overlay
90 self.secondary_network = args.secondary_network 124 self.secondary_network = args.secondary_network
91 125
92 def command_line(self): 126 def command_line(self):
diff --git a/scripts/run-qemu-ota b/scripts/run-qemu-ota
index de63297..232ee11 100755
--- a/scripts/run-qemu-ota
+++ b/scripts/run-qemu-ota
@@ -2,7 +2,7 @@
2 2
3from argparse import ArgumentParser 3from argparse import ArgumentParser
4from subprocess import Popen 4from subprocess import Popen
5from os.path import exists 5from os.path import exists, dirname
6import sys 6import sys
7from qemucommand import QemuCommand 7from qemucommand import QemuCommand
8 8
@@ -39,27 +39,37 @@ def main():
39 'This can be used to test Uptane Primary/Secondary communication.') 39 'This can be used to test Uptane Primary/Secondary communication.')
40 parser.add_argument('-n', '--dry-run', help='Print qemu command line rather then run it', action='store_true') 40 parser.add_argument('-n', '--dry-run', help='Print qemu command line rather then run it', action='store_true')
41 args = parser.parse_args() 41 args = parser.parse_args()
42
43 if args.overlay and not exists(args.overlay) and dirname(args.overlay) and not dirname(args.overlay) == '.':
44 print('Error: please provide a file name in the current working directory. ' +
45 'Overlays do not work properly with other directories.')
46 sys.exit(1)
47 if args.overlay and exists(args.overlay) and args.imagename != parser.get_default('imagename'):
48 # qemu-img amend -o <filename> might work, but it has not yet been done
49 # successfully.
50 print('Warning: cannot change backing image of overlay after it has been created.')
51
42 try: 52 try:
43 qemu_command = QemuCommand(args) 53 qemu_command = QemuCommand(args)
44 except ValueError as e: 54 except ValueError as e:
45 print(e.message) 55 print(e.message)
46 sys.exit(1) 56 sys.exit(1)
47 57
48 print("Launching %s with mac address %s" % (args.imagename, qemu_command.mac_address))
49 print("To connect via SSH:")
50 print(" ssh -o StrictHostKeyChecking=no root@localhost -p %d" % qemu_command.ssh_port)
51 print("To connect to the serial console:")
52 print(" nc localhost %d" % qemu_command.serial_port)
53
54 cmdline = qemu_command.command_line() 58 cmdline = qemu_command.command_line()
55 if args.overlay and not exists(args.overlay): 59 if args.overlay and not exists(args.overlay):
56 print("Image file %s does not yet exist, creating." % args.overlay) 60 print("Overlay file %s does not yet exist, creating." % args.overlay)
57 img_cmdline = qemu_command.img_command_line() 61 img_cmdline = qemu_command.img_command_line()
58 if args.dry_run: 62 if args.dry_run:
59 print(" ".join(img_cmdline)) 63 print(" ".join(img_cmdline))
60 else: 64 else:
61 Popen(img_cmdline).wait() 65 Popen(img_cmdline).wait()
62 66
67 print("Launching %s with mac address %s" % (args.imagename, qemu_command.mac_address))
68 print("To connect via SSH:")
69 print(" ssh -o StrictHostKeyChecking=no root@localhost -p %d" % qemu_command.ssh_port)
70 print("To connect to the serial console:")
71 print(" nc localhost %d" % qemu_command.serial_port)
72
63 if args.dry_run: 73 if args.dry_run:
64 print(" ".join(cmdline)) 74 print(" ".join(cmdline))
65 else: 75 else: