summaryrefslogtreecommitdiffstats
path: root/import-layers/yocto-poky/scripts/lib/wic
diff options
context:
space:
mode:
Diffstat (limited to 'import-layers/yocto-poky/scripts/lib/wic')
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks2
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/canned-wks/directdisk-multi-rootfs.wks2
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/canned-wks/directdisk.wks2
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/canned-wks/mkefidisk.wks4
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/canned-wks/mkgummidisk.wks2
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/canned-wks/systemd-bootdisk.wks11
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/conf.py2
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/creator.py5
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/engine.py31
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/filemap.py561
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/help.py15
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/imager/baseimager.py5
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/imager/direct.py67
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/ksparser.py31
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/msger.py78
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/partition.py34
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/plugin.py12
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/pluginbase.py42
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/plugins/imager/direct_plugin.py3
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-efi.py19
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-pcbios.py6
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/plugins/source/isoimage-isohybrid.py61
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/plugins/source/rawcopy.py9
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/utils/fs_related.py84
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/utils/oe/misc.py22
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/utils/partitionedfs.py52
-rw-r--r--import-layers/yocto-poky/scripts/lib/wic/utils/runner.py6
27 files changed, 816 insertions, 352 deletions
diff --git a/import-layers/yocto-poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks b/import-layers/yocto-poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks
index ea01cf375..8d7d8de6e 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks
+++ b/import-layers/yocto-poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks
@@ -6,5 +6,5 @@
part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
-bootloader --ptable gpt --timeout=0 --append="rootwait rootfstype=ext4 video=vesafb vga=0x318 console=tty0"
+bootloader --ptable gpt --timeout=0 --append="rootwait rootfstype=ext4 video=vesafb vga=0x318 console=tty0 console=ttyS0,115200n8"
diff --git a/import-layers/yocto-poky/scripts/lib/wic/canned-wks/directdisk-multi-rootfs.wks b/import-layers/yocto-poky/scripts/lib/wic/canned-wks/directdisk-multi-rootfs.wks
index 8a81f8f51..f61d941d6 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/canned-wks/directdisk-multi-rootfs.wks
+++ b/import-layers/yocto-poky/scripts/lib/wic/canned-wks/directdisk-multi-rootfs.wks
@@ -19,5 +19,5 @@ part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 10
part / --source rootfs --rootfs-dir=rootfs1 --ondisk sda --fstype=ext4 --label platform --align 1024
part /rescue --source rootfs --rootfs-dir=rootfs2 --ondisk sda --fstype=ext4 --label secondary --align 1024
-bootloader --timeout=0 --append="rootwait rootfstype=ext4 video=vesafb vga=0x318 console=tty0"
+bootloader --timeout=0 --append="rootwait rootfstype=ext4 video=vesafb vga=0x318 console=tty0 console=ttyS0,115200n8"
diff --git a/import-layers/yocto-poky/scripts/lib/wic/canned-wks/directdisk.wks b/import-layers/yocto-poky/scripts/lib/wic/canned-wks/directdisk.wks
index 6db74a78b..8c8e06b02 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/canned-wks/directdisk.wks
+++ b/import-layers/yocto-poky/scripts/lib/wic/canned-wks/directdisk.wks
@@ -4,5 +4,5 @@
include common.wks.inc
-bootloader --timeout=0 --append="rootwait rootfstype=ext4 video=vesafb vga=0x318 console=tty0"
+bootloader --timeout=0 --append="rootwait rootfstype=ext4 video=vesafb vga=0x318 console=tty0 console=ttyS0,115200n8"
diff --git a/import-layers/yocto-poky/scripts/lib/wic/canned-wks/mkefidisk.wks b/import-layers/yocto-poky/scripts/lib/wic/canned-wks/mkefidisk.wks
index 696e94e3d..9f534fe18 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/canned-wks/mkefidisk.wks
+++ b/import-layers/yocto-poky/scripts/lib/wic/canned-wks/mkefidisk.wks
@@ -4,8 +4,8 @@
part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
-part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024
+part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
part swap --ondisk sda --size 44 --label swap1 --fstype=swap
-bootloader --timeout=10 --append="rootwait rootfstype=ext4 console=ttyPCH0,115200 console=tty0 vmalloc=256MB snd-hda-intel.enable_msi=0"
+bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
diff --git a/import-layers/yocto-poky/scripts/lib/wic/canned-wks/mkgummidisk.wks b/import-layers/yocto-poky/scripts/lib/wic/canned-wks/mkgummidisk.wks
index 66a22f60b..f3ae09099 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/canned-wks/mkgummidisk.wks
+++ b/import-layers/yocto-poky/scripts/lib/wic/canned-wks/mkgummidisk.wks
@@ -8,4 +8,4 @@ part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024
part swap --ondisk sda --size 44 --label swap1 --fstype=swap
-bootloader --timeout=10 --append="rootwait rootfstype=ext4 console=ttyPCH0,115200 console=tty0 vmalloc=256MB snd-hda-intel.enable_msi=0"
+bootloader --ptable gpt --timeout=5 --append="rootwait rootfstype=ext4 console=ttyS0,115200 console=tty0"
diff --git a/import-layers/yocto-poky/scripts/lib/wic/canned-wks/systemd-bootdisk.wks b/import-layers/yocto-poky/scripts/lib/wic/canned-wks/systemd-bootdisk.wks
new file mode 100644
index 000000000..b90002356
--- /dev/null
+++ b/import-layers/yocto-poky/scripts/lib/wic/canned-wks/systemd-bootdisk.wks
@@ -0,0 +1,11 @@
+# short-description: Create an EFI disk image with systemd-boot
+# long-description: Creates a partitioned EFI disk image that the user
+# can directly dd to boot media. The selected bootloader is systemd-boot.
+
+part /boot --source bootimg-efi --sourceparams="loader=systemd-boot" --ondisk sda --label msdos --active --align 1024
+
+part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024
+
+part swap --ondisk sda --size 44 --label swap1 --fstype=swap
+
+bootloader --ptable gpt --timeout=5 --append="rootwait rootfstype=ext4 console=ttyS0,115200 console=tty0"
diff --git a/import-layers/yocto-poky/scripts/lib/wic/conf.py b/import-layers/yocto-poky/scripts/lib/wic/conf.py
index f7d56d046..070ec3096 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/conf.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/conf.py
@@ -70,7 +70,7 @@ class ConfigMgr(object):
self.create = {}
# initialize the values with defaults
- for sec, vals in self.DEFAULTS.iteritems():
+ for sec, vals in self.DEFAULTS.items():
setattr(self, sec, vals)
def __set_ksconf(self, ksconf):
diff --git a/import-layers/yocto-poky/scripts/lib/wic/creator.py b/import-layers/yocto-poky/scripts/lib/wic/creator.py
index 523129728..8f7d1503f 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/creator.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/creator.py
@@ -24,7 +24,7 @@ from wic.conf import configmgr
from wic.plugin import pluginmgr
-class Creator(object):
+class Creator():
"""${name}: create an image
Usage:
@@ -41,7 +41,7 @@ class Creator(object):
# get cmds from pluginmgr
# mix-in do_subcmd interface
- for subcmd, klass in pluginmgr.get_plugins('imager').iteritems():
+ for subcmd, klass in pluginmgr.get_plugins('imager').items():
if not hasattr(klass, 'do_create'):
msger.warning("Unsupported subcmd: %s" % subcmd)
continue
@@ -69,6 +69,7 @@ class Creator(object):
optparser.add_option('', '--tmpfs', action='store_true', dest='enabletmpfs',
help='Setup tmpdir as tmpfs to accelerate, experimental'
' feature, use it if you have more than 4G memory')
+ optparser.add_option('', '--bmap', action='store_true', help='generate .bmap')
return optparser
def postoptparse(self, options):
diff --git a/import-layers/yocto-poky/scripts/lib/wic/engine.py b/import-layers/yocto-poky/scripts/lib/wic/engine.py
index 76b93e82f..5b104631c 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/engine.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/engine.py
@@ -44,7 +44,7 @@ def verify_build_env():
Returns True if it is, false otherwise
"""
if not os.environ.get("BUILDDIR"):
- print "BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)"
+ print("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)")
sys.exit(1)
return True
@@ -107,7 +107,7 @@ def list_canned_images(scripts_path):
desc = line[idx + len("short-description:"):].strip()
break
basename = os.path.splitext(fname)[0]
- print " %s\t\t%s" % (basename.ljust(30), desc)
+ print(" %s\t\t%s" % (basename.ljust(30), desc))
def list_canned_image_help(scripts_path, fullpath):
@@ -120,15 +120,15 @@ def list_canned_image_help(scripts_path, fullpath):
if not found:
idx = line.find("long-description:")
if idx != -1:
- print
- print line[idx + len("long-description:"):].strip()
+ print()
+ print(line[idx + len("long-description:"):].strip())
found = True
continue
if not line.strip():
break
idx = line.find("#")
if idx != -1:
- print line[idx + len("#:"):].rstrip()
+ print(line[idx + len("#:"):].rstrip())
else:
break
@@ -140,12 +140,12 @@ def list_source_plugins():
plugins = pluginmgr.get_source_plugins()
for plugin in plugins:
- print " %s" % plugin
+ print(" %s" % plugin)
def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
native_sysroot, scripts_path, image_output_dir,
- compressor, debug):
+ compressor, bmap, debug):
"""Create image
wks_file - user-defined OE kickstart file
@@ -156,6 +156,7 @@ def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
scripts_path - absolute path to /scripts dir
image_output_dir - dirname to create for image
compressor - compressor utility to compress the image
+ bmap - enable generation of .bmap
Normally, the values for the build artifacts values are determined
by 'wic -e' from the output of the 'bitbake -e' command given an
@@ -178,7 +179,7 @@ def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
try:
oe_builddir = os.environ["BUILDDIR"]
except KeyError:
- print "BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)"
+ print("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)")
sys.exit(1)
if debug:
@@ -186,10 +187,14 @@ def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
crobj = creator.Creator()
- crobj.main(["direct", native_sysroot, kernel_dir, bootimg_dir, rootfs_dir,
- wks_file, image_output_dir, oe_builddir, compressor or ""])
+ cmdline = ["direct", native_sysroot, kernel_dir, bootimg_dir, rootfs_dir,
+ wks_file, image_output_dir, oe_builddir, compressor or ""]
+ if bmap:
+ cmdline.append('--bmap')
- print "\nThe image(s) were created using OE kickstart file:\n %s" % wks_file
+ crobj.main(cmdline)
+
+ print("\nThe image(s) were created using OE kickstart file:\n %s" % wks_file)
def wic_list(args, scripts_path):
@@ -209,10 +214,10 @@ def wic_list(args, scripts_path):
wks_file = args[0]
fullpath = find_canned_image(scripts_path, wks_file)
if not fullpath:
- print "No image named %s found, exiting. "\
+ print("No image named %s found, exiting. "\
"(Use 'wic list images' to list available images, or "\
"specify a fully-qualified OE kickstart (.wks) "\
- "filename)\n" % wks_file
+ "filename)\n" % wks_file)
sys.exit(1)
list_canned_image_help(scripts_path, fullpath)
return True
diff --git a/import-layers/yocto-poky/scripts/lib/wic/filemap.py b/import-layers/yocto-poky/scripts/lib/wic/filemap.py
new file mode 100644
index 000000000..f3240ba8d
--- /dev/null
+++ b/import-layers/yocto-poky/scripts/lib/wic/filemap.py
@@ -0,0 +1,561 @@
+# Copyright (c) 2012 Intel, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License, version 2,
+# as published by the Free Software Foundation.
+#
+# 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.
+
+"""
+This module implements python implements a way to get file block. Two methods
+are supported - the FIEMAP ioctl and the 'SEEK_HOLE / SEEK_DATA' features of
+the file seek syscall. The former is implemented by the 'FilemapFiemap' class,
+the latter is implemented by the 'FilemapSeek' class. Both classes provide the
+same API. The 'filemap' function automatically selects which class can be used
+and returns an instance of the class.
+"""
+
+# Disable the following pylint recommendations:
+# * Too many instance attributes (R0902)
+# pylint: disable=R0902
+
+import os
+import struct
+import array
+import fcntl
+import tempfile
+import logging
+
+def get_block_size(file_obj):
+ """
+ Returns block size for file object 'file_obj'. Errors are indicated by the
+ 'IOError' exception.
+ """
+
+ from fcntl import ioctl
+ import struct
+
+ # Get the block size of the host file-system for the image file by calling
+ # the FIGETBSZ ioctl (number 2).
+ binary_data = ioctl(file_obj, 2, struct.pack('I', 0))
+ return struct.unpack('I', binary_data)[0]
+
+class ErrorNotSupp(Exception):
+ """
+ An exception of this type is raised when the 'FIEMAP' or 'SEEK_HOLE' feature
+ is not supported either by the kernel or the file-system.
+ """
+ pass
+
+class Error(Exception):
+ """A class for all the other exceptions raised by this module."""
+ pass
+
+
+class _FilemapBase(object):
+ """
+ This is a base class for a couple of other classes in this module. This
+ class simply performs the common parts of the initialization process: opens
+ the image file, gets its size, etc. The 'log' parameter is the logger object
+ to use for printing messages.
+ """
+
+ def __init__(self, image, log=None):
+ """
+ Initialize a class instance. The 'image' argument is full path to the
+ file or file object to operate on.
+ """
+
+ self._log = log
+ if self._log is None:
+ self._log = logging.getLogger(__name__)
+
+ self._f_image_needs_close = False
+
+ if hasattr(image, "fileno"):
+ self._f_image = image
+ self._image_path = image.name
+ else:
+ self._image_path = image
+ self._open_image_file()
+
+ try:
+ self.image_size = os.fstat(self._f_image.fileno()).st_size
+ except IOError as err:
+ raise Error("cannot get information about file '%s': %s"
+ % (self._f_image.name, err))
+
+ try:
+ self.block_size = get_block_size(self._f_image)
+ except IOError as err:
+ raise Error("cannot get block size for '%s': %s"
+ % (self._image_path, err))
+
+ self.blocks_cnt = self.image_size + self.block_size - 1
+ self.blocks_cnt //= self.block_size
+
+ try:
+ self._f_image.flush()
+ except IOError as err:
+ raise Error("cannot flush image file '%s': %s"
+ % (self._image_path, err))
+
+ try:
+ os.fsync(self._f_image.fileno()),
+ except OSError as err:
+ raise Error("cannot synchronize image file '%s': %s "
+ % (self._image_path, err.strerror))
+
+ self._log.debug("opened image \"%s\"" % self._image_path)
+ self._log.debug("block size %d, blocks count %d, image size %d"
+ % (self.block_size, self.blocks_cnt, self.image_size))
+
+ def __del__(self):
+ """The class destructor which just closes the image file."""
+ if self._f_image_needs_close:
+ self._f_image.close()
+
+ def _open_image_file(self):
+ """Open the image file."""
+ try:
+ self._f_image = open(self._image_path, 'rb')
+ except IOError as err:
+ raise Error("cannot open image file '%s': %s"
+ % (self._image_path, err))
+
+ self._f_image_needs_close = True
+
+ def block_is_mapped(self, block): # pylint: disable=W0613,R0201
+ """
+ This method has has to be implemented by child classes. It returns
+ 'True' if block number 'block' of the image file is mapped and 'False'
+ otherwise.
+ """
+
+ raise Error("the method is not implemented")
+
+ def block_is_unmapped(self, block): # pylint: disable=W0613,R0201
+ """
+ This method has has to be implemented by child classes. It returns
+ 'True' if block number 'block' of the image file is not mapped (hole)
+ and 'False' otherwise.
+ """
+
+ raise Error("the method is not implemented")
+
+ def get_mapped_ranges(self, start, count): # pylint: disable=W0613,R0201
+ """
+ This method has has to be implemented by child classes. This is a
+ generator which yields ranges of mapped blocks in the file. The ranges
+ are tuples of 2 elements: [first, last], where 'first' is the first
+ mapped block and 'last' is the last mapped block.
+
+ The ranges are yielded for the area of the file of size 'count' blocks,
+ starting from block 'start'.
+ """
+
+ raise Error("the method is not implemented")
+
+ def get_unmapped_ranges(self, start, count): # pylint: disable=W0613,R0201
+ """
+ This method has has to be implemented by child classes. Just like
+ 'get_mapped_ranges()', but yields unmapped block ranges instead
+ (holes).
+ """
+
+ raise Error("the method is not implemented")
+
+
+# The 'SEEK_HOLE' and 'SEEK_DATA' options of the file seek system call
+_SEEK_DATA = 3
+_SEEK_HOLE = 4
+
+def _lseek(file_obj, offset, whence):
+ """This is a helper function which invokes 'os.lseek' for file object
+ 'file_obj' and with specified 'offset' and 'whence'. The 'whence'
+ argument is supposed to be either '_SEEK_DATA' or '_SEEK_HOLE'. When
+ there is no more data or hole starting from 'offset', this function
+ returns '-1'. Otherwise the data or hole position is returned."""
+
+ try:
+ return os.lseek(file_obj.fileno(), offset, whence)
+ except OSError as err:
+ # The 'lseek' system call returns the ENXIO if there is no data or
+ # hole starting from the specified offset.
+ if err.errno == os.errno.ENXIO:
+ return -1
+ elif err.errno == os.errno.EINVAL:
+ raise ErrorNotSupp("the kernel or file-system does not support "
+ "\"SEEK_HOLE\" and \"SEEK_DATA\"")
+ else:
+ raise
+
+class FilemapSeek(_FilemapBase):
+ """
+ This class uses the 'SEEK_HOLE' and 'SEEK_DATA' to find file block mapping.
+ Unfortunately, the current implementation requires the caller to have write
+ access to the image file.
+ """
+
+ def __init__(self, image, log=None):
+ """Refer the '_FilemapBase' class for the documentation."""
+
+ # Call the base class constructor first
+ _FilemapBase.__init__(self, image, log)
+ self._log.debug("FilemapSeek: initializing")
+
+ self._probe_seek_hole()
+
+ def _probe_seek_hole(self):
+ """
+ Check whether the system implements 'SEEK_HOLE' and 'SEEK_DATA'.
+ Unfortunately, there seems to be no clean way for detecting this,
+ because often the system just fakes them by just assuming that all
+ files are fully mapped, so 'SEEK_HOLE' always returns EOF and
+ 'SEEK_DATA' always returns the requested offset.
+
+ I could not invent a better way of detecting the fake 'SEEK_HOLE'
+ implementation than just to create a temporary file in the same
+ directory where the image file resides. It would be nice to change this
+ to something better.
+ """
+
+ directory = os.path.dirname(self._image_path)
+
+ try:
+ tmp_obj = tempfile.TemporaryFile("w+", dir=directory)
+ except IOError as err:
+ raise ErrorNotSupp("cannot create a temporary in \"%s\": %s"
+ % (directory, err))
+
+ try:
+ os.ftruncate(tmp_obj.fileno(), self.block_size)
+ except OSError as err:
+ raise ErrorNotSupp("cannot truncate temporary file in \"%s\": %s"
+ % (directory, err))
+
+ offs = _lseek(tmp_obj, 0, _SEEK_HOLE)
+ if offs != 0:
+ # We are dealing with the stub 'SEEK_HOLE' implementation which
+ # always returns EOF.
+ self._log.debug("lseek(0, SEEK_HOLE) returned %d" % offs)
+ raise ErrorNotSupp("the file-system does not support "
+ "\"SEEK_HOLE\" and \"SEEK_DATA\" but only "
+ "provides a stub implementation")
+
+ tmp_obj.close()
+
+ def block_is_mapped(self, block):
+ """Refer the '_FilemapBase' class for the documentation."""
+ offs = _lseek(self._f_image, block * self.block_size, _SEEK_DATA)
+ if offs == -1:
+ result = False
+ else:
+ result = (offs // self.block_size == block)
+
+ self._log.debug("FilemapSeek: block_is_mapped(%d) returns %s"
+ % (block, result))
+ return result
+
+ def block_is_unmapped(self, block):
+ """Refer the '_FilemapBase' class for the documentation."""
+ return not self.block_is_mapped(block)
+
+ def _get_ranges(self, start, count, whence1, whence2):
+ """
+ This function implements 'get_mapped_ranges()' and
+ 'get_unmapped_ranges()' depending on what is passed in the 'whence1'
+ and 'whence2' arguments.
+ """
+
+ assert whence1 != whence2
+ end = start * self.block_size
+ limit = end + count * self.block_size
+
+ while True:
+ start = _lseek(self._f_image, end, whence1)
+ if start == -1 or start >= limit or start == self.image_size:
+ break
+
+ end = _lseek(self._f_image, start, whence2)
+ if end == -1 or end == self.image_size:
+ end = self.blocks_cnt * self.block_size
+ if end > limit:
+ end = limit
+
+ start_blk = start // self.block_size
+ end_blk = end // self.block_size - 1
+ self._log.debug("FilemapSeek: yielding range (%d, %d)"
+ % (start_blk, end_blk))
+ yield (start_blk, end_blk)
+
+ def get_mapped_ranges(self, start, count):
+ """Refer the '_FilemapBase' class for the documentation."""
+ self._log.debug("FilemapSeek: get_mapped_ranges(%d, %d(%d))"
+ % (start, count, start + count - 1))
+ return self._get_ranges(start, count, _SEEK_DATA, _SEEK_HOLE)
+
+ def get_unmapped_ranges(self, start, count):
+ """Refer the '_FilemapBase' class for the documentation."""
+ self._log.debug("FilemapSeek: get_unmapped_ranges(%d, %d(%d))"
+ % (start, count, start + count - 1))
+ return self._get_ranges(start, count, _SEEK_HOLE, _SEEK_DATA)
+
+
+# Below goes the FIEMAP ioctl implementation, which is not very readable
+# because it deals with the rather complex FIEMAP ioctl. To understand the
+# code, you need to know the FIEMAP interface, which is documented in the
+# "Documentation/filesystems/fiemap.txt" file in the Linux kernel sources.
+
+# Format string for 'struct fiemap'
+_FIEMAP_FORMAT = "=QQLLLL"
+# sizeof(struct fiemap)
+_FIEMAP_SIZE = struct.calcsize(_FIEMAP_FORMAT)
+# Format string for 'struct fiemap_extent'
+_FIEMAP_EXTENT_FORMAT = "=QQQQQLLLL"
+# sizeof(struct fiemap_extent)
+_FIEMAP_EXTENT_SIZE = struct.calcsize(_FIEMAP_EXTENT_FORMAT)
+# The FIEMAP ioctl number
+_FIEMAP_IOCTL = 0xC020660B
+# This FIEMAP ioctl flag which instructs the kernel to sync the file before
+# reading the block map
+_FIEMAP_FLAG_SYNC = 0x00000001
+# Size of the buffer for 'struct fiemap_extent' elements which will be used
+# when invoking the FIEMAP ioctl. The larger is the buffer, the less times the
+# FIEMAP ioctl will be invoked.
+_FIEMAP_BUFFER_SIZE = 256 * 1024
+
+class FilemapFiemap(_FilemapBase):
+ """
+ This class provides API to the FIEMAP ioctl. Namely, it allows to iterate
+ over all mapped blocks and over all holes.
+
+ This class synchronizes the image file every time it invokes the FIEMAP
+ ioctl in order to work-around early FIEMAP implementation kernel bugs.
+ """
+
+ def __init__(self, image, log=None):
+ """
+ Initialize a class instance. The 'image' argument is full the file
+ object to operate on.
+ """
+
+ # Call the base class constructor first
+ _FilemapBase.__init__(self, image, log)
+ self._log.debug("FilemapFiemap: initializing")
+
+ self._buf_size = _FIEMAP_BUFFER_SIZE
+
+ # Calculate how many 'struct fiemap_extent' elements fit the buffer
+ self._buf_size -= _FIEMAP_SIZE
+ self._fiemap_extent_cnt = self._buf_size // _FIEMAP_EXTENT_SIZE
+ assert self._fiemap_extent_cnt > 0
+ self._buf_size = self._fiemap_extent_cnt * _FIEMAP_EXTENT_SIZE
+ self._buf_size += _FIEMAP_SIZE
+
+ # Allocate a mutable buffer for the FIEMAP ioctl
+ self._buf = array.array('B', [0] * self._buf_size)
+
+ # Check if the FIEMAP ioctl is supported
+ self.block_is_mapped(0)
+
+ def _invoke_fiemap(self, block, count):
+ """
+ Invoke the FIEMAP ioctl for 'count' blocks of the file starting from
+ block number 'block'.
+
+ The full result of the operation is stored in 'self._buf' on exit.
+ Returns the unpacked 'struct fiemap' data structure in form of a python
+ list (just like 'struct.upack()').
+ """
+
+ if self.blocks_cnt != 0 and (block < 0 or block >= self.blocks_cnt):
+ raise Error("bad block number %d, should be within [0, %d]"
+ % (block, self.blocks_cnt))
+
+ # Initialize the 'struct fiemap' part of the buffer. We use the
+ # '_FIEMAP_FLAG_SYNC' flag in order to make sure the file is
+ # synchronized. The reason for this is that early FIEMAP
+ # implementations had many bugs related to cached dirty data, and
+ # synchronizing the file is a necessary work-around.
+ struct.pack_into(_FIEMAP_FORMAT, self._buf, 0, block * self.block_size,
+ count * self.block_size, _FIEMAP_FLAG_SYNC, 0,
+ self._fiemap_extent_cnt, 0)
+
+ try:
+ fcntl.ioctl(self._f_image, _FIEMAP_IOCTL, self._buf, 1)
+ except IOError as err:
+ # Note, the FIEMAP ioctl is supported by the Linux kernel starting
+ # from version 2.6.28 (year 2008).
+ if err.errno == os.errno.EOPNOTSUPP:
+ errstr = "FilemapFiemap: the FIEMAP ioctl is not supported " \
+ "by the file-system"
+ self._log.debug(errstr)
+ raise ErrorNotSupp(errstr)
+ if err.errno == os.errno.ENOTTY:
+ errstr = "FilemapFiemap: the FIEMAP ioctl is not supported " \
+ "by the kernel"
+ self._log.debug(errstr)
+ raise ErrorNotSupp(errstr)
+ raise Error("the FIEMAP ioctl failed for '%s': %s"
+ % (self._image_path, err))
+
+ return struct.unpack(_FIEMAP_FORMAT, self._buf[:_FIEMAP_SIZE])
+
+ def block_is_mapped(self, block):
+ """Refer the '_FilemapBase' class for the documentation."""
+ struct_fiemap = self._invoke_fiemap(block, 1)
+
+ # The 3rd element of 'struct_fiemap' is the 'fm_mapped_extents' field.
+ # If it contains zero, the block is not mapped, otherwise it is
+ # mapped.
+ result = bool(struct_fiemap[3])
+ self._log.debug("FilemapFiemap: block_is_mapped(%d) returns %s"
+ % (block, result))
+ return result
+
+ def block_is_unmapped(self, block):
+ """Refer the '_FilemapBase' class for the documentation."""
+ return not self.block_is_mapped(block)
+
+ def _unpack_fiemap_extent(self, index):
+ """
+ Unpack a 'struct fiemap_extent' structure object number 'index' from
+ the internal 'self._buf' buffer.
+ """
+
+ offset = _FIEMAP_SIZE + _FIEMAP_EXTENT_SIZE * index
+ return struct.unpack(_FIEMAP_EXTENT_FORMAT,
+ self._buf[offset : offset + _FIEMAP_EXTENT_SIZE])
+
+ def _do_get_mapped_ranges(self, start, count):
+ """
+ Implements most the functionality for the 'get_mapped_ranges()'
+ generator: invokes the FIEMAP ioctl, walks through the mapped extents
+ and yields mapped block ranges. However, the ranges may be consecutive
+ (e.g., (1, 100), (100, 200)) and 'get_mapped_ranges()' simply merges
+ them.
+ """
+
+ block = start
+ while block < start + count:
+ struct_fiemap = self._invoke_fiemap(block, count)
+
+ mapped_extents = struct_fiemap[3]
+ if mapped_extents == 0:
+ # No more mapped blocks
+ return
+
+ extent = 0
+ while extent < mapped_extents:
+ fiemap_extent = self._unpack_fiemap_extent(extent)
+
+ # Start of the extent
+ extent_start = fiemap_extent[0]
+ # Starting block number of the extent
+ extent_block = extent_start // self.block_size
+ # Length of the extent
+ extent_len = fiemap_extent[2]
+ # Count of blocks in the extent
+ extent_count = extent_len // self.block_size
+
+ # Extent length and offset have to be block-aligned
+ assert extent_start % self.block_size == 0
+ assert extent_len % self.block_size == 0
+
+ if extent_block > start + count - 1:
+ return
+
+ first = max(extent_block, block)
+ last = min(extent_block + extent_count, start + count) - 1
+ yield (first, last)
+
+ extent += 1
+
+ block = extent_block + extent_count
+
+ def get_mapped_ranges(self, start, count):
+ """Refer the '_FilemapBase' class for the documentation."""
+ self._log.debug("FilemapFiemap: get_mapped_ranges(%d, %d(%d))"
+ % (start, count, start + count - 1))
+ iterator = self._do_get_mapped_ranges(start, count)
+ first_prev, last_prev = next(iterator)
+
+ for first, last in iterator:
+ if last_prev == first - 1:
+ last_prev = last
+ else:
+ self._log.debug("FilemapFiemap: yielding range (%d, %d)"
+ % (first_prev, last_prev))
+ yield (first_prev, last_prev)
+ first_prev, last_prev = first, last
+
+ self._log.debug("FilemapFiemap: yielding range (%d, %d)"
+ % (first_prev, last_prev))
+ yield (first_prev, last_prev)
+
+ def get_unmapped_ranges(self, start, count):
+ """Refer the '_FilemapBase' class for the documentation."""
+ self._log.debug("FilemapFiemap: get_unmapped_ranges(%d, %d(%d))"
+ % (start, count, start + count - 1))
+ hole_first = start
+ for first, last in self._do_get_mapped_ranges(start, count):
+ if first > hole_first:
+ self._log.debug("FilemapFiemap: yielding range (%d, %d)"
+ % (hole_first, first - 1))
+ yield (hole_first, first - 1)
+
+ hole_first = last + 1
+
+ if hole_first < start + count:
+ self._log.debug("FilemapFiemap: yielding range (%d, %d)"
+ % (hole_first, start + count - 1))
+ yield (hole_first, start + count - 1)
+
+def filemap(image, log=None):
+ """
+ Create and return an instance of a Filemap class - 'FilemapFiemap' or
+ 'FilemapSeek', depending on what the system we run on supports. If the
+ FIEMAP ioctl is supported, an instance of the 'FilemapFiemap' class is
+ returned. Otherwise, if 'SEEK_HOLE' is supported an instance of the
+ 'FilemapSeek' class is returned. If none of these are supported, the
+ function generates an 'Error' type exception.
+ """
+
+ try:
+ return FilemapFiemap(image, log)
+ except ErrorNotSupp:
+ return FilemapSeek(image, log)
+
+def sparse_copy(src_fname, dst_fname, offset=0, skip=0):
+ """Efficiently copy sparse file to or into another file."""
+ fmap = filemap(src_fname)
+ try:
+ dst_file = open(dst_fname, 'r+b')
+ except IOError:
+ dst_file = open(dst_fname, 'wb')
+
+ for first, last in fmap.get_mapped_ranges(0, fmap.blocks_cnt):
+ start = first * fmap.block_size
+ end = (last + 1) * fmap.block_size
+
+ if start < skip < end:
+ start = skip
+
+ fmap._f_image.seek(start, os.SEEK_SET)
+ dst_file.seek(offset + start, os.SEEK_SET)
+
+ chunk_size = 1024 * 1024
+ to_read = end - start
+ read = 0
+
+ while read < to_read:
+ if read + chunk_size > to_read:
+ chunk_size = to_read - read
+ chunk = fmap._f_image.read(chunk_size)
+ dst_file.write(chunk)
+ read += chunk_size
+ dst_file.close()
diff --git a/import-layers/yocto-poky/scripts/lib/wic/help.py b/import-layers/yocto-poky/scripts/lib/wic/help.py
index 405d25a87..e5347ec4b 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/help.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/help.py
@@ -45,7 +45,7 @@ def display_help(subcommand, subcommands):
if callable(hlp):
hlp = hlp()
pager = subprocess.Popen('less', stdin=subprocess.PIPE)
- pager.communicate(hlp)
+ pager.communicate(hlp.encode('utf-8'))
return True
@@ -55,7 +55,7 @@ def wic_help(args, usage_str, subcommands):
Subcommand help dispatcher.
"""
if len(args) == 1 or not display_help(args[1], subcommands):
- print usage_str
+ print(usage_str)
def get_wic_plugins_help():
@@ -66,7 +66,7 @@ def get_wic_plugins_help():
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).iteritems():
+ for name, plugin in pluginmgr.get_plugins(plugin_type).items():
result += "\n %s plugin:\n" % name
if plugin.__doc__:
result += plugin.__doc__
@@ -152,7 +152,7 @@ SYNOPSIS
[-e | --image-name] [-s, --skip-build-check] [-D, --debug]
[-r, --rootfs-dir] [-b, --bootimg-dir]
[-k, --kernel-dir] [-n, --native-sysroot] [-f, --build-rootfs]
- [-c, --compress-with]
+ [-c, --compress-with] [-m, --bmap]
DESCRIPTION
This command creates an OpenEmbedded image based on the 'OE
@@ -221,6 +221,9 @@ DESCRIPTION
The -c option is used to specify compressor utility to compress
an image. gzip, bzip2 and xz compressors are supported.
+
+ The -m option is used to produce .bmap file for the image. This file
+ can be used to flash image using bmaptool utility.
"""
wic_list_usage = """
@@ -738,6 +741,10 @@ DESCRIPTION
in bootloader configuration before running wic. In this case .wks file can
be generated or modified to set preconfigured parition UUID using this option.
+ --system-id: This option is specific to wic. It specifies partition system id. It's useful
+ for the harware that requires non-default partition system ids. The parameter
+ in one byte long hex number either with 0x prefix or without it.
+
* bootloader
This command allows the user to specify various bootloader
diff --git a/import-layers/yocto-poky/scripts/lib/wic/imager/baseimager.py b/import-layers/yocto-poky/scripts/lib/wic/imager/baseimager.py
index 760cf8a58..1a52dd8b4 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/imager/baseimager.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/imager/baseimager.py
@@ -16,7 +16,6 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-from __future__ import with_statement
import os
import tempfile
import shutil
@@ -25,7 +24,7 @@ from wic import msger
from wic.utils.errors import CreatorError
from wic.utils import runner
-class BaseImageCreator(object):
+class BaseImageCreator():
"""Base class for image creation.
BaseImageCreator is the simplest creator class available; it will
@@ -68,7 +67,7 @@ class BaseImageCreator(object):
}
# update setting from createopts
- for key in createopts.keys():
+ for key in createopts:
if key in optmap:
option = optmap[key]
else:
diff --git a/import-layers/yocto-poky/scripts/lib/wic/imager/direct.py b/import-layers/yocto-poky/scripts/lib/wic/imager/direct.py
index a1b424965..edf5e5d22 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/imager/direct.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/imager/direct.py
@@ -26,20 +26,40 @@
import os
import shutil
+import uuid
from wic import msger
-from wic.utils import fs_related
from wic.utils.oe.misc import get_bitbake_var
from wic.utils.partitionedfs import Image
from wic.utils.errors import CreatorError, ImageError
from wic.imager.baseimager import BaseImageCreator
from wic.plugin import pluginmgr
-from wic.utils.oe.misc import exec_cmd
+from wic.utils.oe.misc import exec_cmd, exec_native_cmd
disk_methods = {
"do_install_disk":None,
}
+class DiskImage():
+ """
+ A Disk backed by a file.
+ """
+ def __init__(self, device, size):
+ self.size = size
+ self.device = device
+ self.created = False
+
+ def exists(self):
+ return os.path.exists(self.device)
+
+ def create(self):
+ if self.created:
+ return
+ # create sparse disk image
+ cmd = "truncate %s -s %s" % (self.device, self.size)
+ exec_cmd(cmd)
+ self.created = True
+
class DirectImageCreator(BaseImageCreator):
"""
Installs a system into a file containing a partitioned disk image.
@@ -52,7 +72,8 @@ class DirectImageCreator(BaseImageCreator):
"""
def __init__(self, oe_builddir, image_output_dir, rootfs_dir, bootimg_dir,
- kernel_dir, native_sysroot, compressor, creatoropts=None):
+ kernel_dir, native_sysroot, compressor, creatoropts=None,
+ bmap=False):
"""
Initialize a DirectImageCreator instance.
@@ -74,6 +95,7 @@ class DirectImageCreator(BaseImageCreator):
self.kernel_dir = kernel_dir
self.native_sysroot = native_sysroot
self.compressor = compressor
+ self.bmap = bmap
def __get_part_num(self, num, parts):
"""calculate the real partition number, accounting for partitions not
@@ -221,12 +243,23 @@ class DirectImageCreator(BaseImageCreator):
self.__image = Image(self.native_sysroot)
- for part in parts:
+ disk_ids = {}
+ for num, part in enumerate(parts, 1):
# as a convenience, set source to the boot partition source
# instead of forcing it to be set via bootloader --source
if not self.ks.bootloader.source and part.mountpoint == "/boot":
self.ks.bootloader.source = part.source
+ # generate parition UUIDs
+ if not part.uuid and part.use_uuid:
+ 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, parts))
+
fstab_path = self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR"))
shutil.rmtree(self.workdir)
@@ -267,7 +300,8 @@ class DirectImageCreator(BaseImageCreator):
align=part.align,
no_table=part.no_table,
part_type=part.part_type,
- uuid=part.uuid)
+ uuid=part.uuid,
+ system_id=part.system_id)
if fstab_path:
shutil.move(fstab_path + ".orig", fstab_path)
@@ -279,9 +313,9 @@ class DirectImageCreator(BaseImageCreator):
full_path = self._full_path(self.__imgdir, disk_name, "direct")
msger.debug("Adding disk %s as %s with size %s bytes" \
% (disk_name, full_path, disk['min_size']))
- disk_obj = fs_related.DiskImage(full_path, disk['min_size'])
+ disk_obj = DiskImage(full_path, disk['min_size'])
self.__disks[disk_name] = disk_obj
- self.__image.add_disk(disk_name, disk_obj)
+ self.__image.add_disk(disk_name, disk_obj, disk_ids.get(disk_name))
self.__image.create()
@@ -313,12 +347,17 @@ class DirectImageCreator(BaseImageCreator):
self.bootimg_dir,
self.kernel_dir,
self.native_sysroot)
- # Compress the image
- if self.compressor:
- for disk_name, disk in self.__image.disks.items():
- full_path = self._full_path(self.__imgdir, disk_name, "direct")
- msger.debug("Compressing disk %s with %s" % \
- (disk_name, self.compressor))
+
+ for disk_name, disk in self.__image.disks.items():
+ full_path = self._full_path(self.__imgdir, 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))
def print_outimage_info(self):
@@ -375,6 +414,6 @@ class DirectImageCreator(BaseImageCreator):
if not self.__image is None:
try:
self.__image.cleanup()
- except ImageError, err:
+ except ImageError as err:
msger.warning("%s" % err)
diff --git a/import-layers/yocto-poky/scripts/lib/wic/ksparser.py b/import-layers/yocto-poky/scripts/lib/wic/ksparser.py
index 8c3f80882..0894e2b19 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/ksparser.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/ksparser.py
@@ -51,7 +51,7 @@ def sizetype(arg):
Converts size string in <num>[K|k|M|G] format into the integer value
"""
if arg.isdigit():
- return int(arg) * 1024L
+ return int(arg) * 1024
if not arg[:-1].isdigit():
raise ArgumentTypeError("Invalid size: %r" % arg)
@@ -60,9 +60,9 @@ def sizetype(arg):
if arg.endswith("k") or arg.endswith("K"):
return size
if arg.endswith("M"):
- return size * 1024L
+ return size * 1024
if arg.endswith("G"):
- return size * 1024L * 1024L
+ return size * 1024 * 1024
raise ArgumentTypeError("Invalid size: %r" % arg)
@@ -92,7 +92,25 @@ def cannedpathtype(arg):
raise ArgumentTypeError("file not found: %s" % arg)
return result
-class KickStart(object):
+def systemidtype(arg):
+ """
+ Custom type for ArgumentParser
+ Checks if the argument sutisfies system id requirements,
+ i.e. if it's one byte long integer > 0
+ """
+ error = "Invalid system type: %s. must be hex "\
+ "between 0x1 and 0xFF" % arg
+ try:
+ result = int(arg, 16)
+ except ValueError:
+ raise ArgumentTypeError(error)
+
+ if result <= 0 or result > 0xff:
+ raise ArgumentTypeError(error)
+
+ return arg
+
+class KickStart():
""""Kickstart parser implementation."""
def __init__(self, confpath):
@@ -106,10 +124,10 @@ class KickStart(object):
subparsers = parser.add_subparsers()
part = subparsers.add_parser('part')
- part.add_argument('mountpoint')
+ part.add_argument('mountpoint', nargs='?')
part.add_argument('--active', action='store_true')
part.add_argument('--align', type=int)
- part.add_argument("--extra-space", type=sizetype, default=10*1024L)
+ part.add_argument("--extra-space", type=sizetype, default=10*1024)
part.add_argument('--fsoptions', dest='fsopts')
part.add_argument('--fstype')
part.add_argument('--label')
@@ -121,6 +139,7 @@ class KickStart(object):
part.add_argument('--size', type=sizetype, default=0)
part.add_argument('--source')
part.add_argument('--sourceparams')
+ part.add_argument('--system-id', type=systemidtype)
part.add_argument('--use-uuid', action='store_true')
part.add_argument('--uuid')
diff --git a/import-layers/yocto-poky/scripts/lib/wic/msger.py b/import-layers/yocto-poky/scripts/lib/wic/msger.py
index b73755422..fb8336d94 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/msger.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/msger.py
@@ -21,18 +21,14 @@ import sys
import re
import time
-__ALL__ = ['set_mode',
- 'get_loglevel',
+__ALL__ = ['get_loglevel',
'set_loglevel',
'set_logfile',
- 'raw',
'debug',
'verbose',
'info',
'warning',
'error',
- 'ask',
- 'pause',
]
# COLORs in ANSI
@@ -70,10 +66,6 @@ def _general_print(head, color, msg=None, stream=None, level='normal'):
# skip
return
- # encode raw 'unicode' str to utf8 encoded str
- if msg and isinstance(msg, unicode):
- msg = msg.encode('utf-8', 'ignore')
-
errormsg = ''
if CATCHERR_BUFFILE_FD > 0:
size = os.lseek(CATCHERR_BUFFILE_FD, 0, os.SEEK_END)
@@ -122,9 +114,6 @@ def _color_print(head, color, msg, stream, level):
newline = True
if msg is not None:
- if isinstance(msg, unicode):
- msg = msg.encode('utf8', 'ignore')
-
stream.write('%s%s' % (head, msg))
if newline:
stream.write('\n')
@@ -159,7 +148,7 @@ def _split_msg(head, msg):
return head, msg
def get_loglevel():
- return (k for k, v in LOG_LEVELS.items() if v == LOG_LEVEL).next()
+ return next((k for k, v in LOG_LEVELS.items() if v == LOG_LEVEL))
def set_loglevel(level):
global LOG_LEVEL
@@ -182,9 +171,6 @@ def log(msg=''):
if msg:
LOG_CONTENT += msg
-def raw(msg=''):
- _general_print('', NO_COLOR, msg)
-
def info(msg):
head, msg = _split_msg('Info', msg)
_general_print(head, INFO_COLOR, msg)
@@ -206,66 +192,6 @@ def error(msg):
_color_perror(head, ERR_COLOR, msg)
sys.exit(1)
-def ask(msg, default=True):
- _general_print('\rQ', ASK_COLOR, '')
- try:
- if default:
- msg += '(Y/n) '
- else:
- msg += '(y/N) '
- if INTERACTIVE:
- while True:
- repl = raw_input(msg)
- if repl.lower() == 'y':
- return True
- elif repl.lower() == 'n':
- return False
- elif not repl.strip():
- # <Enter>
- return default
-
- # else loop
- else:
- if default:
- msg += ' Y'
- else:
- msg += ' N'
- _general_print('', NO_COLOR, msg)
-
- return default
- except KeyboardInterrupt:
- sys.stdout.write('\n')
- sys.exit(2)
-
-def choice(msg, choices, default=0):
- if default >= len(choices):
- return None
- _general_print('\rQ', ASK_COLOR, '')
- try:
- msg += " [%s] " % '/'.join(choices)
- if INTERACTIVE:
- while True:
- repl = raw_input(msg)
- if repl in choices:
- return repl
- elif not repl.strip():
- return choices[default]
- else:
- msg += choices[default]
- _general_print('', NO_COLOR, msg)
-
- return choices[default]
- except KeyboardInterrupt:
- sys.stdout.write('\n')
- sys.exit(2)
-
-def pause(msg=None):
- if INTERACTIVE:
- _general_print('\rQ', ASK_COLOR, '')
- if msg is None:
- msg = 'press <ENTER> to continue ...'
- raw_input(msg)
-
def set_logfile(fpath):
global LOG_FILE_FP
diff --git a/import-layers/yocto-poky/scripts/lib/wic/partition.py b/import-layers/yocto-poky/scripts/lib/wic/partition.py
index f40d1bc8b..90f65a1e3 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/partition.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/partition.py
@@ -26,7 +26,6 @@
import os
import tempfile
-import uuid
from wic.utils.oe.misc import msger, parse_sourceparams
from wic.utils.oe.misc import exec_cmd, exec_native_cmd
@@ -38,7 +37,7 @@ partition_methods = {
"do_configure_partition":None,
}
-class Partition(object):
+class Partition():
def __init__(self, args, lineno):
self.args = args
@@ -57,10 +56,9 @@ class Partition(object):
self.size = args.size
self.source = args.source
self.sourceparams = args.sourceparams
+ self.system_id = args.system_id
self.use_uuid = args.use_uuid
self.uuid = args.uuid
- if args.use_uuid and not self.uuid:
- self.uuid = str(uuid.uuid4())
self.lineno = lineno
self.source_file = ""
@@ -219,9 +217,7 @@ class Partition(object):
msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
(extra_blocks, self.mountpoint, rootfs_size))
- dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \
- (rootfs, rootfs_size)
- exec_cmd(dd_cmd)
+ exec_cmd("truncate %s -s %d" % (rootfs, rootfs_size * 1024))
extra_imagecmd = "-i 8192"
@@ -254,9 +250,7 @@ class Partition(object):
msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
(extra_blocks, self.mountpoint, rootfs_size))
- dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \
- (rootfs, rootfs_size)
- exec_cmd(dd_cmd)
+ exec_cmd("truncate %s -s %d" % (rootfs, rootfs_size * 1024))
label_str = ""
if self.label:
@@ -284,14 +278,6 @@ class Partition(object):
msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
(extra_blocks, self.mountpoint, blocks))
- # Ensure total sectors is an integral number of sectors per
- # track or mcopy will complain. Sectors are 512 bytes, and we
- # generate images with 32 sectors per track. This calculation
- # is done in blocks, thus the mod by 16 instead of 32. Apply
- # sector count fix only when needed.
- if blocks % 16 != 0:
- blocks += (16 - (blocks % 16))
-
label_str = "-n boot"
if self.label:
label_str = "-n %s" % self.label
@@ -319,9 +305,7 @@ class Partition(object):
"""
Prepare an empty ext2/3/4 partition.
"""
- dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \
- (rootfs, self.size)
- exec_cmd(dd_cmd)
+ exec_cmd("truncate %s -s %d" % (rootfs, self.size * 1024))
extra_imagecmd = "-i 8192"
@@ -338,9 +322,7 @@ class Partition(object):
"""
Prepare an empty btrfs partition.
"""
- dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \
- (rootfs, self.size)
- exec_cmd(dd_cmd)
+ exec_cmd("truncate %s -s %d" % (rootfs, self.size * 1024))
label_str = ""
if self.label:
@@ -401,9 +383,7 @@ class Partition(object):
"""
path = "%s/fs.%s" % (cr_workdir, self.fstype)
- dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \
- (path, self.size)
- exec_cmd(dd_cmd)
+ exec_cmd("truncate %s -s %d" % (path, self.size * 1024))
import uuid
label_str = ""
diff --git a/import-layers/yocto-poky/scripts/lib/wic/plugin.py b/import-layers/yocto-poky/scripts/lib/wic/plugin.py
index ccfdfcb93..306b32437 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/plugin.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/plugin.py
@@ -29,7 +29,7 @@ PLUGIN_TYPES = ["imager", "source"]
PLUGIN_DIR = "/lib/wic/plugins" # relative to scripts
SCRIPTS_PLUGIN_DIR = "scripts" + PLUGIN_DIR
-class PluginMgr(object):
+class PluginMgr():
plugin_dirs = {}
# make the manager class as singleton
@@ -42,7 +42,7 @@ class PluginMgr(object):
def __init__(self):
wic_path = os.path.dirname(__file__)
- eos = wic_path.find('scripts') + len('scripts')
+ eos = wic_path.rfind('scripts') + len('scripts')
scripts_path = wic_path[:eos]
self.scripts_path = scripts_path
self.plugin_dir = scripts_path + PLUGIN_DIR
@@ -81,7 +81,7 @@ class PluginMgr(object):
# the value True/False means "loaded"
def _load_all(self):
- for (pdir, loaded) in self.plugin_dirs.iteritems():
+ for (pdir, loaded) in self.plugin_dirs.items():
if loaded:
continue
@@ -97,7 +97,7 @@ class PluginMgr(object):
self.plugin_dirs[pdir] = True
msger.debug("Plugin module %s:%s imported"\
% (mod, pymod.__file__))
- except ImportError, err:
+ except ImportError as err:
msg = 'Failed to load plugin %s/%s: %s' \
% (os.path.basename(pdir), mod, err)
msger.warning(msg)
@@ -135,9 +135,9 @@ class PluginMgr(object):
None is returned.
"""
return_methods = None
- for _source_name, klass in self.get_plugins('source').iteritems():
+ for _source_name, klass in self.get_plugins('source').items():
if _source_name == source_name:
- for _method_name in methods.keys():
+ for _method_name in methods:
if not hasattr(klass, _method_name):
msger.warning("Unimplemented %s source interface for: %s"\
% (_method_name, _source_name))
diff --git a/import-layers/yocto-poky/scripts/lib/wic/pluginbase.py b/import-layers/yocto-poky/scripts/lib/wic/pluginbase.py
index ee8fe95c6..e737dee7b 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/pluginbase.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/pluginbase.py
@@ -15,34 +15,26 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-from wic import msger
-
-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']] = {}
+__all__ = ['ImagerPlugin', 'SourcePlugin', 'get_plugins']
- elif hasattr(cls, 'wic_plugin_type') and 'name' in attrs:
- cls.plugins[cls.wic_plugin_type][attrs['name']] = cls
+import sys
+from collections import defaultdict
- def show_plugins(cls):
- for cls in cls.plugins[cls.wic_plugin_type]:
- print cls
+from wic import msger
- def get_plugins(cls):
- return cls.plugins
+class PluginMeta(type):
+ plugins = defaultdict(dict)
+ def __new__(cls, name, bases, attrs):
+ class_type = type.__new__(cls, name, bases, attrs)
+ if 'name' in attrs:
+ cls.plugins[class_type.wic_plugin_type][attrs['name']] = class_type
+ return class_type
-class ImagerPlugin(_Plugin):
+class ImagerPlugin(PluginMeta("Plugin", (), {})):
wic_plugin_type = "imager"
-
-class SourcePlugin(_Plugin):
+class SourcePlugin(PluginMeta("Plugin", (), {})):
wic_plugin_type = "source"
"""
The methods that can be implemented by --source plugins.
@@ -99,10 +91,4 @@ class SourcePlugin(_Plugin):
msger.debug("SourcePlugin: do_prepare_partition: part: %s" % part)
def get_plugins(typen):
- plugins = ImagerPlugin.get_plugins()
- if typen in plugins:
- return plugins[typen]
- else:
- return None
-
-__all__ = ['ImagerPlugin', 'SourcePlugin', 'get_plugins']
+ return PluginMeta.plugins.get(typen)
diff --git a/import-layers/yocto-poky/scripts/lib/wic/plugins/imager/direct_plugin.py b/import-layers/yocto-poky/scripts/lib/wic/plugins/imager/direct_plugin.py
index 6d3f46cc6..8fe393080 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/plugins/imager/direct_plugin.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/plugins/imager/direct_plugin.py
@@ -86,7 +86,8 @@ class DirectPlugin(ImagerPlugin):
kernel_dir,
native_sysroot,
compressor,
- creatoropts)
+ creatoropts,
+ opts.bmap)
try:
creator.create()
diff --git a/import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-efi.py b/import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-efi.py
index a4734c9b3..8bc362254 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-efi.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-efi.py
@@ -84,7 +84,7 @@ class BootimgEFIPlugin(SourcePlugin):
@classmethod
def do_configure_gummiboot(cls, hdddir, creator, cr_workdir):
"""
- Create loader-specific (gummiboot) config
+ Create loader-specific systemd-boot/gummiboot config
"""
install_cmd = "install -d %s/loader" % hdddir
exec_cmd(install_cmd)
@@ -149,7 +149,8 @@ class BootimgEFIPlugin(SourcePlugin):
try:
if source_params['loader'] == 'grub-efi':
cls.do_configure_grubefi(hdddir, creator, cr_workdir)
- elif source_params['loader'] == 'gummiboot':
+ elif source_params['loader'] == 'gummiboot' \
+ or source_params['loader'] == 'systemd-boot':
cls.do_configure_gummiboot(hdddir, creator, cr_workdir)
else:
msger.error("unrecognized bootimg-efi loader: %s" % source_params['loader'])
@@ -189,7 +190,8 @@ class BootimgEFIPlugin(SourcePlugin):
exec_cmd(cp_cmd, True)
shutil.move("%s/grub.cfg" % cr_workdir,
"%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir)
- elif source_params['loader'] == 'gummiboot':
+ elif source_params['loader'] == 'gummiboot' \
+ or source_params['loader'] == 'systemd-boot':
cp_cmd = "cp %s/EFI/BOOT/* %s/EFI/BOOT" % (bootimg_dir, hdddir)
exec_cmd(cp_cmd, True)
else:
@@ -197,6 +199,11 @@ class BootimgEFIPlugin(SourcePlugin):
except KeyError:
msger.error("bootimg-efi requires a loader, none specified")
+ startup = os.path.join(bootimg_dir, "startup.nsh")
+ if os.path.exists(startup):
+ cp_cmd = "cp %s %s/" % (startup, hdddir)
+ exec_cmd(cp_cmd, True)
+
du_cmd = "du -bks %s" % hdddir
out = exec_cmd(du_cmd)
blocks = int(out.split()[0])
@@ -211,12 +218,6 @@ class BootimgEFIPlugin(SourcePlugin):
msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
(extra_blocks, part.mountpoint, blocks))
- # Ensure total sectors is an integral number of sectors per
- # track or mcopy will complain. Sectors are 512 bytes, and we
- # generate images with 32 sectors per track. This calculation is
- # done in blocks, thus the mod by 16 instead of 32.
- blocks += (16 - (blocks % 16))
-
# dosfs image, created by mkdosfs
bootimg = "%s/boot.img" % cr_workdir
diff --git a/import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-pcbios.py b/import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-pcbios.py
index 5b719bf3b..f204daa32 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-pcbios.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/plugins/source/bootimg-pcbios.py
@@ -179,12 +179,6 @@ class BootimgPcbiosPlugin(SourcePlugin):
msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
(extra_blocks, part.mountpoint, blocks))
- # Ensure total sectors is an integral number of sectors per
- # track or mcopy will complain. Sectors are 512 bytes, and we
- # generate images with 32 sectors per track. This calculation is
- # done in blocks, thus the mod by 16 instead of 32.
- blocks += (16 - (blocks % 16))
-
# dosfs image, created by mkdosfs
bootimg = "%s/boot.img" % cr_workdir
diff --git a/import-layers/yocto-poky/scripts/lib/wic/plugins/source/isoimage-isohybrid.py b/import-layers/yocto-poky/scripts/lib/wic/plugins/source/isoimage-isohybrid.py
index bc9928314..3858fd439 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/plugins/source/isoimage-isohybrid.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/plugins/source/isoimage-isohybrid.py
@@ -27,6 +27,7 @@ import glob
from wic import msger
from wic.pluginbase import SourcePlugin
+from wic.utils.misc import get_custom_config
from wic.utils.oe.misc import exec_cmd, exec_native_cmd, get_bitbake_var
class IsoImagePlugin(SourcePlugin):
@@ -59,7 +60,7 @@ class IsoImagePlugin(SourcePlugin):
"""
Create loader-specific (syslinux) config
"""
- splash = os.path.join(cr_workdir, "/ISO/boot/splash.jpg")
+ splash = os.path.join(cr_workdir, "ISO/boot/splash.jpg")
if os.path.exists(splash):
splashline = "menu background splash.jpg"
else:
@@ -94,33 +95,43 @@ class IsoImagePlugin(SourcePlugin):
"""
Create loader-specific (grub-efi) config
"""
- splash = os.path.join(cr_workdir, "/EFI/boot/splash.jpg")
- if os.path.exists(splash):
- splashline = "menu background splash.jpg"
+ configfile = creator.ks.bootloader.configfile
+ if configfile:
+ grubefi_conf = get_custom_config(configfile)
+ if grubefi_conf:
+ msger.debug("Using custom configuration file "
+ "%s for grub.cfg" % configfile)
+ else:
+ msger.error("configfile is specified but failed to "
+ "get it from %s." % configfile)
else:
- splashline = ""
+ splash = os.path.join(cr_workdir, "EFI/boot/splash.jpg")
+ if os.path.exists(splash):
+ splashline = "menu background splash.jpg"
+ else:
+ splashline = ""
- bootloader = creator.ks.bootloader
+ bootloader = creator.ks.bootloader
- grubefi_conf = ""
- grubefi_conf += "serial --unit=0 --speed=115200 --word=8 "
- grubefi_conf += "--parity=no --stop=1\n"
- grubefi_conf += "default=boot\n"
- grubefi_conf += "timeout=%s\n" % (bootloader.timeout or 10)
- grubefi_conf += "\n"
- grubefi_conf += "search --set=root --label %s " % part.label
- grubefi_conf += "\n"
- grubefi_conf += "menuentry 'boot'{\n"
+ grubefi_conf = ""
+ grubefi_conf += "serial --unit=0 --speed=115200 --word=8 "
+ grubefi_conf += "--parity=no --stop=1\n"
+ grubefi_conf += "default=boot\n"
+ grubefi_conf += "timeout=%s\n" % (bootloader.timeout or 10)
+ grubefi_conf += "\n"
+ grubefi_conf += "search --set=root --label %s " % part.label
+ grubefi_conf += "\n"
+ grubefi_conf += "menuentry 'boot'{\n"
- kernel = "/bzImage"
+ kernel = "/bzImage"
- grubefi_conf += "linux %s rootwait %s\n" \
- % (kernel, bootloader.append)
- grubefi_conf += "initrd /initrd \n"
- grubefi_conf += "}\n"
+ grubefi_conf += "linux %s rootwait %s\n" \
+ % (kernel, bootloader.append)
+ grubefi_conf += "initrd /initrd \n"
+ grubefi_conf += "}\n"
- if splashline:
- grubefi_conf += "%s\n" % splashline
+ if splashline:
+ grubefi_conf += "%s\n" % splashline
msger.debug("Writing grubefi config %s/EFI/BOOT/grub.cfg" \
% cr_workdir)
@@ -430,12 +441,6 @@ class IsoImagePlugin(SourcePlugin):
% (part.mountpoint, blocks)
msger.debug(msg)
- # Ensure total sectors is an integral number of sectors per
- # track or mcopy will complain. Sectors are 512 bytes, and we
- # generate images with 32 sectors per track. This calculation is
- # done in blocks, thus the mod by 16 instead of 32.
- blocks += (16 - (blocks % 16))
-
# dosfs image for EFI boot
bootimg = "%s/efi.img" % isodir
diff --git a/import-layers/yocto-poky/scripts/lib/wic/plugins/source/rawcopy.py b/import-layers/yocto-poky/scripts/lib/wic/plugins/source/rawcopy.py
index 0472f536b..e0b11f95a 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/plugins/source/rawcopy.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/plugins/source/rawcopy.py
@@ -20,6 +20,7 @@ import os
from wic import msger
from wic.pluginbase import SourcePlugin
from wic.utils.oe.misc import exec_cmd, get_bitbake_var
+from wic.filemap import sparse_copy
class RawCopyPlugin(SourcePlugin):
"""
@@ -67,14 +68,12 @@ class RawCopyPlugin(SourcePlugin):
return
src = os.path.join(bootimg_dir, source_params['file'])
- dst = os.path.join(cr_workdir, source_params['file'])
+ dst = os.path.join(cr_workdir, "%s.%s" % (source_params['file'], part.lineno))
if 'skip' in source_params:
- dd_cmd = "dd if=%s of=%s ibs=%s skip=1 conv=notrunc" % \
- (src, dst, source_params['skip'])
+ sparse_copy(src, dst, skip=source_params['skip'])
else:
- dd_cmd = "cp %s %s" % (src, dst)
- exec_cmd(dd_cmd)
+ sparse_copy(src, dst)
# get the size in the right units for kickstart (kB)
du_cmd = "du -Lbks %s" % dst
diff --git a/import-layers/yocto-poky/scripts/lib/wic/utils/fs_related.py b/import-layers/yocto-poky/scripts/lib/wic/utils/fs_related.py
deleted file mode 100644
index 2e74461a4..000000000
--- a/import-layers/yocto-poky/scripts/lib/wic/utils/fs_related.py
+++ /dev/null
@@ -1,84 +0,0 @@
-#!/usr/bin/env python -tt
-#
-# Copyright (c) 2007, Red Hat, Inc.
-# Copyright (c) 2009, 2010, 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.
-
-from __future__ import with_statement
-import os
-import errno
-
-from wic.utils.oe.misc import exec_cmd
-
-def makedirs(dirname):
- """A version of os.makedirs() that doesn't throw an
- exception if the leaf directory already exists.
- """
- try:
- os.makedirs(dirname)
- except OSError, err:
- if err.errno != errno.EEXIST:
- raise
-
-class Disk:
- """
- Generic base object for a disk.
- """
- def __init__(self, size, device=None):
- self._device = device
- self._size = size
-
- def create(self):
- pass
-
- def cleanup(self):
- pass
-
- def get_device(self):
- return self._device
- def set_device(self, path):
- self._device = path
- device = property(get_device, set_device)
-
- def get_size(self):
- return self._size
- size = property(get_size)
-
-
-class DiskImage(Disk):
- """
- A Disk backed by a file.
- """
- def __init__(self, image_file, size):
- Disk.__init__(self, size)
- self.image_file = image_file
-
- def exists(self):
- return os.path.exists(self.image_file)
-
- def create(self):
- if self.device is not None:
- return
-
- blocks = self.size / 1024
- if self.size - blocks * 1024:
- blocks += 1
-
- # create disk image
- dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=1" % \
- (self.image_file, blocks)
- exec_cmd(dd_cmd)
-
- self.device = self.image_file
diff --git a/import-layers/yocto-poky/scripts/lib/wic/utils/oe/misc.py b/import-layers/yocto-poky/scripts/lib/wic/utils/oe/misc.py
index 81239ac35..fe188c9d2 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/utils/oe/misc.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/utils/oe/misc.py
@@ -28,12 +28,14 @@
import os
from collections import defaultdict
+from distutils import spawn
from wic import msger
from wic.utils import runner
# executable -> recipe pairs for exec_native_cmd
-NATIVE_RECIPES = {"mcopy": "mtools",
+NATIVE_RECIPES = {"bmaptool": "bmap-tools",
+ "mcopy": "mtools",
"mkdosfs": "dosfstools",
"mkfs.btrfs": "btrfs-tools",
"mkfs.ext2": "e2fsprogs",
@@ -43,6 +45,7 @@ NATIVE_RECIPES = {"mcopy": "mtools",
"mksquashfs": "squashfs-tools",
"mkswap": "util-linux",
"parted": "parted",
+ "sfdisk": "util-linux",
"sgdisk": "gptfdisk",
"syslinux": "syslinux"
}
@@ -82,13 +85,6 @@ def exec_cmd(cmd_and_args, as_shell=False, catch=3):
return out
-def cmd_in_path(cmd, path):
- import scriptpath
-
- scriptpath.add_bitbake_lib_path()
-
- return bb.utils.which(path, cmd) != "" or False
-
def exec_native_cmd(cmd_and_args, native_sysroot, catch=3, pseudo=""):
"""
Execute native command, catching stderr, stdout
@@ -111,7 +107,7 @@ def exec_native_cmd(cmd_and_args, native_sysroot, catch=3, pseudo=""):
msger.debug("exec_native_cmd: %s" % cmd_and_args)
# If the command isn't in the native sysroot say we failed.
- if cmd_in_path(args[0], native_paths):
+ if spawn.find_executable(args[0], native_paths):
ret, out = _exec_cmd(native_cmd_and_args, True, catch)
else:
ret = 127
@@ -186,8 +182,8 @@ class BitbakeVars(defaultdict):
for line in varsfile:
self._parse_line(line, image)
else:
- print "Couldn't get bitbake variable from %s." % fname
- print "File %s doesn't exist." % fname
+ print("Couldn't get bitbake variable from %s." % fname)
+ print("File %s doesn't exist." % fname)
return
else:
# Get bitbake -e output
@@ -201,8 +197,8 @@ class BitbakeVars(defaultdict):
msger.set_loglevel(log_level)
if ret:
- print "Couldn't get '%s' output." % cmd
- print "Bitbake failed with error:\n%s\n" % lines
+ print("Couldn't get '%s' output." % cmd)
+ print("Bitbake failed with error:\n%s\n" % lines)
return
# Parse bitbake -e output
diff --git a/import-layers/yocto-poky/scripts/lib/wic/utils/partitionedfs.py b/import-layers/yocto-poky/scripts/lib/wic/utils/partitionedfs.py
index ad596d26f..cb03009fc 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/utils/partitionedfs.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/utils/partitionedfs.py
@@ -22,6 +22,7 @@ import os
from wic import msger
from wic.utils.errors import ImageError
from wic.utils.oe.misc import exec_cmd, exec_native_cmd
+from wic.filemap import sparse_copy
# Overhead of the MBR partitioning scheme (just one sector)
MBR_OVERHEAD = 1
@@ -32,7 +33,7 @@ GPT_OVERHEAD = 34
# Size of a sector in bytes
SECTOR_SIZE = 512
-class Image(object):
+class Image():
"""
Generic base object for an image.
@@ -42,6 +43,7 @@ class Image(object):
def __init__(self, native_sysroot=None):
self.disks = {}
self.partitions = []
+ self.partimages = []
# Size of a sector used in calculations
self.sector_size = SECTOR_SIZE
self._partitions_layed_out = False
@@ -66,15 +68,17 @@ class Image(object):
'offset': 0, # Offset of next partition (in sectors)
# Minimum required disk size to fit all partitions (in bytes)
'min_size': 0,
- 'ptable_format': "msdos"} # Partition table format
+ 'ptable_format': "msdos", # Partition table format
+ 'identifier': None} # Disk system identifier
- def add_disk(self, disk_name, disk_obj):
+ def add_disk(self, disk_name, disk_obj, identifier):
""" Add a disk object which have to be partitioned. More than one disk
can be added. In case of multiple disks, disk partitions have to be
added for each disk separately with 'add_partition()". """
self.__add_disk(disk_name)
self.disks[disk_name]['disk'] = disk_obj
+ self.disks[disk_name]['identifier'] = identifier
def __add_partition(self, part):
""" This is a helper function for 'add_partition()' which adds a
@@ -87,14 +91,14 @@ class Image(object):
def add_partition(self, size, disk_name, mountpoint, source_file=None, fstype=None,
label=None, fsopts=None, boot=False, align=None, no_table=False,
- part_type=None, uuid=None):
+ part_type=None, uuid=None, system_id=None):
""" Add the next partition. Prtitions have to be added in the
first-to-last order. """
ks_pnum = len(self.partitions)
# Converting kB to sectors for parted
- size = size * 1024 / self.sector_size
+ size = size * 1024 // self.sector_size
part = {'ks_pnum': ks_pnum, # Partition number in the KS file
'size': size, # In sectors
@@ -110,7 +114,8 @@ class Image(object):
'align': align, # Partition alignment
'no_table' : no_table, # Partition does not appear in partition table
'part_type' : part_type, # Partition type
- 'uuid': uuid} # Partition UUID
+ 'uuid': uuid, # Partition UUID
+ 'system_id': system_id} # Partition system id
self.__add_partition(part)
@@ -130,7 +135,7 @@ class Image(object):
for num in range(len(self.partitions)):
part = self.partitions[num]
- if not self.disks.has_key(part['disk_name']):
+ if part['disk_name'] not in self.disks:
raise ImageError("No disk %s for partition %s" \
% (part['disk_name'], part['mountpoint']))
@@ -171,12 +176,12 @@ class Image(object):
# gaps we could enlargea the previous partition?
# Calc how much the alignment is off.
- align_sectors = disk['offset'] % (part['align'] * 1024 / self.sector_size)
+ align_sectors = disk['offset'] % (part['align'] * 1024 // self.sector_size)
if align_sectors:
# If partition is not aligned as required, we need
# to move forward to the next alignment point
- align_sectors = (part['align'] * 1024 / self.sector_size) - align_sectors
+ align_sectors = (part['align'] * 1024 // self.sector_size) - align_sectors
msger.debug("Realignment for %s%s with %s sectors, original"
" offset %s, target alignment is %sK." %
@@ -234,7 +239,7 @@ class Image(object):
def __format_disks(self):
self.layout_partitions()
- for dev in self.disks.keys():
+ for dev in self.disks:
disk = self.disks[dev]
msger.debug("Initializing partition table for %s" % \
(disk['disk'].device))
@@ -242,6 +247,12 @@ class Image(object):
(disk['disk'].device, disk['ptable_format']),
self.native_sysroot)
+ if disk['identifier']:
+ msger.debug("Set disk identifier %x" % disk['identifier'])
+ with open(disk['disk'].device, 'r+b') as img:
+ img.seek(0x1B8)
+ img.write(disk['identifier'].to_bytes(4, 'little'))
+
msger.debug("Creating partitions")
for part in self.partitions:
@@ -296,7 +307,7 @@ class Image(object):
(part['num'], part['part_type'],
disk['disk'].device), self.native_sysroot)
- if part['uuid']:
+ if part['uuid'] and disk['ptable_format'] == "gpt":
msger.debug("partition %d: set UUID to %s" % \
(part['num'], part['uuid']))
exec_native_cmd("sgdisk --partition-guid=%d:%s %s" % \
@@ -310,6 +321,10 @@ class Image(object):
exec_native_cmd("parted -s %s set %d %s on" % \
(disk['disk'].device, part['num'], flag_name),
self.native_sysroot)
+ if part['system_id']:
+ exec_native_cmd("sfdisk --part-type %s %s %s" % \
+ (disk['disk'].device, part['num'], part['system_id']),
+ self.native_sysroot)
# Parted defaults to enabling the lba flag for fat16 partitions,
# which causes compatibility issues with some firmware (and really
@@ -330,6 +345,10 @@ class Image(object):
disk['disk'].cleanup()
except:
pass
+ # remove partition images
+ for image in self.partimages:
+ if os.path.isfile(image):
+ os.remove(image)
def assemble(self, image_file):
msger.debug("Installing partitions")
@@ -338,20 +357,19 @@ class Image(object):
source = part['source_file']
if source:
# install source_file contents into a partition
- cmd = "dd if=%s of=%s bs=%d seek=%d count=%d conv=notrunc" % \
- (source, image_file, self.sector_size,
- part['start'], part['size'])
- exec_cmd(cmd)
+ sparse_copy(source, image_file, part['start'] * self.sector_size)
msger.debug("Installed %s in partition %d, sectors %d-%d, "
"size %d sectors" % \
(source, part['num'], part['start'],
part['start'] + part['size'] - 1, part['size']))
- os.rename(source, image_file + '.p%d' % part['num'])
+ partimage = image_file + '.p%d' % part['num']
+ os.rename(source, partimage)
+ self.partimages.append(partimage)
def create(self):
- for dev in self.disks.keys():
+ for dev in self.disks:
disk = self.disks[dev]
disk['disk'].create()
diff --git a/import-layers/yocto-poky/scripts/lib/wic/utils/runner.py b/import-layers/yocto-poky/scripts/lib/wic/utils/runner.py
index 7431917ff..db536ba58 100644
--- a/import-layers/yocto-poky/scripts/lib/wic/utils/runner.py
+++ b/import-layers/yocto-poky/scripts/lib/wic/utils/runner.py
@@ -65,9 +65,9 @@ def runtool(cmdln_or_args, catch=1):
process = subprocess.Popen(cmdln_or_args, stdout=sout,
stderr=serr, shell=shell)
(sout, serr) = process.communicate()
- # combine stdout and stderr, filter None out
- out = ''.join(filter(None, [sout, serr]))
- except OSError, err:
+ # combine stdout and stderr, filter None out and decode
+ out = ''.join([out.decode('utf-8') for out in [sout, serr] if out])
+ except OSError as err:
if err.errno == 2:
# [Errno 2] No such file or directory
msger.error('Cannot run command: %s, lost dependency?' % cmd)
OpenPOWER on IntegriCloud