Openembedded Core Discussions
 help / color / mirror / Atom feed
From: "João Henrique Ferreira de Freitas" <joaohf@gmail.com>
To: openembedded-core@lists.openembedded.org
Cc: tom.zanussi@linux.intel.com
Subject: [PATCH v3 7/7] wic: Extend --rootfs-dir to connect rootfs-dirs
Date: Thu, 27 Mar 2014 19:07:58 -0300	[thread overview]
Message-ID: <1395958078-5191-8-git-send-email-joaohf@gmail.com> (raw)
In-Reply-To: <1395958078-5191-1-git-send-email-joaohf@gmail.com>

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

Signed-off-by: João Henrique Ferreira de Freitas <joaohf@gmail.com>
---
 scripts/lib/mic/imager/direct.py                |  2 +-
 scripts/lib/mic/plugins/imager/direct_plugin.py | 17 +++++++++++-
 scripts/lib/mic/plugins/source/rootfs.py        | 17 +++++++++---
 scripts/wic                                     | 36 +++++++++++++++++++++++--
 4 files changed, 64 insertions(+), 8 deletions(-)

diff --git a/scripts/lib/mic/imager/direct.py b/scripts/lib/mic/imager/direct.py
index 07a47ea..200a2f3 100644
--- a/scripts/lib/mic/imager/direct.py
+++ b/scripts/lib/mic/imager/direct.py
@@ -89,7 +89,7 @@ class DirectImageCreator(BaseImageCreator):
         is called from mount_instroot, make sure it doesn't get called
         from BaseImage.mount()"""
 
-        image_rootfs = self.rootfs_dir
+        image_rootfs = self.rootfs_dir['ROOTFS_DIR']
 
         parts = self._get_parts()
 
diff --git a/scripts/lib/mic/plugins/imager/direct_plugin.py b/scripts/lib/mic/plugins/imager/direct_plugin.py
index e015256..fc7c10c 100644
--- a/scripts/lib/mic/plugins/imager/direct_plugin.py
+++ b/scripts/lib/mic/plugins/imager/direct_plugin.py
@@ -43,6 +43,19 @@ class DirectPlugin(ImagerPlugin):
     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
     def do_create(self, subcmd, opts, *args):
         """
         Create direct image, called from creator as 'direct' cmd
@@ -63,11 +76,13 @@ class DirectPlugin(ImagerPlugin):
         image_output_dir = args[7]
         oe_builddir = args[8]
 
+        krootfs_dir = self.__rootfs_dir_to_dict(rootfs_dir)
+
         configmgr._ksconf = ksconf
 
         creator = direct.DirectImageCreator(oe_builddir,
                                             image_output_dir,
-                                            rootfs_dir,
+                                            krootfs_dir,
                                             bootimg_dir,
                                             kernel_dir,
                                             native_sysroot,
diff --git a/scripts/lib/mic/plugins/source/rootfs.py b/scripts/lib/mic/plugins/source/rootfs.py
index 83aec45..4eb12ee 100644
--- a/scripts/lib/mic/plugins/source/rootfs.py
+++ b/scripts/lib/mic/plugins/source/rootfs.py
@@ -45,15 +45,24 @@ class RootfsPlugin(SourcePlugin):
 
     @classmethod
     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
         'prepares' the partition to be incorporated into the image.
         In this case, prepare content for legacy bios boot partition.
         """
-        if part.rootfs:
-            rootfs_dir = part.rootfs 
-        
+        if part.rootfs is None:
+            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.prepare_rootfs(cr_workdir, oe_builddir, rootfs_dir, native_sysroot)
 
diff --git a/scripts/wic b/scripts/wic
index 824acae..5a89b08 100755
--- a/scripts/wic
+++ b/scripts/wic
@@ -45,6 +45,30 @@ sys.path = sys.path + [lib_path]
 from image.help 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):
     """
@@ -60,7 +84,8 @@ def wic_create_subcommand(args, usage_str):
     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")
     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",
                       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",
@@ -125,7 +150,7 @@ def wic_create_subcommand(args, usage_str):
         image_output_dir = options.outdir
 
     if not options.image_name:
-        rootfs_dir = options.rootfs_dir
+        rootfs_dir = options.rootfs_dir['ROOTFS_DIR']
         bootimg_dir = options.bootimg_dir
         kernel_dir = options.kernel_dir
         native_sysroot = options.native_sysroot
@@ -162,6 +187,13 @@ def wic_create_subcommand(args, usage_str):
                 (not_found, not_found_dir)
             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,
                native_sysroot, hdddir, staging_data_dir, scripts_path,
                image_output_dir, options.debug, options.properties_file)
