Browse Source

bt-kernel: Add support for Bazel build system

- kernel modules can now be built using Bazel/kleaf for pineapple.
- Added macro that makes it easy to register new modules

Change-Id: If19f9663135342bc36f543b1598231d133c1748f
Franklin Abreu Bueno 2 years ago
parent
commit
d261d4757e
3 changed files with 125 additions and 0 deletions
  1. 5 0
      BUILD.bazel
  2. 61 0
      bt_kernel.bzl
  3. 59 0
      bt_modules.bzl

+ 5 - 0
BUILD.bazel

@@ -0,0 +1,5 @@
+load(":bt_kernel.bzl", "define_bt_modules")
+
+targets = ["pineapple"]
+
+define_bt_modules(targets)

+ 61 - 0
bt_kernel.bzl

@@ -0,0 +1,61 @@
+load("//msm-kernel:target_variants.bzl", "get_all_variants")
+load("//build/kernel/kleaf:kernel.bzl", "ddk_module")
+
+load(":bt_modules.bzl", "bt_modules")
+
+def _get_module_srcs(module):
+    """
+    Gets all the module sources, formats them with the path for that module
+    and then groups them together
+    It also includes all the headers within the `include` directory
+    `native.glob()` returns a new list with every file need for the current package
+    """
+    return native.glob(
+        ["{}/{}".format(module.path, src) for src in module.srcs] + ["include/*.h"]
+    )
+
+def _get_module_deps(module, formatter):
+    """
+    Formats the dependent targets with the necessary prefix
+    Args:
+        module: kernel module
+        formatter: function that will replace the format string within `deps`
+    Example:
+        kernel build = "pineapple_gki"
+        dep = "%b_btpower"
+        The formatted string will look as follow
+        formatted_dep = formatter(dep) = "pineapple_gki_btpower"
+    """
+    return [formatter(dep) for dep in module.deps]
+
+def define_target_variant_modules(target, variant, modules):
+    """
+    Generates the ddk_module for each of our kernel modules
+    Args:
+        target: either `pineapple` or `kalama`
+        variant: either `gki` or `consolidate`
+        modules: bt_modules dict defined in `bt_modules.bzl`
+    """
+    kernel_build = "{}_{}".format(target, variant)
+    modules = [modules.get(module_name) for module_name in modules]
+    formatter = lambda s : s.replace("%b", kernel_build)
+
+    for module in modules:
+        rule_name = "{}_{}".format(kernel_build, module.name)
+        module_srcs = _get_module_srcs(module)
+
+        ddk_module(
+            name = rule_name,
+            kernel_build = "//msm-kernel:{}".format(kernel_build),
+            srcs = module_srcs,
+            out = "{}.ko".format(module.name),
+            deps = ["//msm-kernel:all_headers"] + _get_module_deps(module, formatter),
+            includes = ["include"],
+            visibility = ["//visibility:public"],
+        )
+
+def define_bt_modules(targets):
+    for target in targets:
+        for (t, v) in get_all_variants():
+            if t == target:
+                define_target_variant_modules(t, v, bt_modules)

+ 59 - 0
bt_modules.bzl

@@ -0,0 +1,59 @@
+PWR_PATH = "pwr"
+SLIMBUS_PATH = "slimbus"
+FMRTC_PATH = "rtc6226"
+
+# This dictionary holds all the BT modules included in the bt-kernel
+bt_modules = {}
+
+def register_bt_modules(name, path = None, config_opt = None, srcs = {}, deps = []):
+    """
+    Register modules
+    Args:
+        name: Name of the module (which will be used to generate the name of the .ko file)
+        path: Path in which the source files can be found
+        config_opt: Config name used in Kconfig (not needed currently)
+        srcs: source files and local headers
+        deps: a list of dependent targets
+    """
+    module = struct(
+        name = name,
+        path = path,
+        srcs = srcs,
+        config_opt = config_opt,
+        deps =  deps
+    )
+    bt_modules[name] = module
+
+# --- BT Modules ---
+
+register_bt_modules(
+    name = "btpower",
+    path = PWR_PATH,
+    config_opt = "CONFIG_MSM_BT_PWR",
+    srcs = ["btpower.c"]
+)
+
+register_bt_modules(
+    name = "bt_fm_slim",
+    path = SLIMBUS_PATH,
+    config_opt = "CONFIG_BTFM_SLIM",
+    srcs = [
+        "btfm_slim.c",
+        "btfm_slim.h",
+        "btfm_slim_codec.c",
+        "btfm_slim_slave.c",
+        "btfm_slim_slave.h",
+    ],
+    deps = [":%b_btpower"]
+)
+
+register_bt_modules(
+    name = "radio-i2c-rtc6226-qca",
+    path = FMRTC_PATH,
+    config_opt = "CONFIG_I2C_RTC6226_QCA",
+    srcs = [
+        "radio-rtc6226-common.c",
+        "radio-rtc6226-i2c.c",
+        "radio-rtc6226.h",
+    ]
+)