Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | # 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 6 | # |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 7 | # QB_OPT_APPEND: options to append to qemu, e.g., "-device usb-mouse" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 8 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9 | # QB_DEFAULT_KERNEL: default kernel to boot, e.g., "bzImage" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 10 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 11 | # QB_DEFAULT_FSTYPE: default FSTYPE to boot, e.g., "ext4" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 12 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 13 | # QB_MEM: memory, e.g., "-m 512" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 14 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 15 | # QB_MACHINE: qemu machine, e.g., "-machine virt" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 16 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 17 | # QB_CPU: qemu cpu, e.g., "-cpu qemu32" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 18 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 19 | # QB_CPU_KVM: the similar to QB_CPU, but used when kvm, e.g., '-cpu kvm64', |
| 20 | # set it when support kvm. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 21 | # |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame^] | 22 | # QB_SMP: amount of CPU cores inside qemu guest, each mapped to a thread on the host, |
| 23 | # e.g. "-smp 8". |
| 24 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 25 | # QB_KERNEL_CMDLINE_APPEND: options to append to kernel's -append |
| 26 | # option, e.g., "console=ttyS0 console=tty" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 27 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 28 | # QB_DTB: qemu dtb name |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 29 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 30 | # QB_AUDIO_DRV: qemu audio driver, e.g., "alsa", set it when support audio |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 31 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 32 | # QB_AUDIO_OPT: qemu audio option, e.g., "-soundhw ac97,es1370", used |
| 33 | # when QB_AUDIO_DRV is set. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 34 | # |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 35 | # 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 38 | # QB_KERNEL_ROOT: kernel's root, e.g., /dev/vda |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 39 | # |
| 40 | # QB_NETWORK_DEVICE: network device, e.g., "-device virtio-net-pci,netdev=net0,mac=@MAC@", |
| 41 | # it needs work with QB_TAP_OPT and QB_SLIRP_OPT. |
| 42 | # Note, runqemu will replace @MAC@ with a predefined mac, you can set |
| 43 | # a custom one, but that may cause conflicts when multiple qemus are |
| 44 | # running on the same host. |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 45 | # Note: If more than one interface of type -device virtio-net-device gets added, |
| 46 | # QB_NETWORK_DEVICE_prepend might be used, since Qemu enumerates the eth* |
| 47 | # devices in reverse order to -device arguments. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 48 | # |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 49 | # QB_TAP_OPT: network option for 'tap' mode, e.g., |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 50 | # "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 51 | # Note, runqemu will replace "@TAP@" with the one which is used, such as tap0, tap1 ... |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 52 | # |
| 53 | # QB_SLIRP_OPT: network option for SLIRP mode, e.g., -netdev user,id=net0" |
| 54 | # |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 55 | # QB_CMDLINE_IP_SLIRP: If QB_NETWORK_DEVICE adds more than one network interface to qemu, usually the |
| 56 | # ip= kernel comand line argument needs to be changed accordingly. Details are documented |
| 57 | # in the kernel docuemntation https://www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt |
| 58 | # Example to configure only the first interface: "ip=eth0:dhcp" |
| 59 | # QB_CMDLINE_IP_TAP: This parameter is similar to the QB_CMDLINE_IP_SLIRP parameter. Since the tap interface requires |
| 60 | # static IP configuration @CLIENT@ and @GATEWAY@ place holders are replaced by the IP and the gateway |
| 61 | # address of the qemu guest by runqemu. |
| 62 | # Example: "ip=192.168.7.@CLIENT@::192.168.7.@GATEWAY@:255.255.255.0::eth0" |
| 63 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 64 | # QB_ROOTFS_OPT: used as rootfs, e.g., |
| 65 | # "-drive id=disk0,file=@ROOTFS@,if=none,format=raw -device virtio-blk-device,drive=disk0" |
| 66 | # Note, runqemu will replace "@ROOTFS@" with the one which is used, such as core-image-minimal-qemuarm64.ext4. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 67 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 68 | # QB_SERIAL_OPT: serial port, e.g., "-serial mon:stdio" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 69 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 70 | # QB_TCPSERIAL_OPT: tcp serial port option, e.g., |
| 71 | # " -device virtio-serial-device -chardev socket,id=virtcon,port=@PORT@,host=127.0.0.1 -device virtconsole,chardev=virtcon" |
| 72 | # Note, runqemu will replace "@PORT@" with the port number which is used. |
| 73 | # |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 74 | # QB_ROOTFS_EXTRA_OPT: extra options to be appended to the rootfs device in case there is none specified by QB_ROOTFS_OPT. |
| 75 | # Can be used to automatically determine the image from the other variables |
| 76 | # but define things link 'bootindex' when booting from EFI or 'readonly' when using squashfs |
| 77 | # without the need to specify a dedicated qemu configuration |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 78 | # |
| 79 | # QB_GRAPHICS: QEMU video card type (e.g. "-vga std") |
| 80 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 81 | # Usage: |
| 82 | # IMAGE_CLASSES += "qemuboot" |
| 83 | # See "runqemu help" for more info |
| 84 | |
| 85 | QB_MEM ?= "-m 256" |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame^] | 86 | QB_SMP ?= "" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 87 | QB_SERIAL_OPT ?= "-serial mon:stdio -serial null" |
| 88 | QB_DEFAULT_KERNEL ?= "${KERNEL_IMAGETYPE}" |
| 89 | QB_DEFAULT_FSTYPE ?= "ext4" |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 90 | QB_RNG ?= "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0" |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 91 | QB_OPT_APPEND ?= "" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 92 | QB_NETWORK_DEVICE ?= "-device virtio-net-pci,netdev=net0,mac=@MAC@" |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 93 | QB_CMDLINE_IP_SLIRP ?= "ip=dhcp" |
| 94 | QB_CMDLINE_IP_TAP ?= "ip=192.168.7.@CLIENT@::192.168.7.@GATEWAY@:255.255.255.0" |
| 95 | QB_ROOTFS_EXTRA_OPT ?= "" |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 96 | QB_GRAPHICS ?= "" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 97 | |
| 98 | # This should be kept align with ROOT_VM |
| 99 | QB_DRIVE_TYPE ?= "/dev/sd" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 100 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 101 | inherit image-artifact-names |
| 102 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 103 | # Create qemuboot.conf |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 104 | addtask do_write_qemuboot_conf after do_rootfs before do_image |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 105 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 106 | def qemuboot_vars(d): |
| 107 | build_vars = ['MACHINE', 'TUNE_ARCH', 'DEPLOY_DIR_IMAGE', |
| 108 | 'KERNEL_IMAGETYPE', 'IMAGE_NAME', 'IMAGE_LINK_NAME', |
| 109 | 'STAGING_DIR_NATIVE', 'STAGING_BINDIR_NATIVE', |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 110 | 'STAGING_DIR_HOST', 'SERIAL_CONSOLES'] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 111 | return build_vars + [k for k in d.keys() if k.startswith('QB_')] |
| 112 | |
| 113 | do_write_qemuboot_conf[vardeps] += "${@' '.join(qemuboot_vars(d))}" |
| 114 | do_write_qemuboot_conf[vardepsexclude] += "TOPDIR" |
| 115 | python do_write_qemuboot_conf() { |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 116 | import configparser |
| 117 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 118 | qemuboot = "%s/%s.qemuboot.conf" % (d.getVar('IMGDEPLOYDIR'), d.getVar('IMAGE_NAME')) |
| 119 | qemuboot_link = "%s/%s.qemuboot.conf" % (d.getVar('IMGDEPLOYDIR'), d.getVar('IMAGE_LINK_NAME')) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 120 | finalpath = d.getVar("DEPLOY_DIR_IMAGE") |
| 121 | topdir = d.getVar('TOPDIR') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 122 | cf = configparser.ConfigParser() |
| 123 | cf.add_section('config_bsp') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 124 | for k in sorted(qemuboot_vars(d)): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 125 | # qemu-helper-native sysroot is not removed by rm_work and |
| 126 | # contains all tools required by runqemu |
| 127 | if k == 'STAGING_BINDIR_NATIVE': |
| 128 | val = os.path.join(d.getVar('BASE_WORKDIR'), d.getVar('BUILD_SYS'), |
| 129 | 'qemu-helper-native/1.0-r1/recipe-sysroot-native/usr/bin/') |
| 130 | else: |
| 131 | val = d.getVar(k) |
| 132 | # we only want to write out relative paths so that we can relocate images |
| 133 | # and still run them |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 134 | if val.startswith(topdir): |
| 135 | val = os.path.relpath(val, finalpath) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 136 | cf.set('config_bsp', k, '%s' % val) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 137 | |
| 138 | # QB_DEFAULT_KERNEL's value of KERNEL_IMAGETYPE is the name of a symlink |
| 139 | # to the kernel file, which hinders relocatability of the qb conf. |
| 140 | # Read the link and replace it with the full filename of the target. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 141 | kernel_link = os.path.join(d.getVar('DEPLOY_DIR_IMAGE'), d.getVar('QB_DEFAULT_KERNEL')) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 142 | kernel = os.path.realpath(kernel_link) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 143 | # we only want to write out relative paths so that we can relocate images |
| 144 | # and still run them |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 145 | kernel = os.path.relpath(kernel, finalpath) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 146 | cf.set('config_bsp', 'QB_DEFAULT_KERNEL', kernel) |
| 147 | |
| 148 | bb.utils.mkdirhier(os.path.dirname(qemuboot)) |
| 149 | with open(qemuboot, 'w') as f: |
| 150 | cf.write(f) |
| 151 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 152 | if qemuboot_link != qemuboot: |
| 153 | if os.path.lexists(qemuboot_link): |
| 154 | os.remove(qemuboot_link) |
| 155 | os.symlink(os.path.basename(qemuboot), qemuboot_link) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 156 | } |