Skip to contentSkip to conversation

wic: Implement --build-rootfs command line option

PATCH In review Ed Bartosh 2 participants 5 messages Apr 7, 2015 – Apr 10, 2015

lore
Share & tools
lore

Ed Bartosh

author
#0 lore raw

PATCH 1/1 wic: Implement --build-rootfs command line option

-f/--build-rootfs option makes wic to run bitbake <image> to produce rootfs. This option requires image name to be specified with -e/--image-name.

---
 scripts/lib/image/help.py | 10 ++++++----
 scripts/wic               | 25 ++++++++++++++++++++++---
 2 files changed, 28 insertions(+), 7 deletions(-)
scripts/lib/image/help.py +6 -4
index e1eb265..e365a07 100644
@@ -111,7 +111,7 @@ wic_create_usage = """
             [-i <JSON PROPERTY FILE> | --infile <JSON PROPERTY_FILE>]
             [-e | --image-name] [-s, --skip-build-check] [-D, --debug]
             [-r, --rootfs-dir] [-b, --bootimg-dir]
-            [-k, --kernel-dir] [-n, --native-sysroot]
+            [-k, --kernel-dir] [-n, --native-sysroot] [-f, --build-rootfs]
 
  This command creates an OpenEmbedded image based on the 'OE kickstart
  commands' found in the <wks file>.
@@ -132,7 +132,7 @@ SYNOPSIS
         [-i <JSON PROPERTY FILE> | --infile <JSON PROPERTY_FILE>]
         [-e | --image-name] [-s, --skip-build-check] [-D, --debug]
         [-r, --rootfs-dir] [-b, --bootimg-dir]
-        [-k, --kernel-dir] [-n, --native-sysroot]
+        [-k, --kernel-dir] [-n, --native-sysroot] [-f, --build-rootfs]
 
 DESCRIPTION
     This command creates an OpenEmbedded image based on the 'OE
@@ -167,6 +167,8 @@ DESCRIPTION
     The -n option is used to specify the path to the native sysroot
     containing the tools to use to build the image.
 
+    The -f option is used to build rootfs by running "bitbake <image>"
+
     The -s option is used to skip the build check.  The build check is
     a simple sanity check used to determine whether the user has
     sourced the build environment so that the -e option can operate
@@ -528,8 +530,8 @@ DESCRIPTION
        usage: wic create <wks file or image name> [-o <DIRNAME> | ...]
             [-i <JSON PROPERTY FILE> | --infile <JSON PROPERTY_FILE>]
             [-e | --image-name] [-s, --skip-build-check] [-D, --debug]
-            [-r, --rootfs-dir] [-b, --bootimg-dir]
-            [-k, --kernel-dir] [-n, --native-sysroot]
+            [-r, --rootfs-dir] [-b, --bootimg-dir] [-k, --kernel-dir]
+            [-n, --native-sysroot] [-f, --build-rootfs]
 
        This command creates an OpenEmbedded image based on the 'OE
        kickstart commands' found in the <wks file>.
scripts/wic +22 -3
index e7df60f..feff302 100755
@@ -40,11 +40,15 @@ import logging
 # External modules
 scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
 lib_path = scripts_path + '/lib'
-sys.path = sys.path + [lib_path]
+bitbake_path = os.path.join(scripts_path, '../bitbake/lib')
+sys.path = sys.path + [lib_path, bitbake_path]
 
 from image.help import *
 from image.engine import *
 
+from bb import cookerdata
+from bb.main import bitbake_main, BitBakeConfigParameters
+
 def rootfs_dir_to_args(krootfs_dir):
     """
     Get a rootfs_dir dict and serialize to string
@@ -94,6 +98,7 @@ def wic_create_subcommand(args, usage_str):
                       action = "store", help = "path to the native sysroot containing the tools to use to build the image")
     parser.add_option("-p", "--skip-build-check", dest = "build_check",
                       action = "store_false", default = True, help = "skip the build check")
