Linux Kernel之Backports Project

简介

Backports Project:

The Backports Project enables old kernels to run the latest drivers.

官网:https://backports.wiki.kernel.org/index.php/Main_Page

Backports Project始于2007年,当时名为compat-wireless。随着该项目的范围扩大到不仅仅是无线网络驱动程序,它被更名为compat-drivers。现在,该项目简称为 backports

目前支持的子系统:

  • Ethernet
  • Wireless
  • Bluetooth
  • NFC
  • ieee802154
  • Media
  • Regulator

每个backports版本都已针对所有支持的内核进行了测试编译,最早的版本是 3.0

Backports Project支持2种工作流模式:

  • 内核集成模式(kernel integration mode)
    • future kernel source tree and older kernel source tree must be present on the same machine at the same time
    • backports suite integrates the subsystems/drivers of the future kernel directly into the older kernel
  • release包模式(package releases mode)
    • future kernel source tree and older kernel source tree do not need to be present on the same machine at the same time
    • on machine hosting future kernel source tree, backport package is generated
    • on machine hosting older kernel, backport package is built out-of-tree against older kerne
    • backport package is loosely akin to a patch file

对于第三方驱动常用的是第二种release包模式。

内核集成模式

backports项目最初只支持将版本打包为tarball,及第二种模式。
backports-20141114 (first release branch will be based on origin/linux-3.19.y) 开始才添加内核集成模式的支持。

内核集成模式可以:

  • 自动整合新版本的设备驱动

    atomically integrate future versions of device drivers

  • 应用必要的补丁到backport工程

    apply required patches to backport them

  • 增加相应的钩子到Kconfig使其变得可见和可用

    add hooks into kconfig to make them visible and usable

  • 处理相同驱动新老版本的冲突

    deal with conflicts with older versions of these same drivers

通过支持内核集成,backports项目现在可以支持在旧内核上自动backport子系统和驱动程序,而不需要要求是模块,都可以built-in

基本用法

脚本工具gentree.py可以用来内核集成 Backport。
任何一个 >= 3.0的内核树都可以做为kernel target,任何一个next-20141114之后的tag(backports的linux-next分支)或者v3.19之后的 release 版本(backports的stable分支)都可以作为kernel source

$./gentree.py --integrate --clean --gitdebug --git-revision backports-tag ~/backports kernel source/ ~/kernel target/

集成OK后,通过make menuconfig可以看到多出来的 Backport 选项,类似下面:

[*] Backport Linux next-20141114-0-gd7e5a72 (backports backports-20141114-0-gded96b2)  --->

详细的介绍可查看官方文档:https://backports.wiki.kernel.org/index.php/Documentation/integration

release包模式

Backports Project提供了2种类型的 packages:

编译构建

Backports Project的编译遵循 Linux kernel 的构建机制,所以编译过程是类似的。

  • 本地编译
    # as a user
    make help
    make defconfig-help
    make defconfig-wifi
    make menuconfig
    make -j4
    # as root
    make install
    # reboot and enjoy
  • 交叉编译:
    set -a
    CROSS_COMPILE=${CROSS_COMPILE}
    ARCH=${TARGET_CPU}
    KLIB_BUILD=${DEV_PATH}/${LINUX_DIR}
    KLIB=${TARGET_ROOT_ON_HOST}
    set +a
    make oldconfig  # menuconfig worked here too
    make
    #make install
    注:

    The ‘make install’ target isn’t currently sane for cross-builds due to the bacport_firmware_install script not respecting prefixes. For now you can comment out that script few others like initrd updates, from being run out of the Makefiles.

开发和新增驱动

这部分属于进阶部分,这里就略过了,具体可查看官方文档:https://backports.wiki.kernel.org/index.php/Documentation/backports/hacking