All public rules and macros to build the kernel.

android_filegroup

Like filegroup, but applies transitions to Android.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcsSources of the filegroup.List of labelsoptional[]
cpuArchitecture.Stringoptional"arm64"

checkpatch

Run checkpatch.sh at the root of this package.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
checkpatch_plLabel to checkpatch.pl.

This is usually //<common_package>:scripts/checkpatch.pl.
Labelrequired
ignorelistcheckpatch ignorelistLabeloptional"@kleaf//build/kernel/static_analysis:checkpatch_ignorelist"

ddk_config

EXPERIMENTAL. A target that can later be used to configure a ddk_module.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsSee ddk_module.deps.List of labelsoptional[]
defconfigThe defconfig file.LabeloptionalNone
kconfigsThe extra Kconfig files for external modules that use this config.

See Documentation/kbuild/kconfig-language.rst for its format.
List of labelsoptional[]
kernel_buildkernel_build.Labelrequired

ddk_headers

A rule that exports a list of header files to be used in DDK.

Example:

ddk_headers(
   name = "headers",
   hdrs = ["include/module.h", "template.c"],
   includes = ["include"],
)

ddk_headers can be chained; that is, a ddk_headers target can re-export another ddk_headers target. For example:

ddk_headers(
   name = "foo",
   hdrs = ["include_foo/foo.h"],
   includes = ["include_foo"],
)
ddk_headers(
   name = "headers",
   hdrs = [":foo", "include/module.h"],
   includes = ["include"],
)

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
hdrsOne of the following:

- Local header files to be exported. You may also need to set the includes attribute. - Other ddk_headers targets to be re-exported.
List of labelsoptional[]
defconfigsdefconfig files.

Items must already be declared in kconfigs. An item not declared in Kconfig and inherited Kconfig files is silently dropped.

An item declared in kconfigs without a specific value in defconfigs uses default value specified in kconfigs.
List of labelsoptional[]
includesA list of directories, relative to the current package, that are re-exported as include directories.

ddk_module with deps including this target automatically adds the given include directory in the generated Kbuild files.

You still need to add the actual header files to hdrs.
List of stringsoptional[]
kconfigsKconfig files.

See Documentation/kbuild/kconfig-language.rst for its format.

Kconfig is optional for a ddk_module. The final Kconfig known by this module consists of the following:

- Kconfig from kernel_build - Kconfig from dependent modules, if any - Kconfig of this module, if any
List of labelsoptional[]
linux_includesLike includes but specified in LINUXINCLUDES instead.

Setting this attribute allows you to override headers from ${KERNEL_DIR}. See “Order of includes” in ddk_module for details.

Like includes, linux_includes is applied to dependent ddk_modules.
List of stringsoptional[]
textual_hdrsDEPRECATED. Use hdrs instead.

The list of header files to be textually included by sources.

This is the location for declaring header files that cannot be compiled on their own; that is, they always need to be textually included by other source files to build valid code.
List of labelsoptional[]

ddk_headers_archive

An archive of ddk_headers.

The archive includes all headers, as well as a BUILD file that is semantically identical to the original ddk_headers definition.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcs-List of labelsoptional[]

ddk_prebuilt_object

Wraps a <stem>.o file so it can be used in ddk_module.srcs.

An optional .<stem>.o.cmd file may be provided. If not provided, a fake .<stem>.o.cmd is generated.

Example:

ddk_prebuilt_object(
    name = "foo",
    src = "foo.o",
)

ddk_module(
    name = "mymod",
    deps = [":foo"],
    # ...
)

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcThe .o file, e.g. foo.oLabelrequired
cmdThe .cmd file, e.g. .foo.o.cmd. If missing, an empty file is provided.LabeloptionalNone
configIf set, name of the config with the CONFIG_ prefix. The prebuilt object is only linked when the given config matches config_bool_value.Stringoptional""
config_bool_valueIf config is set, and config_bool_value == True, the object is only included if the config is y or m. If config is set and config_bool_value == False, the object is only included if the config is not set.BooleanoptionalFalse

ddk_uapi_headers

A rule that generates a sanitized UAPI header tarball.

Example:

ddk_uapi_headers(
   name = "my_headers",
   srcs = glob(["include/uapi/**/*.h"]),
   out = "my_headers.tar.gz",
   kernel_build = "//common:kernel_aarch64",
)

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcsUAPI headers files which can be sanitized by “make headers_install”List of labelsoptional[]
outName of the output tarballStringrequired
kernel_buildkernel_build.Labelrequired

dependency_graph_drawer

A rule that creates a Graphviz diagram file.

  • Inputs: A json file describing a graph as an adjacency list.

  • Outputs: A dependency_graph.dot file containing the diagram representation.

  • NOTE: For further simplification of the resulting diagram tred utility from the CLI can be used as in the following example:

    tred dependency_graph.dot > simplified.dot
    
  • Example:

    dependency_graph_drawer(
        name = "db845c_dependency_graph",
        adjacency_list = ":db845c_dependencies",
    )
    

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
adjacency_list-Labelrequired
colorfulWhether outgoing edges from every node are colored.BooleanoptionalFalse

dependency_graph_extractor

A rule that extracts a symbol dependency graph from a kernel build and modules.

It works by matching undefined symbols from one module with exported symbols from other.

  • Inputs: It receives a Kernel build target, where the analysis will run (vmlinux + in-tree modules), aditionally a list of external modules can be accepted.

  • Outputs: A dependency_graph.json file describing the graph as an adjacency list.

  • Example:

    dependency_graph_extractor(
        name = "db845c_dependencies",
        kernel_build = ":db845c",
        # kernel_modules = [],
    )
    

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
enable_add_vmlinuxIf True enables kernel_build_add_vmlinux transition.BooleanoptionalTrue
exclude_base_kernel_modulesWhether the analysis should made for only external modules.BooleanoptionalFalse
kernel_build-LabeloptionalNone
kernel_modules-List of labelsoptional[]

dtb_image

Build dtb image.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcsDTB sources to add to the dtb imageList of labelsoptional[]
outName of dtb image.

Default to name if not set
Stringoptional""

dtbo

Build dtbo.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcsList of *.dtbo files used to package the dtbo.img. This corresponds to MKDTIMG_DTBOS in build configs; see example below.

Example: kernel_build( name = “tuna_kernel”, outs = [ “path/to/foo.dtbo”, “path/to/bar.dtbo”, ], ) dtbo( name = “tuna_images”, kernel_build = “:tuna_kernel”, srcs = [ “:tuna_kernel/path/to/foo.dtbo”, “:tuna_kernel/path/to/bar.dtbo”, ], )
List of labelsoptional[]
config_fileA config file to create dtbo image by cfg_create command.

If set, use mkdtimg cfg_create with the given config file, instead of mkdtimg create
LabeloptionalNone
kernel_buildThe kernel_build.Labelrequired

extract_symbols

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcSource abi_gki_* file. Used when kmi_symbol_list_add_only.LabeloptionalNone
enable_add_vmlinuxIf True enables kernel_build_add_vmlinux transition.BooleanoptionalTrue
kernel_build-LabeloptionalNone
kernel_modules-List of labelsoptional[]
kernel_modules_exclude_listBase name list of kernel modules to exclude from.List of stringsoptional[]
kmi_symbol_list_add_only-BooleanoptionalFalse
module_grouping-BooleanoptionalTrue

gki_artifacts

BUILD_GKI_ARTIFACTS. Build boot images and optionally boot-img.tar.gz as default outputs.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
archARCH.Stringrequired
boot_img_sizesA dictionary, with key is the compression algorithm, and value is the size of the boot image.

