wic: Extend --rootfs-dir to connect rootfs-dirs

The wic command-line param --rootfs-dir gets generalized to support
multiple directories. Each '--rootfs-dir' could be connected using a
special string, that should be present in .wks. I.e:

wic create ... --rootfs-dir rootfs1=/some/rootfs/dir \
  --rootfs-dir rootfs2=/some/other/rootfs/dir

  part / --source rootfs --rootfs-dir="rootfs1" --ondisk sda --fstype=ext3 \
    --label primary --align 1024

  part /standby --source rootfs --rootfs-dir="rootfs2" \
    --ondisk sda --fstype=ext3 --label secondary --align 1024

The user could use harded-code directory instead of connectors. Like this:

  wic create ... hard-coded-path.wks -r /some/rootfs/dir

  part / --source rootfs --ondisk sda --fstype=ext3 --label primary --align 1024

  part /standby --source rootfs --rootfs-dir=/some/rootfs/dir \
    --ondisk sda --fstype=ext3 --label secondary --align 1024

(From OE-Core rev: 719d093c40e4c259a4c97d6c8a5efb5aeef5fd38)

Signed-off-by: João Henrique Ferreira de Freitas <joaohf@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
João Henrique Ferreira de Freitas 2014-03-29 00:12:08 -03:00 committed by Richard Purdie
parent 3c00384884
commit ba65fe654a
4 changed files with 80 additions and 15 deletions

View File

@ -84,16 +84,18 @@ class DirectImageCreator(BaseImageCreator):
self.hdddir = hdddir self.hdddir = hdddir
self.staging_data_dir = staging_data_dir self.staging_data_dir = staging_data_dir
def __write_fstab(self): def __write_fstab(self, image_rootfs):
"""overriden to generate fstab (temporarily) in rootfs. This """overriden to generate fstab (temporarily) in rootfs. This
is called from mount_instroot, make sure it doesn't get called is called from mount_instroot, make sure it doesn't get called
from BaseImage.mount()""" from BaseImage.mount()"""
if image_rootfs is None:
image_rootfs = self.rootfs_dir return None
parts = self._get_parts()
fstab = image_rootfs + "/etc/fstab" fstab = image_rootfs + "/etc/fstab"
if not os.path.isfile(fstab):
return None
parts = self._get_parts()
self._save_fstab(fstab) self._save_fstab(fstab)
fstab_lines = self._get_fstab(fstab, parts) fstab_lines = self._get_fstab(fstab, parts)
@ -126,6 +128,8 @@ class DirectImageCreator(BaseImageCreator):
def _restore_fstab(self, fstab): def _restore_fstab(self, fstab):
"""Restore the saved fstab in rootfs""" """Restore the saved fstab in rootfs"""
if fstab is None:
return
shutil.move(fstab + ".orig", fstab) shutil.move(fstab + ".orig", fstab)
def _get_fstab(self, fstab, parts): def _get_fstab(self, fstab, parts):
@ -235,8 +239,6 @@ class DirectImageCreator(BaseImageCreator):
self.__instimage = PartitionedMount(self._instroot) self.__instimage = PartitionedMount(self._instroot)
fstab = self.__write_fstab()
for p in parts: for p in parts:
# as a convenience, set source to the boot partition source # as a convenience, set source to the boot partition source
# instead of forcing it to be set via bootloader --source # instead of forcing it to be set via bootloader --source
@ -263,6 +265,9 @@ class DirectImageCreator(BaseImageCreator):
p.prepare(self, self.workdir, self.oe_builddir, self.rootfs_dir, p.prepare(self, self.workdir, self.oe_builddir, self.rootfs_dir,
self.bootimg_dir, self.kernel_dir, self.native_sysroot) self.bootimg_dir, self.kernel_dir, self.native_sysroot)
fstab = self.__write_fstab(p.get_rootfs())
self._restore_fstab(fstab)
self.__instimage.add_partition(int(p.size), self.__instimage.add_partition(int(p.size),
p.disk, p.disk,
p.mountpoint, p.mountpoint,
@ -273,7 +278,6 @@ class DirectImageCreator(BaseImageCreator):
boot = p.active, boot = p.active,
align = p.align, align = p.align,
part_type = p.part_type) part_type = p.part_type)
self._restore_fstab(fstab)
self.__instimage.layout_partitions(self._ptable_format) self.__instimage.layout_partitions(self._ptable_format)
self.__imgdir = self.workdir self.__imgdir = self.workdir

View File

