aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/plugins/imager
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2017-02-09 15:52:55 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-02-15 20:06:33 -0800
commit4dc9dbfc7fbc16d349a019e8973d50905cd28244 (patch)
tree8a24d47f4b1b476dae4765748f57e5d8666eb2e5 /scripts/lib/wic/plugins/imager
parentc826233ad08ee5a4b9943a05d4e73f3fb3281588 (diff)
downloadopenembedded-core-contrib-4dc9dbfc7fbc16d349a019e8973d50905cd28244.tar.gz
wic: move disk operations to PartitionImage class
Disk operations were spread over DirectPlugin, DiskImage and Image code making the code hard to understand. Renamed Image class to PartitionedImage. Removed DiskImage class. Moved disk operations to PartitionedImage. There was an implicit support for multiple disks: if different devices were specified in .wks file (e.g. --ondisk sda and --ondisk sdb), wic would theoretically generate multiple images. This is quite confusing option and the code supporting it was broken for a long time. The same effect (multiple output images) can be achieved in obvious and clear way - by using multiple .wks files. This functionality was removed. PartitionedImage works only with one image. This makes the code less complex and easier to maintain. Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Diffstat (limited to 'scripts/lib/wic/plugins/imager')
-rw-r--r--scripts/lib/wic/plugins/imager/direct.py97
1 files changed, 30 insertions, 67 deletions
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
index a9144e2f4b..fefe88e0df 100644
--- a/scripts/lib/wic/plugins/imager/direct.py
+++ b/scripts/lib/wic/plugins/imager/direct.py
@@ -36,25 +36,8 @@ from wic.plugin import pluginmgr
from wic.pluginbase import ImagerPlugin
from wic.utils.errors import CreatorError, ImageError
from wic.utils.misc import get_bitbake_var, exec_cmd, exec_native_cmd
-from wic.utils.partitionedfs import Image
+from wic.utils.partitionedfs import PartitionedImage
-class DiskImage():
- """
- A Disk backed by a file.
- """
- def __init__(self, device, size):
- self.size = size
- self.device = device
- self.created = False
-
- def create(self):
- if self.created:
- return
- # create sparse disk image
- with open(self.device, 'w') as sparse:
- os.ftruncate(sparse.fileno(), self.size)
-
- self.created = True
class DirectPlugin(ImagerPlugin):
"""
@@ -189,9 +172,10 @@ class DirectPlugin(ImagerPlugin):
filesystems from the artifacts directly and combine them into
a partitioned image.
"""
- self._image = Image(self.native_sysroot)
+ image_path = self._full_path(self.workdir, self.parts[0].disk, "direct")
+ self._image = PartitionedImage(image_path, self.ptable_format,
+ self.native_sysroot)
- disk_ids = {}
for num, part in enumerate(self.parts, 1):
# as a convenience, set source to the boot partition source
# instead of forcing it to be set via bootloader --source
@@ -203,10 +187,8 @@ class DirectPlugin(ImagerPlugin):
if self.ptable_format == 'gpt':
part.uuid = str(uuid.uuid4())
else: # msdos partition table
- if part.disk not in disk_ids:
- disk_ids[part.disk] = int.from_bytes(os.urandom(4), 'little')
- disk_id = disk_ids[part.disk]
- part.uuid = '%0x-%02d' % (disk_id, self._get_part_num(num, self.parts))
+ part.uuid = '%0x-%02d' % (self._image.identifier,
+ self._get_part_num(num, self.parts))
fstab_path = self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR"))
@@ -225,11 +207,6 @@ class DirectPlugin(ImagerPlugin):
part.size = int(round(float(rsize_bb)))
# need to create the filesystems in order to get their
# sizes before we can add them and do the layout.
- # Image.create() actually calls __format_disks() to create
- # the disk images and carve out the partitions, then
- # self.assemble() calls Image.assemble() which calls
- # __write_partitition() for each partition to dd the fs
- # into the partitions.
part.prepare(self, self.workdir, self.oe_builddir, self.rootfs_dir,
self.bootimg_dir, self.kernel_dir, self.native_sysroot)
@@ -238,26 +215,14 @@ class DirectPlugin(ImagerPlugin):
if fstab_path:
shutil.move(fstab_path + ".orig", fstab_path)
- self._image.layout_partitions(self.ptable_format)
-
- for disk_name, disk in self._image.disks.items():
- full_path = self._full_path(self.workdir, disk_name, "direct")
- msger.debug("Adding disk %s as %s with size %s bytes" \
- % (disk_name, full_path, disk['min_size']))
- disk_obj = DiskImage(full_path, disk['min_size'])
- self._image.add_disk(disk_name, disk_obj, disk_ids.get(disk_name))
-
+ self._image.layout_partitions()
self._image.create()
def assemble(self):
"""
- Assemble partitions into disk image(s)
+ Assemble partitions into disk image
"""
- for disk_name, disk in self._image.disks.items():
- full_path = self._full_path(self.workdir, disk_name, "direct")
- msger.debug("Assembling disk %s as %s with size %s bytes" \
- % (disk_name, full_path, disk['min_size']))
- self._image.assemble(full_path)
+ self._image.assemble()
def finalize(self):
"""
@@ -267,26 +232,25 @@ class DirectPlugin(ImagerPlugin):
creating and installing a bootloader configuration.
"""
source_plugin = self.ks.bootloader.source
+ disk_name = self.parts[0].disk
if source_plugin:
name = "do_install_disk"
methods = pluginmgr.get_source_plugin_methods(source_plugin,
{name: None})
- for disk_name, disk in self._image.disks.items():
- methods["do_install_disk"](disk, disk_name, self, self.workdir,
- self.oe_builddir, self.bootimg_dir,
- self.kernel_dir, self.native_sysroot)
-
- for disk_name, disk in self._image.disks.items():
- full_path = self._full_path(self.workdir, disk_name, "direct")
- # Generate .bmap
- if self.bmap:
- msger.debug("Generating bmap file for %s" % disk_name)
- exec_native_cmd("bmaptool create %s -o %s.bmap" % (full_path, full_path),
- self.native_sysroot)
- # Compress the image
- if self.compressor:
- msger.debug("Compressing disk %s with %s" % (disk_name, self.compressor))
- exec_cmd("%s %s" % (self.compressor, full_path))
+ methods["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:
+ msger.debug("Generating bmap file for %s" % disk_name)
+ exec_native_cmd("bmaptool create %s -o %s.bmap" % (full_path, full_path),
+ self.native_sysroot)
+ # Compress the image
+ if self.compressor:
+ msger.debug("Compressing disk %s with %s" % (disk_name, self.compressor))
+ exec_cmd("%s %s" % (self.compressor, full_path))
def print_info(self):
"""
@@ -294,13 +258,12 @@ class DirectPlugin(ImagerPlugin):
"""
msg = "The new image(s) can be found here:\n"
- for disk_name in self._image.disks:
- extension = "direct" + {"gzip": ".gz",
- "bzip2": ".bz2",
- "xz": ".xz",
- None: ""}.get(self.compressor)
- full_path = self._full_path(self.outdir, disk_name, extension)
- msg += ' %s\n\n' % full_path
+ extension = "direct" + {"gzip": ".gz",
+ "bzip2": ".bz2",
+ "xz": ".xz",
+ None: ""}.get(self.compressor)
+ full_path = self._full_path(self.outdir, self.parts[0].disk, extension)
+ msg += ' %s\n\n' % full_path
msg += 'The following build artifacts were used to create the image(s):\n'
for part in self.parts: