blob: 170077c22c21ee2320065beaa9d7068875af665b [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License version 2 as
6# published by the Free Software Foundation.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License along
14# with this program; if not, write to the Free Software Foundation, Inc.,
15# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16#
17# DESCRIPTION
18# This implements the 'isoimage-isohybrid' source plugin class for 'wic'
19#
20# AUTHORS
21# Mihaly Varga <mihaly.varga (at] ni.com>
22
Brad Bishop6e60e8b2018-02-01 10:27:11 -050023import glob
24import logging
Patrick Williamsc124f4f2015-09-15 14:41:29 -050025import os
26import re
27import shutil
28
Brad Bishop6e60e8b2018-02-01 10:27:11 -050029from wic import WicError
30from wic.engine import get_custom_config
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031from wic.pluginbase import SourcePlugin
Brad Bishopd7bf8c12018-02-25 22:55:05 -050032from wic.misc import exec_cmd, exec_native_cmd, get_bitbake_var
Brad Bishop6e60e8b2018-02-01 10:27:11 -050033
34logger = logging.getLogger('wic')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050035
36class IsoImagePlugin(SourcePlugin):
37 """
38 Create a bootable ISO image
39
40 This plugin creates a hybrid, legacy and EFI bootable ISO image. The
41 generated image can be used on optical media as well as USB media.
42
43 Legacy boot uses syslinux and EFI boot uses grub or gummiboot (not
44 implemented yet) as bootloader. The plugin creates the directories required
45 by bootloaders and populates them by creating and configuring the
46 bootloader files.
47
48 Example kickstart file:
49 part /boot --source isoimage-isohybrid --sourceparams="loader=grub-efi, \\
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080050 image_name= IsoImage" --ondisk cd --label LIVECD
Patrick Williamsc124f4f2015-09-15 14:41:29 -050051 bootloader --timeout=10 --append=" "
52
53 In --sourceparams "loader" specifies the bootloader used for booting in EFI
54 mode, while "image_name" specifies the name of the generated image. In the
55 example above, wic creates an ISO image named IsoImage-cd.direct (default
56 extension added by direct imeger plugin) and a file named IsoImage-cd.iso
57 """
58
59 name = 'isoimage-isohybrid'
60
61 @classmethod
62 def do_configure_syslinux(cls, creator, cr_workdir):
63 """
64 Create loader-specific (syslinux) config
65 """
Patrick Williamsc0f7c042017-02-23 20:41:17 -060066 splash = os.path.join(cr_workdir, "ISO/boot/splash.jpg")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067 if os.path.exists(splash):
68 splashline = "menu background splash.jpg"
69 else:
70 splashline = ""
71
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050072 bootloader = creator.ks.bootloader
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073
74 syslinux_conf = ""
75 syslinux_conf += "PROMPT 0\n"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050076 syslinux_conf += "TIMEOUT %s \n" % (bootloader.timeout or 10)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050077 syslinux_conf += "\n"
78 syslinux_conf += "ALLOWOPTIONS 1\n"
79 syslinux_conf += "SERIAL 0 115200\n"
80 syslinux_conf += "\n"
81 if splashline:
82 syslinux_conf += "%s\n" % splashline
83 syslinux_conf += "DEFAULT boot\n"
84 syslinux_conf += "LABEL boot\n"
85
86 kernel = "/bzImage"
87 syslinux_conf += "KERNEL " + kernel + "\n"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050088 syslinux_conf += "APPEND initrd=/initrd LABEL=boot %s\n" \
89 % bootloader.append
Patrick Williamsc124f4f2015-09-15 14:41:29 -050090
Brad Bishop6e60e8b2018-02-01 10:27:11 -050091 logger.debug("Writing syslinux config %s/ISO/isolinux/isolinux.cfg",
92 cr_workdir)
93
Patrick Williamsc124f4f2015-09-15 14:41:29 -050094 with open("%s/ISO/isolinux/isolinux.cfg" % cr_workdir, "w") as cfg:
95 cfg.write(syslinux_conf)
96
97 @classmethod
Brad Bishopd7bf8c12018-02-25 22:55:05 -050098 def do_configure_grubefi(cls, part, creator, target_dir):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050099 """
100 Create loader-specific (grub-efi) config
101 """
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600102 configfile = creator.ks.bootloader.configfile
103 if configfile:
104 grubefi_conf = get_custom_config(configfile)
105 if grubefi_conf:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500106 logger.debug("Using custom configuration file %s for grub.cfg",
107 configfile)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600108 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500109 raise WicError("configfile is specified "
110 "but failed to get it from %s", configfile)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500111 else:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500112 splash = os.path.join(target_dir, "splash.jpg")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600113 if os.path.exists(splash):
114 splashline = "menu background splash.jpg"
115 else:
116 splashline = ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500117
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600118 bootloader = creator.ks.bootloader
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500119
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600120 grubefi_conf = ""
121 grubefi_conf += "serial --unit=0 --speed=115200 --word=8 "
122 grubefi_conf += "--parity=no --stop=1\n"
123 grubefi_conf += "default=boot\n"
124 grubefi_conf += "timeout=%s\n" % (bootloader.timeout or 10)
125 grubefi_conf += "\n"
126 grubefi_conf += "search --set=root --label %s " % part.label
127 grubefi_conf += "\n"
128 grubefi_conf += "menuentry 'boot'{\n"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500129
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600130 kernel = "/bzImage"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500131
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600132 grubefi_conf += "linux %s rootwait %s\n" \
133 % (kernel, bootloader.append)
134 grubefi_conf += "initrd /initrd \n"
135 grubefi_conf += "}\n"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500136
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600137 if splashline:
138 grubefi_conf += "%s\n" % splashline
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500139
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500140 cfg_path = os.path.join(target_dir, "grub.cfg")
141 logger.debug("Writing grubefi config %s", cfg_path)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500142
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500143 with open(cfg_path, "w") as cfg:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500144 cfg.write(grubefi_conf)
145
146 @staticmethod
147 def _build_initramfs_path(rootfs_dir, cr_workdir):
148 """
149 Create path for initramfs image
150 """
151
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500152 initrd = get_bitbake_var("INITRD_LIVE") or get_bitbake_var("INITRD")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500153 if not initrd:
154 initrd_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
155 if not initrd_dir:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500156 raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting.")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500157
158 image_name = get_bitbake_var("IMAGE_BASENAME")
159 if not image_name:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500160 raise WicError("Couldn't find IMAGE_BASENAME, exiting.")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500161
162 image_type = get_bitbake_var("INITRAMFS_FSTYPES")
163 if not image_type:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500164 raise WicError("Couldn't find INITRAMFS_FSTYPES, exiting.")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500165
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500166 machine = os.path.basename(initrd_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500167
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500168 pattern = '%s/%s*%s.%s' % (initrd_dir, image_name, machine, image_type)
169 files = glob.glob(pattern)
170 if files:
171 initrd = files[0]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500172
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500173 if not initrd or not os.path.exists(initrd):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500174 # Create initrd from rootfs directory
175 initrd = "%s/initrd.cpio.gz" % cr_workdir
176 initrd_dir = "%s/INITRD" % cr_workdir
177 shutil.copytree("%s" % rootfs_dir, \
178 "%s" % initrd_dir, symlinks=True)
179
180 if os.path.isfile("%s/init" % rootfs_dir):
181 shutil.copy2("%s/init" % rootfs_dir, "%s/init" % initrd_dir)
182 elif os.path.lexists("%s/init" % rootfs_dir):
183 os.symlink(os.readlink("%s/init" % rootfs_dir), \
184 "%s/init" % initrd_dir)
185 elif os.path.isfile("%s/sbin/init" % rootfs_dir):
186 shutil.copy2("%s/sbin/init" % rootfs_dir, \
187 "%s" % initrd_dir)
188 elif os.path.lexists("%s/sbin/init" % rootfs_dir):
189 os.symlink(os.readlink("%s/sbin/init" % rootfs_dir), \
190 "%s/init" % initrd_dir)
191 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500192 raise WicError("Couldn't find or build initrd, exiting.")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500193
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800194 exec_cmd("cd %s && find . | cpio -o -H newc -R root:root >%s/initrd.cpio " \
195 % (initrd_dir, cr_workdir), as_shell=True)
196 exec_cmd("gzip -f -9 %s/initrd.cpio" % cr_workdir, as_shell=True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500197 shutil.rmtree(initrd_dir)
198
199 return initrd
200
201 @classmethod
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500202 def do_configure_partition(cls, part, source_params, creator, cr_workdir,
203 oe_builddir, bootimg_dir, kernel_dir,
204 native_sysroot):
205 """
206 Called before do_prepare_partition(), creates loader-specific config
207 """
208 isodir = "%s/ISO/" % cr_workdir
209
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500210 if os.path.exists(isodir):
211 shutil.rmtree(isodir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500212
213 install_cmd = "install -d %s " % isodir
214 exec_cmd(install_cmd)
215
216 # Overwrite the name of the created image
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500217 logger.debug(source_params)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500218 if 'image_name' in source_params and \
219 source_params['image_name'].strip():
220 creator.name = source_params['image_name'].strip()
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500221 logger.debug("The name of the image is: %s", creator.name)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500222
223 @classmethod
224 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
225 oe_builddir, bootimg_dir, kernel_dir,
226 rootfs_dir, native_sysroot):
227 """
228 Called to do the actual content population for a partition i.e. it
229 'prepares' the partition to be incorporated into the image.
230 In this case, prepare content for a bootable ISO image.
231 """
232
233 isodir = "%s/ISO" % cr_workdir
234
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500235 if part.rootfs_dir is None:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500236 if not 'ROOTFS_DIR' in rootfs_dir:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500237 raise WicError("Couldn't find --rootfs-dir, exiting.")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500238 rootfs_dir = rootfs_dir['ROOTFS_DIR']
239 else:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500240 if part.rootfs_dir in rootfs_dir:
241 rootfs_dir = rootfs_dir[part.rootfs_dir]
242 elif part.rootfs_dir:
243 rootfs_dir = part.rootfs_dir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500244 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500245 raise WicError("Couldn't find --rootfs-dir=%s connection "
246 "or it is not a valid path, exiting." %
247 part.rootfs_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500248
249 if not os.path.isdir(rootfs_dir):
250 rootfs_dir = get_bitbake_var("IMAGE_ROOTFS")
251 if not os.path.isdir(rootfs_dir):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500252 raise WicError("Couldn't find IMAGE_ROOTFS, exiting.")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500253
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500254 part.rootfs_dir = rootfs_dir
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500255 deploy_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500256 img_iso_dir = get_bitbake_var("ISODIR")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500257
258 # Remove the temporary file created by part.prepare_rootfs()
259 if os.path.isfile(part.source_file):
260 os.remove(part.source_file)
261
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500262 # Support using a different initrd other than default
263 if source_params.get('initrd'):
264 initrd = source_params['initrd']
265 if not deploy_dir:
266 raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting")
267 cp_cmd = "cp %s/%s %s" % (deploy_dir, initrd, cr_workdir)
268 exec_cmd(cp_cmd)
269 else:
270 # Prepare initial ramdisk
271 initrd = "%s/initrd" % deploy_dir
272 if not os.path.isfile(initrd):
273 initrd = "%s/initrd" % img_iso_dir
274 if not os.path.isfile(initrd):
275 initrd = cls._build_initramfs_path(rootfs_dir, cr_workdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500276
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500277 install_cmd = "install -m 0644 %s %s/initrd" % (initrd, isodir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500278 exec_cmd(install_cmd)
279
280 # Remove the temporary file created by _build_initramfs_path function
281 if os.path.isfile("%s/initrd.cpio.gz" % cr_workdir):
282 os.remove("%s/initrd.cpio.gz" % cr_workdir)
283
284 # Install bzImage
285 install_cmd = "install -m 0644 %s/bzImage %s/bzImage" % \
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500286 (kernel_dir, isodir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500287 exec_cmd(install_cmd)
288
289 #Create bootloader for efi boot
290 try:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500291 target_dir = "%s/EFI/BOOT" % isodir
292 if os.path.exists(target_dir):
293 shutil.rmtree(target_dir)
294
295 os.makedirs(target_dir)
296
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500297 if source_params['loader'] == 'grub-efi':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500298 # Builds bootx64.efi/bootia32.efi if ISODIR didn't exist or
299 # didn't contains it
300 target_arch = get_bitbake_var("TARGET_SYS")
301 if not target_arch:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500302 raise WicError("Coludn't find target architecture")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500303
304 if re.match("x86_64", target_arch):
Brad Bishopc4ea0752018-11-15 14:30:15 -0800305 grub_src_image = "grub-efi-bootx64.efi"
306 grub_dest_image = "bootx64.efi"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500307 elif re.match('i.86', target_arch):
Brad Bishopc4ea0752018-11-15 14:30:15 -0800308 grub_src_image = "grub-efi-bootia32.efi"
309 grub_dest_image = "bootia32.efi"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500310 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500311 raise WicError("grub-efi is incompatible with target %s" %
312 target_arch)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500313
Brad Bishopc4ea0752018-11-15 14:30:15 -0800314 grub_target = os.path.join(target_dir, grub_dest_image)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500315 if not os.path.isfile(grub_target):
Brad Bishopc4ea0752018-11-15 14:30:15 -0800316 grub_src = os.path.join(deploy_dir, grub_src_image)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500317 if not os.path.exists(grub_src):
318 raise WicError("Grub loader %s is not found in %s. "
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800319 "Please build grub-efi first" % (grub_src_image, deploy_dir))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500320 shutil.copy(grub_src, grub_target)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500321
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500322 if not os.path.isfile(os.path.join(target_dir, "boot.cfg")):
323 cls.do_configure_grubefi(part, creator, target_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500324
325 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500326 raise WicError("unrecognized bootimg-efi loader: %s" %
327 source_params['loader'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500328 except KeyError:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500329 raise WicError("bootimg-efi requires a loader, none specified")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500330
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500331 # Create efi.img that contains bootloader files for EFI booting
332 # if ISODIR didn't exist or didn't contains it
333 if os.path.isfile("%s/efi.img" % img_iso_dir):
334 install_cmd = "install -m 0644 %s/efi.img %s/efi.img" % \
335 (img_iso_dir, isodir)
336 exec_cmd(install_cmd)
337 else:
338 du_cmd = "du -bks %s/EFI" % isodir
339 out = exec_cmd(du_cmd)
340 blocks = int(out.split()[0])
341 # Add some extra space for file system overhead
342 blocks += 100
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500343 logger.debug("Added 100 extra blocks to %s to get to %d "
344 "total blocks", part.mountpoint, blocks)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500345
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500346 # dosfs image for EFI boot
347 bootimg = "%s/efi.img" % isodir
348
349 dosfs_cmd = 'mkfs.vfat -n "EFIimg" -S 512 -C %s %d' \
350 % (bootimg, blocks)
351 exec_native_cmd(dosfs_cmd, native_sysroot)
352
353 mmd_cmd = "mmd -i %s ::/EFI" % bootimg
354 exec_native_cmd(mmd_cmd, native_sysroot)
355
356 mcopy_cmd = "mcopy -i %s -s %s/EFI/* ::/EFI/" \
357 % (bootimg, isodir)
358 exec_native_cmd(mcopy_cmd, native_sysroot)
359
360 chmod_cmd = "chmod 644 %s" % bootimg
361 exec_cmd(chmod_cmd)
362
363 # Prepare files for legacy boot
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500364 syslinux_dir = get_bitbake_var("STAGING_DATADIR")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500365 if not syslinux_dir:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500366 raise WicError("Couldn't find STAGING_DATADIR, exiting.")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500367
368 if os.path.exists("%s/isolinux" % isodir):
369 shutil.rmtree("%s/isolinux" % isodir)
370
371 install_cmd = "install -d %s/isolinux" % isodir
372 exec_cmd(install_cmd)
373
374 cls.do_configure_syslinux(creator, cr_workdir)
375
376 install_cmd = "install -m 444 %s/syslinux/ldlinux.sys " % syslinux_dir
377 install_cmd += "%s/isolinux/ldlinux.sys" % isodir
378 exec_cmd(install_cmd)
379
380 install_cmd = "install -m 444 %s/syslinux/isohdpfx.bin " % syslinux_dir
381 install_cmd += "%s/isolinux/isohdpfx.bin" % isodir
382 exec_cmd(install_cmd)
383
384 install_cmd = "install -m 644 %s/syslinux/isolinux.bin " % syslinux_dir
385 install_cmd += "%s/isolinux/isolinux.bin" % isodir
386 exec_cmd(install_cmd)
387
388 install_cmd = "install -m 644 %s/syslinux/ldlinux.c32 " % syslinux_dir
389 install_cmd += "%s/isolinux/ldlinux.c32" % isodir
390 exec_cmd(install_cmd)
391
392 #create ISO image
393 iso_img = "%s/tempiso_img.iso" % cr_workdir
394 iso_bootimg = "isolinux/isolinux.bin"
395 iso_bootcat = "isolinux/boot.cat"
396 efi_img = "efi.img"
397
398 mkisofs_cmd = "mkisofs -V %s " % part.label
399 mkisofs_cmd += "-o %s -U " % iso_img
400 mkisofs_cmd += "-J -joliet-long -r -iso-level 2 -b %s " % iso_bootimg
401 mkisofs_cmd += "-c %s -no-emul-boot -boot-load-size 4 " % iso_bootcat
402 mkisofs_cmd += "-boot-info-table -eltorito-alt-boot "
403 mkisofs_cmd += "-eltorito-platform 0xEF -eltorito-boot %s " % efi_img
404 mkisofs_cmd += "-no-emul-boot %s " % isodir
405
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500406 logger.debug("running command: %s", mkisofs_cmd)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500407 exec_native_cmd(mkisofs_cmd, native_sysroot)
408
409 shutil.rmtree(isodir)
410
411 du_cmd = "du -Lbks %s" % iso_img
412 out = exec_cmd(du_cmd)
413 isoimg_size = int(out.split()[0])
414
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500415 part.size = isoimg_size
416 part.source_file = iso_img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500417
418 @classmethod
419 def do_install_disk(cls, disk, disk_name, creator, workdir, oe_builddir,
420 bootimg_dir, kernel_dir, native_sysroot):
421 """
422 Called after all partitions have been prepared and assembled into a
423 disk image. In this case, we insert/modify the MBR using isohybrid
424 utility for booting via BIOS from disk storage devices.
425 """
426
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500427 iso_img = "%s.p1" % disk.path
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500428 full_path = creator._full_path(workdir, disk_name, "direct")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500429 full_path_iso = creator._full_path(workdir, disk_name, "iso")
430
431 isohybrid_cmd = "isohybrid -u %s" % iso_img
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500432 logger.debug("running command: %s", isohybrid_cmd)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500433 exec_native_cmd(isohybrid_cmd, native_sysroot)
434
435 # Replace the image created by direct plugin with the one created by
436 # mkisofs command. This is necessary because the iso image created by
437 # mkisofs has a very specific MBR is system area of the ISO image, and
438 # direct plugin adds and configures an another MBR.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500439 logger.debug("Replaceing the image created by direct plugin\n")
440 os.remove(disk.path)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500441 shutil.copy2(iso_img, full_path_iso)
442 shutil.copy2(full_path_iso, full_path)