summaryrefslogtreecommitdiffstats
path: root/meta/classes-recipe/qemuboot.bbclass
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2022-08-10 14:35:29 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-08-12 15:27:17 +0100
commitfd1517e2b51a170f2427122c6b95396db251d827 (patch)
treedabfe3e631339c2fc99a9ee7febb0f9c128e325e /meta/classes-recipe/qemuboot.bbclass
parent10317912ee319ccf7f83605d438b5cbf9663f296 (diff)
downloadpoky-fd1517e2b51a170f2427122c6b95396db251d827.tar.gz
classes: Update classes to match new bitbake class scope functionality
Move classes to classes-global or classes-recipe as appropriate to take advantage of new bitbake functionality to check class scope/usage. (From OE-Core rev: f5c128008365e141082c129417eb72d2751e8045) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes-recipe/qemuboot.bbclass')
-rw-r--r--meta/classes-recipe/qemuboot.bbclass171
1 files changed, 171 insertions, 0 deletions
diff --git a/meta/classes-recipe/qemuboot.bbclass b/meta/classes-recipe/qemuboot.bbclass
new file mode 100644
index 0000000000..018c000ca2
--- /dev/null
+++ b/meta/classes-recipe/qemuboot.bbclass
@@ -0,0 +1,171 @@
1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7# Help runqemu boot target board, "QB" means Qemu Boot, the following
8# vars can be set in conf files, such as <bsp.conf> to make it can be
9# boot by runqemu:
10#
11# QB_SYSTEM_NAME: qemu name, e.g., "qemu-system-i386"
12#
13# QB_OPT_APPEND: options to append to qemu, e.g., "-device usb-mouse"
14#
15# QB_DEFAULT_KERNEL: default kernel to boot, e.g., "bzImage"
16#
17# QB_DEFAULT_FSTYPE: default FSTYPE to boot, e.g., "ext4"
18#
19# QB_MEM: memory, e.g., "-m 512"
20#
21# QB_MACHINE: qemu machine, e.g., "-machine virt"
22#
23# QB_CPU: qemu cpu, e.g., "-cpu qemu32"
24#
25# QB_CPU_KVM: the similar to QB_CPU, but used when kvm, e.g., '-cpu kvm64',
26# set it when support kvm.
27#
28# QB_SMP: amount of CPU cores inside qemu guest, each mapped to a thread on the host,
29# e.g. "-smp 8".
30#
31# QB_KERNEL_CMDLINE_APPEND: options to append to kernel's -append
32# option, e.g., "console=ttyS0 console=tty"
33#
34# QB_DTB: qemu dtb name
35#
36# QB_AUDIO_DRV: qemu audio driver, e.g., "alsa", set it when support audio
37#
38# QB_AUDIO_OPT: qemu audio option, e.g., "-device AC97", used
39# when QB_AUDIO_DRV is set.
40#
41# QB_RNG: Pass-through for host random number generator, it can speedup boot
42# in system mode, where system is experiencing entropy starvation
43#
44# QB_KERNEL_ROOT: kernel's root, e.g., /dev/vda
45# By default "/dev/vda rw" gets passed to the kernel.
46# To mount the rootfs read-only QB_KERNEL_ROOT can be set to e.g. "/dev/vda ro".
47#
48# QB_NETWORK_DEVICE: network device, e.g., "-device virtio-net-pci,netdev=net0,mac=@MAC@",
49# it needs work with QB_TAP_OPT and QB_SLIRP_OPT.
50# Note, runqemu will replace @MAC@ with a predefined mac, you can set
51# a custom one, but that may cause conflicts when multiple qemus are
52# running on the same host.
53# Note: If more than one interface of type -device virtio-net-device gets added,
54# QB_NETWORK_DEVICE:prepend might be used, since Qemu enumerates the eth*
55# devices in reverse order to -device arguments.
56#
57# QB_TAP_OPT: network option for 'tap' mode, e.g.,
58# "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no"
59# Note, runqemu will replace "@TAP@" with the one which is used, such as tap0, tap1 ...
60#
61# QB_SLIRP_OPT: network option for SLIRP mode, e.g., -netdev user,id=net0"
62#
63# QB_CMDLINE_IP_SLIRP: If QB_NETWORK_DEVICE adds more than one network interface to qemu, usually the
64# ip= kernel comand line argument needs to be changed accordingly. Details are documented
65# in the kernel docuemntation https://www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt
66# Example to configure only the first interface: "ip=eth0:dhcp"
67# QB_CMDLINE_IP_TAP: This parameter is similar to the QB_CMDLINE_IP_SLIRP parameter. Since the tap interface requires
68# static IP configuration @CLIENT@ and @GATEWAY@ place holders are replaced by the IP and the gateway
69# address of the qemu guest by runqemu.
70# Example: "ip=192.168.7.@CLIENT@::192.168.7.@GATEWAY@:255.255.255.0::eth0"
71#
72# QB_ROOTFS_OPT: used as rootfs, e.g.,
73# "-drive id=disk0,file=@ROOTFS@,if=none,format=raw -device virtio-blk-device,drive=disk0"
74# Note, runqemu will replace "@ROOTFS@" with the one which is used, such as core-image-minimal-qemuarm64.ext4.
75#
76# QB_SERIAL_OPT: serial port, e.g., "-serial mon:stdio"
77#
78# QB_TCPSERIAL_OPT: tcp serial port option, e.g.,
79# " -device virtio-serial-device -chardev socket,id=virtcon,port=@PORT@,host=127.0.0.1 -device virtconsole,chardev=virtcon"
80# Note, runqemu will replace "@PORT@" with the port number which is used.
81#
82# QB_ROOTFS_EXTRA_OPT: extra options to be appended to the rootfs device in case there is none specified by QB_ROOTFS_OPT.
83# Can be used to automatically determine the image from the other variables
84# but define things link 'bootindex' when booting from EFI or 'readonly' when using squashfs
85# without the need to specify a dedicated qemu configuration
86#
87# QB_GRAPHICS: QEMU video card type (e.g. "-vga std")
88#
89# Usage:
90# IMAGE_CLASSES += "qemuboot"
91# See "runqemu help" for more info
92
93QB_MEM ?= "-m 256"
94QB_SMP ?= ""
95QB_SERIAL_OPT ?= "-serial mon:stdio -serial null"
96QB_DEFAULT_KERNEL ?= "${KERNEL_IMAGETYPE}"
97QB_DEFAULT_FSTYPE ?= "ext4"
98QB_RNG ?= "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
99QB_OPT_APPEND ?= ""
100QB_NETWORK_DEVICE ?= "-device virtio-net-pci,netdev=net0,mac=@MAC@"
101QB_CMDLINE_IP_SLIRP ?= "ip=dhcp"
102QB_CMDLINE_IP_TAP ?= "ip=192.168.7.@CLIENT@::192.168.7.@GATEWAY@:255.255.255.0::eth0:off:8.8.8.8"
103QB_ROOTFS_EXTRA_OPT ?= ""
104QB_GRAPHICS ?= ""
105
106# This should be kept align with ROOT_VM
107QB_DRIVE_TYPE ?= "/dev/sd"
108
109inherit image-artifact-names
110
111# Create qemuboot.conf
112addtask do_write_qemuboot_conf after do_rootfs before do_image
113
114def qemuboot_vars(d):
115 build_vars = ['MACHINE', 'TUNE_ARCH', 'DEPLOY_DIR_IMAGE',
116 'KERNEL_IMAGETYPE', 'IMAGE_NAME', 'IMAGE_LINK_NAME',
117 'STAGING_DIR_NATIVE', 'STAGING_BINDIR_NATIVE',
118 'STAGING_DIR_HOST', 'SERIAL_CONSOLES', 'UNINATIVE_LOADER']
119 return build_vars + [k for k in d.keys() if k.startswith('QB_')]
120
121do_write_qemuboot_conf[vardeps] += "${@' '.join(qemuboot_vars(d))}"
122do_write_qemuboot_conf[vardepsexclude] += "TOPDIR"
123python do_write_qemuboot_conf() {
124 import configparser
125
126 qemuboot = "%s/%s.qemuboot.conf" % (d.getVar('IMGDEPLOYDIR'), d.getVar('IMAGE_NAME'))
127 if d.getVar('IMAGE_LINK_NAME'):
128 qemuboot_link = "%s/%s.qemuboot.conf" % (d.getVar('IMGDEPLOYDIR'), d.getVar('IMAGE_LINK_NAME'))
129 else:
130 qemuboot_link = ""
131 finalpath = d.getVar("DEPLOY_DIR_IMAGE")
132 topdir = d.getVar('TOPDIR')
133 cf = configparser.ConfigParser()
134 cf.add_section('config_bsp')
135 for k in sorted(qemuboot_vars(d)):
136 if ":" in k:
137 continue
138 # qemu-helper-native sysroot is not removed by rm_work and
139 # contains all tools required by runqemu
140 if k == 'STAGING_BINDIR_NATIVE':
141 val = os.path.join(d.getVar('BASE_WORKDIR'), d.getVar('BUILD_SYS'),
142 'qemu-helper-native/1.0-r1/recipe-sysroot-native/usr/bin/')
143 else:
144 val = d.getVar(k)
145 if val is None:
146 continue
147 # we only want to write out relative paths so that we can relocate images
148 # and still run them
149 if val.startswith(topdir):
150 val = os.path.relpath(val, finalpath)
151 cf.set('config_bsp', k, '%s' % val)
152
153 # QB_DEFAULT_KERNEL's value of KERNEL_IMAGETYPE is the name of a symlink
154 # to the kernel file, which hinders relocatability of the qb conf.
155 # Read the link and replace it with the full filename of the target.
156 kernel_link = os.path.join(d.getVar('DEPLOY_DIR_IMAGE'), d.getVar('QB_DEFAULT_KERNEL'))
157 kernel = os.path.realpath(kernel_link)
158 # we only want to write out relative paths so that we can relocate images
159 # and still run them
160 kernel = os.path.relpath(kernel, finalpath)
161 cf.set('config_bsp', 'QB_DEFAULT_KERNEL', kernel)
162
163 bb.utils.mkdirhier(os.path.dirname(qemuboot))
164 with open(qemuboot, 'w') as f:
165 cf.write(f)
166
167 if qemuboot_link and qemuboot_link != qemuboot:
168 if os.path.lexists(qemuboot_link):
169 os.remove(qemuboot_link)
170 os.symlink(os.path.basename(qemuboot), qemuboot_link)
171}