+    parser.add_option("-f", "--build-rootfs", action="store_true", help = "build rootfs")
     parser.add_option("-D", "--debug", dest = "debug", action = "store_true",
                       default = False, help = "output debug information")
 
@@ -123,8 +128,6 @@ def wic_create_subcommand(args, usage_str):
         else:
             print "Done.\n"
 
-    print "Creating image(s)...\n"
-
     bitbake_env_lines = find_bitbake_env_lines(options.image_name)
     if not bitbake_env_lines:
         print "Couldn't get bitbake environment, exiting."
@@ -134,9 +137,24 @@ def wic_create_subcommand(args, usage_str):
     bootimg_dir = ""
 
     if options.image_name:
+        if options.build_rootfs:
+            argv = ["bitbake", options.image_name]
+            if options.debug:
+                argv.append("--debug")
+
+            print "Building rootfs...\n"
+            if bitbake_main(BitBakeConfigParameters(argv),
+                            cookerdata.CookerConfiguration()):
+                sys.exit(1)
+
         (rootfs_dir, kernel_dir, bootimg_dir, native_sysroot) \
             = find_artifacts(options.image_name)
 
+    else:
+        if options.build_rootfs:
+            print "Image name is not specified, exiting. (Use -e/--image-name to specify it)\n"
+            sys.exit(1)
+
     wks_file = args[0]
 
     if not wks_file.endswith(".wks"):
@@ -194,6 +212,7 @@ def wic_create_subcommand(args, usage_str):
 
     rootfs_dir = rootfs_dir_to_args(krootfs_dir)
 
+    print "Creating image(s)...\n"
     wic_create(args, wks_file, rootfs_dir, bootimg_dir, kernel_dir,
                native_sysroot, scripts_path, image_output_dir,
                options.debug, options.properties_file)
Signature · 1 line
2.1.4
#1 lore raw

Hi Ed,

I liked.

Two points:

- How about if user sets INHERIT = "rm_work"? I mean the image recipe will be rm, right? I always put my images in RM_WORK_EXCLUDE so wic can use it.

- What will be the behavior if: wic create test-image-4Gb -e test-image --rootfs rootfs1=test-image --rootfs rootfs2=bringup-image -f. A believed that only 'test-image' will be build. Right?

Thanks.

Quoted 123 lines · Ed Bartosh

-f/--build-rootfs option makes wic to run bitbake <image> to produce rootfs. This option requires image name to be specified with -e/--image-name.

---
  scripts/lib/image/help.py | 10 ++++++----
  scripts/wic               | 25 ++++++++++++++++++++++---
  2 files changed, 28 insertions(+), 7 deletions(-)
