securemsm_kernel.bzl 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. load("//build/kernel/kleaf:kernel.bzl", "kernel_modules_install",
  2. "ddk_module")
  3. load(":securemsm_modules.bzl", "securemsm_modules",
  4. "securemsm_modules_by_config")
  5. load("//build/bazel_common_rules/dist:dist.bzl", "copy_to_dist_dir")
  6. def _replace_formatting_codes(target, variant, s):
  7. kernel_build = "{}_{}".format(target, variant)
  8. return s.replace("%b", kernel_build).replace("%t", target)
  9. def _console_print(target, variant, module, message):
  10. if module:
  11. print('{}: {}: securemsm-kernel: {}: {}'.format(target, variant, module, message))
  12. else:
  13. print('{}: {}: securemsm-kernel: {} '.format(target, variant, message))
  14. def _get_options(target, variant, target_config_option, modules, extra_options):
  15. all_options = {option: True for option in extra_options}
  16. redundant_options = []
  17. for option in securemsm_modules_by_config:
  18. module_name = securemsm_modules_by_config[option]
  19. if option in all_options:
  20. if module_name in modules:
  21. redundant_options.append(option)
  22. else:
  23. _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))
  24. else:
  25. all_options[option] = True
  26. if target_config_option in all_options:
  27. redundant_options.append(target_config_option)
  28. else:
  29. all_options[target_config_option] = True
  30. if redundant_options:
  31. _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)))
  32. return all_options
  33. def _get_module_srcs(target, variant, module, options):
  34. srcs = [] + module["default_srcs"] + module["srcs"]
  35. module_path = "{}/".format(module["path"]) if module["path"] else ""
  36. for option in module["config_srcs"]:
  37. srcs.extend(module["config_srcs"][option].get(option in options, []))
  38. globbed_srcs = native.glob(["{}{}".format(module_path, _replace_formatting_codes(target, variant, src)) for src in srcs])
  39. if not globbed_srcs:
  40. _console_print(target, variant, module["name"], 'WARNING: Module has no sources attached!')
  41. return globbed_srcs
  42. def define_target_variant_modules(target, variant, modules, extra_options = [], config_option = None):
  43. kernel_build_variant = "{}_{}".format(target, variant)
  44. options = _get_options(target, variant, config_option, modules, extra_options)
  45. module_rules = []
  46. target_local_defines = []
  47. modules = [securemsm_modules[module_name] for module_name in modules]
  48. tv = "{}_{}".format(target, variant)
  49. target_local_defines = ["SMCINVOKE_TRACE_INCLUDE_PATH=../../../{}/smcinvoke".format(native.package_name())]
  50. for config in extra_options:
  51. target_local_defines.append(config)
  52. for module in modules:
  53. rule_name = "{}_{}".format(kernel_build_variant, module["name"])
  54. module_srcs = _get_module_srcs(target, variant, module, options)
  55. ddk_module(
  56. name = rule_name,
  57. kernel_build = "//msm-kernel:{}".format(kernel_build_variant),
  58. srcs = module_srcs,
  59. out = "{}.ko".format(module["name"]),
  60. deps = ["//msm-kernel:all_headers"] + [_replace_formatting_codes(target, variant, dep) for dep in module["deps"]],
  61. hdrs = module["hdrs"],
  62. local_defines = target_local_defines,
  63. copts = module["copts"]
  64. )
  65. module_rules.append(rule_name)
  66. copy_to_dist_dir(
  67. name = "{}_securemsm-kernel_dist".format(kernel_build_variant),
  68. data = module_rules,
  69. dist_dir = "out/target/product/{}/dlkm/lib/modules/".format(target),
  70. flat = True,
  71. wipe_dist_dir = False,
  72. allow_duplicate_filenames = False,
  73. mode_overrides = {"**/*": "644"},
  74. log = "info",
  75. )
  76. kernel_modules_install(
  77. name = "{}_modules_install".format(kernel_build_variant),
  78. kernel_build = "//msm-kernel:{}".format(kernel_build_variant),
  79. kernel_modules = module_rules
  80. )
  81. def define_consolidate_gki_modules(target, modules, extra_options = [], config_option = None):
  82. define_target_variant_modules(target, "consolidate", modules, extra_options, config_option)
  83. define_target_variant_modules(target, "gki", modules, extra_options, config_option)