def finalize(self): """ Finalize the disk image. For example, prepare the image to be bootable by e.g. creating and installing a bootloader configuration. """ source_plugin = self.ks.bootloader.source disk_name = self.parts[0].disk if source_plugin: plugin = PluginMgr.get_plugins('source')[source_plugin] plugin.do_install_disk(self._image, disk_name, self, self.workdir, self.oe_builddir, self.bootimg_dir, self.kernel_dir, self.native_sysroot) full_path = self._image.path # Generate .bmap if self.bmap: logger.debug("Generating bmap file for %s", disk_name) python = os.path.join(self.native_sysroot, 'usr/bin/python3-native/python3') bmaptool = os.path.join(self.native_sysroot, 'usr/bin/bmaptool') exec_native_cmd("%s %s create %s -o %s.bmap" % \ (python, bmaptool, full_path, full_path), self.native_sysroot) # Compress the image if self.compressor: logger.debug("Compressing disk %s with %s", disk_name, self.compressor) exec_cmd("%s %s" % (self.compressor, full_path))
def list_source_plugins(): """ List the available source plugins i.e. plugins available for --source. """ plugins = PluginMgr.get_plugins('source') for plugin in plugins: print(" %s" % plugin)
def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir, native_sysroot, options): """ Create image wks_file - user-defined OE kickstart file rootfs_dir - absolute path to the build's /rootfs dir bootimg_dir - absolute path to the build's boot artifacts directory kernel_dir - absolute path to the build's kernel directory native_sysroot - absolute path to the build's native sysroots dir image_output_dir - dirname to create for image options - wic command line options (debug, bmap, etc) Normally, the values for the build artifacts values are determined by 'wic -e' from the output of the 'bitbake -e' command given an image name e.g. 'core-image-minimal' and a given machine set in local.conf. If that's the case, the variables get the following values from the output of 'bitbake -e': rootfs_dir: IMAGE_ROOTFS kernel_dir: DEPLOY_DIR_IMAGE native_sysroot: STAGING_DIR_NATIVE In the above case, bootimg_dir remains unset and the plugin-specific image creation code is responsible for finding the bootimg artifacts. In the case where the values are passed in explicitly i.e 'wic -e' is not used but rather the individual 'wic' options are used to explicitly specify these values. """ try: oe_builddir = os.environ["BUILDDIR"] except KeyError: raise WicError( "BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)" ) if not os.path.exists(options.outdir): os.makedirs(options.outdir) pname = options.imager plugin_class = PluginMgr.get_plugins('imager').get(pname) if not plugin_class: raise WicError('Unknown plugin: %s' % pname) plugin = plugin_class(wks_file, rootfs_dir, bootimg_dir, kernel_dir, native_sysroot, oe_builddir, options) plugin.do_create() logger.info("The image(s) were created using OE kickstart file:\n %s", wks_file)
def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir, native_sysroot, options): """ Create image wks_file - user-defined OE kickstart file rootfs_dir - absolute path to the build's /rootfs dir bootimg_dir - absolute path to the build's boot artifacts directory kernel_dir - absolute path to the build's kernel directory native_sysroot - absolute path to the build's native sysroots dir image_output_dir - dirname to create for image options - wic command line options (debug, bmap, etc) Normally, the values for the build artifacts values are determined by 'wic -e' from the output of the 'bitbake -e' command given an image name e.g. 'core-image-minimal' and a given machine set in local.conf. If that's the case, the variables get the following values from the output of 'bitbake -e': rootfs_dir: IMAGE_ROOTFS kernel_dir: DEPLOY_DIR_IMAGE native_sysroot: STAGING_DIR_NATIVE In the above case, bootimg_dir remains unset and the plugin-specific image creation code is responsible for finding the bootimg artifacts. In the case where the values are passed in explicitly i.e 'wic -e' is not used but rather the individual 'wic' options are used to explicitly specify these values. """ try: oe_builddir = os.environ["BUILDDIR"] except KeyError: raise WicError("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)") if not os.path.exists(options.outdir): os.makedirs(options.outdir) pname = options.imager plugin_class = PluginMgr.get_plugins('imager').get(pname) if not plugin_class: raise WicError('Unknown plugin: %s' % pname) plugin = plugin_class(wks_file, rootfs_dir, bootimg_dir, kernel_dir, native_sysroot, oe_builddir, options) plugin.do_create() logger.info("The image(s) were created using OE kickstart file:\n %s", wks_file)
def get_wic_plugins_help(): """ Combine wic_plugins_help with the help for every known source plugin. """ result = wic_plugins_help for plugin_type in PLUGIN_TYPES: result += '\n\n%s PLUGINS\n\n' % plugin_type.upper() for name, plugin in PluginMgr.get_plugins(plugin_type).items(): result += "\n %s plugin:\n" % name if plugin.__doc__: result += plugin.__doc__ else: result += "\n %s is missing docstring\n" % plugin return result
def prepare(self, creator, cr_workdir, oe_builddir, rootfs_dir, bootimg_dir, kernel_dir, native_sysroot): """ Prepare content for individual partitions, depending on partition command parameters. """ if not self.source: if not self.size and not self.fixed_size: raise WicError("The %s partition has a size of zero. Please " "specify a non-zero --size/--fixed-size for that " "partition." % self.mountpoint) if self.fstype == "swap": self.prepare_swap_partition(cr_workdir, oe_builddir, native_sysroot) self.source_file = "%s/fs.%s" % (cr_workdir, self.fstype) else: if self.fstype == 'squashfs': raise WicError("It's not possible to create empty squashfs " "partition '%s'" % (self.mountpoint)) rootfs = "%s/fs_%s.%s.%s" % (cr_workdir, self.label, self.lineno, self.fstype) if os.path.isfile(rootfs): os.remove(rootfs) prefix = "ext" if self.fstype.startswith("ext") else self.fstype method = getattr(self, "prepare_empty_partition_" + prefix) method(rootfs, oe_builddir, native_sysroot) self.source_file = rootfs return plugins = PluginMgr.get_plugins('source') if self.source not in plugins: raise WicError("The '%s' --source specified for %s doesn't exist.\n\t" "See 'wic list source-plugins' for a list of available" " --sources.\n\tSee 'wic help source-plugins' for " "details on adding a new source plugin." % (self.source, self.mountpoint)) srcparams_dict = {} if self.sourceparams: # Split sourceparams string of the form key1=val1[,key2=val2,...] # into a dict. Also accepts valueless keys i.e. without = splitted = self.sourceparams.split(',') srcparams_dict = dict(par.split('=') for par in splitted if par) plugin = PluginMgr.get_plugins('source')[self.source] plugin.do_configure_partition(self, srcparams_dict, creator, cr_workdir, oe_builddir, bootimg_dir, kernel_dir, native_sysroot) plugin.do_stage_partition(self, srcparams_dict, creator, cr_workdir, oe_builddir, bootimg_dir, kernel_dir, native_sysroot) plugin.do_prepare_partition(self, srcparams_dict, creator, cr_workdir, oe_builddir, bootimg_dir, kernel_dir, rootfs_dir, native_sysroot) # further processing required Partition.size to be an integer, make # sure that it is one if not isinstance(self.size, int): raise WicError("Partition %s internal size is not an integer. " "This a bug in source plugin %s and needs to be fixed." % (self.mountpoint, self.source)) if self.fixed_size and self.size > self.fixed_size: raise WicError("File system image of partition %s is " "larger (%d kB) than its allowed size %d kB" % (self.mountpoint, self.size, self.fixed_size))
def prepare(self, creator, cr_workdir, oe_builddir, rootfs_dir, bootimg_dir, kernel_dir, native_sysroot): """ Prepare content for individual partitions, depending on partition command parameters. """ if not self.source: if not self.size and not self.fixed_size: raise WicError( "The %s partition has a size of zero. Please " "specify a non-zero --size/--fixed-size for that " "partition." % self.mountpoint) if self.fstype == "swap": self.prepare_swap_partition(cr_workdir, oe_builddir, native_sysroot) self.source_file = "%s/fs.%s" % (cr_workdir, self.fstype) else: if self.fstype == 'squashfs': raise WicError( "It's not possible to create empty squashfs " "partition '%s'" % (self.mountpoint)) rootfs = "%s/fs_%s.%s.%s" % (cr_workdir, self.label, self.lineno, self.fstype) if os.path.isfile(rootfs): os.remove(rootfs) prefix = "ext" if self.fstype.startswith( "ext") else self.fstype method = getattr(self, "prepare_empty_partition_" + prefix) method(rootfs, oe_builddir, native_sysroot) self.source_file = rootfs return plugins = PluginMgr.get_plugins('source') if self.source not in plugins: raise WicError( "The '%s' --source specified for %s doesn't exist.\n\t" "See 'wic list source-plugins' for a list of available" " --sources.\n\tSee 'wic help source-plugins' for " "details on adding a new source plugin." % (self.source, self.mountpoint)) srcparams_dict = {} if self.sourceparams: # Split sourceparams string of the form key1=val1[,key2=val2,...] # into a dict. Also accepts valueless keys i.e. without = splitted = self.sourceparams.split(',') srcparams_dict = dict(par.split('=') for par in splitted if par) plugin = PluginMgr.get_plugins('source')[self.source] plugin.do_configure_partition(self, srcparams_dict, creator, cr_workdir, oe_builddir, bootimg_dir, kernel_dir, native_sysroot) plugin.do_stage_partition(self, srcparams_dict, creator, cr_workdir, oe_builddir, bootimg_dir, kernel_dir, native_sysroot) plugin.do_prepare_partition(self, srcparams_dict, creator, cr_workdir, oe_builddir, bootimg_dir, kernel_dir, rootfs_dir, native_sysroot) # further processing required Partition.size to be an integer, make # sure that it is one if not isinstance(self.size, int): raise WicError( "Partition %s internal size is not an integer. " "This a bug in source plugin %s and needs to be fixed." % (self.mountpoint, self.source)) if self.fixed_size and self.size > self.fixed_size: raise WicError("File system image of partition %s is " "larger (%d kB) than its allowed size %d kB" % (self.mountpoint, self.size, self.fixed_size))