blob: afc9ea0f8fefff8b6beadc205ffec986aa46b157 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#
Brad Bishopc342db32019-05-15 21:57:59 -04002# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003#
4# DESCRIPTION
5# This implements the 'isoimage-isohybrid' source plugin class for 'wic'
6#
7# AUTHORS
8# Mihaly Varga <mihaly.varga (at] ni.com>
9
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010import glob
11import logging
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012import os
13import re
14import shutil
15
Brad Bishop6e60e8b2018-02-01 10:27:11 -050016from wic import WicError
17from wic.engine import get_custom_config
Patrick Williamsc124f4f2015-09-15 14:41:29 -050018from wic.pluginbase import SourcePlugin
Brad Bishopd7bf8c12018-02-25 22:55:05 -050019from wic.misc import exec_cmd, exec_native_cmd, get_bitbake_var
Brad Bishop6e60e8b2018-02-01 10:27:11 -050020
21logger = logging.getLogger('wic')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050022
23class IsoImagePlugin(SourcePlugin):
24 """
25 Create a bootable ISO image
26
27 This plugin creates a hybrid, legacy and EFI bootable ISO image. The
28 generated image can be used on optical media as well as USB media.
29
30 Legacy boot uses syslinux and EFI boot uses grub or gummiboot (not
31 implemented yet) as bootloader. The plugin creates the directories required
32 by bootloaders and populates them by creating and configuring the
33 bootloader files.
34
35 Example kickstart file:
36 part /boot --source isoimage-isohybrid --sourceparams="loader=grub-efi, \\
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080037 image_name= IsoImage" --ondisk cd --label LIVECD
Patrick Williamsc124f4f2015-09-15 14:41:29 -050038 bootloader --timeout=10 --append=" "
39
40 In --sourceparams "loader" specifies the bootloader used for booting in EFI
41 mode, while "image_name" specifies the name of the generated image. In the
42 example above, wic creates an ISO image named IsoImage-cd.direct (default
43 extension added by direct imeger plugin) and a file named IsoImage-cd.iso
44 """
45
46 name = 'isoimage-isohybrid'
47
48 @classmethod
49 def do_configure_syslinux(cls, creator, cr_workdir):
50 """
51 Create loader-specific (syslinux) config
52 """
Patrick Williamsc0f7c042017-02-23 20:41:17 -060053 splash = os.path.join(cr_workdir, "ISO/boot/splash.jpg")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050054 if os.path.exists(splash):
55 splashline = "menu background splash.jpg"
56 else:
57 splashline = ""
58
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050059 bootloader = creator.ks.bootloader
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060
61 syslinux_conf = ""
62 syslinux_conf += "PROMPT 0\n"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050063 syslinux_conf += "TIMEOUT %s \n" % (bootloader.timeout or 10)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050064 syslinux_conf += "\n"
65 syslinux_conf += "ALLOWOPTIONS 1\n"
66 syslinux_conf += "SERIAL 0 115200\n"
67 syslinux_conf += "\n"
68 if splashline:
69 syslinux_conf += "%s\n" % splashline
70 syslinux_conf += "DEFAULT boot\n"
71 syslinux_conf += "LABEL boot\n"
72
Brad Bishop15ae2502019-06-18 21:44:24 -040073 kernel = get_bitbake_var("KERNEL_IMAGETYPE")
Brad Bishop96ff1982019-08-19 13:50:42 -040074 if get_bitbake_var("INITRAMFS_IMAGE_BUNDLE") == "1":
75 if get_bitbake_var("INITRAMFS_IMAGE"):
76 kernel = "%s-%s.bin" % \
77 (get_bitbake_var("KERNEL_IMAGETYPE"), get_bitbake_var("INITRAMFS_LINK_NAME"))
78
Brad Bishop15ae2502019-06-18 21:44:24 -040079 syslinux_conf += "KERNEL /" + kernel + "\n"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050080 syslinux_conf += "APPEND initrd=/initrd LABEL=boot %s\n" \
81 % bootloader.append
Patrick Williamsc124f4f2015-09-15 14:41:29 -050082
Brad Bishop6e60e8b2018-02-01 10:27:11 -050083 logger.debug("Writing syslinux config %s/ISO/isolinux/isolinux.cfg",
84 cr_workdir)
85
Patrick Williamsc124f4f2015-09-15 14:41:29 -050086 with open("%s/ISO/isolinux/isolinux.cfg" % cr_workdir, "w") as cfg:
87 cfg.write(syslinux_conf)
88
89 @classmethod
Brad Bishopd7bf8c12018-02-25 22:55:05 -050090 def do_configure_grubefi(cls, part, creator, target_dir):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050091 """
92 Create loader-specific (grub-efi) config
93 """
Patrick Williamsc0f7c042017-02-23 20:41:17 -060094 configfile = creator.ks.bootloader.configfile
95 if configfile:
96 grubefi_conf = get_custom_config(configfile)
97 if grubefi_conf:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050098 logger.debug("Using custom configuration file %s for grub.cfg",
99 configfile)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600100 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500101 raise WicError("configfile is specified "
102 "but failed to get it from %s", configfile)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500103 else:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500104 splash = os.path.join(target_dir, "splash.jpg")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600105 if os.path.exists(splash):
106 splashline = "menu background splash.jpg"
107 else:
108 splashline = ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500109
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600110 bootloader = creator.ks.bootloader
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500111
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600112 grubefi_conf = ""
113 grubefi_conf += "serial --unit=0 --speed=115200 --word=8 "
114 grubefi_conf += "--parity=no --stop=1\n"
115 grubefi_conf += "default=boot\n"
116 grubefi_conf += "timeout=%s\n" % (bootloader.timeout or 10)
117 grubefi_conf += "\n"
118 grubefi_conf += "search --set=root --label %s " % part.label
119 grubefi_conf += "\n"
120 grubefi_conf += "menuentry 'boot'{\n"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500121
Brad Bishop15ae2502019-06-18 21:44:24 -0400122 kernel = get_bitbake_var("KERNEL_IMAGETYPE")
Brad Bishop96ff1982019-08-19 13:50:42 -0400123 if get_bitbake_var("INITRAMFS_IMAGE_BUNDLE") == "1":
124 if get_bitbake_var("INITRAMFS_IMAGE"):
125 kernel = "%s-%s.bin" % \
126 (get_bitbake_var("KERNEL_IMAGETYPE"), get_bitbake_var("INITRAMFS_LINK_NAME"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500127
Brad Bishop15ae2502019-06-18 21:44:24 -0400128 grubefi_conf += "linux /%s rootwait %s\n" \
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600129 % (kernel, bootloader.append)
130 grubefi_conf += "initrd /initrd \n"
131 grubefi_conf += "}\n"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500132
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600133 if splashline:
134 grubefi_conf += "%s\n" % splashline
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500135
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500136 cfg_path = os.path.join(target_dir, "grub.cfg")
137 logger.debug("Writing grubefi config %s", cfg_path)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500138
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500139 with open(cfg_path, "w") as cfg:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500140 cfg.write(grubefi_conf)
141
142 @staticmethod
143 def _build_initramfs_path(rootfs_dir, cr_workdir):
144 """
145 Create path for initramfs image
146 """
147
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500148 initrd = get_bitbake_var("INITRD_LIVE") or get_bitbake_var("INITRD")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500149 if not initrd:
150 initrd_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
151 if not initrd_dir:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500152 raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting.")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500153
154 image_name = get_bitbake_var("IMAGE_BASENAME")
155 if not image_name:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500156 raise WicError("Couldn't find IMAGE_BASENAME, exiting.")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500157
158 image_type = get_bitbake_var("INITRAMFS_FSTYPES")
159 if not image_type:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500160 raise WicError("Couldn't find INITRAMFS_FSTYPES, exiting.")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500161
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500162 machine = os.path.basename(initrd_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500163
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500164 pattern = '%s/%s*%s.%s' % (initrd_dir, image_name, machine, image_type)
165 files = glob.glob(pattern)
166 if files:
167 initrd = files[0]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500168
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500169 if not initrd or not os.path.exists(initrd):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500170 # Create initrd from rootfs directory
171 initrd = "%s/initrd.cpio.gz" % cr_workdir
172 initrd_dir = "%s/INITRD" % cr_workdir
173 shutil.copytree("%s" % rootfs_dir, \
174 "%s" % initrd_dir, symlinks=True)
175
176 if os.path.isfile("%s/init" % rootfs_dir):
177 shutil.copy2("%s/init" % rootfs_dir, "%s/init" % initrd_dir)
178 elif os.path.lexists("%s/init" % rootfs_dir):
179 os.symlink(os.readlink("%s/init" % rootfs_dir), \
180 "%s/init" % initrd_dir)
181 elif os.path.isfile("%s/sbin/init" % rootfs_dir):
182 shutil.copy2("%s/sbin/init" % rootfs_dir, \
183 "%s" % initrd_dir)
184 elif os.path.lexists("%s/sbin/init" % rootfs_dir):
185 os.symlink(os.readlink("%s/sbin/init" % rootfs_dir), \
186 "%s/init" % initrd_dir)
187 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500188 raise WicError("Couldn't find or build initrd, exiting.")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500189
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800190 exec_cmd("cd %s && find . | cpio -o -H newc -R root:root >%s/initrd.cpio " \
191 % (initrd_dir, cr_workdir), as_shell=True)
192 exec_cmd("gzip -f -9 %s/initrd.cpio" % cr_workdir, as_shell=True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500193 shutil.rmtree(initrd_dir)
194
195 return initrd
196
197 @classmethod
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500198 def do_configure_partition(cls, part, source_params, creator, cr_workdir,
199 oe_builddir, bootimg_dir, kernel_dir,
200 native_sysroot):
201 """
202 Called before do_prepare_partition(), creates loader-specific config
203 """
204 isodir = "%s/ISO/" % cr_workdir
205
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500206 if os.path.exists(isodir):
207 shutil.rmtree(isodir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500208
209 install_cmd = "install -d %s " % isodir
210 exec_cmd(install_cmd)
211
212 # Overwrite the name of the created image
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500213 logger.debug(source_params)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500214 if 'image_name' in source_params and \
215 source_params['image_name'].strip():
216 creator.name = source_params['image_name'].strip()
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500217 logger.debug("The name of the image is: %s", creator.name)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500218
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600219 @staticmethod
220 def _install_payload(source_params, iso_dir):
221 """
222 Copies contents of payload directory (as specified in 'payload_dir' param) into iso_dir
223 """
224
225 if source_params.get('payload_dir'):
226 payload_dir = source_params['payload_dir']
227
228 logger.debug("Payload directory: %s", payload_dir)
229 shutil.copytree(payload_dir, iso_dir, symlinks=True, dirs_exist_ok=True)
230
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500231 @classmethod
232 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
233 oe_builddir, bootimg_dir, kernel_dir,
234 rootfs_dir, native_sysroot):
235 """
236 Called to do the actual content population for a partition i.e. it
237 'prepares' the partition to be incorporated into the image.
238 In this case, prepare content for a bootable ISO image.
239 """
240
241 isodir = "%s/ISO" % cr_workdir
242
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600243 cls._install_payload(source_params, isodir)
244
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500245 if part.rootfs_dir is None:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500246 if not 'ROOTFS_DIR' in rootfs_dir:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500247 raise WicError("Couldn't find --rootfs-dir, exiting.")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500248 rootfs_dir = rootfs_dir['ROOTFS_DIR']
249 else:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500250 if part.rootfs_dir in rootfs_dir:
251 rootfs_dir = rootfs_dir[part.rootfs_dir]
252 elif part.rootfs_dir:
253 rootfs_dir = part.rootfs_dir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500254 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500255 raise WicError("Couldn't find --rootfs-dir=%s connection "
256 "or it is not a valid path, exiting." %
257 part.rootfs_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500258
259 if not os.path.isdir(rootfs_dir):
260 rootfs_dir = get_bitbake_var("IMAGE_ROOTFS")
261 if not os.path.isdir(rootfs_dir):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500262 raise WicError("Couldn't find IMAGE_ROOTFS, exiting.")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500263
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500264 part.rootfs_dir = rootfs_dir
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500265 deploy_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500266 img_iso_dir = get_bitbake_var("ISODIR")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500267
268 # Remove the temporary file created by part.prepare_rootfs()
269 if os.path.isfile(part.source_file):
270 os.remove(part.source_file)
271
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500272 # Support using a different initrd other than default
273 if source_params.get('initrd'):
274 initrd = source_params['initrd']
275 if not deploy_dir:
276 raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting")
277 cp_cmd = "cp %s/%s %s" % (deploy_dir, initrd, cr_workdir)
278 exec_cmd(cp_cmd)
279 else:
280 # Prepare initial ramdisk
281 initrd = "%s/initrd" % deploy_dir
282 if not os.path.isfile(initrd):
283 initrd = "%s/initrd" % img_iso_dir
284 if not os.path.isfile(initrd):
285 initrd = cls._build_initramfs_path(rootfs_dir, cr_workdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500286
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500287 install_cmd = "install -m 0644 %s %s/initrd" % (initrd, isodir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500288 exec_cmd(install_cmd)
289
290 # Remove the temporary file created by _build_initramfs_path function
291 if os.path.isfile("%s/initrd.cpio.gz" % cr_workdir):
292 os.remove("%s/initrd.cpio.gz" % cr_workdir)
293
Brad Bishop15ae2502019-06-18 21:44:24 -0400294 kernel = get_bitbake_var("KERNEL_IMAGETYPE")
Brad Bishop96ff1982019-08-19 13:50:42 -0400295 if get_bitbake_var("INITRAMFS_IMAGE_BUNDLE") == "1":
296 if get_bitbake_var("INITRAMFS_IMAGE"):
297 kernel = "%s-%s.bin" % \
298 (get_bitbake_var("KERNEL_IMAGETYPE"), get_bitbake_var("INITRAMFS_LINK_NAME"))
Brad Bishop15ae2502019-06-18 21:44:24 -0400299
300 install_cmd = "install -m 0644 %s/%s %s/%s" % \
301 (kernel_dir, kernel, isodir, kernel)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500302 exec_cmd(install_cmd)
303
304 #Create bootloader for efi boot
305 try:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500306 target_dir = "%s/EFI/BOOT" % isodir
307 if os.path.exists(target_dir):
308 shutil.rmtree(target_dir)
309
310 os.makedirs(target_dir)
311
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500312 if source_params['loader'] == 'grub-efi':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500313 # Builds bootx64.efi/bootia32.efi if ISODIR didn't exist or
314 # didn't contains it
315 target_arch = get_bitbake_var("TARGET_SYS")
316 if not target_arch:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500317 raise WicError("Coludn't find target architecture")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500318
319 if re.match("x86_64", target_arch):
Brad Bishopc4ea0752018-11-15 14:30:15 -0800320 grub_src_image = "grub-efi-bootx64.efi"
321 grub_dest_image = "bootx64.efi"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500322 elif re.match('i.86', target_arch):
Brad Bishopc4ea0752018-11-15 14:30:15 -0800323 grub_src_image = "grub-efi-bootia32.efi"
324 grub_dest_image = "bootia32.efi"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500325 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500326 raise WicError("grub-efi is incompatible with target %s" %
327 target_arch)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500328
Brad Bishopc4ea0752018-11-15 14:30:15 -0800329 grub_target = os.path.join(target_dir, grub_dest_image)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500330 if not os.path.isfile(grub_target):
Brad Bishopc4ea0752018-11-15 14:30:15 -0800331 grub_src = os.path.join(deploy_dir, grub_src_image)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500332 if not os.path.exists(grub_src):
333 raise WicError("Grub loader %s is not found in %s. "
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800334 "Please build grub-efi first" % (grub_src_image, deploy_dir))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500335 shutil.copy(grub_src, grub_target)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500336
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500337 if not os.path.isfile(os.path.join(target_dir, "boot.cfg")):
338 cls.do_configure_grubefi(part, creator, target_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500339
340 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500341 raise WicError("unrecognized bootimg-efi loader: %s" %
342 source_params['loader'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500343 except KeyError:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500344 raise WicError("bootimg-efi requires a loader, none specified")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500345
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500346 # Create efi.img that contains bootloader files for EFI booting
347 # if ISODIR didn't exist or didn't contains it
348 if os.path.isfile("%s/efi.img" % img_iso_dir):
349 install_cmd = "install -m 0644 %s/efi.img %s/efi.img" % \
350 (img_iso_dir, isodir)
351 exec_cmd(install_cmd)
352 else:
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500353 # Default to 100 blocks of extra space for file system overhead
354 esp_extra_blocks = int(source_params.get('esp_extra_blocks', '100'))
355
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500356 du_cmd = "du -bks %s/EFI" % isodir
357 out = exec_cmd(du_cmd)
358 blocks = int(out.split()[0])
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500359 blocks += esp_extra_blocks
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500360 logger.debug("Added 100 extra blocks to %s to get to %d "
361 "total blocks", part.mountpoint, blocks)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500362
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500363 # dosfs image for EFI boot
364 bootimg = "%s/efi.img" % isodir
365
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500366 esp_label = source_params.get('esp_label', 'EFIimg')
367
368 dosfs_cmd = 'mkfs.vfat -n \'%s\' -S 512 -C %s %d' \
369 % (esp_label, bootimg, blocks)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500370 exec_native_cmd(dosfs_cmd, native_sysroot)
371
372 mmd_cmd = "mmd -i %s ::/EFI" % bootimg
373 exec_native_cmd(mmd_cmd, native_sysroot)
374
375 mcopy_cmd = "mcopy -i %s -s %s/EFI/* ::/EFI/" \
376 % (bootimg, isodir)
377 exec_native_cmd(mcopy_cmd, native_sysroot)
378
379 chmod_cmd = "chmod 644 %s" % bootimg
380 exec_cmd(chmod_cmd)
381
382 # Prepare files for legacy boot
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500383 syslinux_dir = get_bitbake_var("STAGING_DATADIR")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500384 if not syslinux_dir:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500385 raise WicError("Couldn't find STAGING_DATADIR, exiting.")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500386
387 if os.path.exists("%s/isolinux" % isodir):
388 shutil.rmtree("%s/isolinux" % isodir)
389
390 install_cmd = "install -d %s/isolinux" % isodir
391 exec_cmd(install_cmd)
392
393 cls.do_configure_syslinux(creator, cr_workdir)
394
395 install_cmd = "install -m 444 %s/syslinux/ldlinux.sys " % syslinux_dir
396 install_cmd += "%s/isolinux/ldlinux.sys" % isodir
397 exec_cmd(install_cmd)
398
399 install_cmd = "install -m 444 %s/syslinux/isohdpfx.bin " % syslinux_dir
400 install_cmd += "%s/isolinux/isohdpfx.bin" % isodir
401 exec_cmd(install_cmd)
402
403 install_cmd = "install -m 644 %s/syslinux/isolinux.bin " % syslinux_dir
404 install_cmd += "%s/isolinux/isolinux.bin" % isodir
405 exec_cmd(install_cmd)
406
407 install_cmd = "install -m 644 %s/syslinux/ldlinux.c32 " % syslinux_dir
408 install_cmd += "%s/isolinux/ldlinux.c32" % isodir
409 exec_cmd(install_cmd)
410
411 #create ISO image
412 iso_img = "%s/tempiso_img.iso" % cr_workdir
413 iso_bootimg = "isolinux/isolinux.bin"
414 iso_bootcat = "isolinux/boot.cat"
415 efi_img = "efi.img"
416
417 mkisofs_cmd = "mkisofs -V %s " % part.label
418 mkisofs_cmd += "-o %s -U " % iso_img
419 mkisofs_cmd += "-J -joliet-long -r -iso-level 2 -b %s " % iso_bootimg
420 mkisofs_cmd += "-c %s -no-emul-boot -boot-load-size 4 " % iso_bootcat
421 mkisofs_cmd += "-boot-info-table -eltorito-alt-boot "
422 mkisofs_cmd += "-eltorito-platform 0xEF -eltorito-boot %s " % efi_img
423 mkisofs_cmd += "-no-emul-boot %s " % isodir
424
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500425 logger.debug("running command: %s", mkisofs_cmd)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500426 exec_native_cmd(mkisofs_cmd, native_sysroot)
427
428 shutil.rmtree(isodir)
429
430 du_cmd = "du -Lbks %s" % iso_img
431 out = exec_cmd(du_cmd)
432 isoimg_size = int(out.split()[0])
433
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500434 part.size = isoimg_size
435 part.source_file = iso_img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500436
437 @classmethod
438 def do_install_disk(cls, disk, disk_name, creator, workdir, oe_builddir,
439 bootimg_dir, kernel_dir, native_sysroot):
440 """
441 Called after all partitions have been prepared and assembled into a
442 disk image. In this case, we insert/modify the MBR using isohybrid
443 utility for booting via BIOS from disk storage devices.
444 """
445
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500446 iso_img = "%s.p1" % disk.path
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500447 full_path = creator._full_path(workdir, disk_name, "direct")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500448 full_path_iso = creator._full_path(workdir, disk_name, "iso")
449
450 isohybrid_cmd = "isohybrid -u %s" % iso_img
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500451 logger.debug("running command: %s", isohybrid_cmd)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500452 exec_native_cmd(isohybrid_cmd, native_sysroot)
453
454 # Replace the image created by direct plugin with the one created by
455 # mkisofs command. This is necessary because the iso image created by
456 # mkisofs has a very specific MBR is system area of the ISO image, and
457 # direct plugin adds and configures an another MBR.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500458 logger.debug("Replaceing the image created by direct plugin\n")
459 os.remove(disk.path)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500460 shutil.copy2(iso_img, full_path_iso)
461 shutil.copy2(full_path_iso, full_path)