@ -42,6 +42,19 @@ from mic.pluginbase import ImagerPlugin
class DirectPlugin(ImagerPlugin): class DirectPlugin(ImagerPlugin):
name = 'direct' name = 'direct'
@classmethod
def __rootfs_dir_to_dict(self, rootfs_dirs):
"""
Gets a string that contain 'connection=dir' splitted by
space and return a dict
"""
krootfs_dir = {}
for rootfs_dir in rootfs_dirs.split(' '):
k, v = rootfs_dir.split('=')
krootfs_dir[k] = v
return krootfs_dir
@classmethod @classmethod
def do_create(self, subcmd, opts, *args): def do_create(self, subcmd, opts, *args):
""" """
@ -63,11 +76,13 @@ class DirectPlugin(ImagerPlugin):
image_output_dir = args[7] image_output_dir = args[7]
oe_builddir = args[8] oe_builddir = args[8]
krootfs_dir = self.__rootfs_dir_to_dict(rootfs_dir)
configmgr._ksconf = ksconf configmgr._ksconf = ksconf
creator = direct.DirectImageCreator(oe_builddir, creator = direct.DirectImageCreator(oe_builddir,
image_output_dir, image_output_dir,
rootfs_dir, krootfs_dir,
bootimg_dir, bootimg_dir,
kernel_dir, kernel_dir,
native_sysroot, native_sysroot,

View File

@ -45,14 +45,26 @@ class RootfsPlugin(SourcePlugin):
@classmethod @classmethod
def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir, def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir,
kernel_dir, rootfs_dir, native_sysroot): kernel_dir, krootfs_dir, native_sysroot):
""" """
Called to do the actual content population for a partition i.e. it Called to do the actual content population for a partition i.e. it
'prepares' the partition to be incorporated into the image. 'prepares' the partition to be incorporated into the image.
In this case, prepare content for legacy bios boot partition. In this case, prepare content for legacy bios boot partition.
""" """
if part.rootfs: if part.rootfs is None:
rootfs_dir = part.rootfs if not 'ROOTFS_DIR' in krootfs_dir:
msg = "Couldn't find --rootfs-dir, exiting"
msger.error(msg)
rootfs_dir = krootfs_dir['ROOTFS_DIR']
else:
if part.rootfs in krootfs_dir:
rootfs_dir = krootfs_dir[part.rootfs]
elif os.path.isdir(part.rootfs):
rootfs_dir = part.rootfs
else:
msg = "Couldn't find --rootfs-dir=%s connection"
msg += " or it is not a valid path, exiting"
msger.error(msg % part.rootfs)
part.set_rootfs(rootfs_dir) part.set_rootfs(rootfs_dir)
part.prepare_rootfs(cr_workdir, oe_builddir, rootfs_dir, native_sysroot) part.prepare_rootfs(cr_workdir, oe_builddir, rootfs_dir, native_sysroot)

View File

@ -45,6 +45,30 @@ sys.path = sys.path + [lib_path]
from image.help import * from image.help import *
from image.engine import * from image.engine import *
def rootfs_dir_to_args(krootfs_dir):
"""
Get a rootfs_dir dict and serialize to string
"""
rootfs_dir = ''
for k, v in krootfs_dir.items():
rootfs_dir += ' '
rootfs_dir += '='.join([k, v])
return rootfs_dir.strip()
def callback_rootfs_dir(option, opt, value, parser):
"""
Build a dict using --rootfs_dir connection=dir
"""
if not type(parser.values.rootfs_dir) is dict:
parser.values.rootfs_dir = dict()
if '=' in value:
(key, rootfs_dir) = value.split('=')
else:
key = 'ROOTFS_DIR'
rootfs_dir = value
parser.values.rootfs_dir[key] = rootfs_dir
def wic_create_subcommand(args, usage_str): def wic_create_subcommand(args, usage_str):
""" """
@ -60,7 +84,8 @@ def wic_create_subcommand(args, usage_str):
parser.add_option("-e", "--image-name", dest = "image_name", parser.add_option("-e", "--image-name", dest = "image_name",
action = "store", help = "name of the image to use the artifacts from e.g. core-image-sato") action = "store", help = "name of the image to use the artifacts from e.g. core-image-sato")
parser.add_option("-r", "--rootfs-dir", dest = "rootfs_dir", parser.add_option("-r", "--rootfs-dir", dest = "rootfs_dir",
action = "store", help = "path to the /rootfs dir to use as the .wks rootfs source") action = "callback", callback = callback_rootfs_dir, type = "string",
help = "path to the /rootfs dir to use as the .wks rootfs source")
parser.add_option("-b", "--bootimg-dir", dest = "bootimg_dir", parser.add_option("-b", "--bootimg-dir", dest = "bootimg_dir",
action = "store", help = "path to the dir containing the boot artifacts (e.g. /EFI or /syslinux dirs) to use as the .wks bootimg source") action = "store", help = "path to the dir containing the boot artifacts (e.g. /EFI or /syslinux dirs) to use as the .wks bootimg source")
parser.add_option("-k", "--kernel-dir", dest = "kernel_dir", parser.add_option("-k", "--kernel-dir", dest = "kernel_dir",
@ -125,11 +150,13 @@ def wic_create_subcommand(args, usage_str):
image_output_dir = options.outdir image_output_dir = options.outdir
if not options.image_name: if not options.image_name:
rootfs_dir = options.rootfs_dir rootfs_dir = ''
if 'ROOTFS_DIR' in options.rootfs_dir:
rootfs_dir = options.rootfs_dir['ROOTFS_DIR']
bootimg_dir = options.bootimg_dir bootimg_dir = options.bootimg_dir
kernel_dir = options.kernel_dir kernel_dir = options.kernel_dir
native_sysroot = options.native_sysroot native_sysroot = options.native_sysroot
if not os.path.isdir(rootfs_dir): if rootfs_dir and not os.path.isdir(rootfs_dir):
print "--roofs-dir (-r) not found, exiting\n" print "--roofs-dir (-r) not found, exiting\n"
sys.exit(1) sys.exit(1)
if not os.path.isdir(bootimg_dir): if not os.path.isdir(bootimg_dir):
@ -162,6 +189,13 @@ def wic_create_subcommand(args, usage_str):
(not_found, not_found_dir) (not_found, not_found_dir)
sys.exit(1) sys.exit(1)
krootfs_dir = options.rootfs_dir
if krootfs_dir is None:
krootfs_dir = {}
krootfs_dir['ROOTFS_DIR'] = rootfs_dir
rootfs_dir = rootfs_dir_to_args(krootfs_dir)
wic_create(args, wks_file, rootfs_dir, bootimg_dir, kernel_dir, wic_create(args, wks_file, rootfs_dir, bootimg_dir, kernel_dir,
native_sysroot, hdddir, staging_data_dir, scripts_path, native_sysroot, hdddir, staging_data_dir, scripts_path,
image_output_dir, options.debug, options.properties_file) image_output_dir, options.debug, options.properties_file)