generic-poky/scripts/lib/wic/pluginbase.py

112 lines
4.0 KiB
Python
Raw Normal View History

#!/usr/bin/env python -tt
wic: Add mic w/pykickstart This is the starting point for the implemention described in [YOCTO 3847] which came to the conclusion that it would make sense to use kickstart syntax to implement image creation in OpenEmbedded. I subsequently realized that there was an existing tool that already implemented image creation using kickstart syntax, the Tizen/Meego mic tool. As such, it made sense to use that as a starting point - this commit essentially just copies the relevant Python code from the MIC tool to the scripts/lib dir, where it can be accessed by the previously created wic tool. Most of this will be removed or renamed by later commits, since we're initially focusing on partitioning only. Care should be taken so that we can easily add back any additional functionality should we decide later to expand the tool, though (we may also want to contribute our local changes to the mic tool to the Tizen project if it makes sense, and therefore should avoid gratuitous changes to the original code if possible). Added the /mic subdir from Tizen mic repo as a starting point: git clone git://review.tizen.org/tools/mic.git For reference, the top commit: commit 20164175ddc234a17b8a12c33d04b012347b1530 Author: Gui Chen <gui.chen@intel.com> Date: Sun Jun 30 22:32:16 2013 -0400 bump up to 0.19.2 Also added the /plugins subdir, moved to under the /mic subdir (to match the default plugin_dir location in mic.conf.in, which was renamed to yocto-image.conf (moved and renamed by later patches) and put into /scripts. (From OE-Core rev: 31f0360f1fd4ebc9dfcaed42d1c50d2448b4632e) Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2013-08-24 15:31:34 +00:00
#
# Copyright (c) 2011 Intel, Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; version 2 of the License
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import os
import shutil
from wic import msger
from wic.utils import errors
wic: Add mic w/pykickstart This is the starting point for the implemention described in [YOCTO 3847] which came to the conclusion that it would make sense to use kickstart syntax to implement image creation in OpenEmbedded. I subsequently realized that there was an existing tool that already implemented image creation using kickstart syntax, the Tizen/Meego mic tool. As such, it made sense to use that as a starting point - this commit essentially just copies the relevant Python code from the MIC tool to the scripts/lib dir, where it can be accessed by the previously created wic tool. Most of this will be removed or renamed by later commits, since we're initially focusing on partitioning only. Care should be taken so that we can easily add back any additional functionality should we decide later to expand the tool, though (we may also want to contribute our local changes to the mic tool to the Tizen project if it makes sense, and therefore should avoid gratuitous changes to the original code if possible). Added the /mic subdir from Tizen mic repo as a starting point: git clone git://review.tizen.org/tools/mic.git For reference, the top commit: commit 20164175ddc234a17b8a12c33d04b012347b1530 Author: Gui Chen <gui.chen@intel.com> Date: Sun Jun 30 22:32:16 2013 -0400 bump up to 0.19.2 Also added the /plugins subdir, moved to under the /mic subdir (to match the default plugin_dir location in mic.conf.in, which was renamed to yocto-image.conf (moved and renamed by later patches) and put into /scripts. (From OE-Core rev: 31f0360f1fd4ebc9dfcaed42d1c50d2448b4632e) Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2013-08-24 15:31:34 +00:00
class _Plugin(object):
class __metaclass__(type):
def __init__(cls, name, bases, attrs):
if not hasattr(cls, 'plugins'):
cls.plugins = {}
elif 'wic_plugin_type' in attrs:
if attrs['wic_plugin_type'] not in cls.plugins:
cls.plugins[attrs['wic_plugin_type']] = {}
wic: Add mic w/pykickstart This is the starting point for the implemention described in [YOCTO 3847] which came to the conclusion that it would make sense to use kickstart syntax to implement image creation in OpenEmbedded. I subsequently realized that there was an existing tool that already implemented image creation using kickstart syntax, the Tizen/Meego mic tool. As such, it made sense to use that as a starting point - this commit essentially just copies the relevant Python code from the MIC tool to the scripts/lib dir, where it can be accessed by the previously created wic tool. Most of this will be removed or renamed by later commits, since we're initially focusing on partitioning only. Care should be taken so that we can easily add back any additional functionality should we decide later to expand the tool, though (we may also want to contribute our local changes to the mic tool to the Tizen project if it makes sense, and therefore should avoid gratuitous changes to the original code if possible). Added the /mic subdir from Tizen mic repo as a starting point: git clone git://review.tizen.org/tools/mic.git For reference, the top commit: commit 20164175ddc234a17b8a12c33d04b012347b1530 Author: Gui Chen <gui.chen@intel.com> Date: Sun Jun 30 22:32:16 2013 -0400 bump up to 0.19.2 Also added the /plugins subdir, moved to under the /mic subdir (to match the default plugin_dir location in mic.conf.in, which was renamed to yocto-image.conf (moved and renamed by later patches) and put into /scripts. (From OE-Core rev: 31f0360f1fd4ebc9dfcaed42d1c50d2448b4632e) Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2013-08-24 15:31:34 +00:00
elif hasattr(cls, 'wic_plugin_type') and 'name' in attrs:
cls.plugins[cls.wic_plugin_type][attrs['name']] = cls
wic: Add mic w/pykickstart This is the starting point for the implemention described in [YOCTO 3847] which came to the conclusion that it would make sense to use kickstart syntax to implement image creation in OpenEmbedded. I subsequently realized that there was an existing tool that already implemented image creation using kickstart syntax, the Tizen/Meego mic tool. As such, it made sense to use that as a starting point - this commit essentially just copies the relevant Python code from the MIC tool to the scripts/lib dir, where it can be accessed by the previously created wic tool. Most of this will be removed or renamed by later commits, since we're initially focusing on partitioning only. Care should be taken so that we can easily add back any additional functionality should we decide later to expand the tool, though (we may also want to contribute our local changes to the mic tool to the Tizen project if it makes sense, and therefore should avoid gratuitous changes to the original code if possible). Added the /mic subdir from Tizen mic repo as a starting point: git clone git://review.tizen.org/tools/mic.git For reference, the top commit: commit 20164175ddc234a17b8a12c33d04b012347b1530 Author: Gui Chen <gui.chen@intel.com> Date: Sun Jun 30 22:32:16 2013 -0400 bump up to 0.19.2 Also added the /plugins subdir, moved to under the /mic subdir (to match the default plugin_dir location in mic.conf.in, which was renamed to yocto-image.conf (moved and renamed by later patches) and put into /scripts. (From OE-Core rev: 31f0360f1fd4ebc9dfcaed42d1c50d2448b4632e) Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2013-08-24 15:31:34 +00:00
def show_plugins(cls):
for cls in cls.plugins[cls.wic_plugin_type]:
wic: Add mic w/pykickstart This is the starting point for the implemention described in [YOCTO 3847] which came to the conclusion that it would make sense to use kickstart syntax to implement image creation in OpenEmbedded. I subsequently realized that there was an existing tool that already implemented image creation using kickstart syntax, the Tizen/Meego mic tool. As such, it made sense to use that as a starting point - this commit essentially just copies the relevant Python code from the MIC tool to the scripts/lib dir, where it can be accessed by the previously created wic tool. Most of this will be removed or renamed by later commits, since we're initially focusing on partitioning only. Care should be taken so that we can easily add back any additional functionality should we decide later to expand the tool, though (we may also want to contribute our local changes to the mic tool to the Tizen project if it makes sense, and therefore should avoid gratuitous changes to the original code if possible). Added the /mic subdir from Tizen mic repo as a starting point: git clone git://review.tizen.org/tools/mic.git For reference, the top commit: commit 20164175ddc234a17b8a12c33d04b012347b1530 Author: Gui Chen <gui.chen@intel.com> Date: Sun Jun 30 22:32:16 2013 -0400 bump up to 0.19.2 Also added the /plugins subdir, moved to under the /mic subdir (to match the default plugin_dir location in mic.conf.in, which was renamed to yocto-image.conf (moved and renamed by later patches) and put into /scripts. (From OE-Core rev: 31f0360f1fd4ebc9dfcaed42d1c50d2448b4632e) Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2013-08-24 15:31:34 +00:00
print cls
def get_plugins(cls):
return cls.plugins
wic: Add mic w/pykickstart This is the starting point for the implemention described in [YOCTO 3847] which came to the conclusion that it would make sense to use kickstart syntax to implement image creation in OpenEmbedded. I subsequently realized that there was an existing tool that already implemented image creation using kickstart syntax, the Tizen/Meego mic tool. As such, it made sense to use that as a starting point - this commit essentially just copies the relevant Python code from the MIC tool to the scripts/lib dir, where it can be accessed by the previously created wic tool. Most of this will be removed or renamed by later commits, since we're initially focusing on partitioning only. Care should be taken so that we can easily add back any additional functionality should we decide later to expand the tool, though (we may also want to contribute our local changes to the mic tool to the Tizen project if it makes sense, and therefore should avoid gratuitous changes to the original code if possible). Added the /mic subdir from Tizen mic repo as a starting point: git clone git://review.tizen.org/tools/mic.git For reference, the top commit: commit 20164175ddc234a17b8a12c33d04b012347b1530 Author: Gui Chen <gui.chen@intel.com> Date: Sun Jun 30 22:32:16 2013 -0400 bump up to 0.19.2 Also added the /plugins subdir, moved to under the /mic subdir (to match the default plugin_dir location in mic.conf.in, which was renamed to yocto-image.conf (moved and renamed by later patches) and put into /scripts. (From OE-Core rev: 31f0360f1fd4ebc9dfcaed42d1c50d2448b4632e) Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2013-08-24 15:31:34 +00:00
class ImagerPlugin(_Plugin):
wic_plugin_type = "imager"
wic: Add mic w/pykickstart This is the starting point for the implemention described in [YOCTO 3847] which came to the conclusion that it would make sense to use kickstart syntax to implement image creation in OpenEmbedded. I subsequently realized that there was an existing tool that already implemented image creation using kickstart syntax, the Tizen/Meego mic tool. As such, it made sense to use that as a starting point - this commit essentially just copies the relevant Python code from the MIC tool to the scripts/lib dir, where it can be accessed by the previously created wic tool. Most of this will be removed or renamed by later commits, since we're initially focusing on partitioning only. Care should be taken so that we can easily add back any additional functionality should we decide later to expand the tool, though (we may also want to contribute our local changes to the mic tool to the Tizen project if it makes sense, and therefore should avoid gratuitous changes to the original code if possible). Added the /mic subdir from Tizen mic repo as a starting point: git clone git://review.tizen.org/tools/mic.git For reference, the top commit: commit 20164175ddc234a17b8a12c33d04b012347b1530 Author: Gui Chen <gui.chen@intel.com> Date: Sun Jun 30 22:32:16 2013 -0400 bump up to 0.19.2 Also added the /plugins subdir, moved to under the /mic subdir (to match the default plugin_dir location in mic.conf.in, which was renamed to yocto-image.conf (moved and renamed by later patches) and put into /scripts. (From OE-Core rev: 31f0360f1fd4ebc9dfcaed42d1c50d2448b4632e) Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2013-08-24 15:31:34 +00:00
wic: Add SourcePlugin class Define the SourcePlugin class, which is the class that should be subclassed to create a 'source' plugin. 'Source' plugins provide a mechanism to customize various aspects of the image generation process in wic, mainly the contents of partitions. The initial version of wic defined a --source param for partitions, which was in the first revision hard-coded to two possible values: rootfs and bootimg. This patch essentially removes the hard-coded --bootimg param and replaces it with a plugin system that maps the value specified as --source to a particular 'source' plugin instead. A 'source' plugin is created as a subclass of SourcePlugin and the plugin file containing it is added to scriptsl/lib/mic/plugins/source/ to make the plugin implementation available to the wic implementation. When the wic implementation needs to invoke a partition-specific implementation, it looks for the plugin that has the same name as the --source param given to that partition. For example, if the partition is set up like this: part /boot --source bootimg-pcbios ... then the methods defined as class members of the plugin having the matching .name class member would be used. To be more concrete, here's the plugin definition that would match a '--source bootimg-pcbios' usage, along with an example method that would be called by the wic implementation when it needed to invoke an implementation-specific partition-preparation function: class BootimgPcbiosPlugin(SourcePlugin): name = 'bootimg-pcbios' @classmethod def do_prepare_partition(self, part, ...) If the subclass itself doesn't implement a function, a 'default' version in a superclass will be located and used, which is why all plugins must be derived from SourcePlugin. This scheme is extensible - adding more hooks is a simple matter of adding more plugin methods to SourcePlugin and derived classes. The code that then needs to call the plugin methods the uses plugin.get_source_plugin_methods() to find the method(s) needed by the call; this is done by filling up a dict with keys containing the methon names of interest - on success, these will be filled in with the actual methods. fPlease see the implementation for examples and details. Note that a source plugin need not restrict itself to methods that apply directly to partitions - methods can also be defined for higher level processing such as at the 'disk' level. The get_default_source_plugin() of DirectImageCreator allows the default source plugin to be retrieved; by default this is set to be the same plugin used for the /boot partition, but that can be overridden by specifying a different --source and therefore different plugin on the 'bootloader' line. This isn't ideal, but it avoids forcing a new high-level object to be defined for that purpose. Note that the '--source rootfs' param remains as its current hard-coded value, which is just the rootfs to be used to populate the partition - by default, that's just the value of the bitbake ROOTFS_DIR variable (or whatever was passed in using the -r param). Note that this also could also be overridden by creating a source plugin using a different name; at this point, unlike with bootimg, there's been no need to do so. (From OE-Core rev: 663833d8ecccb36ab42150bc5c9c00be79fa5b93) Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2014-02-04 01:16:57 +00:00
class SourcePlugin(_Plugin):
wic_plugin_type = "source"
wic: Add SourcePlugin class Define the SourcePlugin class, which is the class that should be subclassed to create a 'source' plugin. 'Source' plugins provide a mechanism to customize various aspects of the image generation process in wic, mainly the contents of partitions. The initial version of wic defined a --source param for partitions, which was in the first revision hard-coded to two possible values: rootfs and bootimg. This patch essentially removes the hard-coded --bootimg param and replaces it with a plugin system that maps the value specified as --source to a particular 'source' plugin instead. A 'source' plugin is created as a subclass of SourcePlugin and the plugin file containing it is added to scriptsl/lib/mic/plugins/source/ to make the plugin implementation available to the wic implementation. When the wic implementation needs to invoke a partition-specific implementation, it looks for the plugin that has the same name as the --source param given to that partition. For example, if the partition is set up like this: part /boot --source bootimg-pcbios ... then the methods defined as class members of the plugin having the matching .name class member would be used. To be more concrete, here's the plugin definition that would match a '--source bootimg-pcbios' usage, along with an example method that would be called by the wic implementation when it needed to invoke an implementation-specific partition-preparation function: class BootimgPcbiosPlugin(SourcePlugin): name = 'bootimg-pcbios' @classmethod def do_prepare_partition(self, part, ...) If the subclass itself doesn't implement a function, a 'default' version in a superclass will be located and used, which is why all plugins must be derived from SourcePlugin. This scheme is extensible - adding more hooks is a simple matter of adding more plugin methods to SourcePlugin and derived classes. The code that then needs to call the plugin methods the uses plugin.get_source_plugin_methods() to find the method(s) needed by the call; this is done by filling up a dict with keys containing the methon names of interest - on success, these will be filled in with the actual methods. fPlease see the implementation for examples and details. Note that a source plugin need not restrict itself to methods that apply directly to partitions - methods can also be defined for higher level processing such as at the 'disk' level. The get_default_source_plugin() of DirectImageCreator allows the default source plugin to be retrieved; by default this is set to be the same plugin used for the /boot partition, but that can be overridden by specifying a different --source and therefore different plugin on the 'bootloader' line. This isn't ideal, but it avoids forcing a new high-level object to be defined for that purpose. Note that the '--source rootfs' param remains as its current hard-coded value, which is just the rootfs to be used to populate the partition - by default, that's just the value of the bitbake ROOTFS_DIR variable (or whatever was passed in using the -r param). Note that this also could also be overridden by creating a source plugin using a different name; at this point, unlike with bootimg, there's been no need to do so. (From OE-Core rev: 663833d8ecccb36ab42150bc5c9c00be79fa5b93) Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2014-02-04 01:16:57 +00:00
"""
The methods that can be implemented by --source plugins.
Any methods not implemented in a subclass inherit these.
"""
@classmethod
def do_install_disk(self, disk, disk_name, cr, workdir, oe_builddir,
bootimg_dir, kernel_dir, native_sysroot):
"""
Called after all partitions have been prepared and assembled into a
disk image. This provides a hook to allow finalization of a
disk image e.g. to write an MBR to it.
"""
msger.debug("SourcePlugin: do_install_disk: disk: %s" % disk_name)
@classmethod
def do_stage_partition(self, part, source_params, cr, cr_workdir,
oe_builddir, bootimg_dir, kernel_dir,
native_sysroot):
wic: Add SourcePlugin class Define the SourcePlugin class, which is the class that should be subclassed to create a 'source' plugin. 'Source' plugins provide a mechanism to customize various aspects of the image generation process in wic, mainly the contents of partitions. The initial version of wic defined a --source param for partitions, which was in the first revision hard-coded to two possible values: rootfs and bootimg. This patch essentially removes the hard-coded --bootimg param and replaces it with a plugin system that maps the value specified as --source to a particular 'source' plugin instead. A 'source' plugin is created as a subclass of SourcePlugin and the plugin file containing it is added to scriptsl/lib/mic/plugins/source/ to make the plugin implementation available to the wic implementation. When the wic implementation needs to invoke a partition-specific implementation, it looks for the plugin that has the same name as the --source param given to that partition. For example, if the partition is set up like this: part /boot --source bootimg-pcbios ... then the methods defined as class members of the plugin having the matching .name class member would be used. To be more concrete, here's the plugin definition that would match a '--source bootimg-pcbios' usage, along with an example method that would be called by the wic implementation when it needed to invoke an implementation-specific partition-preparation function: class BootimgPcbiosPlugin(SourcePlugin): name = 'bootimg-pcbios' @classmethod def do_prepare_partition(self, part, ...) If the subclass itself doesn't implement a function, a 'default' version in a superclass will be located and used, which is why all plugins must be derived from SourcePlugin. This scheme is extensible - adding more hooks is a simple matter of adding more plugin methods to SourcePlugin and derived classes. The code that then needs to call the plugin methods the uses plugin.get_source_plugin_methods() to find the method(s) needed by the call; this is done by filling up a dict with keys containing the methon names of interest - on success, these will be filled in with the actual methods. fPlease see the implementation for examples and details. Note that a source plugin need not restrict itself to methods that apply directly to partitions - methods can also be defined for higher level processing such as at the 'disk' level. The get_default_source_plugin() of DirectImageCreator allows the default source plugin to be retrieved; by default this is set to be the same plugin used for the /boot partition, but that can be overridden by specifying a different --source and therefore different plugin on the 'bootloader' line. This isn't ideal, but it avoids forcing a new high-level object to be defined for that purpose. Note that the '--source rootfs' param remains as its current hard-coded value, which is just the rootfs to be used to populate the partition - by default, that's just the value of the bitbake ROOTFS_DIR variable (or whatever was passed in using the -r param). Note that this also could also be overridden by creating a source plugin using a different name; at this point, unlike with bootimg, there's been no need to do so. (From OE-Core rev: 663833d8ecccb36ab42150bc5c9c00be79fa5b93) Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2014-02-04 01:16:57 +00:00
"""
Special content staging hook called before do_prepare_partition(),
normally empty.
Typically, a partition will just use the passed-in parame e.g
straight bootimg_dir, etc, but in some cases, things need to
be more tailored e.g. to use a deploy dir + /boot, etc. This
hook allows those files to be staged in a customized fashion.
Not that get_bitbake_var() allows you to acces non-standard
variables that you might want to use for this.
"""
msger.debug("SourcePlugin: do_stage_partition: part: %s" % part)
@classmethod
def do_configure_partition(self, part, source_params, cr, cr_workdir,
oe_builddir, bootimg_dir, kernel_dir,
native_sysroot):
wic: Add SourcePlugin class Define the SourcePlugin class, which is the class that should be subclassed to create a 'source' plugin. 'Source' plugins provide a mechanism to customize various aspects of the image generation process in wic, mainly the contents of partitions. The initial version of wic defined a --source param for partitions, which was in the first revision hard-coded to two possible values: rootfs and bootimg. This patch essentially removes the hard-coded --bootimg param and replaces it with a plugin system that maps the value specified as --source to a particular 'source' plugin instead. A 'source' plugin is created as a subclass of SourcePlugin and the plugin file containing it is added to scriptsl/lib/mic/plugins/source/ to make the plugin implementation available to the wic implementation. When the wic implementation needs to invoke a partition-specific implementation, it looks for the plugin that has the same name as the --source param given to that partition. For example, if the partition is set up like this: part /boot --source bootimg-pcbios ... then the methods defined as class members of the plugin having the matching .name class member would be used. To be more concrete, here's the plugin definition that would match a '--source bootimg-pcbios' usage, along with an example method that would be called by the wic implementation when it needed to invoke an implementation-specific partition-preparation function: class BootimgPcbiosPlugin(SourcePlugin): name = 'bootimg-pcbios' @classmethod def do_prepare_partition(self, part, ...) If the subclass itself doesn't implement a function, a 'default' version in a superclass will be located and used, which is why all plugins must be derived from SourcePlugin. This scheme is extensible - adding more hooks is a simple matter of adding more plugin methods to SourcePlugin and derived classes. The code that then needs to call the plugin methods the uses plugin.get_source_plugin_methods() to find the method(s) needed by the call; this is done by filling up a dict with keys containing the methon names of interest - on success, these will be filled in with the actual methods. fPlease see the implementation for examples and details. Note that a source plugin need not restrict itself to methods that apply directly to partitions - methods can also be defined for higher level processing such as at the 'disk' level. The get_default_source_plugin() of DirectImageCreator allows the default source plugin to be retrieved; by default this is set to be the same plugin used for the /boot partition, but that can be overridden by specifying a different --source and therefore different plugin on the 'bootloader' line. This isn't ideal, but it avoids forcing a new high-level object to be defined for that purpose. Note that the '--source rootfs' param remains as its current hard-coded value, which is just the rootfs to be used to populate the partition - by default, that's just the value of the bitbake ROOTFS_DIR variable (or whatever was passed in using the -r param). Note that this also could also be overridden by creating a source plugin using a different name; at this point, unlike with bootimg, there's been no need to do so. (From OE-Core rev: 663833d8ecccb36ab42150bc5c9c00be79fa5b93) Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2014-02-04 01:16:57 +00:00
"""
Called before do_prepare_partition(), typically used to create
custom configuration files for a partition, for example
syslinux or grub config files.
"""
msger.debug("SourcePlugin: do_configure_partition: part: %s" % part)
@classmethod
def do_prepare_partition(self, part, source_params, cr, cr_workdir,
oe_builddir, bootimg_dir, kernel_dir, rootfs_dir,
native_sysroot):
wic: Add SourcePlugin class Define the SourcePlugin class, which is the class that should be subclassed to create a 'source' plugin. 'Source' plugins provide a mechanism to customize various aspects of the image generation process in wic, mainly the contents of partitions. The initial version of wic defined a --source param for partitions, which was in the first revision hard-coded to two possible values: rootfs and bootimg. This patch essentially removes the hard-coded --bootimg param and replaces it with a plugin system that maps the value specified as --source to a particular 'source' plugin instead. A 'source' plugin is created as a subclass of SourcePlugin and the plugin file containing it is added to scriptsl/lib/mic/plugins/source/ to make the plugin implementation available to the wic implementation. When the wic implementation needs to invoke a partition-specific implementation, it looks for the plugin that has the same name as the --source param given to that partition. For example, if the partition is set up like this: part /boot --source bootimg-pcbios ... then the methods defined as class members of the plugin having the matching .name class member would be used. To be more concrete, here's the plugin definition that would match a '--source bootimg-pcbios' usage, along with an example method that would be called by the wic implementation when it needed to invoke an implementation-specific partition-preparation function: class BootimgPcbiosPlugin(SourcePlugin): name = 'bootimg-pcbios' @classmethod def do_prepare_partition(self, part, ...) If the subclass itself doesn't implement a function, a 'default' version in a superclass will be located and used, which is why all plugins must be derived from SourcePlugin. This scheme is extensible - adding more hooks is a simple matter of adding more plugin methods to SourcePlugin and derived classes. The code that then needs to call the plugin methods the uses plugin.get_source_plugin_methods() to find the method(s) needed by the call; this is done by filling up a dict with keys containing the methon names of interest - on success, these will be filled in with the actual methods. fPlease see the implementation for examples and details. Note that a source plugin need not restrict itself to methods that apply directly to partitions - methods can also be defined for higher level processing such as at the 'disk' level. The get_default_source_plugin() of DirectImageCreator allows the default source plugin to be retrieved; by default this is set to be the same plugin used for the /boot partition, but that can be overridden by specifying a different --source and therefore different plugin on the 'bootloader' line. This isn't ideal, but it avoids forcing a new high-level object to be defined for that purpose. Note that the '--source rootfs' param remains as its current hard-coded value, which is just the rootfs to be used to populate the partition - by default, that's just the value of the bitbake ROOTFS_DIR variable (or whatever was passed in using the -r param). Note that this also could also be overridden by creating a source plugin using a different name; at this point, unlike with bootimg, there's been no need to do so. (From OE-Core rev: 663833d8ecccb36ab42150bc5c9c00be79fa5b93) Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2014-02-04 01:16:57 +00:00
"""
Called to do the actual content population for a partition i.e. it
'prepares' the partition to be incorporated into the image.
"""
msger.debug("SourcePlugin: do_prepare_partition: part: %s" % part)
wic: Add mic w/pykickstart This is the starting point for the implemention described in [YOCTO 3847] which came to the conclusion that it would make sense to use kickstart syntax to implement image creation in OpenEmbedded. I subsequently realized that there was an existing tool that already implemented image creation using kickstart syntax, the Tizen/Meego mic tool. As such, it made sense to use that as a starting point - this commit essentially just copies the relevant Python code from the MIC tool to the scripts/lib dir, where it can be accessed by the previously created wic tool. Most of this will be removed or renamed by later commits, since we're initially focusing on partitioning only. Care should be taken so that we can easily add back any additional functionality should we decide later to expand the tool, though (we may also want to contribute our local changes to the mic tool to the Tizen project if it makes sense, and therefore should avoid gratuitous changes to the original code if possible). Added the /mic subdir from Tizen mic repo as a starting point: git clone git://review.tizen.org/tools/mic.git For reference, the top commit: commit 20164175ddc234a17b8a12c33d04b012347b1530 Author: Gui Chen <gui.chen@intel.com> Date: Sun Jun 30 22:32:16 2013 -0400 bump up to 0.19.2 Also added the /plugins subdir, moved to under the /mic subdir (to match the default plugin_dir location in mic.conf.in, which was renamed to yocto-image.conf (moved and renamed by later patches) and put into /scripts. (From OE-Core rev: 31f0360f1fd4ebc9dfcaed42d1c50d2448b4632e) Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2013-08-24 15:31:34 +00:00
def get_plugins(typen):
ps = ImagerPlugin.get_plugins()
if typen in ps:
return ps[typen]
else:
return None
__all__ = ['ImagerPlugin', 'SourcePlugin', 'get_plugins']