diff options
| author | Christopher Clark <christopher.w.clark@gmail.com> | 2020-02-25 16:15:50 -0800 |
|---|---|---|
| committer | Bruce Ashfield <bruce.ashfield@gmail.com> | 2020-02-27 16:59:22 -0500 |
| commit | c66da6821f38a9db3422990bd4068ab691169803 (patch) | |
| tree | 91af09706dd5a7cf37cec6ed123e4c56fc8c1f1f /scripts/lib/wic/plugins/source | |
| parent | e0884db20be8582f8ecf161a5dc1a84c620e68dd (diff) | |
| download | meta-virtualization-c66da6821f38a9db3422990bd4068ab691169803.tar.gz | |
wic: add support for bootable pcbios partition with Xen hypervisor
New bootimg-biosxen wic plugin to populate a boot partition for
launching Xen and dom0.
Includes example kickstart wks files to generate disk images to boot
into Xen from PC BIOS.
eg: wic create directdisk-xen -e xen-image-minimal
and write the resulting image file to a disk for boot.
Signed-off-by: Christopher Clark <christopher.clark6@baesystems.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Diffstat (limited to 'scripts/lib/wic/plugins/source')
| -rw-r--r-- | scripts/lib/wic/plugins/source/bootimg-biosxen.py | 212 |
1 files changed, 212 insertions, 0 deletions
diff --git a/scripts/lib/wic/plugins/source/bootimg-biosxen.py b/scripts/lib/wic/plugins/source/bootimg-biosxen.py new file mode 100644 index 00000000..f00747db --- /dev/null +++ b/scripts/lib/wic/plugins/source/bootimg-biosxen.py | |||
| @@ -0,0 +1,212 @@ | |||
| 1 | # | ||
| 2 | # This program is free software; you can redistribute it and/or modify | ||
| 3 | # it under the terms of the GNU General Public License version 2 as | ||
| 4 | # published by the Free Software Foundation. | ||
| 5 | # | ||
| 6 | # This program is distributed in the hope that it will be useful, | ||
| 7 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 8 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 9 | # GNU General Public License for more details. | ||
| 10 | # | ||
| 11 | # You should have received a copy of the GNU General Public License along | ||
| 12 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 13 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 14 | # | ||
| 15 | # DESCRIPTION | ||
| 16 | # This implements the 'bootimg-biosxen' source plugin class for 'wic' | ||
| 17 | # | ||
| 18 | # Bootloader arguments: Xen args are separated from Linux ones at '---': | ||
| 19 | # eg. | ||
| 20 | # bootloader --append="console=com1,vga com1=115200,8n1 --- console=hvc0" | ||
| 21 | # | ||
| 22 | # Optional source param: initrd | ||
| 23 | # accepts multiple ramdisk files to be supplied to multiboot. | ||
| 24 | # eg. | ||
| 25 | # part /boot --source bootimg-biosxen --sourceparams="initrd=foo.initrd;bar.initrd" | ||
| 26 | # | ||
| 27 | # AUTHORS | ||
| 28 | # Christopher Clark <christopher.w.clark [at] gmail.com> | ||
| 29 | # Elements derived from bootimg-biosplusefi.py by: | ||
| 30 | # William Bourque <wbourque [at] gmail.com> | ||
| 31 | |||
| 32 | import logging | ||
| 33 | import os | ||
| 34 | import types | ||
| 35 | |||
| 36 | from wic import WicError | ||
| 37 | import wic.pluginbase | ||
| 38 | from importlib.machinery import SourceFileLoader | ||
| 39 | from wic.misc import (exec_cmd, get_bitbake_var) | ||
| 40 | |||
| 41 | logger = logging.getLogger('wic') | ||
| 42 | |||
| 43 | class BootimgBiosXenPlugin(wic.pluginbase.SourcePlugin): | ||
| 44 | """ | ||
| 45 | Create MBR boot partition including files for Xen | ||
| 46 | |||
| 47 | """ | ||
| 48 | |||
| 49 | name = 'bootimg-biosxen' | ||
| 50 | __PCBIOS_MODULE_NAME = "bootimg-pcbios" | ||
| 51 | __imgBiosObj = None | ||
| 52 | |||
| 53 | @classmethod | ||
| 54 | def __init__(cls): | ||
| 55 | """ | ||
| 56 | Constructor (init) | ||
| 57 | """ | ||
| 58 | # original comment from bootimg-biosplusefi.py : | ||
| 59 | # "XXX For some reasons, __init__ constructor is never called. | ||
| 60 | # Something to do with how pluginbase works?" | ||
| 61 | cls.__instanciateBIOSClass() | ||
| 62 | |||
| 63 | @classmethod | ||
| 64 | def __instanciateBIOSClass(cls): | ||
| 65 | """ | ||
| 66 | |||
| 67 | """ | ||
| 68 | # Import bootimg-pcbios (class name "BootimgPcbiosPlugin") | ||
| 69 | modulePath = os.path.join(os.path.dirname(wic.pluginbase.__file__), | ||
| 70 | "plugins", "source", | ||
| 71 | cls.__PCBIOS_MODULE_NAME + ".py") | ||
| 72 | loader = SourceFileLoader(cls.__PCBIOS_MODULE_NAME, modulePath) | ||
| 73 | mod = types.ModuleType(loader.name) | ||
| 74 | loader.exec_module(mod) | ||
| 75 | cls.__imgBiosObj = mod.BootimgPcbiosPlugin() | ||
| 76 | |||
| 77 | @classmethod | ||
| 78 | def do_install_disk(cls, disk, disk_name, creator, workdir, oe_builddir, | ||
| 79 | bootimg_dir, kernel_dir, native_sysroot): | ||
| 80 | """ | ||
| 81 | Called after all partitions have been prepared and assembled into a | ||
| 82 | disk image. | ||
| 83 | """ | ||
| 84 | if not cls.__imgBiosObj: | ||
| 85 | cls.__instanciateBIOSClass() | ||
| 86 | |||
| 87 | cls.__imgBiosObj.do_install_disk(disk, disk_name, creator, workdir, | ||
| 88 | oe_builddir, bootimg_dir, kernel_dir, | ||
| 89 | native_sysroot) | ||
| 90 | |||
| 91 | @classmethod | ||
| 92 | def do_configure_partition(cls, part, source_params, creator, cr_workdir, | ||
| 93 | oe_builddir, bootimg_dir, kernel_dir, | ||
| 94 | native_sysroot): | ||
| 95 | """ | ||
| 96 | Called before do_prepare_partition(), creates syslinux config | ||
| 97 | """ | ||
| 98 | if not cls.__imgBiosObj: | ||
| 99 | cls.__instanciateBIOSClass() | ||
| 100 | |||
| 101 | bootloader = creator.ks.bootloader | ||
| 102 | |||
| 103 | if not bootloader.configfile: | ||
| 104 | splash = os.path.join(cr_workdir, "/hdd/boot/splash.jpg") | ||
| 105 | if os.path.exists(splash): | ||
| 106 | splashline = "menu background splash.jpg" | ||
| 107 | else: | ||
| 108 | splashline = "" | ||
| 109 | |||
| 110 | syslinux_conf = "" | ||
| 111 | syslinux_conf += "PROMPT 0\n" | ||
| 112 | syslinux_conf += "TIMEOUT " + str(bootloader.timeout) + "\n" | ||
| 113 | syslinux_conf += "\n" | ||
| 114 | syslinux_conf += "ALLOWOPTIONS 1\n" | ||
| 115 | syslinux_conf += "\n" | ||
| 116 | if splashline: | ||
| 117 | syslinux_conf += "%s\n" % splashline | ||
| 118 | |||
| 119 | syslinux_conf += "DEFAULT boot\n" | ||
| 120 | syslinux_conf += "LABEL boot\n" | ||
| 121 | syslinux_conf += " KERNEL mboot.c32\n" | ||
| 122 | |||
| 123 | # Split the bootloader args at '---' to separate the Xen args | ||
| 124 | # from the Linux kernel args. | ||
| 125 | # The Xen args here are defaults; overridden by bootloader append. | ||
| 126 | xen_args = "console=com1,vga com1=115200,8n1" | ||
| 127 | kernel_append = "" | ||
| 128 | if bootloader.append: | ||
| 129 | separator_pos = bootloader.append.find('---') | ||
| 130 | if separator_pos != -1: | ||
| 131 | xen_args = bootloader.append[:separator_pos] | ||
| 132 | kernel_append = bootloader.append[separator_pos+3:] | ||
| 133 | else: | ||
| 134 | kernel_append = bootloader.append | ||
| 135 | |||
| 136 | kernel_args = "label=boot root=%s %s" % \ | ||
| 137 | (creator.rootdev, kernel_append) | ||
| 138 | |||
| 139 | syslinux_conf += " APPEND /xen.gz %s --- /vmlinuz %s" % \ | ||
| 140 | (xen_args, kernel_args) | ||
| 141 | |||
| 142 | initrd = source_params.get('initrd') | ||
| 143 | if initrd: | ||
| 144 | initrds = initrd.split(';') | ||
| 145 | for initrd_file in initrds: | ||
| 146 | syslinux_conf += " --- /%s" % os.path.basename(initrd_file) | ||
| 147 | syslinux_conf += "\n" | ||
| 148 | |||
| 149 | logger.debug("Writing syslinux config %s/hdd/boot/syslinux.cfg", | ||
| 150 | cr_workdir) | ||
| 151 | |||
| 152 | hdddir = "%s/hdd/boot" % cr_workdir | ||
| 153 | install_cmd = "install -d %s" % hdddir | ||
| 154 | exec_cmd(install_cmd) | ||
| 155 | |||
| 156 | cfg = open("%s/hdd/boot/syslinux.cfg" % cr_workdir, "w") | ||
| 157 | cfg.write(syslinux_conf) | ||
| 158 | cfg.close() | ||
| 159 | |||
| 160 | else: | ||
| 161 | cls.__imgBiosObj.do_configure_partition(part, source_params, | ||
| 162 | creator, cr_workdir, | ||
| 163 | oe_builddir, bootimg_dir, | ||
| 164 | kernel_dir, native_sysroot) | ||
| 165 | |||
| 166 | @classmethod | ||
| 167 | def do_prepare_partition(cls, part, source_params, creator, cr_workdir, | ||
| 168 | oe_builddir, bootimg_dir, kernel_dir, | ||
| 169 | rootfs_dir, native_sysroot): | ||
| 170 | """ | ||
| 171 | Called to do the actual content population for a partition i.e. it | ||
| 172 | 'prepares' the partition to be incorporated into the image. | ||
| 173 | """ | ||
| 174 | if not cls.__imgBiosObj: | ||
| 175 | cls.__instanciateBIOSClass() | ||
| 176 | |||
| 177 | bootimg_dir = cls.__imgBiosObj._get_bootimg_dir(bootimg_dir, 'syslinux') | ||
| 178 | hdddir = "%s/hdd/boot" % cr_workdir | ||
| 179 | |||
| 180 | # machine-deduction logic originally from isoimage-isohybrid.py | ||
| 181 | initrd_dir = get_bitbake_var("DEPLOY_DIR_IMAGE") | ||
| 182 | if not initrd_dir: | ||
| 183 | raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting.") | ||
| 184 | machine = os.path.basename(initrd_dir) | ||
| 185 | |||
| 186 | xen = "xen-" + machine + ".gz" | ||
| 187 | |||
| 188 | cmds = ["install -m 0644 %s/%s %s/xen.gz" % | ||
| 189 | (kernel_dir, xen, hdddir), | ||
| 190 | "install -m 0644 %s/syslinux/mboot.c32 %s/mboot.c32" % | ||
| 191 | (bootimg_dir, hdddir)] | ||
| 192 | |||
| 193 | initrd = source_params.get('initrd') | ||
| 194 | |||
| 195 | # Allow multiple 'initrds', as per the bootimg-efi class. | ||
| 196 | # This can be used to install additional binaries for multiboot. | ||
| 197 | # eg. TXT ACMs, XSM/Flask policy file, microcode binary | ||
| 198 | if initrd: | ||
| 199 | initrds = initrd.split(';') | ||
| 200 | for initrd_file in initrds: | ||
| 201 | cmds.append("install -m 0644 %s/%s %s/%s" % | ||
| 202 | (kernel_dir, initrd_file, hdddir, | ||
| 203 | os.path.basename(initrd_file))) | ||
| 204 | |||
| 205 | for install_cmd in cmds: | ||
| 206 | exec_cmd(install_cmd) | ||
| 207 | |||
| 208 | cls.__imgBiosObj.do_prepare_partition(part, source_params, | ||
| 209 | creator, cr_workdir, | ||
| 210 | oe_builddir, bootimg_dir, | ||
| 211 | kernel_dir, rootfs_dir, | ||
| 212 | native_sysroot) | ||
