| 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" | 
|  | 6 | # QB_OPT_APPEND: options to append to qemu, e.g., "-show-cursor" | 
|  | 7 | # QB_DEFAULT_KERNEL: default kernel to boot, e.g., "bzImage" | 
|  | 8 | # QB_DEFAULT_FSTYPE: default FSTYPE to boot, e.g., "ext4" | 
|  | 9 | # QB_MEM: memory, e.g., "-m 512" | 
|  | 10 | # QB_MACHINE: qemu machine, e.g., "-machine virt" | 
|  | 11 | # QB_CPU: qemu cpu, e.g., "-cpu qemu32" | 
|  | 12 | # QB_CPU_KVM: the similar to QB_CPU, but used when kvm, e.g., '-cpu kvm64', | 
|  | 13 | #             set it when support kvm. | 
|  | 14 | # QB_KERNEL_CMDLINE_APPEND: options to append to kernel's -append | 
|  | 15 | #                           option, e.g., "console=ttyS0 console=tty" | 
|  | 16 | # QB_DTB: qemu dtb name | 
|  | 17 | # QB_AUDIO_DRV: qemu audio driver, e.g., "alsa", set it when support audio | 
|  | 18 | # QB_AUDIO_OPT: qemu audio option, e.g., "-soundhw ac97,es1370", used | 
|  | 19 | #               when QB_AUDIO_DRV is set. | 
|  | 20 | # QB_KERNEL_ROOT: kernel's root, e.g., /dev/vda | 
|  | 21 | # QB_TAP_OPT: netowrk option for 'tap' mode, e.g., | 
|  | 22 | #             "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no -device virtio-net-device,netdev=net0" | 
|  | 23 | #              Note, runqemu will replace "@TAP@" with the one which is used, such as tap0, tap1 ... | 
|  | 24 | # QB_SLIRP_OPT: network option for SLIRP mode, e.g., | 
|  | 25 | #             "-netdev user,id=net0 -device virtio-net-device,netdev=net0" | 
|  | 26 | # QB_ROOTFS_OPT: used as rootfs, e.g., | 
|  | 27 | #               "-drive id=disk0,file=@ROOTFS@,if=none,format=raw -device virtio-blk-device,drive=disk0" | 
|  | 28 | #              Note, runqemu will replace "@ROOTFS@" with the one which is used, such as core-image-minimal-qemuarm64.ext4. | 
|  | 29 | # QB_SERIAL_OPT: serial port, e.g., "-serial mon:stdio" | 
|  | 30 | # QB_TCPSERIAL_OPT: tcp serial port option, e.g., | 
|  | 31 | #                   " -device virtio-serial-device -chardev socket,id=virtcon,port=@PORT@,host=127.0.0.1 -device virtconsole,chardev=virtcon" | 
|  | 32 | #                   Note, runqemu will replace "@PORT@" with the port number which is used. | 
|  | 33 | # | 
|  | 34 | # Usage: | 
|  | 35 | # IMAGE_CLASSES += "qemuboot" | 
|  | 36 | # See "runqemu help" for more info | 
|  | 37 |  | 
|  | 38 | QB_MEM ?= "-m 256" | 
|  | 39 | QB_SERIAL_OPT ?= "-serial mon:stdio -serial null" | 
|  | 40 | QB_DEFAULT_KERNEL ?= "${KERNEL_IMAGETYPE}" | 
|  | 41 | QB_DEFAULT_FSTYPE ?= "ext4" | 
|  | 42 | QB_OPT_APPEND ?= "-show-cursor" | 
|  | 43 |  | 
|  | 44 | # Create qemuboot.conf | 
|  | 45 | ROOTFS_POSTPROCESS_COMMAND += "write_qemuboot_conf; " | 
|  | 46 |  | 
|  | 47 | python write_qemuboot_conf() { | 
|  | 48 | import configparser | 
|  | 49 |  | 
|  | 50 | build_vars = ['MACHINE', 'TUNE_ARCH', 'DEPLOY_DIR_IMAGE', \ | 
|  | 51 | 'KERNEL_IMAGETYPE', 'IMAGE_NAME', 'IMAGE_LINK_NAME', \ | 
|  | 52 | 'STAGING_DIR_NATIVE', 'STAGING_BINDIR_NATIVE', \ | 
|  | 53 | 'STAGING_DIR_HOST'] | 
|  | 54 |  | 
|  | 55 | # Vars from bsp | 
|  | 56 | qb_vars = [] | 
|  | 57 | for k in d.keys(): | 
|  | 58 | if k.startswith('QB_'): | 
|  | 59 | qb_vars.append(k) | 
|  | 60 |  | 
|  | 61 | qemuboot = "%s/%s.qemuboot.conf" % (d.getVar('DEPLOY_DIR_IMAGE', True), d.getVar('IMAGE_NAME', True)) | 
|  | 62 | qemuboot_link = "%s/%s.qemuboot.conf" % (d.getVar('DEPLOY_DIR_IMAGE', True), d.getVar('IMAGE_LINK_NAME', True)) | 
|  | 63 | cf = configparser.ConfigParser() | 
|  | 64 | cf.add_section('config_bsp') | 
|  | 65 | for k in build_vars + qb_vars: | 
|  | 66 | cf.set('config_bsp', k, '%s' % d.getVar(k, True)) | 
|  | 67 |  | 
|  | 68 | # QB_DEFAULT_KERNEL's value of KERNEL_IMAGETYPE is the name of a symlink | 
|  | 69 | # to the kernel file, which hinders relocatability of the qb conf. | 
|  | 70 | # Read the link and replace it with the full filename of the target. | 
|  | 71 | kernel_link = os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True), d.getVar('QB_DEFAULT_KERNEL', True)) | 
|  | 72 | kernel = os.path.realpath(kernel_link) | 
|  | 73 | cf.set('config_bsp', 'QB_DEFAULT_KERNEL', kernel) | 
|  | 74 |  | 
|  | 75 | bb.utils.mkdirhier(os.path.dirname(qemuboot)) | 
|  | 76 | with open(qemuboot, 'w') as f: | 
|  | 77 | cf.write(f) | 
|  | 78 |  | 
|  | 79 | if os.path.lexists(qemuboot_link): | 
|  | 80 | os.remove(qemuboot_link) | 
|  | 81 | os.symlink(os.path.basename(qemuboot), qemuboot_link) | 
|  | 82 | } |