自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
維持穩定的核心模組介面
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
為供應商模組維護穩定的核心模組介面 (KMI) 至關重要。GKI 核心會以二進位格式建構及發布,供應商可載入的模組則會在個別樹狀結構中建構。產生的 GKI 核心和供應商模組必須能一起運作。
一般來說,Linux 社群對於主線程式核心的內核 ABI 穩定性概念不以為然。面對不同的工具鍊、設定和不斷演進的 Linux 主線核心,在主線上維護穩定的 KMI 是不切實際的。不過,在受嚴格限制的 GKI 環境中,可以透過下列限制維持穩定的 KMI:
只有單一設定 (gki_defconfig
) 可用於建構核心。
KMI 僅在相同的 LTS 和 Android 版本的核心中穩定,例如 android14-6.1
、android15-6.6
或 android16-6.12
。
android-mainline
不會維持 KMI 穩定性。
只有 AOSP 提供的特定 Clang 工具鍊,以及為相應分支定義的工具鍊,才能用於建構核心和模組。
只有在符號清單中指定的模組所使用的符號,才會受到穩定性監控,並視為 KMI 符號。
- 相應的做法是,供應商模組只能使用 KMI 符號。如果需要非 KMI 符號,則會透過失敗的模組載入來強制執行這項限制。
KMI 分支凍結後,系統會允許變更,但不能破壞 KMI。這些異動包括:
- 設定變更
- 核心程式碼變更
- 工具鍊變更 (包括更新)
使用密封的建構程序和 LLVM 工具鍊
密封建構程序會在 kernel/manifest
中使用 repo
資訊清單,完整描述建構環境,確保 KMI 穩定。舉例來說,android16-6.12
的資訊清單包含工具鍊、建構系統,以及建構通用核心映像檔 (GKI) 核心所需的所有其他項目。建構設定 (主要是 BUILD.bazel
) 可確保正確使用所附工具,產生一致的建構結果。
使用密封式建構程序,還可確保樹狀結構的 ABI 說明是否一致,無論是 Google 產生的 (例如 android16-6.12
的 gki/aarch64/abi.stg
),或是在包含供應商模組的本機樹狀結構中產生的。核心模組介面 (KMI) 的ABI 說明書建立和比較工具也提供為清單檔案所述的存放區的一部分。
用於建構 GKI 核心的工具鍊,必須與用於建構供應商模組的工具鍊完全相容。自 Android 10 起,所有 Android 核心都必須使用 LLVM 工具鍊建構。在 GKI 中,用於建構產品核心和供應商模組的 LLVM 工具鍊,必須產生與 AOSP 的 LLVM 工具鍊相同的 ABI,合作夥伴也必須確保 KMI 與 GKI 核心相容。我們強烈建議您使用提供的建構工具,因為這些工具提供最佳相容性。
後續步驟
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Maintain a stable kernel module interface\n\nIt's critical to maintain a stable kernel module interface (KMI) for vendor\nmodules. The GKI kernel is\nbuilt and shipped in binary form and vendor-loadable modules are built in a\nseparate tree. The resulting GKI kernel and vendor modules must work as\nthough they were built together.\n\nGenerally, the Linux community has\n[frowned on the notion of in-kernel ABI\nstability](https://www.kernel.org/doc/Documentation/process/stable-api-nonsense.rst)\nfor the mainline kernel. In the face of different toolchains, configurations,\nand an ever-evolving Linux mainline kernel, it isn't feasible to maintain a\nstable KMI in mainline. However, it's possible to maintain a stable KMI in\nthe highly-constrained GKI environment with these constraints:\n\n- Only a single configuration, `gki_defconfig`, can be used to build the\n kernel.\n\n- The KMI is only stable within the same LTS and Android version of a kernel,\n such as `android14-6.1`, `android15-6.6` or `android16-6.12`.\n\n - No KMI stability is maintained for `android-mainline`.\n- Only the specific *Clang* toolchain supplied in AOSP and defined for the\n corresponding branch is used for building kernel and modules.\n\n- Only symbols known to be used by modules as specified in a symbol list are\n monitored for stability and considered KMI symbols.\n\n - The corollary is that vendor modules must use only KMI symbols. This constraint is enforced by failing module loads if non-KMI-symbols are required.\n- After the KMI branch is frozen, changes are allowed but can't break the KMI.\n These changes include the following:\n\n - Config changes\n - Kernel code changes\n - Toolchain changes (including updates)\n\nUse the hermetic build process and LLVM toolchain\n-------------------------------------------------\n\nThe hermetic build process ensures a stable KMI by having `repo` manifests in\n`kernel/manifest` completely describe the build environment. For example, the\n[manifest for `android16-6.12`](https://android.googlesource.com/kernel/manifest/+/refs/heads/common-android16-6.12/default.xml)\nincludes the toolchain, build system, and everything else required to build the\nGeneric Kernel Image (GKI) kernel. The build configuration, primarily\n[`BUILD.bazel`](https://android.googlesource.com/kernel/common/+/refs/heads/android16-6.12/BUILD.bazel),\nensures that the included tools are used correctly to generate consistent build\nresults.\n\nUsing a hermetic build process also ensures that the ABI description for the\ntree is consistent whether generated by Google (for example,\n[`gki/aarch64/abi.stg`](https://android.googlesource.com/kernel/common/+/refs/heads/android16-6.12/gki/aarch64/abi.stg)\nfor `android16-6.12`) or generated in a local tree that includes the vendor\nmodules. The\n[tools to create and compare the ABI description](https://android.googlesource.com/kernel/build/+/refs/heads/main-kernel/abi/)\nfor the Kernel Module Interface (KMI) are also provided as part of the repo\ndescribed by the manifest.\n\nThe toolchain used to build the GKI kernel must be completely compatible with\nthe toolchain used to build vendor modules. As of Android\n10, all Android kernels must be built\nwith an LLVM toolchain. With GKI, the LLVM toolchain used to build product\nkernels and vendor modules must generate the same ABI as the LLVM toolchain from\nAOSP and partners must ensure that the KMI is compatible with the GKI kernel.\nUsing the provided build tools is strongly encouraged as they provide the\nbest compatibility.\n\nWhat's next?\n------------\n\n- For instructions on building the kernel using the hermetic build process and\n LLVM toolchain, refer to refer to\n [Build kernels](/docs/setup/build/building-kernels).\n\n- For instructions on how to monitor the ABI and fix issues, refer to\n [Android Kernel ABI Monitoring](/docs/core/architecture/kernel/abi-monitor)"]]