blob: 3468d1c67049af8eb5edd38ab42e2362fb1adf4b [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001# Help runqemu boot target board, "QB" means Qemu Boot, the following
2# vars can be set in conf files, such as <bsp.conf> to make it can be
3# boot by runqemu:
4#
5# QB_SYSTEM_NAME: qemu name, e.g., "qemu-system-i386"
Brad Bishop6e60e8b2018-02-01 10:27:11 -05006#
Patrick Williamsc0f7c042017-02-23 20:41:17 -06007# QB_OPT_APPEND: options to append to qemu, e.g., "-show-cursor"
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008#
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009# QB_DEFAULT_KERNEL: default kernel to boot, e.g., "bzImage"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011# QB_DEFAULT_FSTYPE: default FSTYPE to boot, e.g., "ext4"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060013# QB_MEM: memory, e.g., "-m 512"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050014#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060015# QB_MACHINE: qemu machine, e.g., "-machine virt"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050016#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060017# QB_CPU: qemu cpu, e.g., "-cpu qemu32"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050018#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060019# QB_CPU_KVM: the similar to QB_CPU, but used when kvm, e.g., '-cpu kvm64',
20# set it when support kvm.
Brad Bishop6e60e8b2018-02-01 10:27:11 -050021#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060022# QB_KERNEL_CMDLINE_APPEND: options to append to kernel's -append
23# option, e.g., "console=ttyS0 console=tty"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050024#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060025# QB_DTB: qemu dtb name
Brad Bishop6e60e8b2018-02-01 10:27:11 -050026#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060027# QB_AUDIO_DRV: qemu audio driver, e.g., "alsa", set it when support audio
Brad Bishop6e60e8b2018-02-01 10:27:11 -050028#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060029# QB_AUDIO_OPT: qemu audio option, e.g., "-soundhw ac97,es1370", used
30# when QB_AUDIO_DRV is set.
Brad Bishop6e60e8b2018-02-01 10:27:11 -050031#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060032# QB_KERNEL_ROOT: kernel's root, e.g., /dev/vda
Brad Bishop6e60e8b2018-02-01 10:27:11 -050033#
34# QB_NETWORK_DEVICE: network device, e.g., "-device virtio-net-pci,netdev=net0,mac=@MAC@",
35# it needs work with QB_TAP_OPT and QB_SLIRP_OPT.
36# Note, runqemu will replace @MAC@ with a predefined mac, you can set
37# a custom one, but that may cause conflicts when multiple qemus are
38# running on the same host.
39#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060040# QB_TAP_OPT: netowrk option for 'tap' mode, e.g.,
Brad Bishop6e60e8b2018-02-01 10:27:11 -050041# "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060042# Note, runqemu will replace "@TAP@" with the one which is used, such as tap0, tap1 ...
Brad Bishop6e60e8b2018-02-01 10:27:11 -050043#
44# QB_SLIRP_OPT: network option for SLIRP mode, e.g., -netdev user,id=net0"
45#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060046# QB_ROOTFS_OPT: used as rootfs, e.g.,
47# "-drive id=disk0,file=@ROOTFS@,if=none,format=raw -device virtio-blk-device,drive=disk0"
48# Note, runqemu will replace "@ROOTFS@" with the one which is used, such as core-image-minimal-qemuarm64.ext4.
Brad Bishop6e60e8b2018-02-01 10:27:11 -050049#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060050# QB_SERIAL_OPT: serial port, e.g., "-serial mon:stdio"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050051#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060052# QB_TCPSERIAL_OPT: tcp serial port option, e.g.,
53# " -device virtio-serial-device -chardev socket,id=virtcon,port=@PORT@,host=127.0.0.1 -device virtconsole,chardev=virtcon"
54# Note, runqemu will replace "@PORT@" with the port number which is used.
55#
56# Usage:
57# IMAGE_CLASSES += "qemuboot"
58# See "runqemu help" for more info
59
60QB_MEM ?= "-m 256"
61QB_SERIAL_OPT ?= "-serial mon:stdio -serial null"
62QB_DEFAULT_KERNEL ?= "${KERNEL_IMAGETYPE}"
63QB_DEFAULT_FSTYPE ?= "ext4"
64QB_OPT_APPEND ?= "-show-cursor"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050065QB_NETWORK_DEVICE ?= "-device virtio-net-pci,netdev=net0,mac=@MAC@"
66
67# This should be kept align with ROOT_VM
68QB_DRIVE_TYPE ?= "/dev/sd"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060069
70# Create qemuboot.conf
Brad Bishop6e60e8b2018-02-01 10:27:11 -050071addtask do_write_qemuboot_conf after do_rootfs before do_image
72IMGDEPLOYDIR ?= "${WORKDIR}/deploy-${PN}-image-complete"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060073
Brad Bishop6e60e8b2018-02-01 10:27:11 -050074def qemuboot_vars(d):
75 build_vars = ['MACHINE', 'TUNE_ARCH', 'DEPLOY_DIR_IMAGE',
76 'KERNEL_IMAGETYPE', 'IMAGE_NAME', 'IMAGE_LINK_NAME',
77 'STAGING_DIR_NATIVE', 'STAGING_BINDIR_NATIVE',
78 'STAGING_DIR_HOST']
79 return build_vars + [k for k in d.keys() if k.startswith('QB_')]
80
81do_write_qemuboot_conf[vardeps] += "${@' '.join(qemuboot_vars(d))}"
82do_write_qemuboot_conf[vardepsexclude] += "TOPDIR"
83python do_write_qemuboot_conf() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -060084 import configparser
85
Brad Bishop6e60e8b2018-02-01 10:27:11 -050086 qemuboot = "%s/%s.qemuboot.conf" % (d.getVar('IMGDEPLOYDIR'), d.getVar('IMAGE_NAME'))
87 qemuboot_link = "%s/%s.qemuboot.conf" % (d.getVar('IMGDEPLOYDIR'), d.getVar('IMAGE_LINK_NAME'))
88 topdir="%s/"%(d.getVar('TOPDIR')).replace("//","/")
Patrick Williamsc0f7c042017-02-23 20:41:17 -060089 cf = configparser.ConfigParser()
90 cf.add_section('config_bsp')
Brad Bishop6e60e8b2018-02-01 10:27:11 -050091 for k in qemuboot_vars(d):
92 # qemu-helper-native sysroot is not removed by rm_work and
93 # contains all tools required by runqemu
94 if k == 'STAGING_BINDIR_NATIVE':
95 val = os.path.join(d.getVar('BASE_WORKDIR'), d.getVar('BUILD_SYS'),
96 'qemu-helper-native/1.0-r1/recipe-sysroot-native/usr/bin/')
97 else:
98 val = d.getVar(k)
99 # we only want to write out relative paths so that we can relocate images
100 # and still run them
101 val=val.replace(topdir,"")
102 cf.set('config_bsp', k, '%s' % val)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600103
104 # QB_DEFAULT_KERNEL's value of KERNEL_IMAGETYPE is the name of a symlink
105 # to the kernel file, which hinders relocatability of the qb conf.
106 # Read the link and replace it with the full filename of the target.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500107 kernel_link = os.path.join(d.getVar('DEPLOY_DIR_IMAGE'), d.getVar('QB_DEFAULT_KERNEL'))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600108 kernel = os.path.realpath(kernel_link)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500109 # we only want to write out relative paths so that we can relocate images
110 # and still run them
111 kernel=kernel.replace(topdir,"")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600112 cf.set('config_bsp', 'QB_DEFAULT_KERNEL', kernel)
113
114 bb.utils.mkdirhier(os.path.dirname(qemuboot))
115 with open(qemuboot, 'w') as f:
116 cf.write(f)
117
118 if os.path.lexists(qemuboot_link):
119 os.remove(qemuboot_link)
120 os.symlink(os.path.basename(qemuboot), qemuboot_link)
121}