From 5527261cec9017c5bf77166241422a74625beab0 Mon Sep 17 00:00:00 2001 From: Nathan Rossi Date: Wed, 4 Sep 2013 16:44:20 +1000 Subject: linux-machine-config.inc: Refactored useful python functions * Refactored the useful python functions into more generic form and placed them in the 'xilinx-utils.bbclass' which can be inherited for the functions. Signed-off-by: Nathan Rossi --- classes/xilinx-utils.bbclass | 58 +++++++++++++++++++++++++++ recipes-kernel/linux/linux-machine-config.inc | 38 +++--------------- 2 files changed, 64 insertions(+), 32 deletions(-) create mode 100644 classes/xilinx-utils.bbclass diff --git a/classes/xilinx-utils.bbclass b/classes/xilinx-utils.bbclass new file mode 100644 index 00000000..0d007b94 --- /dev/null +++ b/classes/xilinx-utils.bbclass @@ -0,0 +1,58 @@ +# Utility functions for various Xilinx specific recipes + +# Returns a ':' seperated list of expanded '${BBPATH}/$path' +def get_additional_bbpath_filespath(path, d): + board_extrapaths = [] + bbpath = d.getVar("BBPATH", True) or "" + for i in bbpath.split(":"): + board_extrapaths.append(os.path.join(i, path)) + if len(board_extrapaths): + return ":".join(board_extrapaths) + ":" + return "" + +# Add a prefix or suffix to all paths in the list of paths +# e.g. add 'file://' to all paths +def paths_affix(paths, suffix = "", prefix = ""): + if paths: + files=set() + for path in paths.split(): + newpath = path + if suffix and len(suffix) != 0: + newpath = newpath + suffix + if prefix and len(prefix) != 0: + newpath = prefix + newpath + files.add(newpath) + if len(files) != 0: + return ' '.join(files) + return '' + +# Expand all relative paths to absolute based on the WORKDIR location +def expand_workdir_paths(variable, d): + workdir = d.getVar("WORKDIR", True) + variable_value = d.getVar(variable, True) or '' + if variable_value: + files=set() + for path in variable_value.split(): + if workdir: + files.add(os.path.join(workdir, path)) + else: + files.add(path) + if len(files) != 0: + return ' '.join(files) + return '' + +# Returns a space seperated list of all files which match the extension, joined +# with the dir path. +def expand_dir_basepaths_by_extension(variable, dir, extension, d): + variable_value = d.getVar(variable, True) or '' + if variable_value: + files=set() + for path in variable_value.split(): + if os.path.splitext(path)[1] == extension or extension == None: + if dir: + files.add(os.path.join(dir, os.path.basename(path))) + else: + files.add(os.path.basename(path)) + if len(files) != 0: + return ' '.join(files) + return '' diff --git a/recipes-kernel/linux/linux-machine-config.inc b/recipes-kernel/linux/linux-machine-config.inc index f9af2abe..f4e7fa54 100644 --- a/recipes-kernel/linux/linux-machine-config.inc +++ b/recipes-kernel/linux/linux-machine-config.inc @@ -14,47 +14,21 @@ # available) to the FILESEXTRAPATHS. # -# Returns a space seperated list of all '.dts' files which -def get_all_devicetrees(d): - workdir = d.getVar("WORKDIR", True) - machine_devicetree = d.getVar("MACHINE_DEVICETREE", True) or '' - if machine_devicetree: - files=set() - for path in machine_devicetree.split(): - if os.path.splitext(path)[1] == '.dts': - files.add(os.path.join(workdir, "devicetree", os.path.basename(path))) - if len(files) != 0: - return ' '.join(files) - return '' - -# Retuns a ':' seperated list of expanded '${BBPATH}/$path' -def get_additional_bbpath_filespath(path, d): - board_extrapaths = [] - bbpath = d.getVar("BBPATH", True) or "" - for i in bbpath.split(":"): - board_extrapaths.append(os.path.join(i, path)) - if len(board_extrapaths): - return ":".join(board_extrapaths) + ":" - return "" +inherit xilinx-utils # If OOT_KERNEL_DEVICETREE is not set, default to the device tree's provided by # MACHINE_DEVICETREE -OOT_KERNEL_DEVICETREE ?= "${@get_all_devicetrees(d)}" +OOT_KERNEL_DEVICETREE ?= "${@expand_dir_basepaths_by_extension("MACHINE_DEVICETREE", os.path.join(d.getVar("WORKDIR", True), 'devicetree'), '.dts', d)}" # Appends the '/conf/machine/boards' path to FILESEXTRAPATHS for all # layers (using the ${BBPATH}) FILESEXTRAPATHS_append := "${@get_additional_bbpath_filespath('conf/machine/boards', d)}" # Using the MACHINE_DEVICETREE and MACHINE_KCONFIG vars, append them to SRC_URI -python () { - machine_devicetree = d.getVar("MACHINE_DEVICETREE", True) or '' - machine_kconfigs = d.getVar("MACHINE_KCONFIG", True) or '' - sources = set() - for path in (machine_devicetree.split() + machine_kconfigs.split()): - sources.add("file://" + path) - if len(sources) != 0: - d.setVar("SRC_URI_append", " %s " % " ".join(sources)) -} +SRC_URI_append += " \ + ${@paths_affix(d.getVar("MACHINE_DEVICETREE", True) or '', prefix = 'file://')} \ + ${@paths_affix(d.getVar("MACHINE_KCONFIG", True) or '', prefix = 'file://')} \ + " # Copy all device tree's into the same directory. This is due to compatibility # with dtc and the use of DTSI (Device Tree Includes), the version of DTC in -- cgit v1.2.3-54-g00ecf