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:31 +0000
commit0d1023673b356c430a2370507cea973e7c8efa47 (patch)
tree93da2358b80db9ed118bbcbb0fedbe772241ded9 /scripts/runqemu
parent80b0e933a016f5575f3c6536359940da98e42eee (diff)
downloadpoky-0d1023673b356c430a2370507cea973e7c8efa47.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. (From OE-Core rev: d5c38964a4458aa31ec37810773ecc4f5d410dbe) 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):
1058 1058
1059 self.nfs_running = True 1059 self.nfs_running = True
1060 1060
1061 def setup_cmd(self):
1062 cmd = self.get('QB_SETUP_CMD')
1063 if cmd != '':
1064 logger.info('Running setup command %s' % str(cmd))
1065 if subprocess.call(cmd, shell=True) != 0:
1066 raise RunQemuError('Failed to run %s' % cmd)
1067
1061 def setup_net_bridge(self): 1068 def setup_net_bridge(self):
1062 self.set('NETWORK_CMD', '-netdev bridge,br=%s,id=net0,helper=%s -device virtio-net-pci,netdev=net0 ' % ( 1069 self.set('NETWORK_CMD', '-netdev bridge,br=%s,id=net0,helper=%s -device virtio-net-pci,netdev=net0 ' % (
1063 self.net_bridge, os.path.join(self.bindir_native, 'qemu-oe-bridge-helper'))) 1070 self.net_bridge, os.path.join(self.bindir_native, 'qemu-oe-bridge-helper')))
@@ -1526,6 +1533,13 @@ class BaseConfig(object):
1526 else: 1533 else:
1527 logger.error("Failed to run qemu: %s", process.stderr.read().decode()) 1534 logger.error("Failed to run qemu: %s", process.stderr.read().decode())
1528 1535
1536 def cleanup_cmd(self):
1537 cmd = self.get('QB_CLEANUP_CMD')
1538 if cmd != '':
1539 logger.info('Running cleanup command %s' % str(cmd))
1540 if subprocess.call(cmd, shell=True) != 0:
1541 raise RunQemuError('Failed to run %s' % cmd)
1542
1529 def cleanup(self): 1543 def cleanup(self):
1530 if self.cleaned: 1544 if self.cleaned:
1531 return 1545 return
@@ -1654,6 +1668,7 @@ def main():
1654 config.setup_network() 1668 config.setup_network()
1655 config.setup_rootfs() 1669 config.setup_rootfs()
1656 config.setup_final() 1670 config.setup_final()
1671 config.setup_cmd()
1657 config.start_qemu() 1672 config.start_qemu()
1658 except RunQemuError as err: 1673 except RunQemuError as err:
1659 logger.error(err) 1674 logger.error(err)
@@ -1663,6 +1678,7 @@ def main():
1663 traceback.print_exc() 1678 traceback.print_exc()
1664 return 1 1679 return 1
1665 finally: 1680 finally:
1681 config.cleanup_cmd()
1666 config.cleanup() 1682 config.cleanup()
1667 # Deliberately ignore the return code of 'tput smam'. 1683 # Deliberately ignore the return code of 'tput smam'.
1668 subprocess.call(["tput", "smam"]) 1684 subprocess.call(["tput", "smam"])