runqemu 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  1. #!/usr/bin/env python3
  2. # Handle running OE images standalone with QEMU
  3. #
  4. # Copyright (C) 2006-2011 Linux Foundation
  5. # Copyright (c) 2016 Wind River Systems, Inc.
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License version 2 as
  9. # published by the Free Software Foundation.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License along
  17. # with this program; if not, write to the Free Software Foundation, Inc.,
  18. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. import os
  20. import sys
  21. import logging
  22. import subprocess
  23. import re
  24. import fcntl
  25. import shutil
  26. import glob
  27. import configparser
  28. class OEPathError(Exception):
  29. """Custom Exception to give better guidance on missing binaries"""
  30. def __init__(self, message):
  31. self.message = "In order for this script to dynamically infer paths\n \
  32. kernels or filesystem images, you either need bitbake in your PATH\n \
  33. or to source oe-init-build-env before running this script.\n\n \
  34. Dynamic path inference can be avoided by passing a *.qemuboot.conf to\n \
  35. runqemu, i.e. `runqemu /path/to/my-image-name.qemuboot.conf`\n\n %s" % message
  36. def create_logger():
  37. logger = logging.getLogger('runqemu')
  38. logger.setLevel(logging.INFO)
  39. # create console handler and set level to debug
  40. ch = logging.StreamHandler()
  41. ch.setLevel(logging.INFO)
  42. # create formatter
  43. formatter = logging.Formatter('%(name)s - %(levelname)s - %(message)s')
  44. # add formatter to ch
  45. ch.setFormatter(formatter)
  46. # add ch to logger
  47. logger.addHandler(ch)
  48. return logger
  49. logger = create_logger()
  50. def print_usage():
  51. print("""
  52. Usage: you can run this script with any valid combination
  53. of the following environment variables (in any order):
  54. KERNEL - the kernel image file to use
  55. ROOTFS - the rootfs image file or nfsroot directory to use
  56. MACHINE - the machine name (optional, autodetected from KERNEL filename if unspecified)
  57. Simplified QEMU command-line options can be passed with:
  58. nographic - disable video console
  59. serial - enable a serial console on /dev/ttyS0
  60. slirp - enable user networking, no root privileges is required
  61. kvm - enable KVM when running x86/x86_64 (VT-capable CPU required)
  62. kvm-vhost - enable KVM with vhost when running x86/x86_64 (VT-capable CPU required)
  63. publicvnc - enable a VNC server open to all hosts
  64. audio - enable audio
  65. tcpserial=<port> - specify tcp serial port number
  66. biosdir=<dir> - specify custom bios dir
  67. biosfilename=<filename> - specify bios filename
  68. qemuparams=<xyz> - specify custom parameters to QEMU
  69. bootparams=<xyz> - specify custom kernel parameters during boot
  70. help: print this text
  71. Examples:
  72. runqemu qemuarm
  73. runqemu tmp/deploy/images/qemuarm
  74. runqemu tmp/deploy/images/qemux86/.qemuboot.conf
  75. runqemu qemux86-64 core-image-sato ext4
  76. runqemu qemux86-64 wic-image-minimal wic
  77. runqemu path/to/bzImage-qemux86.bin path/to/nfsrootdir/ serial
  78. runqemu qemux86 iso/hddimg/vmdk/qcow2/vdi/ramfs/cpio.gz...
  79. runqemu qemux86 qemuparams="-m 256"
  80. runqemu qemux86 bootparams="psplash=false"
  81. runqemu path/to/<image>-<machine>.vmdk
  82. runqemu path/to/<image>-<machine>.wic
  83. """)
  84. def check_tun():
  85. """Check /dev/net/run"""
  86. dev_tun = '/dev/net/tun'
  87. if not os.path.exists(dev_tun):
  88. raise Exception("TUN control device %s is unavailable; you may need to enable TUN (e.g. sudo modprobe tun)" % dev_tun)
  89. if not os.access(dev_tun, os.W_OK):
  90. raise Exception("TUN control device %s is not writable, please fix (e.g. sudo chmod 666 %s)" % (dev_tun, dev_tun))
  91. def check_libgl(qemu_bin):
  92. cmd = 'ldd %s' % qemu_bin
  93. logger.info('Running %s...' % cmd)
  94. need_gl = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8')
  95. if re.search('libGLU', need_gl):
  96. # We can't run without a libGL.so
  97. libgl = False
  98. check_files = (('/usr/lib/libGL.so', '/usr/lib/libGLU.so'), \
  99. ('/usr/lib64/libGL.so', '/usr/lib64/libGLU.so'), \
  100. ('/usr/lib/*-linux-gnu/libGL.so', '/usr/lib/*-linux-gnu/libGLU.so'))
  101. for (f1, f2) in check_files:
  102. if re.search('\*', f1):
  103. for g1 in glob.glob(f1):
  104. if libgl:
  105. break
  106. if os.path.exists(g1):
  107. for g2 in glob.glob(f2):
  108. if os.path.exists(g2):
  109. libgl = True
  110. break
  111. if libgl:
  112. break
  113. else:
  114. if os.path.exists(f1) and os.path.exists(f2):
  115. libgl = True
  116. break
  117. if not libgl:
  118. logger.error("You need libGL.so and libGLU.so to exist in your library path to run the QEMU emulator.")
  119. logger.error("Ubuntu package names are: libgl1-mesa-dev and libglu1-mesa-dev.")
  120. logger.error("Fedora package names are: mesa-libGL-devel mesa-libGLU-devel.")
  121. raise Exception('%s requires libGLU, but not found' % qemu_bin)
  122. def get_first_file(cmds):
  123. """Return first file found in wildcard cmds"""
  124. for cmd in cmds:
  125. all_files = glob.glob(cmd)
  126. if all_files:
  127. for f in all_files:
  128. if not os.path.isdir(f):
  129. return f
  130. return ''
  131. class BaseConfig(object):
  132. def __init__(self):
  133. # Vars can be merged with .qemuboot.conf, use a dict to manage them.
  134. self.d = {
  135. 'MACHINE': '',
  136. 'DEPLOY_DIR_IMAGE': '',
  137. 'QB_KERNEL_ROOT': '/dev/vda',
  138. }
  139. self.qemu_opt = ''
  140. self.qemu_opt_script = ''
  141. self.nfs_dir = ''
  142. self.clean_nfs_dir = False
  143. self.nfs_server = ''
  144. self.rootfs = ''
  145. self.qemuboot = ''
  146. self.qbconfload = False
  147. self.kernel = ''
  148. self.kernel_cmdline = ''
  149. self.kernel_cmdline_script = ''
  150. self.dtb = ''
  151. self.fstype = ''
  152. self.kvm_enabled = False
  153. self.vhost_enabled = False
  154. self.slirp_enabled = False
  155. self.nfs_instance = 0
  156. self.nfs_running = False
  157. self.serialstdio = False
  158. self.cleantap = False
  159. self.saved_stty = ''
  160. self.audio_enabled = False
  161. self.tcpserial_portnum = ''
  162. self.custombiosdir = ''
  163. self.lock = ''
  164. self.lock_descriptor = ''
  165. self.bitbake_e = ''
  166. self.snapshot = False
  167. self.fstypes = ('ext2', 'ext3', 'ext4', 'jffs2', 'nfs', 'btrfs', 'cpio.gz', 'cpio', 'ramfs')
  168. self.vmtypes = ('hddimg', 'hdddirect', 'wic', 'vmdk', 'qcow2', 'vdi', 'iso')
  169. def acquire_lock(self):
  170. logger.info("Acquiring lockfile %s..." % self.lock)
  171. try:
  172. self.lock_descriptor = open(self.lock, 'w')
  173. fcntl.flock(self.lock_descriptor, fcntl.LOCK_EX|fcntl.LOCK_NB)
  174. except Exception as e:
  175. logger.info("Acquiring lockfile %s failed: %s" % (self.lock, e))
  176. if self.lock_descriptor:
  177. self.lock_descriptor.close()
  178. return False
  179. return True
  180. def release_lock(self):
  181. fcntl.flock(self.lock_descriptor, fcntl.LOCK_UN)
  182. self.lock_descriptor.close()
  183. os.remove(self.lock)
  184. def get(self, key):
  185. if key in self.d:
  186. return self.d.get(key)
  187. else:
  188. return ''
  189. def set(self, key, value):
  190. self.d[key] = value
  191. def is_deploy_dir_image(self, p):
  192. if os.path.isdir(p):
  193. if not re.search('.qemuboot.conf$', '\n'.join(os.listdir(p)), re.M):
  194. logger.info("Can't find required *.qemuboot.conf in %s" % p)
  195. return False
  196. if not re.search('-image-', '\n'.join(os.listdir(p))):
  197. logger.info("Can't find *-image-* in %s" % p)
  198. return False
  199. return True
  200. else:
  201. return False
  202. def check_arg_fstype(self, fst):
  203. """Check and set FSTYPE"""
  204. if fst not in self.fstypes + self.vmtypes:
  205. logger.warn("Maybe unsupported FSTYPE: %s" % fst)
  206. if not self.fstype or self.fstype == fst:
  207. if fst == 'ramfs':
  208. fst = 'cpio.gz'
  209. self.fstype = fst
  210. else:
  211. raise Exception("Conflicting: FSTYPE %s and %s" % (self.fstype, fst))
  212. def set_machine_deploy_dir(self, machine, deploy_dir_image):
  213. """Set MACHINE and DEPLOY_DIR_IMAGE"""
  214. logger.info('MACHINE: %s' % machine)
  215. self.set("MACHINE", machine)
  216. logger.info('DEPLOY_DIR_IMAGE: %s' % deploy_dir_image)
  217. self.set("DEPLOY_DIR_IMAGE", deploy_dir_image)
  218. def check_arg_nfs(self, p):
  219. if os.path.isdir(p):
  220. self.nfs_dir = p
  221. else:
  222. m = re.match('(.*):(.*)', p)
  223. self.nfs_server = m.group(1)
  224. self.nfs_dir = m.group(2)
  225. self.rootfs = ""
  226. self.check_arg_fstype('nfs')
  227. def check_arg_path(self, p):
  228. """
  229. - Check whether it is <image>.qemuboot.conf or contains <image>.qemuboot.conf
  230. - Check whether is a kernel file
  231. - Check whether is a image file
  232. - Check whether it is a nfs dir
  233. """
  234. if p.endswith('.qemuboot.conf'):
  235. self.qemuboot = p
  236. self.qbconfload = True
  237. elif re.search('\.bin$', p) or re.search('bzImage', p) or \
  238. re.search('zImage', p) or re.search('vmlinux', p) or \
  239. re.search('fitImage', p) or re.search('uImage', p):
  240. self.kernel = p
  241. elif os.path.exists(p) and (not os.path.isdir(p)) and re.search('-image-', os.path.basename(p)):
  242. self.rootfs = p
  243. dirpath = os.path.dirname(p)
  244. m = re.search('(.*)\.(.*)$', p)
  245. if m:
  246. qb = '%s%s' % (re.sub('\.rootfs$', '', m.group(1)), '.qemuboot.conf')
  247. if os.path.exists(qb):
  248. self.qemuboot = qb
  249. self.qbconfload = True
  250. else:
  251. logger.warn("%s doesn't exist" % qb)
  252. fst = m.group(2)
  253. self.check_arg_fstype(fst)
  254. else:
  255. raise Exception("Can't find FSTYPE from: %s" % p)
  256. elif os.path.isdir(p) or re.search(':', arg) and re.search('/', arg):
  257. if self.is_deploy_dir_image(p):
  258. logger.info('DEPLOY_DIR_IMAGE: %s' % p)
  259. self.set("DEPLOY_DIR_IMAGE", p)
  260. else:
  261. logger.info("Assuming %s is an nfs rootfs" % p)
  262. self.check_arg_nfs(p)
  263. else:
  264. raise Exception("Unknown path arg %s" % p)
  265. def check_arg_machine(self, arg):
  266. """Check whether it is a machine"""
  267. if self.get('MACHINE') and self.get('MACHINE') != arg or re.search('/', arg):
  268. raise Exception("Unknown arg: %s" % arg)
  269. elif self.get('MACHINE') == arg:
  270. return
  271. logger.info('Assuming MACHINE = %s' % arg)
  272. # if we're running under testimage, or similarly as a child
  273. # of an existing bitbake invocation, we can't invoke bitbake
  274. # to validate the MACHINE setting and must assume it's correct...
  275. # FIXME: testimage.bbclass exports these two variables into env,
  276. # are there other scenarios in which we need to support being
  277. # invoked by bitbake?
  278. deploy = os.environ.get('DEPLOY_DIR_IMAGE')
  279. bbchild = deploy and os.environ.get('OE_TMPDIR')
  280. if bbchild:
  281. self.set_machine_deploy_dir(arg, deploy)
  282. return
  283. # also check whether we're running under a sourced toolchain
  284. # environment file
  285. if os.environ.get('OECORE_NATIVE_SYSROOT'):
  286. self.set("MACHINE", arg)
  287. return
  288. cmd = 'MACHINE=%s bitbake -e' % arg
  289. logger.info('Running %s...' % cmd)
  290. self.bitbake_e = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8')
  291. # bitbake -e doesn't report invalid MACHINE as an error, so
  292. # let's check DEPLOY_DIR_IMAGE to make sure that it is a valid
  293. # MACHINE.
  294. s = re.search('^DEPLOY_DIR_IMAGE="(.*)"', self.bitbake_e, re.M)
  295. if s:
  296. deploy_dir_image = s.group(1)
  297. else:
  298. raise Exception("bitbake -e %s" % self.bitbake_e)
  299. if self.is_deploy_dir_image(deploy_dir_image):
  300. self.set_machine_deploy_dir(arg, deploy_dir_image)
  301. else:
  302. logger.error("%s not a directory valid DEPLOY_DIR_IMAGE" % deploy_dir_image)
  303. self.set("MACHINE", arg)
  304. def check_args(self):
  305. unknown_arg = ""
  306. for arg in sys.argv[1:]:
  307. if arg in self.fstypes + self.vmtypes:
  308. self.check_arg_fstype(arg)
  309. elif arg == 'nographic':
  310. self.qemu_opt_script += ' -nographic'
  311. self.kernel_cmdline_script += ' console=ttyS0'
  312. elif arg == 'serial':
  313. self.kernel_cmdline_script += ' console=ttyS0'
  314. self.serialstdio = True
  315. elif arg == 'audio':
  316. logger.info("Enabling audio in qemu")
  317. logger.info("Please install sound drivers in linux host")
  318. self.audio_enabled = True
  319. elif arg == 'kvm':
  320. self.kvm_enabled = True
  321. elif arg == 'kvm-vhost':
  322. self.vhost_enabled = True
  323. elif arg == 'slirp':
  324. self.slirp_enabled = True
  325. elif arg == 'snapshot':
  326. self.snapshot = True
  327. elif arg == 'publicvnc':
  328. self.qemu_opt_script += ' -vnc :0'
  329. elif arg.startswith('tcpserial='):
  330. self.tcpserial_portnum = arg[len('tcpserial='):]
  331. elif arg.startswith('biosdir='):
  332. self.custombiosdir = arg[len('biosdir='):]
  333. elif arg.startswith('biosfilename='):
  334. self.qemu_opt_script += ' -bios %s' % arg[len('biosfilename='):]
  335. elif arg.startswith('qemuparams='):
  336. self.qemu_opt_script += ' %s' % arg[len('qemuparams='):]
  337. elif arg.startswith('bootparams='):
  338. self.kernel_cmdline_script += ' %s' % arg[len('bootparams='):]
  339. elif os.path.exists(arg) or (re.search(':', arg) and re.search('/', arg)):
  340. self.check_arg_path(os.path.abspath(arg))
  341. elif re.search('-image-', arg):
  342. # Lazy rootfs
  343. self.rootfs = arg
  344. else:
  345. # At last, assume is it the MACHINE
  346. if (not unknown_arg) or unknown_arg == arg:
  347. unknown_arg = arg
  348. else:
  349. raise Exception("Can't handle two unknown args: %s %s" % (unknown_arg, arg))
  350. # Check to make sure it is a valid machine
  351. if unknown_arg:
  352. if self.get('MACHINE') == unknown_arg:
  353. return
  354. if not self.get('DEPLOY_DIR_IMAGE'):
  355. # Trying to get DEPLOY_DIR_IMAGE from env.
  356. p = os.getenv('DEPLOY_DIR_IMAGE')
  357. if p and self.is_deploy_dir_image(p):
  358. machine = os.path.basename(p)
  359. if unknown_arg == machine:
  360. self.set_machine_deploy_dir(machine, p)
  361. return
  362. else:
  363. logger.info('DEPLOY_DIR_IMAGE: %s' % p)
  364. self.set("DEPLOY_DIR_IMAGE", p)
  365. self.check_arg_machine(unknown_arg)
  366. def check_kvm(self):
  367. """Check kvm and kvm-host"""
  368. if not (self.kvm_enabled or self.vhost_enabled):
  369. self.qemu_opt_script += ' %s %s' % (self.get('QB_MACHINE'), self.get('QB_CPU'))
  370. return
  371. if not self.get('QB_CPU_KVM'):
  372. raise Exception("QB_CPU_KVM is NULL, this board doesn't support kvm")
  373. self.qemu_opt_script += ' %s %s' % (self.get('QB_MACHINE'), self.get('QB_CPU_KVM'))
  374. yocto_kvm_wiki = "https://wiki.yoctoproject.org/wiki/How_to_enable_KVM_for_Poky_qemu"
  375. yocto_paravirt_kvm_wiki = "https://wiki.yoctoproject.org/wiki/Running_an_x86_Yocto_Linux_image_under_QEMU_KVM"
  376. dev_kvm = '/dev/kvm'
  377. dev_vhost = '/dev/vhost-net'
  378. with open('/proc/cpuinfo', 'r') as f:
  379. kvm_cap = re.search('vmx|svm', "".join(f.readlines()))
  380. if not kvm_cap:
  381. logger.error("You are trying to enable KVM on a cpu without VT support.")
  382. logger.error("Remove kvm from the command-line, or refer:")
  383. raise Exception(yocto_kvm_wiki)
  384. if not os.path.exists(dev_kvm):
  385. logger.error("Missing KVM device. Have you inserted kvm modules?")
  386. logger.error("For further help see:")
  387. raise Exception(yocto_kvm_wiki)
  388. if os.access(dev_kvm, os.W_OK|os.R_OK):
  389. self.qemu_opt_script += ' -enable-kvm'
  390. else:
  391. logger.error("You have no read or write permission on /dev/kvm.")
  392. logger.error("Please change the ownership of this file as described at:")
  393. raise Exception(yocto_kvm_wiki)
  394. if self.vhost_enabled:
  395. if not os.path.exists(dev_vhost):
  396. logger.error("Missing virtio net device. Have you inserted vhost-net module?")
  397. logger.error("For further help see:")
  398. raise Exception(yocto_paravirt_kvm_wiki)
  399. if not os.access(dev_kvm, os.W_OK|os.R_OK):
  400. logger.error("You have no read or write permission on /dev/vhost-net.")
  401. logger.error("Please change the ownership of this file as described at:")
  402. raise Exception(yocto_kvm_wiki)
  403. def check_fstype(self):
  404. """Check and setup FSTYPE"""
  405. if not self.fstype:
  406. fstype = self.get('QB_DEFAULT_FSTYPE')
  407. if fstype:
  408. self.fstype = fstype
  409. else:
  410. raise Exception("FSTYPE is NULL!")
  411. def check_rootfs(self):
  412. """Check and set rootfs"""
  413. if self.fstype == 'nfs':
  414. return
  415. if self.rootfs and not os.path.exists(self.rootfs):
  416. # Lazy rootfs
  417. self.rootfs = "%s/%s-%s.%s" % (self.get('DEPLOY_DIR_IMAGE'),
  418. self.rootfs, self.get('MACHINE'),
  419. self.fstype)
  420. elif not self.rootfs:
  421. cmd_name = '%s/%s*.%s' % (self.get('DEPLOY_DIR_IMAGE'), self.get('IMAGE_NAME'), self.fstype)
  422. cmd_link = '%s/%s*.%s' % (self.get('DEPLOY_DIR_IMAGE'), self.get('IMAGE_LINK_NAME'), self.fstype)
  423. cmds = (cmd_name, cmd_link)
  424. self.rootfs = get_first_file(cmds)
  425. if not self.rootfs:
  426. raise Exception("Failed to find rootfs: %s or %s" % cmds)
  427. if not os.path.exists(self.rootfs):
  428. raise Exception("Can't find rootfs: %s" % self.rootfs)
  429. def check_kernel(self):
  430. """Check and set kernel, dtb"""
  431. # The vm image doesn't need a kernel
  432. if self.fstype in self.vmtypes:
  433. return
  434. # QB_DEFAULT_KERNEL is always a full file path
  435. kernel_name = os.path.basename(self.get('QB_DEFAULT_KERNEL'))
  436. deploy_dir_image = self.get('DEPLOY_DIR_IMAGE')
  437. if not self.kernel:
  438. kernel_match_name = "%s/%s" % (deploy_dir_image, kernel_name)
  439. kernel_match_link = "%s/%s" % (deploy_dir_image, self.get('KERNEL_IMAGETYPE'))
  440. kernel_startswith = "%s/%s*" % (deploy_dir_image, self.get('KERNEL_IMAGETYPE'))
  441. cmds = (kernel_match_name, kernel_match_link, kernel_startswith)
  442. self.kernel = get_first_file(cmds)
  443. if not self.kernel:
  444. raise Exception('KERNEL not found: %s, %s or %s' % cmds)
  445. if not os.path.exists(self.kernel):
  446. raise Exception("KERNEL %s not found" % self.kernel)
  447. dtb = self.get('QB_DTB')
  448. if dtb:
  449. cmd_match = "%s/%s" % (deploy_dir_image, dtb)
  450. cmd_startswith = "%s/%s*" % (deploy_dir_image, dtb)
  451. cmd_wild = "%s/*.dtb" % deploy_dir_image
  452. cmds = (cmd_match, cmd_startswith, cmd_wild)
  453. self.dtb = get_first_file(cmds)
  454. if not os.path.exists(self.dtb):
  455. raise Exception('DTB not found: %s, %s or %s' % cmds)
  456. def check_biosdir(self):
  457. """Check custombiosdir"""
  458. if not self.custombiosdir:
  459. return
  460. biosdir = ""
  461. biosdir_native = "%s/%s" % (self.get('STAGING_DIR_NATIVE'), self.custombiosdir)
  462. biosdir_host = "%s/%s" % (self.get('STAGING_DIR_HOST'), self.custombiosdir)
  463. for i in (self.custombiosdir, biosdir_native, biosdir_host):
  464. if os.path.isdir(i):
  465. biosdir = i
  466. break
  467. if biosdir:
  468. logger.info("Assuming biosdir is: %s" % biosdir)
  469. self.qemu_opt_script += ' -L %s' % biosdir
  470. else:
  471. logger.error("Custom BIOS directory not found. Tried: %s, %s, and %s" % (self.custombiosdir, biosdir_native, biosdir_host))
  472. raise Exception("Invalid custombiosdir: %s" % self.custombiosdir)
  473. def check_mem(self):
  474. s = re.search('-m +([0-9]+)', self.qemu_opt_script)
  475. if s:
  476. self.set('QB_MEM', '-m %s' % s.group(1))
  477. elif not self.get('QB_MEM'):
  478. logger.info('QB_MEM is not set, use 512M by default')
  479. self.set('QB_MEM', '-m 512')
  480. self.kernel_cmdline_script += ' mem=%s' % self.get('QB_MEM').replace('-m','').strip() + 'M'
  481. self.qemu_opt_script += ' %s' % self.get('QB_MEM')
  482. def check_tcpserial(self):
  483. if self.tcpserial_portnum:
  484. if self.get('QB_TCPSERIAL_OPT'):
  485. self.qemu_opt_script += ' ' + self.get('QB_TCPSERIAL_OPT').replace('@PORT@', self.tcpserial_portnum)
  486. else:
  487. self.qemu_opt_script += ' -serial tcp:127.0.0.1:%s' % self.tcpserial_portnum
  488. def check_and_set(self):
  489. """Check configs sanity and set when needed"""
  490. self.validate_paths()
  491. if not self.slirp_enabled:
  492. check_tun()
  493. # Check audio
  494. if self.audio_enabled:
  495. if not self.get('QB_AUDIO_DRV'):
  496. raise Exception("QB_AUDIO_DRV is NULL, this board doesn't support audio")
  497. if not self.get('QB_AUDIO_OPT'):
  498. logger.warn('QB_AUDIO_OPT is NULL, you may need define it to make audio work')
  499. else:
  500. self.qemu_opt_script += ' %s' % self.get('QB_AUDIO_OPT')
  501. os.putenv('QEMU_AUDIO_DRV', self.get('QB_AUDIO_DRV'))
  502. else:
  503. os.putenv('QEMU_AUDIO_DRV', 'none')
  504. self.check_kvm()
  505. self.check_fstype()
  506. self.check_rootfs()
  507. self.check_kernel()
  508. self.check_biosdir()
  509. self.check_mem()
  510. self.check_tcpserial()
  511. def read_qemuboot(self):
  512. if not self.qemuboot:
  513. if self.get('DEPLOY_DIR_IMAGE'):
  514. deploy_dir_image = self.get('DEPLOY_DIR_IMAGE')
  515. elif os.getenv('DEPLOY_DIR_IMAGE'):
  516. deploy_dir_image = os.getenv('DEPLOY_DIR_IMAGE')
  517. else:
  518. logger.info("Can't find qemuboot conf file, DEPLOY_DIR_IMAGE is NULL!")
  519. return
  520. if self.rootfs and not os.path.exists(self.rootfs):
  521. # Lazy rootfs
  522. machine = self.get('MACHINE')
  523. if not machine:
  524. machine = os.path.basename(deploy_dir_image)
  525. self.qemuboot = "%s/%s-%s.qemuboot.conf" % (deploy_dir_image,
  526. self.rootfs, machine)
  527. else:
  528. cmd = 'ls -t %s/*.qemuboot.conf' % deploy_dir_image
  529. logger.info('Running %s...' % cmd)
  530. qbs = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8')
  531. if qbs:
  532. self.qemuboot = qbs.split()[0]
  533. self.qbconfload = True
  534. if not self.qemuboot:
  535. # If we haven't found a .qemuboot.conf at this point it probably
  536. # doesn't exist, continue without
  537. return
  538. if not os.path.exists(self.qemuboot):
  539. raise Exception("Failed to find <image>.qemuboot.conf!")
  540. logger.info('CONFFILE: %s' % self.qemuboot)
  541. cf = configparser.ConfigParser()
  542. cf.read(self.qemuboot)
  543. for k, v in cf.items('config_bsp'):
  544. k_upper = k.upper()
  545. self.set(k_upper, v)
  546. def validate_paths(self):
  547. """Ensure all relevant path variables are set"""
  548. # When we're started with a *.qemuboot.conf arg assume that image
  549. # artefacts are relative to that file, rather than in whatever
  550. # directory DEPLOY_DIR_IMAGE in the conf file points to.
  551. if self.qbconfload:
  552. imgdir = os.path.dirname(self.qemuboot)
  553. if imgdir != self.get('DEPLOY_DIR_IMAGE'):
  554. logger.info('Setting DEPLOY_DIR_IMAGE to folder containing %s (%s)' % (self.qemuboot, imgdir))
  555. self.set('DEPLOY_DIR_IMAGE', imgdir)
  556. # If the STAGING_*_NATIVE directories from the config file don't exist
  557. # and we're in a sourced OE build directory try to extract the paths
  558. # from `bitbake -e`
  559. havenative = os.path.exists(self.get('STAGING_DIR_NATIVE')) and \
  560. os.path.exists(self.get('STAGING_BINDIR_NATIVE'))
  561. if not havenative:
  562. if not self.bitbake_e:
  563. self.load_bitbake_env()
  564. if self.bitbake_e:
  565. native_vars = ['STAGING_DIR_NATIVE', 'STAGING_BINDIR_NATIVE']
  566. for nv in native_vars:
  567. s = re.search('^%s="(.*)"' % nv, self.bitbake_e, re.M)
  568. if s and s.group(1) != self.get(nv):
  569. logger.info('Overriding conf file setting of %s to %s from Bitbake environment' % (nv, s.group(1)))
  570. self.set(nv, s.group(1))
  571. else:
  572. # when we're invoked from a running bitbake instance we won't
  573. # be able to call `bitbake -e`, then try:
  574. # - get OE_TMPDIR from environment and guess paths based on it
  575. # - get OECORE_NATIVE_SYSROOT from environment (for sdk)
  576. tmpdir = os.environ.get('OE_TMPDIR', None)
  577. oecore_native_sysroot = os.environ.get('OECORE_NATIVE_SYSROOT', None)
  578. if tmpdir:
  579. logger.info('Setting STAGING_DIR_NATIVE and STAGING_BINDIR_NATIVE relative to OE_TMPDIR (%s)' % tmpdir)
  580. hostos, _, _, _, machine = os.uname()
  581. buildsys = '%s-%s' % (machine, hostos.lower())
  582. staging_dir_native = '%s/sysroots/%s' % (tmpdir, buildsys)
  583. self.set('STAGING_DIR_NATIVE', staging_dir_native)
  584. elif oecore_native_sysroot:
  585. logger.info('Setting STAGING_DIR_NATIVE to OECORE_NATIVE_SYSROOT (%s)' % oecore_native_sysroot)
  586. self.set('STAGING_DIR_NATIVE', oecore_native_sysroot)
  587. if self.get('STAGING_DIR_NATIVE'):
  588. # we have to assume that STAGING_BINDIR_NATIVE is at usr/bin
  589. staging_bindir_native = '%s/usr/bin' % self.get('STAGING_DIR_NATIVE')
  590. logger.info('Setting STAGING_BINDIR_NATIVE to %s' % staging_bindir_native)
  591. self.set('STAGING_BINDIR_NATIVE', '%s/usr/bin' % self.get('STAGING_DIR_NATIVE'))
  592. def print_config(self):
  593. logger.info('Continuing with the following parameters:\n')
  594. if not self.fstype in self.vmtypes:
  595. print('KERNEL: [%s]' % self.kernel)
  596. if self.dtb:
  597. print('DTB: [%s]' % self.dtb)
  598. print('MACHINE: [%s]' % self.get('MACHINE'))
  599. print('FSTYPE: [%s]' % self.fstype)
  600. if self.fstype == 'nfs':
  601. print('NFS_DIR: [%s]' % self.nfs_dir)
  602. else:
  603. print('ROOTFS: [%s]' % self.rootfs)
  604. print('CONFFILE: [%s]' % self.qemuboot)
  605. print('')
  606. def setup_nfs(self):
  607. if not self.nfs_server:
  608. if self.slirp_enabled:
  609. self.nfs_server = '10.0.2.2'
  610. else:
  611. self.nfs_server = '192.168.7.1'
  612. nfs_instance = int(self.nfs_instance)
  613. mountd_rpcport = 21111 + nfs_instance
  614. nfsd_rpcport = 11111 + nfs_instance
  615. nfsd_port = 3049 + 2 * nfs_instance
  616. mountd_port = 3048 + 2 * nfs_instance
  617. unfs_opts="nfsvers=3,port=%s,mountprog=%s,nfsprog=%s,udp,mountport=%s" % (nfsd_port, mountd_rpcport, nfsd_rpcport, mountd_port)
  618. self.unfs_opts = unfs_opts
  619. p = '%s/.runqemu-sdk/pseudo' % os.getenv('HOME')
  620. os.putenv('PSEUDO_LOCALSTATEDIR', p)
  621. # Extract .tar.bz2 or .tar.bz if no self.nfs_dir
  622. if not self.nfs_dir:
  623. src_prefix = '%s/%s' % (self.get('DEPLOY_DIR_IMAGE'), self.get('IMAGE_LINK_NAME'))
  624. dest = "%s-nfsroot" % src_prefix
  625. if os.path.exists('%s.pseudo_state' % dest):
  626. logger.info('Use %s as NFS_DIR' % dest)
  627. self.nfs_dir = dest
  628. else:
  629. src = ""
  630. src1 = '%s.tar.bz2' % src_prefix
  631. src2 = '%s.tar.gz' % src_prefix
  632. if os.path.exists(src1):
  633. src = src1
  634. elif os.path.exists(src2):
  635. src = src2
  636. if not src:
  637. raise Exception("No NFS_DIR is set, and can't find %s or %s to extract" % (src1, src2))
  638. logger.info('NFS_DIR not found, extracting %s to %s' % (src, dest))
  639. cmd = 'runqemu-extract-sdk %s %s' % (src, dest)
  640. logger.info('Running %s...' % cmd)
  641. if subprocess.call(cmd, shell=True) != 0:
  642. raise Exception('Failed to run %s' % cmd)
  643. self.clean_nfs_dir = True
  644. self.nfs_dir = dest
  645. # Start the userspace NFS server
  646. cmd = 'runqemu-export-rootfs restart %s' % self.nfs_dir
  647. logger.info('Running %s...' % cmd)
  648. if subprocess.call(cmd, shell=True) != 0:
  649. raise Exception('Failed to run %s' % cmd)
  650. self.nfs_running = True
  651. def setup_slirp(self):
  652. if self.fstype == 'nfs':
  653. self.setup_nfs()
  654. self.kernel_cmdline_script += ' ip=dhcp'
  655. self.set('NETWORK_CMD', self.get('QB_SLIRP_OPT'))
  656. def setup_tap(self):
  657. """Setup tap"""
  658. # This file is created when runqemu-gen-tapdevs creates a bank of tap
  659. # devices, indicating that the user should not bring up new ones using
  660. # sudo.
  661. nosudo_flag = '/etc/runqemu-nosudo'
  662. self.qemuifup = shutil.which('runqemu-ifup')
  663. self.qemuifdown = shutil.which('runqemu-ifdown')
  664. ip = shutil.which('ip')
  665. lockdir = "/tmp/qemu-tap-locks"
  666. if not (self.qemuifup and self.qemuifdown and ip):
  667. raise OEPathError("runqemu-ifup, runqemu-ifdown or ip not found")
  668. if not os.path.exists(lockdir):
  669. # There might be a race issue when multi runqemu processess are
  670. # running at the same time.
  671. try:
  672. os.mkdir(lockdir)
  673. except FileExistsError:
  674. pass
  675. cmd = '%s link' % ip
  676. logger.info('Running %s...' % cmd)
  677. ip_link = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8')
  678. # Matches line like: 6: tap0: <foo>
  679. possibles = re.findall('^[1-9]+: +(tap[0-9]+): <.*', ip_link, re.M)
  680. tap = ""
  681. for p in possibles:
  682. lockfile = os.path.join(lockdir, p)
  683. if os.path.exists('%s.skip' % lockfile):
  684. logger.info('Found %s.skip, skipping %s' % (lockfile, p))
  685. continue
  686. self.lock = lockfile + '.lock'
  687. if self.acquire_lock():
  688. tap = p
  689. logger.info("Using preconfigured tap device %s" % tap)
  690. logger.info("If this is not intended, touch %s.skip to make runqemu skip %s." %(lockfile, tap))
  691. break
  692. if not tap:
  693. if os.path.exists(nosudo_flag):
  694. logger.error("Error: There are no available tap devices to use for networking,")
  695. logger.error("and I see %s exists, so I am not going to try creating" % nosudo_flag)
  696. raise Exception("a new one with sudo.")
  697. gid = os.getgid()
  698. uid = os.getuid()
  699. logger.info("Setting up tap interface under sudo")
  700. cmd = 'sudo %s %s %s %s' % (self.qemuifup, uid, gid, self.get('STAGING_DIR_NATIVE'))
  701. tap = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8').rstrip('\n')
  702. lockfile = os.path.join(lockdir, tap)
  703. self.lock = lockfile + '.lock'
  704. self.acquire_lock()
  705. self.cleantap = True
  706. logger.info('Created tap: %s' % tap)
  707. if not tap:
  708. logger.error("Failed to setup tap device. Run runqemu-gen-tapdevs to manually create.")
  709. return 1
  710. self.tap = tap
  711. n0 = tap[3:]
  712. n1 = int(n0) * 2 + 1
  713. n2 = n1 + 1
  714. self.nfs_instance = n0
  715. if self.fstype == 'nfs':
  716. self.setup_nfs()
  717. self.kernel_cmdline_script += " ip=192.168.7.%s::192.168.7.%s:255.255.255.0" % (n2, n1)
  718. mac = "52:54:00:12:34:%02x" % n2
  719. qb_tap_opt = self.get('QB_TAP_OPT')
  720. if qb_tap_opt:
  721. qemu_tap_opt = qb_tap_opt.replace('@TAP@', tap).replace('@MAC@', mac)
  722. else:
  723. qemu_tap_opt = "-device virtio-net-pci,netdev=net0,mac=%s -netdev tap,id=net0,ifname=%s,script=no,downscript=no" % (mac, self.tap)
  724. if self.vhost_enabled:
  725. qemu_tap_opt += ',vhost=on'
  726. self.set('NETWORK_CMD', qemu_tap_opt)
  727. def setup_network(self):
  728. cmd = "stty -g"
  729. self.saved_stty = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8')
  730. if self.slirp_enabled:
  731. self.setup_slirp()
  732. else:
  733. self.setup_tap()
  734. rootfs_format = self.fstype if self.fstype in ('vmdk', 'qcow2', 'vdi') else 'raw'
  735. qb_rootfs_opt = self.get('QB_ROOTFS_OPT')
  736. if qb_rootfs_opt:
  737. self.rootfs_options = qb_rootfs_opt.replace('@ROOTFS@', self.rootfs)
  738. else:
  739. self.rootfs_options = '-drive file=%s,if=virtio,format=%s' % (self.rootfs, rootfs_format)
  740. if self.fstype in ('cpio.gz', 'cpio'):
  741. self.kernel_cmdline = 'root=/dev/ram0 rw debugshell'
  742. self.rootfs_options = '-initrd %s' % self.rootfs
  743. else:
  744. if self.fstype in self.vmtypes:
  745. if self.fstype == 'iso':
  746. vm_drive = '-cdrom %s' % self.rootfs
  747. else:
  748. cmd1 = "grep -q 'root=/dev/sd' %s" % self.rootfs
  749. cmd2 = "grep -q 'root=/dev/hd' %s" % self.rootfs
  750. if subprocess.call(cmd1, shell=True) == 0:
  751. logger.info('Using scsi drive')
  752. vm_drive = '-drive if=none,id=hd,file=%s,format=%s -device virtio-scsi-pci,id=scsi -device scsi-hd,drive=hd' \
  753. % (self.rootfs, rootfs_format)
  754. elif subprocess.call(cmd2, shell=True) == 0:
  755. logger.info('Using scsi drive')
  756. vm_drive = "%s,format=%s" % (self.rootfs, rootfs_format)
  757. else:
  758. logger.warn("Can't detect drive type %s" % self.rootfs)
  759. logger.warn('Tring to use virtio block drive')
  760. vm_drive = '-drive if=virtio,file=%s,format=%s' % (self.rootfs, rootfs_format)
  761. self.rootfs_options = '%s -no-reboot' % vm_drive
  762. self.kernel_cmdline = 'root=%s rw highres=off' % (self.get('QB_KERNEL_ROOT'))
  763. if self.fstype == 'nfs':
  764. self.rootfs_options = ''
  765. k_root = '/dev/nfs nfsroot=%s:%s,%s' % (self.nfs_server, self.nfs_dir, self.unfs_opts)
  766. self.kernel_cmdline = 'root=%s rw highres=off' % k_root
  767. self.set('ROOTFS_OPTIONS', self.rootfs_options)
  768. def guess_qb_system(self):
  769. """attempt to determine the appropriate qemu-system binary"""
  770. mach = self.get('MACHINE')
  771. if not mach:
  772. search = '.*(qemux86-64|qemux86|qemuarm64|qemuarm|qemumips64|qemumips64el|qemumipsel|qemumips|qemuppc).*'
  773. if self.rootfs:
  774. match = re.match(search, self.rootfs)
  775. if match:
  776. mach = match.group(1)
  777. elif self.kernel:
  778. match = re.match(search, self.kernel)
  779. if match:
  780. mach = match.group(1)
  781. if not mach:
  782. return None
  783. if mach == 'qemuarm':
  784. qbsys = 'arm'
  785. elif mach == 'qemuarm64':
  786. qbsys = 'aarch64'
  787. elif mach == 'qemux86':
  788. qbsys = 'i386'
  789. elif mach == 'qemux86-64':
  790. qbsys = 'x86_64'
  791. elif mach == 'qemuppc':
  792. qbsys = 'ppc'
  793. elif mach == 'qemumips':
  794. qbsys = 'mips'
  795. elif mach == 'qemumips64':
  796. qbsys = 'mips64'
  797. elif mach == 'qemumipsel':
  798. qbsys = 'mipsel'
  799. elif mach == 'qemumips64el':
  800. qbsys = 'mips64el'
  801. return 'qemu-system-%s' % qbsys
  802. def setup_final(self):
  803. qemu_system = self.get('QB_SYSTEM_NAME')
  804. if not qemu_system:
  805. qemu_system = self.guess_qb_system()
  806. if not qemu_system:
  807. raise Exception("Failed to boot, QB_SYSTEM_NAME is NULL!")
  808. qemu_bin = '%s/%s' % (self.get('STAGING_BINDIR_NATIVE'), qemu_system)
  809. if not os.access(qemu_bin, os.X_OK):
  810. raise OEPathError("No QEMU binary '%s' could be found" % qemu_bin)
  811. check_libgl(qemu_bin)
  812. self.qemu_opt = "%s %s %s %s %s" % (qemu_bin, self.get('NETWORK_CMD'), self.qemu_opt_script, self.get('ROOTFS_OPTIONS'), self.get('QB_OPT_APPEND'))
  813. if self.snapshot:
  814. self.qemu_opt += " -snapshot"
  815. if self.serialstdio:
  816. logger.info("Interrupt character is '^]'")
  817. cmd = "stty intr ^]"
  818. subprocess.call(cmd, shell=True)
  819. first_serial = ""
  820. if not re.search("-nographic", self.qemu_opt):
  821. first_serial = "-serial mon:vc"
  822. # We always want a ttyS1. Since qemu by default adds a serial
  823. # port when nodefaults is not specified, it seems that all that
  824. # would be needed is to make sure a "-serial" is there. However,
  825. # it appears that when "-serial" is specified, it ignores the
  826. # default serial port that is normally added. So here we make
  827. # sure to add two -serial if there are none. And only one if
  828. # there is one -serial already.
  829. serial_num = len(re.findall("-serial", self.qemu_opt))
  830. if serial_num == 0:
  831. self.qemu_opt += " %s %s" % (first_serial, self.get("QB_SERIAL_OPT"))
  832. elif serial_num == 1:
  833. self.qemu_opt += " %s" % self.get("QB_SERIAL_OPT")
  834. def start_qemu(self):
  835. if self.kernel:
  836. kernel_opts = "-kernel %s -append '%s %s %s'" % (self.kernel, self.kernel_cmdline, self.kernel_cmdline_script, self.get('QB_KERNEL_CMDLINE_APPEND'))
  837. if self.dtb:
  838. kernel_opts += " -dtb %s" % self.dtb
  839. else:
  840. kernel_opts = ""
  841. cmd = "%s %s" % (self.qemu_opt, kernel_opts)
  842. logger.info('Running %s' % cmd)
  843. if subprocess.call(cmd, shell=True) != 0:
  844. raise Exception('Failed to run %s' % cmd)
  845. def cleanup(self):
  846. if self.cleantap:
  847. cmd = 'sudo %s %s %s' % (self.qemuifdown, self.tap, self.get('STAGING_DIR_NATIVE'))
  848. logger.info('Running %s' % cmd)
  849. subprocess.call(cmd, shell=True)
  850. if self.lock_descriptor:
  851. logger.info("Releasing lockfile for tap device '%s'" % self.tap)
  852. self.release_lock()
  853. if self.nfs_running:
  854. logger.info("Shutting down the userspace NFS server...")
  855. cmd = "runqemu-export-rootfs stop %s" % self.nfs_dir
  856. logger.info('Running %s' % cmd)
  857. subprocess.call(cmd, shell=True)
  858. if self.saved_stty:
  859. cmd = "stty %s" % self.saved_stty
  860. subprocess.call(cmd, shell=True)
  861. if self.clean_nfs_dir:
  862. logger.info('Removing %s' % self.nfs_dir)
  863. shutil.rmtree(self.nfs_dir)
  864. shutil.rmtree('%s.pseudo_state' % self.nfs_dir)
  865. def load_bitbake_env(self, mach=None):
  866. if self.bitbake_e:
  867. return
  868. bitbake = shutil.which('bitbake')
  869. if not bitbake:
  870. return
  871. if not mach:
  872. mach = self.get('MACHINE')
  873. if mach:
  874. cmd = 'MACHINE=%s bitbake -e' % mach
  875. else:
  876. cmd = 'bitbake -e'
  877. logger.info('Running %s...' % cmd)
  878. try:
  879. self.bitbake_e = subprocess.check_output(cmd, shell=True).decode('utf-8')
  880. except subprocess.CalledProcessError as err:
  881. self.bitbake_e = ''
  882. logger.warn("Couldn't run 'bitbake -e' to gather environment information:\n%s" % err.output.decode('utf-8'))
  883. def main():
  884. if len(sys.argv) == 1 or "help" in sys.argv:
  885. print_usage()
  886. return 0
  887. config = BaseConfig()
  888. try:
  889. config.check_args()
  890. except Exception as esc:
  891. logger.error(esc)
  892. logger.error("Try 'runqemu help' on how to use it")
  893. return 1
  894. config.read_qemuboot()
  895. config.check_and_set()
  896. config.print_config()
  897. try:
  898. config.setup_network()
  899. config.setup_final()
  900. config.start_qemu()
  901. finally:
  902. config.cleanup()
  903. return 0
  904. if __name__ == "__main__":
  905. try:
  906. ret = main()
  907. except OEPathError as err:
  908. ret = 1
  909. logger.error(err.message)
  910. except Exception as esc:
  911. ret = 1
  912. import traceback
  913. traceback.print_exc()
  914. sys.exit(ret)