scripts/lib/image/help.py +6 -4
index e1eb265..e365a07 100644
@@ -111,7 +111,7 @@ wic_create_usage = """
              [-i <JSON PROPERTY FILE> | --infile <JSON PROPERTY_FILE>]
              [-e | --image-name] [-s, --skip-build-check] [-D, --debug]
              [-r, --rootfs-dir] [-b, --bootimg-dir]
-            [-k, --kernel-dir] [-n, --native-sysroot]
+            [-k, --kernel-dir] [-n, --native-sysroot] [-f, --build-rootfs]
 
   This command creates an OpenEmbedded image based on the 'OE kickstart
   commands' found in the <wks file>.
@@ -132,7 +132,7 @@ SYNOPSIS
          [-i <JSON PROPERTY FILE> | --infile <JSON PROPERTY_FILE>]
          [-e | --image-name] [-s, --skip-build-check] [-D, --debug]
          [-r, --rootfs-dir] [-b, --bootimg-dir]
-        [-k, --kernel-dir] [-n, --native-sysroot]
+        [-k, --kernel-dir] [-n, --native-sysroot] [-f, --build-rootfs]
 
  DESCRIPTION
      This command creates an OpenEmbedded image based on the 'OE
@@ -167,6 +167,8 @@ DESCRIPTION
      The -n option is used to specify the path to the native sysroot
      containing the tools to use to build the image.
 
+    The -f option is used to build rootfs by running "bitbake <image>"
+
      The -s option is used to skip the build check.  The build check is
      a simple sanity check used to determine whether the user has
      sourced the build environment so that the -e option can operate
@@ -528,8 +530,8 @@ DESCRIPTION
         usage: wic create <wks file or image name> [-o <DIRNAME> | ...]
              [-i <JSON PROPERTY FILE> | --infile <JSON PROPERTY_FILE>]
              [-e | --image-name] [-s, --skip-build-check] [-D, --debug]
-            [-r, --rootfs-dir] [-b, --bootimg-dir]
-            [-k, --kernel-dir] [-n, --native-sysroot]
+            [-r, --rootfs-dir] [-b, --bootimg-dir] [-k, --kernel-dir]
+            [-n, --native-sysroot] [-f, --build-rootfs]
 
         This command creates an OpenEmbedded image based on the 'OE
         kickstart commands' found in the <wks file>.
scripts/wic +22 -3
index e7df60f..feff302 100755
@@ -40,11 +40,15 @@ import logging
  # External modules
  scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
  lib_path = scripts_path + '/lib'
-sys.path = sys.path + [lib_path]
+bitbake_path = os.path.join(scripts_path, '../bitbake/lib')
+sys.path = sys.path + [lib_path, bitbake_path]
 
  from image.help import *
  from image.engine import *
 
+from bb import cookerdata
+from bb.main import bitbake_main, BitBakeConfigParameters
+
  def rootfs_dir_to_args(krootfs_dir):
      """
      Get a rootfs_dir dict and serialize to string
@@ -94,6 +98,7 @@ def wic_create_subcommand(args, usage_str):
                        action = "store", help = "path to the native sysroot containing the tools to use to build the image")
      parser.add_option("-p", "--skip-build-check", dest = "build_check",
                        action = "store_false", default = True, help = "skip the build check")
+    parser.add_option("-f", "--build-rootfs", action="store_true", help = "build rootfs")
      parser.add_option("-D", "--debug", dest = "debug", action = "store_true",
                        default = False, help = "output debug information")
 
@@ -123,8 +128,6 @@ def wic_create_subcommand(args, usage_str):
          else:
              print "Done.\n"
 
-    print "Creating image(s)...\n"
-
      bitbake_env_lines = find_bitbake_env_lines(options.image_name)
      if not bitbake_env_lines:
          print "Couldn't get bitbake environment, exiting."
@@ -134,9 +137,24 @@ def wic_create_subcommand(args, usage_str):
      bootimg_dir = ""
 
      if options.image_name:
+        if options.build_rootfs:
+            argv = ["bitbake", options.image_name]
+            if options.debug:
+                argv.append("--debug")
+
+            print "Building rootfs...\n"
+            if bitbake_main(BitBakeConfigParameters(argv),
+                            cookerdata.CookerConfiguration()):
+                sys.exit(1)
+
          (rootfs_dir, kernel_dir, bootimg_dir, native_sysroot) \
              = find_artifacts(options.image_name)
 
+    else:
+        if options.build_rootfs:
+            print "Image name is not specified, exiting. (Use -e/--image-name to specify it)\n"
+            sys.exit(1)
+
      wks_file = args[0]
 
      if not wks_file.endswith(".wks"):
@@ -194,6 +212,7 @@ def wic_create_subcommand(args, usage_str):
 
      rootfs_dir = rootfs_dir_to_args(krootfs_dir)
 
+    print "Creating image(s)...\n"
      wic_create(args, wks_file, rootfs_dir, bootimg_dir, kernel_dir,
                 native_sysroot, scripts_path, image_output_dir,
                 options.debug, options.properties_file)
