summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/plugins/source/bootimg_biosxen.py
diff options
context:
space:
mode:
authorAnibal Limon <anibal@limonsoftware.com>2025-07-29 16:21:47 +0000
committerBruce Ashfield <bruce.ashfield@gmail.com>2025-07-31 13:34:50 -0400
commitb66d2ca088cddd6fd3d7cdfe1c7bbe4b420ba53d (patch)
tree7a7210f68eb0e05e29cf1baa830fb668d656c472 /scripts/lib/wic/plugins/source/bootimg_biosxen.py
parent9b034e3defd4aa1108d7a6b4dcca600d4352b132 (diff)
downloadmeta-virtualization-b66d2ca088cddd6fd3d7cdfe1c7bbe4b420ba53d.tar.gz
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 <anibal@limonsoftware.com> Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Diffstat (limited to 'scripts/lib/wic/plugins/source/bootimg_biosxen.py')
-rw-r--r--scripts/lib/wic/plugins/source/bootimg_biosxen.py165
1 files changed, 165 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..e5f545e0
--- /dev/null
+++ b/scripts/lib/wic/plugins/source/bootimg_biosxen.py
@@ -0,0 +1,165 @@
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
32import logging
33import os
34import types
35
36from wic import WicError
37from wic.misc import (exec_cmd, get_bitbake_var)
38from wic.plugins.source.bootimg_pcbios import BootimgPcbiosPlugin
39
40logger = logging.getLogger('wic')
41
42class BootimgBiosXenPlugin(BootimgPcbiosPlugin):
43 """
44 Create MBR boot partition including files for Xen
45
46 """
47
48 name = 'bootimg_biosxen'
49
50 @classmethod
51 def do_configure_partition(cls, part, source_params, creator, cr_workdir,
52 oe_builddir, bootimg_dir, kernel_dir,
53 native_sysroot):
54 """
55 Called before do_prepare_partition(), creates syslinux config
56 """
57 bootloader = creator.ks.bootloader
58
59 if not bootloader.configfile:
60 splash = os.path.join(cr_workdir, "/hdd/boot/splash.jpg")
61 if os.path.exists(splash):
62 splashline = "menu background splash.jpg"
63 else:
64 splashline = ""
65
66 syslinux_conf = ""
67 syslinux_conf += "PROMPT 0\n"
68 syslinux_conf += "TIMEOUT " + str(bootloader.timeout) + "\n"
69 syslinux_conf += "\n"
70 syslinux_conf += "ALLOWOPTIONS 1\n"
71 syslinux_conf += "\n"
72 if splashline:
73 syslinux_conf += "%s\n" % splashline
74
75 syslinux_conf += "DEFAULT boot\n"
76 syslinux_conf += "LABEL boot\n"
77 syslinux_conf += " KERNEL mboot.c32\n"
78
79 # Split the bootloader args at '---' to separate the Xen args
80 # from the Linux kernel args.
81 # The Xen args here are defaults; overridden by bootloader append.
82 xen_args = "console=com1,vga com1=115200,8n1"
83 kernel_append = ""
84 if bootloader.append:
85 separator_pos = bootloader.append.find('---')
86 if separator_pos != -1:
87 xen_args = bootloader.append[:separator_pos]
88 kernel_append = bootloader.append[separator_pos+3:]
89 else:
90 kernel_append = bootloader.append
91
92 kernel_args = "label=boot root=%s %s" % \
93 (creator.rootdev, kernel_append)
94
95 syslinux_conf += " APPEND /xen.gz %s --- /vmlinuz %s" % \
96 (xen_args, kernel_args)
97
98 initrd = source_params.get('initrd')
99 if initrd:
100 initrds = initrd.split(';')
101 for initrd_file in initrds:
102 syslinux_conf += " --- /%s" % os.path.basename(initrd_file)
103 syslinux_conf += "\n"
104
105 logger.debug("Writing syslinux config %s/hdd/boot/syslinux.cfg",
106 cr_workdir)
107
108 hdddir = "%s/hdd/boot" % cr_workdir
109 install_cmd = "install -d %s" % hdddir
110 exec_cmd(install_cmd)
111
112 cfg = open("%s/hdd/boot/syslinux.cfg" % cr_workdir, "w")
113 cfg.write(syslinux_conf)
114 cfg.close()
115
116 else:
117 super().do_configure_partition(part, source_params,
118 creator, cr_workdir,
119 oe_builddir, bootimg_dir,
120 kernel_dir, native_sysroot)
121
122 @classmethod
123 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
124 oe_builddir, bootimg_dir, kernel_dir,
125 rootfs_dir, native_sysroot):
126 """
127 Called to do the actual content population for a partition i.e. it
128 'prepares' the partition to be incorporated into the image.
129 """
130 bootimg_dir = super()._get_bootimg_dir(bootimg_dir, 'syslinux')
131 hdddir = "%s/hdd/boot" % cr_workdir
132
133 # machine-deduction logic originally from isoimage-isohybrid.py
134 initrd_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
135 if not initrd_dir:
136 raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting.")
137 machine = os.path.basename(initrd_dir)
138
139 xen = "xen-" + machine + ".gz"
140
141 cmds = ["install -m 0644 %s/%s %s/xen.gz" %
142 (kernel_dir, xen, hdddir),
143 "install -m 0644 %s/syslinux/mboot.c32 %s/mboot.c32" %
144 (bootimg_dir, hdddir)]
145
146 initrd = source_params.get('initrd')
147
148 # Allow multiple 'initrds', as per the bootimg-efi class.
149 # This can be used to install additional binaries for multiboot.
150 # eg. TXT ACMs, XSM/Flask policy file, microcode binary
151 if initrd:
152 initrds = initrd.split(';')
153 for initrd_file in initrds:
154 cmds.append("install -m 0644 %s/%s %s/%s" %
155 (kernel_dir, initrd_file, hdddir,
156 os.path.basename(initrd_file)))
157
158 for install_cmd in cmds:
159 exec_cmd(install_cmd)
160
161 super().do_prepare_partition(part, source_params,
162 creator, cr_workdir,
163 oe_builddir, bootimg_dir,
164 kernel_dir, rootfs_dir,
165 native_sysroot)