summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/plugins/source/isoimage-isohybrid.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/wic/plugins/source/isoimage-isohybrid.py')
-rw-r--r--scripts/lib/wic/plugins/source/isoimage-isohybrid.py96
1 files changed, 58 insertions, 38 deletions
diff --git a/scripts/lib/wic/plugins/source/isoimage-isohybrid.py b/scripts/lib/wic/plugins/source/isoimage-isohybrid.py
index fb34235631..33de6d8db5 100644
--- a/scripts/lib/wic/plugins/source/isoimage-isohybrid.py
+++ b/scripts/lib/wic/plugins/source/isoimage-isohybrid.py
@@ -20,16 +20,19 @@
20# AUTHORS 20# AUTHORS
21# Mihaly Varga <mihaly.varga (at] ni.com> 21# Mihaly Varga <mihaly.varga (at] ni.com>
22 22
23import glob
24import logging
23import os 25import os
24import re 26import re
25import shutil 27import shutil
26import glob 28import sys
27 29
28from wic import msger
29from wic.engine import get_custom_config 30from wic.engine import get_custom_config
30from wic.pluginbase import SourcePlugin 31from wic.pluginbase import SourcePlugin
31from wic.utils.misc import exec_cmd, exec_native_cmd, get_bitbake_var 32from wic.utils.misc import exec_cmd, exec_native_cmd, get_bitbake_var
32 33
34logger = logging.getLogger('wic')
35
33class IsoImagePlugin(SourcePlugin): 36class IsoImagePlugin(SourcePlugin):
34 """ 37 """
35 Create a bootable ISO image 38 Create a bootable ISO image
@@ -85,8 +88,9 @@ class IsoImagePlugin(SourcePlugin):
85 syslinux_conf += "APPEND initrd=/initrd LABEL=boot %s\n" \ 88 syslinux_conf += "APPEND initrd=/initrd LABEL=boot %s\n" \
86 % bootloader.append 89 % bootloader.append
87 90
88 msger.debug("Writing syslinux config %s/ISO/isolinux/isolinux.cfg" \ 91 logger.debug("Writing syslinux config %s/ISO/isolinux/isolinux.cfg",
89 % cr_workdir) 92 cr_workdir)
93
90 with open("%s/ISO/isolinux/isolinux.cfg" % cr_workdir, "w") as cfg: 94 with open("%s/ISO/isolinux/isolinux.cfg" % cr_workdir, "w") as cfg:
91 cfg.write(syslinux_conf) 95 cfg.write(syslinux_conf)
92 96
@@ -99,11 +103,12 @@ class IsoImagePlugin(SourcePlugin):
99 if configfile: 103 if configfile:
100 grubefi_conf = get_custom_config(configfile) 104 grubefi_conf = get_custom_config(configfile)
101 if grubefi_conf: 105 if grubefi_conf:
102 msger.debug("Using custom configuration file " 106 logger.debug("Using custom configuration file %s for grub.cfg",
103 "%s for grub.cfg" % configfile) 107 configfile)
104 else: 108 else:
105 msger.error("configfile is specified but failed to " 109 logger.error("configfile is specified "
106 "get it from %s." % configfile) 110 "but failed to get it from %s", configfile)
111 sys.exit(1)
107 else: 112 else:
108 splash = os.path.join(cr_workdir, "EFI/boot/splash.jpg") 113 splash = os.path.join(cr_workdir, "EFI/boot/splash.jpg")
109 if os.path.exists(splash): 114 if os.path.exists(splash):
@@ -133,8 +138,8 @@ class IsoImagePlugin(SourcePlugin):
133 if splashline: 138 if splashline:
134 grubefi_conf += "%s\n" % splashline 139 grubefi_conf += "%s\n" % splashline
135 140
136 msger.debug("Writing grubefi config %s/EFI/BOOT/grub.cfg" \ 141 logger.debug("Writing grubefi config %s/EFI/BOOT/grub.cfg", cr_workdir)
137 % cr_workdir) 142
138 with open("%s/EFI/BOOT/grub.cfg" % cr_workdir, "w") as cfg: 143 with open("%s/EFI/BOOT/grub.cfg" % cr_workdir, "w") as cfg:
139 cfg.write(grubefi_conf) 144 cfg.write(grubefi_conf)
140 145
@@ -148,19 +153,23 @@ class IsoImagePlugin(SourcePlugin):
148 if not initrd: 153 if not initrd:
149 initrd_dir = get_bitbake_var("DEPLOY_DIR_IMAGE") 154 initrd_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
150 if not initrd_dir: 155 if not initrd_dir:
151 msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting.\n") 156 logger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting.\n")
157 sys.exit(1)
152 158
153 image_name = get_bitbake_var("IMAGE_BASENAME") 159 image_name = get_bitbake_var("IMAGE_BASENAME")
154 if not image_name: 160 if not image_name:
155 msger.error("Couldn't find IMAGE_BASENAME, exiting.\n") 161 logger.error("Couldn't find IMAGE_BASENAME, exiting.\n")
162 sys.exit(1)
156 163
157 image_type = get_bitbake_var("INITRAMFS_FSTYPES") 164 image_type = get_bitbake_var("INITRAMFS_FSTYPES")
158 if not image_type: 165 if not image_type:
159 msger.error("Couldn't find INITRAMFS_FSTYPES, exiting.\n") 166 logger.error("Couldn't find INITRAMFS_FSTYPES, exiting.\n")
167 sys.exit(1)
160 168
161 target_arch = get_bitbake_var("TRANSLATED_TARGET_ARCH") 169 target_arch = get_bitbake_var("TRANSLATED_TARGET_ARCH")
162 if not target_arch: 170 if not target_arch:
163 msger.error("Couldn't find TRANSLATED_TARGET_ARCH, exiting.\n") 171 logger.error("Couldn't find TRANSLATED_TARGET_ARCH, exiting.\n")
172 sys.exit(1)
164 173
165 initrd = glob.glob('%s/%s*%s.%s' % (initrd_dir, image_name, target_arch, image_type))[0] 174 initrd = glob.glob('%s/%s*%s.%s' % (initrd_dir, image_name, target_arch, image_type))[0]
166 175
@@ -183,7 +192,8 @@ class IsoImagePlugin(SourcePlugin):
183 os.symlink(os.readlink("%s/sbin/init" % rootfs_dir), \ 192 os.symlink(os.readlink("%s/sbin/init" % rootfs_dir), \
184 "%s/init" % initrd_dir) 193 "%s/init" % initrd_dir)
185 else: 194 else:
186 msger.error("Couldn't find or build initrd, exiting.\n") 195 logger.error("Couldn't find or build initrd, exiting.\n")
196 sys.exit(1)
187 197
188 exec_cmd("cd %s && find . | cpio -o -H newc -R +0:+0 >./initrd.cpio " \ 198 exec_cmd("cd %s && find . | cpio -o -H newc -R +0:+0 >./initrd.cpio " \
189 % initrd_dir, as_shell=True) 199 % initrd_dir, as_shell=True)
@@ -209,11 +219,11 @@ class IsoImagePlugin(SourcePlugin):
209 exec_cmd(install_cmd) 219 exec_cmd(install_cmd)
210 220
211 # Overwrite the name of the created image 221 # Overwrite the name of the created image
212 msger.debug("%s" % source_params) 222 logger.debug(source_params)
213 if 'image_name' in source_params and \ 223 if 'image_name' in source_params and \
214 source_params['image_name'].strip(): 224 source_params['image_name'].strip():
215 creator.name = source_params['image_name'].strip() 225 creator.name = source_params['image_name'].strip()
216 msger.debug("The name of the image is: %s" % creator.name) 226 logger.debug("The name of the image is: %s", creator.name)
217 227
218 @classmethod 228 @classmethod
219 def do_prepare_partition(cls, part, source_params, creator, cr_workdir, 229 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
@@ -229,7 +239,8 @@ class IsoImagePlugin(SourcePlugin):
229 239
230 if part.rootfs_dir is None: 240 if part.rootfs_dir is None:
231 if not 'ROOTFS_DIR' in rootfs_dir: 241 if not 'ROOTFS_DIR' in rootfs_dir:
232 msger.error("Couldn't find --rootfs-dir, exiting.\n") 242 logger.error("Couldn't find --rootfs-dir, exiting.\n")
243 sys.exit(1)
233 rootfs_dir = rootfs_dir['ROOTFS_DIR'] 244 rootfs_dir = rootfs_dir['ROOTFS_DIR']
234 else: 245 else:
235 if part.rootfs_dir in rootfs_dir: 246 if part.rootfs_dir in rootfs_dir:
@@ -237,14 +248,16 @@ class IsoImagePlugin(SourcePlugin):
237 elif part.rootfs_dir: 248 elif part.rootfs_dir:
238 rootfs_dir = part.rootfs_dir 249 rootfs_dir = part.rootfs_dir
239 else: 250 else:
240 msg = "Couldn't find --rootfs-dir=%s connection " 251 logger.error("Couldn't find --rootfs-dir=%s connection "
241 msg += "or it is not a valid path, exiting.\n" 252 "or it is not a valid path, exiting.\n",
242 msger.error(msg % part.rootfs_dir) 253 part.rootfs_dir)
254 sys.exit(1)
243 255
244 if not os.path.isdir(rootfs_dir): 256 if not os.path.isdir(rootfs_dir):
245 rootfs_dir = get_bitbake_var("IMAGE_ROOTFS") 257 rootfs_dir = get_bitbake_var("IMAGE_ROOTFS")
246 if not os.path.isdir(rootfs_dir): 258 if not os.path.isdir(rootfs_dir):
247 msger.error("Couldn't find IMAGE_ROOTFS, exiting.\n") 259 logger.error("Couldn't find IMAGE_ROOTFS, exiting.\n")
260 sys.exit(1)
248 261
249 part.rootfs_dir = rootfs_dir 262 part.rootfs_dir = rootfs_dir
250 263
@@ -283,7 +296,8 @@ class IsoImagePlugin(SourcePlugin):
283 if source_params.get('initrd'): 296 if source_params.get('initrd'):
284 initrd = source_params['initrd'] 297 initrd = source_params['initrd']
285 if not deploy_dir: 298 if not deploy_dir:
286 msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n") 299 logger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
300 sys.exit(1)
287 cp_cmd = "cp %s/%s %s" % (deploy_dir, initrd, cr_workdir) 301 cp_cmd = "cp %s/%s %s" % (deploy_dir, initrd, cr_workdir)
288 exec_cmd(cp_cmd) 302 exec_cmd(cp_cmd)
289 else: 303 else:
@@ -326,7 +340,8 @@ class IsoImagePlugin(SourcePlugin):
326 # didn't contains it 340 # didn't contains it
327 target_arch = get_bitbake_var("TARGET_SYS") 341 target_arch = get_bitbake_var("TARGET_SYS")
328 if not target_arch: 342 if not target_arch:
329 msger.error("Coludn't find target architecture\n") 343 logger.error("Coludn't find target architecture\n")
344 sys.exit(1)
330 345
331 if re.match("x86_64", target_arch): 346 if re.match("x86_64", target_arch):
332 grub_target = 'x86_64-efi' 347 grub_target = 'x86_64-efi'
@@ -335,18 +350,21 @@ class IsoImagePlugin(SourcePlugin):
335 grub_target = 'i386-efi' 350 grub_target = 'i386-efi'
336 grub_image = "bootia32.efi" 351 grub_image = "bootia32.efi"
337 else: 352 else:
338 msger.error("grub-efi is incompatible with target %s\n" \ 353 logger.error("grub-efi is incompatible with target %s\n",
339 % target_arch) 354 target_arch)
355 sys.exit(1)
340 356
341 if not os.path.isfile("%s/EFI/BOOT/%s" \ 357 if not os.path.isfile("%s/EFI/BOOT/%s" \
342 % (bootimg_dir, grub_image)): 358 % (bootimg_dir, grub_image)):
343 grub_path = get_bitbake_var("STAGING_LIBDIR", "wic-tools") 359 grub_path = get_bitbake_var("STAGING_LIBDIR", "wic-tools")
344 if not grub_path: 360 if not grub_path:
345 msger.error("Couldn't find STAGING_LIBDIR, exiting.\n") 361 logger.error("Couldn't find STAGING_LIBDIR, exiting.\n")
362 sys.exit(1)
346 363
347 grub_core = "%s/grub/%s" % (grub_path, grub_target) 364 grub_core = "%s/grub/%s" % (grub_path, grub_target)
348 if not os.path.exists(grub_core): 365 if not os.path.exists(grub_core):
349 msger.error("Please build grub-efi first\n") 366 logger.error("Please build grub-efi first\n")
367 sys.exit(1)
350 368
351 grub_cmd = "grub-mkimage -p '/EFI/BOOT' " 369 grub_cmd = "grub-mkimage -p '/EFI/BOOT' "
352 grub_cmd += "-d %s " % grub_core 370 grub_cmd += "-d %s " % grub_core
@@ -362,10 +380,12 @@ class IsoImagePlugin(SourcePlugin):
362 exec_native_cmd(grub_cmd, native_sysroot) 380 exec_native_cmd(grub_cmd, native_sysroot)
363 381
364 else: 382 else:
365 msger.error("unrecognized bootimg-efi loader: %s" \ 383 logger.error("unrecognized bootimg-efi loader: %s",
366 % source_params['loader']) 384 source_params['loader'])
385 sys.exit(1)
367 except KeyError: 386 except KeyError:
368 msger.error("bootimg-efi requires a loader, none specified") 387 logger.error("bootimg-efi requires a loader, none specified")
388 sys.exit(1)
369 389
370 if os.path.exists("%s/EFI/BOOT" % isodir): 390 if os.path.exists("%s/EFI/BOOT" % isodir):
371 shutil.rmtree("%s/EFI/BOOT" % isodir) 391 shutil.rmtree("%s/EFI/BOOT" % isodir)
@@ -388,9 +408,8 @@ class IsoImagePlugin(SourcePlugin):
388 blocks = int(out.split()[0]) 408 blocks = int(out.split()[0])
389 # Add some extra space for file system overhead 409 # Add some extra space for file system overhead
390 blocks += 100 410 blocks += 100
391 msg = "Added 100 extra blocks to %s to get to %d total blocks" \ 411 logger.debug("Added 100 extra blocks to %s to get to %d "
392 % (part.mountpoint, blocks) 412 "total blocks", part.mountpoint, blocks)
393 msger.debug(msg)
394 413
395 # dosfs image for EFI boot 414 # dosfs image for EFI boot
396 bootimg = "%s/efi.img" % isodir 415 bootimg = "%s/efi.img" % isodir
@@ -412,7 +431,8 @@ class IsoImagePlugin(SourcePlugin):
412 # Prepare files for legacy boot 431 # Prepare files for legacy boot
413 syslinux_dir = get_bitbake_var("STAGING_DATADIR", "wic-tools") 432 syslinux_dir = get_bitbake_var("STAGING_DATADIR", "wic-tools")
414 if not syslinux_dir: 433 if not syslinux_dir:
415 msger.error("Couldn't find STAGING_DATADIR, exiting.\n") 434 logger.error("Couldn't find STAGING_DATADIR, exiting.\n")
435 sys.exit(1)
416 436
417 if os.path.exists("%s/isolinux" % isodir): 437 if os.path.exists("%s/isolinux" % isodir):
418 shutil.rmtree("%s/isolinux" % isodir) 438 shutil.rmtree("%s/isolinux" % isodir)
@@ -452,7 +472,7 @@ class IsoImagePlugin(SourcePlugin):
452 mkisofs_cmd += "-eltorito-platform 0xEF -eltorito-boot %s " % efi_img 472 mkisofs_cmd += "-eltorito-platform 0xEF -eltorito-boot %s " % efi_img
453 mkisofs_cmd += "-no-emul-boot %s " % isodir 473 mkisofs_cmd += "-no-emul-boot %s " % isodir
454 474
455 msger.debug("running command: %s" % mkisofs_cmd) 475 logger.debug("running command: %s", mkisofs_cmd)
456 exec_native_cmd(mkisofs_cmd, native_sysroot) 476 exec_native_cmd(mkisofs_cmd, native_sysroot)
457 477
458 shutil.rmtree(isodir) 478 shutil.rmtree(isodir)
@@ -478,14 +498,14 @@ class IsoImagePlugin(SourcePlugin):
478 full_path_iso = creator._full_path(workdir, disk_name, "iso") 498 full_path_iso = creator._full_path(workdir, disk_name, "iso")
479 499
480 isohybrid_cmd = "isohybrid -u %s" % iso_img 500 isohybrid_cmd = "isohybrid -u %s" % iso_img
481 msger.debug("running command: %s" % isohybrid_cmd) 501 logger.debug("running command: %s", isohybrid_cmd)
482 exec_native_cmd(isohybrid_cmd, native_sysroot) 502 exec_native_cmd(isohybrid_cmd, native_sysroot)
483 503
484 # Replace the image created by direct plugin with the one created by 504 # Replace the image created by direct plugin with the one created by
485 # mkisofs command. This is necessary because the iso image created by 505 # mkisofs command. This is necessary because the iso image created by
486 # mkisofs has a very specific MBR is system area of the ISO image, and 506 # mkisofs has a very specific MBR is system area of the ISO image, and
487 # direct plugin adds and configures an another MBR. 507 # direct plugin adds and configures an another MBR.
488 msger.debug("Replaceing the image created by direct plugin\n") 508 logger.debug("Replaceing the image created by direct plugin\n")
489 os.remove(disk.path) 509 os.remove(disk.path)
490 shutil.copy2(iso_img, full_path_iso) 510 shutil.copy2(iso_img, full_path_iso)
491 shutil.copy2(full_path_iso, full_path) 511 shutil.copy2(full_path_iso, full_path)