]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
yocto-kernel: add support for creating recipe-space kernel features
authorTom Zanussi <tom.zanussi@intel.com>
Tue, 12 Mar 2013 03:19:07 +0000 (22:19 -0500)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sun, 17 Mar 2013 23:10:28 +0000 (23:10 +0000)
Add a yocto-kernel command allowing users to create a recipe-space
kernel feature local to a particular BSP.  The new feature is
subsequently available for the normal feature addition and removal
yocto-kernel commands used with features defined in the meta branch of
linux-yocto kernel repos.

(From meta-yocto rev: 13abcd93b9e1591bc45ff5f9eb17b8feb9ac9ae5)

Signed-off-by: Tom Zanussi <tom.zanussi@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
scripts/lib/bsp/help.py
scripts/lib/bsp/kernel.py
scripts/yocto-kernel

index 91de60017ec25a43f59b28f111d26c8209cc7de4..d7c0360a7a49e0f41ec29e62c720e7ef6c649fac 100644 (file)
@@ -388,6 +388,7 @@ yocto_kernel_usage = """
    feature rm        Have a BSP stop using a feature
    features list     List the features available to BSPs
    feature describe  Describe a particular feature
+   feature create    Create a new BSP-local feature
 
  See 'yocto-kernel help COMMAND' for more information on a specific command.
 
@@ -752,6 +753,41 @@ DESCRIPTION
 """
 
 
+yocto_kernel_feature_create_usage = """
+
+ Create a recipe-space kernel feature in a BSP
+
+ usage: yocto-kernel feature create <bsp-name> newfeature.scc \
+        "Feature Description" capabilities [<CONFIG_XXX=x> ...] [<PATCH> ...]
+
+ This command creates a new kernel feature from the bare config
+ options and patches specified on the command-line.
+"""
+
+
+yocto_kernel_feature_create_help = """
+
+NAME
+    yocto-kernel feature create - create a recipe-space kernel feature
+    in a BSP
+
+SYNOPSIS
+    yocto-kernel feature create <bsp-name> newfeature.scc \
+        "Feature Description" capabilities [<CONFIG_XXX=x> ...] [<PATCH> ...]
+
+DESCRIPTION
+    This command creates a new kernel feature from the bare config
+    options and patches specified on the command-line.  The new
+    feature will be created in recipe-space, specifically in either
+    the kernel .bbappend's /files/cfg or /files/features subdirectory,
+    depending on whether or not the feature contains config items only
+    or config items along with patches.  The named feature must end
+    with .scc and must not contain a feature directory to contain the
+    feature (this will be determined automatically), and a feature
+    decription in double-quotes along with a capabilities string
+    (which for the time being can be one of: 'all' or 'board').
+"""
+
 ##
 # yocto-layer help and usage strings
 ##
index ac0b074b5da1272725a199ecb5397bb502866516..ac6861e14b0c32bc2103900b67fd408bb6956401 100644 (file)
@@ -808,7 +808,108 @@ def yocto_kernel_feature_describe(scripts_path, machine, feature):
 
     print desc
 
