summaryrefslogtreecommitdiffstats
path: root/scripts/runqemu
diff options
context:
space:
mode:
authorMikko Rapeli <mikko.rapeli@linaro.org>2022-12-14 10:54:25 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-12-21 10:16:25 +0000
commitd5c38964a4458aa31ec37810773ecc4f5d410dbe (patch)
tree22c80ce07527aba4b22cea7d81ac99427bdfa452 /scripts/runqemu
parent52371624313184e1a825519160c3833e282df8b9 (diff)
downloadopenembedded-core-d5c38964a4458aa31ec37810773ecc4f5d410dbe.tar.gz
runqemu: add QB_SETUP_CMD and QB_CLEANUP_CMD
These enable running custom shell setup and cleanup commands before and after qemu. Enables machine configurations to for example run qemu with swtpm to emulate TPM devices. Example config with meta-tpm2 based swtpm in machine config: * image recipe depens on swtpm-native to get the native tools to PATH, same handling as qemu itself do_testimage[depends] += "swtpm-native:do_populate_sysroot" * startup commands for swtpm daemon, note that swtpm socket file has 107 character limit and absolute paths to build environment will not work QB_SETUP_CMD = " \ test -d '${IMAGE_BASENAME}_swtpm' || ( mkdir -p '${IMAGE_BASENAME}_swtpm' && \ swtpm_setup --tpmstate '${IMAGE_BASENAME}_swtpm' --tpm2 --pcr-banks sha256 ); \ swtpm socket --tpmstate dir='${IMAGE_BASENAME}_swtpm' \ --ctrl type=unixio,path='${IMAGE_BASENAME}_swtpm/swtpm-sock' \ --log level=40 --tpm2 -t -d \ " * qemu startup command in machine config is configured enable swtpm device QB_OPT_APPEND += "-chardev socket,id=chrtpm,path='${IMAGE_BASENAME}_swtpm/swtpm-sock' -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-tis-device,tpmdev=tpm0" * in this case, swtpm daemon stops automatically with qemu machine, but QB_CLEANUP_CMD could be used to kill a specific process and wipe temporary files Now runqemu and testimage.bbclass can be used with swtpm. Signed-off-by: Mikko Rapeli <mikko.rapeli@linaro.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/runqemu')
-rwxr-xr-xscripts/runqemu16
1 files changed, 16 insertions, 0 deletions
diff --git a/scripts/runqemu b/scripts/runqemu
index 04728673de..ccc557f308 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -1058,6 +1058,13 @@ class BaseConfig(object):
self.nfs_running = True
+ def setup_cmd(self):
+ cmd = self.get('QB_SETUP_CMD')
+ if cmd != '':
+ logger.info('Running setup command %s' % str(cmd))
+ if subprocess.call(cmd, shell=True) != 0:
+ raise RunQemuError('Failed to run %s' % cmd)
+
def setup_net_bridge(self):
self.set('NETWORK_CMD', '-netdev bridge,br=%s,id=net0,helper=%s -device virtio-net-pci,netdev=net0 ' % (
self.net_bridge, os.path.join(self.bindir_native, 'qemu-oe-bridge-helper')))
@@ -1526,6 +1533,13 @@ class BaseConfig(object):
else:
logger.error("Failed to run qemu: %s", process.stderr.read().decode())
+ def cleanup_cmd(self):
+ cmd = self.get('QB_CLEANUP_CMD')
+ if cmd != '':
+ logger.info('Running cleanup command %s' % str(cmd))
+ if subprocess.call(cmd, shell=True) != 0:
+ raise RunQemuError('Failed to run %s' % cmd)
+
def cleanup(self):
if self.cleaned:
return
@@ -1654,6 +1668,7 @@ def main():
config.setup_network()
config.setup_rootfs()
config.setup_final()
+ config.setup_cmd()
config.start_qemu()
except RunQemuError as err:
logger.error(err)
@@ -1663,6 +1678,7 @@ def main():
traceback.print_exc()
return 1
finally:
+ config.cleanup_cmd()
config.cleanup()
# Deliberately ignore the return code of 'tput smam'.
subprocess.call(["tput", "smam"])