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 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7 | # QB_OPT_APPEND: options to append to qemu, e.g., "-show-cursor" |
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 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 22 | # QB_KERNEL_CMDLINE_APPEND: options to append to kernel's -append |
| 23 | # option, e.g., "console=ttyS0 console=tty" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 24 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 25 | # QB_DTB: qemu dtb name |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 26 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 27 | # 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^] | 28 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 29 | # QB_AUDIO_OPT: qemu audio option, e.g., "-soundhw ac97,es1370", used |
| 30 | # when QB_AUDIO_DRV is set. |
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_KERNEL_ROOT: kernel's root, e.g., /dev/vda |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 33 | # |
| 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 40 | # QB_TAP_OPT: netowrk option for 'tap' mode, e.g., |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 41 | # "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 42 | # 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^] | 43 | # |
| 44 | # QB_SLIRP_OPT: network option for SLIRP mode, e.g., -netdev user,id=net0" |
| 45 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 46 | # 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 49 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 50 | # QB_SERIAL_OPT: serial port, e.g., "-serial mon:stdio" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 51 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 52 | # 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 | |
| 60 | QB_MEM ?= "-m 256" |
| 61 | QB_SERIAL_OPT ?= "-serial mon:stdio -serial null" |
| 62 | QB_DEFAULT_KERNEL ?= "${KERNEL_IMAGETYPE}" |
| 63 | QB_DEFAULT_FSTYPE ?= "ext4" |
| 64 | QB_OPT_APPEND ?= "-show-cursor" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 65 | QB_NETWORK_DEVICE ?= "-device virtio-net-pci,netdev=net0,mac=@MAC@" |
| 66 | |
| 67 | # This should be kept align with ROOT_VM |
| 68 | QB_DRIVE_TYPE ?= "/dev/sd" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 69 | |
| 70 | # Create qemuboot.conf |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 71 | addtask do_write_qemuboot_conf after do_rootfs before do_image |
| 72 | IMGDEPLOYDIR ?= "${WORKDIR}/deploy-${PN}-image-complete" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 73 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 74 | def 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 | |
| 81 | do_write_qemuboot_conf[vardeps] += "${@' '.join(qemuboot_vars(d))}" |
| 82 | do_write_qemuboot_conf[vardepsexclude] += "TOPDIR" |
| 83 | python do_write_qemuboot_conf() { |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 84 | import configparser |
| 85 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 86 | 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 89 | cf = configparser.ConfigParser() |
| 90 | cf.add_section('config_bsp') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 91 | 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 103 | |
| 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 107 | 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] | 108 | kernel = os.path.realpath(kernel_link) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 109 | # 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 112 | 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 | } |