blob: cc1cbce69d14fff538e2b28aa5e3c3d91b723a4f [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#
William A. Kennington IIIac69b482021-06-02 12:28:27 -070022# QB_SMP: amount of CPU cores inside qemu guest, each mapped to a thread on the host,
23# e.g. "-smp 8".
24#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060025# QB_KERNEL_CMDLINE_APPEND: options to append to kernel's -append
26# option, e.g., "console=ttyS0 console=tty"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050027#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060028# QB_DTB: qemu dtb name
Brad Bishop6e60e8b2018-02-01 10:27:11 -050029#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060030# QB_AUDIO_DRV: qemu audio driver, e.g., "alsa", set it when support audio
Brad Bishop6e60e8b2018-02-01 10:27:11 -050031#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060032# QB_AUDIO_OPT: qemu audio option, e.g., "-soundhw ac97,es1370", used
33# when QB_AUDIO_DRV is set.
Brad Bishop6e60e8b2018-02-01 10:27:11 -050034#
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050035# QB_RNG: Pass-through for host random number generator, it can speedup boot
36# in system mode, where system is experiencing entropy starvation
37#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060038# QB_KERNEL_ROOT: kernel's root, e.g., /dev/vda
Andrew Geissler595f6302022-01-24 19:11:47 +000039# By default "/dev/vda rw" gets passed to the kernel.
40# To mount the rootfs read-only QB_KERNEL_ROOT can be set to e.g. "/dev/vda ro".
Brad Bishop6e60e8b2018-02-01 10:27:11 -050041#
42# QB_NETWORK_DEVICE: network device, e.g., "-device virtio-net-pci,netdev=net0,mac=@MAC@",
43# it needs work with QB_TAP_OPT and QB_SLIRP_OPT.
44# Note, runqemu will replace @MAC@ with a predefined mac, you can set
45# a custom one, but that may cause conflicts when multiple qemus are
46# running on the same host.
Andrew Geissler82c905d2020-04-13 13:39:40 -050047# Note: If more than one interface of type -device virtio-net-device gets added,
Patrick Williams213cb262021-08-07 19:21:33 -050048# QB_NETWORK_DEVICE:prepend might be used, since Qemu enumerates the eth*
Andrew Geissler82c905d2020-04-13 13:39:40 -050049# devices in reverse order to -device arguments.
Brad Bishop6e60e8b2018-02-01 10:27:11 -050050#
Andrew Geissler6ce62a22020-11-30 19:58:47 -060051# QB_TAP_OPT: network option for 'tap' mode, e.g.,
Brad Bishop6e60e8b2018-02-01 10:27:11 -050052# "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060053# Note, runqemu will replace "@TAP@" with the one which is used, such as tap0, tap1 ...
Brad Bishop6e60e8b2018-02-01 10:27:11 -050054#
55# QB_SLIRP_OPT: network option for SLIRP mode, e.g., -netdev user,id=net0"
56#
Andrew Geissler82c905d2020-04-13 13:39:40 -050057# QB_CMDLINE_IP_SLIRP: If QB_NETWORK_DEVICE adds more than one network interface to qemu, usually the
58# ip= kernel comand line argument needs to be changed accordingly. Details are documented
59# in the kernel docuemntation https://www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt
60# Example to configure only the first interface: "ip=eth0:dhcp"
61# QB_CMDLINE_IP_TAP: This parameter is similar to the QB_CMDLINE_IP_SLIRP parameter. Since the tap interface requires
62# static IP configuration @CLIENT@ and @GATEWAY@ place holders are replaced by the IP and the gateway
63# address of the qemu guest by runqemu.
64# Example: "ip=192.168.7.@CLIENT@::192.168.7.@GATEWAY@:255.255.255.0::eth0"
65#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060066# QB_ROOTFS_OPT: used as rootfs, e.g.,
67# "-drive id=disk0,file=@ROOTFS@,if=none,format=raw -device virtio-blk-device,drive=disk0"
68# 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 -050069#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060070# QB_SERIAL_OPT: serial port, e.g., "-serial mon:stdio"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050071#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060072# QB_TCPSERIAL_OPT: tcp serial port option, e.g.,
73# " -device virtio-serial-device -chardev socket,id=virtcon,port=@PORT@,host=127.0.0.1 -device virtconsole,chardev=virtcon"
74# Note, runqemu will replace "@PORT@" with the port number which is used.
75#
Andrew Geissler82c905d2020-04-13 13:39:40 -050076# QB_ROOTFS_EXTRA_OPT: extra options to be appended to the rootfs device in case there is none specified by QB_ROOTFS_OPT.
77# Can be used to automatically determine the image from the other variables
78# but define things link 'bootindex' when booting from EFI or 'readonly' when using squashfs
79# without the need to specify a dedicated qemu configuration
Andrew Geissler95ac1b82021-03-31 14:34:31 -050080#
81# QB_GRAPHICS: QEMU video card type (e.g. "-vga std")
82#
Patrick Williamsc0f7c042017-02-23 20:41:17 -060083# Usage:
84# IMAGE_CLASSES += "qemuboot"
85# See "runqemu help" for more info
86
87QB_MEM ?= "-m 256"
William A. Kennington IIIac69b482021-06-02 12:28:27 -070088QB_SMP ?= ""
Patrick Williamsc0f7c042017-02-23 20:41:17 -060089QB_SERIAL_OPT ?= "-serial mon:stdio -serial null"
90QB_DEFAULT_KERNEL ?= "${KERNEL_IMAGETYPE}"
91QB_DEFAULT_FSTYPE ?= "ext4"
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050092QB_RNG ?= "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
Andrew Geisslerd25ed322020-06-27 00:28:28 -050093QB_OPT_APPEND ?= ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -050094QB_NETWORK_DEVICE ?= "-device virtio-net-pci,netdev=net0,mac=@MAC@"
Andrew Geissler82c905d2020-04-13 13:39:40 -050095QB_CMDLINE_IP_SLIRP ?= "ip=dhcp"
Andrew Geissler595f6302022-01-24 19:11:47 +000096QB_CMDLINE_IP_TAP ?= "ip=192.168.7.@CLIENT@::192.168.7.@GATEWAY@:255.255.255.0::eth0:off:8.8.8.8"
Andrew Geissler82c905d2020-04-13 13:39:40 -050097QB_ROOTFS_EXTRA_OPT ?= ""
Andrew Geissler95ac1b82021-03-31 14:34:31 -050098QB_GRAPHICS ?= ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -050099
100# This should be kept align with ROOT_VM
101QB_DRIVE_TYPE ?= "/dev/sd"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600102
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500103inherit image-artifact-names
104
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600105# Create qemuboot.conf
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500106addtask do_write_qemuboot_conf after do_rootfs before do_image
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600107
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500108def qemuboot_vars(d):
109 build_vars = ['MACHINE', 'TUNE_ARCH', 'DEPLOY_DIR_IMAGE',
110 'KERNEL_IMAGETYPE', 'IMAGE_NAME', 'IMAGE_LINK_NAME',
111 'STAGING_DIR_NATIVE', 'STAGING_BINDIR_NATIVE',
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500112 'STAGING_DIR_HOST', 'SERIAL_CONSOLES']
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500113 return build_vars + [k for k in d.keys() if k.startswith('QB_')]
114
115do_write_qemuboot_conf[vardeps] += "${@' '.join(qemuboot_vars(d))}"
116do_write_qemuboot_conf[vardepsexclude] += "TOPDIR"
117python do_write_qemuboot_conf() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600118 import configparser
119
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500120 qemuboot = "%s/%s.qemuboot.conf" % (d.getVar('IMGDEPLOYDIR'), d.getVar('IMAGE_NAME'))
Andrew Geissler595f6302022-01-24 19:11:47 +0000121 if d.getVar('IMAGE_LINK_NAME'):
122 qemuboot_link = "%s/%s.qemuboot.conf" % (d.getVar('IMGDEPLOYDIR'), d.getVar('IMAGE_LINK_NAME'))
123 else:
124 qemuboot_link = ""
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500125 finalpath = d.getVar("DEPLOY_DIR_IMAGE")
126 topdir = d.getVar('TOPDIR')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600127 cf = configparser.ConfigParser()
128 cf.add_section('config_bsp')
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500129 for k in sorted(qemuboot_vars(d)):
Patrick Williams213cb262021-08-07 19:21:33 -0500130 if ":" in k:
131 continue
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500132 # qemu-helper-native sysroot is not removed by rm_work and
133 # contains all tools required by runqemu
134 if k == 'STAGING_BINDIR_NATIVE':
135 val = os.path.join(d.getVar('BASE_WORKDIR'), d.getVar('BUILD_SYS'),
136 'qemu-helper-native/1.0-r1/recipe-sysroot-native/usr/bin/')
137 else:
138 val = d.getVar(k)
139 # we only want to write out relative paths so that we can relocate images
140 # and still run them
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500141 if val.startswith(topdir):
142 val = os.path.relpath(val, finalpath)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500143 cf.set('config_bsp', k, '%s' % val)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600144
145 # QB_DEFAULT_KERNEL's value of KERNEL_IMAGETYPE is the name of a symlink
146 # to the kernel file, which hinders relocatability of the qb conf.
147 # Read the link and replace it with the full filename of the target.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500148 kernel_link = os.path.join(d.getVar('DEPLOY_DIR_IMAGE'), d.getVar('QB_DEFAULT_KERNEL'))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600149 kernel = os.path.realpath(kernel_link)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500150 # we only want to write out relative paths so that we can relocate images
151 # and still run them
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500152 kernel = os.path.relpath(kernel, finalpath)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600153 cf.set('config_bsp', 'QB_DEFAULT_KERNEL', kernel)
154
155 bb.utils.mkdirhier(os.path.dirname(qemuboot))
156 with open(qemuboot, 'w') as f:
157 cf.write(f)
158
Andrew Geissler595f6302022-01-24 19:11:47 +0000159 if qemuboot_link and qemuboot_link != qemuboot:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500160 if os.path.lexists(qemuboot_link):
161 os.remove(qemuboot_link)
162 os.symlink(os.path.basename(qemuboot), qemuboot_link)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600163}