Merge "securemsm: Add support for Bazel/Kleaf"

This commit is contained in:
qctecmdr
2023-02-17 09:43:39 -08:00
gecommit door Gerrit - the friendly Code Review server
bovenliggende ef1d604ba1 3c9e16a3e9
commit 05197c5c16
5 gewijzigde bestanden met toevoegingen van 233 en 2 verwijderingen

31
BUILD.bazel Normal file
Bestand weergeven

@@ -0,0 +1,31 @@
package(
default_visibility = [
"//visibility:public",
],
)
load("//build/kernel/kleaf:kernel.bzl", "ddk_headers")
ddk_headers(
name = "smcinvoke_kernel_headers",
hdrs = [
"include/linux/smcinvoke*.h",
"include/linux/IClientE*.h",
"linux/misc/qseecom_kernel.h",
"linux/misc/qseecom_priv.h"
],
includes = ["include/linux", "linux"]
)
ddk_headers(
name = "securemsm_kernel_headers",
hdrs = [
"linux/misc/qseecom_kernel.h",
"linux/misc/qseecom_priv.h"
],
includes = ["linux"]
)
load("pineapple.bzl", "define_pineapple")
define_pineapple()

12
pineapple.bzl Normal file
Bestand weergeven

@@ -0,0 +1,12 @@
load(":securemsm_kernel.bzl", "define_consolidate_gki_modules")
def define_pineapple():
define_consolidate_gki_modules(
target = "pineapple",
modules = [
"smcinvoke_dlkm",
"tz_log_dlkm",
],
extra_options = [
"CONFIG_QCOM_SMCINVOKE"]
)

106
securemsm_kernel.bzl Normal file
Bestand weergeven

@@ -0,0 +1,106 @@
load("//build/kernel/kleaf:kernel.bzl", "kernel_modules_install",
"ddk_module")
load(":securemsm_modules.bzl", "securemsm_modules",
"securemsm_modules_by_config")
load("//build/bazel_common_rules/dist:dist.bzl", "copy_to_dist_dir")
def _replace_formatting_codes(target, variant, s):
kernel_build = "{}_{}".format(target, variant)
return s.replace("%b", kernel_build).replace("%t", target)
def _console_print(target, variant, module, message):
if module:
print('{}: {}: securemsm-kernel: {}: {}'.format(target, variant, module, message))
else:
print('{}: {}: securemsm-kernel: {} '.format(target, variant, message))
def _get_options(target, variant, target_config_option, modules, extra_options):
all_options = {option: True for option in extra_options}
redundant_options = []
for option in securemsm_modules_by_config:
module_name = securemsm_modules_by_config[option]
if option in all_options:
if module_name in modules:
redundant_options.append(option)
else:
_console_print(target, variant, None, 'WARNING: Config option "{}" corresponds to securemsm module {}, but this module is not listed in module list!'.format(option, module_name))
else:
all_options[option] = True
if target_config_option in all_options:
redundant_options.append(target_config_option)
else:
all_options[target_config_option] = True
if redundant_options:
_console_print(target, variant, None, 'INFO: The following options are already declared either by a module or the target, no need to redeclare: \n{}'.format('\n'.join(redundant_options)))
return all_options
def _get_module_srcs(target, variant, module, options):
srcs = [] + module["default_srcs"] + module["srcs"]
module_path = "{}/".format(module["path"]) if module["path"] else ""
for option in module["config_srcs"]:
srcs.extend(module["config_srcs"][option].get(option in options, []))
globbed_srcs = native.glob(["{}{}".format(module_path, _replace_formatting_codes(target, variant, src)) for src in srcs])
if not globbed_srcs:
_console_print(target, variant, module["name"], 'WARNING: Module has no sources attached!')
return globbed_srcs
def define_target_variant_modules(target, variant, modules, extra_options = [], config_option = None):
kernel_build_variant = "{}_{}".format(target, variant)
options = _get_options(target, variant, config_option, modules, extra_options)
module_rules = []
target_local_defines = []
modules = [securemsm_modules[module_name] for module_name in modules]
tv = "{}_{}".format(target, variant)
target_local_defines = ["SMCINVOKE_TRACE_INCLUDE_PATH=../../../{}/smcinvoke".format(native.package_name())]
for config in extra_options:
target_local_defines.append(config)
for module in modules:
rule_name = "{}_{}".format(kernel_build_variant, module["name"])
module_srcs = _get_module_srcs(target, variant, module, options)
ddk_module(
name = rule_name,
kernel_build = "//msm-kernel:{}".format(kernel_build_variant),
srcs = module_srcs,
out = "{}.ko".format(module["name"]),
deps = ["//msm-kernel:all_headers"] + [_replace_formatting_codes(target, variant, dep) for dep in module["deps"]],
local_defines = target_local_defines,
copts = module["copts"]
)
module_rules.append(rule_name)
copy_to_dist_dir(
name = "{}_securemsm-kernel_dist".format(kernel_build_variant),
data = module_rules,
dist_dir = "out/target/product/{}/dlkm/lib/modules/".format(target),
flat = True,
wipe_dist_dir = False,
allow_duplicate_filenames = False,
mode_overrides = {"**/*": "644"},
log = "info",
)
kernel_modules_install(
name = "{}_modules_install".format(kernel_build_variant),
kernel_build = "//msm-kernel:{}".format(kernel_build_variant),
kernel_modules = module_rules
)
def define_consolidate_gki_modules(target, modules, extra_options = [], config_option = None):
define_target_variant_modules(target, "consolidate", modules, extra_options, config_option)
define_target_variant_modules(target, "gki", modules, extra_options, config_option)