-- 
1.8.3.2



  parent reply	other threads:[~2014-03-27 22:08 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-15 21:17 [PATCH 0/5] wic: Add --rootfs option to --source param João Henrique Ferreira de Freitas
2014-03-15 21:17 ` [PATCH 1/5] wic: Add RootfsPlugin João Henrique Ferreira de Freitas
2014-03-15 21:17 ` [PATCH 2/5] wic: Hook up RootfsPlugin plugin João Henrique Ferreira de Freitas
2014-03-15 21:17 ` [PATCH 3/5] wic: Add rootfs_dir argument to do_prepare_partition() method João Henrique Ferreira de Freitas
2014-03-15 21:17 ` [PATCH 4/5] wic: Use partition label to be part of rootfs filename João Henrique Ferreira de Freitas
2014-03-15 21:17 ` [PATCH 5/5] wic: Add option --rootfs to --source João Henrique Ferreira de Freitas
2014-03-17 14:53 ` [PATCH 0/5] wic: Add --rootfs option to --source param Otavio Salvador
2014-03-17 15:47   ` João Henrique Freitas
2014-03-17 16:11     ` Otavio Salvador
2014-03-17 16:20       ` João Henrique Freitas
2014-03-31  1:52       ` João Henrique Ferreira de Freitas
2014-03-31 14:39         ` Tom Zanussi
2014-03-31 16:29           ` João Henrique Freitas
2014-03-21 15:54 ` Tom Zanussi
2014-03-23  2:25   ` João Henrique Ferreira de Freitas
2014-03-24 20:13     ` Tom Zanussi
2014-03-25  2:28       ` João Henrique Ferreira de Freitas
2014-03-26  2:42 ` [PATCH v2 0/7] " João Henrique Ferreira de Freitas
2014-03-26  2:42   ` [PATCH v2 1/7] wic: Add RootfsPlugin João Henrique Ferreira de Freitas
2014-03-26  2:42   ` [PATCH v2 2/7] wic: Hook up RootfsPlugin plugin João Henrique Ferreira de Freitas
2014-03-26  2:42   ` [PATCH v2 3/7] wic: Add rootfs_dir argument to do_prepare_partition() method João Henrique Ferreira de Freitas
2014-03-26  2:42   ` [PATCH v2 4/7] wic: Use partition label to be part of rootfs filename João Henrique Ferreira de Freitas
2014-03-26  2:42   ` [PATCH v2 5/7] wic: Add option --rootfs-dir to --source João Henrique Ferreira de Freitas
2014-03-26  2:42   ` [PATCH v2 6/7] wic: Report all ROOTFS_DIR artifacts João Henrique Ferreira de Freitas
2014-03-26  2:42   ` [PATCH v2 7/7] wic: Extend --rootfs-dir to connect rootfs-dirs João Henrique Ferreira de Freitas
2014-03-27 20:15   ` [PATCH v2 0/7] wic: Add --rootfs option to --source param Tom Zanussi
2014-03-27 22:12     ` João Henrique Ferreira de Freitas
2014-03-27 22:07 ` [PATCH v3 " João Henrique Ferreira de Freitas
2014-03-27 22:07   ` [PATCH v3 1/7] wic: Add RootfsPlugin João Henrique Ferreira de Freitas
2014-03-27 22:07   ` [PATCH v3 2/7] wic: Hook up RootfsPlugin plugin João Henrique Ferreira de Freitas
2014-03-27 22:07   ` [PATCH v3 3/7] wic: Add rootfs_dir argument to do_prepare_partition() method João Henrique Ferreira de Freitas
2014-03-27 22:07   ` [PATCH v3 4/7] wic: Use partition label to be part of rootfs filename João Henrique Ferreira de Freitas
2014-03-27 22:07   ` [PATCH v3 5/7] wic: Add option --rootfs-dir to --source João Henrique Ferreira de Freitas
2014-03-27 22:07   ` [PATCH v3 6/7] wic: Report all ROOTFS_DIR artifacts João Henrique Ferreira de Freitas
2014-03-27 22:07   ` João Henrique Ferreira de Freitas [this message]
2014-03-28 21:38   ` [PATCH v3 0/7] wic: Add --rootfs option to --source param Tom Zanussi
2014-03-29  3:24     ` João Henrique Ferreira de Freitas
2014-03-29 19:04       ` Tom Zanussi
2014-03-29  3:12 ` [PATCH v4 " João Henrique Ferreira de Freitas
2014-03-29  3:12   ` [PATCH v4 1/7] wic: Add RootfsPlugin João Henrique Ferreira de Freitas
2014-03-29  3:12   ` [PATCH v4 2/7] wic: Hook up RootfsPlugin plugin João Henrique Ferreira de Freitas
2014-03-29  3:12   ` [PATCH v4 3/7] wic: Add rootfs_dir argument to do_prepare_partition() method João Henrique Ferreira de Freitas
2014-03-29  3:12   ` [PATCH v4 4/7] wic: Use partition label to be part of rootfs filename João Henrique Ferreira de Freitas
2014-03-29  3:12   ` [PATCH v4 5/7] wic: Add option --rootfs-dir to --source João Henrique Ferreira de Freitas
2014-03-29  3:12   ` [PATCH v4 6/7] wic: Report all ROOTFS_DIR artifacts João Henrique Ferreira de Freitas
2014-03-29  3:12   ` [PATCH v4 7/7] wic: Extend --rootfs-dir to connect rootfs-dirs João Henrique Ferreira de Freitas
2014-03-29 19:09   ` [PATCH v4 0/7] wic: Add --rootfs option to --source param Tom Zanussi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1395958078-5191-8-git-send-email-joaohf@gmail.com \
    --to=joaohf@gmail.com \
    --cc=openembedded-core@lists.openembedded.org \
    --cc=tom.zanussi@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox