[go: up one dir, main page]

0% found this document useful (0 votes)
81 views11 pages

Android Kernel Development Guide

Simplified Android Kernel Driver

Uploaded by

delapatua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views11 pages

Android Kernel Development Guide

Simplified Android Kernel Driver

Uploaded by

delapatua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Simplified Android Kernel

Driver Development with DDK v2


Matthias Männich <maennich@android.com> | Android Microconference
DDK - Overview

Android 14 - DDK definition embedded in source tree

// my_mod.c // my_other_mod.c # BUILD.bazel

#include <linux/module.h> #include <linux/module.h> load("//build/kernel/kleaf:kernel.bzl", "ddk_module")

#include "my_mod.h" ddk_module(


name = "my_mod",
MODULE_DESCRIPTION("A demo module"); MODULE_DESCRIPTION("Another demo module"); srcs = ["my_mod.c",],
MODULE_LICENSE("GPL v2"); MODULE_LICENSE("GPL v2"); out = "my_mod.ko",
hdrs = ["my_mod.h"],
void print_from_my_mod(void) { void print_something(void) { kernel_build = "//common:kernel",
printk(KERN_INFO "Hello"); print_from_my_mod(); deps = ["//common:all_headers"],
}; }; )

EXPORT_SYMBOL_GPL(print_from_my_mod); ddk_module(
name = "my_other_mod",
srcs = ["my_other_mod.c",],
out = "my_other_mod.ko",
kernel_build = "//common:kernel",
deps = [
":my_mod",
"//common:all_headers",
],
)
DDK - Overview

Android 14

● Consistent toolchain selection (clang, hermetic toolchain)


● Subset of kernel sources visible to modules (some headers!)
● Build file generation (Kbuild, Makefile, Kconfig)
● Dependency resolution
● Build orchestration (via Kleaf using Bazel)
● Packaging / Image generation

Documentation: https://android.googlesource.com/kernel/build/+/refs/heads/main/kleaf/docs/ddk/main.md
Android 15 - NEW! - "From empty directory to flashable kernel module in less than 5 minutes" *

● Build against prebuilt (signed) GKI images that are # WORKSPACE

○ on your disk kleaf_repository(


name = "kleaf",
○ hosted on ci.android.com
local_repo_dir = "path/to/kleaf/tooling/repo",
○ hosted privately prebuilt_artifact_dir = "path/to/distributed/prebuilts",
)

● Prebuilts come with batteries included


# BUILD.bazel
○ hermetic toolchain (compilers, sysroot, etc.)
load("@kleaf//build/kernel/kleaf:kernel.bzl", "ddk_module")
○ archives of headers
ddk_module(
name = "my_mod",
* subject to bandwidth and local compute resources srcs = ["my_mod.c",],
out = "my_mod.ko",
kernel_build = "@gki_prebuilts//:kernel_aarch64",
)
Android 15 - NEW! - Build against

● a fixed build on ci.android.com ● moving targets


kleaf_repository( kleaf_repository(
name = "kleaf", name = "kleaf",
build_number = "123456789", // slowly moving release branch
) branch = "android15-6.1-2024-01",
)
● a released tag
kleaf_repository(
kleaf_repository( name = "kleaf",
name = "kleaf", // development branch
branch = "android15-6.1-2024-01_r1", branch = "android15-6.1",
) )

kleaf_repository(
name = "kleaf",
// mainline linux + Android patches
branch = "android-mainline",
)
Android 15 - NEW! - Upgrading kernels could be as simple as a one-line change

● Upgrade within same LTS version ● Upgrade to more recent release branch
kleaf_repository( kleaf_repository(
name = "kleaf", name = "kleaf",
- branch = "android14-6.1", - branch = "android15-6.1-2023-03",
+ branch = "android15-6.1", + branch = "android15-6.1-2023-10",
) )

● Upgrade to next LTS version


kleaf_repository(
name = "kleaf", Of course, compile/link/test issues are not fixed yet.
- branch = "android15-6.1",
+ branch = "android15-6.6",
)
Android 15 - NEW! - Upgrading kernels could be as simple as a one-line change

● DDK helps transitioning to newer kernel versions


// my_mod.c

#include <linux/module.h>

MODULE_DESCRIPTION("A demo module"); Work-in-progress API for illustration purposes.


MODULE_LICENSE("GPL v2");

void print_from_my_mod(void) {
#ifdef DDK_ANDROID_14
printk(KERN_INFO "Hello from Android 14");
#elif DDK_ANDROID_15
printk(KERN_INFO "Hello from Android 15");
#else
printk(KERN_INFO "Hello");
#endif
};
Android 15 - NEW! - What about upstreaming DDK modules?

YES, please!

● DDK produces upstream-friendly Kbuild files

● DDK provides a framework to encourage upstream-friendly module development

● Dependency unwinding helps deciding on the upstreaming order

● Modules can be built conditionally based on the kernel built against


○ e.g. my_mod should only be built for 6.1 kernels as 6.2+ contains the module upstream
Questions?
Matthias Männich <maennich@android.com> | Android Microconference

You might also like