76
securemsm_modules.bzl Normal file
Bestand weergeven

@@ -0,0 +1,76 @@
SMCINVOKE_PATH = "smcinvoke"
QSEECOM_PATH = "qseecom"
TZLOG_PATH = "tz_log"
# This dictionary holds all the securemsm-kernel modules included by calling register_securemsm_module
securemsm_modules = {}
securemsm_modules_by_config = {}
# Registers securemsm module to kernel build system.
# name: The name of the module. The name of the file generated for this module will be {name}.ko.
# path: The path that will be prepended to all sources listed for this module.
# config_option: If this module is enabled, the config optiont that will get enabled if so. Not all modules have this, and this is an optional parameter.
# config_srcs: A dictionary of sources to be added to the module depending on if a configuration option is enabled or not. The keys to the dictionary are
# the name of the config option, and the value depends If it is a list, it will just be the list of sources to be added to the module if the config option
# is enabled. If the value is another dictionary, then you can specify sources to be added if the config option is DISABLED by having a list under the
# default_srcs: A list of sources to be added to the module regardless of configuration options.
# deps: A list of kernel_module or ddk_module rules that this module depends on.
def register_securemsm_module(name, path = None, config_option = None, default_srcs = [], config_srcs = {}, deps = [], srcs = [], copts = []):
processed_config_srcs = {}
for config_src_name in config_srcs:
config_src = config_srcs[config_src_name]
if type(config_src) == "list":
processed_config_srcs[config_src_name] = { True: config_src }
else:
processed_config_srcs[config_src_name] = config_src
module = {
"name": name,
"path": path,
"default_srcs": default_srcs,
"config_srcs": processed_config_srcs,
"config_option": config_option,
"deps": deps,
"copts": copts,
"srcs": srcs,
}
securemsm_modules[name] = module
if config_option:
securemsm_modules_by_config[config_option] = name
# ------------------------------------ SECUREMSM MODULE DEFINITIONS ---------------------------------
register_securemsm_module(
name = "smcinvoke_dlkm",
path = SMCINVOKE_PATH,
default_srcs = [
"smcinvoke.c",
"smcinvoke_kernel.c",
"trace_smcinvoke.h",
"IQSEEComCompat.h",
"IQSEEComCompatAppLoader.h",
],
deps = [":smcinvoke_kernel_headers"],
)
register_securemsm_module(
name = "qseecom_dlkm",
path = QSEECOM_PATH,
default_srcs = ["qseecom.c",
"ice.h"],
deps = [":securemsm_kernel_headers"],
srcs = ["config/sec-kernel_defconfig_qseecom.h"],
copts = ["-include", "config/sec-kernel_defconfig_qseecom.h"],
)
register_securemsm_module(
name = "tz_log_dlkm",
path = TZLOG_PATH,
default_srcs = ["tz_log.c"],
)

Bestand weergeven

@@ -487,10 +487,16 @@ TRACE_EVENT(smcinvoke_release,
);
#endif /* _TRACE_SMCINVOKE_H */
/*
* Path must be relative to location of 'define_trace.h' header in kernel
* Define path if not defined in bazel file
*/
#ifndef SMCINVOKE_TRACE_INCLUDE_PATH
#define SMCINVOKE_TRACE_INCLUDE_PATH ../../../../vendor/qcom/opensource/securemsm-kernel/smcinvoke
#endif
#undef TRACE_INCLUDE_PATH
#define TRACE_INCLUDE_PATH ../../../../vendor/qcom/opensource/securemsm-kernel/smcinvoke
#define TRACE_INCLUDE_PATH SMCINVOKE_TRACE_INCLUDE_PATH
#undef TRACE_INCLUDE_FILE
#define TRACE_INCLUDE_FILE trace_smcinvoke