diff options
author | Patrick Vacek <patrickvacek@gmail.com> | 2019-09-06 16:42:37 +0200 |
---|---|---|
committer | Patrick Vacek <patrickvacek@gmail.com> | 2019-09-06 16:42:37 +0200 |
commit | e06640f8f1170ad868db3ecb1af9ff1d2f60c1a2 (patch) | |
tree | 3eb4a960d616f0e071da26f91ab16a7e42385d56 | |
parent | f4c7b3d831f232c312b50d52ff296c4678eb475b (diff) | |
download | meta-updater-e06640f8f1170ad868db3ecb1af9ff1d2f60c1a2.tar.gz |
Copy the image and U-Boot rom when using overlays.
Since bitbake can remove old images that an overlay was non-obviously
dependent on, the safest thing to do is make a copy of the image and
keep it alongside the overlay. When using the overlay later,
automatically use that image. Also do the same thing with the U-Boot
rom. This should also make moving the overlay file to another machine
much easier.
Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
-rw-r--r-- | scripts/qemucommand.py | 50 | ||||
-rwxr-xr-x | scripts/run-qemu-ota | 2 |
2 files changed, 43 insertions, 9 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 | |||
2 | from os import listdir | 2 | from os import listdir |
3 | import random | 3 | import random |
4 | import socket | 4 | import socket |
5 | from shutil import copyfile | ||
5 | from subprocess import check_output | 6 | from subprocess import check_output |
6 | 7 | ||
7 | EXTENSIONS = { | 8 | EXTENSIONS = { |
@@ -39,6 +40,8 @@ def random_mac(): | |||
39 | 40 | ||
40 | class QemuCommand(object): | 41 | class 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..e9f44d6 100755 --- a/scripts/run-qemu-ota +++ b/scripts/run-qemu-ota | |||
@@ -53,7 +53,7 @@ def main(): | |||
53 | 53 | ||
54 | cmdline = qemu_command.command_line() | 54 | cmdline = qemu_command.command_line() |
55 | if args.overlay and not exists(args.overlay): | 55 | if args.overlay and not exists(args.overlay): |
56 | print("Image file %s does not yet exist, creating." % args.overlay) | 56 | print("Overlay file %s does not yet exist, creating." % args.overlay) |
57 | img_cmdline = qemu_command.img_command_line() | 57 | img_cmdline = qemu_command.img_command_line() |
58 | if args.dry_run: | 58 | if args.dry_run: |
59 | print(" ".join(img_cmdline)) | 59 | print(" ".join(img_cmdline)) |