-    
+
+def check_feature_name(feature_name):
+    """
+    Sanity-check the feature name for create/destroy.  Return False if not OK.
+    """
+    if not feature_name.endswith(".scc"):
+        print "Invalid feature name (must end with .scc) [%s], exiting" % feature_name
+        return False
+
+    if "/" in feature_name:
+        print "Invalid feature name (don't specify directory) [%s], exiting" % feature_name
+        return False
+
+    return True
+
+
+def check_create_input(feature_items):
+    """
+    Sanity-check the create input.  Return False if not OK.
+    """
+    if not check_feature_name(feature_items[0]):
+        return False
+
+    if feature_items[1].endswith(".patch") or feature_items[1].startswith("CONFIG_"):
+        print "Missing description and/or compatibilty [%s], exiting" % feature_items[1]
+        return False
+
+    if feature_items[2].endswith(".patch") or feature_items[2].startswith("CONFIG_"):
+        print "Missing description and/or compatibility [%s], exiting" % feature_items[1]
+        return False
+
+    return True
+
+
+def yocto_kernel_feature_create(scripts_path, machine, feature_items):
+    """
+    Create a recipe-space kernel feature in a BSP.
+    """
+    if not check_create_input(feature_items):
+        sys.exit(1)
+
+    feature = feature_items[0]
+    feature_basename = feature.split(".")[0]
+    feature_description = feature_items[1]
+    feature_compat = feature_items[2]
+
+    patches = []
+    cfg_items = []
+
+    for item in feature_items[3:]:
+        if item.endswith(".patch"):
+            patches.append(item)
+        elif item.startswith("CONFIG"):
+            if ("=y" in item or "=m" in item):
+                cfg_items.append(item)
+        else:
+            print "Invalid feature item (must be .patch or CONFIG_*) [%s], exiting" % item
+            sys.exit(1)
+
+    feature_dirname = "cfg"
+    if patches:
+        feature_dirname = "features"
+
+    filesdir = find_filesdir(scripts_path, machine)
+    if not filesdir:
+        print "Couldn't add feature (%s), no 'files' dir found" % feature
+        sys.exit(1)
+
+    featdir = os.path.join(filesdir, feature_dirname)
+    if not os.path.exists(featdir):
+        os.mkdir(featdir)
+
+    for patch in patches:
+        if not os.path.isfile(patch):
+            print "Couldn't find patch (%s), exiting" % patch
+            sys.exit(1)
+        basename = os.path.basename(patch)
+        featdir_patch = os.path.join(featdir, basename)
+        shutil.copyfile(patch, featdir_patch)
+
+    new_cfg_filename = os.path.join(featdir, feature_basename + ".cfg")
+    new_cfg_file = open(new_cfg_filename, "w")
+    for cfg_item in cfg_items:
+        new_cfg_file.write(cfg_item + "\n")
+    new_cfg_file.close()
+
+    new_feature_filename = os.path.join(featdir, feature_basename + ".scc")
+    new_feature_file = open(new_feature_filename, "w")
+    new_feature_file.write("define KFEATURE_DESCRIPTION \"" + feature_description + "\"\n")
+    new_feature_file.write("define KFEATURE_COMPATIBILITY " + feature_compat + "\n\n")
+
+    for patch in patches:
+        patch_dir, patch_file = os.path.split(patch)
+        new_feature_file.write("patch " + patch_file + "\n")
+
+    new_feature_file.write("kconf non-hardware " + feature_basename + ".cfg\n")
+    new_feature_file.close()
+
+    print "Added feature:"
+    print "\t%s" % feature_dirname + "/" + feature
+
+
 def base_branches(context):
     """
     Return a list of the base branches found in the kernel git repo.
index 1f6ed67c04b0a0311851ee267e81d617a44f697b..69fe344d8d2d615db9b5d71c934c1a31c676a821 100755 (executable)
@@ -266,6 +266,27 @@ def yocto_kernel_feature_describe_subcommand(args, usage_str):
     yocto_kernel_feature_describe(scripts_path, args[0], args[1])
 
 
+def yocto_kernel_feature_create_subcommand(args, usage_str):
+    """
+    Command-line handling for creating a recipe-space kernel feature
+    in a BSP.  The real work is done by
+    bsp.kernel.yocto_kernel_feature_create().
+    """
+    logging.debug("yocto_kernel_feature_create_subcommand")
+
+    parser = optparse.OptionParser(usage = usage_str)
+
+    (options, args) = parser.parse_args(args)
+
+    if len(args) < 4:
+        logging.error("Wrong number of arguments, exiting\n")
+        parser.print_help()
+        sys.exit(1)
+
+    machine = args.pop(0)
+    yocto_kernel_feature_create(scripts_path, machine, args)
+
+
 subcommands = {
     "config-list": [yocto_kernel_config_list_subcommand,
                     yocto_kernel_config_list_usage,
@@ -300,6 +321,9 @@ subcommands = {
     "feature-describe": [yocto_kernel_feature_describe_subcommand,
                  yocto_kernel_feature_describe_usage,
                  yocto_kernel_feature_describe_help],
+    "feature-create": [yocto_kernel_feature_create_subcommand,
+                 yocto_kernel_feature_create_usage,
+                 yocto_kernel_feature_create_help],
 }