From 5edc7af428cccfbf53780fc98ed1685b655f43d1 Mon Sep 17 00:00:00 2001 From: Tom Zanussi Date: Mon, 11 Mar 2013 22:19:07 -0500 Subject: [PATCH] yocto-kernel: add support for creating recipe-space kernel features 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 Signed-off-by: Richard Purdie --- scripts/lib/bsp/help.py | 36 +++++++++++++ scripts/lib/bsp/kernel.py | 103 +++++++++++++++++++++++++++++++++++++- scripts/yocto-kernel | 24 +++++++++ 3 files changed, 162 insertions(+), 1 deletion(-) diff --git a/scripts/lib/bsp/help.py b/scripts/lib/bsp/help.py index 91de60017e..d7c0360a7a 100644 --- a/scripts/lib/bsp/help.py +++ b/scripts/lib/bsp/help.py @@ -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 newfeature.scc \ + "Feature Description" capabilities [ ...] [ ...] + + 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 newfeature.scc \ + "Feature Description" capabilities [ ...] [ ...] + +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 ## diff --git a/scripts/lib/bsp/kernel.py b/scripts/lib/bsp/kernel.py index ac0b074b5d..ac6861e14b 100644 --- a/scripts/lib/bsp/kernel.py +++ b/scripts/lib/bsp/kernel.py @@ -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. diff --git a/scripts/yocto-kernel b/scripts/yocto-kernel index 1f6ed67c04..69fe344d8d 100755 --- a/scripts/yocto-kernel +++ b/scripts/yocto-kernel @@ -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], }