blob: 4b7532b3043d7c744603cff5e631a80690719cac [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#
Andrew Geisslerd25ed322020-06-27 00:28:28 -05007# QB_OPT_APPEND: options to append to qemu, e.g., "-device usb-mouse"
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#
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050032# QB_RNG: Pass-through for host random number generator, it can speedup boot
33# in system mode, where system is experiencing entropy starvation
34#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060035# QB_KERNEL_ROOT: kernel's root, e.g., /dev/vda
Brad Bishop6e60e8b2018-02-01 10:27:11 -050036#
37# QB_NETWORK_DEVICE: network device, e.g., "-device virtio-net-pci,netdev=net0,mac=@MAC@",
38# it needs work with QB_TAP_OPT and QB_SLIRP_OPT.
39# Note, runqemu will replace @MAC@ with a predefined mac, you can set
40# a custom one, but that may cause conflicts when multiple qemus are
41# running on the same host.
Andrew Geissler82c905d2020-04-13 13:39:40 -050042# Note: If more than one interface of type -device virtio-net-device gets added,
43# QB_NETWORK_DEVICE_prepend might be used, since Qemu enumerates the eth*
44# devices in reverse order to -device arguments.
Brad Bishop6e60e8b2018-02-01 10:27:11 -050045#
Andrew Geissler6ce62a22020-11-30 19:58:47 -060046# QB_TAP_OPT: network option for 'tap' mode, e.g.,
Brad Bishop6e60e8b2018-02-01 10:27:11 -050047# "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060048# Note, runqemu will replace "@TAP@" with the one which is used, such as tap0, tap1 ...
Brad Bishop6e60e8b2018-02-01 10:27:11 -050049#
50# QB_SLIRP_OPT: network option for SLIRP mode, e.g., -netdev user,id=net0"
51#
Andrew Geissler82c905d2020-04-13 13:39:40 -050052# QB_CMDLINE_IP_SLIRP: If QB_NETWORK_DEVICE adds more than one network interface to qemu, usually the
53# ip= kernel comand line argument needs to be changed accordingly. Details are documented
54# in the kernel docuemntation https://www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt
55# Example to configure only the first interface: "ip=eth0:dhcp"
56# QB_CMDLINE_IP_TAP: This parameter is similar to the QB_CMDLINE_IP_SLIRP parameter. Since the tap interface requires
57# static IP configuration @CLIENT@ and @GATEWAY@ place holders are replaced by the IP and the gateway
58# address of the qemu guest by runqemu.
59# Example: "ip=192.168.7.@CLIENT@::192.168.7.@GATEWAY@:255.255.255.0::eth0"
60#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060061# QB_ROOTFS_OPT: used as rootfs, e.g.,
62# "-drive id=disk0,file=@ROOTFS@,if=none,format=raw -device virtio-blk-device,drive=disk0"
63# 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 -050064#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060065# QB_SERIAL_OPT: serial port, e.g., "-serial mon:stdio"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050066#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060067# QB_TCPSERIAL_OPT: tcp serial port option, e.g.,
68# " -device virtio-serial-device -chardev socket,id=virtcon,port=@PORT@,host=127.0.0.1 -device virtconsole,chardev=virtcon"
69# Note, runqemu will replace "@PORT@" with the port number which is used.
70#
Andrew Geissler82c905d2020-04-13 13:39:40 -050071# QB_ROOTFS_EXTRA_OPT: extra options to be appended to the rootfs device in case there is none specified by QB_ROOTFS_OPT.
72# Can be used to automatically determine the image from the other variables
73# but define things link 'bootindex' when booting from EFI or 'readonly' when using squashfs
74# without the need to specify a dedicated qemu configuration
Patrick Williamsc0f7c042017-02-23 20:41:17 -060075# Usage:
76# IMAGE_CLASSES += "qemuboot"
77# See "runqemu help" for more info
78
79QB_MEM ?= "-m 256"
80QB_SERIAL_OPT ?= "-serial mon:stdio -serial null"
81QB_DEFAULT_KERNEL ?= "${KERNEL_IMAGETYPE}"
82QB_DEFAULT_FSTYPE ?= "ext4"
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050083QB_RNG ?= "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
Andrew Geisslerd25ed322020-06-27 00:28:28 -050084QB_OPT_APPEND ?= ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -050085QB_NETWORK_DEVICE ?= "-device virtio-net-pci,netdev=net0,mac=@MAC@"
Andrew Geissler82c905d2020-04-13 13:39:40 -050086QB_CMDLINE_IP_SLIRP ?= "ip=dhcp"
87QB_CMDLINE_IP_TAP ?= "ip=192.168.7.@CLIENT@::192.168.7.@GATEWAY@:255.255.255.0"
88QB_ROOTFS_EXTRA_OPT ?= ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -050089
90# This should be kept align with ROOT_VM
91QB_DRIVE_TYPE ?= "/dev/sd"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060092
Andrew Geisslerc9f78652020-09-18 14:11:35 -050093inherit image-artifact-names
94
Patrick Williamsc0f7c042017-02-23 20:41:17 -060095# Create qemuboot.conf
Brad Bishop6e60e8b2018-02-01 10:27:11 -050096addtask do_write_qemuboot_conf after do_rootfs before do_image
Patrick Williamsc0f7c042017-02-23 20:41:17 -060097
Brad Bishop6e60e8b2018-02-01 10:27:11 -050098def qemuboot_vars(d):
99 build_vars = ['MACHINE', 'TUNE_ARCH', 'DEPLOY_DIR_IMAGE',
100 'KERNEL_IMAGETYPE', 'IMAGE_NAME', 'IMAGE_LINK_NAME',
101 'STAGING_DIR_NATIVE', 'STAGING_BINDIR_NATIVE',
102 'STAGING_DIR_HOST']
103 return build_vars + [k for k in d.keys() if k.startswith('QB_')]
104
105do_write_qemuboot_conf[vardeps] += "${@' '.join(qemuboot_vars(d))}"
106do_write_qemuboot_conf[vardepsexclude] += "TOPDIR"
107python do_write_qemuboot_conf() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600108 import configparser
109
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500110 qemuboot = "%s/%s.qemuboot.conf" % (d.getVar('IMGDEPLOYDIR'), d.getVar('IMAGE_NAME'))
111 qemuboot_link = "%s/%s.qemuboot.conf" % (d.getVar('IMGDEPLOYDIR'), d.getVar('IMAGE_LINK_NAME'))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500112 finalpath = d.getVar("DEPLOY_DIR_IMAGE")
113 topdir = d.getVar('TOPDIR')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600114 cf = configparser.ConfigParser()
115 cf.add_section('config_bsp')
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500116 for k in sorted(qemuboot_vars(d)):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500117 # qemu-helper-native sysroot is not removed by rm_work and
118 # contains all tools required by runqemu
119 if k == 'STAGING_BINDIR_NATIVE':
120 val = os.path.join(d.getVar('BASE_WORKDIR'), d.getVar('BUILD_SYS'),
121 'qemu-helper-native/1.0-r1/recipe-sysroot-native/usr/bin/')
122 else:
123 val = d.getVar(k)
124 # we only want to write out relative paths so that we can relocate images
125 # and still run them
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500126 if val.startswith(topdir):
127 val = os.path.relpath(val, finalpath)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500128 cf.set('config_bsp', k, '%s' % val)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600129
130 # QB_DEFAULT_KERNEL's value of KERNEL_IMAGETYPE is the name of a symlink
131 # to the kernel file, which hinders relocatability of the qb conf.
132 # Read the link and replace it with the full filename of the target.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500133 kernel_link = os.path.join(d.getVar('DEPLOY_DIR_IMAGE'), d.getVar('QB_DEFAULT_KERNEL'))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600134 kernel = os.path.realpath(kernel_link)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500135 # we only want to write out relative paths so that we can relocate images
136 # and still run them
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500137 kernel = os.path.relpath(kernel, finalpath)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600138 cf.set('config_bsp', 'QB_DEFAULT_KERNEL', kernel)
139
140 bb.utils.mkdirhier(os.path.dirname(qemuboot))
141 with open(qemuboot, 'w') as f:
142 cf.write(f)
143
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500144 if qemuboot_link != qemuboot:
145 if os.path.lexists(qemuboot_link):
146 os.remove(qemuboot_link)
147 os.symlink(os.path.basename(qemuboot), qemuboot_link)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600148}