cjktty18 Sep 2015 • Leave Comments
An alternative is Univt patch.
In this post, we will show how to extract cjktty.patch from a patched kernel. Afterwards, we will apply the extracted patch to our own kernel. During the process, we might look into several relevant commands.
- Suppose our current system kernel is 4.0.5. We will generate a cjktty.patch suitable for this kernel.
The patched kernel is linux-cjktty from which we will extract the desired patch.
According to past experience, cjktty.patch for kernel 3.18 ~ 3.19 fits 4.0 as well. We will choose the branch 3.19-utf8.
Clone the chosen branch locally.
$ cd ~/workspace $ git clone --branch 3.19-utf8 --depth 4 https://github.com/Gentoo-zh/linux-cjktty.git
--branch: we only need branch 3.19-utf8. If not specified, git will clone all the branches, spending a day maybe depending on bandwidth.
--depth: from the repository, we find the the top 3 commits are enough to extract our cjktty.patch. We MUST clone at least the top
3 + 1 = 4commits.
commit 9a5a7d3215307e28df3aea6ac09931a4d55e151e Author: microcai <email@example.com> Date: Thu Jan 13 05:18:45 2011 +0800 [vt] add cjk font that has 65536 chars commit 3dbe651a011ac6b6bbd976d96b5d08fb2baf709c Author: microcai <firstname.lastname@example.org> Date: Mon Feb 21 12:58:18 2011 +0800 [vt] diable setfont if we have cjk font in kernel commit a2553800e3e8ea1d13f3e3a4211599a3268ce9a2 Author: microcai <email@example.com> Date: Fri Jan 9 12:45:07 2015 +0800 [vt] fix 255 glyph limit, prepare for CJK font support commit d8cf08a565defc2f9810b9ecd33b1b3211b029e1 Author: Greg Kroah-Hartman <firstname.lastname@example.org> Date: Thu Mar 26 14:00:21 2015 +0100 Linux 3.19.3
From the output, we can see only 4 commits history as expected. We will extract the patch from the top 3 commits authored by microcai.
~ $ git diff d8cf08a565defc2f9810b9ecd33b1b3211b029e1 9a5a7d3215307e28df3aea6ac09931a4d55e151e -- > cjktty.patch # or ~ $ git diff HEAD~3 -- > cjktty.patch # or ~ $ git format-patch -3 HEAD --stdout > cjktty.patch # or ~ $ git format-patch -3 9a5a7d3215307e28df3aea6ac09931a4d55e151e --stdout > cjktty.patch
- Pay attention to the order of commit ID (SHA1 hash). Put the earliest commit ID (4th) before the latest one (HEAD).
- HEAD~3 means extract patch from top to 3rd commits (inclusive). The latest ID (HEAD) precedes the 3rd one.
format-patch is similar to git diff. *-n
* means patch *n* commits leading up to (inclusive) of current branch. The patch file orgnization is a little different from that of *git diff*.
If you use the git diff command to compare the 3rd patch with the 1st, you will find them the same patch but with different patch format. Specially, format-patch contains more information.
- We recommend to use format-patch to include commit messages, making it more appropriate for most scenarios involving exchanging patches over the Internet. Details refer to reference 1.
Test the patch
~ # cd /usr/src/linux/ ~ # patch -p1 --dry-run < /path/to/cjktty.patch ~ # git apply --whitespace=warn --numstat < /path/to/cjktty.patch ~ # git apply --whitespace=warn --check < /path/to/cjktty.patch
When testing patch file, it might remind errors like:
Hunk #17 FAILED at 2708. # or error: patch failed: drivers/video/console/fbcon.c:2689 error: drivers/video/console/fbcon.c: patch does not apply
- Error number 2708 (reported by patch) refers to line number in Linux-cjktty sources, while 2689 (reported by git apply) in Gentoo-sources. Search 2708 or 2689 in patch file and check either/both kernel sources.
- Some error are caused by extra whitespaces, especially those on blank lines.
Apply the patch
~ # cd /usr/src/linux/ ~ # patch -p1 < /path/to/cjktty.patch ~ # git apply --whitespace=warn < /path/to/cjktty.patch
If you want to make sure the patch is applied correctly,
~ # cd /usr/src/linux/ ~ # patch -p1 --dry-run -R < /path/to/cjktty.patch ~ # git apply --whitespace=warn --check -R < /path/to/cjktty.patch
You can reverse a patch by adding -R argument.
If /usr/src/linux source is polluted by patch error, you can re-install the kernel source.
We cannot reverse a patch error.
# emerge -av --unmerge gentoo-sources-4.0.5 # rm -r /usr/src/linux-4.0.5-gentoo # emerge -av gentoo-sources-4.0.5
- Pay attention to use unmerge instead of depclean. The former will keep package dependencies.
- Maybe we can just extract the source code to /usr/src/linux.