From b66d2ca088cddd6fd3d7cdfe1c7bbe4b420ba53d Mon Sep 17 00:00:00 2001 From: Anibal Limon Date: Tue, 29 Jul 2025 16:21:47 +0000 Subject: scripts: wic plugin bootimg-biosxen drop helper to reuse bootimg_pcbios - With wic plugins rename on OE-Core now can be imported. See OE-Core revs, afa1b5c9f6ed17c021e37a54d0d6abee50a60bf9 2de444fc3ef450f45f8f93403544e8f7461657b0 16c8251e5272510ad96613b8c6623550c5a72a34 - Drop the custom helper to find BootimgPcbiosPlugin plus adapt the code removing all custom calls and references. - Finally rename bootimg-biosxen to allow be imported. Tested with xen-image-minimal and testimage. Signed-off-by: Anibal Limon Signed-off-by: Bruce Ashfield --- scripts/lib/wic/plugins/source/bootimg_biosxen.py | 165 ++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 scripts/lib/wic/plugins/source/bootimg_biosxen.py (limited to 'scripts/lib/wic/plugins/source/bootimg_biosxen.py') 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..e5f545e0 --- /dev/null +++ b/scripts/lib/wic/plugins/source/bootimg_biosxen.py @@ -0,0 +1,165 @@ +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# DESCRIPTION +# This implements the 'bootimg-biosxen' source plugin class for 'wic' +# +# Bootloader arguments: Xen args are separated from Linux ones at '---': +# eg. +# bootloader --append="console=com1,vga com1=115200,8n1 --- console=hvc0" +# +# Optional source param: initrd +# accepts multiple ramdisk files to be supplied to multiboot. +# eg. +# part /boot --source bootimg-biosxen --sourceparams="initrd=foo.initrd;bar.initrd" +# +# AUTHORS +# Christopher Clark +# Elements derived from bootimg-biosplusefi.py by: +# William Bourque + +import logging +import os +import types + +from wic import WicError +from wic.misc import (exec_cmd, get_bitbake_var) +from wic.plugins.source.bootimg_pcbios import BootimgPcbiosPlugin + +logger = logging.getLogger('wic') + +class BootimgBiosXenPlugin(BootimgPcbiosPlugin): + """ + Create MBR boot partition including files for Xen + + """ + + name = 'bootimg_biosxen' + + @classmethod + def do_configure_partition(cls, part, source_params, creator, cr_workdir, + oe_builddir, bootimg_dir, kernel_dir, + native_sysroot): + """ + Called before do_prepare_partition(), creates syslinux config + """ + bootloader = creator.ks.bootloader + + if not bootloader.configfile: + splash = os.path.join(cr_workdir, "/hdd/boot/splash.jpg") + if os.path.exists(splash): + splashline = "menu background splash.jpg" + else: + splashline = "" + + syslinux_conf = "" + syslinux_conf += "PROMPT 0\n" + syslinux_conf += "TIMEOUT " + str(bootloader.timeout) + "\n" + syslinux_conf += "\n" + syslinux_conf += "ALLOWOPTIONS 1\n" + syslinux_conf += "\n" + if splashline: + syslinux_conf += "%s\n" % splashline + + syslinux_conf += "DEFAULT boot\n" + syslinux_conf += "LABEL boot\n" + syslinux_conf += " KERNEL mboot.c32\n" + + # Split the bootloader args at '---' to separate the Xen args + # from the Linux kernel args. + # The Xen args here are defaults; overridden by bootloader append. + xen_args = "console=com1,vga com1=115200,8n1" + kernel_append = "" + if bootloader.append: + separator_pos = bootloader.append.find('---') + if separator_pos != -1: + xen_args = bootloader.append[:separator_pos] + kernel_append = bootloader.append[separator_pos+3:] + else: + kernel_append = bootloader.append + + kernel_args = "label=boot root=%s %s" % \ + (creator.rootdev, kernel_append) + + syslinux_conf += " APPEND /xen.gz %s --- /vmlinuz %s" % \ + (xen_args, kernel_args) + + initrd = source_params.get('initrd') + if initrd: + initrds = initrd.split(';') + for initrd_file in initrds: + syslinux_conf += " --- /%s" % os.path.basename(initrd_file) + syslinux_conf += "\n" + + logger.debug("Writing syslinux config %s/hdd/boot/syslinux.cfg", + cr_workdir) + + hdddir = "%s/hdd/boot" % cr_workdir + install_cmd = "install -d %s" % hdddir + exec_cmd(install_cmd) + + cfg = open("%s/hdd/boot/syslinux.cfg" % cr_workdir, "w") + cfg.write(syslinux_conf) + cfg.close() + + else: + super().do_configure_partition(part, source_params, + creator, cr_workdir, + oe_builddir, bootimg_dir, + kernel_dir, native_sysroot) + + @classmethod + def do_prepare_partition(cls, part, source_params, creator, cr_workdir, + oe_builddir, bootimg_dir, kernel_dir, + rootfs_dir, native_sysroot): + """ + Called to do the actual content population for a partition i.e. it + 'prepares' the partition to be incorporated into the image. + """ + bootimg_dir = super()._get_bootimg_dir(bootimg_dir, 'syslinux') + hdddir = "%s/hdd/boot" % cr_workdir + + # machine-deduction logic originally from isoimage-isohybrid.py + initrd_dir = get_bitbake_var("DEPLOY_DIR_IMAGE") + if not initrd_dir: + raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting.") + machine = os.path.basename(initrd_dir) + + xen = "xen-" + machine + ".gz" + + cmds = ["install -m 0644 %s/%s %s/xen.gz" % + (kernel_dir, xen, hdddir), + "install -m 0644 %s/syslinux/mboot.c32 %s/mboot.c32" % + (bootimg_dir, hdddir)] + + initrd = source_params.get('initrd') + + # Allow multiple 'initrds', as per the bootimg-efi class. + # This can be used to install additional binaries for multiboot. + # eg. TXT ACMs, XSM/Flask policy file, microcode binary + if initrd: + initrds = initrd.split(';') + for initrd_file in initrds: + cmds.append("install -m 0644 %s/%s %s/%s" % + (kernel_dir, initrd_file, hdddir, + os.path.basename(initrd_file))) + + for install_cmd in cmds: + exec_cmd(install_cmd) + + super().do_prepare_partition(part, source_params, + creator, cr_workdir, + oe_builddir, bootimg_dir, + kernel_dir, rootfs_dir, + native_sysroot) -- cgit v1.2.3-54-g00ecf