wic: implement --bmap option

This option enables generation of <image>.bmap file for the
result image using native bmaptool.

[YOCTO #9413]

(From OE-Core rev: d64c7b37c40b052510419b4d6629b83319c833e4)

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ed Bartosh 2016-05-18 15:34:17 +03:00 committed by Richard Purdie
parent a49d279b50
commit b5804498d6
5 changed files with 28 additions and 13 deletions

View File

@ -69,6 +69,7 @@ class Creator():
optparser.add_option('', '--tmpfs', action='store_true', dest='enabletmpfs', optparser.add_option('', '--tmpfs', action='store_true', dest='enabletmpfs',
help='Setup tmpdir as tmpfs to accelerate, experimental' help='Setup tmpdir as tmpfs to accelerate, experimental'
' feature, use it if you have more than 4G memory') ' feature, use it if you have more than 4G memory')
optparser.add_option('', '--bmap', action='store_true', help='generate .bmap')
return optparser return optparser
def postoptparse(self, options): def postoptparse(self, options):

View File

@ -145,7 +145,7 @@ def list_source_plugins():
def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir, def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
native_sysroot, scripts_path, image_output_dir, native_sysroot, scripts_path, image_output_dir,
compressor, debug): compressor, bmap, debug):
"""Create image """Create image
wks_file - user-defined OE kickstart file 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 scripts_path - absolute path to /scripts dir
image_output_dir - dirname to create for image image_output_dir - dirname to create for image
compressor - compressor utility to compress the image compressor - compressor utility to compress the image
bmap - enable generation of .bmap
Normally, the values for the build artifacts values are determined Normally, the values for the build artifacts values are determined
by 'wic -e' from the output of the 'bitbake -e' command given an by 'wic -e' from the output of the 'bitbake -e' command given an
@ -186,8 +187,12 @@ def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
crobj = creator.Creator() crobj = creator.Creator()
crobj.main(["direct", native_sysroot, kernel_dir, bootimg_dir, rootfs_dir, cmdline = ["direct", native_sysroot, kernel_dir, bootimg_dir, rootfs_dir,
wks_file, image_output_dir, oe_builddir, compressor or ""]) wks_file, image_output_dir, oe_builddir, compressor or ""]
if bmap:
cmdline.append('--bmap')
crobj.main(cmdline)
print("\nThe image(s) were created using OE kickstart file:\n %s" % wks_file) print("\nThe image(s) were created using OE kickstart file:\n %s" % wks_file)

View File

@ -33,7 +33,7 @@ from wic.utils.partitionedfs import Image
from wic.utils.errors import CreatorError, ImageError from wic.utils.errors import CreatorError, ImageError
from wic.imager.baseimager import BaseImageCreator from wic.imager.baseimager import BaseImageCreator
from wic.plugin import pluginmgr 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 = { disk_methods = {
"do_install_disk":None, "do_install_disk":None,
@ -71,7 +71,8 @@ class DirectImageCreator(BaseImageCreator):
""" """
def __init__(self, oe_builddir, image_output_dir, rootfs_dir, bootimg_dir, 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. Initialize a DirectImageCreator instance.
@ -93,6 +94,7 @@ class DirectImageCreator(BaseImageCreator):
self.kernel_dir = kernel_dir self.kernel_dir = kernel_dir
self.native_sysroot = native_sysroot self.native_sysroot = native_sysroot
self.compressor = compressor self.compressor = compressor
self.bmap = bmap
def __get_part_num(self, num, parts): def __get_part_num(self, num, parts):
"""calculate the real partition number, accounting for partitions not """calculate the real partition number, accounting for partitions not
@ -333,12 +335,17 @@ class DirectImageCreator(BaseImageCreator):
self.bootimg_dir, self.bootimg_dir,
self.kernel_dir, self.kernel_dir,
self.native_sysroot) self.native_sysroot)
# Compress the image
if self.compressor: for disk_name, disk in self.__image.disks.items():
for disk_name, disk in self.__image.disks.items(): full_path = self._full_path(self.__imgdir, disk_name, "direct")
full_path = self._full_path(self.__imgdir, disk_name, "direct") # Generate .bmap
msger.debug("Compressing disk %s with %s" % \ if self.bmap:
(disk_name, self.compressor)) 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)) exec_cmd("%s %s" % (self.compressor, full_path))
def print_outimage_info(self): def print_outimage_info(self):

View File

@ -86,7 +86,8 @@ class DirectPlugin(ImagerPlugin):
kernel_dir, kernel_dir,
native_sysroot, native_sysroot,
compressor, compressor,
creatoropts) creatoropts,
opts.bmap)
try: try:
creator.create() creator.create()

View File

@ -115,6 +115,7 @@ def wic_create_subcommand(args, usage_str):
parser.add_option("-c", "--compress-with", choices=("gzip", "bzip2", "xz"), parser.add_option("-c", "--compress-with", choices=("gzip", "bzip2", "xz"),
dest='compressor', dest='compressor',
help="compress image with specified compressor") help="compress image with specified compressor")
parser.add_option("-m", "--bmap", action="store_true", help="generate .bmap")
parser.add_option("-v", "--vars", dest='vars_dir', parser.add_option("-v", "--vars", dest='vars_dir',
help="directory with <image>.env files that store " help="directory with <image>.env files that store "
"bitbake variables") "bitbake variables")
@ -245,7 +246,7 @@ def wic_create_subcommand(args, usage_str):
print("Creating image(s)...\n") print("Creating image(s)...\n")
engine.wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir, engine.wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
native_sysroot, scripts_path, image_output_dir, native_sysroot, scripts_path, image_output_dir,
options.compressor, options.debug) options.compressor, options.bmap, options.debug)
def wic_list_subcommand(args, usage_str): def wic_list_subcommand(args, usage_str):