author
#2 lore raw
Quoted 11 lines · João Henrique Ferreira de Freitas

Hi Ed,

I liked.

Two points:

- How about if user sets INHERIT = "rm_work"? I mean the image recipe will be rm, right? I always put my images in RM_WORK_EXCLUDE so wic can use it.

rm_work removes artifacts required by wic. Wic will complain that rootfs
can't be found. There is a bug about i https://bugzilla.yoctoproject.org/show_bug.cgi?id=7042
I closed it as not a bug as wic uses build artifacts by design.

Quoted 5 lines

- What will be the behavior if: wic create test-image-4Gb -e test-image --rootfs rootfs1=test-image --rootfs rootfs2=bringup-image -f. A believed that only 'test-image' will be build. Right?

I don't fully understand command line options in your example, but generally you're right. wic will take image name from -e option and run "bitbake test-image" in this case.

Regards,
Ed

#3 lore raw

Hi

Quoted 7 lines · Ed Bartosh
Quoted 6 lines · João Henrique Ferreira de Freitas

Hi Ed,

I liked.

Two points:

Quoted 7 lines
Quoted 4 lines

- How about if user sets INHERIT = "rm_work"? I mean the image recipe will be rm, right? I always put my images in RM_WORK_EXCLUDE so wic can use it.

rm_work removes artifacts required by wic. Wic will complain that rootfs
can't be found. There is a bug about i https://bugzilla.yoctoproject.org/show_bug.cgi?id=7042
I closed it as not a bug as wic uses build artifacts by design.

I agree.

Quoted 7 lines
Quoted 5 lines

- What will be the behavior if: wic create test-image-4Gb -e test-image --rootfs rootfs1=test-image --rootfs rootfs2=bringup-image -f. A believed that only 'test-image' will be build. Right?

I don't fully understand command line options in your example, but generally you're right. wic will take image name from -e option and run "bitbake test-image" in this case.

This thread explain the above command line options: http://lists.openembedded.org/pipermail/openembedded-core/2014-March/091185.html

Usually I run this sequence:

bitbake test-image
bitbate bringup-image

wic create test-image-4Gb -e test-image --rootfs rootfs1=test-image --rootfs rootfs2=bringup-image

So wic will create a directdisk with two images where each one will be place on specific partition.

I guess if '-f' is used, wic could call bitbake to 'test-image' and 'bringup-image'.

Thanks.

author
#4 lore raw
Quoted 16 lines · João Henrique Ferreira de Freitas
Quoted 8 lines
Quoted 6 lines

- What will be the behavior if: wic create test-image-4Gb -e test-image --rootfs rootfs1=test-image --rootfs rootfs2=bringup-image -f. A believed that only 'test-image' will be build. Right?

I don't fully understand command line options in your example, but generally you're right. wic will take image name from -e option and run "bitbake test-image" in this case.

This thread explain the above command line options: http://lists.openembedded.org/pipermail/openembedded-core/2014-March/091185.html

Usually I run this sequence:

bitbake test-image
bitbate bringup-image

Quoted 7 lines

wic create test-image-4Gb -e test-image --rootfs rootfs1=test-image --rootfs rootfs2=bringup-image

So wic will create a directdisk with two images where each one will be place on specific partition.

I guess if '-f' is used, wic could call bitbake to 'test-image' and 'bringup-image'.

Thank you for explanations. I missed your patches somehow.

Can we do the same by implementing handling of multiple -e/--image-name options in command line and .wks? e.g. wic create directdisk-multi-rootfs.wks -e core-image-minimal -e core-image-minimal-dev

directdisk-multi-rootfs.wks:
part / --image-name core-image-minimal --ondisk sda --fstype=ext3 --label primary --align 1024 part /standby --image-name core-image-minimal-dev --ondisk sda --fstype=ext3 --label secondary --align 1024

--
Regards,
Ed