🔧

How to backport Linux device drivers

2021/02/17に公開

What is backporting ?

The official site (https://backports.wiki.kernel.org/index.php/Main_Page) has good definition.

"Backporting" is the process of making new software run on something old. A version of something new that's been modified to run on something old is called a "backport".

Of course you can backport device drivers by yourself, you can backport more easily with tools developed by Linux backports project. This document explains procedure of backporting with backports project tools.

Procedure

This document explains procedure of backporting Linux 4.4 device drivers to Linux 3.10.108.

Obtain linux-next

Because backports relying on linux-next tree.

cd ~/
mkdir git
cd ~/git
git clone git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git

Obtain backporting source tree

cd ~/git
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
cd linux-stable
git checkout v3.10.108

Obtain backporting destination tree

cd ~/git
git clone git://git.kernel.org/pub/scm/linux/kernel/git/backports/backports.git
cd backports
git checkout linux-4.4.y

Install coccinelle

If your coccinelle version of distribution package is less than 1.0.5, install with package.

sudo apt install coccinelle

If more than 1.0.6, install a older version with source. Because the coccinelle changes syntax[1] from 1.0.6.
This is the procedure of building with 1.0.4 [2] .

git clone https://github.com/coccinelle/coccinelle.git
cd coccinelle
git checkout 1.0.4
sudo apt install pkg-config ocaml-native-compilers ocaml-findlib menhir libmenhir-ocaml-dev libpcre-ocaml-dev texlive-fonts-extra texlive-latex-base
./autogen
./configure
make clean
make
sudo make install

This is a workaround. In the future, backports requires more than 1.0.6. The maintainer Johannes said. https://marc.info/?l=linux-backports&m=152585249900819&w=2

run the backporting

cd ~/git/backports
./gentree.py --copy-list ./copy-list --integrate --clean --git-revision v4.4 ~/git/linux-next ~/git/linux-stable

This is the result.

Get original source files from git ...
Applying patches from patches to [your home]/git/linux-stable/backports/ ...
Modify Kconfig tree ...
Rewrite Makefiles and Kconfig files ...
Applying patches from integration-patches/ to [your home]/git/linux-stable ...
Done!

build

Change the kernel config and build.

cd ~/git/linux-stable
make menuconfig
[*] Backport Linux v4.4-0-gafd2ff9 (backports v4.4.2-1-0-gbec4037)  --->
make -j9
脚注
  1. To get more information for syntax change refer here. https://github.com/coccinelle/coccinelle/issues/135 ↩︎

  2. We use 1.0.4 because 1.0.5 could not be built. ↩︎

Discussion