For example: { "": str(64 * 1024 * 1024), # For Image and boot.img “lz4”: str(64 * 1024 * 1024), # For Image.lz4 and boot-lz4.img }
Dictionary: String -> Stringoptional{}
gki_kernel_cmdlineGKI_KERNEL_CMDLINE.Stringoptional""
kernel_buildThe kernel_build that provides all Image and Image.*.LabeloptionalNone
mkbootimgpath to the mkbootimg.py script; MKBOOTIMG_PATH.Labeloptional"@kleaf//tools/mkbootimg:mkbootimg.py"

gki_artifacts_prebuilts

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcs-List of labelsoptional[]
outs-List of stringsoptional[]

initramfs

Build initramfs.

When included in a pkg_files target included by pkg_install, this rule copies the following to destdir:

  • initramfs.img
  • modules.load
  • modules.load.recovery
  • modules.load.charger
  • vendor_boot.modules.load
  • vendor_boot.modules.load.recovery
  • vendor_boot.modules.load.charger

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsA list of additional dependencies to build initramfs.List of labelsoptional[]
create_modules_orderWhether to create and keep a modules.order file generated by a postorder traversal of the kernel_modules_install sources. It defaults to True.BooleanoptionalTrue
kernel_modules_installThe kernel_modules_install.Labelrequired
modules_blocklistA file containing a list of modules which are blocked from being loaded.

This file is copied directly to staging directory, and should be in the format: blocklist module_name
LabeloptionalNone
modules_charger_listA file containing a list of modules to load when booting intocharger mode.LabeloptionalNone
modules_listA file containing list of modules to use for vendor_boot.modules.load.LabeloptionalNone
modules_optionsa file copied to /lib/modules/<kernel_version>/modules.options on the ramdisk.

Lines in the file should be of the form: options <modulename> <param1>=<val> <param2>=<val> ...
LabeloptionalNone
modules_recovery_listA file containing a list of modules to load when booting into recovery.LabeloptionalNone
ramdisk_compressionIf provided it specfies the format used for any ramdisks generated.If not provided a fallback value from build.config is used.Stringoptional""
ramdisk_compression_argsCommand line arguments passed only to lz4 command to control compression level.Stringoptional""
vendor_boot_nameName of vendor_boot image.

* If "vendor_boot", build vendor_boot.img * If "vendor_kernel_boot", build vendor_kernel_boot.img * If None, skip building vendor_boot.
Stringoptional""

kernel_build_config

Create a build.config file by concatenating build config fragments.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsAdditional build config dependencies.

These include build configs that are indirectly sourced by items in srcs. Unlike srcs, they are not be emitted in the output.
List of labelsoptional[]
srcsList of build config fragments.

Order matters. To prevent buildifier from sorting the list, use the # do not sort magic line. For example:

kernel_build_config( name = “build.config.foo.mixed”, srcs = [ # do not sort “build.config.mixed”, “build.config.foo”, ], )
List of labelsoptional[]

kernel_compile_commands

Define an executable that creates compile_commands.json from kernel targets.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsThe targets to extract from. The following are allowed:

- kernel_build - kernel_module - ddk_module - kernel_module_group
List of labelsoptional[]
kernel_buildThe kernel_build rule to extract from.

Deprecated: Use deps instead.
LabeloptionalNone

kernel_filegroup

EXPERIMENTAL. The API of kernel_filegroup rapidly changes and is not backwards compatible with older builds. The usage of kernel_filegroup is limited to the implementation detail of Kleaf (in particular, define_common_kernels). Do not use kernel_filegroup directly. See download_prebuilt.md for details.

Specify a list of kernel prebuilts.

This is similar to filegroup that gives a convenient name to a collection of targets, which can be referenced from other rules.

It can be used in the base_kernel attribute of a kernel_build.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsA list of additional labels that participates in implementing the providers.

This usually contains a list of prebuilts.

Unlike srcs, these labels are NOT added to the DefaultInfo
List of labelsoptional[]
srcsThe list of labels that are members of this file group.

This usually contains a list of prebuilts, e.g. vmlinux, Image.lz4, kernel-headers.tar.gz, etc.

Not to be confused with kernel_srcs.
List of labelsoptional[]
outsKeys: from _kernel_build.outs. Values: path under $OUT_DIR.Dictionary: Label -> Stringoptional{}
all_module_namesmodule_outs and module_implicit_outs of the original kernel_build target.List of stringsoptional[]
collect_unstripped_modulesSee kernel_build.collect_unstripped_modules.

Unlike kernel_build, this has default value True because kernel_abi sets define_abi_targets to True by default, which in turn sets collect_unstripped_modules to True by default.
BooleanoptionalTrue
config_out_dirDirectory to support kernel_configLabeloptionalNone
config_out_dir_filesFiles in config_out_dirList of labelsoptional[]
ddk_module_defconfig_fragmentsAdditional defconfig fragments for dependant DDK modules.List of labelsoptional[]
ddk_module_headersAdditional ddk_headers for dependant DDK modules.List of labelsoptional[]
env_setup_scriptSetup script from kernel_envLabeloptionalNone
exec_platformExecution platform, where the build is executed.

See https://bazel.build/extending/platforms.
Labelrequired
gki_artifactsA list of files that were built from the gki_artifacts target. The gki-info.txt file should be part of that list.

If kernel_release is set, this attribute has no effect.
LabeloptionalNone
imagesA label providing files similar to a kernel_images target.LabeloptionalNone
internal_outsKeys: from _kernel_build.internal_outs. Values: path under $OUT_DIR.Dictionary: Label -> Stringoptional{}
kernel_releaseA file providing the kernel release string. This is preferred over gki_artifacts.LabeloptionalNone
kernel_uapi_headersThe label pointing to kernel-uapi-headers.tar.gz.

This attribute should be set to the kernel-uapi-headers.tar.gz artifact built by the kernel_build macro if the kernel_filegroup rule were a kernel_build.

Setting this attribute allows merged_kernel_uapi_headers to work properly when this kernel_filegroup is set to the base_kernel.

For example: kernel_filegroup( name = “kernel_aarch64_prebuilts”, srcs = [ “vmlinux”, # ... ], kernel_uapi_headers = “kernel-uapi-headers.tar.gz”, ) kernel_build( name = “tuna”, base_kernel = “:kernel_aarch64_prebuilts”, # ... ) merged_kernel_uapi_headers( name = “tuna_merged_kernel_uapi_headers”, kernel_build = “tuna”, # ... )
LabeloptionalNone
module_env_archiveArchive from kernel_build.pack_module_env that contains necessary files to build external modules.LabeloptionalNone
modules_prepare_archiveArchive from modules_prepareLabeloptionalNone
protected_modules_list-LabeloptionalNone
strip_modulesSee kernel_build.strip_modules.BooleanoptionalFalse
target_platformTarget platform that describes characteristics of the target device.

See https://bazel.build/extending/platforms.
Labelrequired

kernel_kythe

Extract Kythe source code index (kzip file) from a kernel_build.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
corpusA flag containing value of KYTHE_CORPUS. See kythe.io/examples.Labelrequired
kernel_buildThe kernel_build target to extract from.Labelrequired

kernel_module_group

Like filegroup but for kernel_modules or ddk_modules.

Unlike filegroup, srcs must not be empty.

Example:

# //package/my_subsystem

# Hide a.ko and b.ko because they are implementation details of my_subsystem
ddk_module(
    name = "a",
    visibility = ["//visibility:private"],
    ...
)

ddk_module(
    name = "b",
    visibility = ["//visibility:private"],
    ...
)

# my_subsystem is the public target that the device should depend on.
kernel_module_group(
    name = "my_subsystem",
    srcs = [":a", ":b"],
    visibility = ["//package/my_device:__subpackages__"],
)

# //package/my_device
kernel_modules_install(
    name = "my_device_modules_install",
    kernel_modules = [
        "//package/my_subsystem:my_subsystem", # This is equivalent to specifying a and b.
    ],
)

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcsList of kernel_modules or ddk_modules.List of labelsrequired

kernel_modules_install

Generates a rule that runs depmod in the module installation directory.

When including this rule to the srcs attribute of a pkg_files rule that is included in a pkg_install rule, all external kernel modules specified in kernel_modules are included in distribution. This excludes module_outs in kernel_build to avoid conflicts.

Example:

kernel_modules_install(
    name = "foo_modules_install",
    kernel_modules = [               # kernel_module rules
        "//path/to/nfc:nfc_module",
    ],
)
kernel_build(
    name = "foo",
    outs = ["vmlinux"],
    module_outs = ["core_module.ko"],
)
pkg_files(
    name = "foo_dist_files",
    srcs = [
        ":foo",                      # Includes core_module.ko and vmlinux
        ":foo_modules_install",      # Includes nfc_module
    ],
)
pkg_install(
    name = "foo_dist",
    srcs = [":foo_dist_files"],
)

In foo_dist, specifying foo_modules_install in data won't include core_module.ko, because it is already included in foo in data.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
outsA list of additional outputs from make modules_install.

Since external modules are returned by default, it can be used to obtain modules.* related files (results of depmod). Only files with allowed names can be added to outs. (_OUT_ALLOWLIST) _OUT_ALLOWLIST = [“modules.dep”, “modules.alias”, “modules.builtin”, “modules.symbols”, “modules.softdep”] Example: kernel_modules_install( name = “foo_modules_install”, kernel_modules = [“:foo_module_list”], outs = [ “modules.dep”, “modules.alias”, ], )
List of stringsoptional[]
kernel_buildLabel referring to the kernel_build module. Otherwise, it is inferred from kernel_modules.LabeloptionalNone
kernel_modulesA list of labels referring to kernel_modules to install.List of labelsoptional[]

kernel_unstripped_modules_archive

Compress the unstripped modules into a tarball.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
kernel_buildA kernel_build to retrieve unstripped in-tree modules from.

It requires collect_unstripped_modules = True. If the kernel_build has a base_kernel, the rule also retrieves unstripped in-tree modules from the base_kernel, and requires the base_kernel has collect_unstripped_modules = True.
LabeloptionalNone
kernel_modulesA list of external kernel_modules to retrieve unstripped external modules from.

It requires that the base kernel_build has collect_unstripped_modules = True.
List of labelsoptional[]

merge_kzip

Merge .kzip files

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcskzip filesList of labelsoptional[]

merge_module_symvers

Merge Module.symvers files

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcsIt accepts targets from any of the following rules: - ddk_module - kernel_module_group - kernel_build (it requires keep_module_symvers = True to be set).List of labelsoptional[]

merged_kernel_uapi_headers

Merge kernel-uapi-headers.tar.gz.

On certain devices, kernel modules install additional UAPI headers. Use this rule to add these module UAPI headers to the final kernel-uapi-headers.tar.gz.

If there are conflicts of file names in the source tarballs, files higher in the list have higher priority:

  1. UAPI headers from the base_kernel of the kernel_build (ususally the GKI build)
  2. UAPI headers from the kernel_build (usually the device build)
  3. UAPI headers from ``kernel_modules`. Order among the modules are undetermined.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
kernel_buildThe kernel_buildLabelrequired
kernel_modulesA list of external kernel_modules to merge kernel-uapi-headers.tar.gzList of labelsoptional[]

modinfo_summary_report

Generate a report from kernel modules of the given kernel build.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
deps-List of labelsoptional[]

super_image

Build super image.

Optionally takes in a “system_dlkm” and “vendor_dlkm”.

When included in a pkg_files target included by pkg_install, this rule copies super.img to destdir.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
outImage file nameStringoptional"super.img"
super_img_sizeSize of super.imgIntegeroptional268435456
system_dlkm_imagesystem_dlkm_image to include in super.imgLabeloptionalNone
vendor_dlkm_imagevendor_dlkm_image to include in super.imgLabeloptionalNone

system_dlkm_image

Build system_dlkm partition image with signed GKI modules.

When included in a pkg_files target included by pkg_install, this rule copies the following to destdir:

  • system_dlkm.[erofs|ext4].img if fs_types is specified
  • system_dlkm.flatten.[erofs|ext4].img if build_flatten is True
  • system_dlkm.modules.load

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsA list of additional dependencies to build system_dlkm image.List of labelsoptional[]
baseThe system_dlkm_image() corresponding to the base_kernel of the kernel_build. This is required for building a device-specific system_dlkm image. For example, if base_kernel of kernel_build() is //common:kernel_aarch64, then base is //common:kernel_aarch64_system_dlkm_image.LabeloptionalNone
build_flattenWhen True it builds system_dlkm image with no uname -r in the path.BooleanoptionalFalse
fs_typesList of file systems type for system_dlkm images.

Supported filesystems for system_dlkm image are ext4 and erofs. If not specified, build system_dlkm.img with ext4. Otherwise, build system_dlkm.<fs>.img for each file system type in the list.
List of stringsoptional["ext4"]
internal_extra_archive_filesInternal only; subject to change without notice. Extra files to be placed at the root of the archive.List of labelsoptional[]
kernel_modules_installThe kernel_modules_install.Labelrequired
modules_blocklistAn optional file containing a list of modules which are blocked from being loaded.

This file is copied directly to the staging directory and should be in the format: blocklist module_name
LabeloptionalNone
modules_listAn optional file containing the list of kernel modules which shall be copied into a system_dlkm partition image.LabeloptionalNone
propsA text file containing the properties to be used for creation of a system_dlkm image (filesystem, partition size, etc). If this is not set (and build_system_dlkm is), a default set of properties will be used which assumes an ext4 filesystem and a dynamic partition.LabeloptionalNone

unsparsed_image

Build an unsparsed image.

Takes in a .img file and unsparses it.

When included in a pkg_files/pkg_install rule, this rule copies a super_unsparsed.img to destdir.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcimage to unsparseLabeloptionalNone
out-Stringrequired

vendor_boot_image

Build vendor_boot or vendor_kernel_boot image.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsAdditional dependencies to build boot images.List of labelsoptional[]
outsA list of output files that will be installed to DIST_DIR when build_boot_images in build/kernel/build_utils.sh is executed.

Unlike kernel_images, you must specify the list explicitly.
List of stringsoptional[]
dtb_imageA dtb.img to packaged. If this is set, then *.dtb from kernel_build are ignored.

See dtb_image.
LabeloptionalNone
initramfsThe initramfs.LabeloptionalNone
kernel_buildThe kernel_build.Labelrequired
mkbootimgmkbootimg.py script which builds boot.img. Only used if build_boot. If None, default to //tools/mkbootimg:mkbootimg.py. NOTE: This overrides MKBOOTIMG_PATH.Labeloptional"@kleaf//tools/mkbootimg:mkbootimg.py"
ramdisk_compressionIf provided it specfies the format used for any ramdisks generated.If not provided a fallback value from build.config is used.Stringoptional""
ramdisk_compression_argsCommand line arguments passed only to lz4 command to control compression level.Stringoptional""
unpack_ramdiskWhen false it skips unpacking the vendor ramdisk and copy it as is, without modifications, into the boot image. Also skip the mkbootfs step.

Unlike kernel_images(), unpack_ramdisk must be specified explicitly to clarify the intent.
Booleanrequired
vendor_boot_nameName of vendor_boot image.

* If "vendor_boot", build vendor_boot.img * If "vendor_kernel_boot", build vendor_kernel_boot.img
Stringoptional"vendor_boot"
vendor_ramdisk_binariesList of vendor ramdisk binaries which includes the device-specific components of ramdisk like the fstab file and the device-specific rc files. If specifying multiple vendor ramdisks and identical file paths exist in the ramdisks, the file from last ramdisk is used.

Note: order matters. To prevent buildifier from sorting the list, add the following: # do not sort
List of labelsoptional[]
vendor_ramdisk_dev_nodesList of dev nodes description files which describes special device files to be added to the vendor ramdisk. File format is as accepted by mkbootfs.List of labelsoptional[]

vendor_dlkm_image

Build vendor_dlkm image.

Execute build_vendor_dlkm in build_utils.sh.

When included in a pkg_files target included by pkg_install, this rule copies the following to destdir:

  • vendor_dlkm.img
  • vendor_dlkm_flatten.img if build_vendor_dlkm_flatten is True

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsA list of additional dependencies to build system_dlkm image.

This must include the following:

- The file specified by selinux_fc in props, if set
List of labelsoptional[]
archiveWhether to archive the vendor_dlkm modulesBooleanoptionalFalse
base_system_dlkm_imageThe system_dlkm_image() corresponding to the base_kernel of the kernel_build. This is required if dedup_dlkm_modules and not system_dlkm_image. For example, if base_kernel of kernel_build() is //common:kernel_aarch64, then base_system_dlkm_image is //common:kernel_aarch64_system_dlkm_image.LabeloptionalNone
build_flattenWhen True it builds vendor_dlkm image with no uname -r in the pathBooleanoptionalFalse
create_modules_orderWhether to create and keep a modules.order file generated by a postorder traversal of the kernel_modules_install sources. It defaults to True.BooleanoptionalTrue
dedup_dlkm_modulesWhether to exclude system_dlkm modulesBooleanoptionalFalse
etc_filesFiles that need to be copied to vendor_dlkm.img etc/ directory.List of labelsoptional[]
fs_typeFilesystem for vendor_dlkm.img.Stringoptional"ext4"
kernel_modules_installThe kernel_modules_install.Labelrequired
modules_blocklistAn optional file containing a list of modules which are blocked from being loaded.

This file is copied directly to the staging directory and should be in the format: blocklist module_name
LabeloptionalNone
modules_listAn optional file containing the list of kernel modules which shall be copied into a vendor_dlkm partition image. Any modules passed into MODULES_LIST which become part of the vendor_boot.modules.load will be trimmed from the vendor_dlkm.modules.load.LabeloptionalNone
propsA text file containing the properties to be used for creation of a vendor_dlkm image (filesystem, partition size, etc). If this is not set (and build_vendor_dlkm is), a default set of properties will be used which assumes an ext4 filesystem and a dynamic partition.LabeloptionalNone
system_dlkm_image-LabeloptionalNone
vendor_boot_modules_loadFile to vendor_boot.modules.load.

Modules listed in this file is stripped away from the vendor_dlkm image.

As a special case, you may also provide a initramfs target here, in which case the vendor_boot.modules.load of the initramfs is used.
LabeloptionalNone

ddk_library

EXPERIMENTAL. A library that may be used by a DDK module.

The library has its own list of dependencies, flags that are usually local, and not exported to the ddk_module using it. However, hdrs, includes, kconfig and defconfig are exported.

Known issues: - (b/392186874) The generated .o.cmd files contain absolute paths and are not reproducible. - (b/394411899) kernel_compile_commands() doesn't work on ddk_library yet. - (b/395014894) All ddk_module() dependency in ddk_library.deps must be duplicated in the ddk_module() that depends on this ddk_library.

PARAMETERS

NameDescriptionDefault Value
namename of modulenone
kernel_buildkernel_buildnone
srcssee ddk_module.srcsNone
depssee ddk_module.deps. ddk_submodules are not allowed.None
hdrssee ddk_module.hdrsNone
includessee ddk_module.includesNone
linux_includessee ddk_module.linux_includesNone
local_definessee ddk_module.local_definesNone
coptssee ddk_module.coptsNone
removed_coptssee ddk_module.removed_coptsNone
asoptssee ddk_module.asoptsNone
configsee ddk_module.configNone
kconfigsee ddk_module.kconfigNone
defconfigsee ddk_module.defconfigNone
autofdo_profilesee ddk_module.autofdo_profileNone
debug_info_for_profilingsee ddk_module.debug_info_for_profilingNone
pkvm_el2EXPERIMENTAL. If True, builds EL2 hypervisor code.

If True: - The output list is the fixed ["kvm_nvhe.o"], plus relevant .o.cmd files - The generated Makefile is modified to build EL2 hypervisor code.

Note: This is only supported in selected branches.
None
kwargsAdditional attributes to the internal rule. See complete list here.none

ddk_module

Defines a DDK (Driver Development Kit) module.

Example:

ddk_module(
    name = "my_module",
    srcs = ["my_module.c", "private_header.h"],
    out = "my_module.ko",
    # Exported headers
    hdrs = ["include/my_module_exported.h"],
    textual_hdrs = ["my_template.c"],
    includes = ["include"],
)

Note: Local headers should be specified in one of the following ways:

  • In a ddk_headers target in the same package, if you need to auto-generate -I ccflags. In that case, specify the ddk_headers target in deps.
  • Otherwise, in srcs if you don't need the -I ccflags.

Exported headers should be specified in one of the following ways:

  • In a separate ddk_headers target in the same package. Then specify the target in hdrs. This is recommended if there are multiple ddk_modules depending on a glob of headers or a large list of headers.
  • Using hdrs, textual_hdrs and includes of this target.

For details, see build/kernel/kleaf/tests/ddk_examples/README.md.

hdrs, textual_hdrs and includes have the same semantics as ddk_headers. That is, this target effectively acts as a ddk_headers target when specified in the deps attribute of another ddk_module. In other words, the following code snippet:

ddk_module(name = "module_A", hdrs = [...], includes = [...], ...)
ddk_module(name = "module_B", deps = ["module_A"], ...)

... is effectively equivalent to the following:

ddk_headers(name = "module_A_hdrs, hdrs = [...], includes = [...], ...)
ddk_module(name = "module_A", ...)
ddk_module(name = "module_B", deps = ["module_A", "module_A_hdrs"], ...)

Submodules

See ddk_submodule.

If deps contains a ddk_submodule target, the ddk_module target must not specify anything except:

  • kernel_build
  • linux_includes

It is not recommended that a ddk_submodule depends on a ddk_headers target that specifies linux_includes. If a ddk_submodule does depend on a ddk_headers target that specifies linux_includes, all submodules below the same directory (i.e. sharing the same Kbuild file) gets these linux_includes. This is because LINUXINCLUDE is set for the whole Kbuild file, not per compilation unit.

In particular, a ddk_submodule should not depend on //common:all_headers. Instead, the dependency should come from the kernel_build; that is, the kernel_build of the ddk_module, or the base_kernel, should specify ddk_module_headers = "//common:all_headers".

To avoid confusion, the dependency on this ddk_headers target with linux_includes should be moved to the top-level ddk_module. In this case, all submodules of this ddk_module receives the said LINUXINCLUDE from the ddk_headers target.

Example:

# //common
kernel_build(name = "kernel_aarch64", ddk_module_headers = ":all_headers_aarch64")
ddk_headers(
    name = "all_headers_aarch64",
    linux_includes = [
        "arch/arm64/include",
        "arch/arm64/include/uapi",
        "include",
        "include/uapi",
    ],
)
# //device
kernel_build(name = "tuna", base_kernel = "//common:kernel_aarch64")

ddk_headers(name = "uapi", linux_includes = ["uapi/include"])

ddk_module(
    name = "mymodule",
    kernel_build = ":tuna",
    deps = [
        ":mysubmodule"
        # Specify dependency on :uapi in the top level ddk_module
        ":uapi",
    ],
)

ddk_submodule(
    name = "mysubmodule",
    deps = [
        # Not recommended to specify dependency on :uapi since it contains
        # linux_includes

        # No need tp specify dependency on //common:all_headers_aarch64
        # since it comes from :tuna -> //common:kernel_aarch64
    ]
)

Ordering of includes

The best practice is to not have conflicting header names and search paths. But if you do, see below for ordering of include directories to be searched for header files.

A ddk_module is compiled with the following order of include directories (-I options):

  1. Traverse depedencies for linux_includes:
    1. All linux_includes of this target, in the specified order
    2. All linux_includes of deps, in the specified order (recursively apply #1.3 on each target)
    3. All linux_includes of hdrs, in the specified order (recursively apply #1.3 on each target)
    4. All linux_includes from kernel_build:
      1. All linux_includes from ddk_module_headers of the base_kernel of the kernel_build of this ddk_module;
      2. All linux_includes from ddk_module_headers of the kernel_build of this ddk_module;
  2. LINUXINCLUDE (See ${KERNEL_DIR}/Makefile)
  3. Traverse depedencies for includes:
    1. All includes of this target, in the specified order
    2. All includes of deps, in the specified order (recursively apply #3.1 and #3.3 on each target)
    3. All includes of hdrs, in the specified order (recursively apply #3.1 and #3.3 on each target)
    4. All includes from kernel_build:
      1. All includes from ddk_module_headers of the base_kernel of the kernel_build of this ddk_module;
      2. All includes from ddk_module_headers of the kernel_build of this ddk_module;

In other words, #1 and #3 uses the preorder of depset.

“In the specified order” means that order matters within these lists. To prevent buildifier from sorting these lists, use the # do not sort magic line.

To export a target :x in hdrs before other targets in deps (that is, if you need #3.3 before #3.2, or #1.2 before #1.1), specify :x in the deps list in the position you want. See example below.

To export an include directory in includes that needs to be included after other targets in hdrs or deps (that is, if you need #3.1 after #3.2 or #3.3), specify the include directory in a separate ddk_headers target, then specify this ddk_headers target in hdrs and/or deps based on your needs.

For example:

ddk_headers(name = "base_ddk_headers", includes = ["base"], linux_includes = ["uapi/base"])
ddk_headers(name = "device_ddk_headers", includes = ["device"], linux_includes = ["uapi/device"])

kernel_build(
    name = "kernel_aarch64",
    ddk_module_headers = [":base_ddk_headers"],
)
kernel_build(
    name = "device",
    base_kernel = ":kernel_aarch64",
    ddk_module_headers = [":device_ddk_headers"],
)

ddk_headers(name = "dep_a", includes = ["dep_a"], linux_includes = ["uapi/dep_a"])
ddk_headers(name = "dep_b", includes = ["dep_b"])
ddk_headers(name = "dep_c", includes = ["dep_c"], hdrs = ["dep_a"])
ddk_headers(name = "hdrs_a", includes = ["hdrs_a"], linux_includes = ["uapi/hdrs_a"])
ddk_headers(name = "hdrs_b", includes = ["hdrs_b"])
ddk_headers(name = "x", includes = ["x"])

ddk_module(
    name = "module",
    kernel_build = ":device",
    deps = [":dep_b", ":x", ":dep_c"],
    hdrs = [":hdrs_a", ":x", ":hdrs_b"],
    linux_includes = ["uapi/module"],
    includes = ["self_1", "self_2"],
)

Then ":module" is compiled with these flags, in this order:

# 1.1 linux_includes
-Iuapi/module

# 1.2 deps, linux_includes, recursively
-Iuapi/dep_a

# 1.3 hdrs, linux_includes, recursively
-Iuapi/hdrs_a

# 1.4 linux_includes from kernel_build and base_kernel
-Iuapi/device
-Iuapi/base

# 2.
$(LINUXINCLUDE)

# 3.1 includes
-Iself_1
-Iself_2

# 3.2. deps, recursively
-Idep_b
-Ix
-Idep_a   # :dep_c depends on :dep_a, so include dep_a/ first
-Idep_c

# 3.3. hdrs, recursively
-Ihdrs_a
# x is already included, skip
-Ihdrs_b

# 3.4. includes from kernel_build and base_kernel
-Idevice
-Ibase

A dependent module automatically gets #1.1, #1.3, #3.1, #3.3, in this order. For example:

ddk_module(
    name = "child",
    kernel_build = ":device",
    deps = [":module"],
    # ...
)

Then ":child" is compiled with these flags, in this order:

# 1.2. linux_includes of deps, recursively
-Iuapi/module
-Iuapi/hdrs_a

# 1.4 linux_includes from kernel_build and base_kernel
-Iuapi/device
-Iuapi/base

# 2.
$(LINUXINCLUDE)

# 3.2. includes of deps, recursively
-Iself_1
-Iself_2
-Ihdrs_a
-Ix
-Ihdrs_b

# 3.4. includes from kernel_build and base_kernel
-Idevice
-Ibase

PARAMETERS

NameDescriptionDefault Value
nameName of target. This should usually be name of the output .ko file without the suffix.none
kernel_buildkernel_buildnone
srcssources or local headers.

Source files (.c, .S, .rs) must be in the package of this ddk_module target, or in subpackages.

Generated source files (.c, .S, .rs) are accepted as long as they are in the package of this ddk_module target, or in subpackages.

Header files specified here are only visible to this ddk_module target, but not dependencies. To export a header so dependencies can use it, put it in hdrs and set includes accordingly.

Generated header files are accepted.
None
depsA list of dependent targets. Each of them must be one of the following:

- kernel_module - ddk_module - ddk_headers. - ddk_prebuilt_object - ddk_library

If config is set, if some deps of this target have kconfig / defconfig set (including transitive dependencies), you may need to duplicate these targets in ddk_config.deps. Inconsistent configs are disallowed; if the resulting .config is not the same as the one from config, you get a build error.
None
hdrsSee ddk_headers.hdrs

If config is set, if some hdrs of this target have kconfig / defconfig set (including transitive dependencies), you may need to duplicate these targets in ddk_config.deps. Inconsistent configs are disallowed; if the resulting .config is not the same as the one from config, you get a build error.
None
textual_hdrsSee ddk_headers.textual_hdrs. DEPRECATED. Use hdrs.None
includesSee ddk_headers.includesNone
conditional_srcsA dictionary that specifies sources conditionally compiled based on configs.

Example:

conditional_srcs = { “CONFIG_FOO”: { True: [“foo.c”], False: [“notfoo.c”] } }

In the above example, if CONFIG_FOO is y or m, foo.c is compiled. Otherwise, notfoo.c is compiled instead.
None
crate_rootFor Rust modules, the file that will be passed to rustc to be used for building this module.

Currently, each .ko may only contain a single Rust crate. Modules with multiple crates are not yet supported. Hence, only a single file may be passed into crate_root.

Unlike rust_binary, this must always be set for Rust modules. No defaults are assumed.
None
linux_includesSee ddk_headers.linux_includes

Unlike ddk_headers.linux_includes, ddk_module.linux_includes is NOT applied to dependent ddk_modules.
None
outThe output module file. This should usually be "{name}.ko".

This is required if this target does not contain submodules.
None
local_definesList of defines to add to the compile and assemble command line.

Order matters. To prevent buildifier from sorting the list, use the # do not sort magic line.

Each string is prepended with -D and added to the compile/assemble command line for this target, but not to its dependents.

Unlike cc_library.local_defines, this is not subject to “Make” variable substitution or $(location) substitution.

Each string is treated as a single Bourne shell token. Unlike cc_library.local_defines, this is not subject to Bourne shell tokenization. The behavior is similar to cc_library with the no_copts_tokenization feature. For details about no_copts_tokenization, see cc_library.copts.
None
coptsAdd these options to the compilation command.

Order matters. To prevent buildifier from sorting the list, use the # do not sort magic line.

Subject to $(location) substitution.

The flags take effect only for compiling this target, not its dependencies, so be careful about header files included elsewhere.

All host paths should be provided via $(location) substitution. See “Implementation detail” section below.

Each $(location) expression should occupy its own token; optional argument key is allowed as a prefix. For example:

# Good copts = [“-include”, “$(location //other:header.h)”] copts = [“-include=$(location //other:header.h)”] # BAD - Don‘t do this! Split into two tokens. copts = [“-include $(location //other:header.h)”] # BAD - Don’t do this! Split into two tokens. copts = [“$(location //other:header.h) -Werror”] # BAD - Don't do this! Split into two tokens. copts = [“$(location //other:header.h) $(location //other:header2.h)”]

Unlike cc_library.local_defines, this is not subject to “Make” variable substitution.

Each string is treated as a single Bourne shell token. Unlike cc_library.copts this is not subject to Bourne shell tokenization. The behavior is similar to cc_library with the no_copts_tokenization feature. For details about no_copts_tokenization, see cc_library.copts.

Because each string is treated as a single Bourne shell token, if a plural $(locations) expression expands to multiple paths, they are treated as a single Bourne shell token, which is likely an undesirable behavior. To avoid surprising behaviors, use singular $(location) expressions to ensure that the label only expands to one path. For differences between the $(locations) and $(location), see $(location) substitution.

Implementation detail: Unlike usual $(location) expansion, $(location) in copts is expanded to a path relative to the current package before sending to the compiler.

For example:

# package: //package ddk_module( name = “my_module”, copts = [“-include”, “$(location //other:header.h)”], srcs = [“//other:header.h”, “my_module.c”], ) Then the content of generated Makefile is semantically equivalent to:

CFLAGS_my_module.o += -include ../other/header.h

The behavior is such because the generated Makefile is located in package/Makefile, and make is executed under package/. In order to find other/header.h, its path relative to package/ is given.
None
removed_coptsSimilar to copts but for flags removed from the compilation command.

For example: ddk_module( name = “my_module”, removed_copts = [“-Werror”], srcs = [“my_module.c”], ) Then the content of generated Makefile is semantically equivalent to:

CFLAGS_REMOVE_my_module.o += -Werror

Note: Due to implementation details of Kleaf flags in copts are written to a file and provided to the compiler with the @<arg_file> syntax, so they are not affected by removed_copts implemented by CFLAGS_REMOVE_. To remove flags from the Bazel copts list, do so directly.
None
asoptsSimilar to copts but for assembly.

For example: ddk_module( name = “my_module”, asopts = [“-ansi”], srcs = [“my_module.S”], ) Then the content of generated Makefile is semantically equivalent to:

AFLAGS_my_module.o += -ansi
None
linkoptsSimilar to copts but for linking the module.

For example: ddk_module( name = “my_module”, linkopts = [“-lc”], out = “my_module.ko”, # ... ) Then the content of generated Makefile is semantically equivalent to:

LDFLAGS_my_module.ko += -lc
None
configEXPERIMENTAL. The parent ddk_config that encapsulates Kconfig/defconfig.None
kconfigThe Kconfig files for this external module.

See Documentation/kbuild/kconfig-language.rst for its format.

Kconfig is optional for a ddk_module. The final Kconfig known by this module consists of the following:

- Kconfig from kernel_build - Kconfig from dependent modules, if any - Kconfig of this module, if any

For legacy reasons, this is singular and accepts a single target. If multiple Kconfig files should be added, use a filegroup to wrap the files.
None
defconfigThe defconfig file.

Items must already be declared in kconfig. An item not declared in Kconfig and inherited Kconfig files is silently dropped.

An item declared in kconfig without a specific value in defconfig uses default value specified in kconfig.
None
generate_btfAllows generation of BTF type information for the module. See kernel_module.generate_btfNone
autofdo_profileLabel to an AutoFDO profile.None
debug_info_for_profilingIf true, enables extra debug information to be emitted to make profile matching during AutoFDO more accurate.None
kwargsAdditional attributes to the internal rule. See complete list here.none

ddk_submodule

Declares a DDK (Driver Development Kit) submodule.

Symbol dependencies between submodules in the same ddk_module are not specified explicitly. This is convenient when you have multiple module files for a subsystem.

See Building External Modules or Documentation/kbuild/modules.rst, section “6.3 Symbols From Another External Module”, “Use a top-level kbuild file”.

Example:

ddk_submodule(
    name = "a",
    out = "a.ko",
    srcs = ["a.c"],
)

ddk_submodule(
    name = "b",
    out = "b.ko",
    srcs = ["b_1.c", "b_2.c"],
)

ddk_module(
    name = "mymodule",
    kernel_build = ":tuna",
    deps = [":a", ":b"],
)

linux_includes must be specified in the top-level ddk_module; see ddk_module.linux_includes.

ddk_submodule should avoid depending on ddk_headers that has linux_includes. See the Submodules section in ddk_module for best practices.

Ordering of includes

See ddk_module.

Caveats

As an implementation detail, ddk_submodule alone does not build any modules. The ddk_module target is the one responsible for building all .ko files.

A side effect is that for incremental builds, modules may be rebuilt unexpectedly. In the above example, if a.c is modified, the whole mymodule is rebuilt, causing both a.ko and b.ko to be rebuilt. Because ddk_module is always built in a sandbox, the object files (*.o) for b.ko is not cached.

Hence, it is always recommended to use one ddk_module per module (.ko file). You may use build/kernel/kleaf/build_cleaner.py to resolve dependencies; see build/kernel/kleaf/docs/build_cleaner.md.

The ddk_submodule rule should only be used when the dependencies among modules are too complicated to be presented in BUILD.bazel, and are frequently updated. When the dependencies are stable, it is recommended to:

  1. Replace ddk_submodule with ddk_module;
  2. Specify dependencies in the deps attribute explicitly.

PARAMETERS

NameDescriptionDefault Value
nameSee ddk_module.name.none
outSee ddk_module.out.none
srcsSee ddk_module.srcs.None
depsSee ddk_module.deps.

These are only effective in the current submodule, not other submodules declared in the same ddk_module.deps.

These are not exported to downstream targets that depends on the ddk_module that includes the current target.
None
hdrsSee ddk_module.hdrs.

These are only effective in the current submodule, not other submodules declared in the same ddk_module.deps.

These are exported to downstream targets that depends on the ddk_module that includes the current target. Example:

ddk_submodule(name = “module_parent_a”, hdrs = [...]) ddk_module(name = “module_parent”, deps = [“:module_parent_a”]) ddk_module(name = “module_child”, deps = [“:module_parent”])

module_child automatically gets hdrs of module_parent_a.
None
includesSee ddk_module.includes.

These are only effective in the current submodule, not other submodules declared in the same ddk_module.deps.

These are exported to downstream targets that depends on the ddk_module that includes the current target. Example:

ddk_submodule(name = “module_parent_a”, includes = [...]) ddk_module(name = “module_parent”, deps = [“:module_parent_a”]) ddk_module(name = “module_child”, deps = [“:module_parent”])

module_child automatically gets includes of module_parent_a.
None
local_definesSee ddk_module.local_defines.

These are only effective in the current submodule, not other submodules declared in the same ddk_module.deps.

These are not exported to downstream targets that depends on the ddk_module that includes the current target.
None
coptsSee ddk_module.copts.

These are only effective in the current submodule, not other submodules declared in the same ddk_module.deps.

These are not exported to downstream targets that depends on the ddk_module that includes the current target.
None
removed_coptsSee ddk_module.removed_copts.

These are only effective in the current submodule, not other submodules declared in the same ddk_module.deps.

These are not exported to downstream targets that depends on the ddk_module that includes the current target.
None
asoptsSee ddk_module.asopts.

These are only effective in the current submodule, not other submodules declared in the same ddk_module.deps.

These are not exported to downstream targets that depends on the ddk_module that includes the current target.
None
linkoptsSee ddk_module.linkopts.

These are only effective in the current submodule, not other submodules declared in the same ddk_module.deps.

These are not exported to downstream targets that depends on the ddk_module that includes the current target.
None
conditional_srcsSee ddk_module.conditional_srcs.None
crate_rootSee ddk_module.crate_root.None
autofdo_profileSee ddk_module.autofdo_profile.

These are only effective in the current submodule, not other submodules declared in the same ddk_module.deps.
None
debug_info_for_profilingSee ddk_module.debug_info_for_profiling.

These are only effective in the current submodule, not other submodules declared in the same ddk_module.deps.
None
kwargsAdditional attributes to the internal rule, e.g. visibility. See complete list here.none

dependency_graph

Declare targets for dependency graph visualization.

Output: File with a diagram representing a graph in DOT language.

PARAMETERS

NameDescriptionDefault Value
nameName of this target.none
kernel_buildThe kernel_build.none
kernel_modulesA list of external kernel_module()s.none
colorfulWhen set to True, outgoing edges from every node are colored differently.None
exclude_base_kernel_modulesWhether the analysis should made for only external modules.None
kwargsAdditional attributes to the internal rule, e.g. visibility. See complete list here.none

initramfs_modules_lists_test

Tests that the initramfs has modules.load* files with the given content.

PARAMETERS

NameDescriptionDefault Value
namename of the testnone
kernel_imagesname of the kernel_images target. It must build initramfs.none
expected_modules_listfile with the expected content for modules.loadNone
expected_modules_recovery_listfile with the expected content for modules.load.recoveryNone
expected_modules_charger_listfile with the expected content for modules.load.chargerNone
build_vendor_bootIf the kernel_images target builds vendor_boot.imgNone
build_vendor_kernel_bootIf the kernel_images target builds vendor_kernel_boot.imgNone
kwargsAdditional attributes to the internal rule, e.g. visibility. See complete list here.none

kernel_abi

Declare multiple targets to support ABI monitoring.

This macro is meant to be used alongside kernel_build macro.

For example, you may have the following declaration. (For actual definition of kernel_aarch64, see define_common_kernels().

kernel_build(name = "kernel_aarch64", ...)
kernel_abi(
    name = "kernel_aarch64_abi",
    kernel_build = ":kernel_aarch64",
    ...
)

The kernel_abi invocation above defines the following targets:

  • kernel_aarch64_abi_dump
    • Building this target extracts the ABI.
    • Include this target in a kernel_abi_dist target to copy ABI dump to --dist-dir.
  • kernel_aarch64_abi
    • A filegroup that contains kernel_aarch64_abi_dump. It also contains other targets if define_abi_targets = True; see below.

In addition, the following targets are defined if define_abi_targets = True:

  • kernel_aarch64_abi_update_symbol_list
    • Running this target updates kmi_symbol_list.
  • kernel_aarch64_abi_update_protected_exports
    • Running this target updates protected_exports_list.
  • kernel_aarch64_abi_update
    • Running this target updates abi_definition.
  • kernel_aarch64_abi_dump
    • Building this target extracts the ABI.
    • Include this target in a kernel_abi_dist target to copy ABI dump to --dist-dir.

To create a distribution, see kernel_abi_wrapped_dist.

See build/kernel/kleaf/abi.md for a conversion chart from build_abi.sh commands to Bazel commands.

PARAMETERS

NameDescriptionDefault Value
nameName of this target.none
kernel_buildThe kernel_build.none
define_abi_targetsWhether the target contains other files to support ABI monitoring. If None, defaults to True.

If False, this macro is equivalent to just calling kernel_build(name = name, **kwargs) filegroup(name = name + “_abi”, data = [name, abi_dump_target])

If True, implies collect_unstripped_modules = True. See kernel_build.collect_unstripped_modules.
None
kernel_modulesA list of external kernel_module()s to extract symbols from.None
module_groupingIf unspecified or None, it is True by default. If True, then the symbol list will group symbols based on the kernel modules that reference the symbol. Otherwise the symbol list will simply be a sorted list of symbols used by all the kernel modules.None
abi_definition_stgLocation of the ABI definition in STG format.None
kmi_enforcedThis is an indicative option to signal that KMI is enforced. If set to True, KMI checking tools respects it and reacts to it by failing if KMI differences are detected.None
unstripped_modules_archiveA kernel_unstripped_modules_archive which name is specified in abi.prop. DEPRECATED.None
kmi_symbol_list_add_onlyIf unspecified or None, it is False by default. If True, then any symbols in the symbol list that would have been removed are preserved (at the end of the file). Symbol list update will fail if there is no pre-existing symbol list file to read from. This property is intended to prevent unintentional shrinkage of a stable ABI.

This should be set to True if KMI_SYMBOL_LIST_ADD_ONLY=1.
None
kernel_modules_exclude_listList of base names for in-tree kernel modules to exclude from. i.e. This is the modules built in kernel_build, not the kernel_modules mentioned above.None
enable_add_vmlinuxIf unspecified or None, it is True by default. If True, enable the kernel_build_add_vmlinux transition from all targets instantiated by this macro (e.g. produced by abi_dump, extracted_symbols, etc).None
kwargsAdditional attributes to the internal rule, e.g. visibility. See complete list here.none

kernel_abi_dist

This macro is no longer supported. Invoking this macro triggers an error.

PARAMETERS

NameDescriptionDefault Value
nameignorednone
kernel_abiignorednone
kernel_build_add_vmlinuxignoredNone
ignore_diffignoredNone
no_ignore_diff_targetignoredNone
kwargsignorednone

DEPRECATED

Use kernel_abi_wrapped_dist instead.

kernel_abi_wrapped_dist

A wrapper over dist for kernel_abi.

After calling the dist, return the exit code from diff_abi.

Example:

kernel_build(
    name = "tuna",
    base_kernel = "//common:kernel_aarch64",
    ...
)
kernel_abi(name = "tuna_abi", ...)
pkg_files(
    name = "tuna_abi_dist_internal_files",
    srcs = [
        ":tuna",
        # "//common:kernel_aarch64", # remove GKI
        ":tuna_abi", ...             # Add kernel_abi to pkg_files
    ],
    strip_prefix = strip_prefix.files_only(),
    visibility = ["//visibility:private"],
)
pkg_install(
    name = "tuna_abi_dist_internal",
    srcs = [":tuna_abi_dist_internal_files"],
    visibility = ["//visibility:private"],
)
kernel_abi_wrapped_dist(
    name = "tuna_abi_dist",
    dist = ":tuna_abi_dist_internal",
    kernel_abi = ":tuna_abi",
)

Implementation notes:

with_vmlinux_transition is applied on all targets by default. In particular, the kernel_build targets in data automatically builds vmlinux regardless of whether vmlinux is specified in outs.

PARAMETERS

NameDescriptionDefault Value
namename of the ABI dist targetnone
distThe actual dist target (usually a pkg_install).

Note: This dist target should include kernel_abi in pkg_files that the pkg_install installs, e.g.

kernel_abi(name = “tuna_abi”, ...) pkg_files( name = “tuna_abi_dist_files”, srcs = [“:tuna_abi”, ...], # Add kernel_abi to pkg_files() # ... ) pkg_install( name = “tuna_abi_dist_internal”, srcs = [“:tuna_abi_dist_files”], # ... ) kernel_abi_wrapped_dist( name = “tuna_abi_dist”, dist = “:tuna_abi_dist_internal”, # ... )
none
kernel_abiNonconfigurable. name of the kernel_abi invocation.none
ignore_diffNonconfigurable. If True and the return code of stgdiff signals the ABI difference, then the result is ignored.None
no_ignore_diff_targetNonconfigurable. If ignore_diff is True, this need to be set to a name of the target that doesn't have ignore_diff. This target will be recommended as an alternative to a user. If no_ignore_diff_target is None, there will be no alternative recommended.None
kwargsAdditional attributes to the internal rule, e.g. visibility. See complete list here.none

kernel_build

Defines a kernel build target with all dependent targets.

It uses a build_config to construct a deterministic build environment (e.g. common/build.config.gki.aarch64). The kernel sources need to be declared via srcs (using a glob()). outs declares the output files that are surviving the build. The effective output file names will be $(name)/$(output_file). Any other artifact is not guaranteed to be accessible after the rule has run.

A few additional labels are generated. For example, if name is "kernel_aarch64":

  • kernel_aarch64_uapi_headers provides the UAPI kernel headers.
  • kernel_aarch64_headers provides the kernel headers.

PARAMETERS

NameDescriptionDefault Value
nameThe final kernel target name, e.g. "kernel_aarch64".none
outsThe expected output files.

Note: in-tree modules should be specified in module_outs instead.

This attribute must be either a dict or a list. If it is a list, for each item in out:

- If out does not contain a slash, the build rule automatically finds a file with name out in the kernel build output directory ${OUT_DIR}. find ${OUT_DIR} -name {out} There must be exactly one match. The file is copied to the following in the output directory {name}/{out}

Example: kernel_build(name = “kernel_aarch64”, outs = [“vmlinux”]) The bulid system copies ${OUT_DIR}/[<optional subdirectory>/]vmlinux to kernel_aarch64/vmlinux. kernel_aarch64/vmlinux is the label to the file.

- If out contains a slash, the build rule locates the file in the kernel build output directory ${OUT_DIR} with path out The file is copied to the following in the output directory 1. {name}/{out} 2. {name}/$(basename {out})

Example: kernel_build( name = “kernel_aarch64”, outs = [“arch/arm64/boot/vmlinux”]) The bulid system copies ${OUT_DIR}/arch/arm64/boot/vmlinux to: - kernel_aarch64/arch/arm64/boot/vmlinux - kernel_aarch64/vmlinux They are also the labels to the output files, respectively.

See search_and_cp_output.py for details.

Files in outs are part of the DefaultInfo that this kernel_build returns. For example: kernel_build(name = “kernel”, outs = [“vmlinux”], ...) pkg_files(name = “kernel_files”, srcs = [“kernel”], ...) pkg_install(name = “kernel_dist”, srcs = [“:kernel_files”]) vmlinux will be included in the distribution.

If it is a dict, it is wrapped in select().

Example: kernel_build( name = “kernel_aarch64”, outs = {“config_foo”: [“vmlinux”]}) If conditions in config_foo is met, the rule is equivalent to kernel_build( name = “kernel_aarch64”, outs = [“vmlinux”]) As explained above, the bulid system copies ${OUT_DIR}/[<optional subdirectory>/]vmlinux to kernel_aarch64/vmlinux. kernel_aarch64/vmlinux is the label to the file.

Note that a select() may not be passed into kernel_build() because select() cannot be evaluated in macros. Hence: - combining select()s is not allowed. Instead, expand the cartesian product. - To use AND chaining or OR chaining, use selects.config_setting_group().
none
build_configLabel of the build.config file, e.g. "build.config.gki.aarch64".

If it contains no files, the list of constants in @kernel_toolchain_info is used. This is //common:build.config.constants by default, unless otherwise specified.

If it contains no files, makefile must be set as the anchor to the directory to run make.
None
makefileMakefile governing the kernel tree sources (see srcs). Example values:

* None (default): Falls back to the value of KERNEL_DIR from build_config. kernel_build() executes make in KERNEL_DIR.

Note: The usage of specifying KERNEL_DIR in build_config is deprecated and will trigger a warning/error in the future.

* "//common:Makefile" (most common): the kernel sources are located in //common. This means kernel_build() executes make to build the kernel image and in-tree drivers in common.

This usually replaces //common:set_kernel_dir_build_config in your build_config; that is, if you set kernel_build.makefile, it is likely that you may drop //common:set_kernel_dir_build_config from components of kernel_build.build_config.

This replaces KERNEL_DIR=common in your build_config.

* "@kleaf//common:Makefile": If you set up a DDK workspace such that Kleaf tooling and your kernel source tree are located in the @kleaf submodule, you should specify the full label in the package. * the Makefile next to the build config:

For example:

kernel_build( name = "tuna", build_config = "//package:build.config.tuna", # the build.config.tuna is in //package makefile = "//package:Makefile", # so set KERNEL_DIR to "package" )

In this example, build.config.tuna is in //package. Hence, setting makefile = "Makefile" is equivalent to the legacy behavior of not setting KERNEL_DIR in build.config, and allowing _setup_env.sh to decide the value by inferring from the directory containing the build config, which is the //package.

* Makefile in the current package: the kernel sources are in the current package where kernel_build() is called.

For example:

kernel_build( name = "tuna", build_config = "build.config.tuna", # the build.config.tuna is in this package makefile = "Makefile", # so set KERNEL_DIR to this package )
None
keep_module_symversIf set to True, a copy of the default output Module.symvers is kept. * To avoid collisions in mixed build distribution packages, the file is renamed as $(name)_Module.symvers. * Default is False.None
keep_dot_configIf set to True, a copy of the default output .config is kept. * To avoid collisions in mixed build distribution packages, the file is renamed as $(name)_dot_config. * Default is False.None
srcsThe kernel sources (a glob()). If unspecified or None, it is the following: glob( [“**”], exclude = [ “**/.*”, # Hidden files “/.*/”, # Files in hidden directories “**/BUILD.bazel”, # build files “**/*.bzl”, # build files ], )None
module_outsA list of in-tree drivers. Similar to outs, but for *.ko files.

If a *.ko kernel module should not be copied to ${DIST_DIR}, it must be included implicit_outs instead of module_outs. The list implicit_outs + module_outs must include all *.ko files in ${OUT_DIR}. If not, a build error is raised.

Like outs, module_outs are part of the DefaultInfo that this kernel_build returns. For example: kernel_build(name = “kernel”, module_outs = [“foo.ko”], ...) pkg_files(name = “kernel_files”, srcs = [“kernel”], ...) pkg_install(name = “kernel_dist”, srcs = [“:kernel_files”]) foo.ko will be included in the distribution.

Like outs, this may be a dict. If so, it is wrapped in select(). See documentation for outs for more details.
None
implicit_outsLike outs, but not copied to the distribution directory.

Labels are created for each item in implicit_outs as in outs.
None
module_implicit_outslike module_outs, but not copied to the distribution directory.

Labels are created for each item in module_implicit_outs as in outs.
None
generate_vmlinux_btfIf True, generates vmlinux.btf that is stripped of any debug symbols, but contains type and symbol information within a .BTF section. This is suitable for ABI analysis through BTF.

Requires that "vmlinux" is in outs.
None
depsAdditional dependencies to build this kernel.None
archNonconfigurable. Target architecture. Default is arm64.

Value should be one of: * arm64 * x86_64 * riscv64 * arm (for 32-bit, uncommon) * i386 (for 32-bit, uncommon)

This must be consistent to ARCH in build configs if the latter is specified. Otherwise, a warning / error may be raised.
None
base_kernelA label referring the base kernel build.

If set, the list of files specified in the DefaultInfo of the rule specified in base_kernel is copied to a directory, and KBUILD_MIXED_TREE is set to the directory. Setting KBUILD_MIXED_TREE effectively enables mixed build.

To set additional flags for mixed build, change build_config to a kernel_build_config rule, with a build config fragment that contains the additional flags.

The label specified by base_kernel must produce a list of files similar to what a kernel_build rule does. Usually, this points to one of the following: - //common:kernel_{arch} - A kernel_filegroup rule, e.g. load("//build/kernel/kleaf:constants.bzl, “DEFAULT_GKI_OUTS”) kernel_filegroup( name = “my_kernel_filegroup”, srcs = DEFAULT_GKI_OUTS, )
None
make_goalsA list of strings defining targets for the kernel build. This overrides MAKE_GOALS from build config if provided.None
kconfig_extLabel of an external Kconfig.ext file sourced by the GKI kernel.None
dtstreeDevice tree support.None
kmi_symbol_listA label referring to the main KMI symbol list file. See additional_kmi_symbol_lists.

This is the Bazel equivalent of ADDITIONAL_KMI_SYMBOL_LISTS.
None
protected_exports_listA file containing list of protected exports. For example: protected_exports_list = “//common:android/abi_gki_protected_exports”None
protected_modules_listA file containing list of protected modules, For example: protected_modules_list = “//common:android/gki_protected_modules”None
additional_kmi_symbol_listsA list of labels referring to additional KMI symbol list files.

This is the Bazel equivalent of ADDITIONAL_KMI_SYMBOL_LISTS.

Let all_kmi_symbol_lists = [kmi_symbol_list] + additional_kmi_symbol_list

If all_kmi_symbol_lists is a non-empty list, abi_symbollist and abi_symbollist.report are created and added to the DefaultInfo, and copied to DIST_DIR during distribution.

If all_kmi_symbol_lists is None or an empty list, abi_symbollist and abi_symbollist.report are not created.

It is possible to use a glob() to determine whether abi_symbollist and abi_symbollist.report should be generated at build time. For example: kmi_symbol_list = “android/abi_gki_aarch64”, additional_kmi_symbol_lists = glob([“android/abi_gki_aarch64*”], exclude = [“android/abi_gki_aarch64”]),
None
trim_nonlisted_kmiIf True, trim symbols not listed in kmi_symbol_list and additional_kmi_symbol_lists. This is the Bazel equivalent of TRIM_NONLISTED_KMI.

Requires all_kmi_symbol_lists to be non-empty. If kmi_symbol_list or additional_kmi_symbol_lists is a glob(), it is possible to set trim_nonlisted_kmi to be a value based on that glob(). For example: trim_nonlisted_kmi = len(glob([“android/abi_gki_aarch64*”])) > 0
None
kmi_symbol_list_strict_modeIf True, add a build-time check between [kmi_symbol_list] + additional_kmi_symbol_lists and the KMI resulting from the build, to ensure they match 1-1.None
collect_unstripped_modulesIf True, provide all unstripped in-tree.None
kbuild_symtypesThe value of KBUILD_SYMTYPES.

This can be set to one of the following:

- "true" - "false" - "auto" - None, which defaults to "auto"

If the value is "auto", it is determined by the --kbuild_symtypes flag.

If the value is "true"; or the value is "auto" and --kbuild_symtypes is specified, then KBUILD_SYMTYPES=1. Note: kernel build time can be significantly longer.

If the value is "false"; or the value is "auto" and --kbuild_symtypes is not specified, then KBUILD_SYMTYPES=.
None
strip_modulesIf None or not specified, default is False. If set to True, debug information for distributed modules is stripped.

This corresponds to negated value of DO_NOT_STRIP_MODULES in build.config.
None
module_signing_keyA label referring to a module signing key.

This is to allow for dynamic setting of CONFIG_MODULE_SIG_KEY from Bazel.
None
system_trusted_keyA label referring to a trusted system key.

This is to allow for dynamic setting of CONFIG_SYSTEM_TRUSTED_KEY from Bazel.
None
modules_prepare_force_generate_headersIf True it forces generation of additional headers as part of modules_prepare.None
defconfigLabel to the base defconfig.

As a convention, files should usually be named <device>_defconfig (e.g. tuna_defconfig) to provide human-readable hints during the build. The prefix should be the name of the kernel_build. However, this is not a requirement. These configs are also applied to external modules, including kernel_modules and ddk_modules.

For mixed builds (base_kernel is set), this is usually set to the defconfig of the base_kernel, e.g. //common:arch/arm64/configs/gki_defconfig.

If check_defconfig is not disabled, Items must be present in the intermediate .config before post_defconfig_fragments are applied. See build/kernel/kleaf/docs/kernel_config.md for details.

As a special case, if this is evaluated to //build/kernel/kleaf:allmodconfig, Kleaf builds all modules except those exluded in post_defconfig_fragments. In this case, pre_defconfig_fragments must not be set.

See build/kernel/kleaf/docs/kernel_config.md for details.
None
pre_defconfig_fragmentsA list of fragments that are applied to the defconfig before make defconfig.

Even though this is a list, it is highly recommended that the list contains at most one item. This is so that tools/bazel run <name>_config applies to the single pre defconfig fragment correctly.

As a convention, files should usually be named <prop>_defconfig (e.g. 16k_defconfig) or <prop>_<value>_defconfig (e.g. page_size_16k_defconfig) to provide human-readable hints during the build. The prefix should describe what the defconfig does. However, this is not a requirement. These configs are also applied to external modules, including kernel_modules and ddk_modules.

For mixed builds (base_kernel is set), the file usually contains additional in-tree modules to build on top of gki_defconfig, e.g. CONFIG_FOO=m.

NOTE: pre_defconfig_fragments are applied before make defconfig, similar to PRE_DEFCONFIG_CMDS. If you had POST_DEFCONFIG_CMDS applying fragments in your build configs, consider using post_defconfig_fragments instead.

NOTE: Order matters, unlike post_defconfig_fragments. If there are conflicting items, later items overrides earlier items.

If check_defconfig is not disabled, Items must be present in the intermediate .config before post_defconfig_fragments are applied. See build/kernel/kleaf/docs/kernel_config.md for details.
None
post_defconfig_fragmentsA list of fragments that are applied to the defconfig after make defconfig.

As a convention, files should usually be named <prop>_defconfig (e.g. kasan_defconfig) or <prop>_<value>_defconfig (e.g. lto_none_defconfig) to provide human-readable hints during the build. The prefix should describe what the defconfig does. However, this is not a requirement. These configs are also applied to external modules, including kernel_modules and ddk_modules.

Files usually contain debug options. If you want to build in-tree modules, adding them to pre_defconfig_fragments may be a better choice.

NOTE: post_defconfig_fragments are applied after make defconfig, similar to POST_DEFCONFIG_CMDS. If you had PRE_DEFCONFIG_CMDS applying fragments in your build configs, consider using pre_defconfig_fragments instead.

If check_defconfig is not disabled, Items must be present in the final .config. See build/kernel/kleaf/docs/kernel_config.md for details.
None
defconfig_fragmentsDeprecated. Same as post_defconfig_fragments.None
check_defconfigDefault is match.

If disabled, no check is performed.

If match, checks .config against the defconfig, pre_defconfig_fragments and post_defconfig_fragments.

If minimized, checks .config against the result of make savedefconfig right after make defconfig, but before post_defconfig_fragments are applied. This can be set to minimized only if defconfig is set and pre_defconfig_fragments is not set.
None
page_sizeDefault is "default". Page size of the kernel build.

Value may be one of "default", "4k", "16k" or "64k". If "default", the defconfig is left as-is.

16k / 64k page size is only supported on arch = "arm64".
None
pack_module_envIf True, create {name}_module_env.tar.gz and other archives as part of the default output of this target.

These archives contains necessary files to build external modules.
None
sanitizersnon-configurable. A list of sanitizer configurations. By default, no sanitizers are explicity configured; values in defconfig are respected. Possible values are: - ["kasan_any_mode"] - ["kasan_sw_tags"] - ["kasan_generic"] - ["kcsan"]None
ddk_module_defconfig_fragmentsA list of additional defconfigs, to be used in ddk_modules building against this kernel. Unlike post_defconfig_fragments, ddk_module_defconfig_fragments is not applied to this kernel_build target, nor dependent legacy kernel_modules.None
ddk_module_headersA list of ddk_headers, to be used in ddk_modules building against this kernel.

Inherits ddk_module_headers from base_kernel, with a lower priority than ddk_module_headers of this kernel_build.

These headers are not applied to this kernel_build target.
None
kcflagsExtra KCFLAGS. Empty by default.

To add common KCFLAGS, you must explicitly set it to COMMON_KCFLAGS (see //build/kernel/kleaf:constants.bzl).
None
clang_autofdo_profilePath to an AutoFDO profile, For example: clang_autofdo_profile = “//toolchain/pgo-profiles/kernel:aarch64/android16-6.12/kernel.afdo”None
kwargsAdditional attributes to the internal rule, e.g. visibility. See complete list here.none

kernel_dtstree

Specify a kernel DTS tree.

PARAMETERS

NameDescriptionDefault Value
namename of the modulenone
srcssources of the DTS tree. Default is

glob([“**”], exclude = [ “**/.*”, “/.*/”, “**/BUILD.bazel”, “**/*.bzl”, ])
None
makefileMakefile of the DTS tree. Default is :Makefile, i.e. the Makefile at the root of the package.None
kwargsAdditional attributes to the internal rule, e.g. visibility. See complete list here.none

kernel_images

Build multiple kernel images.

You may use filegroup.output_group to request certain files. Example:

kernel_images(
    name = "my_images",
    build_vendor_dlkm = True,
)
filegroup(
    name = "my_vendor_dlkm",
    srcs = [":my_images"],
    output_group = "vendor_dlkm.img",
)

Allowed strings in filegroup.output_group:

  • vendor_dlkm.img, if build_vendor_dlkm is set
  • vendor_dlkm_flatten.img if build_vendor_dlkm_flatten is not empty
  • system_dlkm.img, if build_system_dlkm and system_dlkm_fs_type is set
  • system_dlkm.<type>.img for each of system_dlkm_fs_types, if build_system_dlkm is set and system_dlkm_fs_types is not empty.
  • system_dlkm.flatten.<type>.img for each of sytem_dlkm_fs_types, if build_system_dlkm_flattenis set andsystem_dlkm_fs_types` is not empty.

If no output files are found, the filegroup resolves to an empty one. You may also read OutputGroupInfo on the kernel_images rule directly in your rule implementation.

For details, see Requesting output files.

PARAMETERS

NameDescriptionDefault Value
namename of this rule, e.g. kernel_images,none
kernel_modules_installA kernel_modules_install rule.

The main kernel build is inferred from the kernel_build attribute of the specified kernel_modules_install rule. The main kernel build must contain System.map in outs (which is included if you use DEFAULT_GKI_OUTS or X86_64_OUTS from common_kernels.bzl).
none
kernel_buildA kernel_build rule. Must specify if build_boot.None
base_kernel_imagesThe kernel_images() corresponding to the base_kernel of the kernel_build. This is required for building a device-specific system_dlkm image. For example, if base_kernel of kernel_build() is //common:kernel_aarch64, then base_kernel_images is //common:kernel_aarch64_images.

This is also required if dedup_dlkm_modules and not build_system_dlkm.
None
build_initramfsWhether to build initramfs. Keep in sync with BUILD_INITRAMFS.None
build_vendor_dlkmWhether to build vendor_dlkm image. It must be set if vendor_dlkm_modules_list is set.None
build_vendor_dlkm_flattenWhether to build vendor_dlkm_flatten image. The image have directory structure as /lib/modules/*.ko i.e. no uname -r in the path

Note: at the time of writing (Jan 2022), vendor_dlkm.modules.blocklist is always created regardless of the value of VENDOR_DLKM_MODULES_BLOCKLIST. If build_vendor_dlkm() in build_utils.sh does not generate vendor_dlkm.modules.blocklist, an empty file is created.
None
build_bootWhether to build boot image. It must be set if either BUILD_BOOT_IMG or BUILD_VENDOR_BOOT_IMG is set.

This depends on kernel_build. Hence, if this is set to True, kernel_build must be set.

If True, adds boot.img to boot_image_outs if not already in the list.
None
build_vendor_bootWhether to build vendor_boot.img. It must be set if either BUILD_BOOT_IMG or BUILD_VENDOR_BOOT_IMG is set, and SKIP_VENDOR_BOOT is not set, and BUILD_VENDOR_KERNEL_BOOT is not set.

At most one of build_vendor_boot and build_vendor_kernel_boot may be set to True.

If True, adds vendor_boot.img to boot_image_outs if not already in the list.
None
build_vendor_kernel_bootWhether to build vendor_kernel_boot.img. It must be set if either BUILD_BOOT_IMG or BUILD_VENDOR_BOOT_IMG is set, and SKIP_VENDOR_BOOT is not set, and BUILD_VENDOR_KERNEL_BOOT is set.

At most one of build_vendor_boot and build_vendor_kernel_boot may be set to True.

If True, adds vendor_kernel_boot.img to boot_image_outs if not already in the list.
None
build_system_dlkmWhether to build system_dlkm.img an image with GKI modules.None
build_system_dlkm_flattenWhether to build system_dlkm.flatten..img. This image have directory structure as /lib/modules/*.ko i.e. no uname -r in the path.None
build_dtboWhether to build dtbo image. Keep this in sync with BUILD_DTBO_IMG.

If dtbo_srcs is non-empty, build_dtbo is True by default. Otherwise it is False by default.
None
dtbo_srcslist of *.dtbo files used to package the dtbo.img. Keep this in sync with MKDTIMG_DTBOS; see example below.

If dtbo_srcs is non-empty, build_dtbo must not be explicitly set to False.

Example: kernel_build( name = “tuna_kernel”, outs = [ “path/to/foo.dtbo”, “path/to/bar.dtbo”, ], ) kernel_images( name = “tuna_images”, kernel_build = “:tuna_kernel”, dtbo_srcs = [ “:tuna_kernel/path/to/foo.dtbo”, “:tuna_kernel/path/to/bar.dtbo”, ] )
None
dtbo_configa config file to create dtbo image by cfg_create command.None
mkbootimgPath to the mkbootimg.py script which builds boot.img. Only used if build_boot. If None, default to //tools/mkbootimg:mkbootimg.py. NOTE: This overrides MKBOOTIMG_PATH.None
depsAdditional dependencies to build images.

This must include the following: - For initramfs: - The file specified by MODULES_LIST - The file specified by MODULES_BLOCKLIST, if MODULES_BLOCKLIST is set - The file containing the list of modules needed for booting into recovery. - The file containing the list of modules needed for booting into charger mode. - For vendor_dlkm image: - The file specified by VENDOR_DLKM_MODULES_LIST - The file specified by VENDOR_DLKM_MODULES_BLOCKLIST, if set - The file specified by VENDOR_DLKM_PROPS, if set - The file specified by selinux_fc in VENDOR_DLKM_PROPS, if set
None
boot_image_outsA list of output files that will be installed to DIST_DIR when build_boot_images in build/kernel/build_utils.sh is executed.

You may leave out vendor_boot.img from the list. It is automatically added when build_vendor_boot = True.

If build_boot is equal to False, the default is empty.

If build_boot is equal to True, the default list assumes the following: - BOOT_IMAGE_FILENAME is not set (which takes default value boot.img), or is set to "boot.img" - vendor_boot.img if build_vendor_boot - RAMDISK_EXT=lz4. Is used when ramdisk_compression(see below) is not specified. - The list contains ramdisk.<ramdisk_ext> which means it assumes build_boot_images generates this file. See build_utils.sh on conditions for when it is actually generated. - if build_vendor_boot, it assumes VENDOR_BOOTCONFIG is set and BOOT_IMAGE_HEADER_VERSION >= 4, which creates vendor-bootconfig.img to contain VENDOR_BOOTCONFIG . - The list contains dtb.img
None
modules_listA file containing list of modules to use for vendor_boot.modules.load.None
modules_recovery_listA file containing a list of modules to load when booting into recovery.None
modules_charger_listA file containing a list of modules to load when booting into charger mode.None
modules_blocklistA file containing a list of modules which are blocked from being loaded.

This file is copied directly to staging directory, and should be in the format: blocklist module_name
None
modules_optionsLabel to a file copied to /lib/modules/<kernel_version>/modules.options on the ramdisk.

Lines in the file should be of the form: options <modulename> <param1>=<val> <param2>=<val> ...
None
vendor_ramdisk_binariesList of vendor ramdisk binaries which includes the device-specific components of ramdisk like the fstab file and the device-specific rc files. If specifying multiple vendor ramdisks and identical file paths exist in the ramdisks, the file from last ramdisk is used.

Note: order matters. To prevent buildifier from sorting the list, add the following: # do not sort
None
vendor_ramdisk_dev_nodesList of dev nodes description files which describes special device files to be added to the vendor ramdisk. File format is as accepted by mkbootfs.None
system_dlkm_fs_typeDeprecated. Use system_dlkm_fs_types instead.

Supported filesystems for system_dlkm image are ext4 and erofs. Defaults to ext4 if not specified.
None
system_dlkm_fs_typesList of file systems type for system_dlkm images.

Supported filesystems for system_dlkm image are ext4 and erofs. If not specified, builds system_dlkm.img with ext4 else builds system_dlkm.<fs>.img for each file system type in the list.
None
system_dlkm_modules_listlocation of an optional file containing the list of kernel modules which shall be copied into a system_dlkm partition image.None
system_dlkm_modules_blocklistlocation of an optional file containing a list of modules which are blocked from being loaded.

This file is copied directly to the staging directory and should be in the format: blocklist module_name
None
system_dlkm_propslocation of a text file containing the properties to be used for creation of a system_dlkm image (filesystem, partition size, etc). If this is not set (and build_system_dlkm is), a default set of properties will be used which assumes an ext4 filesystem and a dynamic partition.None
vendor_dlkm_archiveIf set, enable archiving the vendor_dlkm staging directory.None
vendor_dlkm_etc_filesFiles that need to be copied to vendor_dlkm.img etc/ directory.None
vendor_dlkm_fs_typeSupported filesystems for vendor_dlkm.img are ext4 and erofs. Defaults to ext4 if not specified.None
vendor_dlkm_modules_listlocation of an optional file containing the list of kernel modules which shall be copied into a vendor_dlkm partition image. Any modules passed into MODULES_LIST which become part of the vendor_boot.modules.load will be trimmed from the vendor_dlkm.modules.load.None
vendor_dlkm_modules_blocklistlocation of an optional file containing a list of modules which are blocked from being loaded.

This file is copied directly to the staging directory and should be in the format: blocklist module_name
None
vendor_dlkm_propslocation of a text file containing the properties to be used for creation of a vendor_dlkm image (filesystem, partition size, etc). If this is not set (and build_vendor_dlkm is), a default set of properties will be used which assumes an ext4 filesystem and a dynamic partition.None
ramdisk_compressionIf provided it specfies the format used for any ramdisks generated. If not provided a fallback value from build.config is used. Possible values are lz4, gzip, None.None
ramdisk_compression_argsCommand line arguments passed only to lz4 command to control compression level. It only has effect when used with ramdisk_compression equal to “lz4”.None
unpack_ramdiskWhen set to False, skips unpacking the vendor ramdisk and copy it as is, without modifications, into the boot image. Also skips the mkbootfs step.None
avb_sign_boot_imgIf set to True signs the boot image using the avb_boot_key. The kernel prebuilt tool avbtool is used for signing.None
avb_boot_partition_sizeSize of the boot partition in bytes. Used when avb_sign_boot_img is True.None
avb_boot_keyPath to the key used for signing. Used when avb_sign_boot_img is True.None
avb_boot_algorithmavb_boot_key algorithm used e.g. SHA256_RSA2048. Used when avb_sign_boot_img is True.None
avb_boot_partition_name= Name of the boot partition. Used when avb_sign_boot_img is True.None
dedup_dlkm_modulesIf set, modules already in system_dlkm is excluded in vendor_dlkm.modules.load. Modules in vendor_dlkm is allowed to link to modules in system_dlkm.

The system_dlkm image is defined by the following:

- If build_system_dlkm is set, the system_dlkm image built by this rule. - If build_system_dlkm is not set, the system_dlkm image in base_kernel_images. If base_kernel_images is not set, build fails.

If set, additional changes in the userspace is required so that system_dlkm modules are loaded before vendor_dlkm modules.
None
create_modules_orderWhether to create and keep a modules.order file generated by a postorder traversal of the kernel_modules_install sources. It applies to building initramfs and vendor_dlkm.None
kwargsAdditional attributes to the internal rule, e.g. visibility. See complete list here.none

kernel_module

Generates a rule that builds an external kernel module.

Example:

kernel_module(
    name = "nfc",
    srcs = glob([
        "**/*.c",
        "**/*.h",

        # If there are Kbuild files, add them
        "**/Kbuild",
        # If there are additional makefiles in subdirectories, add them
        "**/Makefile",
    ]),
    outs = ["nfc.ko"],
    kernel_build = "//common:kernel_aarch64",
)

PARAMETERS

NameDescriptionDefault Value
nameName of this kernel module.none
kernel_buildLabel referring to the kernel_build module.none
outsThe expected output files. If unspecified or value is None, it is ["{name}.ko"] by default.

For each token out, the build rule automatically finds a file named out in the legacy kernel modules staging directory. The file is copied to the output directory of this package, with the label name/out.

- If out doesn't contain a slash, subdirectories are searched.

Example: kernel_module(name = “nfc”, outs = [“nfc.ko”])

The build system copies <legacy modules staging dir>/lib/modules//extra/<some subdir>/nfc.ko to <package output dir>/nfc.ko

nfc/nfc.ko is the label to the file.

- If out contains slashes, its value is used. The file is also copied to the top of package output directory.

For example: kernel_module(name = “nfc”, outs = [“foo/nfc.ko”])

The build system copies <legacy modules staging dir>/lib/modules/
/extra/foo/nfc.ko to foo/nfc.ko

nfc/foo/nfc.ko is the label to the file.

The file is also copied to <package output dir>/nfc.ko.

nfc/nfc.ko is the label to the file.

See search_and_cp_output.py for details.
None
srcsSource files to build this kernel module. If unspecified or value is None, it is by default the list in the above example: glob([ “**/*.c”, “**/*.h”, “**/Kbuild”, “**/Makefile”, ])None
depsA list of other kernel_module or ddk_module dependencies.

Before building this target, Modules.symvers from the targets in deps are restored, so this target can be built against them.

It is an undefined behavior to put targets of other types to this list (e.g. ddk_headers).
None
makefileMakefile for the module. By default, this is Makefile in the current package.

This file determines where make modules is executed.

This is useful when the Makefile is located in a different package or in a subdirectory.
None
generate_btfAllows generation of BTF type information for the module. If enabled, passes vmlinux image to module build, which is required by BTF generator makefile scripts.

Disabled by default.

Requires CONFIG_DEBUG_INFO_BTF enabled in base kernel.

Requires rebuild of module if vmlinux changed, which may lead to an increase of incremental build time.

BTF type information increases size of module binary.
None
kwargsAdditional attributes to the internal rule, e.g. visibility. See complete list here.none

kernel_module_test

A test on artifacts produced by kernel_module.

PARAMETERS

NameDescriptionDefault Value
namename of testnone
modulesThe list of *.ko kernel modules, or targets that produces *.ko kernel modules (e.g. kernel_module).None
kwargsAdditional attributes to the internal rule, e.g. visibility. See complete list here.none

kernel_uapi_headers_cc_library

Defines a native cc_library based on a kernel's UAPI headers.

Example:

kernel_uapi_headers_cc_library(
    name = "uapi_header_lib",
    kernel_build = "//common:kernel_aarch64",
)

cc_binary(
    name = "foo",
    srcs = ["foo.c"],
    deps = [":uapi_header_lib"],
)

Internally, the kernel_build‘s UAPI header output tarball is unpacked. Then, a header-only cc_library is generated. This allows other native Bazel C/C++ rules to add the kernel’s UAPI headers as a dependency.

The library will automatically include the header directory in the dependent build, so source files are free to simply include the UAPI headers they need.

Note: the kernel_build's output UAPI header tarball includes the usr/include prefix. The prefix is stripped while creating this library. To include the file usr/include/linux/time.h from the tarball, a source file would #include <linux/time.h>.

PARAMETERS

NameDescriptionDefault Value
nameName of target.none
kernel_buildkernel_buildnone

kunit_test

A kunit test.

PARAMETERS

NameDescriptionDefault Value
namename of the testnone
test_namename of the kunit test suitenone
moduleslist of modules to be installed for kunit testnone
depsdependencies for kunit test runnernone
kwargsadditional arguments for py_testnone